Skip to content

Commit

Permalink
[scudo] Use MemMap for AllocationRingBuffer
Browse files Browse the repository at this point in the history
Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D159466
  • Loading branch information
fabio-d committed Sep 26, 2023
1 parent d85d143 commit 4206925
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions compiler-rt/lib/scudo/standalone/combined.h
Expand Up @@ -1044,6 +1044,7 @@ class Allocator {
atomic_u32 DeallocationTid;
};

MemMapT MemMap;
atomic_uptr Pos;
u32 Size;
// An array of Size (at least one) elements of type Entry is immediately
Expand Down Expand Up @@ -1492,12 +1493,15 @@ class Allocator {
static_cast<u32>(getFlags()->allocation_ring_buffer_size);
if (AllocationRingBufferSize < 1)
return;
RawRingBuffer = static_cast<char *>(
map(/*Addr=*/nullptr,
roundUp(ringBufferSizeInBytes(AllocationRingBufferSize),
getPageSizeCached()),
"scudo:ring_buffer"));
MemMapT MemMap;
MemMap.map(
/*Addr=*/0U,
roundUp(ringBufferSizeInBytes(AllocationRingBufferSize),
getPageSizeCached()),
"scudo:ring_buffer");
RawRingBuffer = reinterpret_cast<char *>(MemMap.getBase());
auto *RingBuffer = reinterpret_cast<AllocationRingBuffer *>(RawRingBuffer);
RingBuffer->MemMap = MemMap;
RingBuffer->Size = AllocationRingBufferSize;
static_assert(sizeof(AllocationRingBuffer) %
alignof(typename AllocationRingBuffer::Entry) ==
Expand All @@ -1506,7 +1510,11 @@ class Allocator {
}

void unmapRingBuffer() {
unmap(RawRingBuffer, roundUp(getRingBufferSize(), getPageSizeCached()));
auto *RingBuffer = getRingBuffer();
if (RingBuffer != nullptr) {
MemMapT MemMap = RingBuffer->MemMap;
MemMap.unmap(MemMap.getBase(), MemMap.getCapacity());
}
RawRingBuffer = nullptr;
}

Expand Down

0 comments on commit 4206925

Please sign in to comment.