1 // The content of this file is x86_64-only:
2 #if defined(__x86_64__)
4 #include "sanitizer_common/sanitizer_asm.h"
7 #if !defined(__APPLE__)
10 .section __TEXT,__text
13 ASM_HIDDEN(__tsan_trace_switch)
14 .globl ASM_TSAN_SYMBOL(__tsan_trace_switch_thunk)
15 ASM_TSAN_SYMBOL(__tsan_trace_switch_thunk):
18 # Save scratch registers.
20 CFI_ADJUST_CFA_OFFSET(8)
21 CFI_REL_OFFSET(%rax, 0)
23 CFI_ADJUST_CFA_OFFSET(8)
24 CFI_REL_OFFSET(%rcx, 0)
26 CFI_ADJUST_CFA_OFFSET(8)
27 CFI_REL_OFFSET(%rdx, 0)
29 CFI_ADJUST_CFA_OFFSET(8)
30 CFI_REL_OFFSET(%rsi, 0)
32 CFI_ADJUST_CFA_OFFSET(8)
33 CFI_REL_OFFSET(%rdi, 0)
35 CFI_ADJUST_CFA_OFFSET(8)
36 CFI_REL_OFFSET(%r8, 0)
38 CFI_ADJUST_CFA_OFFSET(8)
39 CFI_REL_OFFSET(%r9, 0)
41 CFI_ADJUST_CFA_OFFSET(8)
42 CFI_REL_OFFSET(%r10, 0)
44 CFI_ADJUST_CFA_OFFSET(8)
45 CFI_REL_OFFSET(%r11, 0)
47 push %rbx # non-scratch
48 CFI_ADJUST_CFA_OFFSET(8)
49 CFI_REL_OFFSET(%rbx, 0)
50 mov %rsp, %rbx # save current rsp
51 CFI_DEF_CFA_REGISTER(%rbx)
52 shr $4, %rsp # clear 4 lsb, align to 16
55 call ASM_TSAN_SYMBOL(__tsan_trace_switch)
57 # Unalign stack frame back.
58 mov %rbx, %rsp # restore the original rsp
59 CFI_DEF_CFA_REGISTER(%rsp)
61 CFI_ADJUST_CFA_OFFSET(-8)
62 # Restore scratch registers.
64 CFI_ADJUST_CFA_OFFSET(-8)
66 CFI_ADJUST_CFA_OFFSET(-8)
68 CFI_ADJUST_CFA_OFFSET(-8)
70 CFI_ADJUST_CFA_OFFSET(-8)
72 CFI_ADJUST_CFA_OFFSET(-8)
74 CFI_ADJUST_CFA_OFFSET(-8)
76 CFI_ADJUST_CFA_OFFSET(-8)
78 CFI_ADJUST_CFA_OFFSET(-8)
80 CFI_ADJUST_CFA_OFFSET(-8)
94 ASM_HIDDEN(__tsan_report_race)
95 .globl ASM_TSAN_SYMBOL(__tsan_report_race_thunk)
96 ASM_TSAN_SYMBOL(__tsan_report_race_thunk):
99 # Save scratch registers.
101 CFI_ADJUST_CFA_OFFSET(8)
102 CFI_REL_OFFSET(%rax, 0)
104 CFI_ADJUST_CFA_OFFSET(8)
105 CFI_REL_OFFSET(%rcx, 0)
107 CFI_ADJUST_CFA_OFFSET(8)
108 CFI_REL_OFFSET(%rdx, 0)
110 CFI_ADJUST_CFA_OFFSET(8)
111 CFI_REL_OFFSET(%rsi, 0)
113 CFI_ADJUST_CFA_OFFSET(8)
114 CFI_REL_OFFSET(%rdi, 0)
116 CFI_ADJUST_CFA_OFFSET(8)
117 CFI_REL_OFFSET(%r8, 0)
119 CFI_ADJUST_CFA_OFFSET(8)
120 CFI_REL_OFFSET(%r9, 0)
122 CFI_ADJUST_CFA_OFFSET(8)
123 CFI_REL_OFFSET(%r10, 0)
125 CFI_ADJUST_CFA_OFFSET(8)
126 CFI_REL_OFFSET(%r11, 0)
128 push %rbx # non-scratch
129 CFI_ADJUST_CFA_OFFSET(8)
130 CFI_REL_OFFSET(%rbx, 0)
131 mov %rsp, %rbx # save current rsp
132 CFI_DEF_CFA_REGISTER(%rbx)
133 shr $4, %rsp # clear 4 lsb, align to 16
136 call ASM_TSAN_SYMBOL(__tsan_report_race)
138 # Unalign stack frame back.
139 mov %rbx, %rsp # restore the original rsp
140 CFI_DEF_CFA_REGISTER(%rsp)
142 CFI_ADJUST_CFA_OFFSET(-8)
143 # Restore scratch registers.
145 CFI_ADJUST_CFA_OFFSET(-8)
147 CFI_ADJUST_CFA_OFFSET(-8)
149 CFI_ADJUST_CFA_OFFSET(-8)
151 CFI_ADJUST_CFA_OFFSET(-8)
153 CFI_ADJUST_CFA_OFFSET(-8)
155 CFI_ADJUST_CFA_OFFSET(-8)
157 CFI_ADJUST_CFA_OFFSET(-8)
159 CFI_ADJUST_CFA_OFFSET(-8)
161 CFI_ADJUST_CFA_OFFSET(-8)
175 ASM_HIDDEN(__tsan_setjmp)
176 #if !defined(__APPLE__)
177 .comm _ZN14__interception11real_setjmpE,8,8
179 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp)
180 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp))
181 ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp):
184 // save env parameter
186 CFI_ADJUST_CFA_OFFSET(8)
187 CFI_REL_OFFSET(%rdi, 0)
189 #if defined(__FreeBSD__)
192 #elif defined(__APPLE__)
195 #elif defined(__linux__)
198 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
201 # error "Unknown platform"
203 // call tsan interceptor
204 call ASM_TSAN_SYMBOL(__tsan_setjmp)
205 // restore env parameter
207 CFI_ADJUST_CFA_OFFSET(-8)
209 // tail jump to libc setjmp
211 #if !defined(__APPLE__)
212 movq _ZN14__interception11real_setjmpE@GOTPCREL(%rip), %rdx
215 jmp ASM_TSAN_SYMBOL(setjmp)
218 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp))
220 .comm _ZN14__interception12real__setjmpE,8,8
221 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp)
222 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp))
223 ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp):
226 // save env parameter
228 CFI_ADJUST_CFA_OFFSET(8)
229 CFI_REL_OFFSET(%rdi, 0)
231 #if defined(__FreeBSD__)
234 #elif defined(__APPLE__)
237 #elif defined(__linux__)
240 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
243 # error "Unknown platform"
245 // call tsan interceptor
246 call ASM_TSAN_SYMBOL(__tsan_setjmp)
247 // restore env parameter
249 CFI_ADJUST_CFA_OFFSET(-8)
251 // tail jump to libc setjmp
253 #if !defined(__APPLE__)
254 movq _ZN14__interception12real__setjmpE@GOTPCREL(%rip), %rdx
257 jmp ASM_TSAN_SYMBOL(_setjmp)
260 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp))
262 .comm _ZN14__interception14real_sigsetjmpE,8,8
263 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp)
264 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp))
265 ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp):
268 // save env parameter
270 CFI_ADJUST_CFA_OFFSET(8)
271 CFI_REL_OFFSET(%rdi, 0)
272 // save savesigs parameter
274 CFI_ADJUST_CFA_OFFSET(8)
275 CFI_REL_OFFSET(%rsi, 0)
278 CFI_ADJUST_CFA_OFFSET(8)
280 #if defined(__FreeBSD__)
283 #elif defined(__APPLE__)
286 #elif defined(__linux__)
289 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
292 # error "Unknown platform"
294 // call tsan interceptor
295 call ASM_TSAN_SYMBOL(__tsan_setjmp)
296 // unalign stack frame
298 CFI_ADJUST_CFA_OFFSET(-8)
299 // restore savesigs parameter
301 CFI_ADJUST_CFA_OFFSET(-8)
303 // restore env parameter
305 CFI_ADJUST_CFA_OFFSET(-8)
307 // tail jump to libc sigsetjmp
309 #if !defined(__APPLE__)
310 movq _ZN14__interception14real_sigsetjmpE@GOTPCREL(%rip), %rdx
313 jmp ASM_TSAN_SYMBOL(sigsetjmp)
316 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp))
318 #if !defined(__APPLE__)
319 .comm _ZN14__interception16real___sigsetjmpE,8,8
320 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp)
321 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp))
322 ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp):
325 // save env parameter
327 CFI_ADJUST_CFA_OFFSET(8)
328 CFI_REL_OFFSET(%rdi, 0)
329 // save savesigs parameter
331 CFI_ADJUST_CFA_OFFSET(8)
332 CFI_REL_OFFSET(%rsi, 0)
335 CFI_ADJUST_CFA_OFFSET(8)
337 #if defined(__FreeBSD__)
343 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
346 // call tsan interceptor
347 call ASM_TSAN_SYMBOL(__tsan_setjmp)
348 // unalign stack frame
350 CFI_ADJUST_CFA_OFFSET(-8)
351 // restore savesigs parameter
353 CFI_ADJUST_CFA_OFFSET(-8)
355 // restore env parameter
357 CFI_ADJUST_CFA_OFFSET(-8)
359 // tail jump to libc sigsetjmp
361 movq _ZN14__interception16real___sigsetjmpE@GOTPCREL(%rip), %rdx
364 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp))
365 #endif // !defined(__APPLE__)
367 #if defined(__FreeBSD__) || defined(__linux__)
368 /* We do not need executable stack. */
369 .section .note.GNU-stack,"",@progbits