diff --git a/include/uc_priv.h b/include/uc_priv.h index 1376650e..069eb3ca 100644 --- a/include/uc_priv.h +++ b/include/uc_priv.h @@ -217,9 +217,10 @@ struct uc_struct { intptr_t qemu_host_page_mask; /* code generation context */ - void *tcg_ctx; // for "TCGContext tcg_ctx" in qemu/translate-all.c + void *tcg_ctx; // for "TCGContext tcg_ctx" in translate-all.c + void *tcg_init_ctx; // for "TCGContext init_tcg_contex" in translate-all.c TBContext tb_ctx; - bool parallel_cpus; // for "bool parallel_cpus" in qemu/translate-all.c + bool parallel_cpus; // for "bool parallel_cpus" in translate-all.c /* memory.c */ unsigned memory_region_transaction_depth; diff --git a/qemu/accel/tcg/translate-all.c b/qemu/accel/tcg/translate-all.c index 1ba1c7c8..b4b2f209 100644 --- a/qemu/accel/tcg/translate-all.c +++ b/qemu/accel/tcg/translate-all.c @@ -167,8 +167,9 @@ static void page_table_config_init(struct uc_struct *uc) static void cpu_gen_init(struct uc_struct *uc) { - uc->tcg_ctx = g_malloc0(sizeof(TCGContext)); - tcg_context_init(uc->tcg_ctx); + uc->tcg_init_ctx = g_malloc0(sizeof(TCGContext));; + + tcg_context_init(uc->tcg_init_ctx); } static void tb_clean_internal(struct uc_struct *uc, int i, void** lp) @@ -879,6 +880,7 @@ void tcg_exec_init(struct uc_struct *uc, unsigned long tb_size) TCGContext *tcg_ctx; cpu_gen_init(uc); + uc->tcg_ctx = uc->tcg_init_ctx; tcg_ctx = uc->tcg_ctx; tcg_ctx->uc = uc; page_init(uc); diff --git a/uc.c b/uc.c index 4387f076..903fb79e 100644 --- a/uc.c +++ b/uc.c @@ -307,9 +307,10 @@ UNICORN_EXPORT uc_err uc_close(uc_engine *uc) { // Cleanup internally. - if (uc->release) - uc->release(uc->tcg_ctx); - g_free(uc->tcg_ctx); + if (uc->release) { + uc->release(uc->tcg_init_ctx); + } + g_free(uc->tcg_init_ctx); // Cleanup CPU. g_free(uc->cpu->cpu_ases);