Index: compiler-rt/lib/scudo/standalone/combined.h =================================================================== --- compiler-rt/lib/scudo/standalone/combined.h +++ compiler-rt/lib/scudo/standalone/combined.h @@ -1035,6 +1035,8 @@ StackDepot Depot; struct AllocationRingBuffer { + MemMapT MemMap; + struct Entry { atomic_uptr Ptr; atomic_uptr AllocationSize; @@ -1492,12 +1494,15 @@ static_cast(getFlags()->allocation_ring_buffer_size); if (AllocationRingBufferSize < 1) return; - RawRingBuffer = static_cast( - map(/*Addr=*/nullptr, - roundUp(ringBufferSizeInBytes(AllocationRingBufferSize), - getPageSizeCached()), - "scudo:ring_buffer")); + MemMapT MemMap; + MemMap.map( + /*Addr=*/0U, + roundUp(ringBufferSizeInBytes(AllocationRingBufferSize), + getPageSizeCached()), + "scudo:ring_buffer"); + RawRingBuffer = reinterpret_cast(MemMap.getBase()); auto *RingBuffer = reinterpret_cast(RawRingBuffer); + RingBuffer->MemMap = MemMap; RingBuffer->Size = AllocationRingBufferSize; static_assert(sizeof(AllocationRingBuffer) % alignof(typename AllocationRingBuffer::Entry) == @@ -1506,7 +1511,11 @@ } void unmapRingBuffer() { - unmap(RawRingBuffer, roundUp(getRingBufferSize(), getPageSizeCached())); + auto *RingBuffer = getRingBuffer(); + if (RingBuffer != nullptr) { + MemMapT MemMap = RingBuffer->MemMap; + MemMap.unmap(MemMap.getBase(), MemMap.getCapacity()); + } RawRingBuffer = nullptr; }