[compiler-rt] a0b9f1f - [scudo] set/check invalid cache entries

Chia-hung Duan via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 25 12:28:02 PDT 2023


Author: Fernando
Date: 2023-07-25T19:26:32Z
New Revision: a0b9f1f84b33b9546795697b1fbce2951acdc81a

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

LOG: [scudo] set/check invalid cache entries

made checking for invalid cache entries and setting invalid cache
entries more implicit and clear.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D155983

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/secondary.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index dbb6006acbbb7d..99b486c16b036b 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -79,6 +79,10 @@ struct CachedBlock {
   uptr BlockBegin = 0;
   MemMapT MemMap = {};
   u64 Time = 0;
+
+  bool isValid() { return CommitBase != 0; }
+
+  void invalidate() { CommitBase = 0; }
 };
 } // namespace
 
@@ -152,7 +156,7 @@ template <typename Config> class MapAllocatorCache {
                 EntriesCount, atomic_load_relaxed(&MaxEntriesCount),
                 atomic_load_relaxed(&MaxEntrySize));
     for (CachedBlock Entry : Entries) {
-      if (!Entry.CommitBase)
+      if (!Entry.isValid())
         continue;
       Str->append("StartBlockAddress: 0x%zx, EndBlockAddress: 0x%zx, "
                   "BlockSize: %zu\n",
@@ -219,7 +223,7 @@ template <typename Config> class MapAllocatorCache {
       if (CacheConfig::QuarantineSize && useMemoryTagging<Config>(Options)) {
         QuarantinePos =
             (QuarantinePos + 1) % Max(CacheConfig::QuarantineSize, 1u);
-        if (!Quarantine[QuarantinePos].CommitBase) {
+        if (!Quarantine[QuarantinePos].isValid()) {
           Quarantine[QuarantinePos] = Entry;
           return;
         }
@@ -234,7 +238,7 @@ template <typename Config> class MapAllocatorCache {
           EmptyCache = true;
       } else {
         for (u32 I = 0; I < MaxCount; I++) {
-          if (Entries[I].CommitBase)
+          if (Entries[I].isValid())
             continue;
           if (I != 0)
             Entries[I] = Entries[0];
@@ -263,13 +267,13 @@ template <typename Config> class MapAllocatorCache {
       if (EntriesCount == 0)
         return false;
       for (u32 I = 0; I < MaxCount; I++) {
-        if (!Entries[I].CommitBase)
+        if (!Entries[I].isValid())
           continue;
         if (Size > Entries[I].CommitSize)
           continue;
         Found = true;
         Entry = Entries[I];
-        Entries[I].CommitBase = 0;
+        Entries[I].invalidate();
         EntriesCount--;
         break;
       }
@@ -310,15 +314,15 @@ template <typename Config> class MapAllocatorCache {
   void disableMemoryTagging() EXCLUDES(Mutex) {
     ScopedLock L(Mutex);
     for (u32 I = 0; I != CacheConfig::QuarantineSize; ++I) {
-      if (Quarantine[I].CommitBase) {
+      if (Quarantine[I].isValid()) {
         MemMapT &MemMap = Quarantine[I].MemMap;
         MemMap.unmap(MemMap.getBase(), MemMap.getCapacity());
-        Quarantine[I].CommitBase = 0;
+        Quarantine[I].invalidate();
       }
     }
     const u32 MaxCount = atomic_load_relaxed(&MaxEntriesCount);
     for (u32 I = 0; I < MaxCount; I++) {
-      if (Entries[I].CommitBase) {
+      if (Entries[I].isValid()) {
         Entries[I].MemMap.setMemoryPermission(Entries[I].CommitBase,
                                               Entries[I].CommitSize, 0);
       }
@@ -339,10 +343,10 @@ template <typename Config> class MapAllocatorCache {
     {
       ScopedLock L(Mutex);
       for (uptr I = 0; I < CacheConfig::EntriesArraySize; I++) {
-        if (!Entries[I].CommitBase)
+        if (!Entries[I].isValid())
           continue;
         MapInfo[N] = Entries[I].MemMap;
-        Entries[I].CommitBase = 0;
+        Entries[I].invalidate();
         N++;
       }
       EntriesCount = 0;
@@ -355,7 +359,7 @@ template <typename Config> class MapAllocatorCache {
   }
 
   void releaseIfOlderThan(CachedBlock &Entry, u64 Time) REQUIRES(Mutex) {
-    if (!Entry.CommitBase || !Entry.Time)
+    if (!Entry.isValid() || !Entry.Time)
       return;
     if (Entry.Time > Time) {
       if (OldestTime == 0 || Entry.Time < OldestTime)


        


More information about the llvm-commits mailing list