diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h --- a/compiler-rt/lib/scudo/standalone/combined.h +++ b/compiler-rt/lib/scudo/standalone/combined.h @@ -178,7 +178,7 @@ static_cast(getFlags()->quarantine_size_kb << 10), static_cast(getFlags()->thread_local_quarantine_size_kb << 10)); - initRingBuffer(); + mapAndInitializeRingBuffer(); } // Initialize the embedded GWP-ASan instance. Requires the main allocator to @@ -228,6 +228,7 @@ } void unmapTestOnly() { + unmapRingBuffer(); TSDRegistry.unmapTestOnly(this); Primary.unmapTestOnly(); Secondary.unmapTestOnly(); @@ -1508,17 +1509,16 @@ &RawRingBuffer[sizeof(AllocationRingBuffer)])[N]; } - void initRingBuffer() { + void mapAndInitializeRingBuffer() { u32 AllocationRingBufferSize = static_cast(getFlags()->allocation_ring_buffer_size); if (AllocationRingBufferSize < 1) return; - MapPlatformData Data = {}; RawRingBuffer = static_cast( map(/*Addr=*/nullptr, roundUp(ringBufferSizeInBytes(AllocationRingBufferSize), getPageSizeCached()), - "AllocatorRingBuffer", /*Flags=*/0, &Data)); + "AllocatorRingBuffer")); auto *RingBuffer = reinterpret_cast(RawRingBuffer); RingBuffer->Size = AllocationRingBufferSize; static_assert(sizeof(AllocationRingBuffer) % @@ -1527,6 +1527,11 @@ "invalid alignment"); } + void unmapRingBuffer() { + unmap(RawRingBuffer, roundUp(getRingBufferSize(), getPageSizeCached())); + RawRingBuffer = nullptr; + } + static constexpr size_t ringBufferSizeInBytes(u32 AllocationRingBufferSize) { return sizeof(AllocationRingBuffer) + AllocationRingBufferSize *