Skip to content

Commit 768877b

Browse files
committed
selftests/seccomp: add xtensa support
Xtensa syscall number can be obtained and changed through the struct user_pt_regs. Syscall return value register is fixed relatively to the current register window in the user_pt_regs, so it needs a bit of special treatment. Signed-off-by: Max Filippov <[email protected]>
1 parent da94a40 commit 768877b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ struct seccomp_data {
122122
# define __NR_seccomp 358
123123
# elif defined(__s390__)
124124
# define __NR_seccomp 348
125+
# elif defined(__xtensa__)
126+
# define __NR_seccomp 337
125127
# else
126128
# warning "seccomp syscall number unknown for this architecture"
127129
# define __NR_seccomp 0xffff
@@ -1622,6 +1624,14 @@ TEST_F(TRACE_poke, getpid_runs_normally)
16221624
# define SYSCALL_SYSCALL_NUM regs[4]
16231625
# define SYSCALL_RET regs[2]
16241626
# define SYSCALL_NUM_RET_SHARE_REG
1627+
#elif defined(__xtensa__)
1628+
# define ARCH_REGS struct user_pt_regs
1629+
# define SYSCALL_NUM syscall
1630+
/*
1631+
* On xtensa syscall return value is in the register
1632+
* a2 of the current window which is not fixed.
1633+
*/
1634+
#define SYSCALL_RET(reg) a[(reg).windowbase * 4 + 2]
16251635
#else
16261636
# error "Do not know how to find your architecture's registers and syscalls"
16271637
#endif
@@ -1693,7 +1703,8 @@ void change_syscall(struct __test_metadata *_metadata,
16931703
EXPECT_EQ(0, ret) {}
16941704

16951705
#if defined(__x86_64__) || defined(__i386__) || defined(__powerpc__) || \
1696-
defined(__s390__) || defined(__hppa__) || defined(__riscv)
1706+
defined(__s390__) || defined(__hppa__) || defined(__riscv) || \
1707+
defined(__xtensa__)
16971708
{
16981709
regs.SYSCALL_NUM = syscall;
16991710
}
@@ -1736,6 +1747,9 @@ void change_syscall(struct __test_metadata *_metadata,
17361747
if (syscall == -1)
17371748
#ifdef SYSCALL_NUM_RET_SHARE_REG
17381749
TH_LOG("Can't modify syscall return on this architecture");
1750+
1751+
#elif defined(__xtensa__)
1752+
regs.SYSCALL_RET(regs) = result;
17391753
#else
17401754
regs.SYSCALL_RET = result;
17411755
#endif

0 commit comments

Comments
 (0)