From 7de60c501cc9e6f85c9332541ede3c8b7f17f293 Mon Sep 17 00:00:00 2001 From: Francis Ricci Date: Mon, 17 Apr 2017 14:07:06 +0000 Subject: [PATCH] Scan Kernel Alloc Once page for global pointers Summary: libxpc stashes some pointers here. Reviewers: kubamracek, alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32045 llvm-svn: 300450 --- compiler-rt/lib/lsan/lsan_common_mac.cc | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/lsan/lsan_common_mac.cc b/compiler-rt/lib/lsan/lsan_common_mac.cc index 022e739..d0ee181 100644 --- a/compiler-rt/lib/lsan/lsan_common_mac.cc +++ b/compiler-rt/lib/lsan/lsan_common_mac.cc @@ -22,6 +22,8 @@ #include +#include + namespace __lsan { typedef struct { @@ -113,8 +115,32 @@ void ProcessGlobalRegions(Frontier *frontier) { } } +// 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) { -- 2.7.4