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