aboutsummaryrefslogtreecommitdiff
path: root/lib/scudo/scudo_tls_linux.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-05-29 16:25:57 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-05-29 16:25:57 +0000
commit224c1c721b03784d0da2af00884ea8d4eb7a1650 (patch)
treeac9e50e358e85ab37022d6fdafaa0c8dbb4adad2 /lib/scudo/scudo_tls_linux.cpp
parent99ea5e489fa5765bf0eb50ca4261ab5cc20abeeb (diff)
Diffstat (limited to 'lib/scudo/scudo_tls_linux.cpp')
-rw-r--r--lib/scudo/scudo_tls_linux.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/scudo/scudo_tls_linux.cpp b/lib/scudo/scudo_tls_linux.cpp
index 5a9cc998bccf..1e38233f339c 100644
--- a/lib/scudo/scudo_tls_linux.cpp
+++ b/lib/scudo/scudo_tls_linux.cpp
@@ -18,7 +18,6 @@
#include "scudo_tls.h"
-#include <limits.h>
#include <pthread.h>
namespace __scudo {
@@ -32,15 +31,17 @@ __attribute__((tls_model("initial-exec")))
THREADLOCAL ScudoThreadContext ThreadLocalContext;
static void teardownThread(void *Ptr) {
- uptr Iteration = reinterpret_cast<uptr>(Ptr);
+ uptr I = reinterpret_cast<uptr>(Ptr);
// The glibc POSIX thread-local-storage deallocation routine calls user
// provided destructors in a loop of PTHREAD_DESTRUCTOR_ITERATIONS.
// We want to be called last since other destructors might call free and the
// like, so we wait until PTHREAD_DESTRUCTOR_ITERATIONS before draining the
// quarantine and swallowing the cache.
- if (Iteration < PTHREAD_DESTRUCTOR_ITERATIONS) {
- pthread_setspecific(PThreadKey, reinterpret_cast<void *>(Iteration + 1));
- return;
+ if (I > 1) {
+ // If pthread_setspecific fails, we will go ahead with the teardown.
+ if (LIKELY(pthread_setspecific(PThreadKey,
+ reinterpret_cast<void *>(I - 1)) == 0))
+ return;
}
ThreadLocalContext.commitBack();
ScudoThreadState = ThreadTornDown;
@@ -53,8 +54,9 @@ static void initOnce() {
}
void initThread() {
- pthread_once(&GlobalInitialized, initOnce);
- pthread_setspecific(PThreadKey, reinterpret_cast<void *>(1));
+ CHECK_EQ(pthread_once(&GlobalInitialized, initOnce), 0);
+ CHECK_EQ(pthread_setspecific(PThreadKey, reinterpret_cast<void *>(
+ GetPthreadDestructorIterations())), 0);
ThreadLocalContext.init();
ScudoThreadState = ThreadInitialized;
}