[compiler-rt] [scudo] Use MemMap in BufferPool and RegionPageMap (PR #66788)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 27 14:56:57 PDT 2023
================
@@ -130,53 +143,33 @@ class BufferPool {
if (index >= StaticBufferCount)
return getDynamicBuffer(NumElements);
- const uptr Offset = index * StaticBufferNumElements;
- memset(&RawBuffer[Offset], 0, StaticBufferNumElements * sizeof(uptr));
- return &RawBuffer[Offset];
+ Buffer Buf;
+ Buf.Data = &RawBuffer[index * StaticBufferNumElements];
+ Buf.BufferIndex = index;
+ memset(Buf.Data, 0, StaticBufferNumElements * sizeof(uptr));
+ return Buf;
}
- void releaseBuffer(uptr *Buffer, const uptr NumElements) {
- const uptr index = getStaticBufferIndex(Buffer, NumElements);
- if (index < StaticBufferCount) {
+ void releaseBuffer(Buffer Buf) {
+ DCHECK(Buf.Data != nullptr);
+ DCHECK_LE(Buf.BufferIndex, StaticBufferCount);
+ if (Buf.BufferIndex != StaticBufferCount) {
ScopedLock L(Mutex);
- DCHECK_EQ((Mask & (static_cast<uptr>(1) << index)), 0U);
- Mask |= static_cast<uptr>(1) << index;
+ DCHECK_EQ((Mask & (static_cast<uptr>(1) << Buf.BufferIndex)), 0U);
+ Mask |= static_cast<uptr>(1) << Buf.BufferIndex;
} else {
- const uptr MappedSize =
- roundUp(NumElements * sizeof(uptr), getPageSizeCached());
- unmap(reinterpret_cast<void *>(Buffer), MappedSize);
+ Buf.MemMap.unmap(Buf.MemMap.getBase(), Buf.MemMap.getCapacity());
}
}
- bool isStaticBufferTestOnly(uptr *Buffer, uptr NumElements) {
- return getStaticBufferIndex(Buffer, NumElements) < StaticBufferCount;
+ bool isStaticBufferTestOnly(const Buffer &Buf) {
+ DCHECK(Buf.Data != nullptr);
----------------
ChiaHungDuan wrote:
DCHECK_NE(Buf.Data, nullptr)
https://github.com/llvm/llvm-project/pull/66788
More information about the llvm-commits
mailing list