1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * syscall_wrapper.h - riscv specific wrappers to syscall definitions 4 * 5 * Based on arch/arm64/include/syscall_wrapper.h 6 */ 7 8 #ifndef __ASM_SYSCALL_WRAPPER_H 9 #define __ASM_SYSCALL_WRAPPER_H 10 11 #include <asm/ptrace.h> 12 13 asmlinkage long __riscv_sys_ni_syscall(const struct pt_regs *); 14 15 #define SC_RISCV_REGS_TO_ARGS(x, ...) \ 16 __MAP(x,__SC_ARGS \ 17 ,,regs->orig_a0,,regs->a1,,regs->a2 \ 18 ,,regs->a3,,regs->a4,,regs->a5,,regs->a6) 19 20 #ifdef CONFIG_COMPAT 21 22 #define COMPAT_SYSCALL_DEFINEx(x, name, ...) \ 23 asmlinkage long __riscv_compat_sys##name(const struct pt_regs *regs); \ 24 ALLOW_ERROR_INJECTION(__riscv_compat_sys##name, ERRNO); \ 25 static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ 26 static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \ 27 asmlinkage long __riscv_compat_sys##name(const struct pt_regs *regs) \ 28 { \ 29 return __se_compat_sys##name(SC_RISCV_REGS_TO_ARGS(x,__VA_ARGS__)); \ 30 } \ 31 static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ 32 { \ 33 return __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \ 34 } \ 35 static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) 36 37 #define COMPAT_SYSCALL_DEFINE0(sname) \ 38 asmlinkage long __riscv_compat_sys_##sname(const struct pt_regs *__unused); \ 39 ALLOW_ERROR_INJECTION(__riscv_compat_sys_##sname, ERRNO); \ 40 asmlinkage long __riscv_compat_sys_##sname(const struct pt_regs *__unused) 41 42 #define COND_SYSCALL_COMPAT(name) \ 43 asmlinkage long __weak __riscv_compat_sys_##name(const struct pt_regs *regs); \ 44 asmlinkage long __weak __riscv_compat_sys_##name(const struct pt_regs *regs) \ 45 { \ 46 return sys_ni_syscall(); \ 47 } 48 49 #endif /* CONFIG_COMPAT */ 50 51 #define __SYSCALL_DEFINEx(x, name, ...) \ 52 asmlinkage long __riscv_sys##name(const struct pt_regs *regs); \ 53 ALLOW_ERROR_INJECTION(__riscv_sys##name, ERRNO); \ 54 static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ 55 static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \ 56 asmlinkage long __riscv_sys##name(const struct pt_regs *regs) \ 57 { \ 58 return __se_sys##name(SC_RISCV_REGS_TO_ARGS(x,__VA_ARGS__)); \ 59 } \ 60 static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ 61 { \ 62 long ret = __do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__)); \ 63 __MAP(x,__SC_TEST,__VA_ARGS__); \ 64 __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \ 65 return ret; \ 66 } \ 67 static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) 68 69 #define SYSCALL_DEFINE0(sname) \ 70 SYSCALL_METADATA(_##sname, 0); \ 71 asmlinkage long __riscv_sys_##sname(const struct pt_regs *__unused); \ 72 ALLOW_ERROR_INJECTION(__riscv_sys_##sname, ERRNO); \ 73 asmlinkage long __riscv_sys_##sname(const struct pt_regs *__unused) 74 75 #define COND_SYSCALL(name) \ 76 asmlinkage long __weak __riscv_sys_##name(const struct pt_regs *regs); \ 77 asmlinkage long __weak __riscv_sys_##name(const struct pt_regs *regs) \ 78 { \ 79 return sys_ni_syscall(); \ 80 } 81 82 #endif /* __ASM_SYSCALL_WRAPPER_H */ 83