GNU Linux-libre 4.19.286-gnu1
[releases.git] / arch / s390 / include / asm / syscall.h
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         unsigned long error = regs->gprs[2];
42 #ifdef CONFIG_COMPAT
43         if (test_tsk_thread_flag(task, TIF_31BIT)) {
44                 /*
45                  * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
46                  * and will match correctly in comparisons.
47                  */
48                 error = (long)(int)error;
49         }
50 #endif
51         return IS_ERR_VALUE(error) ? error : 0;
52 }
53
54 static inline long syscall_get_return_value(struct task_struct *task,
55                                             struct pt_regs *regs)
56 {
57         return regs->gprs[2];
58 }
59
60 static inline void syscall_set_return_value(struct task_struct *task,
61                                             struct pt_regs *regs,
62                                             int error, long val)
63 {
64         regs->gprs[2] = error ? error : val;
65 }
66
67 static inline void syscall_get_arguments(struct task_struct *task,
68                                          struct pt_regs *regs,
69                                          unsigned int i, unsigned int n,
70                                          unsigned long *args)
71 {
72         unsigned long mask = -1UL;
73
74         /*
75          * No arguments for this syscall, there's nothing to do.
76          */
77         if (!n)
78                 return;
79
80         BUG_ON(i + n > 6);
81 #ifdef CONFIG_COMPAT
82         if (test_tsk_thread_flag(task, TIF_31BIT))
83                 mask = 0xffffffff;
84 #endif
85         while (n-- > 0)
86                 if (i + n > 0)
87                         args[n] = regs->gprs[2 + i + n] & mask;
88         if (i == 0)
89                 args[0] = regs->orig_gpr2 & mask;
90 }
91
92 static inline void syscall_set_arguments(struct task_struct *task,
93                                          struct pt_regs *regs,
94                                          unsigned int i, unsigned int n,
95                                          const unsigned long *args)
96 {
97         BUG_ON(i + n > 6);
98         while (n-- > 0)
99                 if (i + n > 0)
100                         regs->gprs[2 + i + n] = args[n];
101         if (i == 0)
102                 regs->orig_gpr2 = args[0];
103 }
104
105 static inline int syscall_get_arch(void)
106 {
107 #ifdef CONFIG_COMPAT
108         if (test_tsk_thread_flag(current, TIF_31BIT))
109                 return AUDIT_ARCH_S390;
110 #endif
111         return AUDIT_ARCH_S390X;
112 }
113 #endif  /* _ASM_SYSCALL_H */