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.


Avoid strict-aliasing related issues when compiling with optimization
[palacios.git] / linux_usr / v3_syscall.c
1 /*
2  * V3 Selective System Call Exiting Control
3  * (c) Kyle C. Hale, 2012
4  *
5  */
6
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <sys/ioctl.h>
11 #include <errno.h>
12 #include <fcntl.h>
13 #include <unistd.h>
14 #include <string.h>
15
16 #include "iface-syscall.h"
17 #include "v3_ctrl.h"
18
19 #define CMD_MAX 10
20 #define SYSCALL_MAX 256
21
22 static void usage (char * argv[]) {
23         v3_usage("<vm device> <syscall_nr> <on|off|status>\n");
24 }
25
26 int main (int argc, char * argv[]) {
27
28         int ret, syscall_nr;
29         char * vm_dev = NULL;
30         struct v3_syscall_cmd syscall_cmd;
31
32         if (argc < 4 || argc > 4) {
33                 fprintf(stderr, "Invalid number of arguments.\n");
34                 usage(argv);
35         }
36
37         vm_dev = argv[1];
38         syscall_nr = strtol(argv[2], NULL, 0);
39
40         if (strncmp(argv[3], "on", CMD_MAX) == 0) {
41                 syscall_cmd.cmd = SYSCALL_ON;
42         } else if (strncmp(argv[3], "off", CMD_MAX) == 0) {
43                 syscall_cmd.cmd = SYSCALL_OFF;
44         } else if (strncmp(argv[3], "status", CMD_MAX) == 0) {
45                 syscall_cmd.cmd = SYSCALL_STAT;
46         } else {
47                 fprintf(stderr, "Invalid command.\n");
48                 usage(argv);
49         }
50
51     if (syscall_nr < 0 || syscall_nr > SYSCALL_MAX) {
52         fprintf(stderr, "Invalid syscall number.\n");
53         return -1;
54     }
55
56     syscall_cmd.syscall_nr = syscall_nr;
57
58         ret = v3_vm_ioctl(vm_dev, V3_VM_SYSCALL_CTRL, &syscall_cmd);
59
60     if (ret < 0) {
61         fprintf(stderr, "Error with syscall control\n");
62         return -1;
63     }
64
65     if (syscall_cmd.cmd == SYSCALL_STAT) {
66         if (ret == SYSCALL_ON) 
67             printf("Selective exiting for syscall #%d is currently ON\n", syscall_cmd.syscall_nr);
68         else if (ret == SYSCALL_OFF) 
69             printf("Selective exiting for syscall #%d is currently OFF\n", syscall_cmd.syscall_nr);
70     } else if (syscall_cmd.cmd == SYSCALL_ON) {
71        printf("Selective exiting for syscall #%d ACTIVATED\n", syscall_cmd.syscall_nr);
72     } else if (syscall_cmd.cmd == SYSCALL_OFF) {
73         printf("Selective exiting for syscall #%d DEACTIVATED\n", syscall_cmd.syscall_nr);
74     }
75
76         return 0;
77 }