1 #include "sanitizer_common/sanitizer_asm.h"
2 #if !defined(__APPLE__)
8 ASM_HIDDEN(__tsan_trace_switch)
9 .globl ASM_TSAN_SYMBOL(__tsan_trace_switch_thunk)
10 ASM_TSAN_SYMBOL(__tsan_trace_switch_thunk):
12 # Save scratch registers.
14 CFI_ADJUST_CFA_OFFSET(8)
15 CFI_REL_OFFSET(%rax, 0)
17 CFI_ADJUST_CFA_OFFSET(8)
18 CFI_REL_OFFSET(%rcx, 0)
20 CFI_ADJUST_CFA_OFFSET(8)
21 CFI_REL_OFFSET(%rdx, 0)
23 CFI_ADJUST_CFA_OFFSET(8)
24 CFI_REL_OFFSET(%rsi, 0)
26 CFI_ADJUST_CFA_OFFSET(8)
27 CFI_REL_OFFSET(%rdi, 0)
29 CFI_ADJUST_CFA_OFFSET(8)
30 CFI_REL_OFFSET(%r8, 0)
32 CFI_ADJUST_CFA_OFFSET(8)
33 CFI_REL_OFFSET(%r9, 0)
35 CFI_ADJUST_CFA_OFFSET(8)
36 CFI_REL_OFFSET(%r10, 0)
38 CFI_ADJUST_CFA_OFFSET(8)
39 CFI_REL_OFFSET(%r11, 0)
41 push %rbx # non-scratch
42 CFI_ADJUST_CFA_OFFSET(8)
43 CFI_REL_OFFSET(%rbx, 0)
44 mov %rsp, %rbx # save current rsp
45 CFI_DEF_CFA_REGISTER(%rbx)
46 shr $4, %rsp # clear 4 lsb, align to 16
49 call ASM_TSAN_SYMBOL(__tsan_trace_switch)
51 # Unalign stack frame back.
52 mov %rbx, %rsp # restore the original rsp
53 CFI_DEF_CFA_REGISTER(%rsp)
55 CFI_ADJUST_CFA_OFFSET(-8)
56 # Restore scratch registers.
58 CFI_ADJUST_CFA_OFFSET(-8)
60 CFI_ADJUST_CFA_OFFSET(-8)
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)
88 ASM_HIDDEN(__tsan_report_race)
89 .globl ASM_TSAN_SYMBOL(__tsan_report_race_thunk)
90 ASM_TSAN_SYMBOL(__tsan_report_race_thunk):
92 # Save scratch registers.
94 CFI_ADJUST_CFA_OFFSET(8)
95 CFI_REL_OFFSET(%rax, 0)
97 CFI_ADJUST_CFA_OFFSET(8)
98 CFI_REL_OFFSET(%rcx, 0)
100 CFI_ADJUST_CFA_OFFSET(8)
101 CFI_REL_OFFSET(%rdx, 0)
103 CFI_ADJUST_CFA_OFFSET(8)
104 CFI_REL_OFFSET(%rsi, 0)
106 CFI_ADJUST_CFA_OFFSET(8)
107 CFI_REL_OFFSET(%rdi, 0)
109 CFI_ADJUST_CFA_OFFSET(8)
110 CFI_REL_OFFSET(%r8, 0)
112 CFI_ADJUST_CFA_OFFSET(8)
113 CFI_REL_OFFSET(%r9, 0)
115 CFI_ADJUST_CFA_OFFSET(8)
116 CFI_REL_OFFSET(%r10, 0)
118 CFI_ADJUST_CFA_OFFSET(8)
119 CFI_REL_OFFSET(%r11, 0)
121 push %rbx # non-scratch
122 CFI_ADJUST_CFA_OFFSET(8)
123 CFI_REL_OFFSET(%rbx, 0)
124 mov %rsp, %rbx # save current rsp
125 CFI_DEF_CFA_REGISTER(%rbx)
126 shr $4, %rsp # clear 4 lsb, align to 16
129 call ASM_TSAN_SYMBOL(__tsan_report_race)
131 # Unalign stack frame back.
132 mov %rbx, %rsp # restore the original rsp
133 CFI_DEF_CFA_REGISTER(%rsp)
135 CFI_ADJUST_CFA_OFFSET(-8)
136 # Restore scratch registers.
138 CFI_ADJUST_CFA_OFFSET(-8)
140 CFI_ADJUST_CFA_OFFSET(-8)
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)
168 ASM_HIDDEN(__tsan_setjmp)
169 #if !defined(__APPLE__)
170 .comm _ZN14__interception11real_setjmpE,8,8
172 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp)
173 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp))
174 ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp):
176 // save env parameter
178 CFI_ADJUST_CFA_OFFSET(8)
179 CFI_REL_OFFSET(%rdi, 0)
181 #if defined(__FreeBSD__)
184 #elif defined(__APPLE__)
187 #elif defined(__linux__)
190 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
193 # error "Unknown platform"
195 // call tsan interceptor
196 call ASM_TSAN_SYMBOL(__tsan_setjmp)
197 // restore env parameter
199 CFI_ADJUST_CFA_OFFSET(-8)
201 // tail jump to libc setjmp
203 #if !defined(__APPLE__)
204 movq _ZN14__interception11real_setjmpE@GOTPCREL(%rip), %rdx
207 jmp ASM_TSAN_SYMBOL(setjmp)
210 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp))
212 .comm _ZN14__interception12real__setjmpE,8,8
213 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp)
214 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp))
215 ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp):
217 // save env parameter
219 CFI_ADJUST_CFA_OFFSET(8)
220 CFI_REL_OFFSET(%rdi, 0)
222 #if defined(__FreeBSD__)
225 #elif defined(__APPLE__)
228 #elif defined(__linux__)
231 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
234 # error "Unknown platform"
236 // call tsan interceptor
237 call ASM_TSAN_SYMBOL(__tsan_setjmp)
238 // restore env parameter
240 CFI_ADJUST_CFA_OFFSET(-8)
242 // tail jump to libc setjmp
244 #if !defined(__APPLE__)
245 movq _ZN14__interception12real__setjmpE@GOTPCREL(%rip), %rdx
248 jmp ASM_TSAN_SYMBOL(_setjmp)
251 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp))
253 .comm _ZN14__interception14real_sigsetjmpE,8,8
254 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp)
255 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp))
256 ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp):
258 // save env parameter
260 CFI_ADJUST_CFA_OFFSET(8)
261 CFI_REL_OFFSET(%rdi, 0)
262 // save savesigs parameter
264 CFI_ADJUST_CFA_OFFSET(8)
265 CFI_REL_OFFSET(%rsi, 0)
268 CFI_ADJUST_CFA_OFFSET(8)
270 #if defined(__FreeBSD__)
273 #elif defined(__APPLE__)
276 #elif defined(__linux__)
279 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
282 # error "Unknown platform"
284 // call tsan interceptor
285 call ASM_TSAN_SYMBOL(__tsan_setjmp)
286 // unalign stack frame
288 CFI_ADJUST_CFA_OFFSET(-8)
289 // restore savesigs parameter
291 CFI_ADJUST_CFA_OFFSET(-8)
293 // restore env parameter
295 CFI_ADJUST_CFA_OFFSET(-8)
297 // tail jump to libc sigsetjmp
299 #if !defined(__APPLE__)
300 movq _ZN14__interception14real_sigsetjmpE@GOTPCREL(%rip), %rdx
303 jmp ASM_TSAN_SYMBOL(sigsetjmp)
306 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp))
308 #if !defined(__APPLE__)
309 .comm _ZN14__interception16real___sigsetjmpE,8,8
310 .globl ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp)
311 ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp))
312 ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp):
314 // save env parameter
316 CFI_ADJUST_CFA_OFFSET(8)
317 CFI_REL_OFFSET(%rdi, 0)
318 // save savesigs parameter
320 CFI_ADJUST_CFA_OFFSET(8)
321 CFI_REL_OFFSET(%rsi, 0)
324 CFI_ADJUST_CFA_OFFSET(8)
326 #if defined(__FreeBSD__)
332 xor %fs:0x30, %rsi // magic mangling of rsp (see libc setjmp)
335 // call tsan interceptor
336 call ASM_TSAN_SYMBOL(__tsan_setjmp)
337 // unalign stack frame
339 CFI_ADJUST_CFA_OFFSET(-8)
340 // restore savesigs parameter
342 CFI_ADJUST_CFA_OFFSET(-8)
344 // restore env parameter
346 CFI_ADJUST_CFA_OFFSET(-8)
348 // tail jump to libc sigsetjmp
350 movq _ZN14__interception16real___sigsetjmpE@GOTPCREL(%rip), %rdx
353 ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp))
354 #endif // !defined(__APPLE__)
356 #if defined(__FreeBSD__) || defined(__linux__)
357 /* We do not need executable stack. */
358 .section .note.GNU-stack,"",@progbits