Skip to content

Commit

Permalink
Remove the outdated hack to zero all code gen buffer
Browse files Browse the repository at this point in the history
This shall also improve performance

Fix #2001
  • Loading branch information
wtdcode committed Jan 4, 2025
1 parent c4567ff commit 2c688ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion qemu/tcg/tcg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions qemu/unicorn_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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++) {
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/test_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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}};

0 comments on commit 2c688ba

Please sign in to comment.