[scudo] Deallocate the AllocatorRingBuffer too in unmapTestOnly
The AllocatorRingBuffer is allocated dynamically when Allocator is
initialized. This patch adds a corresponding deinitialization call in
unmapTestOnly, to avoid running out of virtual memory if the tests are run
a large number of times on memory-constrained platforms.
Reviewed By: Chia-hungDuan
Differential Revision: https://reviews.llvm.org/D149266
GitOrigin-RevId: 0f1a92ba308a20dd4c790843191e3b642e90a9f3
diff --git a/combined.h b/combined.h
index 0066056..52e2674 100644
--- a/combined.h
+++ b/combined.h
@@ -178,7 +178,7 @@
static_cast<uptr>(getFlags()->quarantine_size_kb << 10),
static_cast<uptr>(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<u32>(getFlags()->allocation_ring_buffer_size);
if (AllocationRingBufferSize < 1)
return;
- MapPlatformData Data = {};
RawRingBuffer = static_cast<char *>(
map(/*Addr=*/nullptr,
roundUp(ringBufferSizeInBytes(AllocationRingBufferSize),
getPageSizeCached()),
- "AllocatorRingBuffer", /*Flags=*/0, &Data));
+ "AllocatorRingBuffer"));
auto *RingBuffer = reinterpret_cast<AllocationRingBuffer *>(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 *