xref: /linux/arch/riscv/include/asm/syscall_wrapper.h (revision fd7d598270724cc787982ea48bbe17ad383a8b7f)
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 #define COMPAT_SYS_NI(name) \
50 	SYSCALL_ALIAS(__riscv_compat_sys_##name, sys_ni_posix_timers);
51 
52 #endif /* CONFIG_COMPAT */
53 
54 #define __SYSCALL_DEFINEx(x, name, ...)						\
55 	asmlinkage long __riscv_sys##name(const struct pt_regs *regs);		\
56 	ALLOW_ERROR_INJECTION(__riscv_sys##name, ERRNO);			\
57 	static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__));		\
58 	static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));	\
59 	asmlinkage long __riscv_sys##name(const struct pt_regs *regs)		\
60 	{									\
61 		return __se_sys##name(SC_RISCV_REGS_TO_ARGS(x,__VA_ARGS__));	\
62 	}									\
63 	static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))		\
64 	{									\
65 		long ret = __do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__));	\
66 		__MAP(x,__SC_TEST,__VA_ARGS__);					\
67 		__PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__));		\
68 		return ret;							\
69 	}									\
70 	static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
71 
72 #define SYSCALL_DEFINE0(sname)							\
73 	SYSCALL_METADATA(_##sname, 0);						\
74 	asmlinkage long __riscv_sys_##sname(const struct pt_regs *__unused);	\
75 	ALLOW_ERROR_INJECTION(__riscv_sys_##sname, ERRNO);			\
76 	asmlinkage long __riscv_sys_##sname(const struct pt_regs *__unused)
77 
78 #define COND_SYSCALL(name)							\
79 	asmlinkage long __weak __riscv_sys_##name(const struct pt_regs *regs);	\
80 	asmlinkage long __weak __riscv_sys_##name(const struct pt_regs *regs)	\
81 	{									\
82 		return sys_ni_syscall();					\
83 	}
84 
85 #define SYS_NI(name) SYSCALL_ALIAS(__riscv_sys_##name, sys_ni_posix_timers);
86 
87 #endif /* __ASM_SYSCALL_WRAPPER_H */
88