[compiler-rt] [scudo] Add EnableMultiRegions mode (PR #98076)

Christopher Ferris via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 6 16:33:42 PDT 2024


================
@@ -425,36 +567,54 @@ template <typename Config> class SizeClassAllocator64 {
     for (uptr I = 0; I < NumClasses; I++) {
       if (I == SizeClassMap::BatchClassId)
         continue;
-      RegionInfo *Region = getRegionInfo(I);
-      ScopedLock L(Region->MMLock);
-      TotalReleasedBytes += releaseToOSMaybe(Region, I, ReleaseType);
+      auto RegionInfoIter = RegionInfoManager.getRegionInfoIter(I);
+
+      do {
+        ScopedLock L(RegionInfoIter->MMLock);
+        TotalReleasedBytes +=
+            releaseToOSMaybe(RegionInfoIter.get(), I, ReleaseType);
+        ++RegionInfoIter;
+      } while (!RegionInfoIter.end());
     }
     return TotalReleasedBytes;
   }
 
   const char *getRegionInfoArrayAddress() const {
-    return reinterpret_cast<const char *>(RegionInfoArray);
+    return reinterpret_cast<const char *>(
+        RegionInfoManager.getRawRegionInfoArray());
   }
 
-  static uptr getRegionInfoArraySize() { return sizeof(RegionInfoArray); }
+  uptr getRegionInfoArraySize() {
+    if (Config::getEnableMultiRegions())
+      return 0;
+    return RegionInfoManager.getRawRegionInfoArraySize();
+  }
 
   uptr getCompactPtrBaseByClassId(uptr ClassId) {
-    return getRegionInfo(ClassId)->RegionBeg;
+    return RegionInfoManager.getCurRegionInfo(ClassId)->RegionBeg;
   }
 
   CompactPtrT compactPtr(uptr ClassId, uptr Ptr) {
     DCHECK_LE(ClassId, SizeClassMap::LargestClassId);
+    if (DisablePtrCompaction)
+      return static_cast<CompactPtrT>(Ptr);
     return compactPtrInternal(getCompactPtrBaseByClassId(ClassId), Ptr);
   }
 
   void *decompactPtr(uptr ClassId, CompactPtrT CompactPtr) {
     DCHECK_LE(ClassId, SizeClassMap::LargestClassId);
+    if (DisablePtrCompaction)
+      return reinterpret_cast<void *>(CompactPtr);
     return reinterpret_cast<void *>(
         decompactPtrInternal(getCompactPtrBaseByClassId(ClassId), CompactPtr));
   }
 
   static BlockInfo findNearestBlock(const char *RegionInfoData,
                                     uptr Ptr) NO_THREAD_SAFETY_ANALYSIS {
+    if (Config::getEnableMultiRegions()) {
+      Printf("MultiRegions hasn't supported finding nearest block yet.\n");
----------------
cferris1000 wrote:

hasn't -> doesn't

https://github.com/llvm/llvm-project/pull/98076


More information about the llvm-commits mailing list