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.


uninitializing of memory hooks and host events
[palacios.git] / palacios / src / palacios / vmm_host_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) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, 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 #include <palacios/vmm.h>
21 #include <palacios/vmm_host_events.h>
22 #include <palacios/vm_guest.h>
23 #include <palacios/vmm_muxer.h>
24
25 int v3_init_host_events(struct v3_vm_info * vm) {
26     struct v3_host_events * host_evts = &(vm->host_event_hooks);
27
28     INIT_LIST_HEAD(&(host_evts->keyboard_events));
29     INIT_LIST_HEAD(&(host_evts->mouse_events));
30     INIT_LIST_HEAD(&(host_evts->timer_events));
31     INIT_LIST_HEAD(&(host_evts->serial_events));
32     INIT_LIST_HEAD(&(host_evts->console_events));
33     INIT_LIST_HEAD(&(host_evts->packet_events));
34
35     return 0;
36 }
37
38 int v3_deinit_host_events(struct v3_vm_info * vm) {
39     struct v3_host_events * host_evts = &(vm->host_event_hooks);
40     struct v3_host_event_hook * hook = NULL;
41     struct v3_host_event_hook * tmp = NULL;
42
43     list_for_each_entry_safe(hook, tmp, &(host_evts->keyboard_events), link) {
44         list_del(&(hook->link));
45         V3_Free(hook);
46     }
47
48     list_for_each_entry_safe(hook, tmp, &(host_evts->mouse_events), link) {
49         list_del(&(hook->link));
50         V3_Free(hook);
51     }
52
53
54     list_for_each_entry_safe(hook, tmp, &(host_evts->timer_events), link) {
55         list_del(&(hook->link));
56         V3_Free(hook);
57     }
58
59
60     list_for_each_entry_safe(hook, tmp, &(host_evts->serial_events), link) {
61         list_del(&(hook->link));
62         V3_Free(hook);
63     }
64
65
66     list_for_each_entry_safe(hook, tmp, &(host_evts->console_events), link) {
67         list_del(&(hook->link));
68         V3_Free(hook);
69     }
70
71
72     list_for_each_entry_safe(hook, tmp, &(host_evts->packet_events), link) {
73         list_del(&(hook->link));
74         V3_Free(hook);
75     }
76
77     return 0;
78 }
79
80
81 int v3_hook_host_event(struct v3_vm_info * vm, 
82                        v3_host_evt_type_t event_type, 
83                        union v3_host_event_handler cb, 
84                        void * private_data) {
85   
86     struct v3_host_events * host_evts = &(vm->host_event_hooks);
87     struct v3_host_event_hook * hook = NULL;
88
89     hook = (struct v3_host_event_hook *)V3_Malloc(sizeof(struct v3_host_event_hook));
90     if (hook == NULL) {
91         PrintError("Could not allocate event hook\n");
92         return -1;
93     }
94
95     hook->cb = cb;
96     hook->private_data = private_data;
97
98     switch (event_type)  {
99         case HOST_KEYBOARD_EVT:
100             list_add(&(hook->link), &(host_evts->keyboard_events));
101             break;
102         case HOST_MOUSE_EVT:
103             list_add(&(hook->link), &(host_evts->mouse_events));
104             break;
105         case HOST_TIMER_EVT:
106             list_add(&(hook->link), &(host_evts->timer_events));
107             break;
108         case HOST_SERIAL_EVT:
109             list_add(&(hook->link), &(host_evts->serial_events));
110             break;
111         case HOST_CONSOLE_EVT:
112             list_add(&(hook->link), &(host_evts->console_events));
113             break;
114         case HOST_PACKET_EVT:
115             list_add(&(hook->link), &(host_evts->packet_events));
116             break;
117     }
118
119     return 0;
120 }
121
122
123 int v3_deliver_keyboard_event(struct v3_vm_info * vm, 
124                               struct v3_keyboard_event * evt) {
125     struct v3_host_events * host_evts = NULL;
126     struct v3_host_event_hook * hook = NULL;
127
128     if (vm == NULL) {
129         vm = v3_get_foreground_vm();
130     }
131
132     host_evts = &(vm->host_event_hooks);
133
134     if (vm->run_state != VM_RUNNING) {
135         return -1;
136     }
137
138     list_for_each_entry(hook, &(host_evts->keyboard_events), link) {
139         if (hook->cb.keyboard_handler(vm, evt, hook->private_data) == -1) {
140             return -1;
141         }
142     }
143
144     return 0;
145 }
146
147
148 int v3_deliver_mouse_event(struct v3_vm_info * vm, 
149                            struct v3_mouse_event * evt) {
150     struct v3_host_events * host_evts = NULL;
151     struct v3_host_event_hook * hook = NULL;
152
153     if (vm == NULL) {
154         vm = v3_get_foreground_vm();
155     }
156
157     host_evts = &(vm->host_event_hooks);
158
159     if (vm->run_state != VM_RUNNING) {
160         return -1;
161     }
162
163     list_for_each_entry(hook, &(host_evts->mouse_events), link) {
164         if (hook->cb.mouse_handler(vm, evt, hook->private_data) == -1) {
165             return -1;
166         }
167     }
168
169     return 0;
170 }
171
172
173 int v3_deliver_timer_event(struct v3_vm_info * vm, 
174                            struct v3_timer_event * evt) {
175     struct v3_host_events * host_evts = NULL;
176     struct v3_host_event_hook * hook = NULL;
177
178     if (vm == NULL) {
179         vm = v3_get_foreground_vm();
180     }
181
182     host_evts = &(vm->host_event_hooks);
183
184     if (vm->run_state != VM_RUNNING) {
185         return -1;
186     }
187
188     list_for_each_entry(hook, &(host_evts->timer_events), link) {
189         if (hook->cb.timer_handler(vm, evt, hook->private_data) == -1) {
190             return -1;
191         }
192     }
193
194     return 0;
195 }
196
197 int v3_deliver_serial_event(struct v3_vm_info * vm, 
198                             struct v3_serial_event * evt) {
199     struct v3_host_events * host_evts = NULL;
200     struct v3_host_event_hook * hook = NULL;
201
202     if (vm == NULL) {
203         vm = v3_get_foreground_vm();
204     }
205
206     host_evts = &(vm->host_event_hooks);
207
208     if (vm->run_state != VM_RUNNING) {
209         return -1;
210     }
211
212     list_for_each_entry(hook, &(host_evts->serial_events), link) {
213         if (hook->cb.serial_handler(vm, evt, hook->private_data) == -1) {
214             return -1;
215         }
216     }
217
218     return 0;
219 }
220
221
222
223 int v3_deliver_console_event(struct v3_vm_info * vm, 
224                              struct v3_console_event * evt) {
225     struct v3_host_events * host_evts = NULL;
226     struct v3_host_event_hook * hook = NULL;
227
228     if (vm == NULL) {
229         vm = v3_get_foreground_vm();
230     }
231
232     host_evts = &(vm->host_event_hooks);
233
234     if (vm->run_state != VM_RUNNING) {
235         return -1;
236     }
237
238     list_for_each_entry(hook, &(host_evts->console_events), link) {
239         if (hook->cb.console_handler(vm, evt, hook->private_data) == -1) {
240             return -1;
241         }
242     }
243
244     return 0;
245 }
246
247
248 int v3_deliver_packet_event(struct v3_vm_info * vm, 
249                              struct v3_packet_event * evt) {
250     struct v3_host_events * host_evts = NULL;
251     struct v3_host_event_hook * hook = NULL;
252
253     if (vm == NULL) {
254         vm = v3_get_foreground_vm();
255     }
256
257     host_evts = &(vm->host_event_hooks);
258
259     if (vm->run_state != VM_RUNNING) {
260         return -1;
261     }
262
263     list_for_each_entry(hook, &(host_evts->packet_events), link) {
264         if (hook->cb.packet_handler(vm, evt, hook->private_data) == -1) {
265             return -1;
266         }
267     }
268
269     return 0;
270 }
271
272
273