asan: always pass allocator cache to Allocate()

llvm-svn: 172193
This commit is contained in:
Dmitry Vyukov 2013-01-11 11:15:48 +00:00
parent b1c0dbe2c6
commit 008dba6aa0
2 changed files with 13 additions and 9 deletions

View File

@ -337,8 +337,15 @@ static void *Allocate(uptr size, uptr alignment, StackTrace *stack,
}
AsanThread *t = asanThreadRegistry().GetCurrent();
AllocatorCache *cache = t ? GetAllocatorCache(&t->malloc_storage()) : 0;
void *allocated = allocator.Allocate(cache, needed_size, 8, false);
void *allocated;
if (t) {
AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
allocated = allocator.Allocate(cache, needed_size, 8, false);
} else {
SpinMutexLock l(&fallback_mutex);
AllocatorCache *cache = &fallback_cache;
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;

View File

@ -728,6 +728,7 @@ class LargeMmapAllocator {
internal_memset(this, 0, sizeof(*this));
page_size_ = GetPageSizeCached();
}
void *Allocate(uptr size, uptr alignment) {
CHECK(IsPowerOfTwo(alignment));
uptr map_size = RoundUpMapSize(size);
@ -899,14 +900,10 @@ class CombinedAllocator {
if (alignment > 8)
size = RoundUpTo(size, alignment);
void *res;
if (primary_.CanAllocate(size, alignment)) {
if (cache) // Allocate from cache.
if (primary_.CanAllocate(size, alignment))
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.
else
res = secondary_.Allocate(size, alignment);
}
if (alignment > 8)
CHECK_EQ(reinterpret_cast<uptr>(res) & (alignment - 1), 0);
if (cleared && res)