forked from OSchip/llvm-project
[asan] replace the flag uar_stack_size_log with two flags min_uar_stack_size_log/max_uar_stack_size_log
llvm-svn: 197370
This commit is contained in:
parent
3682fcda17
commit
1aedf6c9e6
|
@ -49,10 +49,10 @@ FakeStack *FakeStack::Create(uptr stack_size_log) {
|
|||
res->stack_size_log_ = stack_size_log;
|
||||
u8 *p = reinterpret_cast<u8 *>(res);
|
||||
VReport(1, "T%d: FakeStack created: %p -- %p stack_size_log: %zd; "
|
||||
"noreserve=%d \n",
|
||||
"mmapped %zdK, noreserve=%d \n",
|
||||
GetCurrentTidOrInvalid(), p,
|
||||
p + FakeStack::RequiredSize(stack_size_log), stack_size_log,
|
||||
flags()->uar_noreserve);
|
||||
size >> 10, flags()->uar_noreserve);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,8 +52,9 @@ struct Flags {
|
|||
bool mac_ignore_invalid_free;
|
||||
// Enables stack-use-after-return checking at run-time.
|
||||
bool detect_stack_use_after_return;
|
||||
// The minimal fake stack size log.
|
||||
int uar_stack_size_log;
|
||||
// The minimal and the maximal fake stack size log.
|
||||
int min_uar_stack_size_log;
|
||||
int max_uar_stack_size_log;
|
||||
// Use mmap with 'norserve' flag to allocate fake stack.
|
||||
bool uar_noreserve;
|
||||
// ASan allocator flag. max_malloc_fill_size is the maximal amount of bytes
|
||||
|
|
|
@ -108,7 +108,8 @@ static void ParseFlagsFromString(Flags *f, const char *str) {
|
|||
ParseFlag(str, &f->mac_ignore_invalid_free, "mac_ignore_invalid_free");
|
||||
ParseFlag(str, &f->detect_stack_use_after_return,
|
||||
"detect_stack_use_after_return");
|
||||
ParseFlag(str, &f->uar_stack_size_log, "uar_stack_size_log");
|
||||
ParseFlag(str, &f->min_uar_stack_size_log, "min_uar_stack_size_log");
|
||||
ParseFlag(str, &f->max_uar_stack_size_log, "max_uar_stack_size_log");
|
||||
ParseFlag(str, &f->uar_noreserve, "uar_noreserve");
|
||||
ParseFlag(str, &f->max_malloc_fill_size, "max_malloc_fill_size");
|
||||
ParseFlag(str, &f->malloc_fill_byte, "malloc_fill_byte");
|
||||
|
@ -151,7 +152,8 @@ void InitializeFlags(Flags *f, const char *env) {
|
|||
f->replace_intrin = true;
|
||||
f->mac_ignore_invalid_free = false;
|
||||
f->detect_stack_use_after_return = false; // Also needs the compiler flag.
|
||||
f->uar_stack_size_log = 0;
|
||||
f->min_uar_stack_size_log = 16; // We can't do smaller anyway.
|
||||
f->max_uar_stack_size_log = 20; // 1Mb per size class, i.e. ~11Mb per thread.
|
||||
f->uar_noreserve = false;
|
||||
f->max_malloc_fill_size = 0x1000; // By default, fill only the first 4K.
|
||||
f->malloc_fill_byte = 0xbe;
|
||||
|
@ -459,6 +461,7 @@ void __asan_init() {
|
|||
__sanitizer_set_report_path(common_flags()->log_path);
|
||||
__asan_option_detect_stack_use_after_return =
|
||||
flags()->detect_stack_use_after_return;
|
||||
CHECK_LE(flags()->min_uar_stack_size_log, flags()->max_uar_stack_size_log);
|
||||
|
||||
if (options) {
|
||||
VReport(1, "Parsed ASAN_OPTIONS: %s\n", options);
|
||||
|
|
|
@ -126,8 +126,11 @@ FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
|
|||
reinterpret_cast<atomic_uintptr_t *>(&fake_stack_), &old_val, 1UL,
|
||||
memory_order_relaxed)) {
|
||||
uptr stack_size_log = Log2(RoundUpToPowerOfTwo(stack_size));
|
||||
if (flags()->uar_stack_size_log)
|
||||
stack_size_log = static_cast<uptr>(flags()->uar_stack_size_log);
|
||||
CHECK_LE(flags()->min_uar_stack_size_log, flags()->max_uar_stack_size_log);
|
||||
stack_size_log =
|
||||
Min(stack_size_log, static_cast<uptr>(flags()->max_uar_stack_size_log));
|
||||
stack_size_log =
|
||||
Max(stack_size_log, static_cast<uptr>(flags()->min_uar_stack_size_log));
|
||||
fake_stack_ = FakeStack::Create(stack_size_log);
|
||||
SetTLSFakeStack(fake_stack_);
|
||||
return fake_stack_;
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
// RUN: %clangxx_asan -DUseThread -O2 %s -o %t && \
|
||||
// RUN: not %t 2>&1 | FileCheck --check-prefix=THREAD %s
|
||||
//
|
||||
// Test the uar_stack_size_log flag.
|
||||
// Test the max_uar_stack_size_log/min_uar_stack_size_log flag.
|
||||
//
|
||||
// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:uar_stack_size_log=20:verbosity=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-20 %s
|
||||
// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:uar_stack_size_log=24:verbosity=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-24 %s
|
||||
// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:max_uar_stack_size_log=20:verbosity=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-20 %s
|
||||
// RUN: ASAN_OPTIONS=$ASAN_OPTIONS:min_uar_stack_size_log=24:max_uar_stack_size_log=28:verbosity=1 not %t 2>&1 | FileCheck --check-prefix=CHECK-24 %s
|
||||
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
|
|
Loading…
Reference in New Issue