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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Kyle C. Hale <kh@u.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
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>
30 static int free_hook (struct guest_info * core, struct exec_hook * hook) {
31 list_del(&(hook->hook_node));
36 static uint_t exec_hash_fn (addr_t key) {
37 return v3_hash_long(key, sizeof(void *) * 8);
41 static int exec_eq_fn (addr_t key1, addr_t key2) {
42 return (key1 == key2);
46 int v3_init_exec_hooks (struct guest_info * core) {
47 struct v3_exec_hooks * hooks = &(core->exec_hooks);
49 INIT_LIST_HEAD(&(hooks->hook_list));
51 hooks->bin_table = v3_create_htable(0, exec_hash_fn, exec_eq_fn);
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;
61 list_for_each_entry_safe(hook, tmp, &(hooks->hook_list), hook_node) {
62 free_hook(core, hook);
65 v3_free_htable(hooks->bin_table, 0, 0);
71 int v3_hook_executable (struct guest_info * core,
72 const uchar_t * binfile,
73 int (*handler)(struct guest_info * core, void * priv_data),
76 struct exec_hook * hook = V3_Malloc(sizeof(struct exec_hook));
77 struct v3_exec_hooks * hooks = &(core->exec_hooks);
80 memset(hook, 0, sizeof(struct exec_hook));
82 hook->handler = handler;
83 hook->priv_data = priv_data;
85 // we hash the name of the file to produce a key
86 key = v3_hash_buffer((uchar_t*)binfile, strlen(binfile));
88 v3_htable_insert(hooks->bin_table, key, (addr_t)hook);
89 list_add(&(hook->hook_node), &(hooks->hook_list));