[llvm-commits] [compiler-rt] r170900 - in /compiler-rt/trunk/lib: asan/asan_allocator2.cc sanitizer_common/sanitizer_allocator.h
Kostya Serebryany
kcc at google.com
Fri Dec 21 06:54:46 PST 2012
Author: kcc
Date: Fri Dec 21 08:54:46 2012
New Revision: 170900
URL: http://llvm.org/viewvc/llvm-project?rev=170900&view=rev
Log:
[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
Modified:
compiler-rt/trunk/lib/asan/asan_allocator2.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
Modified: compiler-rt/trunk/lib/asan/asan_allocator2.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator2.cc?rev=170900&r1=170899&r2=170900&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator2.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator2.cc Fri Dec 21 08:54:46 2012
@@ -82,7 +82,7 @@
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 @@
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 @@
}
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;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=170900&r1=170899&r2=170900&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h Fri Dec 21 08:54:46 2012
@@ -762,10 +762,14 @@
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)
More information about the llvm-commits
mailing list