OSDN Git Service

Add lock when iterating over BacktraceMap.
authorChristopher Ferris <cferris@google.com>
Fri, 17 Jun 2016 06:19:36 +0000 (23:19 -0700)
committerChristopher Ferris <cferris@google.com>
Thu, 25 Aug 2016 22:01:21 +0000 (15:01 -0700)
In order to avoid a race condition in the maps data, acquire
a read lock while iterating over the maps data.

Bug: 29387050
Bug: 31067025

(cherry picked from commit 56f8b5631ab2874dc2ec385802e38555acac0d90)

Change-Id: I48ecd2705b4aa4eedfed1daae2eb3b9b8bf8dda9

runtime/mem_map.cc

index 5d89c21..20c6112 100644 (file)
@@ -157,6 +157,8 @@ bool MemMap::ContainedWithinExistingMap(uint8_t* ptr, size_t size, std::string*
     }
     return false;
   }
+
+  ScopedBacktraceMapIteratorLock lock(map.get());
   for (BacktraceMap::const_iterator it = map->begin(); it != map->end(); ++it) {
     if ((begin >= it->start && begin < it->end)  // start of new within old
         && (end > it->start && end <= it->end)) {  // end of new within old
@@ -180,6 +182,7 @@ static bool CheckNonOverlapping(uintptr_t begin,
     *error_msg = StringPrintf("Failed to build process map");
     return false;
   }
+  ScopedBacktraceMapIteratorLock(map.get());
   for (BacktraceMap::const_iterator it = map->begin(); it != map->end(); ++it) {
     if ((begin >= it->start && begin < it->end)      // start of new within old
         || (end > it->start && end < it->end)        // end of new within old