Commit | Line | Data |
---|---|---|
68bd0f4e RM |
1 | /* |
2 | * Access to user system call parameters and results | |
3 | * | |
18c1e2c8 | 4 | * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved. |
68bd0f4e RM |
5 | * |
6 | * This copyrighted material is made available to anyone wishing to use, | |
7 | * modify, copy, or redistribute it subject to the terms and conditions | |
8 | * of the GNU General Public License v.2. | |
9 | * | |
10 | * See asm-generic/syscall.h for descriptions of what we must do here. | |
11 | */ | |
12 | ||
5e1b0075 PA |
13 | #ifndef _ASM_X86_SYSCALL_H |
14 | #define _ASM_X86_SYSCALL_H | |
68bd0f4e | 15 | |
579ec9e1 | 16 | #include <uapi/linux/audit.h> |
68bd0f4e | 17 | #include <linux/sched.h> |
4ab4ba32 | 18 | #include <linux/err.h> |
72142fd4 | 19 | #include <asm/asm-offsets.h> /* For NR_syscalls */ |
b7456536 | 20 | #include <asm/thread_info.h> /* for TS_COMPAT */ |
fca460f9 | 21 | #include <asm/unistd.h> |
68bd0f4e | 22 | |
f8781c4a | 23 | #ifdef CONFIG_X86_64 |
fa697140 DB |
24 | typedef asmlinkage long (*sys_call_ptr_t)(const struct pt_regs *); |
25 | #else | |
eb974c62 AL |
26 | typedef asmlinkage long (*sys_call_ptr_t)(unsigned long, unsigned long, |
27 | unsigned long, unsigned long, | |
28 | unsigned long, unsigned long); | |
f8781c4a | 29 | #endif /* CONFIG_X86_64 */ |
1599e8fc | 30 | extern const sys_call_ptr_t sys_call_table[]; |
e7b8e675 | 31 | |
034042cc AL |
32 | #if defined(CONFIG_X86_32) |
33 | #define ia32_sys_call_table sys_call_table | |
34 | #define __NR_syscall_compat_max __NR_syscall_max | |
35 | #define IA32_NR_syscalls NR_syscalls | |
36 | #endif | |
37 | ||
38 | #if defined(CONFIG_IA32_EMULATION) | |
39 | extern const sys_call_ptr_t ia32_sys_call_table[]; | |
40 | #endif | |
41 | ||
18c1e2c8 RM |
42 | /* |
43 | * Only the low 32 bits of orig_ax are meaningful, so we return int. | |
44 | * This importantly ignores the high bits on 64-bit, so comparisons | |
45 | * sign-extend the low 32 bits. | |
46 | */ | |
47 | static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) | |
68bd0f4e | 48 | { |
8b4b9f27 | 49 | return regs->orig_ax; |
68bd0f4e RM |
50 | } |
51 | ||
52 | static inline void syscall_rollback(struct task_struct *task, | |
53 | struct pt_regs *regs) | |
54 | { | |
8b4b9f27 | 55 | regs->ax = regs->orig_ax; |
68bd0f4e RM |
56 | } |
57 | ||
58 | static inline long syscall_get_error(struct task_struct *task, | |
59 | struct pt_regs *regs) | |
60 | { | |
61 | unsigned long error = regs->ax; | |
62 | #ifdef CONFIG_IA32_EMULATION | |
63 | /* | |
64 | * TS_COMPAT is set for 32-bit syscall entries and then | |
65 | * remains set until we return to user mode. | |
66 | */ | |
37a8f7c3 | 67 | if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED)) |
68bd0f4e RM |
68 | /* |
69 | * Sign-extend the value so (int)-EFOO becomes (long)-EFOO | |
70 | * and will match correctly in comparisons. | |
71 | */ | |
72 | error = (long) (int) error; | |
73 | #endif | |
4ab4ba32 | 74 | return IS_ERR_VALUE(error) ? error : 0; |
68bd0f4e RM |
75 | } |
76 | ||
77 | static inline long syscall_get_return_value(struct task_struct *task, | |
78 | struct pt_regs *regs) | |
79 | { | |
80 | return regs->ax; | |
81 | } | |
82 | ||
83 | static inline void syscall_set_return_value(struct task_struct *task, | |
84 | struct pt_regs *regs, | |
85 | int error, long val) | |
86 | { | |
87 | regs->ax = (long) error ?: val; | |
88 | } | |
89 | ||
90 | #ifdef CONFIG_X86_32 | |
91 | ||
92 | static inline void syscall_get_arguments(struct task_struct *task, | |
93 | struct pt_regs *regs, | |
94 | unsigned int i, unsigned int n, | |
95 | unsigned long *args) | |
96 | { | |
97 | BUG_ON(i + n > 6); | |
98 | memcpy(args, ®s->bx + i, n * sizeof(args[0])); | |
99 | } | |
100 | ||
101 | static inline void syscall_set_arguments(struct task_struct *task, | |
102 | struct pt_regs *regs, | |
103 | unsigned int i, unsigned int n, | |
104 | const unsigned long *args) | |
105 | { | |
106 | BUG_ON(i + n > 6); | |
107 | memcpy(®s->bx + i, args, n * sizeof(args[0])); | |
108 | } | |
109 | ||
16add411 | 110 | static inline int syscall_get_arch(struct task_struct *task) |
b7456536 WD |
111 | { |
112 | return AUDIT_ARCH_I386; | |
113 | } | |
114 | ||
68bd0f4e RM |
115 | #else /* CONFIG_X86_64 */ |
116 | ||
117 | static inline void syscall_get_arguments(struct task_struct *task, | |
118 | struct pt_regs *regs, | |
119 | unsigned int i, unsigned int n, | |
120 | unsigned long *args) | |
121 | { | |
122 | # ifdef CONFIG_IA32_EMULATION | |
37a8f7c3 | 123 | if (task->thread_info.status & TS_COMPAT) |
746e7cef RM |
124 | switch (i) { |
125 | case 0: | |
68bd0f4e | 126 | if (!n--) break; |
746e7cef RM |
127 | *args++ = regs->bx; |
128 | case 1: | |
68bd0f4e | 129 | if (!n--) break; |
746e7cef RM |
130 | *args++ = regs->cx; |
131 | case 2: | |
68bd0f4e | 132 | if (!n--) break; |
746e7cef | 133 | *args++ = regs->dx; |
68bd0f4e RM |
134 | case 3: |
135 | if (!n--) break; | |
746e7cef RM |
136 | *args++ = regs->si; |
137 | case 4: | |
68bd0f4e | 138 | if (!n--) break; |
746e7cef RM |
139 | *args++ = regs->di; |
140 | case 5: | |
68bd0f4e | 141 | if (!n--) break; |
746e7cef RM |
142 | *args++ = regs->bp; |
143 | case 6: | |
68bd0f4e RM |
144 | if (!n--) break; |
145 | default: | |
146 | BUG(); | |
147 | break; | |
148 | } | |
149 | else | |
150 | # endif | |
746e7cef RM |
151 | switch (i) { |
152 | case 0: | |
68bd0f4e | 153 | if (!n--) break; |
746e7cef RM |
154 | *args++ = regs->di; |
155 | case 1: | |
68bd0f4e | 156 | if (!n--) break; |
746e7cef RM |
157 | *args++ = regs->si; |
158 | case 2: | |
68bd0f4e | 159 | if (!n--) break; |
746e7cef | 160 | *args++ = regs->dx; |
68bd0f4e RM |
161 | case 3: |
162 | if (!n--) break; | |
746e7cef RM |
163 | *args++ = regs->r10; |
164 | case 4: | |
68bd0f4e | 165 | if (!n--) break; |
746e7cef RM |
166 | *args++ = regs->r8; |
167 | case 5: | |
68bd0f4e | 168 | if (!n--) break; |
746e7cef RM |
169 | *args++ = regs->r9; |
170 | case 6: | |
68bd0f4e RM |
171 | if (!n--) break; |
172 | default: | |
173 | BUG(); | |
174 | break; | |
175 | } | |
176 | } | |
177 | ||
178 | static inline void syscall_set_arguments(struct task_struct *task, | |
179 | struct pt_regs *regs, | |
180 | unsigned int i, unsigned int n, | |
181 | const unsigned long *args) | |
182 | { | |
183 | # ifdef CONFIG_IA32_EMULATION | |
37a8f7c3 | 184 | if (task->thread_info.status & TS_COMPAT) |
746e7cef RM |
185 | switch (i) { |
186 | case 0: | |
68bd0f4e | 187 | if (!n--) break; |
746e7cef RM |
188 | regs->bx = *args++; |
189 | case 1: | |
68bd0f4e | 190 | if (!n--) break; |
746e7cef RM |
191 | regs->cx = *args++; |
192 | case 2: | |
68bd0f4e | 193 | if (!n--) break; |
746e7cef | 194 | regs->dx = *args++; |
68bd0f4e RM |
195 | case 3: |
196 | if (!n--) break; | |
746e7cef RM |
197 | regs->si = *args++; |
198 | case 4: | |
68bd0f4e | 199 | if (!n--) break; |
746e7cef RM |
200 | regs->di = *args++; |
201 | case 5: | |
68bd0f4e | 202 | if (!n--) break; |
746e7cef RM |
203 | regs->bp = *args++; |
204 | case 6: | |
68bd0f4e RM |
205 | if (!n--) break; |
206 | default: | |
207 | BUG(); | |
746e7cef | 208 | break; |
68bd0f4e RM |
209 | } |
210 | else | |
211 | # endif | |
746e7cef RM |
212 | switch (i) { |
213 | case 0: | |
68bd0f4e | 214 | if (!n--) break; |
746e7cef RM |
215 | regs->di = *args++; |
216 | case 1: | |
68bd0f4e | 217 | if (!n--) break; |
746e7cef RM |
218 | regs->si = *args++; |
219 | case 2: | |
68bd0f4e | 220 | if (!n--) break; |
746e7cef | 221 | regs->dx = *args++; |
68bd0f4e RM |
222 | case 3: |
223 | if (!n--) break; | |
746e7cef RM |
224 | regs->r10 = *args++; |
225 | case 4: | |
68bd0f4e | 226 | if (!n--) break; |
746e7cef RM |
227 | regs->r8 = *args++; |
228 | case 5: | |
68bd0f4e | 229 | if (!n--) break; |
746e7cef RM |
230 | regs->r9 = *args++; |
231 | case 6: | |
68bd0f4e RM |
232 | if (!n--) break; |
233 | default: | |
234 | BUG(); | |
746e7cef | 235 | break; |
68bd0f4e RM |
236 | } |
237 | } | |
238 | ||
16add411 | 239 | static inline int syscall_get_arch(struct task_struct *task) |
b7456536 | 240 | { |
b9d989c7 | 241 | /* x32 tasks should be considered AUDIT_ARCH_X86_64. */ |
16add411 DL |
242 | return (IS_ENABLED(CONFIG_IA32_EMULATION) && |
243 | task->thread_info.status & TS_COMPAT) | |
244 | ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64; | |
b7456536 | 245 | } |
68bd0f4e RM |
246 | #endif /* CONFIG_X86_32 */ |
247 | ||
5e1b0075 | 248 | #endif /* _ASM_X86_SYSCALL_H */ |