Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <cleger@rivosinc.com>
Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
Link: https://lore.kernel.org/r/20231206134438.473166-1-cleger@rivosinc.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>

authored by

Clément Léger and committed by
Palmer Dabbelt
17c67ed7 5ea6764d

+14
+14
tools/testing/selftests/syscall_user_dispatch/sud_test.c
··· 158 158 159 159 /* In preparation for sigreturn. */ 160 160 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 161 175 } 162 176 163 177 TEST(dispatch_and_return)