From d7c3c3fcf9079bcd24a4221842a8477b89754920 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 17 Sep 2024 16:39:54 +0200 Subject: [PATCH] Save flags and defered flags when runing EmuCall ([DYNAREC] Same for DynaCall) --- src/dynarec/dynarec.c | 2 ++ src/emu/x64emu.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/dynarec/dynarec.c b/src/dynarec/dynarec.c index a9708c840..5dddc23bf 100644 --- a/src/dynarec/dynarec.c +++ b/src/dynarec/dynarec.c @@ -100,6 +100,7 @@ void DynaCall(x64emu_t* emu, uintptr_t addr) uint64_t old_rsi = R_RSI; uint64_t old_rbp = R_RBP; uint64_t old_rip = R_RIP; + x64flags_t old_eflags = emu->eflags; // save defered flags deferred_flags_t old_df = emu->df; multiuint_t old_op1 = emu->op1; @@ -137,6 +138,7 @@ void DynaCall(x64emu_t* emu, uintptr_t addr) emu->res_sav = old_res_sav; emu->df_sav = old_df_sav; // and the old registers + emu->eflags = old_eflags; R_RBX = old_rbx; R_RDI = old_rdi; R_RSI = old_rsi; diff --git a/src/emu/x64emu.c b/src/emu/x64emu.c index ddfa0fc69..c37aad166 100644 --- a/src/emu/x64emu.c +++ b/src/emu/x64emu.c @@ -592,6 +592,18 @@ void EmuCall(x64emu_t* emu, uintptr_t addr) uint64_t old_rsi = R_RSI; uint64_t old_rbp = R_RBP; uint64_t old_rip = R_RIP; + x64flags_t old_eflags = emu->eflags; + // save defered flags + deferred_flags_t old_df = emu->df; + multiuint_t old_op1 = emu->op1; + multiuint_t old_op2 = emu->op2; + multiuint_t old_res = emu->res; + multiuint_t old_op1_sav= emu->op1_sav; + multiuint_t old_res_sav= emu->res_sav; + deferred_flags_t old_df_sav= emu->df_sav; + // uc_link + void* old_uc_link = emu->uc_link; + emu->uc_link = NULL; //Push64(emu, GetRBP(emu)); // set frame pointer //SetRBP(emu, GetRSP(emu)); // save RSP //R_RSP -= 200; @@ -607,10 +619,21 @@ void EmuCall(x64emu_t* emu, uintptr_t addr) Run(emu, 0); emu->quit = 0; // reset Quit flags... emu->df = d_none; + emu->uc_link = old_uc_link; if(emu->flags.quitonlongjmp && emu->flags.longjmp) { if(emu->flags.quitonlongjmp==1) emu->flags.longjmp = 0; // don't change anything because of the longjmp } else { + // restore defered flags + emu->df = old_df; + emu->op1 = old_op1; + emu->op2 = old_op2; + emu->res = old_res; + emu->op1_sav = old_op1_sav; + emu->res_sav = old_res_sav; + emu->df_sav = old_df_sav; + // and the old registers + emu->eflags = old_eflags; R_RBX = old_rbx; R_RDI = old_rdi; R_RSI = old_rsi;