X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_symmod.c;h=82d2f35581fb110f136b01ae4bc8ebadee3c8154;hb=4ca005982593fbdd7f4204ec9805b5f86edf5155;hp=3b45c23d83bbace68e1bbd94ce0a69fa6c06a9f8;hpb=13d9a33d365278c508b8709288f9c7c2949a50f9;p=palacios.git diff --git a/palacios/src/palacios/vmm_symmod.c b/palacios/src/palacios/vmm_symmod.c index 3b45c23..82d2f35 100644 --- a/palacios/src/palacios/vmm_symmod.c +++ b/palacios/src/palacios/vmm_symmod.c @@ -62,7 +62,7 @@ int V3_init_symmod() { int i = 0; if (tmp_def == __stop__v3_capsules) { - PrintDebug("No Symbiotic capsules found\n"); + PrintDebug(VM_NONE, VCORE_NONE, "No Symbiotic capsules found\n"); return 0; } @@ -72,12 +72,19 @@ int V3_init_symmod() { struct v3_sym_capsule * capsule = NULL; if (v3_htable_search(capsule_table, (addr_t)(tmp_def->name))) { - PrintError("Multiple instances of Module (%s)\n", tmp_def->name); + PrintError(VM_NONE, VCORE_NONE, "Multiple instances of Module (%s)\n", tmp_def->name); return -1; } capsule = V3_Malloc(sizeof(struct v3_sym_capsule)); + + if (!capsule) { + PrintError(VM_NONE, VCORE_NONE, "Cannot allocate in initializing symmod\n"); + return -1; + } + + memset(capsule, 0, sizeof(struct v3_sym_capsule)); capsule->name = tmp_def->name; @@ -95,17 +102,20 @@ int V3_init_symmod() { capsule->guest_size = capsule->size; capsule->capsule_data = NULL; } else { + V3_Free(capsule); return -1; } - PrintDebug("Registering Symbiotic Module (%s)\n", tmp_def->name); + PrintDebug(VM_NONE, VCORE_NONE, "Registering Symbiotic Module (%s)\n", tmp_def->name); if (v3_htable_insert(capsule_table, (addr_t)(tmp_def->name), (addr_t)(capsule)) == 0) { - PrintError("Could not insert module %s to master list\n", tmp_def->name); + PrintError(VM_NONE, VCORE_NONE, "Could not insert module %s to master list\n", tmp_def->name); + V3_Free(capsule); return -1; } + list_add(&(capsule->node), &capsule_list); tmp_def = &(__start__v3_capsules[++i]); @@ -114,6 +124,12 @@ int V3_init_symmod() { return 0; } +int V3_deinit_symmod() { + v3_free_htable(capsule_table, 1, 0); + + return 0; +} + /* ***************** */ /* Linkage functions */ /* ***************** */ @@ -150,7 +166,7 @@ static int symbol_hcall_handler(struct guest_info * core, hcall_id_t hcall_id, v int i = 0; - PrintError("Received SYMMOD symbol tables addr=%p, size=%d\n", (void *)sym_start_gva, sym_size); + PrintError(core->vm_info, core, "Received SYMMOD symbol tables addr=%p, size=%d\n", (void *)sym_start_gva, sym_size); for (i = 0; i < sym_size; i++) { char * sym_name = NULL; @@ -159,20 +175,25 @@ static int symbol_hcall_handler(struct guest_info * core, hcall_id_t hcall_id, v addr_t sym_gva = sym_start_gva + (sizeof(struct v3_symbol_def32) * i); - if (guest_va_to_host_va(core, sym_gva, (addr_t *)&(tmp_symbol)) == -1) { - PrintError("Could not locate symbiotic symbol definition\n"); + if (v3_gva_to_hva(core, sym_gva, (addr_t *)&(tmp_symbol)) == -1) { + PrintError(core->vm_info, core, "Could not locate symbiotic symbol definition\n"); continue; } - if (guest_va_to_host_va(core, tmp_symbol->name_gva, (addr_t *)&(sym_name)) == -1) { - PrintError("Could not locate symbiotic symbol name\n"); + if (v3_gva_to_hva(core, tmp_symbol->name_gva, (addr_t *)&(sym_name)) == -1) { + PrintError(core->vm_info, core, "Could not locate symbiotic symbol name\n"); continue; } - PrintError("Symbiotic Symbol (%s) at %p\n", sym_name, (void *)(addr_t)tmp_symbol->value); + PrintError(core->vm_info, core, "Symbiotic Symbol (%s) at %p\n", sym_name, (void *)(addr_t)tmp_symbol->value); new_symbol = (struct v3_symbol *)V3_Malloc(sizeof(struct v3_symbol)); + if (!new_symbol) { + PrintError(core->vm_info, core, "Cannot allocate in symbiotic hcall handler\n"); + return -1; + } + strncpy(new_symbol->name, sym_name, 256); new_symbol->linkage = tmp_symbol->value; @@ -193,11 +214,11 @@ int v3_init_symmod_vm(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { // Add modules to local hash table, should be keyed to config list_for_each_entry(tmp_capsule, &capsule_list, node) { - V3_Print("Adding %s to local module table\n", tmp_capsule->name); + V3_Print(vm, VCORE_NONE, "Adding %s to local module table\n", tmp_capsule->name); if (v3_htable_insert(symmod_state->capsule_table, (addr_t)(tmp_capsule->name), (addr_t)(tmp_capsule)) == 0) { - PrintError("Could not insert module %s to vm local list\n", tmp_capsule->name); + PrintError(vm, VCORE_NONE, "Could not insert module %s to vm local list\n", tmp_capsule->name); return -1; } symmod_state->num_avail_capsules++; @@ -210,11 +231,27 @@ int v3_init_symmod_vm(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { INIT_LIST_HEAD(&(symmod_state->v3_sym_list)); - V3_Print("Symmod initialized\n"); + V3_Print(vm, VCORE_NONE, "Symmod initialized\n"); return 0; } +int v3_deinit_symmod_vm(struct v3_vm_info * vm) { + struct v3_symmod_state * symmod_state = &(vm->sym_vm_state.symmod_state); + struct v3_symbol * sym = NULL; + struct v3_symbol * tmp_sym = NULL; + + v3_remove_hypercall(vm, SYMMOD_SYMS_HCALL); + + v3_free_htable(symmod_state->capsule_table, 0, 0); + + list_for_each_entry_safe(sym, tmp_sym, &(symmod_state->v3_sym_list), sym_node) { + list_del(&(sym->sym_node)); + V3_Free(sym); + } + + return 0; +} int v3_set_symmod_loader(struct v3_vm_info * vm, struct v3_symmod_loader_ops * ops, void * priv_data) { @@ -235,11 +272,11 @@ int v3_load_sym_capsule(struct v3_vm_info * vm, char * name) { struct v3_sym_capsule * capsule = (struct v3_sym_capsule *)v3_htable_search(capsule_table, (addr_t)name); if (!capsule) { - PrintError("Could not find capsule %s\n", name); + PrintError(vm, VCORE_NONE, "Could not find capsule %s\n", name); return -1; } - PrintDebug("Loading Capsule (%s)\n", name); + PrintDebug(vm, VCORE_NONE, "Loading Capsule (%s)\n", name); return symmod_state->loader_ops->load_capsule(vm, capsule, symmod_state->loader_data); } @@ -255,7 +292,7 @@ struct v3_sym_capsule * v3_get_sym_capsule(struct v3_vm_info * vm, char * name) struct v3_sym_capsule * mod = (struct v3_sym_capsule *)v3_htable_search(capsule_table, (addr_t)name); if (!mod) { - PrintError("Could not find module %s\n", name); + PrintError(vm, VCORE_NONE, "Could not find module %s\n", name); return NULL; }