diff --git a/compiler-rt/lib/scudo/standalone/allocator_config.h b/compiler-rt/lib/scudo/standalone/allocator_config.h --- a/compiler-rt/lib/scudo/standalone/allocator_config.h +++ b/compiler-rt/lib/scudo/standalone/allocator_config.h @@ -67,7 +67,7 @@ using TSDRegistryT = TSDRegistrySharedT; // Shared, max 8 TSDs. }; -#if SCUDO_ANDROID +#if SCUDO_ANDROID_BIONIC typedef AndroidConfig Config; #elif SCUDO_FUCHSIA typedef FuchsiaConfig Config; diff --git a/compiler-rt/lib/scudo/standalone/common.h b/compiler-rt/lib/scudo/standalone/common.h --- a/compiler-rt/lib/scudo/standalone/common.h +++ b/compiler-rt/lib/scudo/standalone/common.h @@ -119,7 +119,7 @@ uptr getPageSizeSlow(); INLINE uptr getPageSizeCached() { // Bionic uses a hardcoded value. - if (SCUDO_ANDROID) + if (SCUDO_ANDROID_BIONIC) return 4096U; if (LIKELY(PageSizeCached)) return PageSizeCached; 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,7 +18,7 @@ // MapPlatformData is unused on Linux, define it as a minimally sized structure. struct MapPlatformData {}; -#if SCUDO_ANDROID +#if SCUDO_ANDROID_BIONIC #if defined(__aarch64__) #define __get_tls() \ @@ -52,16 +52,14 @@ #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 = 8; // TODO(kostyak): 6 for Q!! +// To get the TLS_SLOT_SANITIZER define from bionic headers. +#include ALWAYS_INLINE uptr *getAndroidTlsPtr() { return reinterpret_cast(&__get_tls()[TLS_SLOT_SANITIZER]); } -#endif // SCUDO_ANDROID +#endif // SCUDO_ANDROID_BIONIC } // namespace scudo diff --git a/compiler-rt/lib/scudo/standalone/linux.cpp b/compiler-rt/lib/scudo/standalone/linux.cpp --- a/compiler-rt/lib/scudo/standalone/linux.cpp +++ b/compiler-rt/lib/scudo/standalone/linux.cpp @@ -28,11 +28,8 @@ #include #include -#if SCUDO_ANDROID +#if SCUDO_ANDROID_BIONIC #include -// Definitions of prctl arguments to set a vma name in Android kernels. -#define ANDROID_PR_SET_VMA 0x53564d41 -#define ANDROID_PR_SET_VMA_ANON_NAME 0 #endif namespace scudo { @@ -62,9 +59,9 @@ dieOnMapUnmapError(errno == ENOMEM); return nullptr; } -#if SCUDO_ANDROID +#if SCUDO_ANDROID_BIONIC if (!(Flags & MAP_NOACCESS)) - prctl(ANDROID_PR_SET_VMA, ANDROID_PR_SET_VMA_ANON_NAME, P, Size, Name); + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, P, Size, Name); #endif return P; } diff --git a/compiler-rt/lib/scudo/standalone/platform.h b/compiler-rt/lib/scudo/standalone/platform.h --- a/compiler-rt/lib/scudo/standalone/platform.h +++ b/compiler-rt/lib/scudo/standalone/platform.h @@ -16,9 +16,17 @@ #endif #if defined(__ANDROID__) -#define SCUDO_ANDROID 1 +// Include this to get the __BIONIC__ define. +#include + +#if defined(__BIONIC__) +#define SCUDO_ANDROID_BIONIC 1 +#else +#define SCUDO_ANDROID_BIONIC 0 +#endif + #else -#define SCUDO_ANDROID 0 +#define SCUDO_ANDROID_BIONIC 0 #endif #if defined(__Fuchsia__) 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 @@ -72,7 +72,7 @@ private: ALWAYS_INLINE void setCurrentTSD(TSD *CurrentTSD) { -#if SCUDO_ANDROID +#if SCUDO_ANDROID_BIONIC *getAndroidTlsPtr() = reinterpret_cast(CurrentTSD); #elif SCUDO_LINUX ThreadTSD = CurrentTSD; @@ -84,7 +84,7 @@ } ALWAYS_INLINE TSD *getCurrentTSD() { -#if SCUDO_ANDROID +#if SCUDO_ANDROID_BIONIC return reinterpret_cast *>(*getAndroidTlsPtr()); #elif SCUDO_LINUX return ThreadTSD; @@ -152,12 +152,12 @@ u32 CoPrimes[MaxTSDCount]; bool Initialized; HybridMutex Mutex; -#if SCUDO_LINUX && !SCUDO_ANDROID +#if SCUDO_LINUX && !SCUDO_ANDROID_BIONIC static THREADLOCAL TSD *ThreadTSD; #endif }; -#if SCUDO_LINUX && !SCUDO_ANDROID +#if SCUDO_LINUX && !SCUDO_ANDROID_BIONIC template THREADLOCAL TSD *TSDRegistrySharedT::ThreadTSD; diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c.h b/compiler-rt/lib/scudo/standalone/wrappers_c.h --- a/compiler-rt/lib/scudo/standalone/wrappers_c.h +++ b/compiler-rt/lib/scudo/standalone/wrappers_c.h @@ -13,7 +13,7 @@ #include "stats.h" // Bionic's struct mallinfo consists of size_t (mallinfo(3) uses int). -#if SCUDO_ANDROID +#if SCUDO_ANDROID_BIONIC typedef size_t __scudo_mallinfo_data_t; #else typedef int __scudo_mallinfo_data_t; diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c.cpp b/compiler-rt/lib/scudo/standalone/wrappers_c.cpp --- a/compiler-rt/lib/scudo/standalone/wrappers_c.cpp +++ b/compiler-rt/lib/scudo/standalone/wrappers_c.cpp @@ -9,7 +9,7 @@ #include "platform.h" // Skip this compilation unit if compiled as part of Bionic. -#if !SCUDO_ANDROID || !_BIONIC +#if !SCUDO_ANDROID_BIONIC #include "allocator_config.h" #include "wrappers_c.h" @@ -36,4 +36,4 @@ } // extern "C" -#endif // !SCUDO_ANDROID || !_BIONIC +#endif // !SCUDO_ANDROID_BIONIC diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c.inc b/compiler-rt/lib/scudo/standalone/wrappers_c.inc --- a/compiler-rt/lib/scudo/standalone/wrappers_c.inc +++ b/compiler-rt/lib/scudo/standalone/wrappers_c.inc @@ -48,7 +48,7 @@ size, scudo::Chunk::Origin::Malloc, SCUDO_MALLOC_ALIGNMENT)); } -#if SCUDO_ANDROID +#if SCUDO_ANDROID_BIONIC INTERFACE WEAK size_t SCUDO_PREFIX(malloc_usable_size)(const void *ptr) { #else INTERFACE WEAK size_t SCUDO_PREFIX(malloc_usable_size)(void *ptr) { @@ -58,7 +58,7 @@ INTERFACE WEAK void *SCUDO_PREFIX(memalign)(size_t alignment, size_t size) { // Android rounds up the alignment to a power of two if it isn't one. - if (SCUDO_ANDROID) { + if (SCUDO_ANDROID_BIONIC) { if (UNLIKELY(!alignment)) { alignment = 1U; } else { @@ -127,7 +127,7 @@ // Bionic wants a function named PREFIX_iterate and not PREFIX_malloc_iterate // which is somewhat inconsistent with the rest, workaround that. -#if SCUDO_ANDROID && _BIONIC +#if SCUDO_ANDROID_BIONIC #define SCUDO_ITERATE iterate #else #define SCUDO_ITERATE malloc_iterate diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp b/compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp --- a/compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp +++ b/compiler-rt/lib/scudo/standalone/wrappers_c_bionic.cpp @@ -9,7 +9,7 @@ #include "platform.h" // This is only used when compiled as part of Bionic. -#if SCUDO_ANDROID && _BIONIC +#if SCUDO_ANDROID_BIONIC #include "allocator_config.h" #include "wrappers_c.h" @@ -46,4 +46,4 @@ } // extern "C" -#endif // SCUDO_ANDROID && _BIONIC +#endif // SCUDO_ANDROID_BIONIC diff --git a/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp b/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp --- a/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp +++ b/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp @@ -9,7 +9,7 @@ #include "platform.h" // Skip this compilation unit if compiled as part of Bionic. -#if !SCUDO_ANDROID || !_BIONIC +#if !SCUDO_ANDROID_BIONIC #include "allocator_config.h" @@ -104,4 +104,4 @@ static_cast(align)); } -#endif // !SCUDO_ANDROID || !_BIONIC +#endif // !SCUDO_ANDROID_BIONIC