[llvm-commits] [compiler-rt] r156710 - in /compiler-rt/trunk/lib/asan: asan_mapping.h asan_thread.cc
Evgeniy Stepanov
eugeni.stepanov at gmail.com
Sat May 12 05:33:10 PDT 2012
Author: eugenis
Date: Sat May 12 07:33:10 2012
New Revision: 156710
URL: http://llvm.org/viewvc/llvm-project?rev=156710&view=rev
Log:
Fix GetFrameNameByAddr hitting stale stack guards.
In the current implementation AsanThread::GetFrameNameByAddr scans the
stack for a magic guard value to locate base address of the stack
frame. This is not reliable, especially on ARM, where the code that
stores this magic value has to construct it in a register from two
small intermediates; this register can then end up stored in a random
stack location in the prologue of another function.
With this change, GetFrameNameByAddr scans the shadow memory for the
signature of a left stack redzone instead. It is now possible to
remove the magic from the instrumentation pass for additional
performance gain. We keep it there for now just to make sure the new
algorithm does not fail in some corner case.
Modified:
compiler-rt/trunk/lib/asan/asan_mapping.h
compiler-rt/trunk/lib/asan/asan_thread.cc
Modified: compiler-rt/trunk/lib/asan/asan_mapping.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mapping.h?rev=156710&r1=156709&r2=156710&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mapping.h (original)
+++ compiler-rt/trunk/lib/asan/asan_mapping.h Sat May 12 07:33:10 2012
@@ -35,6 +35,7 @@
#define SHADOW_GRANULARITY (1ULL << SHADOW_SCALE)
#define MEM_TO_SHADOW(mem) (((mem) >> SHADOW_SCALE) | (SHADOW_OFFSET))
+#define SHADOW_TO_MEM(shadow) (((shadow) - SHADOW_OFFSET) << SHADOW_SCALE)
#if __WORDSIZE == 64
static const size_t kHighMemEnd = 0x00007fffffffffffUL;
Modified: compiler-rt/trunk/lib/asan/asan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread.cc?rev=156710&r1=156709&r2=156710&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread.cc Sat May 12 07:33:10 2012
@@ -116,17 +116,29 @@
is_fake_stack = true;
}
uintptr_t aligned_addr = addr & ~(__WORDSIZE/8 - 1); // align addr.
- uintptr_t *ptr = (uintptr_t*)aligned_addr;
- while (ptr >= (uintptr_t*)bottom) {
- if (ptr[0] == kCurrentStackFrameMagic ||
- (is_fake_stack && ptr[0] == kRetiredStackFrameMagic)) {
- *offset = addr - (uintptr_t)ptr;
- return (const char*)ptr[1];
- }
- ptr--;
+ uint8_t *shadow_ptr = (uint8_t*)MemToShadow(aligned_addr);
+ uint8_t *shadow_bottom = (uint8_t*)MemToShadow(bottom);
+
+ while (shadow_ptr >= shadow_bottom &&
+ *shadow_ptr != kAsanStackLeftRedzoneMagic) {
+ shadow_ptr--;
+ }
+
+ while (shadow_ptr >= shadow_bottom &&
+ *shadow_ptr == kAsanStackLeftRedzoneMagic) {
+ shadow_ptr--;
}
- *offset = 0;
- return "UNKNOWN";
+
+ if (shadow_ptr < shadow_bottom) {
+ *offset = 0;
+ return "UNKNOWN";
+ }
+
+ uintptr_t* ptr = (uintptr_t*)SHADOW_TO_MEM((uintptr_t)(shadow_ptr + 1));
+ CHECK((ptr[0] == kCurrentStackFrameMagic) ||
+ (is_fake_stack && ptr[0] == kRetiredStackFrameMagic));
+ *offset = addr - (uintptr_t)ptr;
+ return (const char*)ptr[1];
}
} // namespace __asan
More information about the llvm-commits
mailing list