diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp index 1ca0375b8a54c0..04d4c2829a5409 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.cpp @@ -15,4 +15,21 @@ namespace __sanitizer { PersistentAllocator thePersistentAllocator; +void *PersistentAllocator::refillAndAlloc(uptr size) { + // If failed, lock, retry and alloc new superblock. + SpinMutexLock l(&mtx); + for (;;) { + void *s = tryAlloc(size); + if (s) + return s; + atomic_store(®ion_pos, 0, memory_order_relaxed); + uptr allocsz = 64 * 1024; + if (allocsz < size) + allocsz = size; + uptr mem = (uptr)MmapOrDie(allocsz, "stack depot"); + atomic_store(®ion_end, mem + allocsz, memory_order_release); + atomic_store(®ion_pos, mem, memory_order_release); + } +} + } // namespace __sanitizer diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h b/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h index de4fb6ebc3cf87..ae3a023d0786c1 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_persistent_allocator.h @@ -26,6 +26,7 @@ class PersistentAllocator { private: void *tryAlloc(uptr size); + void *refillAndAlloc(uptr size); StaticSpinMutex mtx; // Protects alloc of new blocks for region allocator. atomic_uintptr_t region_pos; // Region allocator for Node's. atomic_uintptr_t region_end; @@ -47,18 +48,7 @@ inline void *PersistentAllocator::alloc(uptr size) { // First, try to allocate optimisitically. void *s = tryAlloc(size); if (s) return s; - // If failed, lock, retry and alloc new superblock. - SpinMutexLock l(&mtx); - for (;;) { - s = tryAlloc(size); - if (s) return s; - atomic_store(®ion_pos, 0, memory_order_relaxed); - uptr allocsz = 64 * 1024; - if (allocsz < size) allocsz = size; - uptr mem = (uptr)MmapOrDie(allocsz, "stack depot"); - atomic_store(®ion_end, mem + allocsz, memory_order_release); - atomic_store(®ion_pos, mem, memory_order_release); - } + return refillAndAlloc(size); } extern PersistentAllocator thePersistentAllocator;