X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_hypercall.c;h=59e64844a497bb0fe19ed3ef84f2fe57d603caf9;hb=c5ba903ae97ea49bbac5b660f76d2031c5302a3d;hp=c664a8385f689de11b974e6ea41357032c8a08f1;hpb=c31bb26014522e5678e9c9dcc9eda760eeb5907a;p=palacios.git diff --git a/palacios/src/palacios/vmm_hypercall.c b/palacios/src/palacios/vmm_hypercall.c index c664a83..59e6484 100644 --- a/palacios/src/palacios/vmm_hypercall.c +++ b/palacios/src/palacios/vmm_hypercall.c @@ -32,14 +32,6 @@ static int hcall_test(struct guest_info * info, hcall_id_t hcall_id, void * priv } - -void v3_init_hypercall_map(struct v3_vm_info * vm) { - vm->hcall_map.rb_node = NULL; - - v3_register_hypercall(vm, TEST_HCALL, hcall_test, NULL); -} - - struct hypercall { uint_t id; @@ -49,6 +41,36 @@ struct hypercall { struct rb_node tree_node; }; +static int free_hypercall(struct v3_vm_info * vm, struct hypercall * hcall); + +void v3_init_hypercall_map(struct v3_vm_info * vm) { + vm->hcall_map.rb_node = NULL; + + v3_register_hypercall(vm, TEST_HCALL, hcall_test, NULL); +} + +int v3_deinit_hypercall_map(struct v3_vm_info * vm) { + struct rb_node * node = NULL; + struct hypercall * hcall = NULL; + struct rb_node * tmp_node = NULL; + + v3_remove_hypercall(vm, TEST_HCALL); + + node = v3_rb_first(&(vm->hcall_map)); + + while (node) { + hcall = rb_entry(node, struct hypercall, tree_node); + tmp_node = node; + node = v3_rb_next(node); + + free_hypercall(vm, hcall); + } + + return 0; +} + + + static inline struct hypercall * __insert_hypercall(struct v3_vm_info * vm, struct hypercall * hcall) { @@ -114,6 +136,11 @@ int v3_register_hypercall(struct v3_vm_info * vm, hcall_id_t hypercall_id, struct hypercall * hcall = (struct hypercall *)V3_Malloc(sizeof(struct hypercall)); + if (!hcall) { + PrintError(vm, VCORE_NONE, "Cannot allocate in registering hypercall\n"); + return -1; + } + hcall->id = hypercall_id; hcall->priv_data = priv_data; hcall->hcall_fn = hypercall; @@ -127,17 +154,23 @@ int v3_register_hypercall(struct v3_vm_info * vm, hcall_id_t hypercall_id, } + +static int free_hypercall(struct v3_vm_info * vm, struct hypercall * hcall) { + v3_rb_erase(&(hcall->tree_node), &(vm->hcall_map)); + V3_Free(hcall); + + return 0; +} + int v3_remove_hypercall(struct v3_vm_info * vm, hcall_id_t hypercall_id) { struct hypercall * hcall = get_hypercall(vm, hypercall_id); if (hcall == NULL) { - PrintError("Attempted to remove non existant hypercall\n"); + PrintError(vm, VCORE_NONE, "Attempted to remove non existant hypercall\n"); return -1; } - v3_rb_erase(&(hcall->tree_node), &(vm->hcall_map)); - - V3_Free(hcall); + free_hypercall(vm, hcall); return 0; } @@ -148,15 +181,14 @@ int v3_handle_hypercall(struct guest_info * info) { struct hypercall * hcall = get_hypercall(info->vm_info, hypercall_id); if (!hcall) { - PrintError("Invalid Hypercall (%d(0x%x) not registered)\n", + PrintError(info->vm_info, info, "Invalid Hypercall (%d(0x%x) not registered)\n", hypercall_id, hypercall_id); return -1; } - if (hcall->hcall_fn(info, hypercall_id, hcall->priv_data) == 0) { - info->vm_regs.rax = 0; - } else { - info->vm_regs.rax = -1; + if (hcall->hcall_fn(info, hypercall_id, hcall->priv_data) != 0) { + PrintError(info->vm_info, info, "Error handling hypercall\n"); + return -1; } return 0;