• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#include "sanitizer_common/sanitizer_asm.h"
2#if !defined(__APPLE__)
3.section .text
4#else
5.section __TEXT,__text
6#endif
7
8ASM_HIDDEN(__tsan_trace_switch)
9.globl ASM_TSAN_SYMBOL(__tsan_trace_switch_thunk)
10ASM_TSAN_SYMBOL(__tsan_trace_switch_thunk):
11  CFI_STARTPROC
12  # Save scratch registers.
13  push %rax
14  CFI_ADJUST_CFA_OFFSET(8)
15  CFI_REL_OFFSET(%rax, 0)
16  push %rcx
17  CFI_ADJUST_CFA_OFFSET(8)
18  CFI_REL_OFFSET(%rcx, 0)
19  push %rdx
20  CFI_ADJUST_CFA_OFFSET(8)
21  CFI_REL_OFFSET(%rdx, 0)
22  push %rsi
23  CFI_ADJUST_CFA_OFFSET(8)
24  CFI_REL_OFFSET(%rsi, 0)
25  push %rdi
26  CFI_ADJUST_CFA_OFFSET(8)
27  CFI_REL_OFFSET(%rdi, 0)
28  push %r8
29  CFI_ADJUST_CFA_OFFSET(8)
30  CFI_REL_OFFSET(%r8, 0)
31  push %r9
32  CFI_ADJUST_CFA_OFFSET(8)
33  CFI_REL_OFFSET(%r9, 0)
34  push %r10
35  CFI_ADJUST_CFA_OFFSET(8)
36  CFI_REL_OFFSET(%r10, 0)
37  push %r11
38  CFI_ADJUST_CFA_OFFSET(8)
39  CFI_REL_OFFSET(%r11, 0)
40  # Align stack frame.
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
47  shl $4, %rsp
48
49  call ASM_TSAN_SYMBOL(__tsan_trace_switch)
50
51  # Unalign stack frame back.
52  mov %rbx, %rsp  # restore the original rsp
53  CFI_DEF_CFA_REGISTER(%rsp)
54  pop %rbx
55  CFI_ADJUST_CFA_OFFSET(-8)
56  # Restore scratch registers.
57  pop %r11
58  CFI_ADJUST_CFA_OFFSET(-8)
59  pop %r10
60  CFI_ADJUST_CFA_OFFSET(-8)
61  pop %r9
62  CFI_ADJUST_CFA_OFFSET(-8)
63  pop %r8
64  CFI_ADJUST_CFA_OFFSET(-8)
65  pop %rdi
66  CFI_ADJUST_CFA_OFFSET(-8)
67  pop %rsi
68  CFI_ADJUST_CFA_OFFSET(-8)
69  pop %rdx
70  CFI_ADJUST_CFA_OFFSET(-8)
71  pop %rcx
72  CFI_ADJUST_CFA_OFFSET(-8)
73  pop %rax
74  CFI_ADJUST_CFA_OFFSET(-8)
75  CFI_RESTORE(%rax)
76  CFI_RESTORE(%rbx)
77  CFI_RESTORE(%rcx)
78  CFI_RESTORE(%rdx)
79  CFI_RESTORE(%rsi)
80  CFI_RESTORE(%rdi)
81  CFI_RESTORE(%r8)
82  CFI_RESTORE(%r9)
83  CFI_RESTORE(%r10)
84  CFI_RESTORE(%r11)
85  ret
86  CFI_ENDPROC
87
88ASM_HIDDEN(__tsan_report_race)
89.globl ASM_TSAN_SYMBOL(__tsan_report_race_thunk)
90ASM_TSAN_SYMBOL(__tsan_report_race_thunk):
91  CFI_STARTPROC
92  # Save scratch registers.
93  push %rax
94  CFI_ADJUST_CFA_OFFSET(8)
95  CFI_REL_OFFSET(%rax, 0)
96  push %rcx
97  CFI_ADJUST_CFA_OFFSET(8)
98  CFI_REL_OFFSET(%rcx, 0)
99  push %rdx
100  CFI_ADJUST_CFA_OFFSET(8)
101  CFI_REL_OFFSET(%rdx, 0)
102  push %rsi
103  CFI_ADJUST_CFA_OFFSET(8)
104  CFI_REL_OFFSET(%rsi, 0)
105  push %rdi
106  CFI_ADJUST_CFA_OFFSET(8)
107  CFI_REL_OFFSET(%rdi, 0)
108  push %r8
109  CFI_ADJUST_CFA_OFFSET(8)
110  CFI_REL_OFFSET(%r8, 0)
111  push %r9
112  CFI_ADJUST_CFA_OFFSET(8)
113  CFI_REL_OFFSET(%r9, 0)
114  push %r10
115  CFI_ADJUST_CFA_OFFSET(8)
116  CFI_REL_OFFSET(%r10, 0)
117  push %r11
118  CFI_ADJUST_CFA_OFFSET(8)
119  CFI_REL_OFFSET(%r11, 0)
120  # Align stack frame.
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
127  shl $4, %rsp
128
129  call ASM_TSAN_SYMBOL(__tsan_report_race)
130
131  # Unalign stack frame back.
132  mov %rbx, %rsp  # restore the original rsp
133  CFI_DEF_CFA_REGISTER(%rsp)
134  pop %rbx
135  CFI_ADJUST_CFA_OFFSET(-8)
136  # Restore scratch registers.
137  pop %r11
138  CFI_ADJUST_CFA_OFFSET(-8)
139  pop %r10
140  CFI_ADJUST_CFA_OFFSET(-8)
141  pop %r9
142  CFI_ADJUST_CFA_OFFSET(-8)
143  pop %r8
144  CFI_ADJUST_CFA_OFFSET(-8)
145  pop %rdi
146  CFI_ADJUST_CFA_OFFSET(-8)
147  pop %rsi
148  CFI_ADJUST_CFA_OFFSET(-8)
149  pop %rdx
150  CFI_ADJUST_CFA_OFFSET(-8)
151  pop %rcx
152  CFI_ADJUST_CFA_OFFSET(-8)
153  pop %rax
154  CFI_ADJUST_CFA_OFFSET(-8)
155  CFI_RESTORE(%rax)
156  CFI_RESTORE(%rbx)
157  CFI_RESTORE(%rcx)
158  CFI_RESTORE(%rdx)
159  CFI_RESTORE(%rsi)
160  CFI_RESTORE(%rdi)
161  CFI_RESTORE(%r8)
162  CFI_RESTORE(%r9)
163  CFI_RESTORE(%r10)
164  CFI_RESTORE(%r11)
165  ret
166  CFI_ENDPROC
167
168ASM_HIDDEN(__tsan_setjmp)
169#if !defined(__APPLE__)
170.comm _ZN14__interception11real_setjmpE,8,8
171#endif
172.globl ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp)
173ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp))
174ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp):
175  CFI_STARTPROC
176  // save env parameter
177  push %rdi
178  CFI_ADJUST_CFA_OFFSET(8)
179  CFI_REL_OFFSET(%rdi, 0)
180  // obtain %rsp
181#if defined(__FreeBSD__)
182  lea 8(%rsp), %rdi
183  mov %rdi, %rsi
184#elif defined(__APPLE__)
185  lea 16(%rsp), %rdi
186  mov %rdi, %rsi
187#elif defined(__linux__)
188  lea 16(%rsp), %rdi
189  mov %rdi, %rsi
190  xor %fs:0x30, %rsi  // magic mangling of rsp (see libc setjmp)
191  rol $0x11, %rsi
192#else
193# error "Unknown platform"
194#endif
195  // call tsan interceptor
196  call ASM_TSAN_SYMBOL(__tsan_setjmp)
197  // restore env parameter
198  pop %rdi
199  CFI_ADJUST_CFA_OFFSET(-8)
200  CFI_RESTORE(%rdi)
201  // tail jump to libc setjmp
202  movl $0, %eax
203#if !defined(__APPLE__)
204  movq _ZN14__interception11real_setjmpE@GOTPCREL(%rip), %rdx
205  jmp *(%rdx)
206#else
207  jmp ASM_TSAN_SYMBOL(setjmp)
208#endif
209  CFI_ENDPROC
210ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(setjmp))
211
212.comm _ZN14__interception12real__setjmpE,8,8
213.globl ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp)
214ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp))
215ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp):
216  CFI_STARTPROC
217  // save env parameter
218  push %rdi
219  CFI_ADJUST_CFA_OFFSET(8)
220  CFI_REL_OFFSET(%rdi, 0)
221  // obtain %rsp
222#if defined(__FreeBSD__)
223  lea 8(%rsp), %rdi
224  mov %rdi, %rsi
225#elif defined(__APPLE__)
226  lea 16(%rsp), %rdi
227  mov %rdi, %rsi
228#elif defined(__linux__)
229  lea 16(%rsp), %rdi
230  mov %rdi, %rsi
231  xor %fs:0x30, %rsi  // magic mangling of rsp (see libc setjmp)
232  rol $0x11, %rsi
233#else
234# error "Unknown platform"
235#endif
236  // call tsan interceptor
237  call ASM_TSAN_SYMBOL(__tsan_setjmp)
238  // restore env parameter
239  pop %rdi
240  CFI_ADJUST_CFA_OFFSET(-8)
241  CFI_RESTORE(%rdi)
242  // tail jump to libc setjmp
243  movl $0, %eax
244#if !defined(__APPLE__)
245  movq _ZN14__interception12real__setjmpE@GOTPCREL(%rip), %rdx
246  jmp *(%rdx)
247#else
248  jmp ASM_TSAN_SYMBOL(_setjmp)
249#endif
250  CFI_ENDPROC
251ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(_setjmp))
252
253.comm _ZN14__interception14real_sigsetjmpE,8,8
254.globl ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp)
255ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp))
256ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp):
257  CFI_STARTPROC
258  // save env parameter
259  push %rdi
260  CFI_ADJUST_CFA_OFFSET(8)
261  CFI_REL_OFFSET(%rdi, 0)
262  // save savesigs parameter
263  push %rsi
264  CFI_ADJUST_CFA_OFFSET(8)
265  CFI_REL_OFFSET(%rsi, 0)
266  // align stack frame
267  sub $8, %rsp
268  CFI_ADJUST_CFA_OFFSET(8)
269  // obtain %rsp
270#if defined(__FreeBSD__)
271  lea 24(%rsp), %rdi
272  mov %rdi, %rsi
273#elif defined(__APPLE__)
274  lea 32(%rsp), %rdi
275  mov %rdi, %rsi
276#elif defined(__linux__)
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#else
282# error "Unknown platform"
283#endif
284  // call tsan interceptor
285  call ASM_TSAN_SYMBOL(__tsan_setjmp)
286  // unalign stack frame
287  add $8, %rsp
288  CFI_ADJUST_CFA_OFFSET(-8)
289  // restore savesigs parameter
290  pop %rsi
291  CFI_ADJUST_CFA_OFFSET(-8)
292  CFI_RESTORE(%rsi)
293  // restore env parameter
294  pop %rdi
295  CFI_ADJUST_CFA_OFFSET(-8)
296  CFI_RESTORE(%rdi)
297  // tail jump to libc sigsetjmp
298  movl $0, %eax
299#if !defined(__APPLE__)
300  movq _ZN14__interception14real_sigsetjmpE@GOTPCREL(%rip), %rdx
301  jmp *(%rdx)
302#else
303  jmp ASM_TSAN_SYMBOL(sigsetjmp)
304#endif
305  CFI_ENDPROC
306ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(sigsetjmp))
307
308#if !defined(__APPLE__)
309.comm _ZN14__interception16real___sigsetjmpE,8,8
310.globl ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp)
311ASM_TYPE_FUNCTION(ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp))
312ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp):
313  CFI_STARTPROC
314  // save env parameter
315  push %rdi
316  CFI_ADJUST_CFA_OFFSET(8)
317  CFI_REL_OFFSET(%rdi, 0)
318  // save savesigs parameter
319  push %rsi
320  CFI_ADJUST_CFA_OFFSET(8)
321  CFI_REL_OFFSET(%rsi, 0)
322  // align stack frame
323  sub $8, %rsp
324  CFI_ADJUST_CFA_OFFSET(8)
325  // obtain %rsp
326#if defined(__FreeBSD__)
327  lea 24(%rsp), %rdi
328  mov %rdi, %rsi
329#else
330  lea 32(%rsp), %rdi
331  mov %rdi, %rsi
332  xor %fs:0x30, %rsi  // magic mangling of rsp (see libc setjmp)
333  rol $0x11, %rsi
334#endif
335  // call tsan interceptor
336  call ASM_TSAN_SYMBOL(__tsan_setjmp)
337  // unalign stack frame
338  add $8, %rsp
339  CFI_ADJUST_CFA_OFFSET(-8)
340  // restore savesigs parameter
341  pop %rsi
342  CFI_ADJUST_CFA_OFFSET(-8)
343  CFI_RESTORE(%rsi)
344  // restore env parameter
345  pop %rdi
346  CFI_ADJUST_CFA_OFFSET(-8)
347  CFI_RESTORE(%rdi)
348  // tail jump to libc sigsetjmp
349  movl $0, %eax
350  movq _ZN14__interception16real___sigsetjmpE@GOTPCREL(%rip), %rdx
351  jmp *(%rdx)
352  CFI_ENDPROC
353ASM_SIZE(ASM_TSAN_SYMBOL_INTERCEPTOR(__sigsetjmp))
354#endif  // !defined(__APPLE__)
355
356#if defined(__FreeBSD__) || defined(__linux__)
357/* We do not need executable stack.  */
358.section        .note.GNU-stack,"",@progbits
359#endif
360