diff --git a/qemu/exec.c b/qemu/exec.c index ac4e5492..45895113 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -1645,9 +1645,9 @@ MemoryRegion *iotlb_to_region(CPUState *cpu, hwaddr index, MemTxAttrs attrs) return sections[index & ~TARGET_PAGE_MASK].mr; } -void phys_mem_clean(struct uc_struct* uc) +void phys_mem_clean(AddressSpace *as) { - AddressSpaceDispatch* d = uc->as.next_dispatch; + AddressSpaceDispatch* d = as->next_dispatch; g_free(d->map.sections); } diff --git a/qemu/include/exec/exec-all.h b/qemu/include/exec/exec-all.h index 7148da04..e22be9e0 100644 --- a/qemu/include/exec/exec-all.h +++ b/qemu/include/exec/exec-all.h @@ -457,6 +457,7 @@ static inline bool cpu_can_do_io(CPUState *cpu) return true; } -void phys_mem_clean(struct uc_struct* uc); +// Unicorn: Used for freeing +void phys_mem_clean(AddressSpace *as); #endif diff --git a/qemu/unicorn_common.h b/qemu/unicorn_common.h index 8dcbb3e5..605fca7c 100644 --- a/qemu/unicorn_common.h +++ b/qemu/unicorn_common.h @@ -27,9 +27,7 @@ static void release_common(void *t) { TCGPool *po, *to; TCGContext *s = (TCGContext *)t; -#if TCG_TARGET_REG_BITS == 32 int i; -#endif // Clean TCG. TCGOpDef* def = &s->tcg_op_defs[0]; @@ -46,8 +44,11 @@ static void release_common(void *t) // TODO(danghvu): these function is not available outside qemu // so we keep them here instead of outside uc_close. - phys_mem_clean(s->uc); - address_space_destroy(&(s->uc->as)); + for (i = 0; i < s->uc->cpu->num_ases; i++) { + AddressSpace *as = s->uc->cpu->cpu_ases[i].as; + phys_mem_clean(as); + address_space_destroy(as); + } memory_free(s->uc); tb_cleanup(s->uc); free_code_gen_buffer(s->uc); diff --git a/uc.c b/uc.c index 1bc8a193..31a05972 100644 --- a/uc.c +++ b/uc.c @@ -429,7 +429,7 @@ uc_err uc_mem_read(uc_engine *uc, uint64_t address, void *_bytes, size_t size) MemoryRegion *mr = memory_mapping(uc, address); if (mr) { len = (size_t)MIN(size - count, mr->end - address); - if (uc->read_mem(&uc->as, address, bytes, len) == false) + if (uc->read_mem(uc->cpu->as, address, bytes, len) == false) break; count += len; address += len; @@ -467,7 +467,7 @@ uc_err uc_mem_write(uc_engine *uc, uint64_t address, const void *_bytes, size_t uc->readonly_mem(mr, false); len = (size_t)MIN(size - count, mr->end - address); - if (uc->write_mem(&uc->as, address, bytes, len) == false) + if (uc->write_mem(uc->cpu->as, address, bytes, len) == false) break; if (!(operms & UC_PROT_WRITE)) // write protected