blob: e99f8a5be2dfd65a790267eba2ff23245c0a7ffd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Sam Ravnborge2d5df92005-09-09 21:28:48 +02009#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#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>
Ingo Molnar2601e642006-07-03 00:24:45 -070015#include <asm/irqflags.h>
H. Peter Anvin1ce6f862012-04-20 12:19:50 -070016#include <asm/asm.h>
H. Peter Anvin63bcff22012-09-21 12:43:12 -070017#include <asm/smap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/linkage.h>
Eric Parisd7e75282012-01-03 14:23:06 -050019#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Roland McGrath5cbf1562008-06-24 01:13:31 -070021/* 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
Jan Beulich24e35802009-09-30 11:22:11 +010027#define sysexit_audit ia32_ret_from_sys_call
28#define sysretl_audit ia32_ret_from_sys_call
Roland McGrath5cbf1562008-06-24 01:13:31 -070029#endif
30
Jiri Olsaea714542011-03-07 19:10:39 +010031 .section .entry.text, "ax"
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 .macro IA32_ARG_FIXUP noebp=0
34 movl %edi,%r8d
35 .if \noebp
36 .else
37 movl %ebp,%r9d
38 .endif
39 xchg %ecx,%esi
40 movl %ebx,%edi
41 movl %edx,%edx /* zero extension */
42 .endm
43
Denys Vlasenkof2db9382015-02-26 14:40:30 -080044 /* clobbers %rax */
45 .macro CLEAR_RREGS _r9=rax
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 xorl %eax,%eax
Denys Vlasenkof2db9382015-02-26 14:40:30 -080047 movq %rax,R11(%rsp)
48 movq %rax,R10(%rsp)
49 movq %\_r9,R9(%rsp)
50 movq %rax,R8(%rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 .endm
52
Roland McGrathd4d67152008-07-09 02:38:07 -070053 /*
54 * Reload arg registers from stack in case ptrace changed them.
55 * We don't reload %eax because syscall_trace_enter() returned
Roland McGratheefdca02010-09-14 12:22:58 -070056 * the %rax value we should see. Instead, we just truncate that
57 * value to 32 bits again as we did on entry from user mode.
58 * If it's a new value set by user_regset during entry tracing,
59 * this matches the normal truncation of the user-mode value.
60 * If it's -1 to make us punt the syscall, then (u32)-1 is still
61 * an appropriately invalid value.
Roland McGrathd4d67152008-07-09 02:38:07 -070062 */
Denys Vlasenkof2db9382015-02-26 14:40:30 -080063 .macro LOAD_ARGS32 _r9=0
Jan Beulich295286a2008-08-29 13:21:11 +010064 .if \_r9
Denys Vlasenkof2db9382015-02-26 14:40:30 -080065 movl R9(%rsp),%r9d
Jan Beulich295286a2008-08-29 13:21:11 +010066 .endif
Denys Vlasenkof2db9382015-02-26 14:40:30 -080067 movl RCX(%rsp),%ecx
68 movl RDX(%rsp),%edx
69 movl RSI(%rsp),%esi
70 movl RDI(%rsp),%edi
Roland McGratheefdca02010-09-14 12:22:58 -070071 movl %eax,%eax /* zero extension */
Andi Kleen176df242007-09-21 16:16:18 +020072 .endm
73
Jan Beulich27651302006-01-11 22:41:59 +010074 .macro CFI_STARTPROC32 simple
75 CFI_STARTPROC \simple
76 CFI_UNDEFINED r8
77 CFI_UNDEFINED r9
78 CFI_UNDEFINED r10
79 CFI_UNDEFINED r11
80 CFI_UNDEFINED r12
81 CFI_UNDEFINED r13
82 CFI_UNDEFINED r14
83 CFI_UNDEFINED r15
84 .endm
85
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -040086#ifdef CONFIG_PARAVIRT
87ENTRY(native_usergs_sysret32)
88 swapgs
89 sysretl
90ENDPROC(native_usergs_sysret32)
91
92ENTRY(native_irq_enable_sysexit)
93 swapgs
94 sti
95 sysexit
96ENDPROC(native_irq_enable_sysexit)
97#endif
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/*
100 * 32bit SYSENTER instruction entry.
101 *
102 * Arguments:
103 * %eax System call number.
104 * %ebx Arg1
105 * %ecx Arg2
106 * %edx Arg3
107 * %esi Arg4
108 * %edi Arg5
109 * %ebp user stack
110 * 0(%ebp) Arg6
111 *
112 * Interrupts off.
113 *
114 * This is purely a fast path. For anything complicated we use the int 0x80
115 * path below. Set up a complete hardware stack frame to share code
116 * with the int 0x80 path.
117 */
118ENTRY(ia32_sysenter_target)
Jan Beulich27651302006-01-11 22:41:59 +0100119 CFI_STARTPROC32 simple
Jan Beulichadf14232006-09-26 10:52:41 +0200120 CFI_SIGNAL_FRAME
Jan Beulich7effaa82005-09-12 18:49:24 +0200121 CFI_DEF_CFA rsp,0
122 CFI_REGISTER rsp,rbp
Jeremy Fitzhardinge457da702008-06-26 07:28:51 -0700123 SWAPGS_UNSAFE_STACK
Brian Gerst9af45652009-01-19 00:38:58 +0900124 movq PER_CPU_VAR(kernel_stack), %rsp
125 addq $(KERNEL_STACK_OFFSET),%rsp
Ingo Molnar2601e642006-07-03 00:24:45 -0700126 /*
127 * No need to follow this irqs on/off section: the syscall
128 * disabled irqs, here we enable it straight after entry:
129 */
Jeremy Fitzhardinge66804152008-06-25 00:19:29 -0400130 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 movl %ebp,%ebp /* zero extension */
Jan Beulich60cf6372011-02-28 15:54:40 +0000132 pushq_cfi $__USER32_DS
Jan Beulich7effaa82005-09-12 18:49:24 +0200133 /*CFI_REL_OFFSET ss,0*/
Jan Beulich60cf6372011-02-28 15:54:40 +0000134 pushq_cfi %rbp
Jan Beulich7effaa82005-09-12 18:49:24 +0200135 CFI_REL_OFFSET rsp,0
Jan Beulich60cf6372011-02-28 15:54:40 +0000136 pushfq_cfi
Jan Beulich7effaa82005-09-12 18:49:24 +0200137 /*CFI_REL_OFFSET rflags,0*/
Jan Beulich46db09d2011-11-29 11:17:45 +0000138 movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
Jan Beulich7effaa82005-09-12 18:49:24 +0200139 CFI_REGISTER rip,r10
Jan Beulich60cf6372011-02-28 15:54:40 +0000140 pushq_cfi $__USER32_CS
Jan Beulich7effaa82005-09-12 18:49:24 +0200141 /*CFI_REL_OFFSET cs,0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 movl %eax, %eax
Jan Beulich60cf6372011-02-28 15:54:40 +0000143 pushq_cfi %r10
Jan Beulich7effaa82005-09-12 18:49:24 +0200144 CFI_REL_OFFSET rip,0
Jan Beulich60cf6372011-02-28 15:54:40 +0000145 pushq_cfi %rax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 cld
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800147 ALLOC_PT_GPREGS_ON_STACK
148 SAVE_C_REGS_EXCEPT_R891011
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 /* no need to do an access_ok check here because rbp has been
150 32bit zero extended */
H. Peter Anvin63bcff22012-09-21 12:43:12 -0700151 ASM_STAC
Jan Beulich295286a2008-08-29 13:21:11 +01001521: movl (%rbp),%ebp
H. Peter Anvin1ce6f862012-04-20 12:19:50 -0700153 _ASM_EXTABLE(1b,ia32_badarg)
H. Peter Anvin63bcff22012-09-21 12:43:12 -0700154 ASM_CLAC
Andy Lutomirski8c7aa692014-10-01 11:49:04 -0700155
156 /*
157 * Sysenter doesn't filter flags, so we need to clear NT
158 * ourselves. To save a few cycles, we can check whether
159 * NT was set instead of doing an unconditional popfq.
160 */
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800161 testl $X86_EFLAGS_NT,EFLAGS(%rsp)
Andy Lutomirski8c7aa692014-10-01 11:49:04 -0700162 jnz sysenter_fix_flags
163sysenter_flags_fixed:
164
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800165 orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP)
166 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP)
Jan Beulich7effaa82005-09-12 18:49:24 +0200167 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 jnz sysenter_tracesys
H. Peter Anvin36d001c2010-09-14 12:42:41 -0700169 cmpq $(IA32_NR_syscalls-1),%rax
Andi Kleen67d53ea2006-04-07 19:50:31 +0200170 ja ia32_badsys
Roland McGrathd4d67152008-07-09 02:38:07 -0700171sysenter_do_call:
Jan Beulich295286a2008-08-29 13:21:11 +0100172 IA32_ARG_FIXUP
Roland McGrath5cbf1562008-06-24 01:13:31 -0700173sysenter_dispatch:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 call *ia32_sys_call_table(,%rax,8)
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800175 movq %rax,RAX(%rsp)
Jeremy Fitzhardinge66804152008-06-25 00:19:29 -0400176 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700177 TRACE_IRQS_OFF
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800178 testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP)
Roland McGrath5cbf1562008-06-24 01:13:31 -0700179 jnz sysexit_audit
180sysexit_from_sys_call:
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800181 andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 /* clear IF, that popfq doesn't enable interrupts early */
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800183 andl $~0x200,EFLAGS(%rsp)
184 movl RIP(%rsp),%edx /* User %eip */
Roland McGrath36197c92008-01-30 13:30:43 +0100185 CFI_REGISTER rip,rdx
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800186 RESTORE_RSI_RDI
187 REMOVE_PT_GPREGS_FROM_STACK 3*8
Jan Beulich24e35802009-09-30 11:22:11 +0100188 xorq %r8,%r8
189 xorq %r9,%r9
190 xorq %r10,%r10
191 xorq %r11,%r11
Jan Beulich60cf6372011-02-28 15:54:40 +0000192 popfq_cfi
Jan Beulich7effaa82005-09-12 18:49:24 +0200193 /*CFI_RESTORE rflags*/
Jan Beulich60cf6372011-02-28 15:54:40 +0000194 popq_cfi %rcx /* User %esp */
Jan Beulich7effaa82005-09-12 18:49:24 +0200195 CFI_REGISTER rsp,rcx
Ingo Molnar2601e642006-07-03 00:24:45 -0700196 TRACE_IRQS_ON
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400197 ENABLE_INTERRUPTS_SYSEXIT32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Andy Lutomirski8c7aa692014-10-01 11:49:04 -0700199 CFI_RESTORE_STATE
200
Roland McGrath5cbf1562008-06-24 01:13:31 -0700201#ifdef CONFIG_AUDITSYSCALL
202 .macro auditsys_entry_common
Richard Guy Briggsb4f0d372014-03-04 10:38:06 -0500203 movl %esi,%r8d /* 5th arg: 4th syscall arg */
204 movl %ecx,%r9d /*swap with edx*/
205 movl %edx,%ecx /* 4th arg: 3rd syscall arg */
206 movl %r9d,%edx /* 3rd arg: 2nd syscall arg */
207 movl %ebx,%esi /* 2nd arg: 1st syscall arg */
208 movl %eax,%edi /* 1st arg: syscall number */
Eric Parisb05d8442012-01-03 14:23:06 -0500209 call __audit_syscall_entry
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800210 movl RAX(%rsp),%eax /* reload syscall number */
H. Peter Anvin36d001c2010-09-14 12:42:41 -0700211 cmpq $(IA32_NR_syscalls-1),%rax
Roland McGrath5cbf1562008-06-24 01:13:31 -0700212 ja ia32_badsys
213 movl %ebx,%edi /* reload 1st syscall arg */
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800214 movl RCX(%rsp),%esi /* reload 2nd syscall arg */
215 movl RDX(%rsp),%edx /* reload 3rd syscall arg */
216 movl RSI(%rsp),%ecx /* reload 4th syscall arg */
217 movl RDI(%rsp),%r8d /* reload 5th syscall arg */
Roland McGrath5cbf1562008-06-24 01:13:31 -0700218 .endm
219
Jan Beulich81766742009-10-26 15:20:29 +0000220 .macro auditsys_exit exit
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800221 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP)
Jan Beulich24e35802009-09-30 11:22:11 +0100222 jnz ia32_ret_from_sys_call
Roland McGrath5cbf1562008-06-24 01:13:31 -0700223 TRACE_IRQS_ON
Jan Beulich40a1ef92013-01-30 07:55:53 +0000224 ENABLE_INTERRUPTS(CLBR_NONE)
Roland McGrath5cbf1562008-06-24 01:13:31 -0700225 movl %eax,%esi /* second arg, syscall return value */
Eric Parisd7e75282012-01-03 14:23:06 -0500226 cmpl $-MAX_ERRNO,%eax /* is it an error ? */
Eric Parisf031cd22012-01-03 14:23:06 -0500227 jbe 1f
228 movslq %eax, %rsi /* if error sign extend to 64 bits */
2291: setbe %al /* 1 if error, 0 if not */
Roland McGrath5cbf1562008-06-24 01:13:31 -0700230 movzbl %al,%edi /* zero-extend that into %edi */
Eric Parisd7e75282012-01-03 14:23:06 -0500231 call __audit_syscall_exit
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800232 movq RAX(%rsp),%rax /* reload syscall return value */
Roland McGrath5cbf1562008-06-24 01:13:31 -0700233 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
Jan Beulich40a1ef92013-01-30 07:55:53 +0000234 DISABLE_INTERRUPTS(CLBR_NONE)
Roland McGrath5cbf1562008-06-24 01:13:31 -0700235 TRACE_IRQS_OFF
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800236 testl %edi,TI_flags+THREAD_INFO(%rsp,RIP)
Jan Beulich24e35802009-09-30 11:22:11 +0100237 jz \exit
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800238 CLEAR_RREGS
Jan Beulich24e35802009-09-30 11:22:11 +0100239 jmp int_with_check
Roland McGrath5cbf1562008-06-24 01:13:31 -0700240 .endm
241
242sysenter_auditsys:
Roland McGrath5cbf1562008-06-24 01:13:31 -0700243 auditsys_entry_common
244 movl %ebp,%r9d /* reload 6th syscall arg */
245 jmp sysenter_dispatch
246
247sysexit_audit:
248 auditsys_exit sysexit_from_sys_call
249#endif
250
Andy Lutomirski8c7aa692014-10-01 11:49:04 -0700251sysenter_fix_flags:
252 pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED)
253 popfq_cfi
254 jmp sysenter_flags_fixed
255
Roland McGrath5cbf1562008-06-24 01:13:31 -0700256sysenter_tracesys:
Roland McGrath5cbf1562008-06-24 01:13:31 -0700257#ifdef CONFIG_AUDITSYSCALL
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800258 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP)
Roland McGrath5cbf1562008-06-24 01:13:31 -0700259 jz sysenter_auditsys
260#endif
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800261 SAVE_EXTRA_REGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 CLEAR_RREGS
Roland McGrath48ee6792008-03-18 18:23:50 -0700263 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 movq %rsp,%rdi /* &pt_regs -> arg1 */
265 call syscall_trace_enter
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800266 LOAD_ARGS32 /* reload args from stack in case ptrace changed it */
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800267 RESTORE_EXTRA_REGS
H. Peter Anvin36d001c2010-09-14 12:42:41 -0700268 cmpq $(IA32_NR_syscalls-1),%rax
Roland McGrath48ee6792008-03-18 18:23:50 -0700269 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 jmp sysenter_do_call
271 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200272ENDPROC(ia32_sysenter_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274/*
275 * 32bit SYSCALL instruction entry.
276 *
277 * Arguments:
278 * %eax System call number.
279 * %ebx Arg1
280 * %ecx return EIP
281 * %edx Arg3
282 * %esi Arg4
283 * %edi Arg5
284 * %ebp Arg2 [note: not saved in the stack frame, should not be touched]
285 * %esp user stack
286 * 0(%esp) Arg6
287 *
288 * Interrupts off.
289 *
290 * This is purely a fast path. For anything complicated we use the int 0x80
291 * path below. Set up a complete hardware stack frame to share code
292 * with the int 0x80 path.
293 */
294ENTRY(ia32_cstar_target)
Jan Beulich27651302006-01-11 22:41:59 +0100295 CFI_STARTPROC32 simple
Jan Beulichadf14232006-09-26 10:52:41 +0200296 CFI_SIGNAL_FRAME
Brian Gerst9af45652009-01-19 00:38:58 +0900297 CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
Jan Beulich7effaa82005-09-12 18:49:24 +0200298 CFI_REGISTER rip,rcx
299 /*CFI_REGISTER rflags,r11*/
Jeremy Fitzhardinge457da702008-06-26 07:28:51 -0700300 SWAPGS_UNSAFE_STACK
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 movl %esp,%r8d
Jan Beulich7effaa82005-09-12 18:49:24 +0200302 CFI_REGISTER rsp,r8
Brian Gerst9af45652009-01-19 00:38:58 +0900303 movq PER_CPU_VAR(kernel_stack),%rsp
Ingo Molnar2601e642006-07-03 00:24:45 -0700304 /*
305 * No need to follow this irqs on/off section: the syscall
306 * disabled irqs and here we enable it straight after entry:
307 */
Jeremy Fitzhardinge66804152008-06-25 00:19:29 -0400308 ENABLE_INTERRUPTS(CLBR_NONE)
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800309 ALLOC_PT_GPREGS_ON_STACK 8
310 SAVE_C_REGS_EXCEPT_RCX_R891011
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 movl %eax,%eax /* zero extension */
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800312 movq %rax,ORIG_RAX(%rsp)
313 movq %rcx,RIP(%rsp)
314 CFI_REL_OFFSET rip,RIP
315 movq %rbp,RCX(%rsp) /* this lies slightly to ptrace */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 movl %ebp,%ecx
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800317 movq $__USER32_CS,CS(%rsp)
318 movq $__USER32_DS,SS(%rsp)
319 movq %r11,EFLAGS(%rsp)
320 /*CFI_REL_OFFSET rflags,EFLAGS*/
321 movq %r8,RSP(%rsp)
322 CFI_REL_OFFSET rsp,RSP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 /* no need to do an access_ok check here because r8 has been
324 32bit zero extended */
325 /* hardware stack frame is complete now */
H. Peter Anvin63bcff22012-09-21 12:43:12 -0700326 ASM_STAC
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271: movl (%r8),%r9d
H. Peter Anvina3e859f2012-04-20 16:51:50 -0700328 _ASM_EXTABLE(1b,ia32_badarg)
H. Peter Anvin63bcff22012-09-21 12:43:12 -0700329 ASM_CLAC
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800330 orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP)
331 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP)
Jan Beulich7effaa82005-09-12 18:49:24 +0200332 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 jnz cstar_tracesys
H. Peter Anvin36d001c2010-09-14 12:42:41 -0700334 cmpq $IA32_NR_syscalls-1,%rax
Andi Kleen67d53ea2006-04-07 19:50:31 +0200335 ja ia32_badsys
Jan Beulich295286a2008-08-29 13:21:11 +0100336cstar_do_call:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 IA32_ARG_FIXUP 1
Roland McGrath5cbf1562008-06-24 01:13:31 -0700338cstar_dispatch:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 call *ia32_sys_call_table(,%rax,8)
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800340 movq %rax,RAX(%rsp)
Jeremy Fitzhardinge66804152008-06-25 00:19:29 -0400341 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700342 TRACE_IRQS_OFF
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800343 testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP)
Roland McGrath5cbf1562008-06-24 01:13:31 -0700344 jnz sysretl_audit
345sysretl_from_sys_call:
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800346 andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP)
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800347 RESTORE_RSI_RDI_RDX
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800348 movl RIP(%rsp),%ecx
Jan Beulich7effaa82005-09-12 18:49:24 +0200349 CFI_REGISTER rip,rcx
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800350 movl EFLAGS(%rsp),%r11d
Jan Beulich7effaa82005-09-12 18:49:24 +0200351 /*CFI_REGISTER rflags,r11*/
Jan Beulich24e35802009-09-30 11:22:11 +0100352 xorq %r10,%r10
353 xorq %r9,%r9
354 xorq %r8,%r8
Ingo Molnar2601e642006-07-03 00:24:45 -0700355 TRACE_IRQS_ON
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800356 movl RSP(%rsp),%esp
Jan Beulich7effaa82005-09-12 18:49:24 +0200357 CFI_RESTORE rsp
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400358 USERGS_SYSRET32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Roland McGrath5cbf1562008-06-24 01:13:31 -0700360#ifdef CONFIG_AUDITSYSCALL
361cstar_auditsys:
Jan Beulich7effaa82005-09-12 18:49:24 +0200362 CFI_RESTORE_STATE
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800363 movl %r9d,R9(%rsp) /* register to be clobbered by call */
Roland McGrath5cbf1562008-06-24 01:13:31 -0700364 auditsys_entry_common
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800365 movl R9(%rsp),%r9d /* reload 6th syscall arg */
Roland McGrath5cbf1562008-06-24 01:13:31 -0700366 jmp cstar_dispatch
367
368sysretl_audit:
Jan Beulich81766742009-10-26 15:20:29 +0000369 auditsys_exit sysretl_from_sys_call
Roland McGrath5cbf1562008-06-24 01:13:31 -0700370#endif
371
372cstar_tracesys:
373#ifdef CONFIG_AUDITSYSCALL
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800374 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP)
Roland McGrath5cbf1562008-06-24 01:13:31 -0700375 jz cstar_auditsys
376#endif
Chuck Ebbertecd744e2007-11-07 10:48:39 -0500377 xchgl %r9d,%ebp
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800378 SAVE_EXTRA_REGS
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800379 CLEAR_RREGS r9
Roland McGrath48ee6792008-03-18 18:23:50 -0700380 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 movq %rsp,%rdi /* &pt_regs -> arg1 */
382 call syscall_trace_enter
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800383 LOAD_ARGS32 1 /* reload args from stack in case ptrace changed it */
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800384 RESTORE_EXTRA_REGS
Chuck Ebbertecd744e2007-11-07 10:48:39 -0500385 xchgl %ebp,%r9d
H. Peter Anvin36d001c2010-09-14 12:42:41 -0700386 cmpq $(IA32_NR_syscalls-1),%rax
Roland McGrath48ee6792008-03-18 18:23:50 -0700387 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 jmp cstar_do_call
Jan Beulich4b787e02006-06-26 13:56:55 +0200389END(ia32_cstar_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391ia32_badarg:
H. Peter Anvin63bcff22012-09-21 12:43:12 -0700392 ASM_CLAC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 movq $-EFAULT,%rax
394 jmp ia32_sysret
395 CFI_ENDPROC
396
397/*
398 * Emulated IA32 system calls via int 0x80.
399 *
400 * Arguments:
401 * %eax System call number.
402 * %ebx Arg1
403 * %ecx Arg2
404 * %edx Arg3
405 * %esi Arg4
406 * %edi Arg5
407 * %ebp Arg6 [note: not saved in the stack frame, should not be touched]
408 *
409 * Notes:
410 * Uses the same stack frame as the x86-64 version.
411 * All registers except %eax must be saved (but ptrace may violate that)
412 * Arguments are zero extended. For system calls that want sign extension and
413 * take long arguments a wrapper is needed. Most calls can just be called
414 * directly.
415 * Assumes it is only called from user space and entered with interrupts off.
416 */
417
418ENTRY(ia32_syscall)
Jan Beulichcdc17932007-07-21 17:10:20 +0200419 CFI_STARTPROC32 simple
Jan Beulichadf14232006-09-26 10:52:41 +0200420 CFI_SIGNAL_FRAME
Jan Beulich7effaa82005-09-12 18:49:24 +0200421 CFI_DEF_CFA rsp,SS+8-RIP
422 /*CFI_REL_OFFSET ss,SS-RIP*/
423 CFI_REL_OFFSET rsp,RSP-RIP
424 /*CFI_REL_OFFSET rflags,EFLAGS-RIP*/
425 /*CFI_REL_OFFSET cs,CS-RIP*/
426 CFI_REL_OFFSET rip,RIP-RIP
Jeremy Fitzhardinge360c0442008-07-08 15:06:28 -0700427 PARAVIRT_ADJUST_EXCEPTION_FRAME
Jeremy Fitzhardinge66804152008-06-25 00:19:29 -0400428 SWAPGS
Ingo Molnar2601e642006-07-03 00:24:45 -0700429 /*
430 * No need to follow this irqs on/off section: the syscall
431 * disabled irqs and here we enable it straight after entry:
432 */
Jeremy Fitzhardinge66804152008-06-25 00:19:29 -0400433 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 movl %eax,%eax
Jan Beulich60cf6372011-02-28 15:54:40 +0000435 pushq_cfi %rax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 cld
437 /* note the registers are not zero extended to the sf.
438 this could be a problem. */
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800439 ALLOC_PT_GPREGS_ON_STACK
440 SAVE_C_REGS_EXCEPT_R891011
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800441 orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP)
442 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 jnz ia32_tracesys
H. Peter Anvin36d001c2010-09-14 12:42:41 -0700444 cmpq $(IA32_NR_syscalls-1),%rax
Roland McGrathc09249f2009-02-06 18:15:18 -0800445 ja ia32_badsys
446ia32_do_call:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 IA32_ARG_FIXUP
448 call *ia32_sys_call_table(,%rax,8) # xxx: rip relative
449ia32_sysret:
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800450 movq %rax,RAX(%rsp)
Jan Beulich24e35802009-09-30 11:22:11 +0100451ia32_ret_from_sys_call:
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800452 CLEAR_RREGS
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800453 jmp int_ret_from_sys_call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800455ia32_tracesys:
456 SAVE_EXTRA_REGS
Jan Beulichcdc17932007-07-21 17:10:20 +0200457 CLEAR_RREGS
Roland McGrath8ab32bb2008-03-16 21:57:41 -0700458 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 movq %rsp,%rdi /* &pt_regs -> arg1 */
460 call syscall_trace_enter
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800461 LOAD_ARGS32 /* reload args from stack in case ptrace changed it */
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800462 RESTORE_EXTRA_REGS
H. Peter Anvin36d001c2010-09-14 12:42:41 -0700463 cmpq $(IA32_NR_syscalls-1),%rax
Roland McGrathc09249f2009-02-06 18:15:18 -0800464 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
465 jmp ia32_do_call
Jan Beulich4b787e02006-06-26 13:56:55 +0200466END(ia32_syscall)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468ia32_badsys:
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800469 movq $0,ORIG_RAX(%rsp)
Jan Beulich24e35802009-09-30 11:22:11 +0100470 movq $-ENOSYS,%rax
471 jmp ia32_sysret
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 CFI_ENDPROC
474
Ramkumar Ramachandrad2475b82013-07-10 23:34:28 +0530475 .macro PTREGSCALL label, func
Jan Beulichf6b2bc82011-11-29 11:24:10 +0000476 ALIGN
477GLOBAL(\label)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 leaq \func(%rip),%rax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 jmp ia32_ptregs_common
480 .endm
481
Jan Beulich27651302006-01-11 22:41:59 +0100482 CFI_STARTPROC32
Jan Beulich7effaa82005-09-12 18:49:24 +0200483
Al Viro3fe26fa2012-11-12 14:32:42 -0500484 PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn
485 PTREGSCALL stub32_sigreturn, sys32_sigreturn
486 PTREGSCALL stub32_execve, compat_sys_execve
David Drysdale27d6ec72014-12-12 16:57:33 -0800487 PTREGSCALL stub32_execveat, compat_sys_execveat
Al Viro3fe26fa2012-11-12 14:32:42 -0500488 PTREGSCALL stub32_fork, sys_fork
489 PTREGSCALL stub32_vfork, sys_vfork
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Jan Beulichf6b2bc82011-11-29 11:24:10 +0000491 ALIGN
Al Viro1d4b4b22012-10-22 22:34:11 -0400492GLOBAL(stub32_clone)
493 leaq sys_clone(%rip),%rax
494 mov %r8, %rcx
495 jmp ia32_ptregs_common
496
497 ALIGN
Jan Beulichf6b2bc82011-11-29 11:24:10 +0000498ia32_ptregs_common:
Jan Beulich27651302006-01-11 22:41:59 +0100499 CFI_ENDPROC
500 CFI_STARTPROC32 simple
Jan Beulichadf14232006-09-26 10:52:41 +0200501 CFI_SIGNAL_FRAME
Denys Vlasenkof2db9382015-02-26 14:40:30 -0800502 CFI_DEF_CFA rsp,SS+8
503 CFI_REL_OFFSET rax,RAX
504 CFI_REL_OFFSET rcx,RCX
505 CFI_REL_OFFSET rdx,RDX
506 CFI_REL_OFFSET rsi,RSI
507 CFI_REL_OFFSET rdi,RDI
508 CFI_REL_OFFSET rip,RIP
509/* CFI_REL_OFFSET cs,CS*/
510/* CFI_REL_OFFSET rflags,EFLAGS*/
511 CFI_REL_OFFSET rsp,RSP
512/* CFI_REL_OFFSET ss,SS*/
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800513 SAVE_EXTRA_REGS 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 call *%rax
Denys Vlasenko76f5df42015-02-26 14:40:27 -0800515 RESTORE_EXTRA_REGS 8
516 ret
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200518END(ia32_ptregs_common)