diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2018-04-26 05:01:20 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2018-05-02 06:26:19 -0700 |
commit | 15c19147a8361b7281519b9784b3b823c447cf7a (patch) | |
tree | b58c6146268ffd5f7b6dc5897dad0871f24518b6 | |
parent | 556f5c46c78f094d03b5e3e48900b7e4f312cc5e (diff) | |
download | glibc-15c19147a8361b7281519b9784b3b823c447cf7a.zip glibc-15c19147a8361b7281519b9784b3b823c447cf7a.tar.gz glibc-15c19147a8361b7281519b9784b3b823c447cf7a.tar.bz2 |
x86-64/swapcontext: Restore the pointer into %rdx after syscall
To prepare for shadow stack support, restore the pointer into %rdx after
syscall and use %rdx, instead of %rsi, to restore context. There is no
functional change.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
* sysdeps/unix/sysv/linux/x86_64/swapcontext.S (__swapcontext):
Restore the pointer into %rdx, after syscall and use %rdx,
instead of %rsi, to restore context.
-rw-r--r-- | sysdeps/unix/sysv/linux/x86_64/swapcontext.S | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S index e577c20..1110c47 100644 --- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S +++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S @@ -79,38 +79,40 @@ ENTRY(__swapcontext) cmpq $-4095, %rax /* Check %rax for error. */ jae SYSCALL_ERROR_LABEL /* Jump to error handler if error. */ - /* Restore destroyed registers. */ - movq %r12, %rsi + /* Restore destroyed register into RDX. The choice is arbitrary, + but leaving RDI and RSI available for use later can avoid + shuffling values. */ + movq %r12, %rdx /* Restore the floating-point context. Not the registers, only the rest. */ - movq oFPREGS(%rsi), %rcx + movq oFPREGS(%rdx), %rcx fldenv (%rcx) - ldmxcsr oMXCSR(%rsi) + ldmxcsr oMXCSR(%rdx) /* Load the new stack pointer and the preserved registers. */ - movq oRSP(%rsi), %rsp - movq oRBX(%rsi), %rbx - movq oRBP(%rsi), %rbp - movq oR12(%rsi), %r12 - movq oR13(%rsi), %r13 - movq oR14(%rsi), %r14 - movq oR15(%rsi), %r15 + movq oRSP(%rdx), %rsp + movq oRBX(%rdx), %rbx + movq oRBP(%rdx), %rbp + movq oR12(%rdx), %r12 + movq oR13(%rdx), %r13 + movq oR14(%rdx), %r14 + movq oR15(%rdx), %r15 /* The following ret should return to the address set with getcontext. Therefore push the address on the stack. */ - movq oRIP(%rsi), %rcx + movq oRIP(%rdx), %rcx pushq %rcx /* Setup registers used for passing args. */ - movq oRDI(%rsi), %rdi - movq oRDX(%rsi), %rdx - movq oRCX(%rsi), %rcx - movq oR8(%rsi), %r8 - movq oR9(%rsi), %r9 - - /* Setup finally %rsi. */ - movq oRSI(%rsi), %rsi + movq oRDI(%rdx), %rdi + movq oRSI(%rdx), %rsi + movq oRCX(%rdx), %rcx + movq oR8(%rdx), %r8 + movq oR9(%rdx), %r9 + + /* Setup finally %rdx. */ + movq oRDX(%rdx), %rdx /* Clear rax to indicate success. */ xorl %eax, %eax |