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 / palacios / vmm_extensions.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 #include <palacios/vmm.h>
21
22 #include <palacios/vmm_extensions.h>
23 #include <palacios/vm_guest.h>
24 #include <palacios/vmm_hashtable.h>
25
26
27 static struct hashtable * ext_table = NULL;
28
29
30 static uint_t ext_hash_fn(addr_t key) {
31     char * name = (char *)key;
32     return v3_hash_buffer((uint8_t *)name, strlen(name));
33 }
34
35 static int ext_eq_fn(addr_t key1, addr_t key2) {
36     char * name1 = (char *)key1;
37     char * name2 = (char *)key2;
38
39     return (strcmp(name1, name2) == 0);
40 }
41
42
43
44 int V3_init_extensions() {
45     extern struct v3_extension_impl * __start__v3_extensions[];
46     extern struct v3_extension_impl * __stop__v3_extensions[];
47     struct v3_extension_impl ** tmp_ext = __start__v3_extensions;
48     int i = 0;
49
50     ext_table = v3_create_htable(0, ext_hash_fn, ext_eq_fn);
51
52     while (tmp_ext != __stop__v3_extensions) {
53         V3_Print("Registering Extension (%s)\n", (*tmp_ext)->name);
54
55         if (v3_htable_search(ext_table, (addr_t)((*tmp_ext)->name))) {
56             PrintError("Multiple instances of Extension (%s)\n", (*tmp_ext)->name);
57             return -1;
58         }
59
60         if (v3_htable_insert(ext_table, (addr_t)((*tmp_ext)->name), (addr_t)(*tmp_ext)) == 0) {
61             PrintError("Could not register Extension (%s)\n", (*tmp_ext)->name);
62             return -1;
63         }
64
65         tmp_ext = &(__start__v3_extensions[++i]);
66     }
67
68     return 0;
69 }
70
71
72
73
74 int V3_deinit_extensions() {
75     v3_free_htable(ext_table, 0, 0);
76     return 0;
77 }
78
79
80 int v3_init_ext_manager(struct v3_vm_info * vm) {
81     struct v3_extensions * ext_state = &(vm->extensions);
82
83     INIT_LIST_HEAD(&(ext_state->extensions));
84     INIT_LIST_HEAD(&(ext_state->on_exits));
85     INIT_LIST_HEAD(&(ext_state->on_entries));
86     
87     return 0;
88 }
89
90
91 int v3_deinit_ext_manager(struct v3_vm_info * vm);
92
93 int v3_add_extension(struct v3_vm_info * vm, const char * name, v3_cfg_tree_t * cfg) {
94     struct v3_extension_impl * impl = NULL;
95     struct v3_extension * ext = NULL;
96
97     impl = (void *)v3_htable_search(ext_table, (addr_t)name);
98
99     if (impl == NULL) {
100         PrintError("Could not find requested extension (%s)\n", name);
101         return -1;
102     }
103     
104     V3_ASSERT(impl->init);
105
106     ext = V3_Malloc(sizeof(struct v3_extension));
107     
108     if (!ext) {
109         PrintError("Could not allocate extension\n");
110         return -1;
111     }
112
113     ext->impl = impl;
114
115     if (impl->init(vm, cfg, &(ext->priv_data)) == -1) {
116         PrintError("Error initializing Extension (%s)\n", name);
117         V3_Free(ext);
118         return -1;
119     }
120
121     list_add(&(ext->node), &(vm->extensions.extensions));
122
123     if (impl->on_exit) {
124         list_add(&(ext->exit_node), &(vm->extensions.on_exits));
125     }
126
127     if (impl->on_entry) {
128         list_add(&(ext->entry_node), &(vm->extensions.on_entries));
129     }
130     
131     return 0;
132 }
133
134 int v3_init_core_extensions(struct guest_info * core) {
135     struct v3_extension * ext = NULL;
136
137     list_for_each_entry(ext, &(core->vm_info->extensions.extensions), node) {
138         if ((ext->impl) && (ext->impl->core_init)) {
139             if (ext->impl->core_init(core, ext->priv_data) == -1) {
140                 PrintError("Error configuring per core extension %s on core %d\n", 
141                            ext->impl->name, core->cpu_id);
142                 return -1;
143             }
144         }
145     }
146
147     return 0;
148 }
149
150
151
152
153 void * v3_get_extension_state(struct v3_vm_info * vm, const char * name) {
154     struct v3_extension * ext = NULL;
155
156     list_for_each_entry(ext, &(vm->extensions.extensions), node) {
157         if (strncmp(ext->impl->name, name, strlen(ext->impl->name)) == 0) {
158             return ext->priv_data;
159         }
160     }
161
162     return NULL;
163 }