1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
| extern int setcontext (const ucontext_t *__ucp) __THROWNL;
#include <sysdep.h> #include <asm/prctl.h> #include "ucontext_i.h"
ENTRY(__setcontext) pushq %rdi cfi_adjust_cfa_offset(8)
leaq oSIGMASK(%rdi), %rsi xorl %edx, %edx movl $SIG_SETMASK, %edi movl $_NSIG8,%r10d movl $__NR_rt_sigprocmask, %eax syscall
popq %rdx cfi_adjust_cfa_offset(-8) cmpq $-4095, %rax jae SYSCALL_ERROR_LABEL
movq oFPREGS(%rdx), %rcx fldenv (%rcx) ldmxcsr oMXCSR(%rdx)
cfi_def_cfa(%rdx, 0) cfi_offset(%rbx,oRBX) cfi_offset(%rbp,oRBP) cfi_offset(%r12,oR12) cfi_offset(%r13,oR13) cfi_offset(%r14,oR14) cfi_offset(%r15,oR15) cfi_offset(%rsp,oRSP) cfi_offset(%rip,oRIP) 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 #if SHSTK_ENABLED testl $X86_FEATURE_1_SHSTK, %fs:FEATURE_1_OFFSET jz L(no_shstk)
movq oSSP(%rdx), %rsi movq %rsi, %rdi movq (oSSP + 8)(%rdx), %rcx cmpq %fs:SSP_BASE_OFFSET, %rcx je L(unwind_shadow_stack) L(find_restore_token_loop): movq -8(%rsi), %rax andq $-8, %rax cmpq %rsi, %rax je L(restore_shadow_stack) subq $8, %rsi jmp L(find_restore_token_loop) L(restore_shadow_stack):
movq $1, %rax incsspq %rax rstorssp -8(%rsi)
saveprevssp movq (oSSP + 8)(%rdx), %rax movq %rax, %fs:SSP_BASE_OFFSET L(unwind_shadow_stack): rdsspq %rcx subq %rdi, %rcx je L(skip_unwind_shadow_stack) negq %rcx shrq $3, %rcx movl $255, %esi L(loop): cmpq %rsi, %rcx cmovb %rcx, %rsi incsspq %rsi subq %rsi, %rcx ja L(loop) L(skip_unwind_shadow_stack): movq oRSI(%rdx), %rsi movq oRDI(%rdx), %rdi movq oRCX(%rdx), %rcx movq oR8(%rdx), %r8 movq oR9(%rdx), %r9 movq oRIP(%rdx), %r10 movq oRDX(%rdx), %rdx
rdsspq %rax cmpq (%rax), %r10
movl $0, %eax jne L(jmp) pushq %r10 ret L(jmp): jmp *%r10 L(no_shstk): #endif
movq oRIP(%rdx), %rcx pushq %rcx movq oRSI(%rdx), %rsi movq oRDI(%rdx), %rdi movq oRCX(%rdx), %rcx movq oR8(%rdx), %r8 movq oR9(%rdx), %r9 movq oRDX(%rdx), %rdx cfi_endproc cfi_startproc xorl %eax, %eax ret PSEUDO_END(__setcontext) weak_alias (__setcontext, setcontext)
|