Allow user to instrument cpuid instruction

This commit is contained in:
mio
2021-10-05 17:15:49 +02:00
parent af60b4dfab
commit 9d8a309fbf
3 changed files with 44 additions and 1 deletions

View File

@ -105,6 +105,7 @@ void helper_into(CPUX86State *env, int next_eip_addend)
void helper_cpuid(CPUX86State *env)
{
uint32_t eax, ebx, ecx, edx;
struct hook *hook;
cpu_svm_check_intercept_param(env, SVM_EXIT_CPUID, 0, GETPC());
@ -114,6 +115,21 @@ void helper_cpuid(CPUX86State *env)
env->regs[R_EBX] = ebx;
env->regs[R_ECX] = ecx;
env->regs[R_EDX] = edx;
// Unicorn: call registered CPUID hooks
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_CPUID)
((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)
break;
}
}
target_ulong helper_read_crN(CPUX86State *env, int reg)

View File

@ -1564,7 +1564,8 @@ static bool x86_insn_hook_validate(uint32_t insn_enum)
if (insn_enum != UC_X86_INS_IN
&& insn_enum != UC_X86_INS_OUT
&& insn_enum != UC_X86_INS_SYSCALL
&& insn_enum != UC_X86_INS_SYSENTER) {
&& insn_enum != UC_X86_INS_SYSENTER
&& insn_enum != UC_X86_INS_CPUID) {
return false;
}
return true;