[llvm] Implement reserveAllocationSpace for SectionMemoryManager (PR #71968)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 19 19:46:51 PST 2023
================
@@ -18,6 +18,66 @@
namespace llvm {
+static uintptr_t requiredPageSize(uintptr_t Size, uint32_t Alignment) {
+ static const size_t PageSize = sys::Process::getPageSize();
+ // Use the same calculation as allocateSection because we need to be able to
+ // satisfy it.
+ uintptr_t RequiredSize = Alignment * ((Size + Alignment - 1) / Alignment + 1);
+ // Round up to the nearest page size. Blocks must be page-aligned.
+ return PageSize * ((RequiredSize + PageSize - 1) / PageSize);
+}
+
+void SectionMemoryManager::reserveAllocationSpace(
+ uintptr_t CodeSize, uint32_t CodeAlign, uintptr_t RODataSize,
+ uint32_t RODataAlign, uintptr_t RWDataSize, uint32_t RWDataAlign) {
+ if (CodeSize == 0 && RODataSize == 0 && RWDataSize == 0)
+ return;
+
+ // Get space required for each section.
+ CodeAlign = CodeAlign ? CodeAlign : 16;
+ RODataAlign = RODataAlign ? RODataAlign : 16;
+ RWDataAlign = RWDataAlign ? RWDataAlign : 16;
+ uintptr_t RequiredCodeSize = requiredPageSize(CodeSize, CodeAlign);
+ uintptr_t RequiredRODataSize = requiredPageSize(RODataSize, RODataAlign);
+ uintptr_t RequiredRWDataSize = requiredPageSize(RWDataSize, RWDataAlign);
+ uintptr_t RequiredSize =
+ RequiredCodeSize + RequiredRODataSize + RequiredRWDataSize;
+
+ std::error_code ec;
+ sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(
----------------
lhames wrote:
I think it's essential to `SectionMemoryManager` that the actual allocation is done by the mapper. We may have to add a `reserve` to the mapper interface to support this.
As a fallback (since this is opt-in anyway, and will be deprecated in the near future): Could we use a Mapper request for RW- memory?
https://github.com/llvm/llvm-project/pull/71968
More information about the llvm-commits
mailing list