[compiler-rt] 10f57cf - [asan] Don't quarantine large blocks
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 22 10:07:58 PDT 2023
Author: Vitaly Buka
Date: 2023-06-22T10:07:45-07:00
New Revision: 10f57cf5dbc6bbb5c3e03a1b98a936ffc0797446
URL: https://github.com/llvm/llvm-project/commit/10f57cf5dbc6bbb5c3e03a1b98a936ffc0797446
DIFF: https://github.com/llvm/llvm-project/commit/10f57cf5dbc6bbb5c3e03a1b98a936ffc0797446.diff
LOG: [asan] Don't quarantine large blocks
Almost NFC, as blocks over max quarantine size will trigger immediate
drain anyway. In followup patches we can optimize passthrough case.
Reviewed By: thurston
Differential Revision: https://reviews.llvm.org/D153495
Added:
compiler-rt/test/asan/TestCases/Linux/small_quarantine_size_mb.cpp
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h b/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h
index 0665db535cce3..b8155cffbd7f1 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h
@@ -99,7 +99,7 @@ class Quarantine {
void Put(Cache *c, Callback cb, Node *ptr, uptr size) {
uptr max_cache_size = GetMaxCacheSize();
- if (max_cache_size) {
+ if (max_cache_size && size <= GetMaxSize()) {
c->Enqueue(cb, ptr, size);
} else {
// GetMaxCacheSize() == 0 only when GetMaxSize() == 0 (see Init).
diff --git a/compiler-rt/test/asan/TestCases/Linux/small_quarantine_size_mb.cpp b/compiler-rt/test/asan/TestCases/Linux/small_quarantine_size_mb.cpp
new file mode 100644
index 0000000000000..35182296aaa97
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/Linux/small_quarantine_size_mb.cpp
@@ -0,0 +1,25 @@
+// RUN: %clangxx_asan %s -o %t
+// RUN: %env_asan_opts=quarantine_size_mb=2 %run %t 1
+// RUN: %env_asan_opts=quarantine_size_mb=2 %run %t 4
+
+#include <cassert>
+#include <sanitizer/allocator_interface.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void *g;
+
+int main(int argc, char **argv) {
+ int s = atoi(argv[1]) * 1024 * 1024;
+ int a = __sanitizer_get_heap_size();
+ g = malloc(s);
+ int b = __sanitizer_get_heap_size();
+ assert(b - a > s / 2);
+ free(g);
+ int c = __sanitizer_get_heap_size();
+ fprintf(stderr, "%d %d\n", a, c);
+ if (atoi(argv[1]) == 1)
+ assert(c - a > s / 2); // NODRAIN
+ else
+ assert(c - a < s / 2); // DRAIN
+}
More information about the llvm-commits
mailing list