From 640251e1aaae23fe671101406646319f6f976e0a Mon Sep 17 00:00:00 2001 From: lazymio Date: Tue, 9 Nov 2021 00:21:34 +0100 Subject: [PATCH] Leave out size parameter in callback --- include/unicorn/unicorn.h | 2 +- qemu/include/tcg/tcg-op.h | 10 ++++++---- qemu/target/arm/helper.h | 2 +- qemu/target/i386/helper.h | 2 +- qemu/target/i386/translate.c | 4 ++-- qemu/target/m68k/helper.h | 2 +- qemu/target/mips/helper.h | 2 +- qemu/target/ppc/helper.h | 2 +- qemu/target/riscv/helper.h | 2 +- qemu/target/sparc/helper.h | 2 +- qemu/tcg/tcg-op.c | 2 +- tests/unit/test_x86.c | 3 ++- uc.c | 6 +++--- 13 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index 3c6bc2a1..979c3a26 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -259,7 +259,7 @@ typedef void (*uc_hook_edge_gen_t)(uc_engine *uc, uc_tb *cur_tb, uc_tb *prev_tb, @arg2: The second argument. */ typedef void (*uc_hook_tcg_op_2)(uc_engine *uc, uint64_t address, uint64_t arg1, - uint64_t arg2, void *user_data); + uint64_t arg2, uint32_t size, void *user_data); typedef uc_hook_tcg_op_2 uc_hook_tcg_sub_t; diff --git a/qemu/include/tcg/tcg-op.h b/qemu/include/tcg/tcg-op.h index 6aad2505..0333daf1 100644 --- a/qemu/include/tcg/tcg-op.h +++ b/qemu/include/tcg/tcg-op.h @@ -42,11 +42,12 @@ static inline void gen_uc_tracecode(TCGContext *tcg_ctx, int32_t size, int32_t t tcg_temp_free_i32(tcg_ctx, tsize); } -static inline void gen_uc_traceopcode(TCGContext *tcg_ctx, void* hook, TCGv_i64 arg1, TCGv_i64 arg2, void *uc, uint64_t pc) +static inline void gen_uc_traceopcode(TCGContext *tcg_ctx, void* hook, TCGv_i64 arg1, TCGv_i64 arg2, uint32_t size, void *uc, uint64_t pc) { TCGv_ptr thook = tcg_const_ptr(tcg_ctx, hook); TCGv_ptr tuc = tcg_const_ptr(tcg_ctx, uc); TCGv_i64 tpc = tcg_const_i64(tcg_ctx, pc); + TCGv_i32 tsz = tcg_const_i32(tcg_ctx, size); // #if TARGET_LONG_BITS == 32 // TCGv_i64 targ1 = temp_tcgv_i64(tcg_ctx, tcgv_i32_temp(tcg_ctx, arg1)); // TCGv_i64 targ2 = temp_tcgv_i64(tcg_ctx, tcgv_i32_temp(tcg_ctx, arg2)); @@ -54,7 +55,8 @@ static inline void gen_uc_traceopcode(TCGContext *tcg_ctx, void* hook, TCGv_i64 // TCGv_i64 targ1 = arg1; // TCGv_i64 targ2 = arg2; // #endif - gen_helper_uc_traceopcode(tcg_ctx, thook, arg1, arg2, tuc, tpc); + gen_helper_uc_traceopcode(tcg_ctx, thook, arg1, arg2, tsz, tuc, tpc); + tcg_temp_free_i32(tcg_ctx, tsz); tcg_temp_free_i64(tcg_ctx, tpc); tcg_temp_free_ptr(tcg_ctx, tuc); tcg_temp_free_ptr(tcg_ctx, thook); @@ -449,7 +451,7 @@ static inline void tcg_gen_sub_i32(TCGContext *tcg_ctx, TCGv_i32 ret, TCGv_i32 a if (hook->to_delete) continue; if (hook->op == UC_TCG_OP_SUB && hook->op_flags == 0) { - gen_uc_traceopcode(tcg_ctx, hook, (TCGv_i64)arg1, (TCGv_i64)arg2, uc, tcg_ctx->pc_start); + gen_uc_traceopcode(tcg_ctx, hook, (TCGv_i64)arg1, (TCGv_i64)arg2, 32, uc, tcg_ctx->pc_start); } } } @@ -682,7 +684,7 @@ static inline void tcg_gen_sub_i64(TCGContext *tcg_ctx, TCGv_i64 ret, TCGv_i64 a if (hook->to_delete) continue; if (hook->op == UC_TCG_OP_SUB && hook->op_flags == 0) { - gen_uc_traceopcode(tcg_ctx, hook, arg1, arg2, uc, tcg_ctx->pc_start); + gen_uc_traceopcode(tcg_ctx, hook, arg1, arg2, 64, uc, tcg_ctx->pc_start); } } } diff --git a/qemu/target/arm/helper.h b/qemu/target/arm/helper.h index f445667b..a9f30ad7 100644 --- a/qemu/target/arm/helper.h +++ b/qemu/target/arm/helper.h @@ -1,5 +1,5 @@ DEF_HELPER_4(uc_tracecode, void, i32, i32, ptr, i64) -DEF_HELPER_5(uc_traceopcode, void, ptr, i64, i64, ptr, i64) +DEF_HELPER_6(uc_traceopcode, void, ptr, i64, i64, i32, ptr, i64) DEF_HELPER_FLAGS_1(sxtb16, TCG_CALL_NO_RWG_SE, i32, i32) DEF_HELPER_FLAGS_1(uxtb16, TCG_CALL_NO_RWG_SE, i32, i32) diff --git a/qemu/target/i386/helper.h b/qemu/target/i386/helper.h index 28dadb82..399cc0df 100644 --- a/qemu/target/i386/helper.h +++ b/qemu/target/i386/helper.h @@ -1,5 +1,5 @@ DEF_HELPER_4(uc_tracecode, void, i32, i32, ptr, i64) -DEF_HELPER_5(uc_traceopcode, void, ptr, i64, i64, ptr, i64) +DEF_HELPER_6(uc_traceopcode, void, ptr, i64, i64, i32, ptr, i64) DEF_HELPER_FLAGS_4(cc_compute_all, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl, int) DEF_HELPER_FLAGS_4(cc_compute_c, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl, int) diff --git a/qemu/target/i386/translate.c b/qemu/target/i386/translate.c index d8fbae77..97c33ecd 100644 --- a/qemu/target/i386/translate.c +++ b/qemu/target/i386/translate.c @@ -1552,7 +1552,7 @@ static void gen_op(DisasContext *s1, int op, MemOp ot, int d) continue; if (hook->op == UC_TCG_OP_SUB && (hook->op_flags & UC_TCG_OP_FLAG_DIRECT) ) { // TCGv is just an offset to tcg_ctx so it's safe to do so. - gen_uc_traceopcode(tcg_ctx, hook, (TCGv_i64)s1->T0, (TCGv_i64)s1->T1, uc, s1->pc_start); + gen_uc_traceopcode(tcg_ctx, hook, (TCGv_i64)s1->T0, (TCGv_i64)s1->T1, 1 << ((ot & MO_SIZE) + 3), uc, s1->pc_start); } } } @@ -1607,7 +1607,7 @@ static void gen_op(DisasContext *s1, int op, MemOp ot, int d) continue; if (hook->op == UC_TCG_OP_SUB && (hook->op_flags & UC_TCG_OP_FLAG_CMP) ) { // TCGv is just an offset to tcg_ctx so it's safe to do so. - gen_uc_traceopcode(tcg_ctx, hook, (TCGv_i64)s1->T0, (TCGv_i64)s1->T1, uc, s1->pc_start); + gen_uc_traceopcode(tcg_ctx, hook, (TCGv_i64)s1->T0, (TCGv_i64)s1->T1, 1 << ((ot & MO_SIZE) + 3), uc, s1->pc_start); } } } diff --git a/qemu/target/m68k/helper.h b/qemu/target/m68k/helper.h index 0b333b0e..413f88dc 100644 --- a/qemu/target/m68k/helper.h +++ b/qemu/target/m68k/helper.h @@ -1,5 +1,5 @@ DEF_HELPER_4(uc_tracecode, void, i32, i32, ptr, i64) -DEF_HELPER_5(uc_traceopcode, void, ptr, i64, i64, ptr, i64) +DEF_HELPER_6(uc_traceopcode, void, ptr, i64, i64, i32, ptr, i64) DEF_HELPER_1(bitrev, i32, i32) DEF_HELPER_1(ff1, i32, i32) diff --git a/qemu/target/mips/helper.h b/qemu/target/mips/helper.h index 51766471..221e7825 100644 --- a/qemu/target/mips/helper.h +++ b/qemu/target/mips/helper.h @@ -1,5 +1,5 @@ DEF_HELPER_4(uc_tracecode, void, i32, i32, ptr, i64) -DEF_HELPER_5(uc_traceopcode, void, ptr, i64, i64, ptr, i64) +DEF_HELPER_6(uc_traceopcode, void, ptr, i64, i64, i32, ptr, i64) DEF_HELPER_3(raise_exception_err, noreturn, env, i32, int) DEF_HELPER_2(raise_exception, noreturn, env, i32) diff --git a/qemu/target/ppc/helper.h b/qemu/target/ppc/helper.h index 8293ebf5..b1c43439 100644 --- a/qemu/target/ppc/helper.h +++ b/qemu/target/ppc/helper.h @@ -1,5 +1,5 @@ DEF_HELPER_4(uc_tracecode, void, i32, i32, ptr, i64) -DEF_HELPER_5(uc_traceopcode, void, ptr, i64, i64, ptr, i64) +DEF_HELPER_6(uc_traceopcode, void, ptr, i64, i64, i32, ptr, i64) DEF_HELPER_FLAGS_3(raise_exception_err, TCG_CALL_NO_WG, void, env, i32, i32) DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, void, env, i32) diff --git a/qemu/target/riscv/helper.h b/qemu/target/riscv/helper.h index 8b273d5e..32e48386 100644 --- a/qemu/target/riscv/helper.h +++ b/qemu/target/riscv/helper.h @@ -1,5 +1,5 @@ DEF_HELPER_4(uc_tracecode, void, i32, i32, ptr, i64) -DEF_HELPER_5(uc_traceopcode, void, ptr, i64, i64, ptr, i64) +DEF_HELPER_6(uc_traceopcode, void, ptr, i64, i64, i32, ptr, i64) DEF_HELPER_1(uc_riscv_exit, void, env) /* Exceptions */ diff --git a/qemu/target/sparc/helper.h b/qemu/target/sparc/helper.h index e019337f..69924307 100644 --- a/qemu/target/sparc/helper.h +++ b/qemu/target/sparc/helper.h @@ -1,5 +1,5 @@ DEF_HELPER_4(uc_tracecode, void, i32, i32, ptr, i64) -DEF_HELPER_5(uc_traceopcode, void, ptr, i64, i64, ptr, i64) +DEF_HELPER_6(uc_traceopcode, void, ptr, i64, i64, i32, ptr, i64) #ifndef TARGET_SPARC64 DEF_HELPER_1(rett, void, env) diff --git a/qemu/tcg/tcg-op.c b/qemu/tcg/tcg-op.c index 4bcf2af3..37971d5d 100644 --- a/qemu/tcg/tcg-op.c +++ b/qemu/tcg/tcg-op.c @@ -909,7 +909,7 @@ void tcg_gen_sub2_i32(TCGContext *tcg_ctx, TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al TCGv_i64 t1 = tcg_temp_new_i64(tcg_ctx); tcg_gen_concat_i32_i64(tcg_ctx, t0, al, ah); tcg_gen_concat_i32_i64(tcg_ctx, t1, bl, bh); - gen_uc_traceopcode(tcg_ctx, hook, t0, t1, uc, tcg_ctx->pc_start); + gen_uc_traceopcode(tcg_ctx, hook, t0, t1, 32, uc, tcg_ctx->pc_start); tcg_temp_free_i64(tcg_ctx, t0); tcg_temp_free_i64(tcg_ctx, t1); } diff --git a/tests/unit/test_x86.c b/tests/unit/test_x86.c index d5589253..5d539f8c 100644 --- a/tests/unit/test_x86.c +++ b/tests/unit/test_x86.c @@ -708,7 +708,8 @@ typedef struct _HOOK_TCG_OP_RESULTS { } HOOK_TCG_OP_RESULTS; static void test_x86_hook_tcg_op_cb(uc_engine *uc, uint64_t address, - uint64_t arg1, uint64_t arg2, void *data) + uint64_t arg1, uint64_t arg2, uint32_t size, + void *data) { HOOK_TCG_OP_RESULTS *results = (HOOK_TCG_OP_RESULTS *)data; HOOK_TCG_OP_RESULT *result = &results->results[results->len++]; diff --git a/uc.c b/uc.c index 4363d61c..26735d2d 100644 --- a/uc.c +++ b/uc.c @@ -1518,9 +1518,9 @@ uc_err uc_hook_del(uc_engine *uc, uc_hook hh) // have memory hooks already. We may exceed the maximum arguments of a tcg // helper but that's easy to extend. void helper_uc_traceopcode(struct hook *hook, uint64_t arg1, uint64_t arg2, - void *handle, uint64_t address); + uint32_t size, void *handle, uint64_t address); void helper_uc_traceopcode(struct hook *hook, uint64_t arg1, uint64_t arg2, - void *handle, uint64_t address) + uint32_t size, void *handle, uint64_t address) { struct uc_struct *uc = handle; @@ -1539,7 +1539,7 @@ void helper_uc_traceopcode(struct hook *hook, uint64_t arg1, uint64_t arg2, // hold in most cases for uc_tracecode. // // TODO: Shall we have a flag to allow users to control whether updating PC? - ((uc_hook_tcg_op_2)hook->callback)(uc, address, arg1, arg2, + ((uc_hook_tcg_op_2)hook->callback)(uc, address, arg1, arg2, size, hook->user_data); if (unlikely(uc->stop_request)) {