summaryrefslogtreecommitdiff
path: root/lib/scudo
diff options
context:
space:
mode:
authorKostya Kortchinsky <kostyak@google.com>2017-05-26 15:39:22 +0000
committerKostya Kortchinsky <kostyak@google.com>2017-05-26 15:39:22 +0000
commit29e1a9ca086738e000a2a7c3e366453fe56f4ed9 (patch)
tree4021dc4bbb9c75b6428fb0b46bd92eb4359f8825 /lib/scudo
parent9233cd47d86013b406b7ae0b6c3280a51c256ae0 (diff)
[scudo] Check the return values of the pthread_* functions
Summary: Currently we are not enforcing the success of `pthread_once`, and `pthread_setspecific`. Errors could lead to harder to debug issues later in the thread's life. This adds checks for a 0 return value for both. If `pthread_setspecific` fails in the teardown path, opt for an immediate teardown as opposed to a fatal failure. Reviewers: alekseyshl, kcc Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D33555 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@303998 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/scudo')
-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 5a9cc998b..1e38233f3 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;
}