diff --git a/qemu/cpus.c b/qemu/cpus.c index 20185687..05978eaf 100644 --- a/qemu/cpus.c +++ b/qemu/cpus.c @@ -88,8 +88,11 @@ int qemu_init_vcpu(CPUState *cpu) /* If the target cpu hasn't set up any address spaces itself, * give it the default one. */ + AddressSpace *as = address_space_init_shareable(cpu->uc, + cpu->memory, + "cpu-memory"); cpu->num_ases = 1; - cpu_address_space_init(cpu, &cpu->uc->as, 0); + cpu_address_space_init(cpu, as, 0); } if (tcg_enabled(cpu->uc)) { diff --git a/qemu/exec.c b/qemu/exec.c index 45895113..e914e1ee 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -451,6 +451,25 @@ void cpu_exec_init(CPUState *cpu, void *opaque) // TODO: assert uc does not already have a cpu? uc->cpu = cpu; + +#ifndef CONFIG_USER_ONLY + + // Unicorn: commented out + /* This is a softmmu CPU object, so create a property for it + * so users can wire up its memory. (This can't go in qom/cpu.c + * because that file is compiled only once for both user-mode + * and system builds.) The default if no link is set up is to use + * the system address space. + */ + /*object_property_add_link(OBJECT(cpu), "memory", TYPE_MEMORY_REGION, + (Object **)&cpu->memory, + qdev_prop_allow_set_link_before_realize, + OBJ_PROP_LINK_UNREF_ON_RELEASE, + &error_abort);*/ + cpu->memory = uc->system_memory; + // Unicorn: commented out + /*object_ref(OBJECT(cpu->memory)); */ +#endif } #if defined(CONFIG_USER_ONLY) diff --git a/qemu/include/qom/cpu.h b/qemu/include/qom/cpu.h index 5b77e102..bd4dfdb8 100644 --- a/qemu/include/qom/cpu.h +++ b/qemu/include/qom/cpu.h @@ -264,6 +264,7 @@ struct CPUState { CPUAddressSpace *cpu_ases; int num_ases; AddressSpace *as; + MemoryRegion *memory; void *env_ptr; /* CPUArchState */ struct TranslationBlock *current_tb; diff --git a/qemu/unicorn_common.h b/qemu/unicorn_common.h index 605fca7c..bdb61778 100644 --- a/qemu/unicorn_common.h +++ b/qemu/unicorn_common.h @@ -44,6 +44,8 @@ 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->as); + 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);