From: Alexander Merritt Date: Tue, 3 Aug 2010 22:40:41 +0000 (-0500) Subject: added new vmm_mem function to find next memory region X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=2c0f0d4f13ebf9071bede458a0d682513082beb3;p=palacios.git added new vmm_mem function to find next memory region --- diff --git a/palacios/include/palacios/vmm_mem.h b/palacios/include/palacios/vmm_mem.h index 7b6d5d4..a8e776a 100644 --- a/palacios/include/palacios/vmm_mem.h +++ b/palacios/include/palacios/vmm_mem.h @@ -103,6 +103,7 @@ int v3_add_shadow_mem(struct v3_vm_info * vm, uint16_t core_id, struct v3_mem_region * v3_get_mem_region(struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr); +struct v3_mem_region * v3_get_next_mem_region(struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr); diff --git a/palacios/src/palacios/vmm_mem.c b/palacios/src/palacios/vmm_mem.c index 3e59d3a..ab8fc2c 100644 --- a/palacios/src/palacios/vmm_mem.c +++ b/palacios/src/palacios/vmm_mem.c @@ -189,8 +189,7 @@ struct v3_mem_region * __insert_mem_region(struct v3_vm_info * vm, -int v3_insert_mem_region(struct v3_vm_info * vm, - struct v3_mem_region * region) { +int v3_insert_mem_region(struct v3_vm_info * vm, struct v3_mem_region * region) { struct v3_mem_region * ret; int i = 0; @@ -283,8 +282,44 @@ struct v3_mem_region * v3_get_mem_region(struct v3_vm_info * vm, uint16_t core_i return NULL; } - - + + return &(vm->mem_map.base_region); +} + + + +/* Search the "hooked" memory regions for a region that ends after the given address. If the + * address is invalid, return NULL. Else, return the first region found or the base region if no + * region ends after the given address. + */ +struct v3_mem_region * v3_get_next_mem_region( struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr) { + struct rb_node * n = vm->mem_map.mem_regions.rb_node; + struct v3_mem_region * reg = NULL; + + // Keep going to the right in the tree while the address is greater than the current region's + // end address. + while (n) { + reg = rb_entry(n, struct v3_mem_region, tree_node); + if (guest_addr >= reg->guest_end) { // reg is [start,end) + n = n->rb_right; + } else { + if ((core_id == reg->core_id) || (reg->core_id == V3_MEM_CORE_ANY)) { + return reg; + } else { + n = n->rb_right; + } + } + } + + // There is no registered region, so we check if it's a valid address in the base region + + if (guest_addr >= vm->mem_map.base_region.guest_end) { + PrintError("%s: Guest Address Exceeds Base Memory Size (ga=%p), (limit=%p)\n", + __FUNCTION__, (void *)guest_addr, (void *)vm->mem_map.base_region.guest_end); + v3_print_mem_map(vm); + return NULL; + } + return &(vm->mem_map.base_region); }