parent
247ffbe0e8
commit
8c2bc394bc
|
@ -341,24 +341,20 @@ struct uc_struct {
|
|||
// default)
|
||||
bool first_tb; // is this the first Translation-Block ever generated since
|
||||
// uc_emu_start()?
|
||||
struct list saved_contexts; // The contexts saved by this uc_struct.
|
||||
bool no_exit_request; // Disable check_exit_request temporarily. A
|
||||
bool no_exit_request; // Disable check_exit_request temporarily. A
|
||||
// workaround to treat the IT block as a whole block.
|
||||
bool init_done; // Whether the initialization is done.
|
||||
bool init_done; // Whether the initialization is done.
|
||||
|
||||
sigjmp_buf jmp_bufs[UC_MAX_NESTED_LEVEL]; // To support nested uc_emu_start
|
||||
int nested_level; // Current nested_level
|
||||
};
|
||||
|
||||
// Metadata stub for the variable-size cpu context used with uc_context_*()
|
||||
// We also save cpu->jmp_env, so emulation can be reentrant
|
||||
struct uc_context {
|
||||
size_t context_size; // size of the real internal context structure
|
||||
size_t jmp_env_size; // size of cpu->jmp_env
|
||||
uc_mode mode; // the mode of this context (uc may be free-ed already)
|
||||
uc_arch arch; // the arch of this context (uc may be free-ed already)
|
||||
struct uc_struct *uc; // the uc_struct which creates this context
|
||||
char data[0]; // context + cpu->jmp_env
|
||||
uc_mode mode; // the mode of this context
|
||||
uc_arch arch; // the arch of this context
|
||||
char data[0]; // context
|
||||
};
|
||||
|
||||
// check if this address is mapped in (via uc_mem_map())
|
||||
|
|
33
uc.c
33
uc.c
|
@ -431,16 +431,6 @@ uc_err uc_close(uc_engine *uc)
|
|||
|
||||
free(uc->mapped_blocks);
|
||||
|
||||
// free the saved contexts list and notify them that uc has been closed.
|
||||
cur = uc->saved_contexts.head;
|
||||
while (cur != NULL) {
|
||||
struct list_item *next = cur->next;
|
||||
struct uc_context *context = (struct uc_context *)cur->data;
|
||||
context->uc = NULL;
|
||||
cur = next;
|
||||
}
|
||||
list_clear(&uc->saved_contexts);
|
||||
|
||||
g_tree_destroy(uc->exits);
|
||||
|
||||
// finally, free uc itself.
|
||||
|
@ -1690,16 +1680,10 @@ uc_err uc_context_alloc(uc_engine *uc, uc_context **context)
|
|||
|
||||
*_context = g_malloc(size);
|
||||
if (*_context) {
|
||||
(*_context)->jmp_env_size = sizeof(*uc->cpu->jmp_env);
|
||||
(*_context)->context_size = uc->cpu_context_size;
|
||||
(*_context)->arch = uc->arch;
|
||||
(*_context)->mode = uc->mode;
|
||||
(*_context)->uc = uc;
|
||||
if (list_insert(&uc->saved_contexts, *_context)) {
|
||||
return UC_ERR_OK;
|
||||
} else {
|
||||
return UC_ERR_NOMEM;
|
||||
}
|
||||
return UC_ERR_OK;
|
||||
} else {
|
||||
return UC_ERR_NOMEM;
|
||||
}
|
||||
|
@ -1717,8 +1701,7 @@ size_t uc_context_size(uc_engine *uc)
|
|||
{
|
||||
UC_INIT(uc);
|
||||
// return the total size of struct uc_context
|
||||
return sizeof(uc_context) + uc->cpu_context_size +
|
||||
sizeof(*uc->cpu->jmp_env);
|
||||
return sizeof(uc_context) + uc->cpu_context_size;
|
||||
}
|
||||
|
||||
UNICORN_EXPORT
|
||||
|
@ -1727,8 +1710,6 @@ uc_err uc_context_save(uc_engine *uc, uc_context *context)
|
|||
UC_INIT(uc);
|
||||
|
||||
memcpy(context->data, uc->cpu->env_ptr, context->context_size);
|
||||
memcpy(context->data + context->context_size, uc->cpu->jmp_env,
|
||||
context->jmp_env_size);
|
||||
|
||||
return UC_ERR_OK;
|
||||
}
|
||||
|
@ -1900,10 +1881,6 @@ uc_err uc_context_restore(uc_engine *uc, uc_context *context)
|
|||
UC_INIT(uc);
|
||||
|
||||
memcpy(uc->cpu->env_ptr, context->data, context->context_size);
|
||||
if (list_exists(&uc->saved_contexts, context)) {
|
||||
memcpy(uc->cpu->jmp_env, context->data + context->context_size,
|
||||
context->jmp_env_size);
|
||||
}
|
||||
|
||||
return UC_ERR_OK;
|
||||
}
|
||||
|
@ -1911,11 +1888,7 @@ uc_err uc_context_restore(uc_engine *uc, uc_context *context)
|
|||
UNICORN_EXPORT
|
||||
uc_err uc_context_free(uc_context *context)
|
||||
{
|
||||
uc_engine *uc = context->uc;
|
||||
// if uc is NULL, it means that uc_engine has been free-ed.
|
||||
if (uc) {
|
||||
list_remove(&uc->saved_contexts, context);
|
||||
}
|
||||
|
||||
return uc_free(context);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue