[compiler-rt] 16f4e85 - Revert "[sanitizer] Remove GetCurrentThread nullness checks from Allocate"

Steven Wu via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 12:59:07 PDT 2024


Author: Steven Wu
Date: 2024-08-15T12:50:03-07:00
New Revision: 16f4e85860efcccbadca5d0a00a3872244efae08

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

LOG: Revert "[sanitizer] Remove GetCurrentThread nullness checks from Allocate"

This reverts commit 4411d1e3926d67c393e6a7bdb910bbe77507ff26 for
breaking Darwin bots:
  AddressSanitizer-Unit :: ./Asan-x86_64-calls-Noinst-Test/10/16
  AddressSanitizer-Unit :: ./Asan-x86_64-calls-Noinst-Test/12/16
  AddressSanitizer-Unit :: ./Asan-x86_64-calls-Noinst-Test/13/16
  AddressSanitizer-Unit :: ./Asan-x86_64-inline-Noinst-Test/10/16
  AddressSanitizer-Unit :: ./Asan-x86_64-inline-Noinst-Test/12/16
  AddressSanitizer-Unit :: ./Asan-x86_64-inline-Noinst-Test/13/16
  AddressSanitizer-Unit :: ./Asan-x86_64h-calls-Noinst-Test/10/16
  AddressSanitizer-Unit :: ./Asan-x86_64h-calls-Noinst-Test/12/16
  AddressSanitizer-Unit :: ./Asan-x86_64h-calls-Noinst-Test/13/16
  AddressSanitizer-Unit :: ./Asan-x86_64h-inline-Noinst-Test/10/16
  AddressSanitizer-Unit :: ./Asan-x86_64h-inline-Noinst-Test/12/16
  AddressSanitizer-Unit :: ./Asan-x86_64h-inline-Noinst-Test/13/16

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_allocator.cpp
    compiler-rt/lib/msan/msan_allocator.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp
index e041861edaf0b7..9e66f77217ec6b 100644
--- a/compiler-rt/lib/asan/asan_allocator.cpp
+++ b/compiler-rt/lib/asan/asan_allocator.cpp
@@ -576,8 +576,15 @@ struct Allocator {
     }
 
     AsanThread *t = GetCurrentThread();
-    void *allocated = allocator.Allocate(
-        GetAllocatorCache(&t->malloc_storage()), needed_size, 8);
+    void *allocated;
+    if (t) {
+      AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
+      allocated = allocator.Allocate(cache, needed_size, 8);
+    } else {
+      SpinMutexLock l(&fallback_mutex);
+      AllocatorCache *cache = &fallback_allocator_cache;
+      allocated = allocator.Allocate(cache, needed_size, 8);
+    }
     if (UNLIKELY(!allocated)) {
       SetAllocatorOutOfMemory();
       if (AllocatorMayReturnNull())

diff  --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp
index f478b9979f2daa..d7d4967c949859 100644
--- a/compiler-rt/lib/msan/msan_allocator.cpp
+++ b/compiler-rt/lib/msan/msan_allocator.cpp
@@ -199,8 +199,15 @@ static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
     ReportRssLimitExceeded(stack);
   }
   MsanThread *t = GetCurrentThread();
-  void *allocated = allocator.Allocate(GetAllocatorCache(&t->malloc_storage()),
-                                       size, alignment);
+  void *allocated;
+  if (t) {
+    AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
+    allocated = allocator.Allocate(cache, size, alignment);
+  } else {
+    SpinMutexLock l(&fallback_mutex);
+    AllocatorCache *cache = &fallback_allocator_cache;
+    allocated = allocator.Allocate(cache, size, alignment);
+  }
   if (UNLIKELY(!allocated)) {
     SetAllocatorOutOfMemory();
     if (AllocatorMayReturnNull())


        


More information about the llvm-commits mailing list