Skip to content

Commit 16f4e85

Browse files
Revert "[sanitizer] Remove GetCurrentThread nullness checks from Allocate"
This reverts commit 4411d1e 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
1 parent 1d5c2ad commit 16f4e85

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

compiler-rt/lib/asan/asan_allocator.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,15 @@ struct Allocator {
576576
}
577577

578578
AsanThread *t = GetCurrentThread();
579-
void *allocated = allocator.Allocate(
580-
GetAllocatorCache(&t->malloc_storage()), needed_size, 8);
579+
void *allocated;
580+
if (t) {
581+
AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
582+
allocated = allocator.Allocate(cache, needed_size, 8);
583+
} else {
584+
SpinMutexLock l(&fallback_mutex);
585+
AllocatorCache *cache = &fallback_allocator_cache;
586+
allocated = allocator.Allocate(cache, needed_size, 8);
587+
}
581588
if (UNLIKELY(!allocated)) {
582589
SetAllocatorOutOfMemory();
583590
if (AllocatorMayReturnNull())

compiler-rt/lib/msan/msan_allocator.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,15 @@ static void *MsanAllocate(BufferedStackTrace *stack, uptr size, uptr alignment,
199199
ReportRssLimitExceeded(stack);
200200
}
201201
MsanThread *t = GetCurrentThread();
202-
void *allocated = allocator.Allocate(GetAllocatorCache(&t->malloc_storage()),
203-
size, alignment);
202+
void *allocated;
203+
if (t) {
204+
AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
205+
allocated = allocator.Allocate(cache, size, alignment);
206+
} else {
207+
SpinMutexLock l(&fallback_mutex);
208+
AllocatorCache *cache = &fallback_allocator_cache;
209+
allocated = allocator.Allocate(cache, size, alignment);
210+
}
204211
if (UNLIKELY(!allocated)) {
205212
SetAllocatorOutOfMemory();
206213
if (AllocatorMayReturnNull())

0 commit comments

Comments
 (0)