JIT (ARM): Fix a crash when resetting the emulator. Also fixes a memory leak. (Related to commit f12a70f4.)

This commit is contained in:
rogerman 2022-04-24 14:11:33 -07:00
parent f12a70f4b7
commit b1ee7e80d5
2 changed files with 5 additions and 10 deletions

View File

@ -4116,10 +4116,7 @@ static u32 compile_basicblock()
emit_endfunc(g_out); emit_endfunc(g_out);
ArmOpCompiled f; ArmOpCompiled f;
f = createFunc(g_out); f = createFunc(g_out);
g_out = NULL;
jit_exec(); jit_exec();
@ -4177,8 +4174,8 @@ void arm_jit_reset(bool enable, bool suppress_msg)
#ifdef MAPPED_JIT_FUNCS #ifdef MAPPED_JIT_FUNCS
//these pointers are allocated by asmjit and need freeing //these pointers are allocated by asmjit and need freeing
#define JITFREE(x) for(int iii=0;iii<ARRAY_SIZE(x);iii++) if(x[iii]) AsmJit::MemoryManager::getGlobal()->free((void*)x[iii]); memset(x,0,sizeof(x)); #define JITFREE(x) for(int iii=0;iii<ARRAY_SIZE(x);iii++) if(x[iii]) x[iii] = NULL;
/* JITFREE(JIT.MAIN_MEM); JITFREE(JIT.MAIN_MEM);
JITFREE(JIT.SWIRAM); JITFREE(JIT.SWIRAM);
JITFREE(JIT.ARM9_ITCM); JITFREE(JIT.ARM9_ITCM);
JITFREE(JIT.ARM9_LCDC); JITFREE(JIT.ARM9_LCDC);
@ -4186,9 +4183,8 @@ void arm_jit_reset(bool enable, bool suppress_msg)
JITFREE(JIT.ARM7_BIOS); JITFREE(JIT.ARM7_BIOS);
JITFREE(JIT.ARM7_ERAM); JITFREE(JIT.ARM7_ERAM);
JITFREE(JIT.ARM7_WIRAM); JITFREE(JIT.ARM7_WIRAM);
JITFREE(JIT.ARM7_WRAM);*/ JITFREE(JIT.ARM7_WRAM);
#undef JITFREE #undef JITFREE
memset(recompile_counts, 0, sizeof(recompile_counts)); memset(recompile_counts, 0, sizeof(recompile_counts));
init_jit_mem(); init_jit_mem();
#else #else

View File

@ -92,10 +92,10 @@ static void *armjitarm_alloc_func(size_t size) {
static void freeFuncs() { static void freeFuncs() {
std::map<JittedFunc, u_int>::iterator it; std::map<JittedFunc, u_int>::iterator it;
for (it=allFuncs.begin(); it!=allFuncs.end(); ++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(); allFuncs.clear();
g_curr_jit_block = NULL;
} }
static void allocNewBlock() { static void allocNewBlock() {
@ -174,7 +174,6 @@ void releaseBytes(t_bytes *bytes) {
} }
JittedFunc createFunc(t_bytes *bytes) { JittedFunc createFunc(t_bytes *bytes) {
for (auto const& lbl : g_LABELS) { for (auto const& lbl : g_LABELS) {
int nj = lbl.second.jumps.size(); int nj = lbl.second.jumps.size();
for (int i = 0; i < nj; i++) { for (int i = 0; i < nj; i++) {