[compiler-rt] r341431 - [hwasan] remove stale Thread:: data members. While doing so noticed that GetThreadStackAndTls was always called with 'at_initialization=true', fixed that.

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 4 16:57:10 PDT 2018


Author: kcc
Date: Tue Sep  4 16:57:09 2018
New Revision: 341431

URL: http://llvm.org/viewvc/llvm-project?rev=341431&view=rev
Log:
[hwasan] remove stale Thread:: data members. While doing so noticed that GetThreadStackAndTls was always called with 'at_initialization=true', fixed that.

Modified:
    compiler-rt/trunk/lib/hwasan/hwasan.cc
    compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc
    compiler-rt/trunk/lib/hwasan/hwasan_linux.cc
    compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
    compiler-rt/trunk/lib/hwasan/hwasan_thread.h

Modified: compiler-rt/trunk/lib/hwasan/hwasan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan.cc?rev=341431&r1=341430&r2=341431&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan.cc Tue Sep  4 16:57:09 2018
@@ -213,7 +213,7 @@ void __hwasan_init() {
 
   HwasanAllocatorInit();
 
-  Thread *main_thread = Thread::Create(nullptr, nullptr);
+  Thread *main_thread = Thread::Create();
   SetCurrentThread(main_thread);
   main_thread->Init();
 

Modified: compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc?rev=341431&r1=341430&r2=341431&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc Tue Sep  4 16:57:09 2018
@@ -111,8 +111,7 @@ static void *HwasanAllocate(StackTrace *
 
   void *user_ptr = allocated;
   if (flags()->tag_in_malloc &&
-      atomic_load_relaxed(&hwasan_allocator_tagging_enabled) &&
-      !t->TaggingIsDisabled())
+      atomic_load_relaxed(&hwasan_allocator_tagging_enabled))
     user_ptr = (void *)TagMemoryAligned(
         (uptr)user_ptr, size, t ? t->GenerateRandomTag() : kFallbackAllocTag);
 

Modified: compiler-rt/trunk/lib/hwasan/hwasan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_linux.cc?rev=341431&r1=341430&r2=341431&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_linux.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_linux.cc Tue Sep  4 16:57:09 2018
@@ -214,7 +214,7 @@ void InstallAtExitHandler() {
 // ---------------------- TSD ---------------- {{{1
 
 extern "C" void __hwasan_thread_enter() {
-  Thread *t = Thread::Create(nullptr, nullptr);
+  Thread *t = Thread::Create();
   SetCurrentThread(t);
   t->Init();
 }

Modified: compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_thread.cc?rev=341431&r1=341430&r2=341431&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_thread.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_thread.cc Tue Sep  4 16:57:09 2018
@@ -57,14 +57,11 @@ void Thread::RemoveFromThreadList(Thread
   CHECK(0 && "RemoveFromThreadList: thread not found");
 }
 
-Thread *Thread::Create(thread_callback_t start_routine,
-                               void *arg) {
+Thread *Thread::Create() {
   static u64 unique_id;
   uptr PageSize = GetPageSizeCached();
   uptr size = RoundUpTo(sizeof(Thread), PageSize);
   Thread *thread = (Thread*)MmapOrDie(size, __func__);
-  thread->start_routine_ = start_routine;
-  thread->arg_ = arg;
   thread->destructor_iterations_ = GetPthreadDestructorIterations();
   thread->random_state_ = flags()->random_tags ? RandomSeed() : 0;
   if (auto sz = flags()->heap_history_size)
@@ -75,6 +72,9 @@ Thread *Thread::Create(thread_callback_t
 }
 
 void Thread::SetThreadStackAndTls() {
+  // GetPthreadDestructorIterations may call malloc, so disable the tagging.
+  ScopedTaggingDisabler disabler;
+
   // If this process is "init" (pid 1), /proc may not be mounted yet.
   if (IsMainThread() && !FileExists("/proc/self/maps")) {
     stack_top_ = stack_bottom_ = 0;
@@ -126,8 +126,10 @@ void Thread::Destroy() {
 }
 
 void Thread::Print(const char *Prefix) {
-  Printf("%s: thread %p id: %zd stack: [%p,%p) tls: [%p,%p)\n", Prefix, this,
-         unique_id_, stack_bottom(), stack_top(), tls_begin(), tls_end());
+  Printf("%s: thread %p id: %zd stack: [%p,%p) sz: %zd tls: [%p,%p)\n", Prefix,
+         this, unique_id_, stack_bottom(), stack_top(),
+         stack_top() - stack_bottom(),
+         tls_begin(), tls_end());
 }
 
 static u32 xorshift(u32 state) {
@@ -139,6 +141,7 @@ static u32 xorshift(u32 state) {
 
 // Generate a (pseudo-)random non-zero tag.
 tag_t Thread::GenerateRandomTag() {
+  if (tagging_disabled_) return 0;
   tag_t tag;
   do {
     if (flags()->random_tags) {

Modified: compiler-rt/trunk/lib/hwasan/hwasan_thread.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_thread.h?rev=341431&r1=341430&r2=341431&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_thread.h (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_thread.h Tue Sep  4 16:57:09 2018
@@ -26,7 +26,7 @@ struct ThreadStartArg {
 
 class Thread {
  public:
-  static Thread *Create(thread_callback_t start_routine, void *arg);
+  static Thread *Create();
   void Destroy();
 
   void Init();
@@ -35,7 +35,7 @@ class Thread {
   uptr stack_bottom() { return stack_bottom_; }
   uptr tls_begin() { return tls_begin_; }
   uptr tls_end() { return tls_end_; }
-  bool IsMainThread() { return start_routine_ == nullptr; }
+  bool IsMainThread() { return unique_id_ == 0; }
 
   bool AddrIsInStack(uptr addr) {
     return addr >= stack_bottom_ && addr < stack_top_;
@@ -85,8 +85,6 @@ class Thread {
   void SetThreadStackAndTls();
   void ClearShadowForThreadStackAndTLS();
   void Print(const char *prefix);
-  thread_callback_t start_routine_;
-  void *arg_;
   uptr stack_top_;
   uptr stack_bottom_;
   uptr tls_begin_;




More information about the llvm-commits mailing list