summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2020-09-12 04:08:07 -0700
committerKees Cook <keescook@chromium.org>2020-09-19 00:59:29 -0700
commit31c36eb87c85b6de0f341b1184f90137106a9f81 (patch)
tree2a7d8732ff23d3875e5ae39e2c2bfb8481090825 /tools
parenta6a4d78419a04095221ec2b518edefb080218d55 (diff)
downloadlinux-stable-31c36eb87c85b6de0f341b1184f90137106a9f81.tar.gz
linux-stable-31c36eb87c85b6de0f341b1184f90137106a9f81.tar.bz2
linux-stable-31c36eb87c85b6de0f341b1184f90137106a9f81.zip
selftests/seccomp: Provide generic syscall setting macro
In order to avoid "#ifdef"s in the main function bodies, create a new macro, SYSCALL_NUM_SET(), where arch-specific logic can live. Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/lkml/20200912110820.597135-3-keescook@chromium.org Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/seccomp/seccomp_bpf.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index a261643db4b8..c44abe7c6a3c 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -1760,6 +1760,17 @@ TEST_F(TRACE_poke, getpid_runs_normally)
# error "Do not know how to find your architecture's registers and syscalls"
#endif
+/*
+ * Most architectures can change the syscall by just updating the
+ * associated register. This is the default if not defined above.
+ */
+#ifndef SYSCALL_NUM_SET
+# define SYSCALL_NUM_SET(_regs, _nr) \
+ do { \
+ SYSCALL_NUM(_regs) = (_nr); \
+ } while (0)
+#endif
+
/* When the syscall return can't be changed, stub out the tests for it. */
#ifdef SYSCALL_NUM_RET_SHARE_REG
# define EXPECT_SYSCALL_RETURN(val, action) EXPECT_EQ(-1, action)
@@ -1830,14 +1841,14 @@ void change_syscall(struct __test_metadata *_metadata,
defined(__s390__) || defined(__hppa__) || defined(__riscv) || \
defined(__xtensa__) || defined(__csky__) || defined(__sh__)
{
- SYSCALL_NUM(regs) = syscall;
+ SYSCALL_NUM_SET(regs, syscall);
}
#elif defined(__mips__)
{
if (SYSCALL_NUM(regs) == __NR_O32_Linux)
regs.SYSCALL_SYSCALL_NUM = syscall;
else
- SYSCALL_NUM(regs) = syscall;
+ SYSCALL_NUM_SET(regs, syscall);
}
#elif defined(__arm__)