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