Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added event hooking framework
[palacios.git] / palacios / src / palacios / vmm_events.c
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2012, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2012, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21
22 #include <palacios/vmm_events.h>
23 #include <palacios/vm_guest.h>
24
25
26
27 int v3_init_events(struct v3_vm_info * vm) {
28     struct v3_event_map * map = &(vm->event_map);
29     int i = 0;
30
31     map->events = V3_Malloc(sizeof(struct list_head) * V3_EVENT_INVALID);
32
33     if (map->events == NULL) {
34         PrintError("Error: could not allocate event map\n");
35         return -1;
36     }
37
38     for (i = 0; i < V3_EVENT_INVALID; i++) {
39         INIT_LIST_HEAD(&(map->events[i]));
40     }
41
42     return 0;
43 }
44
45 int v3_deinit_events(struct v3_vm_info * vm) {
46     struct v3_event_map * map = &(vm->event_map);
47     int i = 0;
48
49     for (i = 0; i < V3_EVENT_INVALID; i++) {
50         if (!list_empty(&(map->events[i]))) {
51             struct v3_notifier * tmp_notifier = NULL;
52             struct v3_notifier * safe_notifier = NULL;
53             PrintError("Found orphan notifier for event %d. Probable memory leak detected.\n", i);
54             
55             list_for_each_entry_safe(tmp_notifier, safe_notifier, &(map->events[i]), node) {
56                 list_del(&(tmp_notifier->node));
57                 V3_Free(tmp_notifier);
58             }
59         }
60     }
61
62
63     V3_Free(map->events);
64
65     return 0;
66
67 }
68
69
70 int v3_request_event(struct v3_vm_info * vm, 
71                      v3_event_type_t event_type, 
72                      void (*notify)(struct guest_info * core, 
73                                     v3_event_type_t event_type,
74                                     void * priv_data, 
75                                     void * event_data),
76                      void * priv_data, 
77                      struct guest_info * current_core) {
78     struct v3_event_map * map = &(vm->event_map);
79     struct v3_notifier * notifier = NULL;
80
81     if (event_type >= V3_EVENT_INVALID) {
82         PrintError("Tried to request illegal event (%d)\n", event_type);
83         return -1;
84     }
85     
86
87     notifier = V3_Malloc(sizeof(struct v3_notifier));
88
89     if (notifier == NULL) {
90         PrintError("Error: Could not allocate notifier\n");
91         return -1;
92     }
93
94     memset(notifier, 0, sizeof(struct v3_notifier));
95     
96     notifier->notify = notify;
97     notifier->priv_data = priv_data;
98
99     while (v3_raise_barrier(vm, current_core) == -1);
100     list_add(&(notifier->node), &(map->events[event_type]));
101     v3_lower_barrier(vm);
102
103
104     return 0;
105 }
106
107