entry_64_compat.S 17 KB

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