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