forked from OSchip/llvm-project
[tsan] Adjust setjmp/longjmp handling on Darwin for macOS Mojave
On macOS Mojave, the OS started using the XOR-by-a-secret-key scheme (same as glibc is alread doing) for storing the SP value in setjmp environment. We need to adjust for that to keep supporting setjmp/longjmp on latest Darwin. The patch is basically doing the same what we're already doing for glibc. rdar://problem/43542596 Differential Revision: https://reviews.llvm.org/D51064 llvm-svn: 340350
This commit is contained in:
parent
14a577bfd1
commit
986f03c2ea
|
@ -511,6 +511,10 @@ MacosVersion GetMacosVersionInternal() {
|
|||
case '2': return MACOS_VERSION_MOUNTAIN_LION;
|
||||
case '3': return MACOS_VERSION_MAVERICKS;
|
||||
case '4': return MACOS_VERSION_YOSEMITE;
|
||||
case '5': return MACOS_VERSION_EL_CAPITAN;
|
||||
case '6': return MACOS_VERSION_SIERRA;
|
||||
case '7': return MACOS_VERSION_HIGH_SIERRA;
|
||||
case '8': return MACOS_VERSION_MOJAVE;
|
||||
default:
|
||||
if (IsDigit(version[1]))
|
||||
return MACOS_VERSION_UNKNOWN_NEWER;
|
||||
|
|
|
@ -40,6 +40,10 @@ enum MacosVersion {
|
|||
MACOS_VERSION_MOUNTAIN_LION,
|
||||
MACOS_VERSION_MAVERICKS,
|
||||
MACOS_VERSION_YOSEMITE,
|
||||
MACOS_VERSION_EL_CAPITAN,
|
||||
MACOS_VERSION_SIERRA,
|
||||
MACOS_VERSION_HIGH_SIERRA,
|
||||
MACOS_VERSION_MOJAVE,
|
||||
MACOS_VERSION_UNKNOWN_NEWER
|
||||
};
|
||||
|
||||
|
|
|
@ -508,7 +508,8 @@ static void LongJmp(ThreadState *thr, uptr *env) {
|
|||
uptr mangled_sp = env[6];
|
||||
#elif SANITIZER_MAC
|
||||
# ifdef __aarch64__
|
||||
uptr mangled_sp = env[13];
|
||||
uptr mangled_sp =
|
||||
(GetMacosVersion() >= MACOS_VERSION_MOJAVE) ? env[12] : env[13];
|
||||
# else
|
||||
uptr mangled_sp = env[2];
|
||||
# endif
|
||||
|
|
|
@ -240,6 +240,9 @@ void InitializePlatformEarly() {
|
|||
#endif
|
||||
}
|
||||
|
||||
static const uptr kPthreadSetjmpXorKeySlot = 0x7;
|
||||
extern "C" uptr __tsan_darwin_setjmp_xor_key = 0;
|
||||
|
||||
void InitializePlatform() {
|
||||
DisableCoreDumperIfNecessary();
|
||||
#if !SANITIZER_GO
|
||||
|
@ -251,6 +254,11 @@ void InitializePlatform() {
|
|||
prev_pthread_introspection_hook =
|
||||
pthread_introspection_hook_install(&my_pthread_introspection_hook);
|
||||
#endif
|
||||
|
||||
if (GetMacosVersion() >= MACOS_VERSION_MOJAVE) {
|
||||
__tsan_darwin_setjmp_xor_key =
|
||||
(uptr)pthread_getspecific(kPthreadSetjmpXorKeySlot);
|
||||
}
|
||||
}
|
||||
|
||||
#if !SANITIZER_GO
|
||||
|
|
|
@ -120,8 +120,10 @@ ASM_SYMBOL_INTERCEPTOR(setjmp):
|
|||
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
|
||||
mov x1, x0
|
||||
eor x1, x2, x0
|
||||
#endif
|
||||
|
||||
// call tsan interceptor
|
||||
|
@ -178,8 +180,10 @@ ASM_SYMBOL_INTERCEPTOR(_setjmp):
|
|||
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
|
||||
mov x1, x0
|
||||
eor x1, x2, x0
|
||||
#endif
|
||||
|
||||
// call tsan interceptor
|
||||
|
@ -238,8 +242,10 @@ ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
|
|||
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
|
||||
mov x1, x0
|
||||
eor x1, x2, x0
|
||||
#endif
|
||||
|
||||
// call tsan interceptor
|
||||
|
|
|
@ -196,6 +196,7 @@ ASM_SYMBOL_INTERCEPTOR(setjmp):
|
|||
#elif defined(__APPLE__)
|
||||
lea 16(%rsp), %rdi
|
||||
mov %rdi, %rsi
|
||||
xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
|
||||
#elif defined(__linux__)
|
||||
lea 16(%rsp), %rdi
|
||||
mov %rdi, %rsi
|
||||
|
@ -244,6 +245,7 @@ ASM_SYMBOL_INTERCEPTOR(_setjmp):
|
|||
#elif defined(__APPLE__)
|
||||
lea 16(%rsp), %rdi
|
||||
mov %rdi, %rsi
|
||||
xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
|
||||
#elif defined(__linux__)
|
||||
lea 16(%rsp), %rdi
|
||||
mov %rdi, %rsi
|
||||
|
@ -299,6 +301,7 @@ ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
|
|||
#elif defined(__APPLE__)
|
||||
lea 32(%rsp), %rdi
|
||||
mov %rdi, %rsi
|
||||
xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
|
||||
#elif defined(__linux__)
|
||||
lea 32(%rsp), %rdi
|
||||
mov %rdi, %rsi
|
||||
|
|
Loading…
Reference in New Issue