From 98bce26abf09218e7f06608e132bf9f44893a5fc Mon Sep 17 00:00:00 2001 From: Paul Moore Date: Mon, 1 Nov 2021 10:34:53 -0600 Subject: arch: move the ARCH_DEF() calls into the arch/ABI specific files This should make it easier to ensure we have arch/ABIs added properly to libseccomp. Signed-off-by: Paul Moore Reviewed-by: Tom Hromatka Signed-off-by: Tom Hromatka (cherry picked from commit 060a677ea5de077a7ae9f82b7142d388a1a336b6) Conflicts: src/arch-sh.c - Doesn't exist in release-2.5 src/syscalls.c - Minor merge conflict where ARCH_DEF() was removed --- src/arch-aarch64.c | 3 +++ src/arch-arm.c | 3 +++ src/arch-mips.c | 2 ++ src/arch-mips64.c | 3 +++ src/arch-mips64n32.c | 3 +++ src/arch-parisc.c | 3 +++ src/arch-parisc64.c | 3 +++ src/arch-ppc.c | 2 ++ src/arch-ppc64.c | 2 ++ src/arch-riscv64.c | 3 +++ src/arch-s390.c | 2 ++ src/arch-s390x.c | 2 ++ src/arch-x32.c | 3 +++ src/arch-x86.c | 2 ++ src/arch-x86_64.c | 3 +++ src/arch.h | 15 +++++++++++++++ src/syscalls.c | 30 ------------------------------ 17 files changed, 54 insertions(+), 30 deletions(-) diff --git a/src/arch-aarch64.c b/src/arch-aarch64.c index b2d76c6..9b12b43 100644 --- a/src/arch-aarch64.c +++ b/src/arch-aarch64.c @@ -25,6 +25,9 @@ #include "arch.h" #include "arch-aarch64.h" +#include "syscalls.h" + +ARCH_DEF(aarch64) const struct arch_def arch_def_aarch64 = { .token = SCMP_ARCH_AARCH64, diff --git a/src/arch-arm.c b/src/arch-arm.c index 732940e..c389815 100644 --- a/src/arch-arm.c +++ b/src/arch-arm.c @@ -25,6 +25,7 @@ #include "arch.h" #include "arch-arm.h" +#include "syscalls.h" #define __SCMP_NR_OABI_SYSCALL_BASE 0x900000 #define __SCMP_ARM_NR_BASE 0x0f0000 @@ -78,6 +79,8 @@ const char *arm_syscall_resolve_num_munge(const struct arch_def *arch, int num) return arch->syscall_resolve_num_raw(num); } +ARCH_DEF(arm) + const struct arch_def arch_def_arm = { .token = SCMP_ARCH_ARM, .token_bpf = AUDIT_ARCH_ARM, diff --git a/src/arch-mips.c b/src/arch-mips.c index 7cc425a..5a12a11 100644 --- a/src/arch-mips.c +++ b/src/arch-mips.c @@ -75,6 +75,8 @@ const char *mips_syscall_resolve_num_raw(int num) return mips_syscall_resolve_num(num); } +ARCH_DEF(mips) + const struct arch_def arch_def_mips = { .token = SCMP_ARCH_MIPS, .token_bpf = AUDIT_ARCH_MIPS, diff --git a/src/arch-mips64.c b/src/arch-mips64.c index d0f72b8..ca7027b 100644 --- a/src/arch-mips64.c +++ b/src/arch-mips64.c @@ -24,6 +24,7 @@ #include "arch.h" #include "arch-mips64.h" +#include "syscalls.h" /* 64 ABI */ #define __SCMP_NR_BASE 5000 @@ -70,6 +71,8 @@ const char *mips64_syscall_resolve_num_munge(const struct arch_def *arch, return arch->syscall_resolve_num_raw(num); } +ARCH_DEF(mips64) + const struct arch_def arch_def_mips64 = { .token = SCMP_ARCH_MIPS64, .token_bpf = AUDIT_ARCH_MIPS64, diff --git a/src/arch-mips64n32.c b/src/arch-mips64n32.c index 532c8f3..c23cfc3 100644 --- a/src/arch-mips64n32.c +++ b/src/arch-mips64n32.c @@ -26,6 +26,7 @@ #include "arch.h" #include "arch-mips64n32.h" +#include "syscalls.h" /* N32 ABI */ #define __SCMP_NR_BASE 6000 @@ -72,6 +73,8 @@ const char *mips64n32_syscall_resolve_num_munge(const struct arch_def *arch, return mips64n32_syscall_resolve_num(num); } +ARCH_DEF(mips64n32) + const struct arch_def arch_def_mips64n32 = { .token = SCMP_ARCH_MIPS64N32, .token_bpf = AUDIT_ARCH_MIPS64N32, diff --git a/src/arch-parisc.c b/src/arch-parisc.c index 4440a04..9a200fe 100644 --- a/src/arch-parisc.c +++ b/src/arch-parisc.c @@ -9,6 +9,9 @@ #include "arch.h" #include "arch-parisc.h" +#include "syscalls.h" + +ARCH_DEF(parisc) const struct arch_def arch_def_parisc = { .token = SCMP_ARCH_PARISC, diff --git a/src/arch-parisc64.c b/src/arch-parisc64.c index d2d85e6..2446407 100644 --- a/src/arch-parisc64.c +++ b/src/arch-parisc64.c @@ -9,6 +9,9 @@ #include "arch.h" #include "arch-parisc64.h" +#include "syscalls.h" + +ARCH_DEF(parisc64) const struct arch_def arch_def_parisc64 = { .token = SCMP_ARCH_PARISC64, diff --git a/src/arch-ppc.c b/src/arch-ppc.c index 0c97bf5..8fdad6f 100644 --- a/src/arch-ppc.c +++ b/src/arch-ppc.c @@ -34,6 +34,8 @@ #define __ppc_NR_socketcall 102 #define __ppc_NR_ipc 117 +ARCH_DEF(ppc) + const struct arch_def arch_def_ppc = { .token = SCMP_ARCH_PPC, .token_bpf = AUDIT_ARCH_PPC, diff --git a/src/arch-ppc64.c b/src/arch-ppc64.c index 27f31a5..a2c88b3 100644 --- a/src/arch-ppc64.c +++ b/src/arch-ppc64.c @@ -34,6 +34,8 @@ #define __ppc64_NR_socketcall 102 #define __ppc64_NR_ipc 117 +ARCH_DEF(ppc64) + const struct arch_def arch_def_ppc64 = { .token = SCMP_ARCH_PPC64, .token_bpf = AUDIT_ARCH_PPC64, diff --git a/src/arch-riscv64.c b/src/arch-riscv64.c index df4f5c8..eb16b1e 100644 --- a/src/arch-riscv64.c +++ b/src/arch-riscv64.c @@ -18,6 +18,9 @@ #include "arch.h" #include "arch-riscv64.h" +#include "syscalls.h" + +ARCH_DEF(riscv64) const struct arch_def arch_def_riscv64 = { .token = SCMP_ARCH_RISCV64, diff --git a/src/arch-s390.c b/src/arch-s390.c index f2c8fda..cbcc769 100644 --- a/src/arch-s390.c +++ b/src/arch-s390.c @@ -17,6 +17,8 @@ #define __s390_NR_socketcall 102 #define __s390_NR_ipc 117 +ARCH_DEF(s390) + const struct arch_def arch_def_s390 = { .token = SCMP_ARCH_S390, .token_bpf = AUDIT_ARCH_S390, diff --git a/src/arch-s390x.c b/src/arch-s390x.c index ddae21b..0f0f619 100644 --- a/src/arch-s390x.c +++ b/src/arch-s390x.c @@ -17,6 +17,8 @@ #define __s390x_NR_socketcall 102 #define __s390x_NR_ipc 117 +ARCH_DEF(s390x) + const struct arch_def arch_def_s390x = { .token = SCMP_ARCH_S390X, .token_bpf = AUDIT_ARCH_S390X, diff --git a/src/arch-x32.c b/src/arch-x32.c index 0a73923..cca6940 100644 --- a/src/arch-x32.c +++ b/src/arch-x32.c @@ -25,6 +25,7 @@ #include "arch.h" #include "arch-x32.h" +#include "syscalls.h" /** * Resolve a syscall name to a number @@ -68,6 +69,8 @@ const char *x32_syscall_resolve_num_munge(const struct arch_def *arch, return arch->syscall_resolve_num_raw(num); } +ARCH_DEF(x32) + const struct arch_def arch_def_x32 = { .token = SCMP_ARCH_X32, /* NOTE: this seems odd but the kernel treats x32 like x86_64 here */ diff --git a/src/arch-x86.c b/src/arch-x86.c index af33137..f086ab0 100644 --- a/src/arch-x86.c +++ b/src/arch-x86.c @@ -33,6 +33,8 @@ #define __x86_NR_socketcall 102 #define __x86_NR_ipc 117 +ARCH_DEF(x86) + const struct arch_def arch_def_x86 = { .token = SCMP_ARCH_X86, .token_bpf = AUDIT_ARCH_I386, diff --git a/src/arch-x86_64.c b/src/arch-x86_64.c index 9c0e5ac..5825612 100644 --- a/src/arch-x86_64.c +++ b/src/arch-x86_64.c @@ -25,6 +25,9 @@ #include "arch.h" #include "arch-x86_64.h" +#include "syscalls.h" + +ARCH_DEF(x86_64) const struct arch_def arch_def_x86_64 = { .token = SCMP_ARCH_X86_64, diff --git a/src/arch.h b/src/arch.h index b6484f9..9816274 100644 --- a/src/arch.h +++ b/src/arch.h @@ -74,6 +74,21 @@ extern const struct arch_def *arch_def_native; const char *NAME##_syscall_resolve_num(int num); \ const struct arch_syscall_def *NAME##_syscall_iterate(unsigned int spot); +/* macro to define the arch specific structures and functions */ +#define ARCH_DEF(NAME) \ + int NAME##_syscall_resolve_name(const char *name) \ + { \ + return syscall_resolve_name(name, OFFSET_ARCH(NAME)); \ + } \ + const char *NAME##_syscall_resolve_num(int num) \ + { \ + return syscall_resolve_num(num, OFFSET_ARCH(NAME)); \ + } \ + const struct arch_syscall_def *NAME##_syscall_iterate(unsigned int spot) \ + { \ + return syscall_iterate(spot, OFFSET_ARCH(NAME)); \ + } + /* syscall name/num mapping */ struct arch_syscall_def { const char *name; diff --git a/src/syscalls.c b/src/syscalls.c index bd6acb5..4e3d0e8 100644 --- a/src/syscalls.c +++ b/src/syscalls.c @@ -29,36 +29,6 @@ #include "arch.h" #include "syscalls.h" -#define ARCH_DEF(NAME) \ - int NAME##_syscall_resolve_name(const char *name) \ - { \ - return syscall_resolve_name(name, OFFSET_ARCH(NAME)); \ - } \ - const char *NAME##_syscall_resolve_num(int num) \ - { \ - return syscall_resolve_num(num, OFFSET_ARCH(NAME)); \ - } \ - const struct arch_syscall_def *NAME##_syscall_iterate(unsigned int spot) \ - { \ - return syscall_iterate(spot, OFFSET_ARCH(NAME)); \ - } - -ARCH_DEF(x86_64) -ARCH_DEF(arm) -ARCH_DEF(aarch64) -ARCH_DEF(mips64n32) -ARCH_DEF(mips64) -ARCH_DEF(mips) -ARCH_DEF(parisc) -ARCH_DEF(parisc64) -ARCH_DEF(ppc64) -ARCH_DEF(ppc) -ARCH_DEF(s390) -ARCH_DEF(s390x) -ARCH_DEF(x32) -ARCH_DEF(x86) -ARCH_DEF(riscv64) - /** * Resolve a syscall name to a number * @param arch the arch definition -- cgit v1.2.1