X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_events.c;h=7402959b7c36db5df5ae4de66def77b94abf0d1f;hb=a5d2c00cc461b4a60a1360a2a0bba55cef467bab;hp=0c565f20c3d57e89efbca9849387a06d18ec4cb8;hpb=e8069ad305c7b50fefb0cc602d9ca53324e6cc9e;p=palacios.git diff --git a/palacios/src/palacios/vmm_events.c b/palacios/src/palacios/vmm_events.c index 0c565f2..7402959 100644 --- a/palacios/src/palacios/vmm_events.c +++ b/palacios/src/palacios/vmm_events.c @@ -28,13 +28,14 @@ int v3_init_events(struct v3_vm_info * vm) { struct v3_event_map * map = &(vm->event_map); int i = 0; - map->events = V3_Malloc(sizeof(struct list_head) * V3_EVENT_INVALID); + map->events = V3_Malloc(sizeof(struct list_head) * (V3_EVENT_INVALID+1)); if (map->events == NULL) { - PrintError("Error: could not allocate event map\n"); + PrintError(vm, VCORE_NONE, "Error: could not allocate event map\n"); return -1; } + // dead code if there are no events, but this is correct for (i = 0; i < V3_EVENT_INVALID; i++) { INIT_LIST_HEAD(&(map->events[i])); } @@ -46,11 +47,13 @@ int v3_deinit_events(struct v3_vm_info * vm) { struct v3_event_map * map = &(vm->event_map); int i = 0; + + // dead code if there are no events, but this is correct for (i = 0; i < V3_EVENT_INVALID; i++) { if (!list_empty(&(map->events[i]))) { struct v3_notifier * tmp_notifier = NULL; struct v3_notifier * safe_notifier = NULL; - PrintError("Found orphan notifier for event %d. Probable memory leak detected.\n", i); + PrintError(vm, VCORE_NONE, "Found orphan notifier for event %d. Probable memory leak detected.\n", i); list_for_each_entry_safe(tmp_notifier, safe_notifier, &(map->events[i]), node) { list_del(&(tmp_notifier->node)); @@ -67,7 +70,7 @@ int v3_deinit_events(struct v3_vm_info * vm) { } -int v3_request_event(struct v3_vm_info * vm, +struct v3_notifier * v3_subscribe_event(struct v3_vm_info * vm, v3_event_type_t event_type, void (*notify)(struct guest_info * core, v3_event_type_t event_type, @@ -79,29 +82,55 @@ int v3_request_event(struct v3_vm_info * vm, struct v3_notifier * notifier = NULL; if (event_type >= V3_EVENT_INVALID) { - PrintError("Tried to request illegal event (%d)\n", event_type); - return -1; + PrintError(vm, VCORE_NONE, "Tried to request illegal event (%d)\n", event_type); + return NULL; } - notifier = V3_Malloc(sizeof(struct v3_notifier)); if (notifier == NULL) { - PrintError("Error: Could not allocate notifier\n"); - return -1; + PrintError(vm, VCORE_NONE, "Error: Could not allocate notifier\n"); + return NULL; } memset(notifier, 0, sizeof(struct v3_notifier)); notifier->notify = notify; notifier->priv_data = priv_data; + notifier->event_type = event_type; while (v3_raise_barrier(vm, current_core) == -1); list_add(&(notifier->node), &(map->events[event_type])); v3_lower_barrier(vm); - - return 0; + return notifier;; } +int v3_unsubscribe_event(struct v3_vm_info * vm, struct v3_notifier * notifier, + struct guest_info * current_core) { + struct v3_event_map * map = &(vm->event_map); + struct v3_notifier * tmp_notifier = NULL; + struct v3_notifier * safe_notifier = NULL; + + if (notifier == NULL) { + PrintError(vm, VCORE_NONE, "Could not unsubscribe invalid event notifier\n"); + return -1; + } + + if (notifier->event_type >= V3_EVENT_INVALID) { + PrintError(vm, VCORE_NONE, "Could not unsubscribe from invalid event\n"); + return -1; + } + + while (v3_raise_barrier(vm, current_core) == -1); + list_for_each_entry_safe(tmp_notifier, safe_notifier, &(map->events[notifier->event_type]), node) { + if (tmp_notifier == notifier) { + list_del(&(tmp_notifier->node)); + V3_Free(tmp_notifier); + } + } + v3_lower_barrier(vm); + + return 0; +}