[Support][ORC] Add an explicit release operation to OwningMemoryBlock.
authorLang Hames <lhames@gmail.com>
Tue, 12 Oct 2021 16:48:29 +0000 (09:48 -0700)
committerLang Hames <lhames@gmail.com>
Tue, 12 Oct 2021 17:13:43 +0000 (10:13 -0700)
This gives OwningMemoryBlock clients a way to check for errors on release.

rdar://84127175

llvm/include/llvm/Support/Memory.h
llvm/unittests/ExecutionEngine/Orc/EPCGenericJITLinkMemoryManagerTest.cpp

index a40ca9f..d7d6037 100644 (file)
@@ -148,13 +148,22 @@ namespace sys {
       return *this;
     }
     ~OwningMemoryBlock() {
-      Memory::releaseMappedMemory(M);
+      if (M.base())
+        Memory::releaseMappedMemory(M);
     }
     void *base() const { return M.base(); }
     /// The size as it was allocated. This is always greater or equal to the
     /// size that was originally requested.
     size_t allocatedSize() const { return M.allocatedSize(); }
     MemoryBlock getMemoryBlock() const { return M; }
+    std::error_code release() {
+      std::error_code EC;
+      if (M.base()) {
+        EC = Memory::releaseMappedMemory(M);
+        M = MemoryBlock();
+      }
+      return EC;
+    }
   private:
     MemoryBlock M;
   };
index e7e4e56..f2b157e 100644 (file)
@@ -68,8 +68,7 @@ public:
       }
       auto MB = std::move(I->second);
       Blocks.erase(I);
-      auto MBToRelease = MB.getMemoryBlock();
-      if (auto EC = sys::Memory::releaseMappedMemory(MBToRelease))
+      if (auto EC = MB.release())
         Err = joinErrors(std::move(Err), errorCodeToError(EC));
     }
     return Err;