X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_hypercall.c;h=6cb51e039fafac5d7b21bbef96677528502ec5de;hb=1c000bda0560742ad6be011722fa226771b656ff;hp=05a66302013c4fee006ad04a031aef3a8c9c1cb7;hpb=3e5e5a12e64630d7a37ed32b8d7e2d993c79f7e0;p=palacios.git diff --git a/palacios/src/palacios/vmm_hypercall.c b/palacios/src/palacios/vmm_hypercall.c index 05a6630..6cb51e0 100644 --- a/palacios/src/palacios/vmm_hypercall.c +++ b/palacios/src/palacios/vmm_hypercall.c @@ -22,9 +22,7 @@ #include -#define HYPERCALL_TEST_HCALL 0x1 - -static int hcall_test(struct guest_info * info, uint_t hcall_id, void * private_data) { +static int hcall_test(struct guest_info * info, hcall_id_t hcall_id, void * private_data) { info->vm_regs.rbx = 0x1111; info->vm_regs.rcx = 0x2222; info->vm_regs.rdx = 0x3333; @@ -34,23 +32,45 @@ static int hcall_test(struct guest_info * info, uint_t hcall_id, void * private_ } - -void v3_init_hypercall_map(struct v3_vm_info * vm) { - vm->hcall_map.rb_node = NULL; - - v3_register_hypercall(vm, HYPERCALL_TEST_HCALL, hcall_test, NULL); -} - - struct hypercall { uint_t id; - int (*hcall_fn)(struct guest_info * info, uint_t hcall_id, void * priv_data); + int (*hcall_fn)(struct guest_info * info, hcall_id_t hcall_id, void * priv_data); void * priv_data; 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) { @@ -90,7 +110,7 @@ static inline struct hypercall * insert_hypercall(struct v3_vm_info * vm, struct } -static struct hypercall * get_hypercall(struct v3_vm_info * vm, uint_t id) { +static struct hypercall * get_hypercall(struct v3_vm_info * vm, hcall_id_t id) { struct rb_node * n = vm->hcall_map.rb_node; struct hypercall * hcall = NULL; @@ -110,8 +130,8 @@ static struct hypercall * get_hypercall(struct v3_vm_info * vm, uint_t id) { } -int v3_register_hypercall(struct v3_vm_info * vm, uint_t hypercall_id, - int (*hypercall)(struct guest_info * info, uint_t hcall_id, void * priv_data), +int v3_register_hypercall(struct v3_vm_info * vm, hcall_id_t hypercall_id, + int (*hypercall)(struct guest_info * info, hcall_id_t hcall_id, void * priv_data), void * priv_data) { struct hypercall * hcall = (struct hypercall *)V3_Malloc(sizeof(struct hypercall)); @@ -129,9 +149,30 @@ int v3_register_hypercall(struct v3_vm_info * vm, uint_t hypercall_id, } -int v3_handle_hypercall(struct guest_info * info) { - uint_t hypercall_id = *(uint_t *)&info->vm_regs.rax; +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"); + return -1; + } + + free_hypercall(vm, hcall); + + return 0; +} + + +int v3_handle_hypercall(struct guest_info * info) { + hcall_id_t hypercall_id = *(uint_t *)&info->vm_regs.rax; struct hypercall * hcall = get_hypercall(info->vm_info, hypercall_id); if (!hcall) { @@ -140,10 +181,9 @@ int v3_handle_hypercall(struct guest_info * info) { 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("Error handling hypercall\n"); + return -1; } return 0;