[PATCH] D55596: Reimplement Thread Static Data ASan routines for NetBSD

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 12 04:04:07 PST 2018


krytarowski updated this revision to Diff 177837.
krytarowski added a comment.

- add missing chunk of patch


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55596/new/

https://reviews.llvm.org/D55596

Files:
  lib/asan/asan_interceptors.h
  lib/asan/asan_posix.cc


Index: lib/asan/asan_posix.cc
===================================================================
--- lib/asan/asan_posix.cc
+++ lib/asan/asan_posix.cc
@@ -40,6 +40,44 @@
 
 // ---------------------- TSD ---------------- {{{1
 
+#if SANITIZER_NETBSD
+// Thread Static Data cannot be used in early init on NetBSD
+// Reuse the Asan TSD API for compatibility with existing code
+// with an alternative implementation.
+
+static bool tsd_key_inited = false;
+static void (*tsd_destructor)(void *tsd) = nullptr;
+static THREADLOCAL void *tsd_key = nullptr;
+
+void tsd_at_exit(void *unused) {
+  (*tsd_destructor)(tsd_key);
+}
+
+void AsanTSDInit(void (*destructor)(void *tsd)) {
+  CHECK(!tsd_key_inited);
+  tsd_key_inited = true;
+  tsd_destructor = destructor;
+  if (REAL(__cxa_atexit)(tsd_at_exit, 0, 0)) {
+    Printf("AddressSanitizer: failed to setup atexit callback");
+    Die();
+  }
+}
+
+void *AsanTSDGet() {
+  CHECK(tsd_key_inited);
+  return tsd_key;
+}
+
+void AsanTSDSet(void *tsd) {
+  CHECK(tsd_key_inited);
+  tsd_key = tsd;
+}
+
+void PlatformTSDDtor(void *tsd) {
+  CHECK(tsd_key_inited);
+  AsanThread::TSDDtor(tsd);
+}
+#else
 static pthread_key_t tsd_key;
 static bool tsd_key_inited = false;
 void AsanTSDInit(void (*destructor)(void *tsd)) {
@@ -67,6 +105,7 @@
   }
   AsanThread::TSDDtor(tsd);
 }
+#endif
 }  // namespace __asan
 
 #endif  // SANITIZER_POSIX
Index: lib/asan/asan_interceptors.h
===================================================================
--- lib/asan/asan_interceptors.h
+++ lib/asan/asan_interceptors.h
@@ -113,6 +113,10 @@
 DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)
 DECLARE_REAL(char*, strstr, const char *s1, const char *s2)
 
+#if ASAN_INTERCEPT___CXA_ATEXIT
+DECLARE_REAL(int, __cxa_atexit, void (*f)(void *a), void *a, void *dso);
+#endif
+
 #if !SANITIZER_MAC
 #define ASAN_INTERCEPT_FUNC(name)                                        \
   do {                                                                   \


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55596.177837.patch
Type: text/x-patch
Size: 1985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181212/761b0f4f/attachment.bin>


More information about the llvm-commits mailing list