162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * syscall_wrapper.h - arm64 specific wrappers to syscall definitions
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Based on arch/x86/include/asm_syscall_wrapper.h
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef __ASM_SYSCALL_WRAPPER_H
962306a36Sopenharmony_ci#define __ASM_SYSCALL_WRAPPER_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <asm/ptrace.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#define SC_ARM64_REGS_TO_ARGS(x, ...)				\
1462306a36Sopenharmony_ci	__MAP(x,__SC_ARGS					\
1562306a36Sopenharmony_ci	      ,,regs->regs[0],,regs->regs[1],,regs->regs[2]	\
1662306a36Sopenharmony_ci	      ,,regs->regs[3],,regs->regs[4],,regs->regs[5])
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#ifdef CONFIG_COMPAT
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#define COMPAT_SYSCALL_DEFINEx(x, name, ...)						\
2162306a36Sopenharmony_ci	asmlinkage long __arm64_compat_sys##name(const struct pt_regs *regs);		\
2262306a36Sopenharmony_ci	ALLOW_ERROR_INJECTION(__arm64_compat_sys##name, ERRNO);				\
2362306a36Sopenharmony_ci	static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__));		\
2462306a36Sopenharmony_ci	static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));	\
2562306a36Sopenharmony_ci	asmlinkage long __arm64_compat_sys##name(const struct pt_regs *regs)		\
2662306a36Sopenharmony_ci	{										\
2762306a36Sopenharmony_ci		return __se_compat_sys##name(SC_ARM64_REGS_TO_ARGS(x,__VA_ARGS__));	\
2862306a36Sopenharmony_ci	}										\
2962306a36Sopenharmony_ci	static long __se_compat_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))		\
3062306a36Sopenharmony_ci	{										\
3162306a36Sopenharmony_ci		return __do_compat_sys##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__));	\
3262306a36Sopenharmony_ci	}										\
3362306a36Sopenharmony_ci	static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define COMPAT_SYSCALL_DEFINE0(sname)							\
3662306a36Sopenharmony_ci	asmlinkage long __arm64_compat_sys_##sname(const struct pt_regs *__unused);	\
3762306a36Sopenharmony_ci	ALLOW_ERROR_INJECTION(__arm64_compat_sys_##sname, ERRNO);			\
3862306a36Sopenharmony_ci	asmlinkage long __arm64_compat_sys_##sname(const struct pt_regs *__unused)
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci#define COND_SYSCALL_COMPAT(name) 							\
4162306a36Sopenharmony_ci	asmlinkage long __arm64_compat_sys_##name(const struct pt_regs *regs);		\
4262306a36Sopenharmony_ci	asmlinkage long __weak __arm64_compat_sys_##name(const struct pt_regs *regs)	\
4362306a36Sopenharmony_ci	{										\
4462306a36Sopenharmony_ci		return sys_ni_syscall();						\
4562306a36Sopenharmony_ci	}
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#endif /* CONFIG_COMPAT */
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define __SYSCALL_DEFINEx(x, name, ...)						\
5062306a36Sopenharmony_ci	asmlinkage long __arm64_sys##name(const struct pt_regs *regs);		\
5162306a36Sopenharmony_ci	ALLOW_ERROR_INJECTION(__arm64_sys##name, ERRNO);			\
5262306a36Sopenharmony_ci	static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__));		\
5362306a36Sopenharmony_ci	static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));	\
5462306a36Sopenharmony_ci	asmlinkage long __arm64_sys##name(const struct pt_regs *regs);		\
5562306a36Sopenharmony_ci	asmlinkage long __arm64_sys##name(const struct pt_regs *regs)		\
5662306a36Sopenharmony_ci	{									\
5762306a36Sopenharmony_ci		return __se_sys##name(SC_ARM64_REGS_TO_ARGS(x,__VA_ARGS__));	\
5862306a36Sopenharmony_ci	}									\
5962306a36Sopenharmony_ci	static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))		\
6062306a36Sopenharmony_ci	{									\
6162306a36Sopenharmony_ci		long ret = __do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__));	\
6262306a36Sopenharmony_ci		__MAP(x,__SC_TEST,__VA_ARGS__);					\
6362306a36Sopenharmony_ci		__PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__));		\
6462306a36Sopenharmony_ci		return ret;							\
6562306a36Sopenharmony_ci	}									\
6662306a36Sopenharmony_ci	static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define SYSCALL_DEFINE0(sname)							\
6962306a36Sopenharmony_ci	SYSCALL_METADATA(_##sname, 0);						\
7062306a36Sopenharmony_ci	asmlinkage long __arm64_sys_##sname(const struct pt_regs *__unused);	\
7162306a36Sopenharmony_ci	ALLOW_ERROR_INJECTION(__arm64_sys_##sname, ERRNO);			\
7262306a36Sopenharmony_ci	asmlinkage long __arm64_sys_##sname(const struct pt_regs *__unused)
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define COND_SYSCALL(name)							\
7562306a36Sopenharmony_ci	asmlinkage long __arm64_sys_##name(const struct pt_regs *regs);		\
7662306a36Sopenharmony_ci	asmlinkage long __weak __arm64_sys_##name(const struct pt_regs *regs)	\
7762306a36Sopenharmony_ci	{									\
7862306a36Sopenharmony_ci		return sys_ni_syscall();					\
7962306a36Sopenharmony_ci	}
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ciasmlinkage long __arm64_sys_ni_syscall(const struct pt_regs *__unused);
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#endif /* __ASM_SYSCALL_WRAPPER_H */
84