X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_usr%2Fv3_top_inject.c;h=6252b91cc30d1047b9a5cd9b9af135c0237a1c75;hb=d0aa5bd27c22a33f04f47363910f9773fdeab7eb;hp=2e5920224960bfb34111a04ca4ce8953b0d70b23;hpb=fd1de839d257d3ed2f0a8f27d231432b166b2cc1;p=palacios.git diff --git a/linux_usr/v3_top_inject.c b/linux_usr/v3_top_inject.c index 2e59202..6252b91 100644 --- a/linux_usr/v3_top_inject.c +++ b/linux_usr/v3_top_inject.c @@ -17,6 +17,7 @@ #include #include "iface-code-inject.h" +#include "v3_ctrl.h" #define __ELF_INJECT_CLASS 32 @@ -25,11 +26,6 @@ #define _ElfW_1(e,w,t) e##w##t -static void usage (char* bin) { - fprintf(stderr, "Usage: %s /dev/v3-vm [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 [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; }