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.


moved internal memory map routines over to new flags structure instead of the hardcod...
[palacios.git] / palacios / include / palacios / vmm_mem.h
1 /*
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.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
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.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #ifndef __VMM_MEM_H
22 #define __VMM_MEM_H
23
24
25 #ifdef __V3VEE__ 
26
27
28 #include <palacios/vmm_types.h>
29
30 #include <palacios/vmm_paging.h>
31 #include <palacios/vmm_rbtree.h>
32 #include <palacios/vmm_list.h>
33
34 struct guest_info;
35 struct v3_vm_info;
36
37
38
39 // These are the types of physical memory address regions
40 // from the perspective of the HOST
41 typedef enum shdw_region_type { 
42     SHDW_REGION_WRITE_HOOK,                 // This region is mapped as read-only (page faults on write)
43     SHDW_REGION_FULL_HOOK,                  // This region is mapped as not present (always generate page faults)
44     SHDW_REGION_ALLOCATED,                  // Region is a section of host memory
45     SHDW_REGION_BASE,
46 } v3_shdw_region_type_t;
47
48 #define V3_MEM_CORE_ANY ((uint16_t)-1)
49
50
51
52 typedef struct {
53     union {
54         uint16_t value;
55         struct {
56             uint8_t read   : 1;
57             uint8_t write  : 1;
58             uint8_t exec   : 1;
59             uint8_t hook   : 1;
60             uint8_t base   : 1;
61             uint8_t alloced : 1;
62         } __attribute__((packed));
63     } __attribute__((packed));
64 } __attribute__((packed)) v3_mem_flags_t;
65
66
67
68 struct v3_shadow_region {
69     addr_t                  guest_start; 
70     addr_t                  guest_end; 
71
72     v3_shdw_region_type_t   host_type;
73     v3_mem_flags_t          flags;
74
75     addr_t                  host_addr; // This either points to a host address mapping
76
77     // Called when data is read from a memory page
78     int (*read_hook)(struct guest_info * core, addr_t guest_addr, void * dst, uint_t length, void * priv_data);
79     // Called when data is written to a memory page
80     int (*write_hook)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data);
81
82     void * priv_data;
83
84     int core_id;
85
86     struct rb_node tree_node; // This for memory regions mapped to the global map
87 };
88
89
90 struct v3_mem_map {
91     struct v3_shadow_region base_region;
92
93     struct rb_root shdw_regions;
94
95     void * hook_hvas; // this is an array of pages, equal to the number of cores
96 };
97
98
99 int v3_init_mem_map(struct v3_vm_info * vm);
100 void v3_delete_mem_map(struct v3_vm_info * vm);
101
102
103
104
105 int v3_add_shadow_mem(struct v3_vm_info * vm, uint16_t core_id,
106                       addr_t guest_addr_start, addr_t guest_addr_end, addr_t host_addr);
107
108 int v3_hook_full_mem(struct v3_vm_info * vm, uint16_t core_id,
109                      addr_t guest_addr_start, addr_t guest_addr_end,
110                      int (*read)(struct guest_info * core, addr_t guest_addr, void * dst, uint_t length, void * priv_data),
111                      int (*write)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data),
112                      void * priv_data);
113
114 int v3_hook_write_mem(struct v3_vm_info * vm, uint16_t core_id, 
115                       addr_t guest_addr_start, addr_t guest_addr_end, addr_t host_addr,
116                       int (*write)(struct guest_info * core, addr_t guest_addr, void * src, uint_t length, void * priv_data),
117                       void * priv_data);
118
119
120 int v3_unhook_mem(struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr_start);
121
122
123
124
125
126 void v3_delete_shadow_region(struct v3_vm_info * vm, struct v3_shadow_region * reg);
127
128
129
130
131 struct v3_shadow_region * v3_get_shadow_region(struct v3_vm_info * vm, uint16_t core_id, addr_t guest_addr);
132
133
134 addr_t v3_get_shadow_addr(struct v3_shadow_region * reg, uint16_t core_id, addr_t guest_addr);
135
136
137
138
139
140 void v3_print_mem_map(struct v3_vm_info * vm);
141
142
143
144 int v3_handle_mem_hook(struct guest_info * info, addr_t guest_va, addr_t guest_pa, 
145                        struct v3_shadow_region * reg, pf_error_t access_info);
146
147
148 #endif // ! __V3VEE__
149
150
151 #endif