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".
19 #include <palacios/vmm.h>
20 #include <palacios/vmm_symmod.h>
21 #include <palacios/vmm_symbiotic.h>
22 #include <palacios/vm_guest.h>
24 static struct hashtable * master_mod_table = NULL;
28 static uint_t mod_hash_fn(addr_t key) {
29 char * name = (char *)key;
30 return v3_hash_buffer((uchar_t *)name, strlen(name));
33 static int mod_eq_fn(addr_t key1, addr_t key2) {
34 char * name1 = (char *)key1;
35 char * name2 = (char *)key2;
37 return (strcmp(name1, name2) == 0);
42 int V3_init_symmod() {
43 extern struct v3_sym_module __start__v3_modules[];
44 extern struct v3_sym_module __stop__v3_modules[];
45 struct v3_sym_module * tmp_mod = __start__v3_modules;
48 master_mod_table = v3_create_htable(0, mod_hash_fn, mod_eq_fn);
50 while (tmp_mod != __stop__v3_modules) {
51 if (v3_htable_search(master_mod_table, (addr_t)(tmp_mod->name))) {
52 PrintError("Multiple instances of Module (%s)\n", tmp_mod->name);
55 PrintDebug("Registering Symbiotic Module (%s)\n", tmp_mod->name);
57 if (v3_htable_insert(master_mod_table,
58 (addr_t)(tmp_mod->name),
59 (addr_t)(tmp_mod)) == 0) {
60 PrintError("Could not insert module %s to master list\n", tmp_mod->name);
63 tmp_mod = &(__start__v3_modules[++i]);
69 /* ***************** */
70 /* Linkage functions */
71 /* ***************** */
74 /* Data structure containing symbols exported via the symbiotic interface */
75 struct v3_symbol_def32 {
78 } __attribute__((packed));
84 struct list_head sym_node;
89 #include <palacios/vm_guest_mem.h>
91 static int symbol_hcall_handler(struct guest_info * core, hcall_id_t hcall_id, void * priv_data) {
92 struct v3_symmod_state * symmod_state = &(core->vm_info->sym_vm_state.symmod_state);
93 addr_t sym_start_gva = core->vm_regs.rbx;
94 uint32_t sym_size = core->vm_regs.rcx;
98 PrintError("Received SYMMOD symbol tables addr=%p, size=%d\n", (void *)sym_start_gva, sym_size);
100 for (i = 0; i < sym_size; i++) {
101 char * sym_name = NULL;
102 struct v3_symbol_def32 * tmp_symbol = NULL;
103 struct v3_symbol * new_symbol = NULL;
104 addr_t sym_gva = sym_start_gva + (sizeof(struct v3_symbol_def32) * i);
107 if (guest_va_to_host_va(core, sym_gva, (addr_t *)&(tmp_symbol)) == -1) {
108 PrintError("Could not locate symbiotic symbol definition\n");
112 if (guest_va_to_host_va(core, tmp_symbol->name_gva, (addr_t *)&(sym_name)) == -1) {
113 PrintError("Could not locate symbiotic symbol name\n");
117 PrintError("Symbiotic Symbol (%s) at %p\n", sym_name, (void *)(addr_t)tmp_symbol->value);
119 new_symbol = (struct v3_symbol *)V3_Malloc(sizeof(struct v3_symbol));
121 strncpy(new_symbol->name, sym_name, 256);
122 new_symbol->linkage = tmp_symbol->value;
124 list_add(&(new_symbol->sym_node), &(symmod_state->v3_sym_list));
131 int v3_init_symmod_vm(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
132 struct v3_symmod_state * symmod_state = &(vm->sym_vm_state.symmod_state);
133 struct v3_symspy_global_page * sym_page = v3_sym_get_symspy_vm(vm);
135 sym_page->symmod_enabled = 1;
137 v3_register_hypercall(vm, SYMMOD_SYMS_HCALL, symbol_hcall_handler, NULL);
139 INIT_LIST_HEAD(&(symmod_state->v3_sym_list));
141 V3_Print("Symmod initialized\n");
148 int v3_set_symmod_loader(struct v3_vm_info * vm, struct v3_symmod_loader_ops * ops, void * priv_data) {
149 struct v3_symmod_state * symmod_state = &(vm->sym_vm_state.symmod_state);
151 symmod_state->loader_ops = ops;
152 symmod_state->loader_data = priv_data;
161 int v3_load_sym_module(struct v3_vm_info * vm, char * mod_name) {
162 struct v3_symmod_state * symmod_state = &(vm->sym_vm_state.symmod_state);
163 struct v3_sym_module * mod = (struct v3_sym_module *)v3_htable_search(master_mod_table, (addr_t)mod_name);
166 PrintError("Could not find module %s\n", mod_name);
170 PrintDebug("Loading Module (%s)\n", mod_name);
172 return symmod_state->loader_ops->load_module(vm, mod, symmod_state->loader_data);
178 struct v3_sym_module * v3_get_sym_module(struct v3_vm_info * vm, char * name) {
179 struct v3_sym_module * mod = (struct v3_sym_module *)v3_htable_search(master_mod_table, (addr_t)name);
182 PrintError("Could not find module %s\n", name);