[PATCH] D47502: [asan, myriad] Simplify main thread handling

Walter Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 29 15:08:06 PDT 2018


waltl created this revision.
waltl added reviewers: vitalybuka, eugenis, alekseyshl.
Herald added a subscriber: kubamracek.

On Myriad RTEMS, we don't need to treat the main thread differently.
The existing thread hooks will do the right thing, so get rid of all
the unneeded special logic.


Repository:
  rL LLVM

https://reviews.llvm.org/D47502

Files:
  compiler-rt/lib/asan/asan_rtems.cc
  compiler-rt/lib/sanitizer_common/sanitizer_rtems.cc
  compiler-rt/lib/sanitizer_common/sanitizer_rtems.h


Index: compiler-rt/lib/sanitizer_common/sanitizer_rtems.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_rtems.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_rtems.h
@@ -17,12 +17,5 @@
 #if SANITIZER_RTEMS
 #include "sanitizer_common.h"
 
-namespace __sanitizer {
-
-extern uptr MainThreadStackBase, MainThreadStackSize;
-extern uptr MainThreadTlsBase, MainThreadTlsSize;
-
-}  // namespace __sanitizer
-
 #endif  // SANITIZER_RTEMS
 #endif  // SANITIZER_RTEMS_H
Index: compiler-rt/lib/sanitizer_common/sanitizer_rtems.cc
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_rtems.cc
+++ compiler-rt/lib/sanitizer_common/sanitizer_rtems.cc
@@ -275,14 +275,4 @@
 
 } // namespace __sanitizer
 
-extern "C" {
-void __sanitizer_startup_hook(void *stack_base, size_t stack_size,
-                              void *tls_base, size_t tls_size) {
-  __sanitizer::MainThreadStackBase = reinterpret_cast<uintptr_t>(stack_base);
-  __sanitizer::MainThreadStackSize = stack_size;
-  __sanitizer::MainThreadTlsBase = reinterpret_cast<uintptr_t>(tls_base);
-  __sanitizer::MainThreadTlsSize = tls_size;
-}
-}  // extern "C"
-
 #endif  // SANITIZER_RTEMS
Index: compiler-rt/lib/asan/asan_rtems.cc
===================================================================
--- compiler-rt/lib/asan/asan_rtems.cc
+++ compiler-rt/lib/asan/asan_rtems.cc
@@ -72,11 +72,6 @@
   ResetShadowMemory();
 }
 
-// Main thread information.  Initialized in CreateMainThread() and
-// used by ThreadStartHook().
-static uptr MainThreadSelf;
-static AsanThread *MainThread;
-
 // We can use a plain thread_local variable for TSD.
 static thread_local void *per_thread;
 
@@ -134,18 +129,12 @@
   tls_end_ = options->tls_bottom + options->tls_size;
 }
 
-// Called by __asan::AsanInitInternal (asan_rtl.c).
+// Called by __asan::AsanInitInternal (asan_rtl.c).  Unlike other ports, the
+// main thread on RTEMS does not require special treatment; its AsanThread is
+// already created by the provided hooks.  This function simply looks up and
+// returns the created thread.
 AsanThread *CreateMainThread() {
-  CHECK_NE(__sanitizer::MainThreadStackBase, 0);
-  CHECK_GT(__sanitizer::MainThreadStackSize, 0);
-  AsanThread *t = CreateAsanThread(
-      nullptr, 0, GetThreadSelf(), true,
-      __sanitizer::MainThreadStackBase, __sanitizer::MainThreadStackSize,
-      __sanitizer::MainThreadTlsBase, __sanitizer::MainThreadTlsSize);
-  SetCurrentThread(t);
-  MainThreadSelf = pthread_self();
-  MainThread = t;
-  return t;
+  return GetThreadContextByTidLocked(0)->thread;
 }
 
 // This is called before each thread creation is attempted.  So, in
@@ -179,16 +168,14 @@
   }
 }
 
-// This is called (1) in the newly-created thread before it runs
-// anything else, with the pointer returned by BeforeThreadCreateHook
-// (above).  cf. asan_interceptors.cc:asan_thread_start.  (2) before
-// a thread restart.
+// This is called (1) in the newly-created thread before it runs anything else,
+// with the pointer returned by BeforeThreadCreateHook (above).  (2) before a
+// thread restart.
 static void ThreadStartHook(void *hook, uptr os_id) {
-  if (!hook && !MainThreadSelf)
+  if (!hook)
     return;
 
-  DCHECK(hook || os_id == MainThreadSelf);
-  AsanThread *thread = hook ? static_cast<AsanThread *>(hook) : MainThread;
+  AsanThread *thread = static_cast<AsanThread *>(hook);
   SetCurrentThread(thread);
 
   ThreadStatus status =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47502.148993.patch
Type: text/x-patch
Size: 3537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180529/6aad3450/attachment.bin>


More information about the llvm-commits mailing list