[PATCH] D32045: Scan Kernel Alloc Once page for global pointers

Francis Ricci via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 07:20:03 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL300450: Scan Kernel Alloc Once page for global pointers (authored by fjricci).

Changed prior to commit:
  https://reviews.llvm.org/D32045?vs=95204&id=95437#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32045

Files:
  compiler-rt/trunk/lib/lsan/lsan_common_mac.cc


Index: compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
===================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
+++ compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
@@ -22,6 +22,8 @@
 
 #include <pthread.h>
 
+#include <mach/mach.h>
+
 namespace __lsan {
 
 typedef struct {
@@ -113,8 +115,32 @@
   }
 }
 
+// libxpc stashes some pointers in the Kernel Alloc Once page,
+// make sure not to report those as leaks.
 void ProcessPlatformSpecificAllocations(Frontier *frontier) {
-  CHECK(0 && "unimplemented");
+  mach_port_name_t port;
+  if (task_for_pid(mach_task_self(), internal_getpid(), &port)
+      != KERN_SUCCESS) {
+    return;
+  }
+
+  unsigned depth = 1;
+  vm_size_t size = 0;
+  vm_address_t address = 0;
+  kern_return_t err = KERN_SUCCESS;
+  mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT_64;
+
+  while (err == KERN_SUCCESS) {
+    struct vm_region_submap_info_64 info;
+    err = vm_region_recurse_64(port, &address, &size, &depth,
+                               (vm_region_info_t)&info, &count);
+    if (info.user_tag == VM_MEMORY_OS_ALLOC_ONCE) {
+      ScanRangeForPointers(address, address + size, frontier,
+                           "GLOBAL", kReachable);
+      return;
+    }
+    address += size;
+  }
 }
 
 void DoStopTheWorld(StopTheWorldCallback callback, void *argument) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32045.95437.patch
Type: text/x-patch
Size: 1377 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170417/61226b81/attachment.bin>


More information about the llvm-commits mailing list