2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
28 #include <palacios/vmm_types.h>
30 #include <palacios/vmm_paging.h>
36 // These are the types of physical memory address regions
37 // from the perspective of the HOST
38 typedef enum shdw_region_type {
39 SHDW_REGION_INVALID, // This region is INVALID (this is a return type to denote errors)
40 SHDW_REGION_WRITE_HOOK, // This region is mapped as read-only (page faults on write)
41 SHDW_REGION_FULL_HOOK, // This region is mapped as not present (always generate page faults)
42 SHDW_REGION_ALLOCATED, // Region is a section of host memory
43 SHDW_REGION_UNALLOCATED, // Region is mapped on demand
50 struct shadow_region {
54 shdw_region_type_t host_type;
56 addr_t host_addr; // This either points to a host address mapping
59 // Called when data is read from a memory page
60 int (*read_hook)(addr_t guest_addr, void * dst, uint_t length, void * priv_data);
61 // Called when data is written to a memory page
62 int (*write_hook)(addr_t guest_addr, void * src, uint_t length, void * priv_data);
66 struct shadow_region *next, *prev;
74 struct shadow_region * head;
79 void init_shadow_region(struct shadow_region * entry,
80 addr_t guest_addr_start,
81 addr_t guest_addr_end,
82 shdw_region_type_t shdw_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 shdw_region_type_t lookup_shadow_map_addr(struct shadow_map * map, addr_t guest_addr, addr_t * host_addr);
99 shdw_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);
118 struct shadow_region * v3_get_shadow_region(struct guest_info * info, addr_t addr);
120 int v3_hook_full_mem(struct guest_info * info, addr_t guest_addr_start, addr_t guest_addr_end,
121 int (*read)(addr_t guest_addr, void * dst, uint_t length, void * priv_data),
122 int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data),
125 int v3_hook_write_mem(struct guest_info * info, addr_t guest_addr_start, addr_t guest_addr_end,
127 int (*write)(addr_t guest_addr, void * src, uint_t length, void * priv_data),
130 int unhook_guest_mem(struct guest_info * info, addr_t guest_addr);
134 const uchar_t * shdw_region_type_to_str(shdw_region_type_t type);
137 int handle_special_page_fault(struct guest_info * info, addr_t fault_addr, addr_t gp_addr, pf_error_t access_info);
139 int v3_handle_mem_wr_hook(struct guest_info * info, addr_t guest_va, addr_t guest_pa,
140 struct shadow_region * reg, pf_error_t access_info);
141 int v3_handle_mem_full_hook(struct guest_info * info, addr_t guest_va, addr_t guest_pa,
142 struct shadow_region * reg, pf_error_t access_info);
144 #endif // ! __V3VEE__