[PATCH] D38854: [scudo] Allow for non-Android Shared TSD platforms, part 2
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 12 10:39:38 PDT 2017
cryptoad created this revision.
Herald added a subscriber: srhines.
Follow up to https://reviews.llvm.org/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.
https://reviews.llvm.org/D38854
Files:
lib/scudo/scudo_platform.h
lib/scudo/scudo_tsd_shared.cpp
lib/scudo/scudo_tsd_shared.inc
Index: lib/scudo/scudo_tsd_shared.inc
===================================================================
--- lib/scudo/scudo_tsd_shared.inc
+++ 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) {
Index: lib/scudo/scudo_tsd_shared.cpp
===================================================================
--- lib/scudo/scudo_tsd_shared.cpp
+++ 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;
@@ -50,7 +50,11 @@
}
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) {
Index: lib/scudo/scudo_platform.h
===================================================================
--- lib/scudo/scudo_platform.h
+++ lib/scudo/scudo_platform.h
@@ -20,15 +20,17 @@
# error "The Scudo hardened allocator is not supported on this platform."
#endif
-#if SANITIZER_ANDROID || SANITIZER_FUCHSIA
+#ifndef SCUDO_TSD_EXCLUSIVE
+# 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
namespace __scudo {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38854.118806.patch
Type: text/x-patch
Size: 2312 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171012/3bcf328c/attachment.bin>
More information about the llvm-commits
mailing list