Add a new hook type UC_HOOK_EDGE_GENERATED and corresponding sample

This commit is contained in:
lazymio
2021-11-01 23:27:35 +01:00
parent b7e82d460c
commit c11b9aa5c3
5 changed files with 80 additions and 10 deletions

View File

@ -245,6 +245,10 @@ static inline TranslationBlock *tb_find(CPUState *cpu,
TranslationBlock *tb;
target_ulong cs_base, pc;
uint32_t flags;
uc_tb cur_tb, prev_tb;
uc_engine *uc = cpu->uc;
struct list_item *cur;
struct hook *hook;
tb = tb_lookup__cpu_state(cpu, &pc, &cs_base, &flags, cf_mask);
if (tb == NULL) {
@ -265,6 +269,23 @@ static inline TranslationBlock *tb_find(CPUState *cpu,
if (last_tb) {
tb_add_jump(last_tb, tb_exit, tb);
}
UC_TB_COPY(&cur_tb, tb);
if (last_tb) {
UC_TB_COPY(&prev_tb, last_tb);
for (cur = uc->hook[UC_HOOK_EDGE_GENERATED_IDX].head;
cur != NULL && (hook = (struct hook *)cur->data); cur = cur->next) {
if (hook->to_delete) {
continue;
}
if (HOOK_BOUND_CHECK(hook, (uint64_t)tb->pc)) {
((uc_hook_edge_gen_t)hook->callback)(uc, &cur_tb, &prev_tb, hook->user_data);
}
}
}
return tb;
}

View File

@ -1049,9 +1049,7 @@ static uc_err uc_gen_tb(struct uc_struct *uc, uint64_t addr, uc_tb *out_tb)
}
if (out_tb != NULL) {
out_tb->pc = tb->pc;
out_tb->size = tb->size;
out_tb->icount = tb->icount;
UC_TB_COPY(out_tb, tb);
}
return UC_ERR_OK;