diff options
| author | Kostya Kortchinsky <kostyak@google.com> | 2017-10-13 20:55:31 +0000 |
|---|---|---|
| committer | Kostya Kortchinsky <kostyak@google.com> | 2017-10-13 20:55:31 +0000 |
| commit | f4c11e353a50eebfe7448fac4af0c3fd5bbc9143 (patch) | |
| tree | 7d8e322797e3766ca243b862d2fec8148e60795e /compiler-rt | |
| parent | cd25c38dc0e4e6a0afd940295aad60f3589dc69f (diff) | |
| download | bcm5719-llvm-f4c11e353a50eebfe7448fac4af0c3fd5bbc9143.tar.gz bcm5719-llvm-f4c11e353a50eebfe7448fac4af0c3fd5bbc9143.zip | |
[scudo] Allow for non-Android Shared TSD platforms, part 2
Summary:
Follow up to D38826.
We introduce `pthread_{get,set}specific` versions of `{get,set}CurrentTSD` to
allow for non Android platforms to use the Shared TSD model.
We now allow `SCUDO_TSD_EXCLUSIVE` to be defined at compile time.
A couple of things:
- I know that `#if SANITIZER_ANDROID` is not ideal within a function, but in
the end I feel it looks more compact and clean than going the .inc route; I
am open to an alternative if anyone has one;
- `SCUDO_TSD_EXCLUSIVE=1` requires ELF TLS support (and not emutls as this uses
malloc). I haven't found anything to enforce that, so it's currently not
checked.
Reviewers: alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, llvm-commits
Differential Revision: https://reviews.llvm.org/D38854
llvm-svn: 315751
Diffstat (limited to 'compiler-rt')
| -rw-r--r-- | compiler-rt/lib/scudo/scudo_platform.h | 24 | ||||
| -rw-r--r-- | compiler-rt/lib/scudo/scudo_tsd_shared.cpp | 10 | ||||
| -rw-r--r-- | compiler-rt/lib/scudo/scudo_tsd_shared.inc | 6 |
3 files changed, 28 insertions, 12 deletions
diff --git a/compiler-rt/lib/scudo/scudo_platform.h b/compiler-rt/lib/scudo/scudo_platform.h index 86ddc1a25ae..095d6ef1941 100644 --- a/compiler-rt/lib/scudo/scudo_platform.h +++ b/compiler-rt/lib/scudo/scudo_platform.h @@ -20,15 +20,25 @@ # error "The Scudo hardened allocator is not supported on this platform." #endif -#if SANITIZER_ANDROID || SANITIZER_FUCHSIA +#define SCUDO_TSD_EXCLUSIVE_SUPPORTED (!SANITIZER_ANDROID && !SANITIZER_FUCHSIA) + +#ifndef SCUDO_TSD_EXCLUSIVE +// SCUDO_TSD_EXCLUSIVE wasn't defined, use a default TSD model for the platform. +# if SANITIZER_ANDROID || SANITIZER_FUCHSIA // Android and Fuchsia use a pool of TSDs shared between threads. -# define SCUDO_TSD_EXCLUSIVE 0 -#elif SANITIZER_LINUX && !SANITIZER_ANDROID +# define SCUDO_TSD_EXCLUSIVE 0 +# elif SANITIZER_LINUX && !SANITIZER_ANDROID // Non-Android Linux use an exclusive TSD per thread. -# define SCUDO_TSD_EXCLUSIVE 1 -#else -# error "No default TSD model defined for this platform." -#endif // SANITIZER_ANDROID || SANITIZER_FUCHSIA +# define SCUDO_TSD_EXCLUSIVE 1 +# else +# error "No default TSD model defined for this platform." +# endif // SANITIZER_ANDROID || SANITIZER_FUCHSIA +#endif // SCUDO_TSD_EXCLUSIVE + +// If the exclusive TSD model is chosen, make sure the platform supports it. +#if SCUDO_TSD_EXCLUSIVE && !SCUDO_TSD_EXCLUSIVE_SUPPORTED +# error "The exclusive TSD model is not supported on this platform." +#endif namespace __scudo { diff --git a/compiler-rt/lib/scudo/scudo_tsd_shared.cpp b/compiler-rt/lib/scudo/scudo_tsd_shared.cpp index 54aec842a0f..6ee2f84a0d4 100644 --- a/compiler-rt/lib/scudo/scudo_tsd_shared.cpp +++ b/compiler-rt/lib/scudo/scudo_tsd_shared.cpp @@ -18,7 +18,7 @@ namespace __scudo { static pthread_once_t GlobalInitialized = PTHREAD_ONCE_INIT; -static pthread_key_t PThreadKey; +pthread_key_t PThreadKey; static atomic_uint32_t CurrentIndex; static ScudoTSD *TSDs; @@ -32,10 +32,6 @@ static uptr getNumberOfCPUs() { } static void initOnce() { - // Hack: TLS_SLOT_TSAN was introduced in N. To be able to use it on M for - // testing, we create an unused key. Since the key_data array follows the tls - // array, it basically gives us the extra entry we need. - // TODO(kostyak): remove and restrict to N and above. CHECK_EQ(pthread_key_create(&PThreadKey, NULL), 0); initScudo(); NumberOfTSDs = getNumberOfCPUs(); @@ -50,7 +46,11 @@ static void initOnce() { } ALWAYS_INLINE void setCurrentTSD(ScudoTSD *TSD) { +#if SANITIZER_ANDROID *get_android_tls_ptr() = reinterpret_cast<uptr>(TSD); +#else + CHECK_EQ(pthread_setspecific(PThreadKey, reinterpret_cast<void *>(TSD)), 0); +#endif // SANITIZER_ANDROID } void initThread(bool MinimalInit) { diff --git a/compiler-rt/lib/scudo/scudo_tsd_shared.inc b/compiler-rt/lib/scudo/scudo_tsd_shared.inc index 9b9c3a2ec6e..79fcd651ed2 100644 --- a/compiler-rt/lib/scudo/scudo_tsd_shared.inc +++ b/compiler-rt/lib/scudo/scudo_tsd_shared.inc @@ -17,8 +17,14 @@ #if !SCUDO_TSD_EXCLUSIVE +extern pthread_key_t PThreadKey; + ALWAYS_INLINE ScudoTSD* getCurrentTSD() { +#if SANITIZER_ANDROID return reinterpret_cast<ScudoTSD *>(*get_android_tls_ptr()); +#else + return reinterpret_cast<ScudoTSD *>(pthread_getspecific(PThreadKey)); +#endif // SANITIZER_ANDROID } ALWAYS_INLINE void initThreadMaybe(bool MinimalInit = false) { |

