7 struct v3_guest_mem_block {
8 void *gpa; // guest physical address this region starts at
9 void *cumgpa; // cumulative GPA in the VM including this block
10 void *hpa; // mapped to this host physical address
11 void *uva; // which is mapped here in this process
12 uint64_t numpages; // this many 4K pages
15 // Whole memory map of guest's physical memory
16 // that is backed by host physical memory (ie, everything we
17 // can read or write from the host user space)
18 struct v3_guest_mem_map {
19 int fd; // used by mmap
21 struct v3_guest_mem_block block[0];
24 // This function gets the basic memory map, but does not map it
25 struct v3_guest_mem_map * v3_guest_mem_get_map(char *vmdev);
26 // This function mmaps it into the guest address space
27 // and fills out the "myaddr" fields
28 int v3_map_guest_mem(struct v3_guest_mem_map *map);
29 // This function unmaps it - it assumes myaddrs are valid
30 int v3_unmap_guest_mem(struct v3_guest_mem_map *map);
31 // What is the first GPA of this guest that contains memory ?
32 void *v3_gpa_start(struct v3_guest_mem_map *map);
33 // What is the last GPA of this guest that contains memory ?
34 void *v3_gpa_end(struct v3_guest_mem_map *map);
35 // map from a gpa to a uva, optionally giving the number of
36 // subsequent bytes for which the mapping is continguous
37 static inline void *v3_gpa_to_uva(struct v3_guest_mem_map *map, void *gpa, uint64_t *num_bytes)
39 uint64_t left, right, middle;
43 if (num_bytes) { *num_bytes=0;}
47 left = 0; right=map->numblocks-1;
50 middle = (right+left)/2;
51 if (gpa > map->block[middle].cumgpa) {
53 } else if (gpa < map->block[middle].gpa) {
62 *num_bytes = map->block[middle].cumgpa - gpa + 1;
64 return map->block[middle].uva + (gpa - map->block[middle].gpa);
73 // efficiently map function over the specified guest memory
74 int v3_guest_mem_apply(void (*func)(void *data, uint64_t num_bytes, void *priv),
75 struct v3_guest_mem_map *map, void *gpa, uint64_t num_bytes, void *priv);
77 // read data out of guest
78 int v3_guest_mem_read(struct v3_guest_mem_map *map, void *gpa, uint64_t num_bytes, char *data);
80 // write data into guest
81 int v3_guest_mem_write(struct v3_guest_mem_map *map, void *gpa, uint64_t num_bytes, char *data);
83 // hash the guest's data
84 int v3_guest_mem_hash(struct v3_guest_mem_map *map, void *gpa, uint64_t num_bytes, uint64_t *hash);