[PATCH] D24131: Add NewAddressDescription, which can describe any type of address.
Filipe Cabecinhas via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 1 07:28:38 PDT 2016
filcab created this revision.
filcab added reviewers: kcc, vitalybuka, eugenis.
filcab added a subscriber: llvm-commits.
Herald added a subscriber: kubabrecka.
This is useful for inclusion in the Error* structures.
The class will be renamed after getting rid of the current AddressDescription,
which is only used in asan_debugging.cc
Split between *Base and the "proper" object with constructors, because VS2013
doesn't allow us to include objects without a trivial default constructor in an
enum, and I'd like to be sure that a NewAddressDescription object is always
valid, so we need initialization.
https://reviews.llvm.org/D24131
Files:
lib/asan/asan_descriptions.h
Index: lib/asan/asan_descriptions.h
===================================================================
--- lib/asan/asan_descriptions.h
+++ lib/asan/asan_descriptions.h
@@ -165,6 +165,84 @@
void PrintAddressDescription(uptr addr, uptr access_size = 1,
const char *bug_type = "");
+enum AddressKind {
+ kAddressKindWild,
+ kAddressKindShadow,
+ kAddressKindHeap,
+ kAddressKindStack,
+ kAddressKindGlobal,
+};
+
+struct NewAddressDescriptionBase {
+ AddressKind kind;
+ union {
+ ShadowAddressDescription shadow;
+ HeapAddressDescription heap;
+ StackAddressDescription stack;
+ GlobalAddressDescription global;
+ uptr addr;
+ };
+ uptr Address() {
+ switch (kind) {
+ case kAddressKindWild:
+ return addr;
+ case kAddressKindShadow:
+ return shadow.addr;
+ case kAddressKindHeap:
+ return heap.addr;
+ case kAddressKindStack:
+ return stack.addr;
+ case kAddressKindGlobal:
+ return global.addr;
+ }
+ }
+ void Print() {
+ switch (kind) {
+ case kAddressKindWild:
+ Printf("Address %p is a wild pointer.\n", addr);
+ return;
+ case kAddressKindShadow:
+ return shadow.Print();
+ case kAddressKindHeap:
+ return heap.Print();
+ case kAddressKindStack:
+ return stack.Print();
+ case kAddressKindGlobal:
+ return global.Print();
+ }
+ }
+};
+
+struct NewAddressDescription : NewAddressDescriptionBase {
+ NewAddressDescription() {
+ kind = kAddressKindWild;
+ addr = 0;
+ }
+ explicit NewAddressDescription(uptr addr) {
+ if (GetShadowAddressInformation(addr, &shadow)) {
+ kind = kAddressKindShadow;
+ return;
+ }
+ if (GetHeapAddressInformation(addr, 1, &heap)) {
+ kind = kAddressKindHeap;
+ return;
+ }
+ asanThreadRegistry().Lock();
+ if (GetStackAddressInformation(addr, &stack)) {
+ kind = kAddressKindStack;
+ asanThreadRegistry().Unlock();
+ return;
+ }
+ asanThreadRegistry().Unlock();
+ if (GetGlobalAddressInformation(addr, &global)) {
+ kind = kAddressKindGlobal;
+ return;
+ }
+ kind = kAddressKindWild;
+ addr = 0;
+ }
+};
+
} // namespace __asan
#endif // ASAN_DESCRIPTIONS_H
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24131.70004.patch
Type: text/x-patch
Size: 2287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160901/43282b22/attachment.bin>
More information about the llvm-commits
mailing list