From: Jack Lange Date: Thu, 11 Feb 2010 04:35:10 +0000 (-0600) Subject: added global module registry X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=65b032e18e7f439d61d682c79884c2d017be6c4d;p=palacios.git added global module registry --- diff --git a/palacios/include/palacios/vmm_symmod.h b/palacios/include/palacios/vmm_symmod.h index bf360d2..d46ad11 100644 --- a/palacios/include/palacios/vmm_symmod.h +++ b/palacios/include/palacios/vmm_symmod.h @@ -42,10 +42,10 @@ struct v3_symmod_state { struct v3_sym_module { - char name[32]; - uint16_t num_bytes; - char * data; -}; + char * name; + void * start_addr; + void * end_addr; +} __attribute__((packed)); int v3_set_symmod_loader(struct v3_vm_info * vm, struct v3_symmod_loader_ops * ops, void * priv_data); @@ -61,17 +61,9 @@ struct v3_sym_module * v3_get_sym_module(struct v3_vm_info * vm, char * name); - -struct v3_module_hdr { - char * name; - void * start_addr; - void * end_addr; -} __attribute__((packed)); - - #define register_module(name, start, end) \ static char v3_module_name[] = name; \ - static struct v3_module_hdr _v3_module \ + static struct v3_sym_module _v3_module \ __attribute__((__used__)) \ __attribute__((unused, __section__ ("_v3_modules"), \ aligned(sizeof(addr_t)))) \ diff --git a/palacios/src/devices/keyboard.c b/palacios/src/devices/keyboard.c index eef0ec0..69a41d3 100644 --- a/palacios/src/devices/keyboard.c +++ b/palacios/src/devices/keyboard.c @@ -377,7 +377,7 @@ static int key_event_handler(struct v3_vm_info * vm, #endif #ifdef CONFIG_SYMMOD else if (evt->scan_code == 0x40) { // F6 Test symmod load - v3_load_sym_module(vm, "test"); + v3_load_sym_module(vm, "test_32"); } #endif diff --git a/palacios/src/devices/lnx_virtio_symmod.c b/palacios/src/devices/lnx_virtio_symmod.c index 53a7171..d3bae18 100644 --- a/palacios/src/devices/lnx_virtio_symmod.c +++ b/palacios/src/devices/lnx_virtio_symmod.c @@ -147,9 +147,9 @@ static int handle_xfer_kick(struct guest_info * core, struct virtio_sym_state * return -1; } - memcpy(buf, module->data + offset, buf_desc->length); + memcpy(buf, module->start_addr + offset, buf_desc->length); PrintDebug("Copying module to virtio buffers: SRC=%p, DST=%p, len=%d\n", - (void *)(module->data + offset), (void *)buf, buf_desc->length); + (void *)(module->start_addr + offset), (void *)buf, buf_desc->length); if (tmp_status != 0) { PrintError("Error loading module segment\n"); diff --git a/palacios/src/palacios/vmm.c b/palacios/src/palacios/vmm.c index cf0d4bd..66ce9c0 100644 --- a/palacios/src/palacios/vmm.c +++ b/palacios/src/palacios/vmm.c @@ -83,7 +83,12 @@ void Init_V3(struct v3_os_hooks * hooks, int num_cpus) { // Register all shadow paging handlers V3_init_shdw_paging(); -#ifdef INSTRUMENT_VMM + +#ifdef CONFIG_SYMMOD + V3_init_symmod(); +#endif + +#ifdef CONFIG_INSTRUMENT_VMM v3_init_instrumentation(); #endif diff --git a/palacios/src/palacios/vmm_symmod.c b/palacios/src/palacios/vmm_symmod.c index 41767ff..a311ae1 100644 --- a/palacios/src/palacios/vmm_symmod.c +++ b/palacios/src/palacios/vmm_symmod.c @@ -21,45 +21,71 @@ #include #include -static struct v3_sym_module test_module; +static struct hashtable * master_mod_table = NULL; -int V3_init_symmod() { - return -1; +static uint_t mod_hash_fn(addr_t key) { + char * name = (char *)key; + return v3_hash_buffer((uchar_t *)name, strlen(name)); } +static int mod_eq_fn(addr_t key1, addr_t key2) { + char * name1 = (char *)key1; + char * name2 = (char *)key2; + + return (strcmp(name1, name2) == 0); +} -int v3_init_symmod_vm(struct v3_vm_info * info, v3_cfg_tree_t * cfg) { - return 0; -} +int V3_init_symmod() { + extern struct v3_sym_module __start__v3_modules[]; + extern struct v3_sym_module __stop__v3_modules[]; + struct v3_sym_module * tmp_mod = __start__v3_modules; + int i = 0; + master_mod_table = v3_create_htable(0, mod_hash_fn, mod_eq_fn); -int v3_set_symmod_loader(struct v3_vm_info * vm, struct v3_symmod_loader_ops * ops, void * priv_data) { - struct v3_symmod_state * symmod_state = &(vm->sym_vm_state.symmod_state); - extern uint8_t symmod_start[]; - extern uint8_t symmod_end[]; + while (tmp_mod != __stop__v3_modules) { + if (v3_htable_search(master_mod_table, (addr_t)(tmp_mod->name))) { + PrintError("Multiple instances of Module (%s)\n", tmp_mod->name); + return -1; + } + + + PrintDebug("Registering Symbiotic Module (%s)\n", tmp_mod->name); + if (v3_htable_insert(master_mod_table, + (addr_t)(tmp_mod->name), + (addr_t)(tmp_mod)) == 0) { + PrintError("Could not insert module %s to master list\n", tmp_mod->name); + return -1; + } - struct v3_sym_module tmp_mod = { - .name = "test", - .num_bytes = symmod_end - symmod_start, - .data = symmod_start, - }; - + tmp_mod = &(__start__v3_modules[++i]); + } - test_module = tmp_mod; + return 0; +} - symmod_state->loader_ops = ops; - symmod_state->loader_data = priv_data; - + +int v3_init_symmod_vm(struct v3_vm_info * info, v3_cfg_tree_t * cfg) { return 0; +} + + +int v3_set_symmod_loader(struct v3_vm_info * vm, struct v3_symmod_loader_ops * ops, void * priv_data) { + struct v3_symmod_state * symmod_state = &(vm->sym_vm_state.symmod_state); + + symmod_state->loader_ops = ops; + symmod_state->loader_data = priv_data; + + return 0; } @@ -68,15 +94,29 @@ int v3_set_symmod_loader(struct v3_vm_info * vm, struct v3_symmod_loader_ops * o int v3_load_sym_module(struct v3_vm_info * vm, char * mod_name) { struct v3_symmod_state * symmod_state = &(vm->sym_vm_state.symmod_state); + struct v3_sym_module * mod = (struct v3_sym_module *)v3_htable_search(master_mod_table, (addr_t)mod_name); + + if (!mod) { + PrintError("Could not find module %s\n", mod_name); + return -1; + } PrintDebug("Loading Module (%s)\n", mod_name); - return symmod_state->loader_ops->load_module(vm, test_module.name, test_module.num_bytes, symmod_state->loader_data); + return symmod_state->loader_ops->load_module(vm, mod->name, mod->end_addr - mod->start_addr, symmod_state->loader_data); } struct v3_sym_module * v3_get_sym_module(struct v3_vm_info * vm, char * name) { - return &test_module; + struct v3_sym_module * mod = (struct v3_sym_module *)v3_htable_search(master_mod_table, (addr_t)name); + + + if (!mod) { + PrintError("Could not find module %s\n", name); + return NULL; + } + + return mod; }