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