Skip to content

Commit 2c688ba

Browse files
committed
Remove the outdated hack to zero all code gen buffer
This shall also improve performance Fix #2001
1 parent c4567ff commit 2c688ba

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

qemu/tcg/tcg.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ static void tcg_region_assign(TCGContext *s, size_t curr_region)
407407
s->code_gen_ptr = start;
408408
s->code_gen_buffer_size = (char *)end - (char *)start;
409409

410-
memset(s->code_gen_buffer, 0x00, s->code_gen_buffer_size);
410+
// memset(s->code_gen_buffer, 0x00, s->code_gen_buffer_size); // Outdated Unicorn hacks
411411
s->code_gen_highwater = (char *)end - TCG_HIGHWATER;
412412
}
413413

@@ -812,6 +812,7 @@ TranslationBlock *tcg_tb_alloc(TCGContext *s)
812812
}
813813
s->code_gen_ptr = next;
814814
s->data_gen_ptr = NULL;
815+
// memset((void*)tb, 0x00, sizeof(TranslationBlock)); // not necessary as both tb and tb->tc.ptr is reused here
815816
return tb;
816817
}
817818

qemu/unicorn_common.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ static void release_common(void *t)
4040
int i;
4141
#endif
4242

43+
// Clear bps
44+
cpu_watchpoint_remove_all(CPU(s->uc->cpu), BP_CPU);
45+
cpu_breakpoint_remove_all(CPU(s->uc->cpu), BP_CPU);
46+
4347
// Clean TCG.
4448
TCGOpDef* def = s->tcg_op_defs;
4549
g_free(def->args_ct);
@@ -72,8 +76,6 @@ static void release_common(void *t)
7276
/* qemu/util/qht.c:264: map = qht_map_create(n_buckets); */
7377
qht_destroy(&s->tb_ctx.htable);
7478

75-
cpu_watchpoint_remove_all(CPU(s->uc->cpu), BP_CPU);
76-
cpu_breakpoint_remove_all(CPU(s->uc->cpu), BP_CPU);
7779

7880
#if TCG_TARGET_REG_BITS == 32
7981
for(i = 0; i < s->nb_globals; i++) {

tests/unit/test_x86.c

+12
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,17 @@ static void test_x86_hook_insn_rdtscp(void)
20192019
OK(uc_close(uc));
20202020
}
20212021

2022+
static void test_x86_dr7() {
2023+
uc_engine *uc;
2024+
char code[] =
2025+
"\x48\xC7\xC0\x05\x00\x01\x00\x0F\x23\xF8"; // mov rax, 0x10005
2026+
// mov dr7, rax
2027+
uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_64, code, sizeof(code) - 1);
2028+
OK(uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));
2029+
2030+
OK(uc_close(uc));
2031+
}
2032+
20222033
TEST_LIST = {
20232034
{"test_x86_in", test_x86_in},
20242035
{"test_x86_out", test_x86_out},
@@ -2079,4 +2090,5 @@ TEST_LIST = {
20792090
{"test_x86_ro_segfault", test_x86_ro_segfault},
20802091
{"test_x86_hook_insn_rdtsc", test_x86_hook_insn_rdtsc},
20812092
{"test_x86_hook_insn_rdtscp", test_x86_hook_insn_rdtscp},
2093+
{"test_x86_dr7", test_x86_dr7},
20822094
{NULL, NULL}};

0 commit comments

Comments
 (0)