[PATCH] D33555: [scudo] Check the return values of the pthread_* functions
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 25 11:07:06 PDT 2017
cryptoad updated this revision to Diff 100272.
cryptoad added a comment.
Other Sanitizers use `GetPthreadDestructorIterations()` instead of
`PTHREAD_DESTRUCTOR_ITERATIONS`, so do that here as well.
https://reviews.llvm.org/D33555
Files:
lib/scudo/scudo_tls_linux.cpp
Index: lib/scudo/scudo_tls_linux.cpp
===================================================================
--- lib/scudo/scudo_tls_linux.cpp
+++ 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 @@
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 @@
}
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33555.100272.patch
Type: text/x-patch
Size: 1697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170525/9b550d5d/attachment.bin>
More information about the llvm-commits
mailing list