Save jit state before/after callback

This commit is contained in:
2024-02-13 11:13:01 +08:00
parent f3323469d0
commit a6fb2a6870
10 changed files with 115 additions and 41 deletions

View File

@@ -939,6 +939,7 @@ uint32_t HELPER(uc_hooksys64)(CPUARMState *env, uint32_t insn, void *hk)
struct hook *hook = (struct hook*)hk;
uc_arm64_cp_reg cp_reg;
uint32_t rt;
uc_engine *uc = env->uc;
if (hook->to_delete) {
return 0;
@@ -965,5 +966,7 @@ uint32_t HELPER(uc_hooksys64)(CPUARMState *env, uint32_t insn, void *hk)
cp_reg.val = 0;
}
return ((uc_cb_insn_sys_t)(hook->callback))(env->uc, uc_rt, &cp_reg, hook->user_data);
uint32_t ret;
JIT_CALLBACK_GUARD_VAR(ret, ((uc_cb_insn_sys_t)(hook->callback))(env->uc, uc_rt, &cp_reg, hook->user_data));
return ret;
}

View File

@@ -25,6 +25,7 @@
#include "exec/ioport.h"
#include "uc_priv.h"
#include "tcg/tcg-apple-jit.h"
void helper_outb(CPUX86State *env, uint32_t port, uint32_t data)
{
@@ -105,6 +106,7 @@ void helper_into(CPUX86State *env, int next_eip_addend)
void helper_cpuid(CPUX86State *env)
{
uint32_t eax, ebx, ecx, edx;
uc_engine *uc = env->uc;
struct hook *hook;
int skip_cpuid = 0;
@@ -120,8 +122,9 @@ void helper_cpuid(CPUX86State *env)
// Multiple cpuid callbacks returning different values is undefined.
// true -> skip the cpuid instruction
if (hook->insn == UC_X86_INS_CPUID)
skip_cpuid = ((uc_cb_insn_cpuid_t)hook->callback)(env->uc, hook->user_data);
if (hook->insn == UC_X86_INS_CPUID) {
JIT_CALLBACK_GUARD_VAR(skip_cpuid, ((uc_cb_insn_cpuid_t)hook->callback)(env->uc, hook->user_data));
}
// the last callback may already asked to stop emulation
if (env->uc->stop_request)

View File

@@ -973,14 +973,17 @@ void helper_syscall(CPUX86State *env, int next_eip_addend)
{
// Unicorn: call registered syscall hooks
struct hook *hook;
uc_engine *uc = env->uc;
HOOK_FOREACH_VAR_DECLARE;
HOOK_FOREACH(env->uc, hook, UC_HOOK_INSN) {
if (hook->to_delete)
continue;
if (!HOOK_BOUND_CHECK(hook, env->eip))
continue;
if (hook->insn == UC_X86_INS_SYSCALL)
((uc_cb_insn_syscall_t)hook->callback)(env->uc, hook->user_data);
if (hook->insn == UC_X86_INS_SYSCALL) {
JIT_CALLBACK_GUARD(((uc_cb_insn_syscall_t)hook->callback)(env->uc, hook->user_data));
}
// the last callback may already asked to stop emulation
if (env->uc->stop_request)
@@ -2348,14 +2351,17 @@ void helper_sysenter(CPUX86State *env, int next_eip_addend)
{
// Unicorn: call registered SYSENTER hooks
struct hook *hook;
uc_engine *uc = env->uc;
HOOK_FOREACH_VAR_DECLARE;
HOOK_FOREACH(env->uc, hook, UC_HOOK_INSN) {
if (hook->to_delete)
continue;
if (!HOOK_BOUND_CHECK(hook, env->eip))
continue;
if (hook->insn == UC_X86_INS_SYSENTER)
((uc_cb_insn_syscall_t)hook->callback)(env->uc, hook->user_data);
if (hook->insn == UC_X86_INS_SYSENTER) {
JIT_CALLBACK_GUARD(((uc_cb_insn_syscall_t)hook->callback)(env->uc, hook->user_data));
}
// the last callback may already asked to stop emulation
if (env->uc->stop_request)