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_top_inject.c
index 2e59202..6252b91 100644 (file)
@@ -17,6 +17,7 @@
 #include <sys/ioctl.h>
 
 #include "iface-code-inject.h"
+#include "v3_ctrl.h"
 
 #define __ELF_INJECT_CLASS 32
 
 #define _ElfW_1(e,w,t) e##w##t
 
 
-static void usage (char* bin) {
-       fprintf(stderr, "Usage: %s /dev/v3-vm<N> <inject-code> <code-entry-offset> [inject-point-exe]\n", bin);
-}
-
-
 /* look for PT_DYNAMIC to see if it's dynamically linked */
 static int is_dynamic (ElfW(Ehdr) * ehdr) {
     int i;
@@ -51,13 +47,17 @@ int main (int argc, char **argv) {
        char *vm_dev = NULL;
        char *top_half = NULL;
     char *bin_file = NULL;
-       int vm_fd, t_fd, err, bytes_read, entry;
+       int t_fd, err, bytes_read, entry;
     struct stat t_stat;
     struct top_half_data elf;
     ElfW(Ehdr) * elf_hdr;
 
        if (argc < 4 || argc > 5) {
-               usage(argv[0]);
+                // TODO: add a better explanation here
+               v3_usage("/dev/v3-vm<N> <inject-code> <code-entry-offset> [inject-point-exe]\n\n"
+                          "\tinject-code       : the binary file to be injected\n\n"
+                          "\tcode-entry-offset : offset in the binary to .text\n\n"
+                          "\tinject-point-exe  : if exec-hooked injection is used, use this exec name\n");
                return -1;
        }
 
@@ -129,14 +129,9 @@ int main (int argc, char **argv) {
     /* is it a dynamically linked executable? */
     elf.is_dyn = is_dynamic(elf_hdr);
 
-       vm_fd = open(vm_dev, O_RDONLY);
-       if (vm_fd == -1) {
-               fprintf(stderr, "Error opening VM device: %s\n", vm_dev);
-               return -1;
-       }
 
     printf("Transferring control to Palacios\n");
-       err = ioctl(vm_fd, V3_VM_TOPHALF_INJECT, &elf);
+       err = v3_vm_ioctl(vm_dev, V3_VM_TOPHALF_INJECT, &elf);
        if (err < 0) {
                fprintf(stderr, "Error providing top half to palacios: %s\n", top_half);
                return -1;
@@ -144,7 +139,6 @@ int main (int argc, char **argv) {
     
     free(elf.elf_data);
        close(t_fd);
-       close(vm_fd);
 
        return 0;
 }