xref: /openbmc/linux/arch/arm/include/asm/syscall.h (revision 4697b584)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2bf2c9f98SWade Farnsworth /*
3bf2c9f98SWade Farnsworth  * Access to user system call parameters and results
4bf2c9f98SWade Farnsworth  *
5bf2c9f98SWade Farnsworth  * See asm-generic/syscall.h for descriptions of what we must do here.
6bf2c9f98SWade Farnsworth  */
7bf2c9f98SWade Farnsworth 
8bf2c9f98SWade Farnsworth #ifndef _ASM_ARM_SYSCALL_H
9bf2c9f98SWade Farnsworth #define _ASM_ARM_SYSCALL_H
10bf2c9f98SWade Farnsworth 
11579ec9e1SEric Paris #include <uapi/linux/audit.h> /* for AUDIT_ARCH_* */
121f59d13bSWill Drewry #include <linux/elf.h> /* for ELF_EM */
13bf2c9f98SWade Farnsworth #include <linux/err.h>
148ef102c6SWade Farnsworth #include <linux/sched.h>
15bf2c9f98SWade Farnsworth 
161f66e06fSWade Farnsworth #include <asm/unistd.h>
171f66e06fSWade Farnsworth 
181f66e06fSWade Farnsworth #define NR_syscalls (__NR_syscalls)
191f66e06fSWade Farnsworth 
20bf2c9f98SWade Farnsworth extern const unsigned long sys_call_table[];
21bf2c9f98SWade Farnsworth 
syscall_get_nr(struct task_struct * task,struct pt_regs * regs)22bf2c9f98SWade Farnsworth static inline int syscall_get_nr(struct task_struct *task,
23bf2c9f98SWade Farnsworth 				 struct pt_regs *regs)
24bf2c9f98SWade Farnsworth {
254e57a4ddSArnd Bergmann 	if (IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT))
264e57a4ddSArnd Bergmann 		return task_thread_info(task)->abi_syscall;
274e57a4ddSArnd Bergmann 
28*4697b584SKees Cook 	if (task_thread_info(task)->abi_syscall == -1)
29*4697b584SKees Cook 		return -1;
30*4697b584SKees Cook 
314e57a4ddSArnd Bergmann 	return task_thread_info(task)->abi_syscall & __NR_SYSCALL_MASK;
32bf2c9f98SWade Farnsworth }
33bf2c9f98SWade Farnsworth 
__in_oabi_syscall(struct task_struct * task)34249dbe74SArnd Bergmann static inline bool __in_oabi_syscall(struct task_struct *task)
35249dbe74SArnd Bergmann {
36249dbe74SArnd Bergmann 	return IS_ENABLED(CONFIG_OABI_COMPAT) &&
37249dbe74SArnd Bergmann 		(task_thread_info(task)->abi_syscall & __NR_OABI_SYSCALL_BASE);
38249dbe74SArnd Bergmann }
39249dbe74SArnd Bergmann 
in_oabi_syscall(void)40249dbe74SArnd Bergmann static inline bool in_oabi_syscall(void)
41249dbe74SArnd Bergmann {
42249dbe74SArnd Bergmann 	return __in_oabi_syscall(current);
43249dbe74SArnd Bergmann }
44249dbe74SArnd Bergmann 
syscall_rollback(struct task_struct * task,struct pt_regs * regs)45bf2c9f98SWade Farnsworth static inline void syscall_rollback(struct task_struct *task,
46bf2c9f98SWade Farnsworth 				    struct pt_regs *regs)
47bf2c9f98SWade Farnsworth {
48bf2c9f98SWade Farnsworth 	regs->ARM_r0 = regs->ARM_ORIG_r0;
49bf2c9f98SWade Farnsworth }
50bf2c9f98SWade Farnsworth 
syscall_get_error(struct task_struct * task,struct pt_regs * regs)51bf2c9f98SWade Farnsworth static inline long syscall_get_error(struct task_struct *task,
52bf2c9f98SWade Farnsworth 				     struct pt_regs *regs)
53bf2c9f98SWade Farnsworth {
54bf2c9f98SWade Farnsworth 	unsigned long error = regs->ARM_r0;
55bf2c9f98SWade Farnsworth 	return IS_ERR_VALUE(error) ? error : 0;
56bf2c9f98SWade Farnsworth }
57bf2c9f98SWade Farnsworth 
syscall_get_return_value(struct task_struct * task,struct pt_regs * regs)58bf2c9f98SWade Farnsworth static inline long syscall_get_return_value(struct task_struct *task,
59bf2c9f98SWade Farnsworth 					    struct pt_regs *regs)
60bf2c9f98SWade Farnsworth {
61bf2c9f98SWade Farnsworth 	return regs->ARM_r0;
62bf2c9f98SWade Farnsworth }
63bf2c9f98SWade Farnsworth 
syscall_set_return_value(struct task_struct * task,struct pt_regs * regs,int error,long val)64bf2c9f98SWade Farnsworth static inline void syscall_set_return_value(struct task_struct *task,
65bf2c9f98SWade Farnsworth 					    struct pt_regs *regs,
66bf2c9f98SWade Farnsworth 					    int error, long val)
67bf2c9f98SWade Farnsworth {
68bf2c9f98SWade Farnsworth 	regs->ARM_r0 = (long) error ? error : val;
69bf2c9f98SWade Farnsworth }
70bf2c9f98SWade Farnsworth 
71bf2c9f98SWade Farnsworth #define SYSCALL_MAX_ARGS 7
72bf2c9f98SWade Farnsworth 
syscall_get_arguments(struct task_struct * task,struct pt_regs * regs,unsigned long * args)73bf2c9f98SWade Farnsworth static inline void syscall_get_arguments(struct task_struct *task,
74bf2c9f98SWade Farnsworth 					 struct pt_regs *regs,
75bf2c9f98SWade Farnsworth 					 unsigned long *args)
76bf2c9f98SWade Farnsworth {
77bf2c9f98SWade Farnsworth 	args[0] = regs->ARM_ORIG_r0;
78bf2c9f98SWade Farnsworth 	args++;
79bf2c9f98SWade Farnsworth 
80b35f549dSSteven Rostedt (Red Hat) 	memcpy(args, &regs->ARM_r0 + 1, 5 * sizeof(args[0]));
81bf2c9f98SWade Farnsworth }
82bf2c9f98SWade Farnsworth 
syscall_get_arch(struct task_struct * task)8316add411SDmitry V. Levin static inline int syscall_get_arch(struct task_struct *task)
841f59d13bSWill Drewry {
851f59d13bSWill Drewry 	/* ARM tasks don't change audit architectures on the fly. */
861f59d13bSWill Drewry 	return AUDIT_ARCH_ARM;
871f59d13bSWill Drewry }
881f59d13bSWill Drewry 
89bf2c9f98SWade Farnsworth #endif /* _ASM_ARM_SYSCALL_H */
90