diff options
author | Kostya Serebryany <kcc@google.com> | 2012-12-21 14:54:46 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2012-12-21 14:54:46 +0000 |
commit | fe80f080eefdd6fbb07aaa550c9addf085a938e0 (patch) | |
tree | 268ae06128e4ed4c5cb80cc448da6b1d86da23a1 | |
parent | fbde69e266f62e945c3a937b3607ac2e039c3717 (diff) | |
download | bcm5719-llvm-fe80f080eefdd6fbb07aaa550c9addf085a938e0.tar.gz bcm5719-llvm-fe80f080eefdd6fbb07aaa550c9addf085a938e0.zip |
[asan] asan_allocator2 fix two asserts that happen on full chrome: a) memalign called with 0 size and large alignment and b) malloc called after TSD has been destructed
llvm-svn: 170900
-rw-r--r-- | compiler-rt/lib/asan/asan_allocator2.cc | 16 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_allocator.h | 10 |
2 files changed, 16 insertions, 10 deletions
diff --git a/compiler-rt/lib/asan/asan_allocator2.cc b/compiler-rt/lib/asan/asan_allocator2.cc index 0bbbaa27a21..36eb78cdeac 100644 --- a/compiler-rt/lib/asan/asan_allocator2.cc +++ b/compiler-rt/lib/asan/asan_allocator2.cc @@ -82,7 +82,7 @@ static const uptr kMaxAllowedMallocSize = static const uptr kMaxThreadLocalQuarantine = FIRST_32_SECOND_64(1 << 18, 1 << 20); -static const uptr kReturnOnZeroMalloc = 0x0123; // Zero page is protected. +static const uptr kReturnOnZeroMalloc = 2048; // Zero page is protected. static int inited = 0; @@ -282,8 +282,12 @@ static void *Allocate(uptr size, uptr alignment, StackTrace *stack, Init(); CHECK(stack); if (alignment < 8) alignment = 8; - if (size == 0) - return reinterpret_cast<void *>(kReturnOnZeroMalloc); + if (size == 0) { + if (alignment <= kReturnOnZeroMalloc) + return reinterpret_cast<void *>(kReturnOnZeroMalloc); + else + return 0; // 0 bytes with large alignment requested. Just return 0. + } CHECK(IsPowerOfTwo(alignment)); uptr rz_size = ComputeRZSize(size); uptr rounded_size = RoundUpTo(size, rz_size); @@ -298,10 +302,8 @@ static void *Allocate(uptr size, uptr alignment, StackTrace *stack, } AsanThread *t = asanThreadRegistry().GetCurrent(); - // Printf("t = %p\n", t); - CHECK(t); // FIXME - void *allocated = allocator.Allocate( - GetAllocatorCache(&t->malloc_storage()), needed_size, 8, false); + AllocatorCache *cache = t ? GetAllocatorCache(&t->malloc_storage()) : 0; + void *allocated = allocator.Allocate(cache, needed_size, 8, false); uptr alloc_beg = reinterpret_cast<uptr>(allocated); uptr alloc_end = alloc_beg + needed_size; uptr beg_plus_redzone = alloc_beg + rz_size; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h index 06c52f88c2c..16c0ddf586c 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h @@ -762,10 +762,14 @@ class CombinedAllocator { if (alignment > 8) size = RoundUpTo(size, alignment); void *res; - if (primary_.CanAllocate(size, alignment)) - res = cache->Allocate(&primary_, primary_.ClassID(size)); - else + if (primary_.CanAllocate(size, alignment)) { + if (cache) // Allocate from cache. + res = cache->Allocate(&primary_, primary_.ClassID(size)); + else // No thread-local cache, allocate directly from primary allocator. + res = primary_.Allocate(size, alignment); + } else { // Secondary allocator does not use cache. res = secondary_.Allocate(size, alignment); + } if (alignment > 8) CHECK_EQ(reinterpret_cast<uptr>(res) & (alignment - 1), 0); if (cleared && res) |