[compiler-rt] 1068cf7 - [NFC][lsan] Rename RootRegion and replace size with end

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Sun May 28 21:21:37 PDT 2023


Author: Vitaly Buka
Date: 2023-05-28T21:21:26-07:00
New Revision: 1068cf787e347dcaa6c155f6d2ebefcca326241a

URL: https://github.com/llvm/llvm-project/commit/1068cf787e347dcaa6c155f6d2ebefcca326241a
DIFF: https://github.com/llvm/llvm-project/commit/1068cf787e347dcaa6c155f6d2ebefcca326241a.diff

LOG: [NFC][lsan] Rename RootRegion and replace size with end

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 ae29e4a21fd19..21430e39e069a 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -241,9 +241,9 @@ static LeakSuppressionContext *GetSuppressionContext() {
   return suppression_ctx;
 }
 
-static InternalMmapVectorNoCtor<RootRegion> root_regions;
+static InternalMmapVectorNoCtor<Region> root_regions;
 
-InternalMmapVectorNoCtor<RootRegion> const *GetRootRegions() {
+InternalMmapVectorNoCtor<Region> const *GetRootRegions() {
   return &root_regions;
 }
 
@@ -527,15 +527,14 @@ static void ProcessThreads(SuspendedThreadsList const &suspended_threads,
 
 #  endif  // SANITIZER_FUCHSIA
 
-void ScanRootRegion(Frontier *frontier, const RootRegion &root_region,
+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.begin + root_region.size);
+  uptr intersection_end = Min(region_end, root_region.end);
   if (intersection_begin >= intersection_end)
     return;
   LOG_POINTERS("Root region %p-%p intersects with mapped region %p-%p (%s)\n",
-               (void *)root_region.begin,
-               (void *)(root_region.begin + root_region.size),
+               (void *)root_region.begin, (void *)root_region.end,
                (void *)region_begin, (void *)region_end,
                is_readable ? "readable" : "unreadable");
   if (is_readable)
@@ -543,8 +542,7 @@ void ScanRootRegion(Frontier *frontier, const RootRegion &root_region,
                          kReachable);
 }
 
-static void ProcessRootRegion(Frontier *frontier,
-                              const RootRegion &root_region) {
+static void ProcessRootRegion(Frontier *frontier, const Region &root_region) {
   MemoryMappingLayout proc_maps(/*cache_enabled*/ true);
   MemoryMappedSegment segment;
   while (proc_maps.Next(&segment)) {
@@ -1014,7 +1012,8 @@ SANITIZER_INTERFACE_ATTRIBUTE
 void __lsan_register_root_region(const void *begin, uptr size) {
 #if CAN_SANITIZE_LEAKS
   Lock l(&global_mutex);
-  RootRegion region = {reinterpret_cast<uptr>(begin), size};
+  Region region = {reinterpret_cast<uptr>(begin),
+                   reinterpret_cast<uptr>(begin) + size};
   root_regions.push_back(region);
   VReport(1, "Registered root region at %p of size %zu\n", begin, size);
 #endif  // CAN_SANITIZE_LEAKS
@@ -1025,9 +1024,10 @@ void __lsan_unregister_root_region(const void *begin, uptr size) {
 #if CAN_SANITIZE_LEAKS
   Lock l(&global_mutex);
   bool removed = false;
+  uptr end = reinterpret_cast<uptr>(begin) + size;
   for (uptr i = 0; i < root_regions.size(); i++) {
-    RootRegion region = root_regions[i];
-    if (region.begin == reinterpret_cast<uptr>(begin) && region.size == size) {
+    Region region = root_regions[i];
+    if (region.begin == reinterpret_cast<uptr>(begin) && region.end == end) {
       removed = true;
       uptr last_index = root_regions.size() - 1;
       root_regions[i] = root_regions[last_index];

diff  --git a/compiler-rt/lib/lsan/lsan_common.h b/compiler-rt/lib/lsan/lsan_common.h
index 2c49bb6500967..bb2ab3cc538a1 100644
--- a/compiler-rt/lib/lsan/lsan_common.h
+++ b/compiler-rt/lib/lsan/lsan_common.h
@@ -239,9 +239,9 @@ void InitializePlatformSpecificModules();
 void ProcessGlobalRegions(Frontier *frontier);
 void ProcessPlatformSpecificAllocations(Frontier *frontier);
 
-struct RootRegion {
+struct Region {
   uptr begin;
-  uptr size;
+  uptr end;
 };
 
 // LockStuffAndStopTheWorld can start to use Scan* calls to collect into
@@ -256,9 +256,9 @@ struct CheckForLeaksParam {
   bool success = false;
 };
 
-InternalMmapVectorNoCtor<RootRegion> const *GetRootRegions();
-void ScanRootRegion(Frontier *frontier, RootRegion const &region,
-                    uptr region_begin, uptr region_end, bool is_readable);
+InternalMmapVectorNoCtor<Region> const *GetRootRegions();
+void ScanRootRegion(Frontier *frontier, const Region &region, uptr region_begin,
+                    uptr region_end, bool is_readable);
 // 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 9ccf098a65675..2ed9aadca05f8 100644
--- a/compiler-rt/lib/lsan/lsan_common_mac.cpp
+++ b/compiler-rt/lib/lsan/lsan_common_mac.cpp
@@ -165,7 +165,7 @@ void ProcessPlatformSpecificAllocations(Frontier *frontier) {
   vm_address_t address = 0;
   kern_return_t err = KERN_SUCCESS;
 
-  InternalMmapVectorNoCtor<RootRegion> const *root_regions = GetRootRegions();
+  InternalMmapVectorNoCtor<Region> const *root_regions = GetRootRegions();
 
   RegionScanState scan_state;
   while (err == KERN_SUCCESS) {


        


More information about the llvm-commits mailing list