@ -341,7 +341,6 @@ struct uc_struct {
|
|||||||
// default)
|
// default)
|
||||||
bool first_tb; // is this the first Translation-Block ever generated since
|
bool first_tb; // is this the first Translation-Block ever generated since
|
||||||
// uc_emu_start()?
|
// 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.
|
// 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.
|
||||||
@ -351,14 +350,11 @@ struct uc_struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Metadata stub for the variable-size cpu context used with uc_context_*()
|
// 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 {
|
struct uc_context {
|
||||||
size_t context_size; // size of the real internal context structure
|
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_mode mode; // the mode of this context (uc may be free-ed already)
|
uc_arch arch; // the arch of this context
|
||||||
uc_arch arch; // the arch of this context (uc may be free-ed already)
|
char data[0]; // context
|
||||||
struct uc_struct *uc; // the uc_struct which creates this context
|
|
||||||
char data[0]; // context + cpu->jmp_env
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// check if this address is mapped in (via uc_mem_map())
|
// check if this address is mapped in (via uc_mem_map())
|
||||||
|
31
uc.c
31
uc.c
@ -431,16 +431,6 @@ uc_err uc_close(uc_engine *uc)
|
|||||||
|
|
||||||
free(uc->mapped_blocks);
|
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);
|
g_tree_destroy(uc->exits);
|
||||||
|
|
||||||
// finally, free uc itself.
|
// finally, free uc itself.
|
||||||
@ -1690,19 +1680,13 @@ uc_err uc_context_alloc(uc_engine *uc, uc_context **context)
|
|||||||
|
|
||||||
*_context = g_malloc(size);
|
*_context = g_malloc(size);
|
||||||
if (*_context) {
|
if (*_context) {
|
||||||
(*_context)->jmp_env_size = sizeof(*uc->cpu->jmp_env);
|
|
||||||
(*_context)->context_size = uc->cpu_context_size;
|
(*_context)->context_size = uc->cpu_context_size;
|
||||||
(*_context)->arch = uc->arch;
|
(*_context)->arch = uc->arch;
|
||||||
(*_context)->mode = uc->mode;
|
(*_context)->mode = uc->mode;
|
||||||
(*_context)->uc = uc;
|
|
||||||
if (list_insert(&uc->saved_contexts, *_context)) {
|
|
||||||
return UC_ERR_OK;
|
return UC_ERR_OK;
|
||||||
} else {
|
} else {
|
||||||
return UC_ERR_NOMEM;
|
return UC_ERR_NOMEM;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return UC_ERR_NOMEM;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
@ -1717,8 +1701,7 @@ size_t uc_context_size(uc_engine *uc)
|
|||||||
{
|
{
|
||||||
UC_INIT(uc);
|
UC_INIT(uc);
|
||||||
// return the total size of struct uc_context
|
// return the total size of struct uc_context
|
||||||
return sizeof(uc_context) + uc->cpu_context_size +
|
return sizeof(uc_context) + uc->cpu_context_size;
|
||||||
sizeof(*uc->cpu->jmp_env);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
@ -1727,8 +1710,6 @@ uc_err uc_context_save(uc_engine *uc, uc_context *context)
|
|||||||
UC_INIT(uc);
|
UC_INIT(uc);
|
||||||
|
|
||||||
memcpy(context->data, uc->cpu->env_ptr, context->context_size);
|
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;
|
return UC_ERR_OK;
|
||||||
}
|
}
|
||||||
@ -1900,10 +1881,6 @@ uc_err uc_context_restore(uc_engine *uc, uc_context *context)
|
|||||||
UC_INIT(uc);
|
UC_INIT(uc);
|
||||||
|
|
||||||
memcpy(uc->cpu->env_ptr, context->data, context->context_size);
|
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;
|
return UC_ERR_OK;
|
||||||
}
|
}
|
||||||
@ -1911,11 +1888,7 @@ uc_err uc_context_restore(uc_engine *uc, uc_context *context)
|
|||||||
UNICORN_EXPORT
|
UNICORN_EXPORT
|
||||||
uc_err uc_context_free(uc_context *context)
|
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);
|
return uc_free(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user