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.


fixed all the printf style warnings/errors
[palacios.git] / palacios / src / palacios / vmm_mem.c
index 7c2a53a..b4a181f 100644 (file)
@@ -1,3 +1,22 @@
+/* 
+ * This file is part of the Palacios Virtual Machine Monitor developed
+ * by the V3VEE Project with funding from the United States National 
+ * Science Foundation and the Department of Energy.  
+ *
+ * The V3VEE Project is a joint project between Northwestern University
+ * and the University of New Mexico.  You can find out more at 
+ * http://www.v3vee.org
+ *
+ * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
+ * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
+ * All rights reserved.
+ *
+ * Author: Jack Lange <jarusl@cs.northwestern.edu>
+ *
+ * This is free software.  You are permitted to use,
+ * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
+ */
+
 #include <palacios/vmm_mem.h>
 #include <palacios/vmm.h>
 #include <palacios/vmm_util.h>
@@ -62,7 +81,7 @@ struct vmm_mem_hook * get_mem_hook(struct guest_info * info, addr_t guest_addr)
   struct shadow_region * region = get_shadow_region_by_addr(&(info->mem_map), guest_addr);
 
   if (region == NULL) {
-    PrintDebug("Could not find shadow region for addr: %x\n", guest_addr);
+    PrintDebug("Could not find shadow region for addr: %p\n", (void *)guest_addr);
     return NULL;
   }
 
@@ -70,32 +89,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;
   }
@@ -136,7 +165,8 @@ int add_shadow_region(struct shadow_map * map,
 {
   struct shadow_region * cursor = map->head;
 
-  PrintDebug("Adding Shadow Region: (0x%x-0x%x)\n", region->guest_start, region->guest_end);
+  PrintDebug("Adding Shadow Region: (0x%p-0x%p)\n", 
+            (void *)region->guest_start, (void *)region->guest_end);
 
   if ((!cursor) || (cursor->guest_start >= region->guest_end)) {
     region->prev = NULL;
@@ -174,7 +204,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;
@@ -196,7 +225,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;
 
@@ -212,7 +241,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) {
@@ -278,7 +307,8 @@ void print_shadow_map(struct shadow_map * map) {
   PrintDebug("Memory Layout (regions: %d) \n", map->num_regions);
 
   while (cur) {
-    PrintDebug("%d:  0x%x - 0x%x (%s) -> ", i, cur->guest_start, cur->guest_end - 1,
+    PrintDebug("%d:  0x%p - 0x%p (%s) -> ", i, 
+              (void *)cur->guest_start, (void *)(cur->guest_end - 1),
               cur->guest_type == GUEST_REGION_PHYSICAL_MEMORY ? "GUEST_REGION_PHYSICAL_MEMORY" :
               cur->guest_type == GUEST_REGION_NOTHING ? "GUEST_REGION_NOTHING" :
               cur->guest_type == GUEST_REGION_MEMORY_MAPPED_DEVICE ? "GUEST_REGION_MEMORY_MAPPED_DEVICE" :
@@ -286,7 +316,7 @@ void print_shadow_map(struct shadow_map * map) {
     if (cur->host_type == HOST_REGION_PHYSICAL_MEMORY || 
        cur->host_type == HOST_REGION_UNALLOCATED ||
        cur->host_type == HOST_REGION_MEMORY_MAPPED_DEVICE) { 
-      PrintDebug("0x%x", cur->host_addr);
+      PrintDebug("0x%p", (void *)(cur->host_addr));
     }
     PrintDebug("(%s)\n",
               cur->host_type == HOST_REGION_PHYSICAL_MEMORY ? "HOST_REGION_PHYSICAL_MEMORY" :