Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


modified copyright tags
[palacios.git] / palacios / src / palacios / vmm_mem.c
index c4747ee..3c7f5a7 100644 (file)
@@ -1,7 +1,11 @@
+/* (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> */
+/* (c) 2008, The V3VEE Project <http://www.v3vee.org> */
+
+
 #include <palacios/vmm_mem.h>
 #include <palacios/vmm.h>
 #include <palacios/vmm_util.h>
-#include <palacios/vmm_emulate.h>
+#include <palacios/vmm_decoder.h>
 
 
 
@@ -70,32 +74,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) 
+{
+
+  // emulate and then dispatch 
+  // or dispatch and emulate
 
-  if (access_info.write == 1) {
-    void * src = NULL;
-    uint_t length = 0;
-    PrintDebug("Memory hook write\n");
-    return -1;
 
-    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;
   }
@@ -106,7 +120,9 @@ int handle_special_page_fault(struct guest_info * info, addr_t mem_addr, pf_erro
 
 
 
-void init_shadow_map(struct shadow_map * map) {
+void init_shadow_map(struct guest_info * info) {
+  struct shadow_map * map = &(info->mem_map);
+
   map->num_regions = 0;
 
   map->head = NULL;
@@ -172,7 +188,6 @@ int add_shadow_region(struct shadow_map * map,
     } else if (cursor->next->guest_end <= region->guest_start) {
       cursor = cursor->next;
     } else {
-      PrintDebug("WTF?\n");
       // This cannot happen!
       // we should panic here
       return -1;
@@ -194,7 +209,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;
 
@@ -210,7 +225,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) {