[llvm-commits] [compiler-rt] r172193 - in /compiler-rt/trunk/lib: asan/asan_allocator2.cc sanitizer_common/sanitizer_allocator.h
Dmitry Vyukov
dvyukov at google.com
Fri Jan 11 03:15:48 PST 2013
Author: dvyukov
Date: Fri Jan 11 05:15:48 2013
New Revision: 172193
URL: http://llvm.org/viewvc/llvm-project?rev=172193&view=rev
Log:
asan: always pass allocator cache to Allocate()
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=172193&r1=172192&r2=172193&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator2.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator2.cc Fri Jan 11 05:15:48 2013
@@ -337,8 +337,15 @@
}
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;
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=172193&r1=172192&r2=172193&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h Fri Jan 11 05:15:48 2013
@@ -728,6 +728,7 @@
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 @@
if (alignment > 8)
size = RoundUpTo(size, alignment);
void *res;
- 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.
+ if (primary_.CanAllocate(size, alignment))
+ res = cache->Allocate(&primary_, primary_.ClassID(size));
+ else
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