From b1ee7e80d58bcb159aaf03cc56ecc7d7ccc75e5c Mon Sep 17 00:00:00 2001 From: rogerman Date: Sun, 24 Apr 2022 14:11:33 -0700 Subject: [PATCH] JIT (ARM): Fix a crash when resetting the emulator. Also fixes a memory leak. (Related to commit f12a70f4.) --- desmume/src/utils/arm_jit/arm_jit_arm.cpp | 10 +++------- desmume/src/utils/arm_jit/emit_core.cpp | 5 ++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/desmume/src/utils/arm_jit/arm_jit_arm.cpp b/desmume/src/utils/arm_jit/arm_jit_arm.cpp index 4d8649a80..e4bf0be4c 100755 --- a/desmume/src/utils/arm_jit/arm_jit_arm.cpp +++ b/desmume/src/utils/arm_jit/arm_jit_arm.cpp @@ -4116,10 +4116,7 @@ static u32 compile_basicblock() emit_endfunc(g_out); ArmOpCompiled f; - - f = createFunc(g_out); - g_out = NULL; jit_exec(); @@ -4177,8 +4174,8 @@ void arm_jit_reset(bool enable, bool suppress_msg) #ifdef MAPPED_JIT_FUNCS //these pointers are allocated by asmjit and need freeing - #define JITFREE(x) for(int iii=0;iiifree((void*)x[iii]); memset(x,0,sizeof(x)); -/* JITFREE(JIT.MAIN_MEM); +#define JITFREE(x) for(int iii=0;iii::iterator it; for (it=allFuncs.begin(); it!=allFuncs.end(); ++it) { - // TODO: Calling munmap() causes a crash when resetting the emulator. Need to research why this happens. - //munmap((void *)it->first, (uintptr_t)it->second); + munmap((void *)it->first, (uintptr_t)it->second); } allFuncs.clear(); + g_curr_jit_block = NULL; } static void allocNewBlock() { @@ -174,7 +174,6 @@ void releaseBytes(t_bytes *bytes) { } JittedFunc createFunc(t_bytes *bytes) { - for (auto const& lbl : g_LABELS) { int nj = lbl.second.jumps.size(); for (int i = 0; i < nj; i++) {