[llvm-commits] [compiler-rt] r170329 - in /compiler-rt/trunk/lib/asan: asan_allocator.h asan_allocator2.cc
Kostya Serebryany
kcc at google.com
Mon Dec 17 05:43:47 PST 2012
Author: kcc
Date: Mon Dec 17 07:43:47 2012
New Revision: 170329
URL: http://llvm.org/viewvc/llvm-project?rev=170329&view=rev
Log:
[asan] asan_allocator2: don't use TLS and fix calloc
Modified:
compiler-rt/trunk/lib/asan/asan_allocator.h
compiler-rt/trunk/lib/asan/asan_allocator2.cc
Modified: compiler-rt/trunk/lib/asan/asan_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.h?rev=170329&r1=170328&r2=170329&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.h (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.h Mon Dec 17 07:43:47 2012
@@ -100,6 +100,9 @@
AsanChunkFifoList quarantine_;
AsanChunk *free_lists_[kNumberOfSizeClasses];
+#if ASAN_ALLOCATOR_VERSION == 2
+ uptr allocator2_cache[1024]; // Opaque.
+#endif
void CommitBack();
};
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=170329&r1=170328&r2=170329&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator2.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator2.cc Mon Dec 17 07:43:47 2012
@@ -54,7 +54,15 @@
typedef CombinedAllocator<PrimaryAllocator, AllocatorCache,
SecondaryAllocator> Allocator;
-static THREADLOCAL AllocatorCache cache;
+// We can not use THREADLOCAL because it is not supported on some of the
+// platforms we care about (OSX 10.6, Android).
+// static THREADLOCAL AllocatorCache cache;
+AllocatorCache *GetAllocatorCache(AsanThreadLocalMallocStorage *ms) {
+ CHECK(ms);
+ CHECK_LE(sizeof(AllocatorCache), sizeof(ms->allocator2_cache));
+ return reinterpret_cast<AllocatorCache *>(ms->allocator2_cache);
+}
+
static Allocator allocator;
static const uptr kMaxAllowedMallocSize =
@@ -172,26 +180,25 @@
class Quarantine: public AsanChunkFifoList {
public:
- void SwallowThreadLocalQuarantine(AsanChunkFifoList *q) {
+ void SwallowThreadLocalQuarantine(AsanThreadLocalMallocStorage *ms) {
+ AsanChunkFifoList *q = &ms->quarantine_;
if (!q->size()) return;
- // Printf("SwallowThreadLocalQuarantine %zd\n", q->size());
SpinMutexLock l(&mutex_);
PushList(q);
- PopAndDeallocateLoop();
+ PopAndDeallocateLoop(ms);
}
void BypassThreadLocalQuarantine(AsanChunk *m) {
SpinMutexLock l(&mutex_);
Push(m);
- PopAndDeallocateLoop();
}
private:
- void PopAndDeallocateLoop() {
+ void PopAndDeallocateLoop(AsanThreadLocalMallocStorage *ms) {
while (size() > (uptr)flags()->quarantine_size) {
- PopAndDeallocate();
+ PopAndDeallocate(ms);
}
}
- void PopAndDeallocate() {
+ void PopAndDeallocate(AsanThreadLocalMallocStorage *ms) {
CHECK_GT(size(), 0);
AsanChunk *m = Pop();
CHECK(m);
@@ -206,7 +213,7 @@
void *p = reinterpret_cast<void *>(alloc_beg);
if (m->from_memalign)
p = allocator.GetBlockBegin(p);
- allocator.Deallocate(&cache, p);
+ allocator.Deallocate(GetAllocatorCache(ms), p);
}
SpinMutex mutex_;
};
@@ -256,7 +263,10 @@
}
AsanThread *t = asanThreadRegistry().GetCurrent();
- void *allocated = allocator.Allocate(&cache, needed_size, 8, false);
+ // Printf("t = %p\n", t);
+ CHECK(t); // FIXME
+ void *allocated = allocator.Allocate(
+ GetAllocatorCache(&t->malloc_storage()), 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;
@@ -324,7 +334,7 @@
q.Push(m);
if (q.size() > kMaxThreadLocalQuarantine)
- quarantine.SwallowThreadLocalQuarantine(&q);
+ quarantine.SwallowThreadLocalQuarantine(&t->malloc_storage());
} else {
quarantine.BypassThreadLocalQuarantine(m);
}
@@ -360,7 +370,7 @@
}
void AsanThreadLocalMallocStorage::CommitBack() {
- UNIMPLEMENTED();
+ quarantine.SwallowThreadLocalQuarantine(this);
}
SANITIZER_INTERFACE_ATTRIBUTE
@@ -382,7 +392,7 @@
void *ptr = Allocate(nmemb * size, 8, stack);
if (ptr)
REAL(memset)(ptr, 0, nmemb * size);
- return 0;
+ return ptr;
}
void *asan_realloc(void *p, uptr size, StackTrace *stack) {
More information about the llvm-commits
mailing list