]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
54ad726c IM |
2 | * Compatibility mode system call entry point for x86-64. |
3 | * | |
1da177e4 | 4 | * Copyright 2000-2002 Andi Kleen, SuSE Labs. |
54ad726c | 5 | */ |
d36f9479 | 6 | #include "calling.h" |
e2d5df93 | 7 | #include <asm/asm-offsets.h> |
1da177e4 LT |
8 | #include <asm/current.h> |
9 | #include <asm/errno.h> | |
54ad726c IM |
10 | #include <asm/ia32_unistd.h> |
11 | #include <asm/thread_info.h> | |
1da177e4 | 12 | #include <asm/segment.h> |
2601e64d | 13 | #include <asm/irqflags.h> |
1ce6f868 | 14 | #include <asm/asm.h> |
63bcff2a | 15 | #include <asm/smap.h> |
1da177e4 | 16 | #include <linux/linkage.h> |
d7e7528b | 17 | #include <linux/err.h> |
1da177e4 | 18 | |
5cbf1565 RM |
19 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ |
20 | #include <linux/elf-em.h> | |
21 | #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE) | |
54ad726c | 22 | #define __AUDIT_ARCH_LE 0x40000000 |
5cbf1565 RM |
23 | |
24 | #ifndef CONFIG_AUDITSYSCALL | |
8f7f06b8 AL |
25 | # define sysexit_audit ia32_ret_from_sys_call_irqs_off |
26 | # define sysretl_audit ia32_ret_from_sys_call_irqs_off | |
5cbf1565 RM |
27 | #endif |
28 | ||
ea714547 JO |
29 | .section .entry.text, "ax" |
30 | ||
2be29982 JF |
31 | #ifdef CONFIG_PARAVIRT |
32 | ENTRY(native_usergs_sysret32) | |
33 | swapgs | |
34 | sysretl | |
35 | ENDPROC(native_usergs_sysret32) | |
2be29982 JF |
36 | #endif |
37 | ||
1da177e4 | 38 | /* |
54ad726c | 39 | * 32-bit SYSENTER instruction entry. |
1da177e4 | 40 | * |
b87cf63e DV |
41 | * SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs. |
42 | * IF and VM in rflags are cleared (IOW: interrupts are off). | |
43 | * SYSENTER does not save anything on the stack, | |
44 | * and does not save old rip (!!!) and rflags. | |
45 | * | |
1da177e4 | 46 | * Arguments: |
b87cf63e DV |
47 | * eax system call number |
48 | * ebx arg1 | |
49 | * ecx arg2 | |
50 | * edx arg3 | |
51 | * esi arg4 | |
52 | * edi arg5 | |
53 | * ebp user stack | |
54 | * 0(%ebp) arg6 | |
55 | * | |
1da177e4 | 56 | * This is purely a fast path. For anything complicated we use the int 0x80 |
b87cf63e | 57 | * path below. We set up a complete hardware stack frame to share code |
1da177e4 | 58 | * with the int 0x80 path. |
b87cf63e | 59 | */ |
4c8cd0c5 | 60 | ENTRY(entry_SYSENTER_compat) |
2601e64d | 61 | /* |
a232e3d5 DV |
62 | * Interrupts are off on entry. |
63 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, | |
64 | * it is too small to ever cause noticeable irq latency. | |
2601e64d | 65 | */ |
a232e3d5 | 66 | SWAPGS_UNSAFE_STACK |
3a23208e | 67 | movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp |
66804154 | 68 | ENABLE_INTERRUPTS(CLBR_NONE) |
a232e3d5 | 69 | |
4ee8ec17 DV |
70 | /* Zero-extending 32-bit regs, do not remove */ |
71 | movl %ebp, %ebp | |
72 | movl %eax, %eax | |
73 | ||
4c9c0e91 | 74 | movl ASM_THREAD_INFO(TI_sysenter_return, %rsp, 0), %r10d |
4c9c0e91 DV |
75 | |
76 | /* Construct struct pt_regs on stack */ | |
131484c8 IM |
77 | pushq $__USER32_DS /* pt_regs->ss */ |
78 | pushq %rbp /* pt_regs->sp */ | |
79 | pushfq /* pt_regs->flags */ | |
80 | pushq $__USER32_CS /* pt_regs->cs */ | |
54ad726c | 81 | pushq %r10 /* pt_regs->ip = thread_info->sysenter_return */ |
131484c8 IM |
82 | pushq %rax /* pt_regs->orig_ax */ |
83 | pushq %rdi /* pt_regs->di */ | |
84 | pushq %rsi /* pt_regs->si */ | |
85 | pushq %rdx /* pt_regs->dx */ | |
86 | pushq %rcx /* pt_regs->cx */ | |
87 | pushq $-ENOSYS /* pt_regs->ax */ | |
1da177e4 | 88 | cld |
54ad726c | 89 | sub $(10*8), %rsp /* pt_regs->r8-11, bp, bx, r12-15 not saved */ |
4c9c0e91 | 90 | |
8c7aa698 AL |
91 | /* |
92 | * Sysenter doesn't filter flags, so we need to clear NT | |
93 | * ourselves. To save a few cycles, we can check whether | |
94 | * NT was set instead of doing an unconditional popfq. | |
95 | */ | |
54ad726c IM |
96 | testl $X86_EFLAGS_NT, EFLAGS(%rsp) |
97 | jnz sysenter_fix_flags | |
8c7aa698 AL |
98 | sysenter_flags_fixed: |
99 | ||
dd27f998 AL |
100 | /* |
101 | * No need to do an access_ok() check here because RBP has been | |
102 | * 32-bit zero extended: | |
103 | */ | |
104 | ASM_STAC | |
105 | 1: movl (%rbp), %ebp | |
106 | _ASM_EXTABLE(1b, ia32_badarg) | |
107 | ASM_CLAC | |
108 | ||
9b47feb7 DV |
109 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
110 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) | |
54ad726c | 111 | jnz sysenter_tracesys |
131484c8 | 112 | |
d4d67150 | 113 | sysenter_do_call: |
54ad726c IM |
114 | /* 32-bit syscall -> 64-bit C ABI argument conversion */ |
115 | movl %edi, %r8d /* arg5 */ | |
116 | movl %ebp, %r9d /* arg6 */ | |
117 | xchg %ecx, %esi /* rsi:arg2, rcx:arg4 */ | |
118 | movl %ebx, %edi /* arg1 */ | |
119 | movl %edx, %edx /* arg3 (zero extension) */ | |
5cbf1565 | 120 | sysenter_dispatch: |
54ad726c | 121 | cmpq $(IA32_NR_syscalls-1), %rax |
3f5159a9 | 122 | ja 1f |
54ad726c IM |
123 | call *ia32_sys_call_table(, %rax, 8) |
124 | movq %rax, RAX(%rsp) | |
3f5159a9 | 125 | 1: |
66804154 | 126 | DISABLE_INTERRUPTS(CLBR_NONE) |
2601e64d | 127 | TRACE_IRQS_OFF |
dca5b52a | 128 | testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
5cbf1565 RM |
129 | jnz sysexit_audit |
130 | sysexit_from_sys_call: | |
4214a16b AL |
131 | /* |
132 | * NB: SYSEXIT is not obviously safe for 64-bit kernels -- an | |
133 | * NMI between STI and SYSEXIT has poorly specified behavior, | |
134 | * and and NMI followed by an IRQ with usergs is fatal. So | |
135 | * we just pretend we're using SYSEXIT but we really use | |
136 | * SYSRETL instead. | |
137 | * | |
138 | * This code path is still called 'sysexit' because it pairs | |
139 | * with 'sysenter' and it uses the SYSENTER calling convention. | |
140 | */ | |
9b47feb7 | 141 | andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
54ad726c | 142 | movl RIP(%rsp), %ecx /* User %eip */ |
cd88ec23 | 143 | movq RAX(%rsp), %rax |
c73e36b7 DV |
144 | movl RSI(%rsp), %esi |
145 | movl RDI(%rsp), %edi | |
54ad726c IM |
146 | xorl %edx, %edx /* Do not leak kernel information */ |
147 | xorq %r8, %r8 | |
148 | xorq %r9, %r9 | |
149 | xorq %r10, %r10 | |
150 | movl EFLAGS(%rsp), %r11d /* User eflags */ | |
2601e64d | 151 | TRACE_IRQS_ON |
4214a16b AL |
152 | |
153 | /* | |
154 | * SYSRETL works even on Intel CPUs. Use it in preference to SYSEXIT, | |
155 | * since it avoids a dicey window with interrupts enabled. | |
156 | */ | |
54ad726c | 157 | movl RSP(%rsp), %esp |
4214a16b | 158 | |
b87cf63e | 159 | /* |
4214a16b AL |
160 | * USERGS_SYSRET32 does: |
161 | * gsbase = user's gs base | |
162 | * eip = ecx | |
163 | * rflags = r11 | |
164 | * cs = __USER32_CS | |
165 | * ss = __USER_DS | |
166 | * | |
167 | * The prologue set RIP(%rsp) to VDSO32_SYSENTER_RETURN, which does: | |
168 | * | |
169 | * pop %ebp | |
170 | * pop %edx | |
171 | * pop %ecx | |
172 | * | |
173 | * Therefore, we invoke SYSRETL with EDX and R8-R10 zeroed to | |
174 | * avoid info leaks. R11 ends up with VDSO32_SYSENTER_RETURN's | |
175 | * address (already known to user code), and R12-R15 are | |
176 | * callee-saved and therefore don't contain any interesting | |
177 | * kernel data. | |
b87cf63e | 178 | */ |
4214a16b | 179 | USERGS_SYSRET32 |
1da177e4 | 180 | |
5cbf1565 RM |
181 | #ifdef CONFIG_AUDITSYSCALL |
182 | .macro auditsys_entry_common | |
a92fde25 DV |
183 | /* |
184 | * At this point, registers hold syscall args in the 32-bit syscall ABI: | |
185 | * EAX is syscall number, the 6 args are in EBX,ECX,EDX,ESI,EDI,EBP. | |
186 | * | |
187 | * We want to pass them to __audit_syscall_entry(), which is a 64-bit | |
188 | * C function with 5 parameters, so shuffle them to match what | |
189 | * the function expects: RDI,RSI,RDX,RCX,R8. | |
190 | */ | |
191 | movl %esi, %r8d /* arg5 (R8 ) <= 4th syscall arg (ESI) */ | |
192 | xchg %ecx, %edx /* arg4 (RCX) <= 3rd syscall arg (EDX) */ | |
193 | /* arg3 (RDX) <= 2nd syscall arg (ECX) */ | |
194 | movl %ebx, %esi /* arg2 (RSI) <= 1st syscall arg (EBX) */ | |
195 | movl %eax, %edi /* arg1 (RDI) <= syscall number (EAX) */ | |
54ad726c | 196 | call __audit_syscall_entry |
a92fde25 | 197 | |
1536bb46 | 198 | /* |
a92fde25 DV |
199 | * We are going to jump back to the syscall dispatch code. |
200 | * Prepare syscall args as required by the 64-bit C ABI. | |
201 | * Registers clobbered by __audit_syscall_entry() are | |
202 | * loaded from pt_regs on stack: | |
1536bb46 DV |
203 | */ |
204 | movl ORIG_RAX(%rsp), %eax /* syscall number */ | |
205 | movl %ebx, %edi /* arg1 */ | |
206 | movl RCX(%rsp), %esi /* arg2 */ | |
207 | movl RDX(%rsp), %edx /* arg3 */ | |
208 | movl RSI(%rsp), %ecx /* arg4 */ | |
209 | movl RDI(%rsp), %r8d /* arg5 */ | |
5cbf1565 RM |
210 | .endm |
211 | ||
81766741 | 212 | .macro auditsys_exit exit |
5cbf1565 | 213 | TRACE_IRQS_ON |
40a1ef95 | 214 | ENABLE_INTERRUPTS(CLBR_NONE) |
29ea1b25 AL |
215 | testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
216 | jnz ia32_ret_from_sys_call | |
54ad726c IM |
217 | movl %eax, %esi /* second arg, syscall return value */ |
218 | cmpl $-MAX_ERRNO, %eax /* is it an error ? */ | |
219 | jbe 1f | |
220 | movslq %eax, %rsi /* if error sign extend to 64 bits */ | |
221 | 1: setbe %al /* 1 if error, 0 if not */ | |
222 | movzbl %al, %edi /* zero-extend that into %edi */ | |
223 | call __audit_syscall_exit | |
54ad726c | 224 | movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %edi |
40a1ef95 | 225 | DISABLE_INTERRUPTS(CLBR_NONE) |
5cbf1565 | 226 | TRACE_IRQS_OFF |
54ad726c IM |
227 | testl %edi, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
228 | jz \exit | |
229 | xorl %eax, %eax /* Do not leak kernel information */ | |
ef0cd5dc DV |
230 | movq %rax, R11(%rsp) |
231 | movq %rax, R10(%rsp) | |
232 | movq %rax, R9(%rsp) | |
233 | movq %rax, R8(%rsp) | |
29ea1b25 | 234 | jmp int_ret_from_sys_call_irqs_off |
5cbf1565 RM |
235 | .endm |
236 | ||
237 | sysenter_auditsys: | |
5cbf1565 | 238 | auditsys_entry_common |
c0c3322e | 239 | movl %ebp, %r9d /* reload 6th syscall arg */ |
54ad726c | 240 | jmp sysenter_dispatch |
5cbf1565 RM |
241 | |
242 | sysexit_audit: | |
243 | auditsys_exit sysexit_from_sys_call | |
244 | #endif | |
245 | ||
8c7aa698 | 246 | sysenter_fix_flags: |
9b47feb7 | 247 | pushq $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) |
131484c8 | 248 | popfq |
54ad726c | 249 | jmp sysenter_flags_fixed |
8c7aa698 | 250 | |
5cbf1565 | 251 | sysenter_tracesys: |
5cbf1565 | 252 | #ifdef CONFIG_AUDITSYSCALL |
dca5b52a | 253 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
5cbf1565 RM |
254 | jz sysenter_auditsys |
255 | #endif | |
76f5df43 | 256 | SAVE_EXTRA_REGS |
54ad726c | 257 | xorl %eax, %eax /* Do not leak kernel information */ |
ef0cd5dc DV |
258 | movq %rax, R11(%rsp) |
259 | movq %rax, R10(%rsp) | |
260 | movq %rax, R9(%rsp) | |
261 | movq %rax, R8(%rsp) | |
54ad726c | 262 | movq %rsp, %rdi /* &pt_regs -> arg1 */ |
1da177e4 | 263 | call syscall_trace_enter |
73cbf687 DV |
264 | |
265 | /* Reload arg registers from stack. (see sysenter_tracesys) */ | |
266 | movl RCX(%rsp), %ecx | |
267 | movl RDX(%rsp), %edx | |
268 | movl RSI(%rsp), %esi | |
269 | movl RDI(%rsp), %edi | |
54ad726c | 270 | movl %eax, %eax /* zero extension */ |
73cbf687 | 271 | |
76f5df43 | 272 | RESTORE_EXTRA_REGS |
1da177e4 | 273 | jmp sysenter_do_call |
4c8cd0c5 | 274 | ENDPROC(entry_SYSENTER_compat) |
1da177e4 LT |
275 | |
276 | /* | |
54ad726c | 277 | * 32-bit SYSCALL instruction entry. |
1da177e4 | 278 | * |
54ad726c | 279 | * 32-bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11, |
b87cf63e DV |
280 | * then loads new ss, cs, and rip from previously programmed MSRs. |
281 | * rflags gets masked by a value from another MSR (so CLD and CLAC | |
282 | * are not needed). SYSCALL does not save anything on the stack | |
283 | * and does not change rsp. | |
284 | * | |
285 | * Note: rflags saving+masking-with-MSR happens only in Long mode | |
54ad726c | 286 | * (in legacy 32-bit mode, IF, RF and VM bits are cleared and that's it). |
b87cf63e DV |
287 | * Don't get confused: rflags saving+masking depends on Long Mode Active bit |
288 | * (EFER.LMA=1), NOT on bitness of userspace where SYSCALL executes | |
289 | * or target CS descriptor's L bit (SYSCALL does not read segment descriptors). | |
290 | * | |
1da177e4 | 291 | * Arguments: |
b87cf63e DV |
292 | * eax system call number |
293 | * ecx return address | |
294 | * ebx arg1 | |
295 | * ebp arg2 (note: not saved in the stack frame, should not be touched) | |
296 | * edx arg3 | |
297 | * esi arg4 | |
298 | * edi arg5 | |
299 | * esp user stack | |
300 | * 0(%esp) arg6 | |
301 | * | |
1da177e4 | 302 | * This is purely a fast path. For anything complicated we use the int 0x80 |
b87cf63e DV |
303 | * path below. We set up a complete hardware stack frame to share code |
304 | * with the int 0x80 path. | |
305 | */ | |
2cd23553 | 306 | ENTRY(entry_SYSCALL_compat) |
a232e3d5 DV |
307 | /* |
308 | * Interrupts are off on entry. | |
309 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, | |
310 | * it is too small to ever cause noticeable irq latency. | |
311 | */ | |
457da70e | 312 | SWAPGS_UNSAFE_STACK |
54ad726c IM |
313 | movl %esp, %r8d |
314 | movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp | |
66804154 | 315 | ENABLE_INTERRUPTS(CLBR_NONE) |
a232e3d5 | 316 | |
4ee8ec17 | 317 | /* Zero-extending 32-bit regs, do not remove */ |
54ad726c | 318 | movl %eax, %eax |
4ee8ec17 | 319 | |
4c9c0e91 | 320 | /* Construct struct pt_regs on stack */ |
131484c8 IM |
321 | pushq $__USER32_DS /* pt_regs->ss */ |
322 | pushq %r8 /* pt_regs->sp */ | |
323 | pushq %r11 /* pt_regs->flags */ | |
324 | pushq $__USER32_CS /* pt_regs->cs */ | |
325 | pushq %rcx /* pt_regs->ip */ | |
326 | pushq %rax /* pt_regs->orig_ax */ | |
327 | pushq %rdi /* pt_regs->di */ | |
328 | pushq %rsi /* pt_regs->si */ | |
329 | pushq %rdx /* pt_regs->dx */ | |
330 | pushq %rbp /* pt_regs->cx */ | |
54ad726c | 331 | movl %ebp, %ecx |
131484c8 | 332 | pushq $-ENOSYS /* pt_regs->ax */ |
54ad726c | 333 | sub $(10*8), %rsp /* pt_regs->r8-11, bp, bx, r12-15 not saved */ |
4c9c0e91 | 334 | |
b87cf63e | 335 | /* |
54ad726c IM |
336 | * No need to do an access_ok check here because r8 has been |
337 | * 32-bit zero extended: | |
b87cf63e | 338 | */ |
63bcff2a | 339 | ASM_STAC |
c0c3322e | 340 | 1: movl (%r8), %r9d |
54ad726c | 341 | _ASM_EXTABLE(1b, ia32_badarg) |
63bcff2a | 342 | ASM_CLAC |
9b47feb7 DV |
343 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
344 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) | |
345 | jnz cstar_tracesys | |
131484c8 | 346 | |
295286a8 | 347 | cstar_do_call: |
54ad726c IM |
348 | /* 32-bit syscall -> 64-bit C ABI argument conversion */ |
349 | movl %edi, %r8d /* arg5 */ | |
c0c3322e | 350 | /* r9 already loaded */ /* arg6 */ |
54ad726c IM |
351 | xchg %ecx, %esi /* rsi:arg2, rcx:arg4 */ |
352 | movl %ebx, %edi /* arg1 */ | |
353 | movl %edx, %edx /* arg3 (zero extension) */ | |
354 | ||
5cbf1565 | 355 | cstar_dispatch: |
54ad726c | 356 | cmpq $(IA32_NR_syscalls-1), %rax |
3f5159a9 | 357 | ja 1f |
54ad726c IM |
358 | |
359 | call *ia32_sys_call_table(, %rax, 8) | |
360 | movq %rax, RAX(%rsp) | |
3f5159a9 | 361 | 1: |
66804154 | 362 | DISABLE_INTERRUPTS(CLBR_NONE) |
2601e64d | 363 | TRACE_IRQS_OFF |
54ad726c IM |
364 | testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
365 | jnz sysretl_audit | |
366 | ||
5cbf1565 | 367 | sysretl_from_sys_call: |
54ad726c | 368 | andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
c73e36b7 DV |
369 | movl RDX(%rsp), %edx |
370 | movl RSI(%rsp), %esi | |
371 | movl RDI(%rsp), %edi | |
54ad726c IM |
372 | movl RIP(%rsp), %ecx |
373 | movl EFLAGS(%rsp), %r11d | |
cd88ec23 | 374 | movq RAX(%rsp), %rax |
54ad726c IM |
375 | xorq %r10, %r10 |
376 | xorq %r9, %r9 | |
377 | xorq %r8, %r8 | |
2601e64d | 378 | TRACE_IRQS_ON |
54ad726c | 379 | movl RSP(%rsp), %esp |
b87cf63e | 380 | /* |
54ad726c | 381 | * 64-bit->32-bit SYSRET restores eip from ecx, |
b87cf63e DV |
382 | * eflags from r11 (but RF and VM bits are forced to 0), |
383 | * cs and ss are loaded from MSRs. | |
54ad726c | 384 | * (Note: 32-bit->32-bit SYSRET is different: since r11 |
b87cf63e | 385 | * does not exist, it merely sets eflags.IF=1). |
61f01dd9 AL |
386 | * |
387 | * NB: On AMD CPUs with the X86_BUG_SYSRET_SS_ATTRS bug, the ss | |
388 | * descriptor is not reinitialized. This means that we must | |
389 | * avoid SYSRET with SS == NULL, which could happen if we schedule, | |
390 | * exit the kernel, and re-enter using an interrupt vector. (All | |
391 | * interrupt entries on x86_64 set SS to NULL.) We prevent that | |
392 | * from happening by reloading SS in __switch_to. | |
b87cf63e | 393 | */ |
2be29982 | 394 | USERGS_SYSRET32 |
b87cf63e | 395 | |
5cbf1565 RM |
396 | #ifdef CONFIG_AUDITSYSCALL |
397 | cstar_auditsys: | |
c0c3322e | 398 | movl %r9d, R9(%rsp) /* register to be clobbered by call */ |
5cbf1565 | 399 | auditsys_entry_common |
c0c3322e | 400 | movl R9(%rsp), %r9d /* reload 6th syscall arg */ |
54ad726c | 401 | jmp cstar_dispatch |
5cbf1565 RM |
402 | |
403 | sysretl_audit: | |
81766741 | 404 | auditsys_exit sysretl_from_sys_call |
5cbf1565 RM |
405 | #endif |
406 | ||
407 | cstar_tracesys: | |
408 | #ifdef CONFIG_AUDITSYSCALL | |
54ad726c IM |
409 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
410 | jz cstar_auditsys | |
5cbf1565 | 411 | #endif |
c0c3322e | 412 | xchgl %r9d, %ebp |
76f5df43 | 413 | SAVE_EXTRA_REGS |
54ad726c | 414 | xorl %eax, %eax /* Do not leak kernel information */ |
ef0cd5dc DV |
415 | movq %rax, R11(%rsp) |
416 | movq %rax, R10(%rsp) | |
c0c3322e | 417 | movq %r9, R9(%rsp) |
ef0cd5dc | 418 | movq %rax, R8(%rsp) |
54ad726c | 419 | movq %rsp, %rdi /* &pt_regs -> arg1 */ |
53e9accf | 420 | call syscall_trace_enter |
c0c3322e | 421 | movl R9(%rsp), %r9d |
73cbf687 DV |
422 | |
423 | /* Reload arg registers from stack. (see sysenter_tracesys) */ | |
424 | movl RCX(%rsp), %ecx | |
425 | movl RDX(%rsp), %edx | |
426 | movl RSI(%rsp), %esi | |
427 | movl RDI(%rsp), %edi | |
54ad726c | 428 | movl %eax, %eax /* zero extension */ |
73cbf687 | 429 | |
76f5df43 | 430 | RESTORE_EXTRA_REGS |
c0c3322e | 431 | xchgl %ebp, %r9d |
53e9accf | 432 | jmp cstar_do_call |
2cd23553 | 433 | END(entry_SYSCALL_compat) |
54ad726c | 434 | |
1da177e4 | 435 | ia32_badarg: |
5e99cb7c AL |
436 | /* |
437 | * So far, we've entered kernel mode, set AC, turned on IRQs, and | |
438 | * saved C regs except r8-r11. We haven't done any of the other | |
439 | * standard entry work, though. We want to bail, but we shouldn't | |
440 | * treat this as a syscall entry since we don't even know what the | |
441 | * args are. Instead, treat this as a non-syscall entry, finish | |
442 | * the entry work, and immediately exit after setting AX = -EFAULT. | |
443 | * | |
444 | * We're really just being polite here. Killing the task outright | |
445 | * would be a reasonable action, too. Given that the only valid | |
446 | * way to have gotten here is through the vDSO, and we already know | |
447 | * that the stack pointer is bad, the task isn't going to survive | |
448 | * for long no matter what we do. | |
449 | */ | |
450 | ||
451 | ASM_CLAC /* undo STAC */ | |
452 | movq $-EFAULT, RAX(%rsp) /* return -EFAULT if possible */ | |
453 | ||
454 | /* Fill in the rest of pt_regs */ | |
455 | xorl %eax, %eax | |
456 | movq %rax, R11(%rsp) | |
457 | movq %rax, R10(%rsp) | |
458 | movq %rax, R9(%rsp) | |
459 | movq %rax, R8(%rsp) | |
460 | SAVE_EXTRA_REGS | |
461 | ||
462 | /* Turn IRQs back off. */ | |
463 | DISABLE_INTERRUPTS(CLBR_NONE) | |
464 | TRACE_IRQS_OFF | |
465 | ||
02bc7768 AL |
466 | /* Now finish entering normal kernel mode. */ |
467 | #ifdef CONFIG_CONTEXT_TRACKING | |
468 | call enter_from_user_mode | |
469 | #endif | |
470 | ||
5e99cb7c AL |
471 | /* And exit again. */ |
472 | jmp retint_user | |
473 | ||
8f7f06b8 AL |
474 | ia32_ret_from_sys_call_irqs_off: |
475 | TRACE_IRQS_ON | |
476 | ENABLE_INTERRUPTS(CLBR_NONE) | |
477 | ||
61b1e3e7 | 478 | ia32_ret_from_sys_call: |
54ad726c | 479 | xorl %eax, %eax /* Do not leak kernel information */ |
ef0cd5dc DV |
480 | movq %rax, R11(%rsp) |
481 | movq %rax, R10(%rsp) | |
482 | movq %rax, R9(%rsp) | |
483 | movq %rax, R8(%rsp) | |
54ad726c | 484 | jmp int_ret_from_sys_call |
61b1e3e7 | 485 | |
b87cf63e DV |
486 | /* |
487 | * Emulated IA32 system calls via int 0x80. | |
1da177e4 | 488 | * |
b87cf63e DV |
489 | * Arguments: |
490 | * eax system call number | |
491 | * ebx arg1 | |
492 | * ecx arg2 | |
493 | * edx arg3 | |
494 | * esi arg4 | |
495 | * edi arg5 | |
496 | * ebp arg6 (note: not saved in the stack frame, should not be touched) | |
1da177e4 LT |
497 | * |
498 | * Notes: | |
b87cf63e DV |
499 | * Uses the same stack frame as the x86-64 version. |
500 | * All registers except eax must be saved (but ptrace may violate that). | |
1da177e4 LT |
501 | * Arguments are zero extended. For system calls that want sign extension and |
502 | * take long arguments a wrapper is needed. Most calls can just be called | |
503 | * directly. | |
b87cf63e DV |
504 | * Assumes it is only called from user space and entered with interrupts off. |
505 | */ | |
1da177e4 | 506 | |
2cd23553 | 507 | ENTRY(entry_INT80_compat) |
2601e64d | 508 | /* |
a232e3d5 DV |
509 | * Interrupts are off on entry. |
510 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, | |
511 | * it is too small to ever cause noticeable irq latency. | |
2601e64d | 512 | */ |
a232e3d5 DV |
513 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
514 | SWAPGS | |
66804154 | 515 | ENABLE_INTERRUPTS(CLBR_NONE) |
a232e3d5 | 516 | |
4ee8ec17 | 517 | /* Zero-extending 32-bit regs, do not remove */ |
54ad726c | 518 | movl %eax, %eax |
4ee8ec17 | 519 | |
4c9c0e91 | 520 | /* Construct struct pt_regs on stack (iret frame is already on stack) */ |
131484c8 IM |
521 | pushq %rax /* pt_regs->orig_ax */ |
522 | pushq %rdi /* pt_regs->di */ | |
523 | pushq %rsi /* pt_regs->si */ | |
524 | pushq %rdx /* pt_regs->dx */ | |
525 | pushq %rcx /* pt_regs->cx */ | |
526 | pushq $-ENOSYS /* pt_regs->ax */ | |
61b1e3e7 DV |
527 | pushq $0 /* pt_regs->r8 */ |
528 | pushq $0 /* pt_regs->r9 */ | |
529 | pushq $0 /* pt_regs->r10 */ | |
530 | pushq $0 /* pt_regs->r11 */ | |
1da177e4 | 531 | cld |
54ad726c IM |
532 | sub $(6*8), %rsp /* pt_regs->bp, bx, r12-15 not saved */ |
533 | ||
534 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) | |
535 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) | |
536 | jnz ia32_tracesys | |
4c9c0e91 | 537 | |
c09249f8 | 538 | ia32_do_call: |
54ad726c IM |
539 | /* 32-bit syscall -> 64-bit C ABI argument conversion */ |
540 | movl %edi, %r8d /* arg5 */ | |
541 | movl %ebp, %r9d /* arg6 */ | |
542 | xchg %ecx, %esi /* rsi:arg2, rcx:arg4 */ | |
543 | movl %ebx, %edi /* arg1 */ | |
544 | movl %edx, %edx /* arg3 (zero extension) */ | |
545 | cmpq $(IA32_NR_syscalls-1), %rax | |
3f5159a9 | 546 | ja 1f |
54ad726c | 547 | |
eb478544 | 548 | call *ia32_sys_call_table(, %rax, 8) |
54ad726c | 549 | movq %rax, RAX(%rsp) |
3f5159a9 | 550 | 1: |
54ad726c | 551 | jmp int_ret_from_sys_call |
1da177e4 | 552 | |
76f5df43 DV |
553 | ia32_tracesys: |
554 | SAVE_EXTRA_REGS | |
54ad726c IM |
555 | movq %rsp, %rdi /* &pt_regs -> arg1 */ |
556 | call syscall_trace_enter | |
73cbf687 DV |
557 | /* |
558 | * Reload arg registers from stack in case ptrace changed them. | |
559 | * Don't reload %eax because syscall_trace_enter() returned | |
560 | * the %rax value we should see. But do truncate it to 32 bits. | |
561 | * If it's -1 to make us punt the syscall, then (u32)-1 is still | |
562 | * an appropriately invalid value. | |
563 | */ | |
564 | movl RCX(%rsp), %ecx | |
565 | movl RDX(%rsp), %edx | |
566 | movl RSI(%rsp), %esi | |
567 | movl RDI(%rsp), %edi | |
54ad726c | 568 | movl %eax, %eax /* zero extension */ |
76f5df43 | 569 | RESTORE_EXTRA_REGS |
54ad726c | 570 | jmp ia32_do_call |
2cd23553 | 571 | END(entry_INT80_compat) |
1da177e4 | 572 | |
d2475b8f | 573 | .macro PTREGSCALL label, func |
f6b2bc84 JB |
574 | ALIGN |
575 | GLOBAL(\label) | |
54ad726c IM |
576 | leaq \func(%rip), %rax |
577 | jmp ia32_ptregs_common | |
1da177e4 LT |
578 | .endm |
579 | ||
54ad726c IM |
580 | PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn |
581 | PTREGSCALL stub32_sigreturn, sys32_sigreturn | |
582 | PTREGSCALL stub32_fork, sys_fork | |
583 | PTREGSCALL stub32_vfork, sys_vfork | |
1da177e4 | 584 | |
1d4b4b29 AV |
585 | ALIGN |
586 | GLOBAL(stub32_clone) | |
54ad726c | 587 | leaq sys_clone(%rip), %rax |
5cdc683b | 588 | /* |
7a5a9824 DV |
589 | * The 32-bit clone ABI is: clone(..., int tls_val, int *child_tidptr). |
590 | * The 64-bit clone ABI is: clone(..., int *child_tidptr, int tls_val). | |
591 | * | |
592 | * The native 64-bit kernel's sys_clone() implements the latter, | |
593 | * so we need to swap arguments here before calling it: | |
5cdc683b | 594 | */ |
7a5a9824 | 595 | xchg %r8, %rcx |
54ad726c | 596 | jmp ia32_ptregs_common |
1d4b4b29 | 597 | |
f6b2bc84 JB |
598 | ALIGN |
599 | ia32_ptregs_common: | |
76f5df43 | 600 | SAVE_EXTRA_REGS 8 |
54ad726c | 601 | call *%rax |
76f5df43 DV |
602 | RESTORE_EXTRA_REGS 8 |
603 | ret | |
4b787e0b | 604 | END(ia32_ptregs_common) |