Skip to content

Commit

Permalink
qemu/tcg: fix UC_HOOK_MEM_READ on ppc64.
Browse files Browse the repository at this point in the history
Directly jump into the slow path when there is any hookmem enabled.

Signed-off-by: Glenn Baker <[email protected]>
  • Loading branch information
glennsec committed Oct 22, 2024
1 parent 376c169 commit bfe3acb
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions qemu/tcg/ppc/tcg-target.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2008,13 +2008,20 @@ static void add_qemu_ldst_label(TCGContext *s, bool is_ld, TCGMemOpIdx oi,
label->label_ptr[0] = lptr;
}

static inline bool has_hookmem(TCGContext *s)
{
return HOOK_EXISTS(s->uc, UC_HOOK_MEM_READ) ||
HOOK_EXISTS(s->uc, UC_HOOK_MEM_WRITE);
}

static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
{
TCGMemOpIdx oi = lb->oi;
MemOp opc = get_memop(oi);
TCGReg hi, lo, arg = TCG_REG_R3;

if (!reloc_pc14(lb->label_ptr[0], s->code_ptr)) {
const int type = has_hookmem(s) ? R_PPC_REL24 : R_PPC_REL14;
if (!patch_reloc(lb->label_ptr[0], type, (intptr_t)s->code_ptr, 0)) {
return false;
}

Expand Down Expand Up @@ -2062,7 +2069,8 @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
MemOp s_bits = opc & MO_SIZE;
TCGReg hi, lo, arg = TCG_REG_R3;

if (!reloc_pc14(lb->label_ptr[0], s->code_ptr)) {
const int type = has_hookmem(s) ? R_PPC_REL24 : R_PPC_REL14;
if (!patch_reloc(lb->label_ptr[0], type, (intptr_t)s->code_ptr, 0)) {
return false;
}

Expand Down Expand Up @@ -2142,7 +2150,11 @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)

/* Load a pointer into the current opcode w/conditional branch-link. */
label_ptr = s->code_ptr;
tcg_out32(s, BC | BI(7, CR_EQ) | BO_COND_FALSE | LK);
// Unicorn: fast path if hookmem is not enabled
if (!has_hookmem(s))
tcg_out32(s, BC | BI(7, CR_EQ) | BO_COND_FALSE | LK);
else
tcg_out32(s, B | LK);

rbase = TCG_REG_R3;
#else /* !CONFIG_SOFTMMU */
Expand Down Expand Up @@ -2217,7 +2229,11 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)

/* Load a pointer into the current opcode w/conditional branch-link. */
label_ptr = s->code_ptr;
tcg_out32(s, BC | BI(7, CR_EQ) | BO_COND_FALSE | LK);
// Unicorn: fast path if hookmem is not enabled
if (!has_hookmem(s))
tcg_out32(s, BC | BI(7, CR_EQ) | BO_COND_FALSE | LK);
else
tcg_out32(s, B | LK);

rbase = TCG_REG_R3;
#else /* !CONFIG_SOFTMMU */
Expand Down

0 comments on commit bfe3acb

Please sign in to comment.