[compiler-rt] r195443 - [ASan] Fix large_allocator_unpoisons_on_free.cc to pass correct parameters to mmap() on OSX.

Alexander Potapenko glider at google.com
Fri Nov 22 03:19:29 PST 2013


Author: glider
Date: Fri Nov 22 05:19:28 2013
New Revision: 195443

URL: http://llvm.org/viewvc/llvm-project?rev=195443&view=rev
Log:
[ASan] Fix large_allocator_unpoisons_on_free.cc to pass correct parameters to mmap() on OSX.

Modified:
    compiler-rt/trunk/lib/asan/lit_tests/TestCases/large_allocator_unpoisons_on_free.cc

Modified: compiler-rt/trunk/lib/asan/lit_tests/TestCases/large_allocator_unpoisons_on_free.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/large_allocator_unpoisons_on_free.cc?rev=195443&r1=195442&r2=195443&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/large_allocator_unpoisons_on_free.cc (original)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/large_allocator_unpoisons_on_free.cc Fri Nov 22 05:19:28 2013
@@ -1,5 +1,7 @@
 // Test that LargeAllocator unpoisons memory before releasing it to the OS.
 // RUN: %clangxx_asan %s -o %t
+// The memory is released only when the deallocated chunk leaves the quarantine,
+// otherwise the mmap(p, ...) call overwrites the malloc header.
 // RUN: ASAN_OPTIONS=quarantine_size=1 %t
 
 #include <assert.h>
@@ -8,16 +10,16 @@
 #include <sys/mman.h>
 
 int main() {
-  void *p = malloc(1024 * 1024);
+  const int kPageSize = 4096;
+  void *p = NULL;
+  posix_memalign(&p, kPageSize, 1024 * 1024);
   free(p);
 
-  char *q = (char *)mmap(p, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 0, 0);
-  assert(q);
-  assert(q <= p);
-  assert(q + 4096 > p);
+  char *q = (char *)mmap(p, kPageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_FIXED, 0, 0);
+  assert(q == p);
 
-  memset(q, 42, 4096);
+  memset(q, 42, kPageSize);
 
-  munmap(q, 4096);
+  munmap(q, kPageSize);
   return 0;
 }





More information about the llvm-commits mailing list