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".
20 #include <palacios/vmm.h>
22 #include <palacios/vmm_extensions.h>
23 #include <palacios/vm_guest.h>
24 #include <palacios/vmm_hashtable.h>
27 static struct hashtable * ext_table = NULL;
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));
35 static int ext_eq_fn(addr_t key1, addr_t key2) {
36 char * name1 = (char *)key1;
37 char * name2 = (char *)key2;
39 return (strcmp(name1, name2) == 0);
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;
50 ext_table = v3_create_htable(0, ext_hash_fn, ext_eq_fn);
52 while (tmp_ext != __stop__v3_extensions) {
53 V3_Print("Registering Extension (%s)\n", (*tmp_ext)->name);
55 if (v3_htable_search(ext_table, (addr_t)((*tmp_ext)->name))) {
56 PrintError("Multiple instances of Extension (%s)\n", (*tmp_ext)->name);
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);
65 tmp_ext = &(__start__v3_extensions[++i]);
72 int V3_deinit_extensions() {
73 v3_free_htable(ext_table, 0, 0);
78 int v3_init_ext_manager(struct v3_vm_info * vm) {
79 struct v3_extensions * ext_state = &(vm->extensions);
81 INIT_LIST_HEAD(&(ext_state->extensions));
82 INIT_LIST_HEAD(&(ext_state->on_exits));
83 INIT_LIST_HEAD(&(ext_state->on_entries));
88 int v3_add_extension(struct v3_vm_info * vm, const char * name, v3_cfg_tree_t * cfg) {
89 struct v3_extension_impl * impl = NULL;
90 struct v3_extension * ext = NULL;
92 impl = (void *)v3_htable_search(ext_table, (addr_t)name);
95 PrintError("Could not find requested extension (%s)\n", name);
99 V3_ASSERT(impl->init);
101 ext = V3_Malloc(sizeof(struct v3_extension));
104 PrintError("Could not allocate extension\n");
110 if (impl->init(vm, cfg, &(ext->priv_data)) == -1) {
111 PrintError("Error initializing Extension (%s)\n", name);
116 list_add(&(ext->node), &(vm->extensions.extensions));
119 list_add(&(ext->exit_node), &(vm->extensions.on_exits));
122 if (impl->on_entry) {
123 list_add(&(ext->entry_node), &(vm->extensions.on_entries));