[compiler-rt] afb73f7 - Revert "[NFC][ASAN] Remove redundant fields of AsanThread"

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue May 30 19:16:58 PDT 2023


Author: Vitaly Buka
Date: 2023-05-30T19:16:46-07:00
New Revision: afb73f7a913ec8e7e8704afe18784571f320ebf6

URL: https://github.com/llvm/llvm-project/commit/afb73f7a913ec8e7e8704afe18784571f320ebf6
DIFF: https://github.com/llvm/llvm-project/commit/afb73f7a913ec8e7e8704afe18784571f320ebf6.diff

LOG: Revert "[NFC][ASAN] Remove redundant fields of AsanThread"

Breaks Windows.

This reverts commit 8ac084728daf5b666624621562afb6d63cc01ae3.

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_interceptors.cpp
    compiler-rt/lib/asan/asan_thread.cpp
    compiler-rt/lib/asan/asan_thread.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index 086b23ca1a64..7aedefe81f95 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -177,9 +177,9 @@ static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) {
   SetCurrentThread(t);
   auto self = GetThreadSelf();
   auto args = asanThreadArgRetval().GetArgs(self);
-  thread_return_t retval =
-      t->ThreadStart(GetTid(), args.routine, args.arg_retval);
+  thread_return_t retval = t->ThreadStart(GetTid());
   asanThreadArgRetval().Finish(self, retval);
+  CHECK_EQ(args.arg_retval, t->get_arg());
   return retval;
 }
 
@@ -197,7 +197,8 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr,
   }();
 
   u32 current_tid = GetCurrentTidOrInvalid();
-  AsanThread *t = AsanThread::Create(current_tid, &stack, detached);
+  AsanThread *t =
+      AsanThread::Create(start_routine, arg, current_tid, &stack, detached);
 
   int result;
   {

diff  --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp
index 5d0c134808b8..f718adf5e1f7 100644
--- a/compiler-rt/lib/asan/asan_thread.cpp
+++ b/compiler-rt/lib/asan/asan_thread.cpp
@@ -91,11 +91,14 @@ AsanThreadContext *GetThreadContextByTidLocked(u32 tid) {
 
 // AsanThread implementation.
 
-AsanThread *AsanThread::Create(u32 parent_tid, StackTrace *stack,
+AsanThread *AsanThread::Create(thread_callback_t start_routine, void *arg,
+                               u32 parent_tid, StackTrace *stack,
                                bool detached) {
   uptr PageSize = GetPageSizeCached();
   uptr size = RoundUpTo(sizeof(AsanThread), PageSize);
   AsanThread *thread = (AsanThread *)MmapOrDie(size, __func__);
+  thread->start_routine_ = start_routine;
+  thread->arg_ = arg;
   AsanThreadContext::CreateThreadContextArgs args = {thread, stack};
   asanThreadRegistry().CreateThread(0, detached, parent_tid, &args);
 
@@ -270,23 +273,22 @@ void AsanThread::Init(const InitOptions *options) {
 // asan_fuchsia.c definies CreateMainThread and SetThreadStackAndTls.
 #if !SANITIZER_FUCHSIA
 
-thread_return_t AsanThread::ThreadStart(tid_t os_id, void *(*routine)(void *),
-                                        void *arg) {
+thread_return_t AsanThread::ThreadStart(tid_t os_id) {
   Init();
   asanThreadRegistry().StartThread(tid(), os_id, ThreadType::Regular, nullptr);
 
   if (common_flags()->use_sigaltstack)
     SetAlternateSignalStack();
 
-  if (!routine) {
+  if (!start_routine_) {
     // start_routine_ == 0 if we're on the main thread or on one of the
     // OS X libdispatch worker threads. But nobody is supposed to call
     // ThreadStart() for the worker threads.
-    CHECK_EQ(tid(), kMainTid);
+    CHECK_EQ(tid(), 0);
     return 0;
   }
 
-  thread_return_t res = (*routine)(arg);
+  thread_return_t res = start_routine_(arg_);
 
   // On POSIX systems we defer this to the TSD destructor. LSan will consider
   // the thread's memory as non-live from the moment we call Destroy(), even
@@ -301,10 +303,10 @@ thread_return_t AsanThread::ThreadStart(tid_t os_id, void *(*routine)(void *),
 
 AsanThread *CreateMainThread() {
   AsanThread *main_thread = AsanThread::Create(
-      /* parent_tid */ kMainTid,
+      /* start_routine */ nullptr, /* arg */ nullptr, /* parent_tid */ kMainTid,
       /* stack */ nullptr, /* detached */ true);
   SetCurrentThread(main_thread);
-  main_thread->ThreadStart(internal_getpid(), nullptr, nullptr);
+  main_thread->ThreadStart(internal_getpid());
   return main_thread;
 }
 

diff  --git a/compiler-rt/lib/asan/asan_thread.h b/compiler-rt/lib/asan/asan_thread.h
index b6b7705f7876..c131dd40d864 100644
--- a/compiler-rt/lib/asan/asan_thread.h
+++ b/compiler-rt/lib/asan/asan_thread.h
@@ -59,14 +59,15 @@ COMPILER_CHECK(sizeof(AsanThreadContext) <= 256);
 // AsanThread are stored in TSD and destroyed when the thread dies.
 class AsanThread {
  public:
-  static AsanThread *Create(u32 parent_tid, StackTrace *stack, bool detached);
+  static AsanThread *Create(thread_callback_t start_routine, void *arg,
+                            u32 parent_tid, StackTrace *stack, bool detached);
   static void TSDDtor(void *tsd);
   void Destroy();
 
   struct InitOptions;
   void Init(const InitOptions *options = nullptr);
 
-  thread_return_t ThreadStart(tid_t os_id, void *(*routine)(void *), void *arg);
+  thread_return_t ThreadStart(tid_t os_id);
 
   uptr stack_top();
   uptr stack_bottom();
@@ -129,6 +130,8 @@ class AsanThread {
 
   void *extra_spill_area() { return &extra_spill_area_; }
 
+  void *get_arg() const { return arg_; }
+
  private:
   // NOTE: There is no AsanThread constructor. It is allocated
   // via mmap() and *must* be valid in zero-initialized state.
@@ -145,6 +148,8 @@ class AsanThread {
   StackBounds GetStackBounds() const;
 
   AsanThreadContext *context_;
+  thread_callback_t start_routine_;
+  void *arg_;
 
   uptr stack_top_;
   uptr stack_bottom_;


        


More information about the llvm-commits mailing list