diff --git a/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h b/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h --- a/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h +++ b/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h @@ -185,7 +185,8 @@ MemoryGroup CodeMem; MemoryGroup RWDataMem; MemoryGroup RODataMem; - MemoryMapper &MMapper; + MemoryMapper *MMapper; + std::unique_ptr OwnedMMapper; }; } // end namespace llvm diff --git a/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp b/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp --- a/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp +++ b/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp @@ -101,7 +101,7 @@ // FIXME: Initialize the Near member for each memory group to avoid // interleaving. std::error_code ec; - sys::MemoryBlock MB = MMapper.allocateMappedMemory( + sys::MemoryBlock MB = MMapper->allocateMappedMemory( Purpose, RequiredSize, &MemGroup.Near, sys::Memory::MF_READ | sys::Memory::MF_WRITE, ec); if (ec) { @@ -204,7 +204,7 @@ SectionMemoryManager::applyMemoryGroupPermissions(MemoryGroup &MemGroup, unsigned Permissions) { for (sys::MemoryBlock &MB : MemGroup.PendingMem) - if (std::error_code EC = MMapper.protectMappedMemory(MB, Permissions)) + if (std::error_code EC = MMapper->protectMappedMemory(MB, Permissions)) return EC; MemGroup.PendingMem.clear(); @@ -234,7 +234,7 @@ SectionMemoryManager::~SectionMemoryManager() { for (MemoryGroup *Group : {&CodeMem, &RWDataMem, &RODataMem}) { for (sys::MemoryBlock &Block : Group->AllocatedMem) - MMapper.releaseMappedMemory(Block); + MMapper->releaseMappedMemory(Block); } } @@ -263,11 +263,14 @@ return sys::Memory::releaseMappedMemory(M); } }; - -DefaultMMapper DefaultMMapperInstance; } // namespace -SectionMemoryManager::SectionMemoryManager(MemoryMapper *MM) - : MMapper(MM ? *MM : DefaultMMapperInstance) {} +SectionMemoryManager::SectionMemoryManager(MemoryMapper *UnownedMM) + : MMapper(UnownedMM), OwnedMMapper(nullptr) { + if (!MMapper) { + OwnedMMapper = std::make_unique(); + MMapper = OwnedMMapper.get(); + } +} } // namespace llvm