From 29e3f73784f6415ff1de21462390d8d0d3e5b3d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 22 May 2023 17:25:15 +0200 Subject: [PATCH] enosys: split audit arch detection into dedicated header MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Weißschuh --- include/Makemodule.am | 1 + include/audit-arch.h | 58 +++++++++++++++++++++++++++++++++++++++++++ misc-utils/enosys.c | 49 +----------------------------------- 3 files changed, 60 insertions(+), 48 deletions(-) create mode 100644 include/audit-arch.h diff --git a/include/Makemodule.am b/include/Makemodule.am index 7c6a7587f6..068b0f8e80 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -1,6 +1,7 @@ dist_noinst_HEADERS += \ include/all-io.h \ + include/audit-arch.h \ include/bitops.h \ include/blkdev.h \ include/buffer.h \ diff --git a/include/audit-arch.h b/include/audit-arch.h new file mode 100644 index 0000000000..9760f2e833 --- /dev/null +++ b/include/audit-arch.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2023 Thomas Weißschuh + * + * This file may be distributed under the terms of the + * GNU Lesser General Public License. + */ +#ifndef UTIL_LINUX_AUDIT_ARCH_H +#define UTIL_LINUX_AUDIT_ARCH_H + +#if __x86_64__ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_X86_64 +#elif __i386__ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_I386 +#elif __arm__ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_ARM +#elif __aarch64__ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_AARCH64 +#elif __riscv +# if __riscv_xlen == 32 +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_RISCV32 +# elif __riscv_xlen == 64 +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_RISCV64 +# endif +#elif __s390x__ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_S390X +#elif __s390__ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_S390 +#elif __PPC64__ +# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_PPC64 +# else +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_PPC64LE +# endif +#elif __powerpc__ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_PPC +#elif __mips__ +# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_MIPS +# else +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_MIPSEL +# endif +#elif __arc__ +# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_ARCV2BE +# else +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_ARCV2 +# endif +#elif __sparc__ +# if __SIZEOF_POINTER__ == 4 +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_SPARC +# else +# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_SPARC64 +# endif +#else +# error Unknown target architecture +#endif + +#endif /* UTIL_LINUX_AUDIT_ARCH_H */ diff --git a/misc-utils/enosys.c b/misc-utils/enosys.c index 7372f29c66..ec02f454f6 100644 --- a/misc-utils/enosys.c +++ b/misc-utils/enosys.c @@ -31,54 +31,7 @@ #include "exitcodes.h" #include "nls.h" #include "bitops.h" - -#if __x86_64__ -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_X86_64 -#elif __i386__ -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_I386 -#elif __arm__ -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_ARM -#elif __aarch64__ -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_AARCH64 -#elif __riscv -# if __riscv_xlen == 32 -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_RISCV32 -# elif __riscv_xlen == 64 -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_RISCV64 -# endif -#elif __s390x__ -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_S390X -#elif __s390__ -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_S390 -#elif __PPC64__ -# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_PPC64 -# else -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_PPC64LE -# endif -#elif __powerpc__ -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_PPC -#elif __mips__ -# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_MIPS -# else -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_MIPSEL -# endif -#elif __arc__ -# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_ARCV2BE -# else -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_ARCV2 -# endif -#elif __sparc__ -# if __SIZEOF_POINTER__ == 4 -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_SPARC -# else -# define SECCOMP_ARCH_NATIVE AUDIT_ARCH_SPARC64 -# endif -#else -# error Unknown target architecture -#endif +#include "audit-arch.h" #define UL_BPF_NOP (struct sock_filter) BPF_JUMP(BPF_JMP | BPF_JA, 0, 0, 0) #define IS_LITTLE_ENDIAN (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) -- 2.47.3