annotate VBoxFrontend/ProgramLoader.cs @ 7:a7650e26195f tip

Added support for generating Com Callable Wrappers
author Ivo Smits
date Fri, 06 May 2011 08:12:43 +0200
parents b0033e69105a
children
rev   line source
0
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
1 ???using System;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
2 using System.Reflection;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
3 using System.Runtime.InteropServices;
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
4
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
5 namespace ConsoleApplication1 {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
6 class ProgramLoader {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
7 [DllImport("/usr/lib/virtualbox/VBoxXPCOMC.so")]
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
8 private static extern Int32 RTR3InitAndSUPLib();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
9
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
10 static unsafe int Main(string[] args) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
11 if (Environment.OSVersion.Platform == PlatformID.Unix) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
12 Console.WriteLine("UNIX based OS detected, doing some magic...");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
13 int init = RTR3InitAndSUPLib();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
14 if (init != 0) throw new COMException("Failed to initialize VirtualBox driver", init);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
15 Unix_setuid();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
16 Assembly.LoadFile("Interop.VirtualBox.XPCOM.dll");
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
17 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
18 return Main2(args);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
19 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
20
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
21 static int Main2(String[] args) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
22 ProgramRun p = new ProgramRun();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
23 return p.Run(args);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
24 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
25
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
26 private static void Unix_setuid() {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
27 uint uid = Mono.Unix.Native.Syscall.getuid();
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
28 uint euid = Mono.Unix.Native.Syscall.geteuid();
3
b0033e69105a Set group ID during initialization, added a patch to mono to fix a double free 'bug'
Ivo Smits
parents: 0
diff changeset
29 uint gid = Mono.Unix.Native.Syscall.getgid();
b0033e69105a Set group ID during initialization, added a patch to mono to fix a double free 'bug'
Ivo Smits
parents: 0
diff changeset
30 uint egid = Mono.Unix.Native.Syscall.getegid();
b0033e69105a Set group ID during initialization, added a patch to mono to fix a double free 'bug'
Ivo Smits
parents: 0
diff changeset
31 Console.WriteLine("Running as user {0} effective {1} group {2} effective {3}", uid, euid, gid, egid);
b0033e69105a Set group ID during initialization, added a patch to mono to fix a double free 'bug'
Ivo Smits
parents: 0
diff changeset
32 if (gid != egid) {
b0033e69105a Set group ID during initialization, added a patch to mono to fix a double free 'bug'
Ivo Smits
parents: 0
diff changeset
33 Console.WriteLine("Set group ID: {0}", gid);
b0033e69105a Set group ID during initialization, added a patch to mono to fix a double free 'bug'
Ivo Smits
parents: 0
diff changeset
34 Mono.Unix.Native.Syscall.setregid(gid, gid);
b0033e69105a Set group ID during initialization, added a patch to mono to fix a double free 'bug'
Ivo Smits
parents: 0
diff changeset
35 }
0
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
36 if (uid != euid) {
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
37 Console.WriteLine("Set user ID: {0}", uid);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
38 Mono.Unix.Native.Syscall.setreuid(uid, uid);
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
39 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
40 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
41 }
e1ec7bf71313 Initial commit
Ivo Smits
parents:
diff changeset
42 }