From 34a1c8e545923403074b41e1e1abfdabe478310b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 25 Nov 2018 22:10:34 +0100 Subject: [PATCH] - delete JIT data when shutting down. --- src/scripting/vm/jit.cpp | 17 +++++++++++++++++ src/scripting/vm/vm.h | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/src/scripting/vm/jit.cpp b/src/scripting/vm/jit.cpp index d80485fcb..74e14a80f 100644 --- a/src/scripting/vm/jit.cpp +++ b/src/scripting/vm/jit.cpp @@ -9,6 +9,7 @@ extern PStruct *TypeVector3; static void OutputJitLog(const asmjit::StringLogger &logger); static TArray JitBlocks; +static TArray JitFrames; static size_t JitBlockPos = 0; static size_t JitBlockSize = 0; @@ -61,6 +62,21 @@ static void *AllocJitMemory(size_t size) #define UWOP_SAVE_XMM128_FAR 9 #define UWOP_PUSH_MACHFRAME 10 + +void JitRelease() +{ +#ifdef _WIN64 + for (auto p : JitFrames) + { + RtlDeleteFunctionTable((PRUNTIME_FUNCTION)p); + } +#endif + for (auto p : JitBlocks) + { + asmjit::OSUtils::releaseVirtualMemory(p, 1024 * 1024); + } +} + static TArray CreateUnwindInfo(asmjit::CCFunc *func) { using namespace asmjit; @@ -276,6 +292,7 @@ static void *AddJitFunction(asmjit::CodeHolder* code, asmjit::CCFunc *func) table[0].EndAddress = (DWORD)(ptrdiff_t)(endaddr - baseaddr); table[0].UnwindInfoAddress = (DWORD)(ptrdiff_t)(unwindptr - baseaddr); BOOLEAN result = RtlAddFunctionTable(table, 1, (DWORD64)baseaddr); + JitFrames.Push((uint8_t*)table); if (result == 0) I_FatalError("RtlAddFunctionTable failed"); #endif diff --git a/src/scripting/vm/vm.h b/src/scripting/vm/vm.h index 1b8faa341..6e328c4c8 100644 --- a/src/scripting/vm/vm.h +++ b/src/scripting/vm/vm.h @@ -53,6 +53,8 @@ extern FMemArena ClassDataAllocator; #define MAX_RETURNS 8 // Maximum number of results a function called by script code can return #define MAX_TRY_DEPTH 8 // Maximum number of nested TRYs in a single function +void JitRelease(); + typedef unsigned char VM_UBYTE; typedef signed char VM_SBYTE; @@ -426,6 +428,8 @@ public: f->~VMFunction(); } AllFunctions.Clear(); + // also release any JIT data + JitRelease(); } static void CreateRegUseInfo() {