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.


Gears Fast System Call Exiting Utility Service
[palacios.git] / gears / services / fsceu / syscall_decode.c
1 /* 
2  *   Kyle C. Hale 2012
3  * Module to be injected into guest kernel to enable
4  *  selective system call exiting
5  */
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/slab.h>
9 #include <linux/mm.h>
10
11 #include "syscall_decode.h"
12
13 #define AUTHOR "Kyle C. Hale <kh@u.northwestern.edu>"
14 #define INFO "This kernel module is a paravirtualized module that will"\
15               "reroute system calls to a handler stub. This stub will decide"\
16               "based on a VMM-mapped vector whether or not the particular system call"\
17               "should trap to the VMM."
18
19
20 extern void syscall_stub(void);
21
22 uint64_t * state_save_area;
23 uint8_t  * syscall_map;
24
25 int init_module (void) {
26     uint64_t ret;
27
28     state_save_area = kmalloc(sizeof(uint64_t)*(PAGE_SIZE), GFP_KERNEL);
29     if (!state_save_area){
30         printk("Problem allocating sate save area\n");
31         return -1;
32     }
33     memset(state_save_area, 0, sizeof(uint64_t)*(PAGE_SIZE));
34
35     syscall_map = kmalloc(NUM_SYSCALLS, GFP_KERNEL);
36     if (!syscall_map) {
37         printk("Problem allocating syscall map\n");
38         return -1;
39     }
40     memset(syscall_map, 0, NUM_SYSCALLS);
41
42     // vmm will return -1 on error, address of syscall_entry on success
43     asm volatile ("vmmcall"
44                 : "=a" (ret)
45                 : "0" (SYSCALL_SETUP_HCALL), "b" (syscall_stub), "c" (syscall_map), 
46                   "d" (state_save_area));
47
48     if (ret < 0) {
49         printk("syscall_decode: problem initing selective syscall exiting\n");
50         return -1;
51     } else {
52         state_save_area[NUM_SAVE_REGS] = ret; 
53     }
54
55     printk("syscall_decode: inited\n");
56     return 0;
57 }
58
59
60 void cleanup_module (void) {
61   int ret;
62   kfree(state_save_area);
63   kfree(syscall_map);
64   /* tell Palacios to restore the original system call entry point */
65   asm volatile ("vmmcall"
66                 : "=a" (ret)
67                 : "0"(SYSCALL_CLEANUP_HCALL));
68   if (ret < 0) {
69     printk("syscall_decode: problem deiniting selective syscall exiting\n");
70   }
71
72   printk("syscall_page: deinited\n");
73 }
74
75 MODULE_LICENSE("GPL");
76 MODULE_AUTHOR(AUTHOR);
77 MODULE_VERSION("0.2");
78 MODULE_DESCRIPTION(INFO);
79