selftests: sud_test: return correct emulated syscall value on RISC-V
[sfrench/cifs-2.6.git] / tools / testing / selftests / syscall_user_dispatch / sud_test.c
index b5d592d4099e85c6ad9d19d36de055eb27415409..d975a67673299fe7fd617c4568e1c3afca93a96e 100644 (file)
@@ -158,6 +158,20 @@ static void handle_sigsys(int sig, siginfo_t *info, void *ucontext)
 
        /* In preparation for sigreturn. */
        SYSCALL_DISPATCH_OFF(glob_sel);
+
+       /*
+        * The tests for argument handling assume that `syscall(x) == x`. This
+        * is a NOP on x86 because the syscall number is passed in %rax, which
+        * happens to also be the function ABI return register.  Other
+        * architectures may need to swizzle the arguments around.
+        */
+#if defined(__riscv)
+/* REG_A7 is not defined in libc headers */
+# define REG_A7 (REG_A0 + 7)
+
+       ((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A0] =
+                       ((ucontext_t *)ucontext)->uc_mcontext.__gregs[REG_A7];
+#endif
 }
 
 TEST(dispatch_and_return)