Fix context saving (#1335)

* Fix context size

* Make UcContext convertible to bytes and picklable

Fix when updaing context

* Test context pickling

* Fix double free when the context is pickled from bytes
This commit is contained in:
lazymio
2020-09-24 00:53:23 +08:00
committed by GitHub
parent 21235916b9
commit 4441394258
3 changed files with 39 additions and 9 deletions

4
uc.c
View File

@@ -1321,12 +1321,12 @@ UNICORN_EXPORT
uc_err uc_context_alloc(uc_engine *uc, uc_context **context)
{
struct uc_context **_context = context;
size_t size = cpu_context_size(uc->arch, uc->mode);
size_t size = uc_context_size(uc);
*_context = malloc(size);
if (*_context) {
(*_context)->jmp_env_size = sizeof(*uc->cpu->jmp_env);
(*_context)->context_size = size - sizeof(uc_context) - (*_context)->jmp_env_size;
(*_context)->context_size = cpu_context_size(uc->arch, uc->mode);
return UC_ERR_OK;
} else {
return UC_ERR_NOMEM;