Skip to content

Commit 17c67ed

Browse files
clementlegerpalmer-dabbelt
authored andcommitted
selftests: sud_test: return correct emulated syscall value on RISC-V
Currently, the sud_test expects the emulated syscall to return the emulated syscall number. This assumption only works on architectures were the syscall calling convention use the same register for syscall number/syscall return value. This is not the case for RISC-V and thus the return value must be also emulated using the provided ucontext. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Palmer Dabbelt <[email protected]> Acked-by: Palmer Dabbelt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 5ea6764 commit 17c67ed

File tree

1 file changed

+14
-0
lines changed
  • tools/testing/selftests/syscall_user_dispatch

1 file changed

+14
-0
lines changed

tools/testing/selftests/syscall_user_dispatch/sud_test.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ static void handle_sigsys(int sig, siginfo_t *info, void *ucontext)
158158

159159
/* In preparation for sigreturn. */
160160
SYSCALL_DISPATCH_OFF(glob_sel);
161+
162+
/*
163+
* The tests for argument handling assume that `syscall(x) == x`. This
164+
* is a NOP on x86 because the syscall number is passed in %rax, which
165+
* happens to also be the function ABI return register. Other
166+
* architectures may need to swizzle the arguments around.
167+
*/
168+
#if defined(__riscv)
169+
/* REG_A7 is not defined in libc headers */
170+
# define REG_A7 (REG_A0 + 7)
171+
172+
((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A0] =
173+
((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A7];
174+
#endif
161175
}
162176

163177
TEST(dispatch_and_return)

0 commit comments

Comments
 (0)