[compiler-rt] 0a6aec2 - [NFC][lsan] Change Mac root regions scan
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Sun May 28 22:28:51 PDT 2023
Author: Vitaly Buka
Date: 2023-05-28T22:28:37-07:00
New Revision: 0a6aec2fb3faad9d5d7f9f353606bdfe298209a8
URL: https://github.com/llvm/llvm-project/commit/0a6aec2fb3faad9d5d7f9f353606bdfe298209a8
DIFF: https://github.com/llvm/llvm-project/commit/0a6aec2fb3faad9d5d7f9f353606bdfe298209a8.diff
LOG: [NFC][lsan] Change Mac root regions scan
Added:
Modified:
compiler-rt/lib/lsan/lsan_common.cpp
compiler-rt/lib/lsan/lsan_common.h
compiler-rt/lib/lsan/lsan_common_mac.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp
index 370869731d47..bf40fb584f1f 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -527,8 +527,11 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
# endif // SANITIZER_FUCHSIA
-void ScanRootRegion(Frontier *frontier, const Region &root_region,
- uptr region_begin, uptr region_end, bool is_readable) {
+bool HasRootRegions() { return !root_regions.empty(); }
+
+static void ScanRootRegion(Frontier *frontier, const Region &root_region,
+ uptr region_begin, uptr region_end,
+ bool is_readable) {
uptr intersection_begin = Max(root_region.begin, region_begin);
uptr intersection_end = Min(region_end, root_region.end);
if (intersection_begin >= intersection_end)
@@ -542,6 +545,16 @@ void ScanRootRegion(Frontier *frontier, const Region &root_region,
kReachable);
}
+void ScanRootRegions(Frontier *frontier,
+ const InternalMmapVectorNoCtor<Region> &mapped_regions) {
+ if (!flags()->use_root_regions || mapped_regions.empty())
+ return;
+
+ for (const auto &m : mapped_regions)
+ for (const auto &r : root_regions)
+ ScanRootRegion(frontier, r, m.begin, m.end, true);
+}
+
static void ProcessRootRegion(Frontier *frontier, const Region &root_region) {
MemoryMappingLayout proc_maps(/*cache_enabled*/ true);
MemoryMappedSegment segment;
diff --git a/compiler-rt/lib/lsan/lsan_common.h b/compiler-rt/lib/lsan/lsan_common.h
index bb2ab3cc538a..0ef74bbc1050 100644
--- a/compiler-rt/lib/lsan/lsan_common.h
+++ b/compiler-rt/lib/lsan/lsan_common.h
@@ -256,9 +256,9 @@ struct CheckForLeaksParam {
bool success = false;
};
-InternalMmapVectorNoCtor<Region> const *GetRootRegions();
-void ScanRootRegion(Frontier *frontier, const Region ®ion, uptr region_begin,
- uptr region_end, bool is_readable);
+bool HasRootRegions();
+void ScanRootRegions(Frontier *frontier,
+ const InternalMmapVectorNoCtor<Region> ®ion);
// Run stoptheworld while holding any platform-specific locks, as well as the
// allocator and thread registry locks.
void LockStuffAndStopTheWorld(StopTheWorldCallback callback,
diff --git a/compiler-rt/lib/lsan/lsan_common_mac.cpp b/compiler-rt/lib/lsan/lsan_common_mac.cpp
index 2ed9aadca05f..d6f821fcb1f7 100644
--- a/compiler-rt/lib/lsan/lsan_common_mac.cpp
+++ b/compiler-rt/lib/lsan/lsan_common_mac.cpp
@@ -165,7 +165,8 @@ void ProcessPlatformSpecificAllocations(Frontier *frontier) {
vm_address_t address = 0;
kern_return_t err = KERN_SUCCESS;
- InternalMmapVectorNoCtor<Region> const *root_regions = GetRootRegions();
+ InternalMmapVectorNoCtor<Region> mapped_regions;
+ bool use_root_regions = flags()->use_root_regions && HasRootRegions();
RegionScanState scan_state;
while (err == KERN_SUCCESS) {
@@ -203,8 +204,7 @@ void ProcessPlatformSpecificAllocations(Frontier *frontier) {
// Recursing over the full memory map is very slow, break out
// early if we don't need the full iteration.
- if (scan_state.seen_regions == SeenRegion::All &&
- !(flags()->use_root_regions && root_regions->size() > 0)) {
+ if (scan_state.seen_regions == SeenRegion::All && !use_root_regions) {
break;
}
@@ -215,15 +215,12 @@ void ProcessPlatformSpecificAllocations(Frontier *frontier) {
//
// TODO(fjricci) - remove this once sanitizer_procmaps_mac has the same
// behavior as sanitizer_procmaps_linux and traverses all memory regions
- if (flags()->use_root_regions) {
- for (uptr i = 0; i < root_regions->size(); i++) {
- ScanRootRegion(frontier, (*root_regions)[i], address, end_address,
- info.protection & kProtectionRead);
- }
- }
+ if (use_root_regions && (info.protection & kProtectionRead))
+ mapped_regions.push_back({address, end_address});
address = end_address;
}
+ ScanRootRegions(frontier, mapped_regions);
}
// On darwin, we can intercept _exit gracefully, and return a failing exit code
More information about the llvm-commits
mailing list