1 // The content of this file is x86_64-only:
2 #if defined(__x86_64__)
4 #include "sanitizer_common/sanitizer_asm.h"
6 #if !defined(__APPLE__)
12 ASM_HIDDEN(__tsan_trace_switch)
13 .globl ASM_TSAN_SYMBOL(__tsan_trace_switch_thunk)
14 ASM_TSAN_SYMBOL(__tsan_trace_switch_thunk):
16 # Save scratch registers.
18 CFI_ADJUST_CFA_OFFSET(8)
19 CFI_REL_OFFSET(%rax, 0)
21 CFI_ADJUST_CFA_OFFSET(8)
22 CFI_REL_OFFSET(%rcx, 0)
24 CFI_ADJUST_CFA_OFFSET(8)
25 CFI_REL_OFFSET(%rdx, 0)
27 CFI_ADJUST_CFA_OFFSET(8)
28 CFI_REL_OFFSET(%rsi, 0)
30 CFI_ADJUST_CFA_OFFSET(8)
31 CFI_REL_OFFSET(%rdi, 0)
33 CFI_ADJUST_CFA_OFFSET(8)
34 CFI_REL_OFFSET(%r8, 0)
36 CFI_ADJUST_CFA_OFFSET(8)
37 CFI_REL_OFFSET(%r9, 0)
39 CFI_ADJUST_CFA_OFFSET(8)
40 CFI_REL_OFFSET(%r10, 0)
42 CFI_ADJUST_CFA_OFFSET(8)
43 CFI_REL_OFFSET(%r11, 0)
45 push %rbx # non-scratch
46 CFI_ADJUST_CFA_OFFSET(8)
47 CFI_REL_OFFSET(%rbx, 0)
48 mov %rsp, %rbx # save current rsp
49 CFI_DEF_CFA_REGISTER(%rbx)
50 shr $4, %rsp # clear 4 lsb, align to 16
53 call ASM_TSAN_SYMBOL(__tsan_trace_switch)
55 # Unalign stack frame back.
56 mov %rbx, %rsp # restore the original rsp
57 CFI_DEF_CFA_REGISTER(%rsp)
59 CFI_ADJUST_CFA_OFFSET(-8)
60 # Restore scratch registers.
62 CFI_ADJUST_CFA_OFFSET(-8)
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)
92 ASM_HIDDEN(__tsan_report_race)
93 .globl ASM_TSAN_SYMBOL(__tsan_report_race_thunk)
94 ASM_TSAN_SYMBOL(__tsan_report_race_thunk):
96 # Save scratch registers.
98 CFI_ADJUST_CFA_OFFSET(8)
99 CFI_REL_OFFSET(%rax, 0)
101 CFI_ADJUST_CFA_OFFSET(8)
102 CFI_REL_OFFSET(%rcx, 0)
104 CFI_ADJUST_CFA_OFFSET(8)
105 CFI_REL_OFFSET(%rdx, 0)
107 CFI_ADJUST_CFA_OFFSET(8)
108 CFI_REL_OFFSET(%rsi, 0)
110 CFI_ADJUST_CFA_OFFSET(8)
111 CFI_REL_OFFSET(%rdi, 0)
113 CFI_ADJUST_CFA_OFFSET(8)
114 CFI_REL_OFFSET(%r8, 0)
116 CFI_ADJUST_CFA_OFFSET(8)
117 CFI_REL_OFFSET(%r9, 0)
119 CFI_ADJUST_CFA_OFFSET(8)
120 CFI_REL_OFFSET(%r10, 0)
122 CFI_ADJUST_CFA_OFFSET(8)
123 CFI_REL_OFFSET(%r11, 0)
125 push %rbx # non-scratch
126 CFI_ADJUST_CFA_OFFSET(8)
127 CFI_REL_OFFSET(%rbx, 0)
128 mov %rsp, %rbx # save current rsp
129 CFI_DEF_CFA_REGISTER(%rbx)
130 shr $4, %rsp # clear 4 lsb, align to 16
133 call ASM_TSAN_SYMBOL(__tsan_report_race)
135 # Unalign stack frame back.
136 mov %rbx, %rsp # restore the original rsp
137 CFI_DEF_CFA_REGISTER(%rsp)
139 CFI_ADJUST_CFA_OFFSET(-8)
140 # Restore scratch registers.
142 CFI_ADJUST_CFA_OFFSET(-8)
144 CFI_ADJUST_CFA_OFFSET(-8)
146 CFI_ADJUST_CFA_OFFSET(-8)
148 CFI_ADJUST_CFA_OFFSET(-8)
150 CFI_ADJUST_CFA_OFFSET(-8)
152 CFI_ADJUST_CFA_OFFSET(-8)
154 CFI_ADJUST_CFA_OFFSET(-8)
156 CFI_ADJUST_CFA_OFFSET(-8)
158 CFI_ADJUST_CFA_OFFSET(-8)
172 ASM_HIDDEN(__tsan_setjmp)
173 #if !defined(__APPLE__)
174 .comm _ZN14__interception11real_setjmpE,8,8
176 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp)
177 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp))
178 ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp):
180 // save env parameter
182 CFI_ADJUST_CFA_OFFSET(8)
183 CFI_REL_OFFSET(%rdi, 0)
185 #if defined(__FreeBSD__)
188 #elif defined(__APPLE__)
191 #elif defined(__linux__)
194 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
197 # error "Unknown platform"
199 // call tsan interceptor
200 call ASM_TSAN_SYMBOL(__tsan_setjmp)
201 // restore env parameter
203 CFI_ADJUST_CFA_OFFSET(-8)
205 // tail jump to libc setjmp
207 #if !defined(__APPLE__)
208 movq _ZN14__interception11real_setjmpE@GOTPCREL(%rip), %rdx
211 jmp ASM_TSAN_SYMBOL(setjmp)
214 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp))
216 .comm _ZN14__interception12real__setjmpE,8,8
217 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp)
218 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp))
219 ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp):
221 // save env parameter
223 CFI_ADJUST_CFA_OFFSET(8)
224 CFI_REL_OFFSET(%rdi, 0)
226 #if defined(__FreeBSD__)
229 #elif defined(__APPLE__)
232 #elif defined(__linux__)
235 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
238 # error "Unknown platform"
240 // call tsan interceptor
241 call ASM_TSAN_SYMBOL(__tsan_setjmp)
242 // restore env parameter
244 CFI_ADJUST_CFA_OFFSET(-8)
246 // tail jump to libc setjmp
248 #if !defined(__APPLE__)
249 movq _ZN14__interception12real__setjmpE@GOTPCREL(%rip), %rdx
252 jmp ASM_TSAN_SYMBOL(_setjmp)
255 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp))
257 .comm _ZN14__interception14real_sigsetjmpE,8,8
258 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp)
259 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp))
260 ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp):
262 // save env parameter
264 CFI_ADJUST_CFA_OFFSET(8)
265 CFI_REL_OFFSET(%rdi, 0)
266 // save savesigs parameter
268 CFI_ADJUST_CFA_OFFSET(8)
269 CFI_REL_OFFSET(%rsi, 0)
272 CFI_ADJUST_CFA_OFFSET(8)
274 #if defined(__FreeBSD__)
277 #elif defined(__APPLE__)
280 #elif defined(__linux__)
283 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
286 # error "Unknown platform"
288 // call tsan interceptor
289 call ASM_TSAN_SYMBOL(__tsan_setjmp)
290 // unalign stack frame
292 CFI_ADJUST_CFA_OFFSET(-8)
293 // restore savesigs parameter
295 CFI_ADJUST_CFA_OFFSET(-8)
297 // restore env parameter
299 CFI_ADJUST_CFA_OFFSET(-8)
301 // tail jump to libc sigsetjmp
303 #if !defined(__APPLE__)
304 movq _ZN14__interception14real_sigsetjmpE@GOTPCREL(%rip), %rdx
307 jmp ASM_TSAN_SYMBOL(sigsetjmp)
310 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp))
312 #if !defined(__APPLE__)
313 .comm _ZN14__interception16real___sigsetjmpE,8,8
314 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp)
315 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp))
316 ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp):
318 // save env parameter
320 CFI_ADJUST_CFA_OFFSET(8)
321 CFI_REL_OFFSET(%rdi, 0)
322 // save savesigs parameter
324 CFI_ADJUST_CFA_OFFSET(8)
325 CFI_REL_OFFSET(%rsi, 0)
328 CFI_ADJUST_CFA_OFFSET(8)
330 #if defined(__FreeBSD__)
336 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
339 // call tsan interceptor
340 call ASM_TSAN_SYMBOL(__tsan_setjmp)
341 // unalign stack frame
343 CFI_ADJUST_CFA_OFFSET(-8)
344 // restore savesigs parameter
346 CFI_ADJUST_CFA_OFFSET(-8)
348 // restore env parameter
350 CFI_ADJUST_CFA_OFFSET(-8)
352 // tail jump to libc sigsetjmp
354 movq _ZN14__interception16real___sigsetjmpE@GOTPCREL(%rip), %rdx
357 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp))
358 #endif // !defined(__APPLE__)
360 #if defined(__FreeBSD__) || defined(__linux__)
361 /* We do not need executable stack. */
362 .section .note.GNU-stack,"",@progbits