Skip to content

Commit 4206925

Browse files
committed
[scudo] Use MemMap for AllocationRingBuffer
Reviewed By: Chia-hungDuan Differential Revision: https://reviews.llvm.org/D159466
1 parent d85d143 commit 4206925

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,7 @@ class Allocator {
10441044
atomic_u32 DeallocationTid;
10451045
};
10461046

1047+
MemMapT MemMap;
10471048
atomic_uptr Pos;
10481049
u32 Size;
10491050
// An array of Size (at least one) elements of type Entry is immediately
@@ -1492,12 +1493,15 @@ class Allocator {
14921493
static_cast<u32>(getFlags()->allocation_ring_buffer_size);
14931494
if (AllocationRingBufferSize < 1)
14941495
return;
1495-
RawRingBuffer = static_cast<char *>(
1496-
map(/*Addr=*/nullptr,
1497-
roundUp(ringBufferSizeInBytes(AllocationRingBufferSize),
1498-
getPageSizeCached()),
1499-
"scudo:ring_buffer"));
1496+
MemMapT MemMap;
1497+
MemMap.map(
1498+
/*Addr=*/0U,
1499+
roundUp(ringBufferSizeInBytes(AllocationRingBufferSize),
1500+
getPageSizeCached()),
1501+
"scudo:ring_buffer");
1502+
RawRingBuffer = reinterpret_cast<char *>(MemMap.getBase());
15001503
auto *RingBuffer = reinterpret_cast<AllocationRingBuffer *>(RawRingBuffer);
1504+
RingBuffer->MemMap = MemMap;
15011505
RingBuffer->Size = AllocationRingBufferSize;
15021506
static_assert(sizeof(AllocationRingBuffer) %
15031507
alignof(typename AllocationRingBuffer::Entry) ==
@@ -1506,7 +1510,11 @@ class Allocator {
15061510
}
15071511

15081512
void unmapRingBuffer() {
1509-
unmap(RawRingBuffer, roundUp(getRingBufferSize(), getPageSizeCached()));
1513+
auto *RingBuffer = getRingBuffer();
1514+
if (RingBuffer != nullptr) {
1515+
MemMapT MemMap = RingBuffer->MemMap;
1516+
MemMap.unmap(MemMap.getBase(), MemMap.getCapacity());
1517+
}
15101518
RawRingBuffer = nullptr;
15111519
}
15121520

0 commit comments

Comments
 (0)