[hwasan] simplify the code, NFC
authorKostya Serebryany <kcc@google.com>
Wed, 5 Sep 2018 00:01:45 +0000 (00:01 +0000)
committerKostya Serebryany <kcc@google.com>
Wed, 5 Sep 2018 00:01:45 +0000 (00:01 +0000)
llvm-svn: 341432

compiler-rt/lib/hwasan/hwasan.cc
compiler-rt/lib/hwasan/hwasan_linux.cc
compiler-rt/lib/hwasan/hwasan_thread.cc
compiler-rt/lib/hwasan/hwasan_thread.h

index 2816551..ed9d3f7 100644 (file)
@@ -213,9 +213,7 @@ void __hwasan_init() {
 
   HwasanAllocatorInit();
 
-  Thread *main_thread = Thread::Create();
-  SetCurrentThread(main_thread);
-  main_thread->Init();
+  Thread::Create();
 
 #if HWASAN_CONTAINS_UBSAN
   __ubsan::InitAsPlugin();
index 9729347..3285431 100644 (file)
@@ -214,9 +214,7 @@ void InstallAtExitHandler() {
 // ---------------------- TSD ---------------- {{{1
 
 extern "C" void __hwasan_thread_enter() {
-  Thread *t = Thread::Create();
-  SetCurrentThread(t);
-  t->Init();
+  Thread::Create();
 }
 
 extern "C" void __hwasan_thread_exit() {
index e9bad90..f3dc974 100644 (file)
@@ -57,7 +57,7 @@ void Thread::RemoveFromThreadList(Thread *t) {
   CHECK(0 && "RemoveFromThreadList: thread not found");
 }
 
-Thread *Thread::Create() {
+void Thread::Create() {
   static u64 unique_id;
   uptr PageSize = GetPageSizeCached();
   uptr size = RoundUpTo(sizeof(Thread), PageSize);
@@ -68,10 +68,11 @@ Thread *Thread::Create() {
     thread->heap_allocations_ = RingBuffer<HeapAllocationRecord>::New(sz);
   thread->unique_id_ = unique_id++;
   InsertIntoThreadList(thread);
-  return thread;
+  SetCurrentThread(thread);
+  thread->Init();
 }
 
-void Thread::SetThreadStackAndTls() {
+void Thread::Init() {
   // GetPthreadDestructorIterations may call malloc, so disable the tagging.
   ScopedTaggingDisabler disabler;
 
@@ -93,10 +94,7 @@ void Thread::SetThreadStackAndTls() {
   CHECK(AddrIsInStack((uptr)&local));
   CHECK(MemIsApp(stack_bottom_));
   CHECK(MemIsApp(stack_top_ - 1));
-}
 
-void Thread::Init() {
-  SetThreadStackAndTls();
   if (stack_bottom_) {
     CHECK(MemIsApp(stack_bottom_));
     CHECK(MemIsApp(stack_top_ - 1));
index 3ab749b..a2bff75 100644 (file)
@@ -26,11 +26,9 @@ struct ThreadStartArg {
 
 class Thread {
  public:
-  static Thread *Create();
+  static void Create();  // Must be called from the thread itself.
   void Destroy();
 
-  void Init();
-
   uptr stack_top() { return stack_top_; }
   uptr stack_bottom() { return stack_bottom_; }
   uptr tls_begin() { return tls_begin_; }
@@ -82,7 +80,7 @@ class Thread {
  private:
   // NOTE: There is no Thread constructor. It is allocated
   // via mmap() and *must* be valid in zero-initialized state.
-  void SetThreadStackAndTls();
+  void Init();
   void ClearShadowForThreadStackAndTLS();
   void Print(const char *prefix);
   uptr stack_top_;