18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * syscall_wrapper.h - s390 specific wrappers to syscall definitions
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _ASM_S390_SYSCALL_WRAPPER_H
88c2ecf20Sopenharmony_ci#define _ASM_S390_SYSCALL_WRAPPER_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifdef CONFIG_COMPAT
118c2ecf20Sopenharmony_ci#define __SC_COMPAT_TYPE(t, a) \
128c2ecf20Sopenharmony_ci	__typeof(__builtin_choose_expr(sizeof(t) > 4, 0L, (t)0)) a
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define __SC_COMPAT_CAST(t, a)						\
158c2ecf20Sopenharmony_ci({									\
168c2ecf20Sopenharmony_ci	long __ReS = a;							\
178c2ecf20Sopenharmony_ci									\
188c2ecf20Sopenharmony_ci	BUILD_BUG_ON((sizeof(t) > 4) && !__TYPE_IS_L(t) &&		\
198c2ecf20Sopenharmony_ci		     !__TYPE_IS_UL(t) && !__TYPE_IS_PTR(t) &&		\
208c2ecf20Sopenharmony_ci		     !__TYPE_IS_LL(t));					\
218c2ecf20Sopenharmony_ci	if (__TYPE_IS_L(t))						\
228c2ecf20Sopenharmony_ci		__ReS = (s32)a;						\
238c2ecf20Sopenharmony_ci	if (__TYPE_IS_UL(t))						\
248c2ecf20Sopenharmony_ci		__ReS = (u32)a;						\
258c2ecf20Sopenharmony_ci	if (__TYPE_IS_PTR(t))						\
268c2ecf20Sopenharmony_ci		__ReS = a & 0x7fffffff;					\
278c2ecf20Sopenharmony_ci	if (__TYPE_IS_LL(t))						\
288c2ecf20Sopenharmony_ci		return -ENOSYS;						\
298c2ecf20Sopenharmony_ci	(t)__ReS;							\
308c2ecf20Sopenharmony_ci})
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define __S390_SYS_STUBx(x, name, ...)					\
338c2ecf20Sopenharmony_ci	asmlinkage long __s390_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__));\
348c2ecf20Sopenharmony_ci	ALLOW_ERROR_INJECTION(__s390_sys##name, ERRNO);			\
358c2ecf20Sopenharmony_ci	asmlinkage long __s390_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))\
368c2ecf20Sopenharmony_ci	{								\
378c2ecf20Sopenharmony_ci		long ret = __s390x_sys##name(__MAP(x,__SC_COMPAT_CAST,__VA_ARGS__));\
388c2ecf20Sopenharmony_ci		__MAP(x,__SC_TEST,__VA_ARGS__);				\
398c2ecf20Sopenharmony_ci		return ret;						\
408c2ecf20Sopenharmony_ci	}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci/*
438c2ecf20Sopenharmony_ci * To keep the naming coherent, re-define SYSCALL_DEFINE0 to create an alias
448c2ecf20Sopenharmony_ci * named __s390x_sys_*()
458c2ecf20Sopenharmony_ci */
468c2ecf20Sopenharmony_ci#define COMPAT_SYSCALL_DEFINE0(sname)					\
478c2ecf20Sopenharmony_ci	SYSCALL_METADATA(_##sname, 0);					\
488c2ecf20Sopenharmony_ci	asmlinkage long __s390_compat_sys_##sname(void);		\
498c2ecf20Sopenharmony_ci	ALLOW_ERROR_INJECTION(__s390_compat_sys_##sname, ERRNO);	\
508c2ecf20Sopenharmony_ci	asmlinkage long __s390_compat_sys_##sname(void)
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define SYSCALL_DEFINE0(sname)						\
538c2ecf20Sopenharmony_ci	SYSCALL_METADATA(_##sname, 0);					\
548c2ecf20Sopenharmony_ci	asmlinkage long __s390x_sys_##sname(void);			\
558c2ecf20Sopenharmony_ci	ALLOW_ERROR_INJECTION(__s390x_sys_##sname, ERRNO);		\
568c2ecf20Sopenharmony_ci	asmlinkage long __s390_sys_##sname(void)			\
578c2ecf20Sopenharmony_ci		__attribute__((alias(__stringify(__s390x_sys_##sname)))); \
588c2ecf20Sopenharmony_ci	asmlinkage long __s390x_sys_##sname(void)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define COND_SYSCALL(name)						\
618c2ecf20Sopenharmony_ci	cond_syscall(__s390x_sys_##name);				\
628c2ecf20Sopenharmony_ci	cond_syscall(__s390_sys_##name)
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define SYS_NI(name)							\
658c2ecf20Sopenharmony_ci	SYSCALL_ALIAS(__s390x_sys_##name, sys_ni_posix_timers);		\
668c2ecf20Sopenharmony_ci	SYSCALL_ALIAS(__s390_sys_##name, sys_ni_posix_timers)
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define COMPAT_SYSCALL_DEFINEx(x, name, ...)					\
698c2ecf20Sopenharmony_ci	__diag_push();								\
708c2ecf20Sopenharmony_ci	__diag_ignore(GCC, 8, "-Wattribute-alias",				\
718c2ecf20Sopenharmony_ci		      "Type aliasing is used to sanitize syscall arguments");\
728c2ecf20Sopenharmony_ci	asmlinkage long __s390_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));	\
738c2ecf20Sopenharmony_ci	asmlinkage long __s390_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))	\
748c2ecf20Sopenharmony_ci		__attribute__((alias(__stringify(__se_compat_sys##name))));	\
758c2ecf20Sopenharmony_ci	ALLOW_ERROR_INJECTION(__s390_compat_sys##name, ERRNO);			\
768c2ecf20Sopenharmony_ci	static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
778c2ecf20Sopenharmony_ci	asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__));	\
788c2ecf20Sopenharmony_ci	asmlinkage long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))	\
798c2ecf20Sopenharmony_ci	{									\
808c2ecf20Sopenharmony_ci		long ret = __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));\
818c2ecf20Sopenharmony_ci		__MAP(x,__SC_TEST,__VA_ARGS__);					\
828c2ecf20Sopenharmony_ci		return ret;							\
838c2ecf20Sopenharmony_ci	}									\
848c2ecf20Sopenharmony_ci	__diag_pop();								\
858c2ecf20Sopenharmony_ci	static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/*
888c2ecf20Sopenharmony_ci * As some compat syscalls may not be implemented, we need to expand
898c2ecf20Sopenharmony_ci * COND_SYSCALL_COMPAT in kernel/sys_ni.c and COMPAT_SYS_NI in
908c2ecf20Sopenharmony_ci * kernel/time/posix-stubs.c to cover this case as well.
918c2ecf20Sopenharmony_ci */
928c2ecf20Sopenharmony_ci#define COND_SYSCALL_COMPAT(name)					\
938c2ecf20Sopenharmony_ci	cond_syscall(__s390_compat_sys_##name)
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define COMPAT_SYS_NI(name)						\
968c2ecf20Sopenharmony_ci	SYSCALL_ALIAS(__s390_compat_sys_##name, sys_ni_posix_timers)
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#else /* CONFIG_COMPAT */
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define __S390_SYS_STUBx(x, fullname, name, ...)
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#define SYSCALL_DEFINE0(sname)						\
1038c2ecf20Sopenharmony_ci	SYSCALL_METADATA(_##sname, 0);					\
1048c2ecf20Sopenharmony_ci	asmlinkage long __s390x_sys_##sname(void);			\
1058c2ecf20Sopenharmony_ci	ALLOW_ERROR_INJECTION(__s390x_sys_##sname, ERRNO);		\
1068c2ecf20Sopenharmony_ci	asmlinkage long __s390x_sys_##sname(void)
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define COND_SYSCALL(name)						\
1098c2ecf20Sopenharmony_ci	cond_syscall(__s390x_sys_##name)
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#define SYS_NI(name)							\
1128c2ecf20Sopenharmony_ci	SYSCALL_ALIAS(__s390x_sys_##name, sys_ni_posix_timers);
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#endif /* CONFIG_COMPAT */
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define __SYSCALL_DEFINEx(x, name, ...)						\
1178c2ecf20Sopenharmony_ci	__diag_push();								\
1188c2ecf20Sopenharmony_ci	__diag_ignore(GCC, 8, "-Wattribute-alias",				\
1198c2ecf20Sopenharmony_ci		      "Type aliasing is used to sanitize syscall arguments");\
1208c2ecf20Sopenharmony_ci	asmlinkage long __s390x_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))	\
1218c2ecf20Sopenharmony_ci		__attribute__((alias(__stringify(__se_sys##name))));		\
1228c2ecf20Sopenharmony_ci	ALLOW_ERROR_INJECTION(__s390x_sys##name, ERRNO);			\
1238c2ecf20Sopenharmony_ci	long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__));			\
1248c2ecf20Sopenharmony_ci	static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));	\
1258c2ecf20Sopenharmony_ci	__S390_SYS_STUBx(x, name, __VA_ARGS__)					\
1268c2ecf20Sopenharmony_ci	asmlinkage long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))		\
1278c2ecf20Sopenharmony_ci	{									\
1288c2ecf20Sopenharmony_ci		long ret = __do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__));	\
1298c2ecf20Sopenharmony_ci		__MAP(x,__SC_TEST,__VA_ARGS__);					\
1308c2ecf20Sopenharmony_ci		return ret;							\
1318c2ecf20Sopenharmony_ci	}									\
1328c2ecf20Sopenharmony_ci	__diag_pop();								\
1338c2ecf20Sopenharmony_ci	static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#endif /* _ASM_X86_SYSCALL_WRAPPER_H */
136