8 #include <palacios/vmm_types.h>
10 #include <palacios/vmm_paging.h>
18 Virtual Physical Virtual Physical Virtual Physical
26 // These are the types of physical memory address regions
27 // from the perspective of the guest
28 typedef enum guest_region_type {
30 GUEST_REGION_PHYSICAL_MEMORY,
31 GUEST_REGION_MEMORY_MAPPED_DEVICE} guest_region_type_t;
33 // These are the types of physical memory address regions
34 // from the perspective of the HOST
35 typedef enum host_region_type {
36 HOST_REGION_INVALID, // This region is INVALID (this is a return type, to denote errors)
37 HOST_REGION_HOOK, // This region is mapped as not present (always generate page faults)
38 HOST_REGION_PHYSICAL_MEMORY, // Region is a section of host memory
39 HOST_REGION_MEMORY_MAPPED_DEVICE, // Region is allocated for DMA
40 HOST_REGION_UNALLOCATED, // Region is mapped on demand
41 HOST_REGION_REMOTE, // Region is located on a remote machine
42 HOST_REGION_SWAPPED, // Region is swapped
47 #define shadow_mem_type_t host_region_type_t
49 struct shadow_region {
50 guest_region_type_t guest_type;
54 host_region_type_t host_type;
55 addr_t host_addr; // This either points to a host address mapping,
56 // or a structure holding the map info
58 struct shadow_region *next, *prev;
66 struct shadow_region * head;
70 void init_shadow_region(struct shadow_region * entry,
71 addr_t guest_addr_start,
72 addr_t guest_addr_end,
73 guest_region_type_t guest_region_type,
74 host_region_type_t host_region_type);
77 void init_shadow_region_physical(struct shadow_region * entry,
78 addr_t guest_addr_start,
79 addr_t guest_addr_end,
80 guest_region_type_t guest_region_type,
81 addr_t host_addr_start,
82 host_region_type_t host_region_type);
85 int add_shadow_region_passthrough(struct guest_info * guest_info,
86 addr_t guest_addr_start,
87 addr_t guest_addr_end,
90 void init_shadow_map(struct guest_info * info);
91 void free_shadow_map(struct shadow_map * map);
93 struct shadow_region * get_shadow_region_by_addr(struct shadow_map * map, addr_t guest_addr);
95 struct shadow_region * get_shadow_region_by_index(struct shadow_map * map, uint_t index);
97 host_region_type_t lookup_shadow_map_addr(struct shadow_map * map, addr_t guest_addr, addr_t * host_addr);
99 host_region_type_t get_shadow_addr_type(struct guest_info * info, addr_t guest_addr);
100 addr_t get_shadow_addr(struct guest_info * info, addr_t guest_addr);
103 // Adding a region that overlaps with an existing region results is undefined
104 // and will probably fail
105 int add_shadow_region(struct shadow_map * map, struct shadow_region * entry);
108 // Deletions result in splitting
109 int delete_shadow_region(struct shadow_map * map,
114 void print_shadow_map(struct shadow_map * map);
120 struct vmm_mem_hook {
121 // Called when data is read from a memory page
122 int (*read)(addr_t guest_addr, void * dst, uint_t length, void * priv_data);
124 // Called when data is written to a memory page
125 int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data);
128 struct shadow_region * region;
133 struct vmm_mem_hook * get_mem_hook(struct guest_info * info, addr_t guest_addr);
135 int hook_guest_mem(struct guest_info * info, addr_t guest_addr_start, addr_t guest_addr_end,
136 int (*read)(addr_t guest_addr, void * dst, uint_t length, void * priv_data),
137 int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data),
139 int unhook_guest_mem(struct guest_info * info, addr_t guest_addr);
144 int mem_hook_dispatch(struct guest_info * info, addr_t mem_addr, pf_error_t access_info, struct vmm_mem_hook * hook);
145 int handle_special_page_fault(struct guest_info * info, addr_t mem_addr, pf_error_t access_info);
148 #endif // ! __V3VEE__