[llvm-commits] [compiler-rt] r172048 - in /compiler-rt/trunk/lib/asan: asan_allocator2.cc tests/asan_test.cc

Kostya Serebryany kcc at google.com
Thu Jan 10 01:25:17 PST 2013


Author: kcc
Date: Thu Jan 10 03:25:16 2013
New Revision: 172048

URL: http://llvm.org/viewvc/llvm-project?rev=172048&view=rev
Log:
[asan] asan_allocator2: do less work under the quarantine lock; make the strcasecmp test more resistant to the contents of unaddressable memory 

Modified:
    compiler-rt/trunk/lib/asan/asan_allocator2.cc
    compiler-rt/trunk/lib/asan/tests/asan_test.cc

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=172048&r1=172047&r2=172048&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator2.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator2.cc Thu Jan 10 03:25:16 2013
@@ -251,9 +251,16 @@
   void SwallowThreadLocalQuarantine(AsanThreadLocalMallocStorage *ms) {
     AsanChunkFifoList *q = &ms->quarantine_;
     if (!q->size()) return;
-    SpinMutexLock l(&mutex_);
-    PushList(q);
-    PopAndDeallocateLoop(ms);
+    AsanChunkFifoList tmp;
+    uptr max_size = flags()->quarantine_size;
+    {
+      SpinMutexLock l(&mutex_);
+      PushList(q);
+      while (size() > max_size)
+        tmp.Push(Pop());
+    }
+    while (!tmp.empty())
+      Deallocate(tmp.Pop(), ms);
   }
 
   void BypassThreadLocalQuarantine(AsanChunk *m) {
@@ -262,14 +269,7 @@
   }
 
  private:
-  void PopAndDeallocateLoop(AsanThreadLocalMallocStorage *ms) {
-    while (size() > (uptr)flags()->quarantine_size) {
-      PopAndDeallocate(ms);
-    }
-  }
-  void PopAndDeallocate(AsanThreadLocalMallocStorage *ms) {
-    CHECK_GT(size(), 0);
-    AsanChunk *m = Pop();
+  static void Deallocate(AsanChunk *m, AsanThreadLocalMallocStorage *ms) {
     CHECK(m);
     CHECK(m->chunk_state == CHUNK_QUARANTINE);
     m->chunk_state = CHUNK_AVAILABLE;

Modified: compiler-rt/trunk/lib/asan/tests/asan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_test.cc?rev=172048&r1=172047&r2=172048&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/asan_test.cc (original)
+++ compiler-rt/trunk/lib/asan/tests/asan_test.cc Thu Jan 10 03:25:16 2013
@@ -1313,8 +1313,9 @@
 typedef int(*PointerToStrCmp)(const char*, const char*);
 void RunStrCmpTest(PointerToStrCmp StrCmp) {
   size_t size = Ident(100);
-  char *s1 = MallocAndMemsetString(size);
-  char *s2 = MallocAndMemsetString(size);
+  int fill = 'o';
+  char *s1 = MallocAndMemsetString(size, fill);
+  char *s2 = MallocAndMemsetString(size, fill);
   s1[size - 1] = '\0';
   s2[size - 1] = '\0';
   // Normal StrCmp calls
@@ -1330,7 +1331,7 @@
   EXPECT_DEATH(Ident(StrCmp)(s1 + size, s2), RightOOBReadMessage(0));
   EXPECT_DEATH(Ident(StrCmp)(s1, s2 + size), RightOOBReadMessage(0));
   // Hit unallocated memory and die.
-  s2[size - 1] = 'z';
+  s1[size - 1] = fill;
   EXPECT_DEATH(Ident(StrCmp)(s1, s1), RightOOBReadMessage(0));
   EXPECT_DEATH(Ident(StrCmp)(s1 + size - 1, s2), RightOOBReadMessage(0));
   free(s1);





More information about the llvm-commits mailing list