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_hypercall.c
1 /* 
2  * V3 Hypercall Add Utility
3  * Allows hypercalls to be added to Palacios at run-time
4  *
5  * (c) Kyle C. Hale, 2011
6  */
7
8 #include <fcntl.h>
9 #include <errno.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <malloc.h>
14 #include <string.h>
15 #include <sys/types.h>
16 #include <sys/ioctl.h>
17
18 #include "../linux_module/iface-host-hypercall.h"
19
20 static void usage (char * bin) {
21         fprintf(stderr, "%s /dev/v3-vm<N> add|remove <nr> [function]\n", bin);
22         fprintf(stderr, "<nr> = hypercall number\n"
23                 "[function] = kernel symbol to bind to\n"
24                 "             (defaults to a nop if not given)\n");
25 }
26
27 int main (int argc, char ** argv) {
28   char * vm_dev = NULL;
29   int vm_fd, err;
30   struct hcall_data hd;
31   enum {ADD,REMOVE} task;
32
33   
34   if (argc < 4 || argc>5) {
35     usage(argv[0]);
36     return -1;
37   }
38
39   vm_dev = argv[1];
40
41   hd.hcall_nr = strtol(argv[3], NULL, 0);
42   
43  
44   if (!strcasecmp(argv[2],"add")) { 
45     task=ADD;
46     if (argc==4) { 
47       hd.fn[0]=0;  // blank
48     } else {
49       strcpy(hd.fn,argv[4]);
50     }
51   } else if (!strcasecmp(argv[2],"remove")) { 
52     task=REMOVE;
53   } else {
54     usage(argv[0]);
55     return -1;
56   }
57
58   printf("%s hypercall %d (0x%x) -> '%s' on %s\n",
59          task==ADD ? "Adding" : "Removing",
60          hd.hcall_nr, hd.hcall_nr,
61          task==REMOVE ? "(unimportant)" 
62          : strcmp(hd.fn,"") ? hd.fn : "(default nop)", vm_dev);
63
64   vm_fd = open(vm_dev, O_RDONLY);
65   if (vm_fd == -1) {
66     perror("Cannot open VM device");
67     return -1;
68   }
69
70   if (ioctl(vm_fd, 
71             task==ADD ? V3_VM_HYPERCALL_ADD : V3_VM_HYPERCALL_REMOVE,
72             &hd) < 0) { 
73     perror("Cannot complete task due ioctl failure");
74     close(vm_fd);
75     return -1;
76   }
77   
78   close(vm_fd);
79
80   printf("Done.\n");
81
82   return 0;
83 }
84
85