Skip to content

Commit dd5c9c2

Browse files
glaubitzdrakenclimber
authored andcommitted
arch: Add 32-bit Motorola 68000 support
Signed-off-by: John Paul Adrian Glaubitz <[email protected]> Acked-by: Paul Moore <[email protected]> Signed-off-by: Tom Hromatka <[email protected]>
1 parent 744c9a8 commit dd5c9c2

22 files changed

+190
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The libseccomp library currently supports the architectures listed below:
3434
* 32-bit ARM EABI (arm)
3535
* 64-bit ARM (aarch64)
3636
* 64-bit LoongArch (loongarch64)
37+
* 32-bit Motorola 68000 (m68k)
3738
* 32-bit MIPS (mips)
3839
* 32-bit MIPS little endian (mipsel)
3940
* 64-bit MIPS (mips64)

doc/man/man1/scmp_sys_resolver.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ special manner by libseccomp depending on the operation.
3434
.B \-a \fIARCH
3535
The architecture to use for resolving the system call. Valid
3636
.I ARCH
37-
values are "x86", "x86_64", "x32", "arm", "aarch64", "loongarch64", "mips",
38-
"mipsel", "mips64", "mipsel64", "mips64n32", "mipsel64n32", "parisc",
37+
values are "x86", "x86_64", "x32", "arm", "aarch64", "loongarch64", "m68k",
38+
"mips", "mipsel", "mips64", "mipsel64", "mips64n32", "mipsel64n32", "parisc",
3939
"parisc64", "ppc", "ppc64", "ppc64le", "s390", "s390x", "sheb" and "sh".
4040
.TP
4141
.B \-t

include/seccomp-syscalls.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@
277277
#define __PNR_riscv_flush_icache -10243
278278
#define __PNR_memfd_secret -10244
279279
#define __PNR_fstat -10245
280+
#define __PNR_atomic_barrier -10246
281+
#define __PNR_atomic_cmpxchg_32 -10247
282+
#define __PNR_getpagesize -10248
280283

281284
/*
282285
* libseccomp syscall definitions
@@ -354,6 +357,18 @@
354357
#define __SNR_arch_prctl __PNR_arch_prctl
355358
#endif
356359

360+
#ifdef __NR_atomic_barrier
361+
#define __SNR_atomic_barrier __NR_atomic_barrier
362+
#else
363+
#define __SNR_atomic_barrier __PNR_atomic_barrier
364+
#endif
365+
366+
#ifdef __NR_atomic_cmpxchg_32
367+
#define __SNR_atomic_cmpxchg_32 __NR_atomic_cmpxchg_32
368+
#else
369+
#define __SNR_atomic_cmpxchg_32 __PNR_atomic_cmpxchg_32
370+
#endif
371+
357372
#ifdef __NR_bdflush
358373
#define __SNR_bdflush __NR_bdflush
359374
#else
@@ -824,6 +839,12 @@
824839

825840
#define __SNR_getitimer __NR_getitimer
826841

842+
#ifdef __NR_getpagesize
843+
#define __SNR_getpagesize __NR_getpagesize
844+
#else
845+
#define __SNR_getpagesize __PNR_getpagesize
846+
#endif
847+
827848
#ifdef __NR_getpeername
828849
#define __SNR_getpeername __NR_getpeername
829850
#else

include/seccomp.h.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ struct scmp_arg_cmp {
164164
#endif /* AUDIT_ARCH_LOONGARCH64 */
165165
#define SCMP_ARCH_LOONGARCH64 AUDIT_ARCH_LOONGARCH64
166166

167+
/**
168+
* The Motorola 68000 architecture tokens
169+
*/
170+
#define SCMP_ARCH_M68K AUDIT_ARCH_M68K
171+
167172
/**
168173
* The MIPS architecture tokens
169174
*/

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ SOURCES_ALL = \
3333
arch-arm.h arch-arm.c \
3434
arch-aarch64.h arch-aarch64.c \
3535
arch-loongarch64.h arch-loongarch64.c \
36+
arch-m68k.h arch-m68k.c \
3637
arch-mips.h arch-mips.c \
3738
arch-mips64.h arch-mips64.c \
3839
arch-mips64n32.h arch-mips64n32.c \

