Move map data into backtrace data proper.

The backtrace structure used to include a pointer to a backtrace_map_t
that represented the map data for a particular pc. This introduced a
race condition where the pointer could be discarded, but the backtrace
structure still contained a pointer to garbage memory. Now all of the map
information is right in the structure.

Bug: 19028453
Change-Id: If7088a73f3c6bf1f3bc8cdd2bb4b62e7cab831c0
diff --git a/include/backtrace/BacktraceMap.h b/include/backtrace/BacktraceMap.h
index 4ed23a8..da96307 100644
--- a/include/backtrace/BacktraceMap.h
+++ b/include/backtrace/BacktraceMap.h
@@ -33,6 +33,8 @@
 #include <string>
 
 struct backtrace_map_t {
+  backtrace_map_t(): start(0), end(0), flags(0) {}
+
   uintptr_t start;
   uintptr_t end;
   int flags;
@@ -48,15 +50,16 @@
 
   virtual ~BacktraceMap();
 
-  // Get the map data structure for the given address.
-  virtual const backtrace_map_t* Find(uintptr_t addr);
+  // Fill in the map data structure for the given address.
+  virtual void FillIn(uintptr_t addr, backtrace_map_t* map);
 
   // The flags returned are the same flags as used by the mmap call.
   // The values are PROT_*.
   int GetFlags(uintptr_t pc) {
-    const backtrace_map_t* map = Find(pc);
-    if (map) {
-      return map->flags;
+    backtrace_map_t map;
+    FillIn(pc, &map);
+    if (IsValid(map)) {
+      return map.flags;
     }
     return PROT_NONE;
   }
@@ -75,6 +78,10 @@
 
   virtual bool Build();
 
+  static inline bool IsValid(const backtrace_map_t& map) {
+    return map.end > 0;
+  }
+
 protected:
   BacktraceMap(pid_t pid);