[PATCH] D154338: Fix race condition in order-of-destruction between SectionMemoryManager and its MemoryMapper
Stefan Gränitz via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 5 05:49:15 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ce06411994e: [Kaleidoscope] Fix race condition in order-of-destruction between… (authored by sgraenitz).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154338/new/
https://reviews.llvm.org/D154338
Files:
llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
Index: llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
===================================================================
--- llvm/lib/ExecutionEngine/SectionMemoryManager.cpp
+++ 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<DefaultMMapper>();
+ MMapper = OwnedMMapper.get();
+ }
+}
} // namespace llvm
Index: llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
===================================================================
--- llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
+++ llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
@@ -185,7 +185,8 @@
MemoryGroup CodeMem;
MemoryGroup RWDataMem;
MemoryGroup RODataMem;
- MemoryMapper &MMapper;
+ MemoryMapper *MMapper;
+ std::unique_ptr<MemoryMapper> OwnedMMapper;
};
} // end namespace llvm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154338.537324.patch
Type: text/x-patch
Size: 2307 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230705/bbe12a90/attachment.bin>
More information about the llvm-commits
mailing list