@@ -79,6 +79,10 @@ struct CachedBlock {
79
79
uptr BlockBegin = 0 ;
80
80
MemMapT MemMap = {};
81
81
u64 Time = 0 ;
82
+
83
+ bool isValid () { return CommitBase != 0 ; }
84
+
85
+ void invalidate () { CommitBase = 0 ; }
82
86
};
83
87
} // namespace
84
88
@@ -152,7 +156,7 @@ template <typename Config> class MapAllocatorCache {
152
156
EntriesCount, atomic_load_relaxed (&MaxEntriesCount),
153
157
atomic_load_relaxed (&MaxEntrySize));
154
158
for (CachedBlock Entry : Entries) {
155
- if (!Entry.CommitBase )
159
+ if (!Entry.isValid () )
156
160
continue ;
157
161
Str->append (" StartBlockAddress: 0x%zx, EndBlockAddress: 0x%zx, "
158
162
" BlockSize: %zu\n " ,
@@ -219,7 +223,7 @@ template <typename Config> class MapAllocatorCache {
219
223
if (CacheConfig::QuarantineSize && useMemoryTagging<Config>(Options)) {
220
224
QuarantinePos =
221
225
(QuarantinePos + 1 ) % Max (CacheConfig::QuarantineSize, 1u );
222
- if (!Quarantine[QuarantinePos].CommitBase ) {
226
+ if (!Quarantine[QuarantinePos].isValid () ) {
223
227
Quarantine[QuarantinePos] = Entry;
224
228
return ;
225
229
}
@@ -234,7 +238,7 @@ template <typename Config> class MapAllocatorCache {
234
238
EmptyCache = true ;
235
239
} else {
236
240
for (u32 I = 0 ; I < MaxCount; I++) {
237
- if (Entries[I].CommitBase )
241
+ if (Entries[I].isValid () )
238
242
continue ;
239
243
if (I != 0 )
240
244
Entries[I] = Entries[0 ];
@@ -263,13 +267,13 @@ template <typename Config> class MapAllocatorCache {
263
267
if (EntriesCount == 0 )
264
268
return false ;
265
269
for (u32 I = 0 ; I < MaxCount; I++) {
266
- if (!Entries[I].CommitBase )
270
+ if (!Entries[I].isValid () )
267
271
continue ;
268
272
if (Size > Entries[I].CommitSize )
269
273
continue ;
270
274
Found = true ;
271
275
Entry = Entries[I];
272
- Entries[I].CommitBase = 0 ;
276
+ Entries[I].invalidate () ;
273
277
EntriesCount--;
274
278
break ;
275
279
}
@@ -310,15 +314,15 @@ template <typename Config> class MapAllocatorCache {
310
314
void disableMemoryTagging () EXCLUDES(Mutex) {
311
315
ScopedLock L (Mutex);
312
316
for (u32 I = 0 ; I != CacheConfig::QuarantineSize; ++I) {
313
- if (Quarantine[I].CommitBase ) {
317
+ if (Quarantine[I].isValid () ) {
314
318
MemMapT &MemMap = Quarantine[I].MemMap ;
315
319
MemMap.unmap (MemMap.getBase (), MemMap.getCapacity ());
316
- Quarantine[I].CommitBase = 0 ;
320
+ Quarantine[I].invalidate () ;
317
321
}
318
322
}
319
323
const u32 MaxCount = atomic_load_relaxed (&MaxEntriesCount);
320
324
for (u32 I = 0 ; I < MaxCount; I++) {
321
- if (Entries[I].CommitBase ) {
325
+ if (Entries[I].isValid () ) {
322
326
Entries[I].MemMap .setMemoryPermission (Entries[I].CommitBase ,
323
327
Entries[I].CommitSize , 0 );
324
328
}
@@ -339,10 +343,10 @@ template <typename Config> class MapAllocatorCache {
339
343
{
340
344
ScopedLock L (Mutex);
341
345
for (uptr I = 0 ; I < CacheConfig::EntriesArraySize; I++) {
342
- if (!Entries[I].CommitBase )
346
+ if (!Entries[I].isValid () )
343
347
continue ;
344
348
MapInfo[N] = Entries[I].MemMap ;
345
- Entries[I].CommitBase = 0 ;
349
+ Entries[I].invalidate () ;
346
350
N++;
347
351
}
348
352
EntriesCount = 0 ;
@@ -355,7 +359,7 @@ template <typename Config> class MapAllocatorCache {
355
359
}
356
360
357
361
void releaseIfOlderThan (CachedBlock &Entry, u64 Time) REQUIRES(Mutex) {
358
- if (!Entry.CommitBase || !Entry.Time )
362
+ if (!Entry.isValid () || !Entry.Time )
359
363
return ;
360
364
if (Entry.Time > Time) {
361
365
if (OldestTime == 0 || Entry.Time < OldestTime)
0 commit comments