]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/asan/TestCases/Linux/thread_local_quarantine_size_kb.cc
1 // Test thread_local_quarantine_size_kb
3 // RUN: %clangxx_asan %s -o %t
4 // RUN: %env_asan_opts=thread_local_quarantine_size_kb=256:verbosity=1 %run %t 2>&1 | \
5 // RUN: FileCheck %s --check-prefix=CHECK-VALUE
6 // RUN: %env_asan_opts=thread_local_quarantine_size_kb=64:quarantine_size_mb=64 %run %t 2>&1 | \
7 // RUN: FileCheck %s --allow-empty --check-prefix=CHECK-SMALL-LOCAL-CACHE-SMALL-OVERHEAD
8 // RUN: %env_asan_opts=thread_local_quarantine_size_kb=0:quarantine_size_mb=0 %run %t 2>&1 | \
9 // RUN: FileCheck %s --check-prefix=CHECK-QUARANTINE-DISABLED
10 // RUN: %env_asan_opts=thread_local_quarantine_size_kb=0:quarantine_size_mb=64 not %run %t 2>&1 | \
11 // RUN: FileCheck %s --check-prefix=CHECK-FOR-PARAMETER-ERROR
16 #include <sanitizer/allocator_interface.h>
18 // The idea is allocate a lot of small blocks, totaling 5Mb of user memory
19 // total, and verify that quarantine does not incur too much memory overhead.
20 // There's always an overhead for red zones, shadow memory and such, but
21 // quarantine accounting should not significantly contribute to that.
22 static const int kNumAllocs
= 20000;
23 static const int kAllocSize
= 256;
24 static const size_t kHeapSizeLimit
= 12 << 20;
27 size_t old_heap_size
= __sanitizer_get_heap_size();
28 for (int i
= 0; i
< kNumAllocs
; i
++) {
29 char *g
= new char[kAllocSize
];
30 memset(g
, -1, kAllocSize
);
33 size_t new_heap_size
= __sanitizer_get_heap_size();
34 fprintf(stderr
, "heap size: new: %zd old: %zd\n", new_heap_size
,
36 if (new_heap_size
- old_heap_size
> kHeapSizeLimit
)
37 fprintf(stderr
, "Heap size limit exceeded");
40 // CHECK-VALUE: thread_local_quarantine_size_kb=256K
41 // CHECK-SMALL-LOCAL-CACHE-SMALL-OVERHEAD-NOT: Heap size limit exceeded
42 // CHECK-QUARANTINE-DISABLED-NOT: Heap size limit exceeded
43 // CHECK-FOR-PARAMETER-ERROR: thread_local_quarantine_size_kb can be set to 0 only when quarantine_size_mb is set to 0