[compiler-rt] r279046 - Convert AsanLocateAddress to Get*AddressInformation functions.
Filipe Cabecinhas via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 18 03:31:19 PDT 2016
Author: filcab
Date: Thu Aug 18 05:31:19 2016
New Revision: 279046
URL: http://llvm.org/viewvc/llvm-project?rev=279046&view=rev
Log:
Convert AsanLocateAddress to Get*AddressInformation functions.
Modified:
compiler-rt/trunk/lib/asan/asan_debugging.cc
Modified: compiler-rt/trunk/lib/asan/asan_debugging.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_debugging.cc?rev=279046&r1=279045&r2=279046&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_debugging.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_debugging.cc Thu Aug 18 05:31:19 2016
@@ -21,50 +21,30 @@
#include "asan_report.h"
#include "asan_thread.h"
-namespace __asan {
-
-void GetInfoForStackVar(uptr addr, AddressDescription *descr, AsanThread *t) {
- descr->name[0] = 0;
- descr->region_address = 0;
- descr->region_size = 0;
- descr->region_kind = "stack";
+namespace {
+using namespace __asan;
- AsanThread::StackFrameAccess access;
- if (!t->GetStackFrameAccessByAddr(addr, &access))
- return;
+void FindInfoForStackVar(uptr addr, const char *frame_descr, uptr offset,
+ AddressDescription *descr) {
InternalMmapVector<StackVarDescr> vars(16);
- if (!ParseFrameDescription(access.frame_descr, &vars)) {
+ if (!ParseFrameDescription(frame_descr, &vars)) {
return;
}
for (uptr i = 0; i < vars.size(); i++) {
- if (access.offset <= vars[i].beg + vars[i].size) {
- internal_strncat(descr->name, vars[i].name_pos,
- Min(descr->name_size, vars[i].name_len));
- descr->region_address = addr - (access.offset - vars[i].beg);
+ if (offset <= vars[i].beg + vars[i].size) {
+ // We use name_len + 1 because strlcpy will guarantee a \0 at the end, so
+ // if we're limiting the copy due to name_len, we add 1 to ensure we copy
+ // the whole name and then terminate with '\0'.
+ internal_strlcpy(descr->name, vars[i].name_pos,
+ Min(descr->name_size, vars[i].name_len + 1));
+ descr->region_address = addr - (offset - vars[i].beg);
descr->region_size = vars[i].size;
return;
}
}
}
-void GetInfoForHeapAddress(uptr addr, AddressDescription *descr) {
- AsanChunkView chunk = FindHeapChunkByAddress(addr);
-
- descr->name[0] = 0;
- descr->region_address = 0;
- descr->region_size = 0;
-
- if (!chunk.IsValid()) {
- descr->region_kind = "heap-invalid";
- return;
- }
-
- descr->region_address = chunk.Beg();
- descr->region_size = chunk.UsedSize();
- descr->region_kind = "heap";
-}
-
void AsanLocateAddress(uptr addr, AddressDescription *descr) {
ShadowAddressDescription shadow_descr;
if (GetShadowAddressInformation(addr, &shadow_descr)) {
@@ -80,17 +60,39 @@ void AsanLocateAddress(uptr addr, Addres
descr->region_size = g.size;
return;
}
+
+ StackAddressDescription stack_descr;
asanThreadRegistry().Lock();
- AsanThread *thread = FindThreadByStackAddress(addr);
+ if (GetStackAddressInformation(addr, &stack_descr)) {
+ asanThreadRegistry().Unlock();
+ descr->region_kind = "stack";
+ if (!stack_descr.frame_descr) {
+ descr->name[0] = 0;
+ descr->region_address = 0;
+ descr->region_size = 0;
+ } else {
+ FindInfoForStackVar(addr, stack_descr.frame_descr, stack_descr.offset,
+ descr);
+ }
+ return;
+ }
asanThreadRegistry().Unlock();
- if (thread) {
- GetInfoForStackVar(addr, descr, thread);
+
+ descr->name[0] = 0;
+ HeapAddressDescription heap_descr;
+ if (GetHeapAddressInformation(addr, 1, &heap_descr)) {
+ descr->region_address = heap_descr.chunk_access.chunk_begin;
+ descr->region_size = heap_descr.chunk_access.chunk_size;
+ descr->region_kind = "heap";
return;
}
- GetInfoForHeapAddress(addr, descr);
+
+ descr->region_address = 0;
+ descr->region_size = 0;
+ descr->region_kind = "heap-invalid";
}
-static uptr AsanGetStack(uptr addr, uptr *trace, u32 size, u32 *thread_id,
+uptr AsanGetStack(uptr addr, uptr *trace, u32 size, u32 *thread_id,
bool alloc_stack) {
AsanChunkView chunk = FindHeapChunkByAddress(addr);
if (!chunk.IsValid()) return 0;
@@ -117,9 +119,7 @@ static uptr AsanGetStack(uptr addr, uptr
return 0;
}
-} // namespace __asan
-
-using namespace __asan;
+} // namespace
SANITIZER_INTERFACE_ATTRIBUTE
const char *__asan_locate_address(uptr addr, char *name, uptr name_size,
More information about the llvm-commits
mailing list