X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_mem.c;h=07006832f92399da79a44466bfe11bf9225257f5;hb=f9bb3db89469169bb5775dc031d89e570c6fed70;hp=4062f1f665440ee7bc8e299891023e3e116b7323;hpb=6fa12b728fed57e76c4a4df5c87d989915c7d6c2;p=palacios.git diff --git a/palacios/src/palacios/vmm_mem.c b/palacios/src/palacios/vmm_mem.c index 4062f1f..0700683 100644 --- a/palacios/src/palacios/vmm_mem.c +++ b/palacios/src/palacios/vmm_mem.c @@ -1,3 +1,6 @@ +/* Northwestern University */ +/* (c) 2008, Jack Lange */ + #include #include #include @@ -70,32 +73,42 @@ struct vmm_mem_hook * get_mem_hook(struct guest_info * info, addr_t guest_addr) } -int mem_hook_dispatch(struct guest_info * info, addr_t mem_addr, pf_error_t access_info, struct vmm_mem_hook * hook) { +/* mem_addr is the guest physical memory address */ +static int mem_hook_dispatch(struct guest_info * info, + addr_t fault_gva, addr_t fault_gpa, + pf_error_t access_info, struct vmm_mem_hook * hook) +{ - if (access_info.write == 1) { - void * src = NULL; - uint_t length = 0; - PrintDebug("Memory hook write\n"); - return -1; + // emulate and then dispatch + // or dispatch and emulate - if (hook->write(mem_addr, src, length, hook->priv_data) != length) { + + if (access_info.write == 1) { + if (v3_emulate_memory_write(info, fault_gva, hook->write, fault_gpa, hook->priv_data) == -1) { + PrintError("Memory write emulation failed\n"); return -1; } + } else { - PrintDebug("Memory hook read\n"); - return -1; + if (v3_emulate_memory_read(info, fault_gva, hook->read, fault_gpa, hook->priv_data) == -1) { + PrintError("Memory read emulation failed\n"); + return -1; + } } - return -1; + return 0; } -int handle_special_page_fault(struct guest_info * info, addr_t mem_addr, pf_error_t access_info) { - struct shadow_region * reg = get_shadow_region_by_addr(&(info->mem_map), mem_addr); +int handle_special_page_fault(struct guest_info * info, + addr_t fault_gva, addr_t fault_gpa, + pf_error_t access_info) +{ + struct shadow_region * reg = get_shadow_region_by_addr(&(info->mem_map), fault_gpa); switch (reg->host_type) { case HOST_REGION_HOOK: - return mem_hook_dispatch(info, mem_addr, access_info, (struct vmm_mem_hook *)(reg->host_addr)); + return mem_hook_dispatch(info, fault_gva, fault_gpa, access_info, (struct vmm_mem_hook *)(reg->host_addr)); default: return -1; } @@ -195,7 +208,7 @@ int delete_shadow_region(struct shadow_map * map, struct shadow_region *get_shadow_region_by_index(struct shadow_map * map, - uint_t index) { + uint_t index) { struct shadow_region * reg = map->head; uint_t i = 0; @@ -211,7 +224,7 @@ struct shadow_region *get_shadow_region_by_index(struct shadow_map * map, struct shadow_region * get_shadow_region_by_addr(struct shadow_map * map, - addr_t addr) { + addr_t addr) { struct shadow_region * reg = map->head; while (reg) {