src/arch-m68k.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Enhanced Seccomp m68k Specific Code
3+
*
4+
* Copyright (c) 2015 Freescale <[email protected]>
5+
* 2017-2023 John Paul Adrian Glaubitz <[email protected]>
6+
* Author: Bogdan Purcareata <[email protected]>
7+
* John Paul Adrian Glaubitz <[email protected]>
8+
*
9+
* Derived from the PPC-specific code
10+
*
11+
*/
12+
13+
/*
14+
* This library is free software; you can redistribute it and/or modify it
15+
* under the terms of version 2.1 of the GNU Lesser General Public License as
16+
* published by the Free Software Foundation.
17+
*
18+
* This library is distributed in the hope that it will be useful, but WITHOUT
19+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
21+
* for more details.
22+
*
23+
* You should have received a copy of the GNU Lesser General Public License
24+
* along with this library; if not, see <http://www.gnu.org/licenses>.
25+
*/
26+
27+
#include <stdlib.h>
28+
#include <errno.h>
29+
#include <string.h>
30+
#include <linux/audit.h>
31+
32+
#include "db.h"
33+
#include "syscalls.h"
34+
#include "arch.h"
35+
#include "arch-m68k.h"
36+
37+
/* m68k syscall numbers */
38+
#define __m68k_NR_socketcall 102
39+
#define __m68k_NR_ipc 117
40+
41+
ARCH_DEF(m68k)
42+
43+
const struct arch_def arch_def_m68k = {
44+
.token = SCMP_ARCH_M68K,
45+
.token_bpf = AUDIT_ARCH_M68K,
46+
.size = ARCH_SIZE_32,
47+
.endian = ARCH_ENDIAN_BIG,
48+
.sys_socketcall = __m68k_NR_socketcall,
49+
.sys_ipc = __m68k_NR_ipc,
50+
.syscall_resolve_name = abi_syscall_resolve_name_munge,
51+
.syscall_resolve_name_raw = m68k_syscall_resolve_name,
52+
.syscall_resolve_num = abi_syscall_resolve_num_munge,
53+
.syscall_resolve_num_raw = m68k_syscall_resolve_num,
54+
.syscall_rewrite = abi_syscall_rewrite,
55+
.rule_add = abi_rule_add,
56+
.syscall_name_kver = m68k_syscall_name_kver,
57+
.syscall_num_kver = m68k_syscall_num_kver,
58+
};

src/arch-m68k.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Enhanced Seccomp m68k Specific Code
3+
*
4+
* Copyright (c) 2015 Freescale <[email protected]>
5+
* 2017-2023 John Paul Adrian Glaubitz <[email protected]>
6+
* Author: Bogdan Purcareata <[email protected]>
7+
* John Paul Adrian Glaubitz <[email protected]>
8+
*
9+
* Derived from the PPC-specific code
10+
*
11+
*/
12+
13+
/*
14+
* This library is free software; you can redistribute it and/or modify it
15+
* under the terms of version 2.1 of the GNU Lesser General Public License as
16+
* published by the Free Software Foundation.
17+
*
18+
* This library is distributed in the hope that it will be useful, but WITHOUT
19+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
21+
* for more details.
22+
*
23+
* You should have received a copy of the GNU Lesser General Public License
24+
* along with this library; if not, see <http://www.gnu.org/licenses>.
25+
*/
26+
27+
#ifndef _ARCH_M68K_H
28+
#define _ARCH_M68K_H
29+
30+
#include "arch.h"
31+
32+
ARCH_DECL(m68k)
33+
34+
#endif

src/arch-syscall-dump.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "arch-x32.h"
3636
#include "arch-arm.h"
3737
#include "arch-loongarch64.h"
38+
#include "arch-m68k.h"
3839
#include "arch-mips.h"
3940
#include "arch-mips64.h"
4041
#include "arch-mips64n32.h"
@@ -110,6 +111,8 @@ int main(int argc, char *argv[])
110111
break;
111112
case SCMP_ARCH_LOONGARCH64:
112113
sys = loongarch64_syscall_iterate(iter);
114+
case SCMP_ARCH_M68K:
115+
sys = m68k_syscall_iterate(iter);
113116
break;
114117
case SCMP_ARCH_MIPS:
115118
case SCMP_ARCH_MIPSEL:

