diff --git a/compiler-rt/lib/scudo/scudo_tsd_shared.cpp b/compiler-rt/lib/scudo/scudo_tsd_shared.cpp --- a/compiler-rt/lib/scudo/scudo_tsd_shared.cpp +++ b/compiler-rt/lib/scudo/scudo_tsd_shared.cpp @@ -14,6 +14,10 @@ #if !SCUDO_TSD_EXCLUSIVE +#if SCUDO_HAS_PLATFORM_TLS_SLOT +#include "scudo_platform_tls_slot.h" +#endif + namespace __scudo { static pthread_once_t GlobalInitialized = PTHREAD_ONCE_INIT; @@ -25,11 +29,21 @@ static u32 CoPrimes[SCUDO_SHARED_TSD_POOL_SIZE]; static u32 NumberOfCoPrimes = 0; -#if SANITIZER_LINUX && !SANITIZER_ANDROID -__attribute__((tls_model("initial-exec"))) -THREADLOCAL ScudoTSD *CurrentTSD; +#if !SCUDO_HAS_PLATFORM_TLS_SLOT && SANITIZER_LINUX +__attribute__((tls_model("initial-exec"))) THREADLOCAL ScudoTSD *CurrentTSD = + nullptr; #endif +ALWAYS_INLINE void setCurrentTSD(ScudoTSD *TSD) { +#if SCUDO_HAS_PLATFORM_TLS_SLOT + *getPlatformAllocatorTlsSlot() = reinterpret_cast(TSD); +#elif SANITIZER_LINUX + CurrentTSD = TSD; +#else + CHECK_EQ(pthread_setspecific(PThreadKey, reinterpret_cast(TSD)), 0); +#endif +} + static void initOnce() { CHECK_EQ(pthread_key_create(&PThreadKey, NULL), 0); initScudo(); @@ -47,16 +61,6 @@ } } -ALWAYS_INLINE void setCurrentTSD(ScudoTSD *TSD) { -#if SANITIZER_ANDROID - *get_android_tls_ptr() = reinterpret_cast(TSD); -#elif SANITIZER_LINUX - CurrentTSD = TSD; -#else - CHECK_EQ(pthread_setspecific(PThreadKey, reinterpret_cast(TSD)), 0); -#endif // SANITIZER_ANDROID -} - void initThread(bool MinimalInit) { pthread_once(&GlobalInitialized, initOnce); // Initial context assignment is done in a plain round-robin fashion. diff --git a/compiler-rt/lib/scudo/scudo_tsd_shared.inc b/compiler-rt/lib/scudo/scudo_tsd_shared.inc --- a/compiler-rt/lib/scudo/scudo_tsd_shared.inc +++ b/compiler-rt/lib/scudo/scudo_tsd_shared.inc @@ -18,24 +18,25 @@ extern pthread_key_t PThreadKey; -#if SANITIZER_LINUX && !SANITIZER_ANDROID +#if !SCUDO_HAS_PLATFORM_TLS_SLOT && SANITIZER_LINUX __attribute__((tls_model("initial-exec"))) extern THREADLOCAL ScudoTSD *CurrentTSD; #endif ALWAYS_INLINE ScudoTSD* getCurrentTSD() { -#if SANITIZER_ANDROID - return reinterpret_cast(*get_android_tls_ptr()); +#if SCUDO_HAS_PLATFORM_TLS_SLOT + return reinterpret_cast(*getPlatformAllocatorTlsSlot()); #elif SANITIZER_LINUX - return CurrentTSD; + return CurrentTSD; #else - return reinterpret_cast(pthread_getspecific(PThreadKey)); -#endif // SANITIZER_ANDROID + return reinterpret_cast(pthread_getspecific(PThreadKey)); +#endif } + ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) { if (LIKELY(getCurrentTSD())) - return; + return; initThread(MinimalInit); }