Skip to content

Commit 0f1a92b

Browse files
fabio-dCaslyn
authored andcommitted
[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
1 parent ec388ad commit 0f1a92b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

compiler-rt/lib/scudo/standalone/combined.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class Allocator {
178178
static_cast<uptr>(getFlags()->quarantine_size_kb << 10),
179179
static_cast<uptr>(getFlags()->thread_local_quarantine_size_kb << 10));
180180

181-
initRingBuffer();
181+
mapAndInitializeRingBuffer();
182182
}
183183

184184
// Initialize the embedded GWP-ASan instance. Requires the main allocator to
@@ -228,6 +228,7 @@ class Allocator {
228228
}
229229

230230
void unmapTestOnly() {
231+
unmapRingBuffer();
231232
TSDRegistry.unmapTestOnly(this);
232233
Primary.unmapTestOnly();
233234
Secondary.unmapTestOnly();
@@ -1508,17 +1509,16 @@ class Allocator {
15081509
&RawRingBuffer[sizeof(AllocationRingBuffer)])[N];
15091510
}
15101511

1511-
void initRingBuffer() {
1512+
void mapAndInitializeRingBuffer() {
15121513
u32 AllocationRingBufferSize =
15131514
static_cast<u32>(getFlags()->allocation_ring_buffer_size);
15141515
if (AllocationRingBufferSize < 1)
15151516
return;
1516-
MapPlatformData Data = {};
15171517
RawRingBuffer = static_cast<char *>(
15181518
map(/*Addr=*/nullptr,
15191519
roundUp(ringBufferSizeInBytes(AllocationRingBufferSize),
15201520
getPageSizeCached()),
1521-
"AllocatorRingBuffer", /*Flags=*/0, &Data));
1521+
"AllocatorRingBuffer"));
15221522
auto *RingBuffer = reinterpret_cast<AllocationRingBuffer *>(RawRingBuffer);
15231523
RingBuffer->Size = AllocationRingBufferSize;
15241524
static_assert(sizeof(AllocationRingBuffer) %
@@ -1527,6 +1527,11 @@ class Allocator {
15271527
"invalid alignment");
15281528
}
15291529

1530+
void unmapRingBuffer() {
1531+
unmap(RawRingBuffer, roundUp(getRingBufferSize(), getPageSizeCached()));
1532+
RawRingBuffer = nullptr;
1533+
}
1534+
15301535
static constexpr size_t ringBufferSizeInBytes(u32 AllocationRingBufferSize) {
15311536
return sizeof(AllocationRingBuffer) +
15321537
AllocationRingBufferSize *

0 commit comments

Comments
 (0)