From 1134d3a03facccd75efc5385ba46918bef94fcb6 Mon Sep 17 00:00:00 2001 From: Anubhab Ghosh Date: Sun, 21 Aug 2022 01:30:15 +0530 Subject: [PATCH] [Orc] Only unmap shared memory in controller process destructor By the time SharedMemoryMapper destructor is called, the RPC connection is no longer available causing the release() call to always fail. Instead at this point only shared memory regions can be unmapped safely. Deinitializers are called and mapped memory is released at the executor side by ExecutorSharedMemoryMapperService::shutdown() instead. Memory can also be released earlier by calling release() earlier before RPC connection is closed. Differential Revision: https://reviews.llvm.org/D132313 --- llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp | 28 ++++++++++++--------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp index 1e8ad27..734b5f0 100644 --- a/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp +++ b/llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp @@ -407,23 +407,19 @@ void SharedMemoryMapper::release(ArrayRef Bases, } SharedMemoryMapper::~SharedMemoryMapper() { - std::vector ReservationAddrs; - if (!Reservations.empty()) { - std::lock_guard Lock(Mutex); - { - ReservationAddrs.reserve(Reservations.size()); - for (const auto &R : Reservations) { - ReservationAddrs.push_back(R.first); - } - } - } + for (const auto R : Reservations) { - std::promise P; - auto F = P.get_future(); - release(ReservationAddrs, [&](Error Err) { P.set_value(std::move(Err)); }); - // FIXME: Release can actually fail. The error should be propagated. - // Meanwhile, a better option is to explicitly call release(). - cantFail(F.get()); +#if defined(LLVM_ON_UNIX) && !defined(__ANDROID__) + + munmap(R.second.LocalAddr, R.second.Size); + +#elif defined(_WIN32) + + UnmapViewOfFile(R.second.LocalAddr); + +#endif + + } } } // namespace orc -- 2.7.4