summaryrefslogtreecommitdiff
path: root/compiler-rt
diff options
context:
space:
mode:
authorFabio D'Urso <fdurso@google.com>2023-05-16 20:07:24 +0000
committerCaslyn Tonelli <caslyn@google.com>2023-05-16 20:09:08 +0000
commit0f1a92ba308a20dd4c790843191e3b642e90a9f3 (patch)
tree71a1a65c803befb9acacb9b97357636bcf766b0e /compiler-rt
parentec388adbbcbf2cf7f2743464ef5b3c5c540a2d23 (diff)
downloadllvm-0f1a92ba308a20dd4c790843191e3b642e90a9f3.tar.gz
[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
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/scudo/standalone/combined.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 006605659bfd..52e2674400fb 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -178,7 +178,7 @@ public:
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 @@ public:
}
void unmapTestOnly() {
+ unmapRingBuffer();
TSDRegistry.unmapTestOnly(this);
Primary.unmapTestOnly();
Secondary.unmapTestOnly();
@@ -1508,17 +1509,16 @@ private:
&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 @@ private:
"invalid alignment");
}
+ void unmapRingBuffer() {
+ unmap(RawRingBuffer, roundUp(getRingBufferSize(), getPageSizeCached()));
+ RawRingBuffer = nullptr;
+ }
+
static constexpr size_t ringBufferSizeInBytes(u32 AllocationRingBufferSize) {
return sizeof(AllocationRingBuffer) +
AllocationRingBufferSize *