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.


added extension framework with initial inspector extension
[palacios.git] / palacios / src / extensions / ext_inspector.c
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 //#include <palacios/vmm_inspector.h>
22 #include <palacios/vmm.h>
23 #include <palacios/vm_guest.h>
24 #include <palacios/vmm_sprintf.h>
25 #include <palacios/vmm_extensions.h>
26
27 #include <palacios/vmm_multitree.h>
28 #include <interfaces/inspector.h>
29
30 // Note that v3_inspect_node_t is actuall a struct v3_mtree
31 // Its set as void for opaque portability
32
33 struct v3_inspector_state {
34     struct v3_mtree state_tree;
35
36 };
37
38
39 static int init_inspector(struct v3_vm_info * vm, v3_cfg_tree_t * cfg, void ** priv_data) {
40     struct v3_inspector_state * state = V3_Malloc(sizeof(struct v3_inspector_state));
41     memset(state, 0, sizeof(struct v3_inspector_state));
42
43     strncpy(state->state_tree.name, "vm->name", 50);
44     state->state_tree.subtree = 1;
45
46     *priv_data = state;
47
48     return 0;
49 }
50
51
52 static int init_inspector_core(struct guest_info * core, void * priv_data) {
53     struct v3_inspector_state * vm_state = priv_data;
54     char core_name[50];
55
56     snprintf(core_name, 50, "core.%d", core->cpu_id);
57
58     {
59         struct v3_mtree * core_node = v3_mtree_create_subtree(&(vm_state->state_tree), core_name);
60         v3_inspect_64(core_node, "RIP", (uint64_t *)&(core->rip));
61         v3_inspect_64(core_node, "NUM_EXITS", (uint64_t *)&(core->num_exits));
62         //      v3_inspect_buf(core_node, "EXEC_NAME", core->exec_name, sizeof(core->exec_name));
63
64
65         struct v3_mtree * gpr_node = v3_mtree_create_subtree(core_node, "GPRS");
66         v3_inspect_64(gpr_node, "RAX", (uint64_t *)&(core->vm_regs.rax));    
67         v3_inspect_64(gpr_node, "RBX", (uint64_t *)&(core->vm_regs.rbx));    
68         v3_inspect_64(gpr_node, "RCX", (uint64_t *)&(core->vm_regs.rcx));    
69         v3_inspect_64(gpr_node, "RDX", (uint64_t *)&(core->vm_regs.rdx));    
70         v3_inspect_64(gpr_node, "RSP", (uint64_t *)&(core->vm_regs.rsp));    
71         v3_inspect_64(gpr_node, "RBP", (uint64_t *)&(core->vm_regs.rbp));    
72         v3_inspect_64(gpr_node, "RSI", (uint64_t *)&(core->vm_regs.rsi));    
73         v3_inspect_64(gpr_node, "RDI", (uint64_t *)&(core->vm_regs.rdi));    
74
75
76         struct v3_mtree * cr_node = v3_mtree_create_subtree(core_node, "CTRL_REGS");
77         v3_inspect_64(cr_node, "CR0", (uint64_t *)&(core->ctrl_regs.cr0));    
78         v3_inspect_64(cr_node, "CR2", (uint64_t *)&(core->ctrl_regs.cr2));    
79         v3_inspect_64(cr_node, "CR3", (uint64_t *)&(core->ctrl_regs.cr3));    
80         v3_inspect_64(cr_node, "CR4", (uint64_t *)&(core->ctrl_regs.cr4));    
81         v3_inspect_64(cr_node, "RFLAGS", (uint64_t *)&(core->ctrl_regs.rflags));    
82         v3_inspect_64(cr_node, "EFER", (uint64_t *)&(core->ctrl_regs.efer));    
83
84
85         //struct v3_mtree * seg_node = v3_mtree_create_subtree(core_node, "SEGMENTS");
86         
87
88
89     }
90
91     return 0;
92 }
93
94
95
96
97
98 static struct v3_extension_impl inspector_impl = {
99     .name = "inspector",
100     .init = init_inspector,
101     .deinit = NULL,
102     .core_init = init_inspector_core,
103     .core_deinit = NULL,
104     .on_entry = NULL,
105     .on_exit = NULL
106 };
107
108
109 register_extension(&inspector_impl);
110
111
112 v3_inspect_node_t * v3_inspect_add_subtree(v3_inspect_node_t * root, char * name) {
113     return v3_mtree_create_subtree(root, name);
114 }
115
116 int v3_inspect_8(v3_inspect_node_t * node, char * name, uint8_t * val) {
117     v3_mtree_create_value(node, name, 1, val);
118     return 0;
119 }
120
121
122 int v3_inspect_16(v3_inspect_node_t * node, char * name, uint16_t * val) {
123     v3_mtree_create_value(node, name, 2, val);
124
125     return 0;
126 }
127
128 int v3_inspect_32(v3_inspect_node_t * node, char * name, uint32_t * val) {
129     v3_mtree_create_value(node, name, 4, val); 
130     return 0;
131 }
132
133 int v3_inspect_64(v3_inspect_node_t * node, char * name, uint64_t * val) {
134     v3_mtree_create_value(node, name, 8, val);
135     return 0;
136 }
137
138 int v3_inspect_addr(v3_inspect_node_t * node, char * name, addr_t * val) {
139     v3_mtree_create_value(node, name, sizeof(addr_t), val);
140     return 0;
141 }
142
143 int v3_inspect_buf(v3_inspect_node_t * node, char * name, 
144                    uint8_t * buf, uint64_t size) {
145     v3_mtree_create_value(node, name, size, buf);
146
147     return 0;
148 }
149
150
151
152 int v3_find_inspection_value(v3_inspect_node_t * node, char * name, 
153                            struct v3_inspection_value * value) {
154     struct v3_mtree * mt_node = v3_mtree_find_node(node, name);
155     
156     if (!mt_node) {
157         return -1;
158     }
159     
160     *value = v3_inspection_value(mt_node);
161
162     return 0;
163 }
164
165 struct v3_inspection_value v3_inspection_value(v3_inspect_node_t * node) {
166     struct v3_mtree * mt_node = node;
167     struct v3_inspection_value value;
168
169     value.value = mt_node->value;
170     value.size = mt_node->size;
171     value.flags = mt_node->user_flags;
172     value.name = mt_node->name;
173
174     return value;
175 }
176
177
178
179 v3_inspect_node_t * v3_get_inspection_root(struct v3_vm_info * vm) {
180     struct v3_inspector_state * inspector = v3_get_extension_state(vm, inspector_impl.name);
181
182     if (inspector == NULL) {
183         return NULL;
184     }
185
186     return &(inspector->state_tree);
187 }
188
189 v3_inspect_node_t * v3_get_inspection_subtree(v3_inspect_node_t * root, char * name) {
190     return v3_mtree_find_subtree(root, name);
191 }
192
193
194 v3_inspect_node_t * v3_inspection_node_next(v3_inspect_node_t * node) {
195     return v3_mtree_next_node(node);
196 }
197
198 v3_inspect_node_t * v3_inspection_first_child(v3_inspect_node_t * root) {
199     return v3_mtree_first_child(root);
200 }
201
202
203
204