xref: /freebsd/contrib/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl_amd64.S (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1// The content of this file is x86_64-only:
2#if defined(__x86_64__)
3
4#include "sanitizer_common/sanitizer_asm.h"
5
6#if !defined(__APPLE__)
7.section .text
8#else
9.section __TEXT,__text
10#endif
11
12ASM_HIDDEN(__tsan_setjmp)
13#if defined(__NetBSD__)
14.comm _ZN14__interception15real___setjmp14E,8,8
15#elif !defined(__APPLE__)
16.comm _ZN14__interception11real_setjmpE,8,8
17#endif
18#if defined(__NetBSD__)
19.globl ASM_SYMBOL_INTERCEPTOR(__setjmp14)
20ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__setjmp14))
21ASM_SYMBOL_INTERCEPTOR(__setjmp14):
22#else
23.globl ASM_SYMBOL_INTERCEPTOR(setjmp)
24ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(setjmp))
25ASM_SYMBOL_INTERCEPTOR(setjmp):
26#endif
27  CFI_STARTPROC
28  _CET_ENDBR
29  // save env parameter
30  push %rdi
31  CFI_ADJUST_CFA_OFFSET(8)
32  CFI_REL_OFFSET(%rdi, 0)
33  // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)`
34#if defined(__FreeBSD__) || defined(__NetBSD__)
35  lea 8(%rsp), %rdi
36#elif defined(__linux__) || defined(__APPLE__)
37  lea 16(%rsp), %rdi
38#else
39# error "Unknown platform"
40#endif
41  // call tsan interceptor
42  call ASM_SYMBOL(__tsan_setjmp)
43  // restore env parameter
44  pop %rdi
45  CFI_ADJUST_CFA_OFFSET(-8)
46  CFI_RESTORE(%rdi)
47  // tail jump to libc setjmp
48  movl $0, %eax
49#if defined(__NetBSD__)
50  movq _ZN14__interception15real___setjmp14E@GOTPCREL(%rip), %rdx
51  jmp *(%rdx)
52#elif !defined(__APPLE__)
53  movq _ZN14__interception11real_setjmpE@GOTPCREL(%rip), %rdx
54  jmp *(%rdx)
55#else
56  jmp ASM_SYMBOL(setjmp)
57#endif
58  CFI_ENDPROC
59#if defined(__NetBSD__)
60ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__setjmp14))
61#else
62ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(setjmp))
63#endif
64
65.comm _ZN14__interception12real__setjmpE,8,8
66.globl ASM_SYMBOL_INTERCEPTOR(_setjmp)
67ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(_setjmp))
68ASM_SYMBOL_INTERCEPTOR(_setjmp):
69  CFI_STARTPROC
70  _CET_ENDBR
71  // save env parameter
72  push %rdi
73  CFI_ADJUST_CFA_OFFSET(8)
74  CFI_REL_OFFSET(%rdi, 0)
75  // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)`
76#if defined(__FreeBSD__) || defined(__NetBSD__)
77  lea 8(%rsp), %rdi
78#elif defined(__linux__) || defined(__APPLE__)
79  lea 16(%rsp), %rdi
80#else
81# error "Unknown platform"
82#endif
83  // call tsan interceptor
84  call ASM_SYMBOL(__tsan_setjmp)
85  // restore env parameter
86  pop %rdi
87  CFI_ADJUST_CFA_OFFSET(-8)
88  CFI_RESTORE(%rdi)
89  // tail jump to libc setjmp
90  movl $0, %eax
91#if !defined(__APPLE__)
92  movq _ZN14__interception12real__setjmpE@GOTPCREL(%rip), %rdx
93  jmp *(%rdx)
94#else
95  jmp ASM_SYMBOL(_setjmp)
96#endif
97  CFI_ENDPROC
98ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(_setjmp))
99
100#if defined(__NetBSD__)
101.comm _ZN14__interception18real___sigsetjmp14E,8,8
102.globl ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14)
103ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14))
104ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14):
105#else
106.comm _ZN14__interception14real_sigsetjmpE,8,8
107.globl ASM_SYMBOL_INTERCEPTOR(sigsetjmp)
108ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(sigsetjmp))
109ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
110#endif
111  CFI_STARTPROC
112  _CET_ENDBR
113  // save env parameter
114  push %rdi
115  CFI_ADJUST_CFA_OFFSET(8)
116  CFI_REL_OFFSET(%rdi, 0)
117  // save savesigs parameter
118  push %rsi
119  CFI_ADJUST_CFA_OFFSET(8)
120  CFI_REL_OFFSET(%rsi, 0)
121  // align stack frame
122  sub $8, %rsp
123  CFI_ADJUST_CFA_OFFSET(8)
124  // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)`
125#if defined(__FreeBSD__) || defined(__NetBSD__)
126  lea 24(%rsp), %rdi
127#elif defined(__linux__) || defined(__APPLE__)
128  lea 32(%rsp), %rdi
129#else
130# error "Unknown platform"
131#endif
132  // call tsan interceptor
133  call ASM_SYMBOL(__tsan_setjmp)
134  // unalign stack frame
135  add $8, %rsp
136  CFI_ADJUST_CFA_OFFSET(-8)
137  // restore savesigs parameter
138  pop %rsi
139  CFI_ADJUST_CFA_OFFSET(-8)
140  CFI_RESTORE(%rsi)
141  // restore env parameter
142  pop %rdi
143  CFI_ADJUST_CFA_OFFSET(-8)
144  CFI_RESTORE(%rdi)
145  // tail jump to libc sigsetjmp
146  movl $0, %eax
147#if defined(__NetBSD__)
148  movq _ZN14__interception18real___sigsetjmp14E@GOTPCREL(%rip), %rdx
149  jmp *(%rdx)
150#elif !defined(__APPLE__)
151  movq _ZN14__interception14real_sigsetjmpE@GOTPCREL(%rip), %rdx
152  jmp *(%rdx)
153#else
154  jmp ASM_SYMBOL(sigsetjmp)
155#endif
156  CFI_ENDPROC
157#if defined(__NetBSD__)
158ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp14))
159#else
160ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(sigsetjmp))
161#endif
162
163#if !defined(__APPLE__) && !defined(__NetBSD__)
164.comm _ZN14__interception16real___sigsetjmpE,8,8
165.globl ASM_SYMBOL_INTERCEPTOR(__sigsetjmp)
166ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp))
167ASM_SYMBOL_INTERCEPTOR(__sigsetjmp):
168  CFI_STARTPROC
169  _CET_ENDBR
170  // save env parameter
171  push %rdi
172  CFI_ADJUST_CFA_OFFSET(8)
173  CFI_REL_OFFSET(%rdi, 0)
174  // save savesigs parameter
175  push %rsi
176  CFI_ADJUST_CFA_OFFSET(8)
177  CFI_REL_OFFSET(%rsi, 0)
178  // align stack frame
179  sub $8, %rsp
180  CFI_ADJUST_CFA_OFFSET(8)
181  // obtain SP, store in %rdi, first argument to `void __tsan_setjmp(uptr sp)`
182#if defined(__FreeBSD__)
183  lea 24(%rsp), %rdi
184#else
185  lea 32(%rsp), %rdi
186#endif
187  // call tsan interceptor
188  call ASM_SYMBOL(__tsan_setjmp)
189  // unalign stack frame
190  add $8, %rsp
191  CFI_ADJUST_CFA_OFFSET(-8)
192  // restore savesigs parameter
193  pop %rsi
194  CFI_ADJUST_CFA_OFFSET(-8)
195  CFI_RESTORE(%rsi)
196  // restore env parameter
197  pop %rdi
198  CFI_ADJUST_CFA_OFFSET(-8)
199  CFI_RESTORE(%rdi)
200  // tail jump to libc sigsetjmp
201  movl $0, %eax
202  movq _ZN14__interception16real___sigsetjmpE@GOTPCREL(%rip), %rdx
203  jmp *(%rdx)
204  CFI_ENDPROC
205ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp))
206#endif  // !defined(__APPLE__) && !defined(__NetBSD__)
207
208NO_EXEC_STACK_DIRECTIVE
209
210#endif
211