[PATCH] D40935: Hardware-assisted AddressSanitizer (compiler-rt)
Kamil Rytarowski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 6 17:36:33 PST 2017
krytarowski added inline comments.
================
Comment at: compiler-rt/lib/hwasan/hwasan_linux.cc:86
+ CHECK_EQ(0, pthread_getspecific(tsd_key));
+ pthread_setspecific(tsd_key, (void *)t);
+}
----------------
I have a local draft MSan patch adjusting similar code for NetBSD. It's right no incomplete as I need to add proper definition of `INTERCEPT_FUNCTION(_lwp_exit);` instead of calling it for each thread.
```
diff --git a/lib/msan/msan_linux.cc b/lib/msan/msan_linux.cc
index 4e6321fcb..d68509672 100644
--- a/lib/msan/msan_linux.cc
+++ b/lib/msan/msan_linux.cc
@@ -30,6 +30,7 @@
#include <sys/time.h>
#include <sys/resource.h>
+#include "interception/interception.h"
#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_procmaps.h"
@@ -174,13 +175,28 @@ void InstallAtExitHandler() {
// ---------------------- TSD ---------------- {{{1
+#if !SANITIZER_NETBSD
static pthread_key_t tsd_key;
+#endif
+
static bool tsd_key_inited = false;
+#if SANITIZER_NETBSD
+INTERCEPTOR(void, _lwp_exit) {
+ CHECK(tsd_key_inited);
+ MsanTSDDtor(GetCurrentThread());
+ REAL(_lwp_exit)();
+}
+#endif
+
void MsanTSDInit(void (*destructor)(void *tsd)) {
CHECK(!tsd_key_inited);
tsd_key_inited = true;
+#if SANITIZER_NETBSD
+ INTERCEPT_FUNCTION(_lwp_exit);
+#else
CHECK_EQ(0, pthread_key_create(&tsd_key, destructor));
+#endif
}
static THREADLOCAL MsanThread* msan_current_thread;
@@ -195,16 +211,20 @@ void SetCurrentThread(MsanThread *t) {
msan_current_thread = t;
// Make sure that MsanTSDDtor gets called at the end.
CHECK(tsd_key_inited);
+#if !SANITIZER_NETBSD
pthread_setspecific(tsd_key, (void *)t);
+#endif
}
void MsanTSDDtor(void *tsd) {
+#if !SANITIZER_NETBSD
MsanThread *t = (MsanThread*)tsd;
if (t->destructor_iterations_ > 1) {
t->destructor_iterations_--;
CHECK_EQ(0, pthread_setspecific(tsd_key, tsd));
return;
}
+#endif
msan_current_thread = nullptr;
// Make sure that signal handler can not see a stale current thread pointer.
atomic_signal_fence(memory_order_seq_cst);
```
https://reviews.llvm.org/D40935
More information about the llvm-commits
mailing list