src/arch-syscall-validate

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,30 @@ function dump_lib_loongarch64() {
348348
dump_lib_arch loongarch64 | mangle_lib_syscall loongarch64
349349
}
350350

351+
# Dump the m68k system syscall table
352+
#
353+
# Arguments:
354+
# 1 path to the kernel source
355+
#
356+
# Dump the architecture's syscall table to stdout.
357+
#
358+
function dump_sys_m68k() {
359+
cat $1/arch/m68k/kernel/syscalls/syscall.tbl | \
360+
grep -v "^#" | \
361+
sed -n "/[0-9]\+[ \t]\+\(common\)/p" | \
362+
awk '{ print $3","$1 }' | \
363+
sort
364+
}
365+
366+
#
367+
# Dump the m68k library syscall table
368+
#
369+
# Dump the library's syscall table to stdout.
370+
#
371+
function dump_lib_m68k() {
372+
dump_lib_arch m68k | mangle_lib_syscall m68k
373+
}
374+
351375
#
352376
# Dump the mips system syscall table
353377
#
@@ -664,6 +688,9 @@ function dump_sys() {
664688
loongarch64)
665689
dump_sys_loongarch64 "$2"
666690
;;
691+
m68k)
692+
dump_sys_m68k "$2"
693+
;;
667694
mips)
668695
dump_sys_mips "$2"
669696
;;
@@ -734,6 +761,9 @@ function dump_lib() {
734761
loongarch64)
735762
dump_lib_loongarch64
736763
;;
764+
m68k)
765+
dump_lib_m68k
766+
;;
737767
mips)
738768
dump_lib_mips
739769
;;
@@ -799,6 +829,7 @@ function gen_csv() {
799829
abi_list+=" x86 x86_64 x32"
800830
abi_list+=" arm aarch64"
801831
abi_list+=" loongarch64"
832+
abi_list+=" m68k"
802833
abi_list+=" mips mips64 mips64n32"
803834
abi_list+=" parisc parisc64"
804835
abi_list+=" ppc ppc64"
@@ -911,6 +942,7 @@ if [[ $opt_arches == "" ]]; then
911942
x86 x86_64 x32 \
912943
arm aarch64 \
913944
loongarch64 \
945+
m68k \
914946
mips mips64 mips64n32 \
915947
parisc parisc64 \
916948
ppc ppc64 \

src/arch.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "arch-arm.h"
3737
#include "arch-aarch64.h"
3838
#include "arch-loongarch64.h"
39+
#include "arch-m68k.h"
3940
#include "arch-mips.h"
4041
#include "arch-mips64.h"
4142
#include "arch-mips64n32.h"
@@ -66,6 +67,8 @@ const struct arch_def *arch_def_native = &arch_def_arm;
6667
const struct arch_def *arch_def_native = &arch_def_aarch64;
6768
#elif __loongarch_lp64
6869
const struct arch_def *arch_def_native = &arch_def_loongarch64;
70+
#elif __m68k__
71+
const struct arch_def *arch_def_native = &arch_def_m68k;
6972
#elif __mips__ && _MIPS_SIM == _MIPS_SIM_ABI32
7073
#if __MIPSEB__
7174
const struct arch_def *arch_def_native = &arch_def_mips;
@@ -146,6 +149,8 @@ const struct arch_def *arch_def_lookup(uint32_t token)
146149
return &arch_def_aarch64;
147150
case SCMP_ARCH_LOONGARCH64:
148151
return &arch_def_loongarch64;
152+
case SCMP_ARCH_M68K:
153+
return &arch_def_m68k;
149154
case SCMP_ARCH_MIPS:
150155
return &arch_def_mips;
151156
case SCMP_ARCH_MIPSEL:
@@ -204,6 +209,8 @@ const struct arch_def *arch_def_lookup_name(const char *arch_name)
204209
return &arch_def_aarch64;
205210
else if (strcmp(arch_name, "loongarch64") == 0)
206211
return &arch_def_loongarch64;
212+
else if (strcmp(arch_name, "m68k") == 0)
213+
return &arch_def_m68k;
207214
else if (strcmp(arch_name, "mips") == 0)
208215
return &arch_def_mips;
209216
else if (strcmp(arch_name, "mipsel") == 0)

0 commit comments

Comments
 (0)