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 @@ -228,6 +228,7 @@ } void unmapTestOnly() { + uninitRingBuffer(); TSDRegistry.unmapTestOnly(this); Primary.unmapTestOnly(); Secondary.unmapTestOnly(); @@ -1070,6 +1071,7 @@ // Pointer to memory mapped area starting with AllocationRingBuffer struct, // and immediately followed by Size elements of type Entry. char *RawRingBuffer = {}; + uptr RawRingBufferSize = 0; // The following might get optimized out by the compiler. NOINLINE void performSanityChecks() { @@ -1503,12 +1505,10 @@ static_cast(getFlags()->allocation_ring_buffer_size); if (AllocationRingBufferSize < 1) return; - MapPlatformData Data = {}; + RawRingBufferSize = roundUp(ringBufferSizeInBytes(AllocationRingBufferSize), + getPageSizeCached()); RawRingBuffer = static_cast( - map(/*Addr=*/nullptr, - roundUp(ringBufferSizeInBytes(AllocationRingBufferSize), - getPageSizeCached()), - "AllocatorRingBuffer", /*Flags=*/0, &Data)); + map(/*Addr=*/nullptr, RawRingBufferSize, "AllocatorRingBuffer")); auto *RingBuffer = reinterpret_cast(RawRingBuffer); RingBuffer->Size = AllocationRingBufferSize; static_assert(sizeof(AllocationRingBuffer) % @@ -1517,6 +1517,8 @@ "invalid alignment"); } + void uninitRingBuffer() { unmap(RawRingBuffer, RawRingBufferSize); } + static constexpr size_t ringBufferSizeInBytes(u32 AllocationRingBufferSize) { return sizeof(AllocationRingBuffer) + AllocationRingBufferSize *