aboutsummaryrefslogtreecommitdiff
path: root/lib/tsan/rtl/tsan_rtl_aarch64.S
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tsan/rtl/tsan_rtl_aarch64.S')
-rw-r--r--lib/tsan/rtl/tsan_rtl_aarch64.S196
1 files changed, 49 insertions, 147 deletions
diff --git a/lib/tsan/rtl/tsan_rtl_aarch64.S b/lib/tsan/rtl/tsan_rtl_aarch64.S
index 3d02bf22f8a5..e0b4c71dfed9 100644
--- a/lib/tsan/rtl/tsan_rtl_aarch64.S
+++ b/lib/tsan/rtl/tsan_rtl_aarch64.S
@@ -3,14 +3,6 @@
#include "sanitizer_common/sanitizer_asm.h"
-#if !defined(__APPLE__)
-.section .bss
-.type __tsan_pointer_chk_guard, %object
-ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__tsan_pointer_chk_guard))
-__tsan_pointer_chk_guard:
-.zero 8
-#endif
-
#if defined(__APPLE__)
.align 2
@@ -40,57 +32,6 @@ _sigsetjmp$non_lazy_ptr:
.align 3
#endif
-#if !defined(__APPLE__)
-// GLIBC mangles the function pointers in jmp_buf (used in {set,long}*jmp
-// functions) by XORing them with a random guard pointer. For AArch64 it is a
-// global variable rather than a TCB one (as for x86_64/powerpc) and althought
-// its value is exported by the loader, it lies within a private GLIBC
-// namespace (meaning it should be only used by GLIBC itself and the ABI is
-// not stable). So InitializeGuardPtr obtains the pointer guard value by
-// issuing a setjmp and checking the resulting pointers values against the
-// original ones.
-ASM_HIDDEN(_Z18InitializeGuardPtrv)
-.global _Z18InitializeGuardPtrv
-ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(_Z18InitializeGuardPtrv))
-_Z18InitializeGuardPtrv:
- CFI_STARTPROC
- // Allocates a jmp_buf for the setjmp call.
- stp x29, x30, [sp, -336]!
- CFI_DEF_CFA_OFFSET (336)
- CFI_OFFSET (29, -336)
- CFI_OFFSET (30, -328)
- add x29, sp, 0
- CFI_DEF_CFA_REGISTER (29)
- add x0, x29, 24
-
- // Call libc setjmp that mangle the stack pointer value
- adrp x1, :got:_ZN14__interception12real__setjmpE
- ldr x1, [x1, #:got_lo12:_ZN14__interception12real__setjmpE]
- ldr x1, [x1]
- blr x1
-
- // glibc setjmp mangles both the frame pointer (FP, pc+4 on blr) and the
- // stack pointer (SP). FP will be placed on ((uintptr*)jmp_buf)[11] and
- // SP at ((uintptr*)jmp_buf)[13].
- // The mangle operation is just 'value' xor 'pointer guard value' and
- // if we know the original value (SP) and the expected one, we can derive
- // the guard pointer value.
- mov x0, sp
-
- // Loads the mangled SP pointer.
- ldr x1, [x29, 128]
- eor x0, x0, x1
- adrp x2, __tsan_pointer_chk_guard
- str x0, [x2, #:lo12:__tsan_pointer_chk_guard]
- ldp x29, x30, [sp], 336
- CFI_RESTORE (30)
- CFI_RESTORE (19)
- CFI_DEF_CFA (31, 0)
- ret
- CFI_ENDPROC
-ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(_Z18InitializeGuardPtrv))
-#endif
-
ASM_HIDDEN(__tsan_setjmp)
.comm _ZN14__interception11real_setjmpE,8,8
.globl ASM_SYMBOL_INTERCEPTOR(setjmp)
@@ -98,7 +39,7 @@ ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(setjmp))
ASM_SYMBOL_INTERCEPTOR(setjmp):
CFI_STARTPROC
- // save env parameters for function call
+ // Save frame/link register
stp x29, x30, [sp, -32]!
CFI_DEF_CFA_OFFSET (32)
CFI_OFFSET (29, -32)
@@ -108,33 +49,24 @@ ASM_SYMBOL_INTERCEPTOR(setjmp):
add x29, sp, 0
CFI_DEF_CFA_REGISTER (29)
- // Save jmp_buf
- str x19, [sp, 16]
- CFI_OFFSET (19, -16)
- mov x19, x0
+ // Save env parameter
+ str x0, [sp, 16]
+ CFI_OFFSET (0, -16)
-#if !defined(__APPLE__)
- // SP pointer mangling (see glibc setjmp)
- adrp x2, __tsan_pointer_chk_guard
- ldr x2, [x2, #:lo12:__tsan_pointer_chk_guard]
- add x0, x29, 32
- eor x1, x2, x0
-#else
- adrp x2, ___tsan_darwin_setjmp_xor_key@page
- ldr x2, [x2, ___tsan_darwin_setjmp_xor_key@pageoff]
+ // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
add x0, x29, 32
- eor x1, x2, x0
-#endif
// call tsan interceptor
bl ASM_SYMBOL(__tsan_setjmp)
- // restore env parameter
- mov x0, x19
- ldr x19, [sp, 16]
+ // Restore env parameter
+ ldr x0, [sp, 16]
+ CFI_RESTORE (0)
+
+ // Restore frame/link register
ldp x29, x30, [sp], 32
+ CFI_RESTORE (29)
CFI_RESTORE (30)
- CFI_RESTORE (19)
CFI_DEF_CFA (31, 0)
// tail jump to libc setjmp
@@ -158,7 +90,7 @@ ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(_setjmp))
ASM_SYMBOL_INTERCEPTOR(_setjmp):
CFI_STARTPROC
- // save env parameters for function call
+ // Save frame/link register
stp x29, x30, [sp, -32]!
CFI_DEF_CFA_OFFSET (32)
CFI_OFFSET (29, -32)
@@ -168,33 +100,24 @@ ASM_SYMBOL_INTERCEPTOR(_setjmp):
add x29, sp, 0
CFI_DEF_CFA_REGISTER (29)
- // Save jmp_buf
- str x19, [sp, 16]
- CFI_OFFSET (19, -16)
- mov x19, x0
+ // Save env parameter
+ str x0, [sp, 16]
+ CFI_OFFSET (0, -16)
-#if !defined(__APPLE__)
- // SP pointer mangling (see glibc setjmp)
- adrp x2, __tsan_pointer_chk_guard
- ldr x2, [x2, #:lo12:__tsan_pointer_chk_guard]
+ // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
add x0, x29, 32
- eor x1, x2, x0
-#else
- adrp x2, ___tsan_darwin_setjmp_xor_key@page
- ldr x2, [x2, ___tsan_darwin_setjmp_xor_key@pageoff]
- add x0, x29, 32
- eor x1, x2, x0
-#endif
// call tsan interceptor
bl ASM_SYMBOL(__tsan_setjmp)
- // Restore jmp_buf parameter
- mov x0, x19
- ldr x19, [sp, 16]
+ // Restore env parameter
+ ldr x0, [sp, 16]
+ CFI_RESTORE (0)
+
+ // Restore frame/link register
ldp x29, x30, [sp], 32
+ CFI_RESTORE (29)
CFI_RESTORE (30)
- CFI_RESTORE (19)
CFI_DEF_CFA (31, 0)
// tail jump to libc setjmp
@@ -218,7 +141,7 @@ ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(sigsetjmp))
ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
CFI_STARTPROC
- // save env parameters for function call
+ // Save frame/link register
stp x29, x30, [sp, -32]!
CFI_DEF_CFA_OFFSET (32)
CFI_OFFSET (29, -32)
@@ -228,38 +151,26 @@ ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
add x29, sp, 0
CFI_DEF_CFA_REGISTER (29)
- // Save jmp_buf and savesigs
- stp x19, x20, [sp, 16]
- CFI_OFFSET (19, -16)
- CFI_OFFSET (20, -8)
- mov w20, w1
- mov x19, x0
+ // Save env and savesigs parameter
+ stp x0, x1, [sp, 16]
+ CFI_OFFSET (0, -16)
+ CFI_OFFSET (1, -8)
-#if !defined(__APPLE__)
- // SP pointer mangling (see glibc setjmp)
- adrp x2, __tsan_pointer_chk_guard
- ldr x2, [x2, #:lo12:__tsan_pointer_chk_guard]
- add x0, x29, 32
- eor x1, x2, x0
-#else
- adrp x2, ___tsan_darwin_setjmp_xor_key@page
- ldr x2, [x2, ___tsan_darwin_setjmp_xor_key@pageoff]
+ // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
add x0, x29, 32
- eor x1, x2, x0
-#endif
// call tsan interceptor
bl ASM_SYMBOL(__tsan_setjmp)
- // restore env parameter
- mov w1, w20
- mov x0, x19
- ldp x19, x20, [sp, 16]
+ // Restore env and savesigs parameter
+ ldp x0, x1, [sp, 16]
+ CFI_RESTORE (0)
+ CFI_RESTORE (1)
+
+ // Restore frame/link register
ldp x29, x30, [sp], 32
- CFI_RESTORE (30)
CFI_RESTORE (29)
- CFI_RESTORE (19)
- CFI_RESTORE (20)
+ CFI_RESTORE (30)
CFI_DEF_CFA (31, 0)
// tail jump to libc sigsetjmp
@@ -283,7 +194,7 @@ ASM_TYPE_FUNCTION(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp))
ASM_SYMBOL_INTERCEPTOR(__sigsetjmp):
CFI_STARTPROC
- // save env parameters for function call
+ // Save frame/link register
stp x29, x30, [sp, -32]!
CFI_DEF_CFA_OFFSET (32)
CFI_OFFSET (29, -32)
@@ -293,32 +204,26 @@ ASM_SYMBOL_INTERCEPTOR(__sigsetjmp):
add x29, sp, 0
CFI_DEF_CFA_REGISTER (29)
- // Save jmp_buf and savesigs
- stp x19, x20, [sp, 16]
- CFI_OFFSET (19, -16)
- CFI_OFFSET (20, -8)
- mov w20, w1
- mov x19, x0
+ // Save env and savesigs parameter
+ stp x0, x1, [sp, 16]
+ CFI_OFFSET (0, -16)
+ CFI_OFFSET (1, -8)
-#if !defined(__APPLE__)
- // SP pointer mangling (see glibc setjmp)
- adrp x2, __tsan_pointer_chk_guard
- ldr x2, [x2, #:lo12:__tsan_pointer_chk_guard]
+ // Obtain SP, first argument to `void __tsan_setjmp(uptr sp)`
add x0, x29, 32
- eor x1, x2, x0
-#endif
// call tsan interceptor
bl ASM_SYMBOL(__tsan_setjmp)
- mov w1, w20
- mov x0, x19
- ldp x19, x20, [sp, 16]
+ // Restore env and savesigs parameter
+ ldp x0, x1, [sp, 16]
+ CFI_RESTORE (0)
+ CFI_RESTORE (1)
+
+ // Restore frame/link register
ldp x29, x30, [sp], 32
- CFI_RESTORE (30)
CFI_RESTORE (29)
- CFI_RESTORE (19)
- CFI_RESTORE (20)
+ CFI_RESTORE (30)
CFI_DEF_CFA (31, 0)
// tail jump to libc __sigsetjmp
@@ -335,9 +240,6 @@ ASM_SYMBOL_INTERCEPTOR(__sigsetjmp):
ASM_SIZE(ASM_SYMBOL_INTERCEPTOR(__sigsetjmp))
#endif
-#if defined(__linux__)
-/* We do not need executable stack. */
-.section .note.GNU-stack,"",@progbits
-#endif
+NO_EXEC_STACK_DIRECTIVE
#endif