6 #include <palacios/vmm_types.h>
8 #include <palacios/vmm_paging.h>
16 Virtual Physical Virtual Physical Virtual Physical
24 // These are the types of physical memory address regions
25 // from the perspective of the guest
26 typedef enum guest_region_type {
28 GUEST_REGION_PHYSICAL_MEMORY,
29 GUEST_REGION_MEMORY_MAPPED_DEVICE} guest_region_type_t;
31 // These are the types of physical memory address regions
32 // from the perspective of the HOST
33 typedef enum host_region_type {
34 HOST_REGION_INVALID, // This region is INVALID (this is a return type, to denote errors)
35 HOST_REGION_HOOK, // This region is mapped as not present (always generate page faults)
36 HOST_REGION_PHYSICAL_MEMORY, // Region is a section of host memory
37 HOST_REGION_MEMORY_MAPPED_DEVICE, // Region is allocated for DMA
38 HOST_REGION_UNALLOCATED, // Region is mapped on demand
39 HOST_REGION_REMOTE, // Region is located on a remote machine
40 HOST_REGION_SWAPPED, // Region is swapped
45 #define shadow_mem_type_t host_region_type_t
47 struct shadow_region {
48 guest_region_type_t guest_type;
52 host_region_type_t host_type;
53 addr_t host_addr; // This either points to a host address mapping,
54 // or a structure holding the map info
56 struct shadow_region *next, *prev;
64 struct shadow_region * head;
68 void init_shadow_region(struct shadow_region * entry,
69 addr_t guest_addr_start,
70 addr_t guest_addr_end,
71 guest_region_type_t guest_region_type,
72 host_region_type_t host_region_type);
75 void init_shadow_region_physical(struct shadow_region * entry,
76 addr_t guest_addr_start,
77 addr_t guest_addr_end,
78 guest_region_type_t guest_region_type,
79 addr_t host_addr_start,
80 host_region_type_t host_region_type);
83 int add_shadow_region_passthrough(struct guest_info * guest_info,
84 addr_t guest_addr_start,
85 addr_t guest_addr_end,
88 void init_shadow_map(struct shadow_map * map);
89 void free_shadow_map(struct shadow_map * map);
91 struct shadow_region * get_shadow_region_by_addr(struct shadow_map * map, addr_t guest_addr);
93 struct shadow_region * get_shadow_region_by_index(struct shadow_map * map, uint_t index);
95 host_region_type_t lookup_shadow_map_addr(struct shadow_map * map, addr_t guest_addr, addr_t * host_addr);
97 host_region_type_t get_shadow_addr_type(struct guest_info * info, addr_t guest_addr);
98 addr_t get_shadow_addr(struct guest_info * info, addr_t guest_addr);
101 // Adding a region that overlaps with an existing region results is undefined
102 // and will probably fail
103 int add_shadow_region(struct shadow_map * map, struct shadow_region * entry);
106 // Deletions result in splitting
107 int delete_shadow_region(struct shadow_map * map,
112 void print_shadow_map(struct shadow_map * map);
118 struct vmm_mem_hook {
119 // Called when data is read from a memory page
120 int (*read)(addr_t guest_addr, void * dst, uint_t length, void * priv_data);
122 // Called when data is written to a memory page
123 int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data);
126 struct shadow_region * region;
131 struct vmm_mem_hook * get_mem_hook(struct guest_info * info, addr_t guest_addr);
133 int hook_guest_mem(struct guest_info * info, addr_t guest_addr_start, addr_t guest_addr_end,
134 int (*read)(addr_t guest_addr, void * dst, uint_t length, void * priv_data),
135 int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data),
137 int unhook_guest_mem(struct guest_info * info, addr_t guest_addr);
142 int mem_hook_dispatch(struct guest_info * info, addr_t mem_addr, pf_error_t access_info, struct vmm_mem_hook * hook);
143 int handle_special_page_fault(struct guest_info * info, addr_t mem_addr, pf_error_t access_info);