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] / gears / service_setup / prepare_inject.pl
1 #! /usr/bin/perl -w
2
3 use Getopt::Long;
4
5 sub usage() {
6         die "\n\nusage: prepare_inject.pl [-w output_file_name inject_object] [-e command {arg_list} ]\n\n".
7             "You must either indicate to write out an injected file with -w or to execute a command,".
8             " with -e, or both.\n\n".
9             "\t'output_file_name' is what the name of the inject_object will be when it is written out to the guest.\n\n".
10             "\t'inject_object' is the file that will be written out to the guest. This could be a text file, program, or ".
11             "really anything.\n\n".
12             "\t'command' is the fully qualified path name for a file within the guest to execute, either by itself, ".
13             "or after a specified inject_object is written out.\n\n";
14 }
15
16 &GetOptions("w:s{2}" => \@write_opts, "e:s{,}" => \@exec_opts, "output:s" => \$out_name) or usage();
17
18 usage() unless (@exec_opts || @write_opts);
19
20 $hfile = <<END;
21 #ifndef _GENERATED_H_
22 #define _GENERATED_H_
23
24 END
25
26
27 if (@exec_opts) {
28         $cmd = $exec_opts[0];
29         $hfile .= "#define DO_FORKEXEC\n"; 
30         $hfile .= "#define CMD \"$cmd\"\n";
31
32         $numargs = scalar(@exec_opts);
33         $hfile .= "char * const args[".$numargs."] = {\"".join('","', @exec_opts)."\"};\n";
34 }
35
36
37 if (@write_opts) {
38         $out_file = $write_opts[0];
39         $inject_file = $write_opts[1];
40         
41         $hfile .= "#define DO_WRITE\n";
42         $hfile .= "#define FILE_NAME \"$out_file\"\n";
43         
44
45         $size = `ls -l $inject_file | cut -f5 -d ' '`;
46         $hfile .= "#define FILE_LENGTH $size\n";
47
48         # generate a string from the file, char * inject_file = string
49         open FILE, $inject_file or die $!;
50         binmode FILE;
51         my ($buf, $data, $n);
52         while (($n = read FILE, $data, 1) != 0) {
53           $buf .= "\\x" . unpack("H8", $data);
54         }
55         
56         close(FILE);
57         $hfile .= "char * inject_file = \"$buf\";\n\n\n";
58 }
59
60 $hfile .= "#endif\n";
61
62 # write out the h file
63 open (W, ">generated.h") or die $!;
64 print W $hfile;
65 close(W);
66
67 print "running special inject code compilation and linking...\n";
68 # compile with generated h file and inject_code_template.c with peter's script
69 $compile_cmd = "perl compile-for-static-user-level-injection.pl -32 ";
70 $compile_cmd .= "--output=$out_name " if defined($out_name);
71 $compile_cmd .= "inject_code_template.c";
72 system($compile_cmd);
73
74 unlink "generated.h";
75
76
77 print "All done.\n";
78