Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit a5c62c5

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@340350 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0a26e00 commit a5c62c5

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

lib/sanitizer_common/sanitizer_mac.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ MacosVersion GetMacosVersionInternal() {
468468
case '2': return MACOS_VERSION_MOUNTAIN_LION;
469469
case '3': return MACOS_VERSION_MAVERICKS;
470470
case '4': return MACOS_VERSION_YOSEMITE;
471+
case '5': return MACOS_VERSION_EL_CAPITAN;
472+
case '6': return MACOS_VERSION_SIERRA;
473+
case '7': return MACOS_VERSION_HIGH_SIERRA;
474+
case '8': return MACOS_VERSION_MOJAVE;
471475
default:
472476
if (IsDigit(version[1]))
473477
return MACOS_VERSION_UNKNOWN_NEWER;

lib/sanitizer_common/sanitizer_mac.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ enum MacosVersion {
4040
MACOS_VERSION_MOUNTAIN_LION,
4141
MACOS_VERSION_MAVERICKS,
4242
MACOS_VERSION_YOSEMITE,
43+
MACOS_VERSION_EL_CAPITAN,
44+
MACOS_VERSION_SIERRA,
45+
MACOS_VERSION_HIGH_SIERRA,
46+
MACOS_VERSION_MOJAVE,
4347
MACOS_VERSION_UNKNOWN_NEWER
4448
};
4549

lib/tsan/rtl/tsan_interceptors.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ static void LongJmp(ThreadState *thr, uptr *env) {
508508
uptr mangled_sp = env[6];
509509
#elif SANITIZER_MAC
510510
# ifdef __aarch64__
511-
uptr mangled_sp = env[13];
511+
uptr mangled_sp =
512+
(GetMacosVersion() >= MACOS_VERSION_MOJAVE) ? env[12] : env[13];
512513
# else
513514
uptr mangled_sp = env[2];
514515
# endif

lib/tsan/rtl/tsan_platform_mac.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ void InitializePlatformEarly() {
240240
#endif
241241
}
242242

243+
static const uptr kPthreadSetjmpXorKeySlot = 0x7;
244+
extern "C" uptr __tsan_darwin_setjmp_xor_key = 0;
245+
243246
void InitializePlatform() {
244247
DisableCoreDumperIfNecessary();
245248
#if !SANITIZER_GO
@@ -251,6 +254,11 @@ void InitializePlatform() {
251254
prev_pthread_introspection_hook =
252255
pthread_introspection_hook_install(&my_pthread_introspection_hook);
253256
#endif
257+
258+
if (GetMacosVersion() >= MACOS_VERSION_MOJAVE) {
259+
__tsan_darwin_setjmp_xor_key =
260+
(uptr)pthread_getspecific(kPthreadSetjmpXorKeySlot);
261+
}
254262
}
255263

256264
#if !SANITIZER_GO

lib/tsan/rtl/tsan_rtl_aarch64.S

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ ASM_SYMBOL_INTERCEPTOR(setjmp):
120120
add x0, x29, 32
121121
eor x1, x2, x0
122122
#else
123+
adrp x2, ___tsan_darwin_setjmp_xor_key@page
124+
ldr x2, [x2, ___tsan_darwin_setjmp_xor_key@pageoff]
123125
add x0, x29, 32
124-
mov x1, x0
126+
eor x1, x2, x0
125127
#endif
126128

127129
// call tsan interceptor
@@ -178,8 +180,10 @@ ASM_SYMBOL_INTERCEPTOR(_setjmp):
178180
add x0, x29, 32
179181
eor x1, x2, x0
180182
#else
183+
adrp x2, ___tsan_darwin_setjmp_xor_key@page
184+
ldr x2, [x2, ___tsan_darwin_setjmp_xor_key@pageoff]
181185
add x0, x29, 32
182-
mov x1, x0
186+
eor x1, x2, x0
183187
#endif
184188

185189
// call tsan interceptor
@@ -238,8 +242,10 @@ ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
238242
add x0, x29, 32
239243
eor x1, x2, x0
240244
#else
245+
adrp x2, ___tsan_darwin_setjmp_xor_key@page
246+
ldr x2, [x2, ___tsan_darwin_setjmp_xor_key@pageoff]
241247
add x0, x29, 32
242-
mov x1, x0
248+
eor x1, x2, x0
243249
#endif
244250

245251
// call tsan interceptor

lib/tsan/rtl/tsan_rtl_amd64.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ ASM_SYMBOL_INTERCEPTOR(setjmp):
196196
#elif defined(__APPLE__)
197197
lea 16(%rsp), %rdi
198198
mov %rdi, %rsi
199+
xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
199200
#elif defined(__linux__)
200201
lea 16(%rsp), %rdi
201202
mov %rdi, %rsi
@@ -244,6 +245,7 @@ ASM_SYMBOL_INTERCEPTOR(_setjmp):
244245
#elif defined(__APPLE__)
245246
lea 16(%rsp), %rdi
246247
mov %rdi, %rsi
248+
xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
247249
#elif defined(__linux__)
248250
lea 16(%rsp), %rdi
249251
mov %rdi, %rsi
@@ -299,6 +301,7 @@ ASM_SYMBOL_INTERCEPTOR(sigsetjmp):
299301
#elif defined(__APPLE__)
300302
lea 32(%rsp), %rdi
301303
mov %rdi, %rsi
304+
xorq ___tsan_darwin_setjmp_xor_key(%rip), %rsi
302305
#elif defined(__linux__)
303306
lea 32(%rsp), %rdi
304307
mov %rdi, %rsi

0 commit comments

Comments
 (0)