diff options
author | Paul Moore <pmoore@redhat.com> | 2016-01-02 17:10:34 -0500 |
---|---|---|
committer | Paul Moore <paul@paul-moore.com> | 2016-02-09 08:32:15 -0500 |
commit | 57df79c166b26d5044e7e27099e6e69671e727dd (patch) | |
tree | a386aa3d1c18f265f311586bda3fca3548f5aa0a /src | |
parent | 9be1538a4ac0e45047a3f1b79691505c3d11ca31 (diff) | |
download | libseccomp-57df79c166b26d5044e7e27099e6e69671e727dd.tar.gz |
arch: make use of function tables instead of switch statements
Signed-off-by: Paul Moore <pmoore@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/arch-aarch64.c | 4 | ||||
-rw-r--r-- | src/arch-arm.c | 4 | ||||
-rw-r--r-- | src/arch-mips.c | 8 | ||||
-rw-r--r-- | src/arch-mips64.c | 8 | ||||
-rw-r--r-- | src/arch-mips64n32.c | 8 | ||||
-rw-r--r-- | src/arch-ppc.c | 4 | ||||
-rw-r--r-- | src/arch-ppc64.c | 8 | ||||
-rw-r--r-- | src/arch-s390.c | 4 | ||||
-rw-r--r-- | src/arch-s390x.c | 4 | ||||
-rw-r--r-- | src/arch-x32.c | 4 | ||||
-rw-r--r-- | src/arch-x86.c | 12 | ||||
-rw-r--r-- | src/arch-x86.h | 5 | ||||
-rw-r--r-- | src/arch-x86_64.c | 4 | ||||
-rw-r--r-- | src/arch.c | 75 | ||||
-rw-r--r-- | src/arch.h | 7 |
15 files changed, 84 insertions, 75 deletions
diff --git a/src/arch-aarch64.c b/src/arch-aarch64.c index a4fbffb..6eb66f5 100644 --- a/src/arch-aarch64.c +++ b/src/arch-aarch64.c @@ -31,4 +31,8 @@ const struct arch_def arch_def_aarch64 = { .token_bpf = AUDIT_ARCH_AARCH64, .size = ARCH_SIZE_64, .endian = ARCH_ENDIAN_LITTLE, + .syscall_resolve_name = aarch64_syscall_resolve_name, + .syscall_resolve_num = aarch64_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; diff --git a/src/arch-arm.c b/src/arch-arm.c index d2f0834..8207986 100644 --- a/src/arch-arm.c +++ b/src/arch-arm.c @@ -31,4 +31,8 @@ const struct arch_def arch_def_arm = { .token_bpf = AUDIT_ARCH_ARM, .size = ARCH_SIZE_32, .endian = ARCH_ENDIAN_LITTLE, + .syscall_resolve_name = arm_syscall_resolve_name, + .syscall_resolve_num = arm_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; diff --git a/src/arch-mips.c b/src/arch-mips.c index 7e88929..3684714 100644 --- a/src/arch-mips.c +++ b/src/arch-mips.c @@ -32,6 +32,10 @@ const struct arch_def arch_def_mips = { .token_bpf = AUDIT_ARCH_MIPS, .size = ARCH_SIZE_32, .endian = ARCH_ENDIAN_BIG, + .syscall_resolve_name = mips_syscall_resolve_name, + .syscall_resolve_num = mips_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; const struct arch_def arch_def_mipsel = { @@ -39,4 +43,8 @@ const struct arch_def arch_def_mipsel = { .token_bpf = AUDIT_ARCH_MIPSEL, .size = ARCH_SIZE_32, .endian = ARCH_ENDIAN_LITTLE, + .syscall_resolve_name = mips_syscall_resolve_name, + .syscall_resolve_num = mips_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; diff --git a/src/arch-mips64.c b/src/arch-mips64.c index b8a33c5..a71864f 100644 --- a/src/arch-mips64.c +++ b/src/arch-mips64.c @@ -30,6 +30,10 @@ const struct arch_def arch_def_mips64 = { .token_bpf = AUDIT_ARCH_MIPS64, .size = ARCH_SIZE_64, .endian = ARCH_ENDIAN_BIG, + .syscall_resolve_name = mips64_syscall_resolve_name, + .syscall_resolve_num = mips64_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; const struct arch_def arch_def_mipsel64 = { @@ -37,4 +41,8 @@ const struct arch_def arch_def_mipsel64 = { .token_bpf = AUDIT_ARCH_MIPSEL64, .size = ARCH_SIZE_64, .endian = ARCH_ENDIAN_LITTLE, + .syscall_resolve_name = mips64_syscall_resolve_name, + .syscall_resolve_num = mips64_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; diff --git a/src/arch-mips64n32.c b/src/arch-mips64n32.c index f00715b..b6a56e1 100644 --- a/src/arch-mips64n32.c +++ b/src/arch-mips64n32.c @@ -32,6 +32,10 @@ const struct arch_def arch_def_mips64n32 = { .token_bpf = AUDIT_ARCH_MIPS64N32, .size = ARCH_SIZE_32, .endian = ARCH_ENDIAN_BIG, + .syscall_resolve_name = mips64n32_syscall_resolve_name, + .syscall_resolve_num = mips64n32_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; const struct arch_def arch_def_mipsel64n32 = { @@ -39,4 +43,8 @@ const struct arch_def arch_def_mipsel64n32 = { .token_bpf = AUDIT_ARCH_MIPSEL64N32, .size = ARCH_SIZE_32, .endian = ARCH_ENDIAN_LITTLE, + .syscall_resolve_name = mips64n32_syscall_resolve_name, + .syscall_resolve_num = mips64n32_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; diff --git a/src/arch-ppc.c b/src/arch-ppc.c index 56dbdb4..058b66b 100644 --- a/src/arch-ppc.c +++ b/src/arch-ppc.c @@ -30,4 +30,8 @@ const struct arch_def arch_def_ppc = { .token_bpf = AUDIT_ARCH_PPC, .size = ARCH_SIZE_32, .endian = ARCH_ENDIAN_BIG, + .syscall_resolve_name = ppc_syscall_resolve_name, + .syscall_resolve_num = ppc_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; diff --git a/src/arch-ppc64.c b/src/arch-ppc64.c index 5f461cb..087e2f3 100644 --- a/src/arch-ppc64.c +++ b/src/arch-ppc64.c @@ -30,6 +30,10 @@ const struct arch_def arch_def_ppc64 = { .token_bpf = AUDIT_ARCH_PPC64, .size = ARCH_SIZE_64, .endian = ARCH_ENDIAN_BIG, + .syscall_resolve_name = ppc64_syscall_resolve_name, + .syscall_resolve_num = ppc64_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; const struct arch_def arch_def_ppc64le = { @@ -37,4 +41,8 @@ const struct arch_def arch_def_ppc64le = { .token_bpf = AUDIT_ARCH_PPC64LE, .size = ARCH_SIZE_64, .endian = ARCH_ENDIAN_LITTLE, + .syscall_resolve_name = ppc64_syscall_resolve_name, + .syscall_resolve_num = ppc64_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; diff --git a/src/arch-s390.c b/src/arch-s390.c index 5aa36fe..31f082a 100644 --- a/src/arch-s390.c +++ b/src/arch-s390.c @@ -15,4 +15,8 @@ const struct arch_def arch_def_s390 = { .token_bpf = AUDIT_ARCH_S390, .size = ARCH_SIZE_32, .endian = ARCH_ENDIAN_BIG, + .syscall_resolve_name = s390_syscall_resolve_name, + .syscall_resolve_num = s390_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; diff --git a/src/arch-s390x.c b/src/arch-s390x.c index 23c711c..0a1fdc8 100644 --- a/src/arch-s390x.c +++ b/src/arch-s390x.c @@ -15,4 +15,8 @@ const struct arch_def arch_def_s390x = { .token_bpf = AUDIT_ARCH_S390X, .size = ARCH_SIZE_64, .endian = ARCH_ENDIAN_BIG, + .syscall_resolve_name = s390x_syscall_resolve_name, + .syscall_resolve_num = s390x_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; diff --git a/src/arch-x32.c b/src/arch-x32.c index 8b5dd97..c64f7b9 100644 --- a/src/arch-x32.c +++ b/src/arch-x32.c @@ -32,4 +32,8 @@ const struct arch_def arch_def_x32 = { .token_bpf = AUDIT_ARCH_X86_64, .size = ARCH_SIZE_32, .endian = ARCH_ENDIAN_LITTLE, + .syscall_resolve_name = x32_syscall_resolve_name, + .syscall_resolve_num = x32_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; diff --git a/src/arch-x86.c b/src/arch-x86.c index 4877b3c..8954ec3 100644 --- a/src/arch-x86.c +++ b/src/arch-x86.c @@ -35,11 +35,14 @@ const struct arch_def arch_def_x86 = { .token_bpf = AUDIT_ARCH_I386, .size = ARCH_SIZE_32, .endian = ARCH_ENDIAN_LITTLE, + .syscall_resolve_name = x86_syscall_resolve_name, + .syscall_resolve_num = x86_syscall_resolve_num, + .syscall_rewrite = x86_syscall_rewrite, + .filter_rewrite = x86_filter_rewrite, }; /** * Rewrite a syscall value to match the architecture - * @param arch the architecture definition * @param syscall the syscall number * * Syscalls can vary across different architectures so this function rewrites @@ -47,7 +50,7 @@ const struct arch_def arch_def_x86 = { * zero on success, negative values on failure. * */ -int x86_syscall_rewrite(const struct arch_def *arch, int *syscall) +int x86_syscall_rewrite(int *syscall) { int sys = *syscall; @@ -75,14 +78,13 @@ int x86_syscall_rewrite(const struct arch_def *arch, int *syscall) * fail. Returns zero on success, negative values on failure. * */ -int x86_filter_rewrite(const struct arch_def *arch, bool strict, - struct db_api_rule_list *rule) +int x86_filter_rewrite(bool strict, struct db_api_rule_list *rule) { int arg_max; unsigned int iter; int sys = rule->syscall; - arg_max = arch_arg_count_max(arch); + arg_max = ARG_COUNT_MAX; if (arg_max < 0) return arg_max; diff --git a/src/arch-x86.h b/src/arch-x86.h index 8460bbe..4f895e0 100644 --- a/src/arch-x86.h +++ b/src/arch-x86.h @@ -35,9 +35,8 @@ const char *x86_syscall_resolve_num(int num); const char *x86_syscall_iterate_name(unsigned int spot); -int x86_syscall_rewrite(const struct arch_def *arch, int *syscall); +int x86_syscall_rewrite(int *syscall); -int x86_filter_rewrite(const struct arch_def *arch, bool strict, - struct db_api_rule_list *rule); +int x86_filter_rewrite(bool strict, struct db_api_rule_list *rule); #endif diff --git a/src/arch-x86_64.c b/src/arch-x86_64.c index 55656c2..b5453b3 100644 --- a/src/arch-x86_64.c +++ b/src/arch-x86_64.c @@ -31,4 +31,8 @@ const struct arch_def arch_def_x86_64 = { .token_bpf = AUDIT_ARCH_X86_64, .size = ARCH_SIZE_64, .endian = ARCH_ENDIAN_LITTLE, + .syscall_resolve_name = x86_64_syscall_resolve_name, + .syscall_resolve_num = x86_64_syscall_resolve_num, + .syscall_rewrite = NULL, + .filter_rewrite = NULL, }; @@ -292,36 +292,8 @@ int arch_arg_offset(const struct arch_def *arch, unsigned int arg) */ int arch_syscall_resolve_name(const struct arch_def *arch, const char *name) { - switch (arch->token) { - case SCMP_ARCH_X86: - return x86_syscall_resolve_name(name); - case SCMP_ARCH_X86_64: - return x86_64_syscall_resolve_name(name); - case SCMP_ARCH_X32: - return x32_syscall_resolve_name(name); - case SCMP_ARCH_ARM: - return arm_syscall_resolve_name(name); - case SCMP_ARCH_AARCH64: - return aarch64_syscall_resolve_name(name); - case SCMP_ARCH_MIPS: - case SCMP_ARCH_MIPSEL: - return mips_syscall_resolve_name(name); - case SCMP_ARCH_MIPS64: - case SCMP_ARCH_MIPSEL64: - return mips64_syscall_resolve_name(name); - case SCMP_ARCH_MIPS64N32: - case SCMP_ARCH_MIPSEL64N32: - return mips64n32_syscall_resolve_name(name); - case SCMP_ARCH_PPC: - return ppc_syscall_resolve_name(name); - case SCMP_ARCH_PPC64: - case SCMP_ARCH_PPC64LE: - return ppc64_syscall_resolve_name(name); - case SCMP_ARCH_S390: - return s390_syscall_resolve_name(name); - case SCMP_ARCH_S390X: - return s390x_syscall_resolve_name(name); - } + if (arch->syscall_resolve_name) + return (*arch->syscall_resolve_name)(name); return __NR_SCMP_ERROR; } @@ -338,36 +310,8 @@ int arch_syscall_resolve_name(const struct arch_def *arch, const char *name) */ const char *arch_syscall_resolve_num(const struct arch_def *arch, int num) { - switch (arch->token) { - case SCMP_ARCH_X86: - return x86_syscall_resolve_num(num); - case SCMP_ARCH_X86_64: - return x86_64_syscall_resolve_num(num); - case SCMP_ARCH_X32: - return x32_syscall_resolve_num(num); - case SCMP_ARCH_ARM: - return arm_syscall_resolve_num(num); - case SCMP_ARCH_AARCH64: - return aarch64_syscall_resolve_num(num); - case SCMP_ARCH_MIPS: - case SCMP_ARCH_MIPSEL: - return mips_syscall_resolve_num(num); - case SCMP_ARCH_MIPS64: - case SCMP_ARCH_MIPSEL64: - return mips64_syscall_resolve_num(num); - case SCMP_ARCH_MIPS64N32: - case SCMP_ARCH_MIPSEL64N32: - return mips64n32_syscall_resolve_num(num); - case SCMP_ARCH_PPC: - return ppc_syscall_resolve_num(num); - case SCMP_ARCH_PPC64: - case SCMP_ARCH_PPC64LE: - return ppc64_syscall_resolve_num(num); - case SCMP_ARCH_S390: - return s390_syscall_resolve_num(num); - case SCMP_ARCH_S390X: - return s390x_syscall_resolve_num(num); - } + if (arch->syscall_resolve_num) + return (*arch->syscall_resolve_num)(num); return NULL; } @@ -425,10 +369,8 @@ int arch_syscall_rewrite(const struct arch_def *arch, int *syscall) return -EINVAL; } else if (sys <= -100 && sys > -10000) { /* rewritable syscalls */ - switch (arch->token) { - case SCMP_ARCH_X86: - x86_syscall_rewrite(arch, syscall); - } + if (arch->syscall_rewrite) + (*arch->syscall_rewrite)(syscall); } /* syscalls not defined on this architecture */ @@ -466,9 +408,8 @@ int arch_filter_rewrite(const struct arch_def *arch, bool strict, return -EINVAL; } else if (sys <= -100 && sys > -10000) { /* rewritable syscalls */ - switch (arch->token) { - case SCMP_ARCH_X86: - rc = x86_filter_rewrite(arch, strict, rule); + if (arch->filter_rewrite) { + rc = (*arch->filter_rewrite)(strict, rule); /* we still want to catch invalid rewrites */ if (rc == -EINVAL) return -EINVAL; @@ -33,6 +33,7 @@ struct db_api_rule_list; struct arch_def { + /* arch definition */ uint32_t token; uint32_t token_bpf; enum { @@ -45,6 +46,12 @@ struct arch_def { ARCH_ENDIAN_LITTLE, ARCH_ENDIAN_BIG, } endian; + + /* arch specific functions */ + int (*syscall_resolve_name)(const char *name); + const char *(*syscall_resolve_num)(int num); + int (*syscall_rewrite)(int *syscall); + int (*filter_rewrite)(bool strict, struct db_api_rule_list *rule); }; /* arch_def for the current architecture */ |