1 #include "sanitizer_common/sanitizer_asm.h" 2 .section .text 3 4 .hidden __tsan_trace_switch 5 .globl __tsan_trace_switch_thunk 6 __tsan_trace_switch_thunk: 7 CFI_STARTPROC 8 # Save scratch registers. 9 push %rax 10 CFI_ADJUST_CFA_OFFSET(8) 11 CFI_REL_OFFSET(%rax, 0) 12 push %rcx 13 CFI_ADJUST_CFA_OFFSET(8) 14 CFI_REL_OFFSET(%rcx, 0) 15 push %rdx 16 CFI_ADJUST_CFA_OFFSET(8) 17 CFI_REL_OFFSET(%rdx, 0) 18 push %rsi 19 CFI_ADJUST_CFA_OFFSET(8) 20 CFI_REL_OFFSET(%rsi, 0) 21 push %rdi 22 CFI_ADJUST_CFA_OFFSET(8) 23 CFI_REL_OFFSET(%rdi, 0) 24 push %r8 25 CFI_ADJUST_CFA_OFFSET(8) 26 CFI_REL_OFFSET(%r8, 0) 27 push %r9 28 CFI_ADJUST_CFA_OFFSET(8) 29 CFI_REL_OFFSET(%r9, 0) 30 push %r10 31 CFI_ADJUST_CFA_OFFSET(8) 32 CFI_REL_OFFSET(%r10, 0) 33 push %r11 34 CFI_ADJUST_CFA_OFFSET(8) 35 CFI_REL_OFFSET(%r11, 0) 36 # Align stack frame. 37 push %rbx # non-scratch 38 CFI_ADJUST_CFA_OFFSET(8) 39 CFI_REL_OFFSET(%rbx, 0) 40 mov %rsp, %rbx # save current rsp 41 CFI_DEF_CFA_REGISTER(%rbx) 42 shr $4, %rsp # clear 4 lsb, align to 16 43 shl $4, %rsp 44 45 call __tsan_trace_switch 46 47 # Unalign stack frame back. 48 mov %rbx, %rsp # restore the original rsp 49 CFI_DEF_CFA_REGISTER(%rsp) 50 pop %rbx 51 CFI_ADJUST_CFA_OFFSET(-8) 52 # Restore scratch registers. 53 pop %r11 54 CFI_ADJUST_CFA_OFFSET(-8) 55 pop %r10 56 CFI_ADJUST_CFA_OFFSET(-8) 57 pop %r9 58 CFI_ADJUST_CFA_OFFSET(-8) 59 pop %r8 60 CFI_ADJUST_CFA_OFFSET(-8) 61 pop %rdi 62 CFI_ADJUST_CFA_OFFSET(-8) 63 pop %rsi 64 CFI_ADJUST_CFA_OFFSET(-8) 65 pop %rdx 66 CFI_ADJUST_CFA_OFFSET(-8) 67 pop %rcx 68 CFI_ADJUST_CFA_OFFSET(-8) 69 pop %rax 70 CFI_ADJUST_CFA_OFFSET(-8) 71 CFI_RESTORE(%rax) 72 CFI_RESTORE(%rbx) 73 CFI_RESTORE(%rcx) 74 CFI_RESTORE(%rdx) 75 CFI_RESTORE(%rsi) 76 CFI_RESTORE(%rdi) 77 CFI_RESTORE(%r8) 78 CFI_RESTORE(%r9) 79 CFI_RESTORE(%r10) 80 CFI_RESTORE(%r11) 81 ret 82 CFI_ENDPROC 83 84 .hidden __tsan_report_race 85 .globl __tsan_report_race_thunk 86 __tsan_report_race_thunk: 87 CFI_STARTPROC 88 # Save scratch registers. 89 push %rax 90 CFI_ADJUST_CFA_OFFSET(8) 91 CFI_REL_OFFSET(%rax, 0) 92 push %rcx 93 CFI_ADJUST_CFA_OFFSET(8) 94 CFI_REL_OFFSET(%rcx, 0) 95 push %rdx 96 CFI_ADJUST_CFA_OFFSET(8) 97 CFI_REL_OFFSET(%rdx, 0) 98 push %rsi 99 CFI_ADJUST_CFA_OFFSET(8) 100 CFI_REL_OFFSET(%rsi, 0) 101 push %rdi 102 CFI_ADJUST_CFA_OFFSET(8) 103 CFI_REL_OFFSET(%rdi, 0) 104 push %r8 105 CFI_ADJUST_CFA_OFFSET(8) 106 CFI_REL_OFFSET(%r8, 0) 107 push %r9 108 CFI_ADJUST_CFA_OFFSET(8) 109 CFI_REL_OFFSET(%r9, 0) 110 push %r10 111 CFI_ADJUST_CFA_OFFSET(8) 112 CFI_REL_OFFSET(%r10, 0) 113 push %r11 114 CFI_ADJUST_CFA_OFFSET(8) 115 CFI_REL_OFFSET(%r11, 0) 116 # Align stack frame. 117 push %rbx # non-scratch 118 CFI_ADJUST_CFA_OFFSET(8) 119 CFI_REL_OFFSET(%rbx, 0) 120 mov %rsp, %rbx # save current rsp 121 CFI_DEF_CFA_REGISTER(%rbx) 122 shr $4, %rsp # clear 4 lsb, align to 16 123 shl $4, %rsp 124 125 call __tsan_report_race 126 127 # Unalign stack frame back. 128 mov %rbx, %rsp # restore the original rsp 129 CFI_DEF_CFA_REGISTER(%rsp) 130 pop %rbx 131 CFI_ADJUST_CFA_OFFSET(-8) 132 # Restore scratch registers. 133 pop %r11 134 CFI_ADJUST_CFA_OFFSET(-8) 135 pop %r10 136 CFI_ADJUST_CFA_OFFSET(-8) 137 pop %r9 138 CFI_ADJUST_CFA_OFFSET(-8) 139 pop %r8 140 CFI_ADJUST_CFA_OFFSET(-8) 141 pop %rdi 142 CFI_ADJUST_CFA_OFFSET(-8) 143 pop %rsi 144 CFI_ADJUST_CFA_OFFSET(-8) 145 pop %rdx 146 CFI_ADJUST_CFA_OFFSET(-8) 147 pop %rcx 148 CFI_ADJUST_CFA_OFFSET(-8) 149 pop %rax 150 CFI_ADJUST_CFA_OFFSET(-8) 151 CFI_RESTORE(%rax) 152 CFI_RESTORE(%rbx) 153 CFI_RESTORE(%rcx) 154 CFI_RESTORE(%rdx) 155 CFI_RESTORE(%rsi) 156 CFI_RESTORE(%rdi) 157 CFI_RESTORE(%r8) 158 CFI_RESTORE(%r9) 159 CFI_RESTORE(%r10) 160 CFI_RESTORE(%r11) 161 ret 162 CFI_ENDPROC 163 164 .hidden __tsan_setjmp 165 .comm _ZN14__interception11real_setjmpE,8,8 166 .globl setjmp 167 .type setjmp, @function 168 setjmp: 169 CFI_STARTPROC 170 // save env parameter 171 push %rdi 172 CFI_ADJUST_CFA_OFFSET(8) 173 CFI_REL_OFFSET(%rdi, 0) 174 // obtain %rsp 175 lea 16(%rsp), %rdi 176 mov %rdi, %rsi 177 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp) 178 rol $0x11, %rsi 179 // call tsan interceptor 180 call __tsan_setjmp 181 // restore env parameter 182 pop %rdi 183 CFI_ADJUST_CFA_OFFSET(-8) 184 CFI_RESTORE(%rdi) 185 // tail jump to libc setjmp 186 movl $0, %eax 187 movq _ZN14__interception11real_setjmpE@GOTPCREL(%rip), %rdx 188 jmp *(%rdx) 189 CFI_ENDPROC 190 .size setjmp, .-setjmp 191 192 .comm _ZN14__interception12real__setjmpE,8,8 193 .globl _setjmp 194 .type _setjmp, @function 195 _setjmp: 196 CFI_STARTPROC 197 // save env parameter 198 push %rdi 199 CFI_ADJUST_CFA_OFFSET(8) 200 CFI_REL_OFFSET(%rdi, 0) 201 // obtain %rsp 202 lea 16(%rsp), %rdi 203 mov %rdi, %rsi 204 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp) 205 rol $0x11, %rsi 206 // call tsan interceptor 207 call __tsan_setjmp 208 // restore env parameter 209 pop %rdi 210 CFI_ADJUST_CFA_OFFSET(-8) 211 CFI_RESTORE(%rdi) 212 // tail jump to libc setjmp 213 movl $0, %eax 214 movq _ZN14__interception12real__setjmpE@GOTPCREL(%rip), %rdx 215 jmp *(%rdx) 216 CFI_ENDPROC 217 .size _setjmp, .-_setjmp 218 219 .comm _ZN14__interception14real_sigsetjmpE,8,8 220 .globl sigsetjmp 221 .type sigsetjmp, @function 222 sigsetjmp: 223 CFI_STARTPROC 224 // save env parameter 225 push %rdi 226 CFI_ADJUST_CFA_OFFSET(8) 227 CFI_REL_OFFSET(%rdi, 0) 228 // save savesigs parameter 229 push %rsi 230 CFI_ADJUST_CFA_OFFSET(8) 231 CFI_REL_OFFSET(%rsi, 0) 232 // align stack frame 233 sub $8, %rsp 234 CFI_ADJUST_CFA_OFFSET(8) 235 // obtain %rsp 236 lea 32(%rsp), %rdi 237 mov %rdi, %rsi 238 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp) 239 rol $0x11, %rsi 240 // call tsan interceptor 241 call __tsan_setjmp 242 // unalign stack frame 243 add $8, %rsp 244 CFI_ADJUST_CFA_OFFSET(-8) 245 // restore savesigs parameter 246 pop %rsi 247 CFI_ADJUST_CFA_OFFSET(-8) 248 CFI_RESTORE(%rsi) 249 // restore env parameter 250 pop %rdi 251 CFI_ADJUST_CFA_OFFSET(-8) 252 CFI_RESTORE(%rdi) 253 // tail jump to libc sigsetjmp 254 movl $0, %eax 255 movq _ZN14__interception14real_sigsetjmpE@GOTPCREL(%rip), %rdx 256 jmp *(%rdx) 257 CFI_ENDPROC 258 .size sigsetjmp, .-sigsetjmp 259 260 .comm _ZN14__interception16real___sigsetjmpE,8,8 261 .globl __sigsetjmp 262 .type __sigsetjmp, @function 263 __sigsetjmp: 264 CFI_STARTPROC 265 // save env parameter 266 push %rdi 267 CFI_ADJUST_CFA_OFFSET(8) 268 CFI_REL_OFFSET(%rdi, 0) 269 // save savesigs parameter 270 push %rsi 271 CFI_ADJUST_CFA_OFFSET(8) 272 CFI_REL_OFFSET(%rsi, 0) 273 // align stack frame 274 sub $8, %rsp 275 CFI_ADJUST_CFA_OFFSET(8) 276 // obtain %rsp 277 lea 32(%rsp), %rdi 278 mov %rdi, %rsi 279 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp) 280 rol $0x11, %rsi 281 // call tsan interceptor 282 call __tsan_setjmp 283 // unalign stack frame 284 add $8, %rsp 285 CFI_ADJUST_CFA_OFFSET(-8) 286 // restore savesigs parameter 287 pop %rsi 288 CFI_ADJUST_CFA_OFFSET(-8) 289 CFI_RESTORE(%rsi) 290 // restore env parameter 291 pop %rdi 292 CFI_ADJUST_CFA_OFFSET(-8) 293 CFI_RESTORE(%rdi) 294 // tail jump to libc sigsetjmp 295 movl $0, %eax 296 movq _ZN14__interception16real___sigsetjmpE@GOTPCREL(%rip), %rdx 297 jmp *(%rdx) 298 CFI_ENDPROC 299 .size __sigsetjmp, .-__sigsetjmp 300 301 #ifdef __linux__ 302 /* We do not need executable stack. */ 303 .section .note.GNU-stack,"",@progbits 304 #endif 305