Mercurial > hg > vboxdotnet
comparison VBoxFrontend/VBoxMono.c @ 2:f1deea9c97a0
Cleaned up the interop code generator, added wrapper application to initialize kernel driver and run mono
author | Ivo Smits |
---|---|
date | Wed, 04 May 2011 16:10:08 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:55ca098c88d0 | 2:f1deea9c97a0 |
---|---|
1 /* To compile, you may have to specify: | |
2 * The include paths for mono: -I /usr/include/mono-1.0/ -I /usr/include/glib-2.0/ -I /usr/lib/glib-2.0/include/ | |
3 * The location of the VBoxXPCOMC.so library: /usr/lib/virtualbox/VBoxXPCOMC.so | |
4 * The location of the mono library (if an alternative build is to be used): /home/ivo/mono/devtest/lib/libmono-2.0.so | |
5 * To link against the mono library (if the system wide installed version is to be used): -lmono | |
6 * Where to look for the VBoxXPCOMC.so library at run time: -Wl,-R,/usr/lib/virtualbox | |
7 * Where to look for the mono library at run time (if non-standard): -R,/home/ivo/mono/devtest/lib/ | |
8 * | |
9 * The resulting commandline may look like this: | |
10 gcc VBoxMono.c -o VBoxMono -lmono \ | |
11 -I /usr/include/mono-1.0/ -I /usr/include/glib-2.0/ -I /usr/lib/glib-2.0/include/ \ | |
12 /usr/lib/virtualbox/VBoxXPCOMC.so -Wl,-R,/usr/lib/virtualbox | |
13 * The resulting commandline may look like this if mono is installed in an alternative location: | |
14 gcc VBoxMono.c -o VBoxMono \ | |
15 -I /usr/include/mono-1.0/ -I /usr/include/glib-2.0/ -I /usr/lib/glib-2.0/include/ \ | |
16 /usr/lib/virtualbox/VBoxXPCOMC.so -Wl,-R,/usr/lib/virtualbox \ | |
17 /home/ivo/mono/devtest/lib/libmono-2.0.so -Wl,-R,/home/ivo/mono/devtest/lib/ | |
18 * Then make the binary owned by root and set the suid bit: | |
19 sudo chown root VBoxMono | |
20 sudo chmod u+s VBoxMono | |
21 */ | |
22 | |
23 #include <unistd.h> | |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <mono/jit/jit.h> | |
27 #include <mono/metadata/assembly.h> | |
28 #include <mono/metadata/mono-config.h> | |
29 | |
30 extern int RTR3InitAndSUPLib(); | |
31 | |
32 int main(int argc, char *argv[]) { | |
33 if (argc < 2) { | |
34 fprintf(stderr, "VBoxMono: Usage: %s assembly.exe\n", argv[0]); | |
35 return 1; | |
36 } | |
37 int rc = RTR3InitAndSUPLib(); | |
38 if (rc != 0) { | |
39 fprintf(stderr, "VBoxMono: Could not initialize VirtualBox driver (%d)\n", rc); | |
40 return rc; | |
41 } | |
42 int gid = getuid(); | |
43 if (gid != getegid()) setregid(gid, gid); | |
44 int uid = getuid(); | |
45 if (uid != geteuid()) setreuid(uid, uid); | |
46 mono_config_parse(NULL); | |
47 //mono_set_dirs("/home/ivo/mono/devtest/lib", "/etc"); | |
48 MonoDomain *domain = mono_jit_init_version("VirtualBox", "v2.0.50727"); | |
49 if (!domain) { | |
50 fprintf(stderr, "VBoxMono: Could not create application domain\n"); | |
51 return 1; | |
52 } | |
53 MonoAssembly *assembly = mono_domain_assembly_open(domain, argv[1]); | |
54 if (!assembly) { | |
55 fprintf(stderr, "VBoxMono: Could not load assembly %s\n", argv[1]); | |
56 mono_jit_cleanup(domain); | |
57 return 1; | |
58 } | |
59 int ret = mono_jit_exec(domain, assembly, argc - 1, argv + 1); | |
60 mono_jit_cleanup(domain); | |
61 return ret; | |
62 } |