1 #include "sanitizer_common/sanitizer_asm.h"
2 .type __tsan_pointer_chk_guard, %object
3 .size __tsan_pointer_chk_guard, 8
4 __tsan_pointer_chk_guard:
9 // GLIBC mangles the function pointers in jmp_buf (used in {set,long}*jmp
10 // functions) by XORing them with a random guard pointer. For AArch64 it is a
11 // global variable rather than a TCB one (as for x86_64/powerpc) and althought
12 // its value is exported by the loader, it lies within a private GLIBC
13 // namespace (meaning it should be only used by GLIBC itself and the ABI is
14 // not stable). So InitializeGuardPtr obtains the pointer guard value by
15 // issuing a setjmp and checking the resulting pointers values against the
17 .hidden _Z18InitializeGuardPtrv
18 .global _Z18InitializeGuardPtrv
19 .type _Z18InitializeGuardPtrv, @function
20 _Z18InitializeGuardPtrv:
22 // Allocates a jmp_buf for the setjmp call.
23 stp x29, x30, [sp, -336]!
24 CFI_DEF_CFA_OFFSET (336)
28 CFI_DEF_CFA_REGISTER (29)
31 // Call libc setjmp that mangle the stack pointer value
32 adrp x1, :got:_ZN14__interception12real__setjmpE
33 ldr x1, [x1, #:got_lo12:_ZN14__interception12real__setjmpE]
37 // glibc setjmp mangles both the frame pointer (FP, pc+4 on blr) and the
38 // stack pointer (SP). FP will be placed on ((uintptr*)jmp_buf)[11] and
39 // SP at ((uintptr*)jmp_buf)[13].
40 // The mangle operation is just 'value' xor 'pointer guard value' and
41 // if we know the original value (SP) and the expected one, we can derive
42 // the guard pointer value.
45 // Loads the mangled SP pointer.
48 adrp x2, __tsan_pointer_chk_guard
49 str x0, [x2, #:lo12:__tsan_pointer_chk_guard]
50 ldp x29, x30, [sp], 336
56 .size _Z18InitializeGuardPtrv, .-_Z18InitializeGuardPtrv
59 .comm _ZN14__interception11real_setjmpE,8,8
60 .type setjmp, @function
64 // save env parameters for function call
65 stp x29, x30, [sp, -32]!
66 CFI_DEF_CFA_OFFSET (32)
70 // Adjust the SP for previous frame
72 CFI_DEF_CFA_REGISTER (29)
79 // SP pointer mangling (see glibc setjmp)
80 adrp x2, __tsan_pointer_chk_guard
81 ldr x2, [x2, #:lo12:__tsan_pointer_chk_guard]
85 // call tsan interceptor
88 // restore env parameter
91 ldp x29, x30, [sp], 32
96 // tail jump to libc setjmp
97 adrp x1, :got:_ZN14__interception11real_setjmpE
98 ldr x1, [x1, #:got_lo12:_ZN14__interception11real_setjmpE]
103 .size setjmp, .-setjmp
105 .comm _ZN14__interception12real__setjmpE,8,8
107 .type _setjmp, @function
111 // save env parameters for function call
112 stp x29, x30, [sp, -32]!
113 CFI_DEF_CFA_OFFSET (32)
117 // Adjust the SP for previous frame
119 CFI_DEF_CFA_REGISTER (29)
126 // SP pointer mangling (see glibc setjmp)
127 adrp x2, __tsan_pointer_chk_guard
128 ldr x2, [x2, #:lo12:__tsan_pointer_chk_guard]
132 // call tsan interceptor
135 // Restore jmp_buf parameter
138 ldp x29, x30, [sp], 32
143 // tail jump to libc setjmp
144 adrp x1, :got:_ZN14__interception12real__setjmpE
145 ldr x1, [x1, #:got_lo12:_ZN14__interception12real__setjmpE]
150 .size _setjmp, .-_setjmp
152 .comm _ZN14__interception14real_sigsetjmpE,8,8
154 .type sigsetjmp, @function
158 // save env parameters for function call
159 stp x29, x30, [sp, -32]!
160 CFI_DEF_CFA_OFFSET (32)
164 // Adjust the SP for previous frame
166 CFI_DEF_CFA_REGISTER (29)
168 // Save jmp_buf and savesigs
169 stp x19, x20, [sp, 16]
175 // SP pointer mangling (see glibc setjmp)
176 adrp x2, __tsan_pointer_chk_guard
177 ldr x2, [x2, #:lo12:__tsan_pointer_chk_guard]
181 // call tsan interceptor
184 // restore env parameter
187 ldp x19, x20, [sp, 16]
188 ldp x29, x30, [sp], 32
195 // tail jump to libc sigsetjmp
196 adrp x2, :got:_ZN14__interception14real_sigsetjmpE
197 ldr x2, [x2, #:got_lo12:_ZN14__interception14real_sigsetjmpE]
201 .size sigsetjmp, .-sigsetjmp
203 .comm _ZN14__interception16real___sigsetjmpE,8,8
205 .type __sigsetjmp, @function
209 // save env parameters for function call
210 stp x29, x30, [sp, -32]!
211 CFI_DEF_CFA_OFFSET (32)
215 // Adjust the SP for previous frame
217 CFI_DEF_CFA_REGISTER (29)
219 // Save jmp_buf and savesigs
220 stp x19, x20, [sp, 16]
226 // SP pointer mangling (see glibc setjmp)
227 adrp x2, __tsan_pointer_chk_guard
228 ldr x2, [x2, #:lo12:__tsan_pointer_chk_guard]
232 // call tsan interceptor
237 ldp x19, x20, [sp, 16]
238 ldp x29, x30, [sp], 32
245 // tail jump to libc __sigsetjmp
246 adrp x2, :got:_ZN14__interception16real___sigsetjmpE
247 ldr x2, [x2, #:got_lo12:_ZN14__interception16real___sigsetjmpE]
251 .size __sigsetjmp, .-__sigsetjmp
253 #if defined(__linux__)
254 /* We do not need executable stack. */
255 .section .note.GNU-stack,"",@progbits