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_SYMBOL(__tsan_trace_switch_thunk)
14 ASM_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_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_SYMBOL(__tsan_report_race_thunk)
94 ASM_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_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(__NetBSD__)
174 .comm _ZN14__interception15real___setjmp14E,8,8
175 #elif !defined(__APPLE__)
176 .comm _ZN14__interception11real_setjmpE,8,8
178 #if defined(__NetBSD__)
179 .globl ASM_SYMBOL_INTERCEPTOR(__setjmp14)
180 ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__setjmp14))
181 ASM_SYMBOL_INTERCEPTOR(__setjmp14):
183 .globl ASM_SYMBOL_INTERCEPTOR(setjmp)
184 ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(setjmp))
185 ASM_SYMBOL_INTERCEPTOR(setjmp):
188 // save env parameter
190 CFI_ADJUST_CFA_OFFSET(8)
191 CFI_REL_OFFSET(%rdi, 0)
193 #if defined(__FreeBSD__) || defined(__NetBSD__)
196 #elif defined(__APPLE__)
199 xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
200 #elif defined(__linux__)
203 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
206 # error "Unknown platform"
208 // call tsan interceptor
209 call ASM_SYMBOL(__tsan_setjmp)
210 // restore env parameter
212 CFI_ADJUST_CFA_OFFSET(-8)
214 // tail jump to libc setjmp
216 #if defined(__NetBSD__)
217 movq _ZN14__interception15real___setjmp14E@GOTPCREL(%rip), %rdx
219 #elif !defined(__APPLE__)
220 movq _ZN14__interception11real_setjmpE@GOTPCREL(%rip), %rdx
223 jmp ASM_SYMBOL(setjmp)
226 #if defined(__NetBSD__)
227 ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__setjmp14))
229 ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(setjmp))
232 .comm _ZN14__interception12real__setjmpE,8,8
233 .globl ASM_SYMBOL_INTERCEPTOR(_setjmp)
234 ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(_setjmp))
235 ASM_SYMBOL_INTERCEPTOR(_setjmp):
237 // save env parameter
239 CFI_ADJUST_CFA_OFFSET(8)
240 CFI_REL_OFFSET(%rdi, 0)
242 #if defined(__FreeBSD__) || defined(__NetBSD__)
245 #elif defined(__APPLE__)
248 xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
249 #elif defined(__linux__)
252 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
255 # error "Unknown platform"
257 // call tsan interceptor
258 call ASM_SYMBOL(__tsan_setjmp)
259 // restore env parameter
261 CFI_ADJUST_CFA_OFFSET(-8)
263 // tail jump to libc setjmp
265 #if !defined(__APPLE__)
266 movq _ZN14__interception12real__setjmpE@GOTPCREL(%rip), %rdx
269 jmp ASM_SYMBOL(_setjmp)
272 ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(_setjmp))
274 #if defined(__NetBSD__)
275 .comm _ZN14__interception18real___sigsetjmp14E,8,8
276 .globl ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14)
277 ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14))
278 ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14):
280 .comm _ZN14__interception14real_sigsetjmpE,8,8
281 .globl ASM_SYMBOL_INTERCEPTOR(sigsetjmp)
282 ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(sigsetjmp))
283 ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
286 // save env parameter
288 CFI_ADJUST_CFA_OFFSET(8)
289 CFI_REL_OFFSET(%rdi, 0)
290 // save savesigs parameter
292 CFI_ADJUST_CFA_OFFSET(8)
293 CFI_REL_OFFSET(%rsi, 0)
296 CFI_ADJUST_CFA_OFFSET(8)
298 #if defined(__FreeBSD__) || defined(__NetBSD__)
301 #elif defined(__APPLE__)
304 xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
305 #elif defined(__linux__)
308 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
311 # error "Unknown platform"
313 // call tsan interceptor
314 call ASM_SYMBOL(__tsan_setjmp)
315 // unalign stack frame
317 CFI_ADJUST_CFA_OFFSET(-8)
318 // restore savesigs parameter
320 CFI_ADJUST_CFA_OFFSET(-8)
322 // restore env parameter
324 CFI_ADJUST_CFA_OFFSET(-8)
326 // tail jump to libc sigsetjmp
328 #if defined(__NetBSD__)
329 movq _ZN14__interception18real___sigsetjmp14E@GOTPCREL(%rip), %rdx
331 #elif !defined(__APPLE__)
332 movq _ZN14__interception14real_sigsetjmpE@GOTPCREL(%rip), %rdx
335 jmp ASM_SYMBOL(sigsetjmp)
338 #if defined(__NetBSD__)
339 ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14))
341 ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(sigsetjmp))
344 #if !defined(__APPLE__) && !defined(__NetBSD__)
345 .comm _ZN14__interception16real___sigsetjmpE,8,8
346 .globl ASM_SYMBOL_INTERCEPTOR(__sigsetjmp)
347 ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp))
348 ASM_SYMBOL_INTERCEPTOR(__sigsetjmp):
350 // save env parameter
352 CFI_ADJUST_CFA_OFFSET(8)
353 CFI_REL_OFFSET(%rdi, 0)
354 // save savesigs parameter
356 CFI_ADJUST_CFA_OFFSET(8)
357 CFI_REL_OFFSET(%rsi, 0)
360 CFI_ADJUST_CFA_OFFSET(8)
362 #if defined(__FreeBSD__)
368 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
371 // call tsan interceptor
372 call ASM_SYMBOL(__tsan_setjmp)
373 // unalign stack frame
375 CFI_ADJUST_CFA_OFFSET(-8)
376 // restore savesigs parameter
378 CFI_ADJUST_CFA_OFFSET(-8)
380 // restore env parameter
382 CFI_ADJUST_CFA_OFFSET(-8)
384 // tail jump to libc sigsetjmp
386 movq _ZN14__interception16real___sigsetjmpE@GOTPCREL(%rip), %rdx
389 ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp))
390 #endif // !defined(__APPLE__) && !defined(__NetBSD__)
392 #if defined(__FreeBSD__) || defined(__linux__)
393 /* We do not need executable stack. */
394 /* This note is not needed on NetBSD. */
395 .section .note.GNU-stack,"",@progbits