tcg: define tcg_init_ctx and make tcg_ctx a pointer

Groundwork for supporting multiple TCG contexts.

The core of this patch is this change to tcg/tcg.h:

> -extern TCGContext tcg_ctx;
> +extern TCGContext tcg_init_ctx;
> +extern TCGContext *tcg_ctx;

Note that for now we set *tcg_ctx to whatever TCGContext is passed
to tcg_context_init -- in this case &tcg_init_ctx.

Backports commit b1311c4acf503dc9c1a310cc40b64f05b08833dc from qemu
This commit is contained in:
Emilio G. Cota 2018-03-14 09:26:42 -04:00 committed by Lioncash
parent 078c9e7e3b
commit 9d5b378475
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
3 changed files with 11 additions and 7 deletions

View file

@ -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;

View file

@ -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);

7
uc.c
View file

@ -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);