[asan] make use-after-return mode more robust: allow to call instrumented functions while reporting an error

llvm-svn: 146231
This commit is contained in:
Kostya Serebryany 2011-12-09 01:49:31 +00:00
parent ae89987ffe
commit 72fde3727e
3 changed files with 12 additions and 3 deletions

View File

@ -869,7 +869,6 @@ bool FakeStack::AddrIsInSizeClass(uintptr_t addr, size_t size_class) {
}
uintptr_t FakeStack::AddrIsInFakeStack(uintptr_t addr) {
if (!alive_) return 0;
for (size_t i = 0; i < kNumberOfSizeClasses; i++) {
if (AddrIsInSizeClass(addr, i)) return allocated_size_classes_[i];
}
@ -959,7 +958,7 @@ void FakeStack::AllocateOneSizeClass(size_t size_class) {
}
uintptr_t FakeStack::AllocateStack(size_t size, size_t real_stack) {
CHECK(alive_);
if (!alive_) return real_stack;
CHECK(size <= kMaxStackMallocSize && size > 1);
size_t size_class = ComputeSizeClass(size);
if (!allocated_size_classes_[size_class]) {

View File

@ -101,6 +101,7 @@ class FakeStack {
FakeStack();
explicit FakeStack(LinkerInitialized) {}
void Init(size_t stack_size);
void StopUsingFakeStack() { alive_ = false; }
void Cleanup();
uintptr_t AllocateStack(size_t size, size_t real_stack);
static void OnFree(size_t ptr, size_t size, size_t real_stack);

View File

@ -586,13 +586,22 @@ void __asan_report_error(uintptr_t pc, uintptr_t bp, uintptr_t sp,
}
}
AsanThread *curr_thread = asanThreadRegistry().GetCurrent();
int curr_tid = asanThreadRegistry().GetCurrentTidOrMinusOne();
if (curr_thread) {
// We started reporting an error message. Stop using the fake stack
// in case we will call an instrumented function from a symbolizer.
curr_thread->fake_stack().StopUsingFakeStack();
}
Report("ERROR: AddressSanitizer %s on address "
"%p at pc 0x%lx bp 0x%lx sp 0x%lx\n",
bug_descr, addr, pc, bp, sp);
Printf("%s of size %d at %p thread T%d\n",
access_size ? (is_write ? "WRITE" : "READ") : "ACCESS",
access_size, addr, asanThreadRegistry().GetCurrentTidOrMinusOne());
access_size, addr, curr_tid);
if (FLAG_debug) {
PrintBytes("PC: ", (uintptr_t*)pc);