Fix save/restore to work while emulation is not active

This commit is contained in:
Andrew Dutcher 2016-09-08 14:41:34 -07:00
parent 885b809004
commit 3deb9fdcad
2 changed files with 3 additions and 3 deletions

View file

@ -740,7 +740,7 @@ static void test_i386_reg_save(void **state)
int32_t eax = 1; int32_t eax = 1;
// Initialize emulator // Initialize emulator
uc_assert_success(uc_open(UC_ARCH_X86, UC_MODE_16, &uc)); uc_assert_success(uc_open(UC_ARCH_X86, UC_MODE_32, &uc));
// map 8KB memory for this emulation // map 8KB memory for this emulation
uc_assert_success(uc_mem_map(uc, address, 8 * 1024, UC_PROT_ALL)); uc_assert_success(uc_mem_map(uc, address, 8 * 1024, UC_PROT_ALL));

4
uc.c
View file

@ -1184,12 +1184,12 @@ void *uc_save_regstate(uc_engine *uc, void *buffer) {
buffer = malloc(sz); buffer = malloc(sz);
} }
memcpy(buffer, uc->current_cpu->env_ptr, sz); memcpy(buffer, first_cpu->env_ptr, sz);
return buffer; return buffer;
} }
UNICORN_EXPORT UNICORN_EXPORT
void uc_restore_regstate(uc_engine *uc, void *buffer) { void uc_restore_regstate(uc_engine *uc, void *buffer) {
size_t sz = cpu_regs_size(uc->arch, uc->mode); size_t sz = cpu_regs_size(uc->arch, uc->mode);
memcpy(uc->current_cpu->env_ptr, buffer, sz); memcpy(first_cpu->env_ptr, buffer, sz);
} }