aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2015-01-07 02:37:52 +0000
committerKostya Serebryany <kcc@google.com>2015-01-07 02:37:52 +0000
commitc26d26c3f3cde1121cb8f081c991fca8973d28bc (patch)
tree1914ef006a0fa169e07e4d65f94a8853e818f8be
parentb3793db6a5060ab98be7f01a5d9e8247e95f4261 (diff)
downloadcompiler-rt-c26d26c3f3cde1121cb8f081c991fca8973d28bc.tar.gz
[asan] add flag quarantine_size_mb, deprecate quarantine_size
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@225337 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/asan/asan_allocator.cc4
-rw-r--r--lib/asan/asan_flags.cc13
-rw-r--r--lib/asan/asan_flags.inc6
-rw-r--r--lib/asan/asan_rtl.cc2
-rw-r--r--test/asan/TestCases/Linux/quarantine_size_mb.cc24
-rw-r--r--test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc2
-rw-r--r--test/asan/TestCases/Posix/tsd_dtor_leak.cc21
7 files changed, 53 insertions, 19 deletions
diff --git a/lib/asan/asan_allocator.cc b/lib/asan/asan_allocator.cc
index 9525cf536..fd63ac68c 100644
--- a/lib/asan/asan_allocator.cc
+++ b/lib/asan/asan_allocator.cc
@@ -206,7 +206,7 @@ QuarantineCache *GetQuarantineCache(AsanThreadLocalMallocStorage *ms) {
}
void AllocatorOptions::SetFrom(const Flags *f, const CommonFlags *cf) {
- quarantine_size_mb = f->quarantine_size >> 20;
+ quarantine_size_mb = f->quarantine_size_mb;
min_redzone = f->redzone;
max_redzone = f->max_redzone;
may_return_null = cf->allocator_may_return_null;
@@ -214,7 +214,7 @@ void AllocatorOptions::SetFrom(const Flags *f, const CommonFlags *cf) {
}
void AllocatorOptions::CopyTo(Flags *f, CommonFlags *cf) {
- f->quarantine_size = (int)quarantine_size_mb << 20;
+ f->quarantine_size_mb = quarantine_size_mb;
f->redzone = min_redzone;
f->max_redzone = max_redzone;
cf->allocator_may_return_null = may_return_null;
diff --git a/lib/asan/asan_flags.cc b/lib/asan/asan_flags.cc
index d6144a7a6..2c2d5c8f1 100644
--- a/lib/asan/asan_flags.cc
+++ b/lib/asan/asan_flags.cc
@@ -64,6 +64,7 @@ void InitializeFlags(Flags *f) {
OverrideCommonFlags(cf);
}
+ const int kDefaultQuarantineSizeMb = (ASAN_LOW_MEMORY) ? 1UL << 6 : 1UL << 8;
f->SetDefaults();
// Override from compile definition.
@@ -118,6 +119,18 @@ void InitializeFlags(Flags *f) {
CHECK_LE(f->max_redzone, 2048);
CHECK(IsPowerOfTwo(f->redzone));
CHECK(IsPowerOfTwo(f->max_redzone));
+
+ // quarantine_size is deprecated but we still honor it.
+ // quarantine_size can not be used together with quarantine_size_mb.
+ if (f->quarantine_size >= 0 && f->quarantine_size_mb >= 0) {
+ Report("%s: please use either 'quarantine_size' (deprecated) or "
+ "quarantine_size_mb, but not both\n", SanitizerToolName);
+ Die();
+ }
+ if (f->quarantine_size >= 0)
+ f->quarantine_size_mb = f->quarantine_size >> 20;
+ if (f->quarantine_size_mb < 0)
+ f->quarantine_size_mb = kDefaultQuarantineSizeMb;
}
} // namespace __asan
diff --git a/lib/asan/asan_flags.inc b/lib/asan/asan_flags.inc
index 066b47aec..ec9d41980 100644
--- a/lib/asan/asan_flags.inc
+++ b/lib/asan/asan_flags.inc
@@ -17,8 +17,10 @@
// ASAN_FLAG(Type, Name, DefaultValue, Description)
// See COMMON_FLAG in sanitizer_flags.inc for more details.
-ASAN_FLAG(int, quarantine_size, (ASAN_LOW_MEMORY) ? 1UL << 26 : 1UL << 28,
- "Size (in bytes) of quarantine used to detect use-after-free "
+ASAN_FLAG(int, quarantine_size, -1,
+ "Deprecated, please use quarantine_size_mb.")
+ASAN_FLAG(int, quarantine_size_mb, -1,
+ "Size (in Mb) of quarantine used to detect use-after-free "
"errors. Lower value may reduce memory usage but increase the "
"chance of false negatives.")
ASAN_FLAG(int, redzone, 16,
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index 9d994885e..db258e73e 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -281,7 +281,7 @@ static void PrintAddressSpaceLayout() {
Printf("\n");
Printf("redzone=%zu\n", (uptr)flags()->redzone);
Printf("max_redzone=%zu\n", (uptr)flags()->max_redzone);
- Printf("quarantine_size=%zuM\n", (uptr)flags()->quarantine_size >> 20);
+ Printf("quarantine_size_mb=%zuM\n", (uptr)flags()->quarantine_size_mb);
Printf("malloc_context_size=%zu\n",
(uptr)common_flags()->malloc_context_size);
diff --git a/test/asan/TestCases/Linux/quarantine_size_mb.cc b/test/asan/TestCases/Linux/quarantine_size_mb.cc
new file mode 100644
index 000000000..449999244
--- /dev/null
+++ b/test/asan/TestCases/Linux/quarantine_size_mb.cc
@@ -0,0 +1,24 @@
+// Test quarantine_size_mb (and the deprecated quarantine_size)
+// RUN: %clangxx_asan %s -o %t
+// RUN: ASAN_OPTIONS=quarantine_size=10485760:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
+// RUN: ASAN_OPTIONS=quarantine_size_mb=10:verbosity=1:hard_rss_limit_mb=50 %run %t 2>&1 | FileCheck %s --check-prefix=Q10
+// RUN: ASAN_OPTIONS=quarantine_size_mb=10:quarantine_size=20:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=BOTH
+// RUN: ASAN_OPTIONS=quarantine_size_mb=1000:hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
+// RUN: ASAN_OPTIONS=hard_rss_limit_mb=50 not %run %t 2>&1 | FileCheck %s --check-prefix=RSS_LIMIT
+#include <string.h>
+char *g;
+
+static const int kNumAllocs = 1 << 11;
+static const int kAllocSize = 1 << 20;
+
+int main() {
+ for (int i = 0; i < kNumAllocs; i++) {
+ g = new char[kAllocSize];
+ memset(g, -1, kAllocSize);
+ delete [] (g);
+ }
+}
+
+// Q10: quarantine_size_mb=10M
+// BOTH: please use either 'quarantine_size' (deprecated) or quarantine_size_mb, but not both
+// RSS_LIMIT: AddressSanitizer: hard rss limit exhausted
diff --git a/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc b/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc
index 0a4998049..f852a62ea 100644
--- a/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc
+++ b/test/asan/TestCases/Posix/large_allocator_unpoisons_on_free.cc
@@ -2,7 +2,7 @@
// 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 %run %t
+// RUN: ASAN_OPTIONS=quarantine_size_mb=0 %run %t
#include <assert.h>
#include <string.h>
diff --git a/test/asan/TestCases/Posix/tsd_dtor_leak.cc b/test/asan/TestCases/Posix/tsd_dtor_leak.cc
index cdccf1a9f..695224522 100644
--- a/test/asan/TestCases/Posix/tsd_dtor_leak.cc
+++ b/test/asan/TestCases/Posix/tsd_dtor_leak.cc
@@ -1,7 +1,7 @@
// Regression test for a leak in tsd:
// https://code.google.com/p/address-sanitizer/issues/detail?id=233
// RUN: %clangxx_asan -O1 %s -pthread -o %t
-// RUN: ASAN_OPTIONS=quarantine_size=1 %run %t
+// RUN: ASAN_OPTIONS=quarantine_size_mb=0 %run %t
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@@ -25,22 +25,17 @@ void Dtor(void *tsd) {
int main() {
assert(0 == pthread_key_create(&tsd_key, Dtor));
- size_t old_heap_size = 0;
+ pthread_t t;
+ for (int i = 0; i < 3; i++) {
+ pthread_create(&t, 0, Thread, 0);
+ pthread_join(t, 0);
+ }
+ size_t old_heap_size = __sanitizer_get_heap_size();
for (int i = 0; i < 10; i++) {
- pthread_t t;
pthread_create(&t, 0, Thread, 0);
pthread_join(t, 0);
size_t new_heap_size = __sanitizer_get_heap_size();
fprintf(stderr, "heap size: new: %zd old: %zd\n", new_heap_size, old_heap_size);
- if (old_heap_size)
- assert(old_heap_size == new_heap_size);
-#if defined(__FreeBSD__)
- // On FreeBSD SYSCALL(sched_yielld) allocates some more space during the
- // 2nd attempt.
- if (i > 0)
- old_heap_size = new_heap_size;
-#else
- old_heap_size = new_heap_size;
-#endif
+ assert(old_heap_size == new_heap_size);
}
}