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.


e78052e7e979b425bca43b5fcde3d592c6a417f6
[palacios.git] / palacios / src / extensions / vmm_execve_hook.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) 2011, Kyle C. Hale <kh@u.norhtwestern.edu>
11  * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Kyle C. Hale <kh@u.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 #include <palacios/vmm.h>
22 #include <palacios/vm_guest.h>
23 #include <palacios/vmm_string.h>
24 #include <palacios/vmm_syscall_hijack.h>
25 #include <palacios/vmm_hashtable.h>
26 #include <palacios/vmm_execve_hook.h>
27
28
29
30 static int free_hook (struct guest_info * core, struct exec_hook * hook) {
31     list_del(&(hook->hook_node));
32     V3_Free(hook);
33     return 0;
34 }
35     
36 static uint_t exec_hash_fn (addr_t key) {
37     return v3_hash_long(key, sizeof(void *) * 8);
38 }
39
40
41 static int exec_eq_fn (addr_t key1, addr_t key2) {
42     return (key1 == key2);
43 }
44
45
46 int v3_init_exec_hooks (struct guest_info * core) {
47     struct v3_exec_hooks * hooks = &(core->exec_hooks);
48
49     INIT_LIST_HEAD(&(hooks->hook_list));
50
51     hooks->bin_table = v3_create_htable(0, exec_hash_fn, exec_eq_fn);
52     return 0;
53 }
54
55
56 int v3_deinit_exec_hooks (struct guest_info * core) {
57     struct v3_exec_hooks * hooks = &(core->exec_hooks);
58     struct exec_hook * hook = NULL;
59     struct exec_hook * tmp = NULL;
60     
61     list_for_each_entry_safe(hook, tmp, &(hooks->hook_list), hook_node) {
62         free_hook(core, hook);
63     }
64
65     v3_free_htable(hooks->bin_table, 0, 0);
66
67     return 0;
68 }
69
70
71 int v3_hook_executable (struct guest_info * core, 
72     const uchar_t * binfile,
73     int (*handler)(struct guest_info * core, void * priv_data),
74     void * priv_data) 
75 {
76     struct exec_hook * hook = V3_Malloc(sizeof(struct exec_hook));
77     struct v3_exec_hooks * hooks = &(core->exec_hooks);
78     addr_t key;
79     
80     memset(hook, 0, sizeof(struct exec_hook));
81     
82     hook->handler = handler;
83     hook->priv_data = priv_data;
84     
85     // we hash the name of the file to produce a key
86     key = v3_hash_buffer((uchar_t*)binfile, strlen(binfile));
87
88     v3_htable_insert(hooks->bin_table, key, (addr_t)hook);
89     list_add(&(hook->hook_node), &(hooks->hook_list));
90
91     return 0;
92 }
93
94