From 2c688bae734b1e63b2e2fd5d715c1070af722651 Mon Sep 17 00:00:00 2001 From: mio Date: Sat, 4 Jan 2025 17:05:34 +0800 Subject: [PATCH] Remove the outdated hack to zero all code gen buffer This shall also improve performance Fix #2001 --- qemu/tcg/tcg.c | 3 ++- qemu/unicorn_common.h | 6 ++++-- tests/unit/test_x86.c | 12 ++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/qemu/tcg/tcg.c b/qemu/tcg/tcg.c index a91f2de6f1..65703a3a77 100644 --- a/qemu/tcg/tcg.c +++ b/qemu/tcg/tcg.c @@ -407,7 +407,7 @@ static void tcg_region_assign(TCGContext *s, size_t curr_region) s->code_gen_ptr = start; s->code_gen_buffer_size = (char *)end - (char *)start; - memset(s->code_gen_buffer, 0x00, s->code_gen_buffer_size); + // memset(s->code_gen_buffer, 0x00, s->code_gen_buffer_size); // Outdated Unicorn hacks s->code_gen_highwater = (char *)end - TCG_HIGHWATER; } @@ -812,6 +812,7 @@ TranslationBlock *tcg_tb_alloc(TCGContext *s) } s->code_gen_ptr = next; s->data_gen_ptr = NULL; + // memset((void*)tb, 0x00, sizeof(TranslationBlock)); // not necessary as both tb and tb->tc.ptr is reused here return tb; } diff --git a/qemu/unicorn_common.h b/qemu/unicorn_common.h index b557c49058..8ce54aaa9e 100644 --- a/qemu/unicorn_common.h +++ b/qemu/unicorn_common.h @@ -40,6 +40,10 @@ static void release_common(void *t) int i; #endif + // Clear bps + cpu_watchpoint_remove_all(CPU(s->uc->cpu), BP_CPU); + cpu_breakpoint_remove_all(CPU(s->uc->cpu), BP_CPU); + // Clean TCG. TCGOpDef* def = s->tcg_op_defs; g_free(def->args_ct); @@ -72,8 +76,6 @@ static void release_common(void *t) /* qemu/util/qht.c:264: map = qht_map_create(n_buckets); */ qht_destroy(&s->tb_ctx.htable); - cpu_watchpoint_remove_all(CPU(s->uc->cpu), BP_CPU); - cpu_breakpoint_remove_all(CPU(s->uc->cpu), BP_CPU); #if TCG_TARGET_REG_BITS == 32 for(i = 0; i < s->nb_globals; i++) { diff --git a/tests/unit/test_x86.c b/tests/unit/test_x86.c index df36332d0d..51f655787b 100644 --- a/tests/unit/test_x86.c +++ b/tests/unit/test_x86.c @@ -2019,6 +2019,17 @@ static void test_x86_hook_insn_rdtscp(void) OK(uc_close(uc)); } +static void test_x86_dr7() { + uc_engine *uc; + char code[] = + "\x48\xC7\xC0\x05\x00\x01\x00\x0F\x23\xF8"; // mov rax, 0x10005 + // mov dr7, rax + uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_64, code, sizeof(code) - 1); + OK(uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0)); + + OK(uc_close(uc)); +} + TEST_LIST = { {"test_x86_in", test_x86_in}, {"test_x86_out", test_x86_out}, @@ -2079,4 +2090,5 @@ TEST_LIST = { {"test_x86_ro_segfault", test_x86_ro_segfault}, {"test_x86_hook_insn_rdtsc", test_x86_hook_insn_rdtsc}, {"test_x86_hook_insn_rdtscp", test_x86_hook_insn_rdtscp}, + {"test_x86_dr7", test_x86_dr7}, {NULL, NULL}};