Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Compatibility mode system call entry point for x86-64. |
| 3 | * |
| 4 | * Copyright 2000-2002 Andi Kleen, SuSE Labs. |
| 5 | */ |
| 6 | |
Ingo Molnar | d36f947 | 2015-06-03 18:29:26 +0200 | [diff] [blame] | 7 | #include "calling.h" |
Sam Ravnborg | e2d5df9 | 2005-09-09 21:28:48 +0200 | [diff] [blame] | 8 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <asm/current.h> |
| 10 | #include <asm/errno.h> |
| 11 | #include <asm/ia32_unistd.h> |
| 12 | #include <asm/thread_info.h> |
| 13 | #include <asm/segment.h> |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 14 | #include <asm/irqflags.h> |
H. Peter Anvin | 1ce6f86 | 2012-04-20 12:19:50 -0700 | [diff] [blame] | 15 | #include <asm/asm.h> |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 16 | #include <asm/smap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/linkage.h> |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 18 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 20 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ |
| 21 | #include <linux/elf-em.h> |
| 22 | #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE) |
| 23 | #define __AUDIT_ARCH_LE 0x40000000 |
| 24 | |
| 25 | #ifndef CONFIG_AUDITSYSCALL |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 26 | #define sysexit_audit ia32_ret_from_sys_call |
| 27 | #define sysretl_audit ia32_ret_from_sys_call |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 28 | #endif |
| 29 | |
Jiri Olsa | ea71454 | 2011-03-07 19:10:39 +0100 | [diff] [blame] | 30 | .section .entry.text, "ax" |
| 31 | |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 32 | /* clobbers %rax */ |
| 33 | .macro CLEAR_RREGS _r9=rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | xorl %eax,%eax |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 35 | movq %rax,R11(%rsp) |
| 36 | movq %rax,R10(%rsp) |
| 37 | movq %\_r9,R9(%rsp) |
| 38 | movq %rax,R8(%rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | .endm |
| 40 | |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 41 | /* |
| 42 | * Reload arg registers from stack in case ptrace changed them. |
| 43 | * We don't reload %eax because syscall_trace_enter() returned |
Roland McGrath | eefdca0 | 2010-09-14 12:22:58 -0700 | [diff] [blame] | 44 | * the %rax value we should see. Instead, we just truncate that |
| 45 | * value to 32 bits again as we did on entry from user mode. |
| 46 | * If it's a new value set by user_regset during entry tracing, |
| 47 | * this matches the normal truncation of the user-mode value. |
| 48 | * If it's -1 to make us punt the syscall, then (u32)-1 is still |
| 49 | * an appropriately invalid value. |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 50 | */ |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 51 | .macro LOAD_ARGS32 _r9=0 |
Jan Beulich | 295286a | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 52 | .if \_r9 |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 53 | movl R9(%rsp),%r9d |
Jan Beulich | 295286a | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 54 | .endif |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 55 | movl RCX(%rsp),%ecx |
| 56 | movl RDX(%rsp),%edx |
| 57 | movl RSI(%rsp),%esi |
| 58 | movl RDI(%rsp),%edi |
Roland McGrath | eefdca0 | 2010-09-14 12:22:58 -0700 | [diff] [blame] | 59 | movl %eax,%eax /* zero extension */ |
Andi Kleen | 176df24 | 2007-09-21 16:16:18 +0200 | [diff] [blame] | 60 | .endm |
| 61 | |
Jan Beulich | 2765130 | 2006-01-11 22:41:59 +0100 | [diff] [blame] | 62 | |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 63 | #ifdef CONFIG_PARAVIRT |
| 64 | ENTRY(native_usergs_sysret32) |
| 65 | swapgs |
| 66 | sysretl |
| 67 | ENDPROC(native_usergs_sysret32) |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 68 | #endif |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* |
| 71 | * 32bit SYSENTER instruction entry. |
| 72 | * |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 73 | * SYSENTER loads ss, rsp, cs, and rip from previously programmed MSRs. |
| 74 | * IF and VM in rflags are cleared (IOW: interrupts are off). |
| 75 | * SYSENTER does not save anything on the stack, |
| 76 | * and does not save old rip (!!!) and rflags. |
| 77 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | * Arguments: |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 79 | * eax system call number |
| 80 | * ebx arg1 |
| 81 | * ecx arg2 |
| 82 | * edx arg3 |
| 83 | * esi arg4 |
| 84 | * edi arg5 |
| 85 | * ebp user stack |
| 86 | * 0(%ebp) arg6 |
| 87 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | * This is purely a fast path. For anything complicated we use the int 0x80 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 89 | * path below. We set up a complete hardware stack frame to share code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | * with the int 0x80 path. |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 91 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | ENTRY(ia32_sysenter_target) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 93 | /* |
| 94 | * Interrupts are off on entry. |
| 95 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, |
| 96 | * it is too small to ever cause noticeable irq latency. |
| 97 | */ |
Jeremy Fitzhardinge | 457da70 | 2008-06-26 07:28:51 -0700 | [diff] [blame] | 98 | SWAPGS_UNSAFE_STACK |
Denys Vlasenko | 3a23208 | 2015-04-24 17:31:35 +0200 | [diff] [blame] | 99 | movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 100 | ENABLE_INTERRUPTS(CLBR_NONE) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 101 | |
Denys Vlasenko | 4ee8ec1 | 2015-03-27 11:36:21 +0100 | [diff] [blame] | 102 | /* Zero-extending 32-bit regs, do not remove */ |
| 103 | movl %ebp, %ebp |
| 104 | movl %eax, %eax |
| 105 | |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 106 | movl ASM_THREAD_INFO(TI_sysenter_return, %rsp, 0), %r10d |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 107 | |
| 108 | /* Construct struct pt_regs on stack */ |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 109 | pushq $__USER32_DS /* pt_regs->ss */ |
| 110 | pushq %rbp /* pt_regs->sp */ |
| 111 | pushfq /* pt_regs->flags */ |
| 112 | pushq $__USER32_CS /* pt_regs->cs */ |
| 113 | pushq %r10 /* pt_regs->ip = thread_info->sysenter_return */ |
| 114 | pushq %rax /* pt_regs->orig_ax */ |
| 115 | pushq %rdi /* pt_regs->di */ |
| 116 | pushq %rsi /* pt_regs->si */ |
| 117 | pushq %rdx /* pt_regs->dx */ |
| 118 | pushq %rcx /* pt_regs->cx */ |
| 119 | pushq $-ENOSYS /* pt_regs->ax */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | cld |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 121 | sub $(10*8),%rsp /* pt_regs->r8-11,bp,bx,r12-15 not saved */ |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 122 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 123 | /* |
| 124 | * no need to do an access_ok check here because rbp has been |
| 125 | * 32bit zero extended |
| 126 | */ |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 127 | ASM_STAC |
Jan Beulich | 295286a | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 128 | 1: movl (%rbp),%ebp |
H. Peter Anvin | 1ce6f86 | 2012-04-20 12:19:50 -0700 | [diff] [blame] | 129 | _ASM_EXTABLE(1b,ia32_badarg) |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 130 | ASM_CLAC |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * Sysenter doesn't filter flags, so we need to clear NT |
| 134 | * ourselves. To save a few cycles, we can check whether |
| 135 | * NT was set instead of doing an unconditional popfq. |
| 136 | */ |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 137 | testl $X86_EFLAGS_NT,EFLAGS(%rsp) |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 138 | jnz sysenter_fix_flags |
| 139 | sysenter_flags_fixed: |
| 140 | |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 141 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
| 142 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | jnz sysenter_tracesys |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 144 | |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 145 | sysenter_do_call: |
Denys Vlasenko | 14f6e95 | 2015-02-26 14:40:35 -0800 | [diff] [blame] | 146 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
| 147 | movl %edi,%r8d /* arg5 */ |
| 148 | movl %ebp,%r9d /* arg6 */ |
| 149 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ |
| 150 | movl %ebx,%edi /* arg1 */ |
| 151 | movl %edx,%edx /* arg3 (zero extension) */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 152 | sysenter_dispatch: |
Denys Vlasenko | 3f5159a | 2015-04-21 18:03:14 +0200 | [diff] [blame] | 153 | cmpq $(IA32_NR_syscalls-1),%rax |
| 154 | ja 1f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | call *ia32_sys_call_table(,%rax,8) |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 156 | movq %rax,RAX(%rsp) |
Denys Vlasenko | 3f5159a | 2015-04-21 18:03:14 +0200 | [diff] [blame] | 157 | 1: |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 158 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 159 | TRACE_IRQS_OFF |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 160 | testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 161 | jnz sysexit_audit |
| 162 | sysexit_from_sys_call: |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 163 | /* |
| 164 | * NB: SYSEXIT is not obviously safe for 64-bit kernels -- an |
| 165 | * NMI between STI and SYSEXIT has poorly specified behavior, |
| 166 | * and and NMI followed by an IRQ with usergs is fatal. So |
| 167 | * we just pretend we're using SYSEXIT but we really use |
| 168 | * SYSRETL instead. |
| 169 | * |
| 170 | * This code path is still called 'sysexit' because it pairs |
| 171 | * with 'sysenter' and it uses the SYSENTER calling convention. |
| 172 | */ |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 173 | andl $~TS_COMPAT,ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 174 | movl RIP(%rsp),%ecx /* User %eip */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 175 | RESTORE_RSI_RDI |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 176 | xorl %edx,%edx /* avoid info leaks */ |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 177 | xorq %r8,%r8 |
| 178 | xorq %r9,%r9 |
| 179 | xorq %r10,%r10 |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 180 | movl EFLAGS(%rsp),%r11d /* User eflags */ |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 181 | TRACE_IRQS_ON |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 182 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 183 | /* |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 184 | * SYSRETL works even on Intel CPUs. Use it in preference to SYSEXIT, |
| 185 | * since it avoids a dicey window with interrupts enabled. |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 186 | */ |
Andy Lutomirski | 4214a16 | 2015-04-02 17:12:12 -0700 | [diff] [blame] | 187 | movl RSP(%rsp),%esp |
| 188 | |
| 189 | /* |
| 190 | * USERGS_SYSRET32 does: |
| 191 | * gsbase = user's gs base |
| 192 | * eip = ecx |
| 193 | * rflags = r11 |
| 194 | * cs = __USER32_CS |
| 195 | * ss = __USER_DS |
| 196 | * |
| 197 | * The prologue set RIP(%rsp) to VDSO32_SYSENTER_RETURN, which does: |
| 198 | * |
| 199 | * pop %ebp |
| 200 | * pop %edx |
| 201 | * pop %ecx |
| 202 | * |
| 203 | * Therefore, we invoke SYSRETL with EDX and R8-R10 zeroed to |
| 204 | * avoid info leaks. R11 ends up with VDSO32_SYSENTER_RETURN's |
| 205 | * address (already known to user code), and R12-R15 are |
| 206 | * callee-saved and therefore don't contain any interesting |
| 207 | * kernel data. |
| 208 | */ |
| 209 | USERGS_SYSRET32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 211 | #ifdef CONFIG_AUDITSYSCALL |
| 212 | .macro auditsys_entry_common |
Richard Guy Briggs | b4f0d37 | 2014-03-04 10:38:06 -0500 | [diff] [blame] | 213 | movl %esi,%r8d /* 5th arg: 4th syscall arg */ |
| 214 | movl %ecx,%r9d /*swap with edx*/ |
| 215 | movl %edx,%ecx /* 4th arg: 3rd syscall arg */ |
| 216 | movl %r9d,%edx /* 3rd arg: 2nd syscall arg */ |
| 217 | movl %ebx,%esi /* 2nd arg: 1st syscall arg */ |
| 218 | movl %eax,%edi /* 1st arg: syscall number */ |
Eric Paris | b05d844 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 219 | call __audit_syscall_entry |
Denys Vlasenko | 3f5159a | 2015-04-21 18:03:14 +0200 | [diff] [blame] | 220 | movl ORIG_RAX(%rsp),%eax /* reload syscall number */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 221 | movl %ebx,%edi /* reload 1st syscall arg */ |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 222 | movl RCX(%rsp),%esi /* reload 2nd syscall arg */ |
| 223 | movl RDX(%rsp),%edx /* reload 3rd syscall arg */ |
| 224 | movl RSI(%rsp),%ecx /* reload 4th syscall arg */ |
| 225 | movl RDI(%rsp),%r8d /* reload 5th syscall arg */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 226 | .endm |
| 227 | |
Jan Beulich | 8176674 | 2009-10-26 15:20:29 +0000 | [diff] [blame] | 228 | .macro auditsys_exit exit |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 229 | testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 230 | jnz ia32_ret_from_sys_call |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 231 | TRACE_IRQS_ON |
Jan Beulich | 40a1ef9 | 2013-01-30 07:55:53 +0000 | [diff] [blame] | 232 | ENABLE_INTERRUPTS(CLBR_NONE) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 233 | movl %eax,%esi /* second arg, syscall return value */ |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 234 | cmpl $-MAX_ERRNO,%eax /* is it an error ? */ |
Eric Paris | f031cd2 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 235 | jbe 1f |
| 236 | movslq %eax, %rsi /* if error sign extend to 64 bits */ |
| 237 | 1: setbe %al /* 1 if error, 0 if not */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 238 | movzbl %al,%edi /* zero-extend that into %edi */ |
Eric Paris | d7e7528 | 2012-01-03 14:23:06 -0500 | [diff] [blame] | 239 | call __audit_syscall_exit |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 240 | movq RAX(%rsp),%rax /* reload syscall return value */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 241 | movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi |
Jan Beulich | 40a1ef9 | 2013-01-30 07:55:53 +0000 | [diff] [blame] | 242 | DISABLE_INTERRUPTS(CLBR_NONE) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 243 | TRACE_IRQS_OFF |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 244 | testl %edi, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 245 | jz \exit |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 246 | CLEAR_RREGS |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 247 | jmp int_with_check |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 248 | .endm |
| 249 | |
| 250 | sysenter_auditsys: |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 251 | auditsys_entry_common |
| 252 | movl %ebp,%r9d /* reload 6th syscall arg */ |
| 253 | jmp sysenter_dispatch |
| 254 | |
| 255 | sysexit_audit: |
| 256 | auditsys_exit sysexit_from_sys_call |
| 257 | #endif |
| 258 | |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 259 | sysenter_fix_flags: |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 260 | pushq $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) |
| 261 | popfq |
Andy Lutomirski | 8c7aa69 | 2014-10-01 11:49:04 -0700 | [diff] [blame] | 262 | jmp sysenter_flags_fixed |
| 263 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 264 | sysenter_tracesys: |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 265 | #ifdef CONFIG_AUDITSYSCALL |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 266 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 267 | jz sysenter_auditsys |
| 268 | #endif |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 269 | SAVE_EXTRA_REGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | CLEAR_RREGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
| 272 | call syscall_trace_enter |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 273 | LOAD_ARGS32 /* reload args from stack in case ptrace changed it */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 274 | RESTORE_EXTRA_REGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | jmp sysenter_do_call |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 276 | ENDPROC(ia32_sysenter_target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | /* |
| 279 | * 32bit SYSCALL instruction entry. |
| 280 | * |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 281 | * 32bit SYSCALL saves rip to rcx, clears rflags.RF, then saves rflags to r11, |
| 282 | * then loads new ss, cs, and rip from previously programmed MSRs. |
| 283 | * rflags gets masked by a value from another MSR (so CLD and CLAC |
| 284 | * are not needed). SYSCALL does not save anything on the stack |
| 285 | * and does not change rsp. |
| 286 | * |
| 287 | * Note: rflags saving+masking-with-MSR happens only in Long mode |
| 288 | * (in legacy 32bit mode, IF, RF and VM bits are cleared and that's it). |
| 289 | * Don't get confused: rflags saving+masking depends on Long Mode Active bit |
| 290 | * (EFER.LMA=1), NOT on bitness of userspace where SYSCALL executes |
| 291 | * or target CS descriptor's L bit (SYSCALL does not read segment descriptors). |
| 292 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | * Arguments: |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 294 | * eax system call number |
| 295 | * ecx return address |
| 296 | * ebx arg1 |
| 297 | * ebp arg2 (note: not saved in the stack frame, should not be touched) |
| 298 | * edx arg3 |
| 299 | * esi arg4 |
| 300 | * edi arg5 |
| 301 | * esp user stack |
| 302 | * 0(%esp) arg6 |
| 303 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | * This is purely a fast path. For anything complicated we use the int 0x80 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 305 | * path below. We set up a complete hardware stack frame to share code |
| 306 | * with the int 0x80 path. |
| 307 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | ENTRY(ia32_cstar_target) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 309 | /* |
| 310 | * Interrupts are off on entry. |
| 311 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, |
| 312 | * it is too small to ever cause noticeable irq latency. |
| 313 | */ |
Jeremy Fitzhardinge | 457da70 | 2008-06-26 07:28:51 -0700 | [diff] [blame] | 314 | SWAPGS_UNSAFE_STACK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | movl %esp,%r8d |
Denys Vlasenko | 3a23208 | 2015-04-24 17:31:35 +0200 | [diff] [blame] | 316 | movq PER_CPU_VAR(cpu_current_top_of_stack),%rsp |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 317 | ENABLE_INTERRUPTS(CLBR_NONE) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 318 | |
Denys Vlasenko | 4ee8ec1 | 2015-03-27 11:36:21 +0100 | [diff] [blame] | 319 | /* Zero-extending 32-bit regs, do not remove */ |
| 320 | movl %eax,%eax |
| 321 | |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 322 | /* Construct struct pt_regs on stack */ |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 323 | pushq $__USER32_DS /* pt_regs->ss */ |
| 324 | pushq %r8 /* pt_regs->sp */ |
| 325 | pushq %r11 /* pt_regs->flags */ |
| 326 | pushq $__USER32_CS /* pt_regs->cs */ |
| 327 | pushq %rcx /* pt_regs->ip */ |
| 328 | pushq %rax /* pt_regs->orig_ax */ |
| 329 | pushq %rdi /* pt_regs->di */ |
| 330 | pushq %rsi /* pt_regs->si */ |
| 331 | pushq %rdx /* pt_regs->dx */ |
| 332 | pushq %rbp /* pt_regs->cx */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | movl %ebp,%ecx |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 334 | pushq $-ENOSYS /* pt_regs->ax */ |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 335 | sub $(10*8),%rsp /* pt_regs->r8-11,bp,bx,r12-15 not saved */ |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 336 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 337 | /* |
| 338 | * no need to do an access_ok check here because r8 has been |
| 339 | * 32bit zero extended |
| 340 | */ |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 341 | ASM_STAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | 1: movl (%r8),%r9d |
H. Peter Anvin | a3e859f | 2012-04-20 16:51:50 -0700 | [diff] [blame] | 343 | _ASM_EXTABLE(1b,ia32_badarg) |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 344 | ASM_CLAC |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 345 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
| 346 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | jnz cstar_tracesys |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 348 | |
Jan Beulich | 295286a | 2008-08-29 13:21:11 +0100 | [diff] [blame] | 349 | cstar_do_call: |
Denys Vlasenko | 14f6e95 | 2015-02-26 14:40:35 -0800 | [diff] [blame] | 350 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
| 351 | movl %edi,%r8d /* arg5 */ |
| 352 | /* r9 already loaded */ /* arg6 */ |
| 353 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ |
| 354 | movl %ebx,%edi /* arg1 */ |
| 355 | movl %edx,%edx /* arg3 (zero extension) */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 356 | cstar_dispatch: |
Denys Vlasenko | 3f5159a | 2015-04-21 18:03:14 +0200 | [diff] [blame] | 357 | cmpq $(IA32_NR_syscalls-1),%rax |
| 358 | ja 1f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | call *ia32_sys_call_table(,%rax,8) |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 360 | movq %rax,RAX(%rsp) |
Denys Vlasenko | 3f5159a | 2015-04-21 18:03:14 +0200 | [diff] [blame] | 361 | 1: |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 362 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 363 | TRACE_IRQS_OFF |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 364 | testl $_TIF_ALLWORK_MASK, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 365 | jnz sysretl_audit |
| 366 | sysretl_from_sys_call: |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 367 | andl $~TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 368 | RESTORE_RSI_RDI_RDX |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 369 | movl RIP(%rsp),%ecx |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 370 | movl EFLAGS(%rsp),%r11d |
Jan Beulich | 24e3580 | 2009-09-30 11:22:11 +0100 | [diff] [blame] | 371 | xorq %r10,%r10 |
| 372 | xorq %r9,%r9 |
| 373 | xorq %r8,%r8 |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 374 | TRACE_IRQS_ON |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 375 | movl RSP(%rsp),%esp |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 376 | /* |
| 377 | * 64bit->32bit SYSRET restores eip from ecx, |
| 378 | * eflags from r11 (but RF and VM bits are forced to 0), |
| 379 | * cs and ss are loaded from MSRs. |
| 380 | * (Note: 32bit->32bit SYSRET is different: since r11 |
| 381 | * does not exist, it merely sets eflags.IF=1). |
Andy Lutomirski | 61f01dd | 2015-04-26 16:47:59 -0700 | [diff] [blame] | 382 | * |
| 383 | * NB: On AMD CPUs with the X86_BUG_SYSRET_SS_ATTRS bug, the ss |
| 384 | * descriptor is not reinitialized. This means that we must |
| 385 | * avoid SYSRET with SS == NULL, which could happen if we schedule, |
| 386 | * exit the kernel, and re-enter using an interrupt vector. (All |
| 387 | * interrupt entries on x86_64 set SS to NULL.) We prevent that |
| 388 | * from happening by reloading SS in __switch_to. |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 389 | */ |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 390 | USERGS_SYSRET32 |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 391 | |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 392 | #ifdef CONFIG_AUDITSYSCALL |
| 393 | cstar_auditsys: |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 394 | movl %r9d,R9(%rsp) /* register to be clobbered by call */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 395 | auditsys_entry_common |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 396 | movl R9(%rsp),%r9d /* reload 6th syscall arg */ |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 397 | jmp cstar_dispatch |
| 398 | |
| 399 | sysretl_audit: |
Jan Beulich | 8176674 | 2009-10-26 15:20:29 +0000 | [diff] [blame] | 400 | auditsys_exit sysretl_from_sys_call |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 401 | #endif |
| 402 | |
| 403 | cstar_tracesys: |
| 404 | #ifdef CONFIG_AUDITSYSCALL |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 405 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT), ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 406 | jz cstar_auditsys |
| 407 | #endif |
Chuck Ebbert | ecd744e | 2007-11-07 10:48:39 -0500 | [diff] [blame] | 408 | xchgl %r9d,%ebp |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 409 | SAVE_EXTRA_REGS |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 410 | CLEAR_RREGS r9 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
| 412 | call syscall_trace_enter |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 413 | LOAD_ARGS32 1 /* reload args from stack in case ptrace changed it */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 414 | RESTORE_EXTRA_REGS |
Chuck Ebbert | ecd744e | 2007-11-07 10:48:39 -0500 | [diff] [blame] | 415 | xchgl %ebp,%r9d |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | jmp cstar_do_call |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 417 | END(ia32_cstar_target) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | ia32_badarg: |
H. Peter Anvin | 63bcff2 | 2012-09-21 12:43:12 -0700 | [diff] [blame] | 420 | ASM_CLAC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | movq $-EFAULT,%rax |
| 422 | jmp ia32_sysret |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Denys Vlasenko | 61b1e3e | 2015-06-02 19:35:10 +0200 | [diff] [blame^] | 424 | ia32_ret_from_sys_call: |
| 425 | CLEAR_RREGS |
| 426 | jmp int_ret_from_sys_call |
| 427 | |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 428 | /* |
| 429 | * Emulated IA32 system calls via int 0x80. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | * |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 431 | * Arguments: |
| 432 | * eax system call number |
| 433 | * ebx arg1 |
| 434 | * ecx arg2 |
| 435 | * edx arg3 |
| 436 | * esi arg4 |
| 437 | * edi arg5 |
| 438 | * ebp arg6 (note: not saved in the stack frame, should not be touched) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | * |
| 440 | * Notes: |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 441 | * Uses the same stack frame as the x86-64 version. |
| 442 | * All registers except eax must be saved (but ptrace may violate that). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | * Arguments are zero extended. For system calls that want sign extension and |
| 444 | * take long arguments a wrapper is needed. Most calls can just be called |
| 445 | * directly. |
Denys Vlasenko | b87cf63 | 2015-02-26 14:40:32 -0800 | [diff] [blame] | 446 | * Assumes it is only called from user space and entered with interrupts off. |
| 447 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | ENTRY(ia32_syscall) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 450 | /* |
| 451 | * Interrupts are off on entry. |
| 452 | * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON, |
| 453 | * it is too small to ever cause noticeable irq latency. |
| 454 | */ |
Jeremy Fitzhardinge | 360c044 | 2008-07-08 15:06:28 -0700 | [diff] [blame] | 455 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 456 | SWAPGS |
Jeremy Fitzhardinge | 6680415 | 2008-06-25 00:19:29 -0400 | [diff] [blame] | 457 | ENABLE_INTERRUPTS(CLBR_NONE) |
Denys Vlasenko | a232e3d | 2015-03-27 11:36:20 +0100 | [diff] [blame] | 458 | |
Denys Vlasenko | 4ee8ec1 | 2015-03-27 11:36:21 +0100 | [diff] [blame] | 459 | /* Zero-extending 32-bit regs, do not remove */ |
| 460 | movl %eax,%eax |
| 461 | |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 462 | /* Construct struct pt_regs on stack (iret frame is already on stack) */ |
Ingo Molnar | 131484c | 2015-05-28 12:21:47 +0200 | [diff] [blame] | 463 | pushq %rax /* pt_regs->orig_ax */ |
| 464 | pushq %rdi /* pt_regs->di */ |
| 465 | pushq %rsi /* pt_regs->si */ |
| 466 | pushq %rdx /* pt_regs->dx */ |
| 467 | pushq %rcx /* pt_regs->cx */ |
| 468 | pushq $-ENOSYS /* pt_regs->ax */ |
Denys Vlasenko | 61b1e3e | 2015-06-02 19:35:10 +0200 | [diff] [blame^] | 469 | pushq $0 /* pt_regs->r8 */ |
| 470 | pushq $0 /* pt_regs->r9 */ |
| 471 | pushq $0 /* pt_regs->r10 */ |
| 472 | pushq $0 /* pt_regs->r11 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | cld |
Denys Vlasenko | 61b1e3e | 2015-06-02 19:35:10 +0200 | [diff] [blame^] | 474 | sub $(6*8),%rsp /* pt_regs->bp,bx,r12-15 not saved */ |
Denys Vlasenko | 4c9c0e9 | 2015-03-31 19:00:04 +0200 | [diff] [blame] | 475 | |
Ingo Molnar | dca5b52 | 2015-03-24 19:44:42 +0100 | [diff] [blame] | 476 | orl $TS_COMPAT, ASM_THREAD_INFO(TI_status, %rsp, SIZEOF_PTREGS) |
| 477 | testl $_TIF_WORK_SYSCALL_ENTRY, ASM_THREAD_INFO(TI_flags, %rsp, SIZEOF_PTREGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | jnz ia32_tracesys |
Roland McGrath | c09249f | 2009-02-06 18:15:18 -0800 | [diff] [blame] | 479 | ia32_do_call: |
Denys Vlasenko | 14f6e95 | 2015-02-26 14:40:35 -0800 | [diff] [blame] | 480 | /* 32bit syscall -> 64bit C ABI argument conversion */ |
| 481 | movl %edi,%r8d /* arg5 */ |
| 482 | movl %ebp,%r9d /* arg6 */ |
| 483 | xchg %ecx,%esi /* rsi:arg2, rcx:arg4 */ |
| 484 | movl %ebx,%edi /* arg1 */ |
| 485 | movl %edx,%edx /* arg3 (zero extension) */ |
Denys Vlasenko | 3f5159a | 2015-04-21 18:03:14 +0200 | [diff] [blame] | 486 | cmpq $(IA32_NR_syscalls-1),%rax |
| 487 | ja 1f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | call *ia32_sys_call_table(,%rax,8) # xxx: rip relative |
| 489 | ia32_sysret: |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 490 | movq %rax,RAX(%rsp) |
Denys Vlasenko | 3f5159a | 2015-04-21 18:03:14 +0200 | [diff] [blame] | 491 | 1: |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 492 | jmp int_ret_from_sys_call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 494 | ia32_tracesys: |
| 495 | SAVE_EXTRA_REGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | movq %rsp,%rdi /* &pt_regs -> arg1 */ |
| 497 | call syscall_trace_enter |
Denys Vlasenko | f2db938 | 2015-02-26 14:40:30 -0800 | [diff] [blame] | 498 | LOAD_ARGS32 /* reload args from stack in case ptrace changed it */ |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 499 | RESTORE_EXTRA_REGS |
Roland McGrath | c09249f | 2009-02-06 18:15:18 -0800 | [diff] [blame] | 500 | jmp ia32_do_call |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 501 | END(ia32_syscall) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
Ramkumar Ramachandra | d2475b8 | 2013-07-10 23:34:28 +0530 | [diff] [blame] | 503 | .macro PTREGSCALL label, func |
Jan Beulich | f6b2bc8 | 2011-11-29 11:24:10 +0000 | [diff] [blame] | 504 | ALIGN |
| 505 | GLOBAL(\label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | leaq \func(%rip),%rax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | jmp ia32_ptregs_common |
| 508 | .endm |
| 509 | |
Al Viro | 3fe26fa | 2012-11-12 14:32:42 -0500 | [diff] [blame] | 510 | PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn |
| 511 | PTREGSCALL stub32_sigreturn, sys32_sigreturn |
Al Viro | 3fe26fa | 2012-11-12 14:32:42 -0500 | [diff] [blame] | 512 | PTREGSCALL stub32_fork, sys_fork |
| 513 | PTREGSCALL stub32_vfork, sys_vfork |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
Jan Beulich | f6b2bc8 | 2011-11-29 11:24:10 +0000 | [diff] [blame] | 515 | ALIGN |
Al Viro | 1d4b4b2 | 2012-10-22 22:34:11 -0400 | [diff] [blame] | 516 | GLOBAL(stub32_clone) |
| 517 | leaq sys_clone(%rip),%rax |
| 518 | mov %r8, %rcx |
| 519 | jmp ia32_ptregs_common |
| 520 | |
| 521 | ALIGN |
Jan Beulich | f6b2bc8 | 2011-11-29 11:24:10 +0000 | [diff] [blame] | 522 | ia32_ptregs_common: |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 523 | SAVE_EXTRA_REGS 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | call *%rax |
Denys Vlasenko | 76f5df4 | 2015-02-26 14:40:27 -0800 | [diff] [blame] | 525 | RESTORE_EXTRA_REGS 8 |
| 526 | ret |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 527 | END(ia32_ptregs_common) |