diff --git a/compiler-rt/lib/scudo/standalone/linux.h b/compiler-rt/lib/scudo/standalone/linux.h --- a/compiler-rt/lib/scudo/standalone/linux.h +++ b/compiler-rt/lib/scudo/standalone/linux.h @@ -18,51 +18,6 @@ // MapPlatformData is unused on Linux, define it as a minimally sized structure. struct MapPlatformData {}; -#if SCUDO_ANDROID - -#if defined(__aarch64__) -#define __get_tls() \ - ({ \ - void **__v; \ - __asm__("mrs %0, tpidr_el0" : "=r"(__v)); \ - __v; \ - }) -#elif defined(__arm__) -#define __get_tls() \ - ({ \ - void **__v; \ - __asm__("mrc p15, 0, %0, c13, c0, 3" : "=r"(__v)); \ - __v; \ - }) -#elif defined(__i386__) -#define __get_tls() \ - ({ \ - void **__v; \ - __asm__("movl %%gs:0, %0" : "=r"(__v)); \ - __v; \ - }) -#elif defined(__x86_64__) -#define __get_tls() \ - ({ \ - void **__v; \ - __asm__("mov %%fs:0, %0" : "=r"(__v)); \ - __v; \ - }) -#else -#error "Unsupported architecture." -#endif - -// The Android Bionic team has allocated a TLS slot for sanitizers starting -// with Q, given that Android currently doesn't support ELF TLS. It is used to -// store sanitizer thread specific data. -static const int TLS_SLOT_SANITIZER = 6; - -ALWAYS_INLINE uptr *getAndroidTlsPtr() { - return reinterpret_cast(&__get_tls()[TLS_SLOT_SANITIZER]); -} - -#endif // SCUDO_ANDROID - } // namespace scudo #endif // SCUDO_LINUX diff --git a/compiler-rt/lib/scudo/standalone/tsd_shared.h b/compiler-rt/lib/scudo/standalone/tsd_shared.h --- a/compiler-rt/lib/scudo/standalone/tsd_shared.h +++ b/compiler-rt/lib/scudo/standalone/tsd_shared.h @@ -12,6 +12,10 @@ #include "linux.h" // for getAndroidTlsPtr() #include "tsd.h" +#if SCUDO_HAS_PLATFORM_TLS_SLOT +#include "scudo_platform_tls_slot.h" +#endif + namespace scudo { template @@ -80,26 +84,20 @@ } private: - ALWAYS_INLINE void setCurrentTSD(TSD *CurrentTSD) { -#if _BIONIC - *getAndroidTlsPtr() = reinterpret_cast(CurrentTSD); -#elif SCUDO_LINUX - ThreadTSD = CurrentTSD; + ALWAYS_INLINE uptr *getTlsPtr() const { +#if SCUDO_HAS_PLATFORM_TLS_SLOT + return reinterpret_cast(getPlatformTlsSlot()); #else - CHECK_EQ( - pthread_setspecific(PThreadKey, reinterpret_cast(CurrentTSD)), - 0); + return &ThreadTSD; #endif } + ALWAYS_INLINE void setCurrentTSD(TSD *CurrentTSD) { + *getTlsPtr() = reinterpret_cast(CurrentTSD); + } + ALWAYS_INLINE TSD *getCurrentTSD() { -#if _BIONIC - return reinterpret_cast *>(*getAndroidTlsPtr()); -#elif SCUDO_LINUX - return ThreadTSD; -#else - return reinterpret_cast *>(pthread_getspecific(PThreadKey)); -#endif + return reinterpret_cast *>(*getTlsPtr()); } bool setNumberOfTSDs(u32 N) { @@ -196,14 +194,14 @@ HybridMutex MutexTSDs; TSD TSDs[TSDsArraySize]; #if SCUDO_LINUX && !_BIONIC - static THREADLOCAL TSD *ThreadTSD; + static THREADLOCAL uptr ThreadTSD; #endif }; #if SCUDO_LINUX && !_BIONIC template -THREADLOCAL TSD - *TSDRegistrySharedT::ThreadTSD; +THREADLOCAL uptr + TSDRegistrySharedT::ThreadTSD; #endif } // namespace scudo