1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Access to user system call parameters and results 4 * 5 * Copyright IBM Corp. 2008 6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) 7 */ 8 9 #ifndef _ASM_SYSCALL_H 10 #define _ASM_SYSCALL_H 1 11 12 #include <uapi/linux/audit.h> 13 #include <linux/sched.h> 14 #include <linux/err.h> 15 #include <asm/ptrace.h> 16 17 /* 18 * The syscall table always contains 32 bit pointers since we know that the 19 * address of the function to be called is (way) below 4GB. So the "int" 20 * type here is what we want [need] for both 32 bit and 64 bit systems. 21 */ 22 extern const unsigned int sys_call_table[]; 23 extern const unsigned int sys_call_table_emu[]; 24 25 static inline long syscall_get_nr(struct task_struct *task, 26 struct pt_regs *regs) 27 { 28 return test_pt_regs_flag(regs, PIF_SYSCALL) ? 29 (regs->int_code & 0xffff) : -1; 30 } 31 32 static inline void syscall_rollback(struct task_struct *task, 33 struct pt_regs *regs) 34 { 35 regs->gprs[2] = regs->orig_gpr2; 36 } 37 38 static inline long syscall_get_error(struct task_struct *task, 39 struct pt_regs *regs) 40 { 41 return IS_ERR_VALUE(regs->gprs[2]) ? regs->gprs[2] : 0; 42 } 43 44 static inline long syscall_get_return_value(struct task_struct *task, 45 struct pt_regs *regs) 46 { 47 return regs->gprs[2]; 48 } 49 50 static inline void syscall_set_return_value(struct task_struct *task, 51 struct pt_regs *regs, 52 int error, long val) 53 { 54 regs->gprs[2] = error ? error : val; 55 } 56 57 static inline void syscall_get_arguments(struct task_struct *task, 58 struct pt_regs *regs, 59 unsigned int i, unsigned int n, 60 unsigned long *args) 61 { 62 unsigned long mask = -1UL; 63 64 /* 65 * No arguments for this syscall, there's nothing to do. 66 */ 67 if (!n) 68 return; 69 70 BUG_ON(i + n > 6); 71 #ifdef CONFIG_COMPAT 72 if (test_tsk_thread_flag(task, TIF_31BIT)) 73 mask = 0xffffffff; 74 #endif 75 while (n-- > 0) 76 if (i + n > 0) 77 args[n] = regs->gprs[2 + i + n] & mask; 78 if (i == 0) 79 args[0] = regs->orig_gpr2 & mask; 80 } 81 82 static inline void syscall_set_arguments(struct task_struct *task, 83 struct pt_regs *regs, 84 unsigned int i, unsigned int n, 85 const unsigned long *args) 86 { 87 BUG_ON(i + n > 6); 88 while (n-- > 0) 89 if (i + n > 0) 90 regs->gprs[2 + i + n] = args[n]; 91 if (i == 0) 92 regs->orig_gpr2 = args[0]; 93 } 94 95 static inline int syscall_get_arch(void) 96 { 97 #ifdef CONFIG_COMPAT 98 if (test_tsk_thread_flag(current, TIF_31BIT)) 99 return AUDIT_ARCH_S390; 100 #endif 101 return AUDIT_ARCH_S390X; 102 } 103 #endif /* _ASM_SYSCALL_H */ 104