[PATCH] D32012: Implement global pointer scanning for darwin leak sanitizer

Francis Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 13 07:26:56 PDT 2017


fjricci created this revision.

https://reviews.llvm.org/D32012

Files:
  lib/lsan/lsan_common_mac.cc


Index: lib/lsan/lsan_common_mac.cc
===================================================================
--- lib/lsan/lsan_common_mac.cc
+++ lib/lsan/lsan_common_mac.cc
@@ -91,7 +91,37 @@
 
 // Scans global variables for heap pointers.
 void ProcessGlobalRegions(Frontier *frontier) {
-  CHECK(0 && "unimplemented");
+  MemoryMappingLayout memory_mapping(false);
+  InternalMmapVector<LoadedModule> modules(/*initial_capacity*/ 128);
+  memory_mapping.DumpListOfModules(&modules);
+  for (uptr i = 0; i < modules.size(); ++i) {
+    // Even when global scanning is disabled, we still need to scan
+    // system libraries for stashed pointers
+    if (!flags()->use_globals && modules[i].instrumented())
+      continue;
+
+    for (const __sanitizer::LoadedModule::AddressRange &range
+         : modules[i].ranges()) {
+      if (range.executable)
+        continue;
+
+      uptr allocator_begin = 0, allocator_end = 0;
+      GetAllocatorGlobalRange(&allocator_begin, &allocator_end);
+      if (range.beg <= allocator_begin && allocator_begin < range.end) {
+        CHECK_LE(allocator_begin, allocator_end);
+        CHECK_LE(allocator_end, range.end);
+        if (range.beg < allocator_begin)
+          ScanRangeForPointers(range.beg, allocator_begin, frontier, "GLOBAL",
+                               kReachable);
+        if (allocator_end < range.end)
+          ScanRangeForPointers(allocator_end, range.end, frontier, "GLOBAL",
+                               kReachable);
+      } else {
+        ScanRangeForPointers(range.beg, range.end, frontier, "GLOBAL",
+                             kReachable);
+      }
+    }
+  }
 }
 
 void ProcessPlatformSpecificAllocations(Frontier *frontier) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32012.95120.patch
Type: text/x-patch
Size: 1707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170413/d96080ed/attachment.bin>


More information about the llvm-commits mailing list