]> sourceware.org Git - glibc.git/commitdiff
x86-64/setcontext: Pop the pointer into %rdx after syscall
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 2 May 2018 13:21:09 +0000 (06:21 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 2 May 2018 13:21:24 +0000 (06:21 -0700)
To prepare for shadow stack support, pop 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/setcontext.S (__setcontext):
Pop the pointer into %rdx after syscall and use %rdx, instead
of %rsi, to restore context.

ChangeLog
sysdeps/unix/sysv/linux/x86_64/setcontext.S

index da305b79d87cca35daceb10e98183a8d8229e203..8459d1e0bbf5aff9105338525cfd9cedb0369bfe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-05-02  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * sysdeps/unix/sysv/linux/x86_64/setcontext.S (__setcontext):
+       Pop the pointer into %rdx after syscall and use %rdx, instead
+       of %rsi, to restore context.
+
 2018-05-02  H.J. Lu  <hongjiu.lu@intel.com>
 
        * nptl/pthread_create.c (START_THREAD_DEFN): Clear previous
index 4a9b662074ddbd62d958d8db7ec09b9d5741ad59..b42af8e291eb8302091c4d65e0ce3a175d1cd31b 100644 (file)
@@ -44,21 +44,24 @@ ENTRY(__setcontext)
        movl    $_NSIG8,%r10d
        movl    $__NR_rt_sigprocmask, %eax
        syscall
-       popq    %rdi                    /* Reload %rdi, adjust stack.  */
+       /* Pop the pointer into RDX. The choice is arbitrary, but
+          leaving RDI and RSI available for use later can avoid
+          shuffling values.  */
+       popq    %rdx
        cfi_adjust_cfa_offset(-8)
        cmpq    $-4095, %rax            /* Check %rax for error.  */
        jae     SYSCALL_ERROR_LABEL     /* Jump to error handler if error.  */
 
        /* Restore the floating-point context.  Not the registers, only the
           rest.  */
-       movq    oFPREGS(%rdi), %rcx
+       movq    oFPREGS(%rdx), %rcx
        fldenv  (%rcx)
-       ldmxcsr oMXCSR(%rdi)
+       ldmxcsr oMXCSR(%rdx)
 
 
        /* Load the new stack pointer, the preserved registers and
           registers used for passing args.  */
-       cfi_def_cfa(%rdi, 0)
+       cfi_def_cfa(%rdx, 0)
        cfi_offset(%rbx,oRBX)
        cfi_offset(%rbp,oRBP)
        cfi_offset(%r12,oR12)
@@ -68,27 +71,27 @@ ENTRY(__setcontext)
        cfi_offset(%rsp,oRSP)
        cfi_offset(%rip,oRIP)
 
-       movq    oRSP(%rdi), %rsp
-       movq    oRBX(%rdi), %rbx
-       movq    oRBP(%rdi), %rbp
-       movq    oR12(%rdi), %r12
-       movq    oR13(%rdi), %r13
-       movq    oR14(%rdi), %r14
-       movq    oR15(%rdi), %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(%rdi), %rcx
+       movq    oRIP(%rdx), %rcx
        pushq   %rcx
 
-       movq    oRSI(%rdi), %rsi
-       movq    oRDX(%rdi), %rdx
-       movq    oRCX(%rdi), %rcx
-       movq    oR8(%rdi), %r8
-       movq    oR9(%rdi), %r9
+       movq    oRSI(%rdx), %rsi
+       movq    oRDI(%rdx), %rdi
+       movq    oRCX(%rdx), %rcx
+       movq    oR8(%rdx), %r8
+       movq    oR9(%rdx), %r9
 
-       /* Setup finally  %rdi.  */
-       movq    oRDI(%rdi), %rdi
+       /* Setup finally %rdx.  */
+       movq    oRDX(%rdx), %rdx
 
        /* End FDE here, we fall into another context.  */
        cfi_endproc
This page took 0.062518 seconds and 5 git commands to generate.