Index: trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/dtrace.c
===================================================================
--- trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/dtrace.c	(revision 53645)
+++ trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/cmd/dtrace/dtrace.c	(revision 53646)
@@ -25,9 +25,13 @@
  */
 
+#ifndef VBOX
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
+#endif
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/wait.h>
+#ifndef _MSC_VER
+# include <sys/wait.h>
+#endif
 
 #include <dtrace.h>
@@ -35,13 +39,46 @@
 #include <stdarg.h>
 #include <stdio.h>
-#include <strings.h>
-#include <unistd.h>
+#ifndef VBOX
+# include <strings.h>
+#endif
+#ifndef _MSC_VER
+# include <unistd.h>
+#else
+# include <direct.h>
+# include <io.h>
+#endif
 #include <limits.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <signal.h>
+#ifndef VBOX
 #include <alloca.h>
 #include <libgen.h>
 #include <libproc.h>
+#endif
+
+#ifdef VBOX
+# include <stdio.h>
+
+# include <iprt/alloca.h>
+# include <iprt/getopt.h>
+# include <iprt/initterm.h>
+# include <iprt/path.h>
+# include <iprt/message.h>
+# include <iprt/process.h>
+# include <iprt/string.h>
+
+# undef PATH_MAX
+# define PATH_MAX RTPATH_MAX
+
+# define getpid		                          RTProcSelf
+# define strlcpy(a_pszDst, a_pszSrc, a_cbDst) RTStrCopy(a_pszDst, a_cbDst, a_pszSrc)
+# define basename(a_pszPath)                  RTPathFilename(a_pszPath)
+
+# ifdef _MSC_VER
+#  pragma warning(disable:4267) /* size_t conversion warnings */
+#  pragma warning(disable:4018) /* signed/unsigned mismatch */
+# endif
+#endif
 
 typedef struct dtrace_cmd {
@@ -66,6 +103,47 @@
 #define	E_USAGE		2
 
+#ifndef VBOX
 static const char DTRACE_OPTSTR[] =
 	"3:6:aAb:Bc:CD:ef:FGhHi:I:lL:m:n:o:p:P:qs:SU:vVwx:X:Z";
+#else
+static const RTGETOPTDEF g_aOptions[] =
+{
+	{ "-32", 10064, RTGETOPT_REQ_NOTHING },
+	{ "-64", 10032, RTGETOPT_REQ_NOTHING },
+	{ NULL, 'a', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'A', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'b', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'B', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'c', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'C', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'D', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'e', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'f', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'F', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'G', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'h', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'H', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'i', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'I', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'l', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'L', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'M', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'n', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'o', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'p', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'P', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'q', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 's', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'S', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'U', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'v', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'V', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'w', 	RTGETOPT_REQ_NOTHING },
+	{ NULL, 'x', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'X', 	RTGETOPT_REQ_STRING },
+	{ NULL, 'Z', 	RTGETOPT_REQ_NOTHING },
+};
+#endif /* VBOX */
+
 
 static char **g_argv;
@@ -93,5 +171,9 @@
 static int g_grabanon = 0;
 static const char *g_ofile = NULL;
+#ifndef _MSC_VER /* stdout isn't a constant usable in C code. */
 static FILE *g_ofp = stdout;
+#else
+static FILE *g_ofp = NULL;
+#endif
 static dtrace_hdl_t *g_dtp;
 static char *g_etcfile = "/etc/system";
@@ -437,4 +519,5 @@
 	(void) close(fd);
 
+#ifndef _MSC_VER
 	if (chown(tmpname, sbuf.st_uid, sbuf.st_gid) != 0) {
 		(void) unlink(tmpname);
@@ -442,4 +525,5 @@
 		    (int)sbuf.st_uid, (int)sbuf.st_gid);
 	}
+#endif
 
 	if (rename(tmpname, fname) == -1)
@@ -511,6 +595,8 @@
 
 	for (i = 0; i < p->dtp_argc; i++) {
+#ifndef VBOX /* no ctf for now  */
 		if (ctf_type_name(p->dtp_argv[i].dtt_ctfp,
 		    p->dtp_argv[i].dtt_type, buf, sizeof (buf)) == NULL)
+#endif
 			(void) strlcpy(buf, "(unknown)", sizeof (buf));
 		oprintf("\t\targs[%d]: %s\n", i, buf);
@@ -742,4 +828,5 @@
 prochandler(struct ps_prochandle *P, const char *msg, void *arg)
 {
+#ifndef VBOX
 	const psinfo_t *prp = Ppsinfo(P);
 	int pid = Pstatus(P)->pr_pid;
@@ -779,4 +866,5 @@
 		break;
 	}
+#endif /* !VBOX */
 }
 
@@ -1155,5 +1243,7 @@
 {
 	dtrace_bufdesc_t buf;
+#ifndef _MSC_VER
 	struct sigaction act, oact;
+#endif
 	dtrace_status_t status[2];
 	dtrace_optval_t opt;
@@ -1165,5 +1255,15 @@
 	struct ps_prochandle *P;
 	pid_t pid;
-
+#ifdef VBOX
+	RTGETOPTUNION ValueUnion;
+	RTGETOPTSTATE GetState;
+
+	err = RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB);
+	if (RT_FAILURE(err))
+		return RTMsgInitFailure(err);
+#endif
+#ifdef _MSC_VER
+	g_ofp = stdout;
+#endif
 	g_pname = basename(argv[0]);
 
@@ -1188,7 +1288,15 @@
 	 * options into g_argv[], and abort if any invalid options are found.
 	 */
+#ifndef VBOX
 	for (optind = 1; optind < argc; optind++) {
 		while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) {
+#else
+	RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, 0);
+	while ((c = RTGetOpt(&GetState, &ValueUnion))) {
+		{
+			const char *optarg = ValueUnion.psz;
+#endif
 			switch (c) {
+#ifndef VBOX
 			case '3':
 				if (strcmp(optarg, "2") != 0) {
@@ -1198,8 +1306,12 @@
 					return (usage(stderr));
 				}
+#else
+			case 10032:
+#endif
 				g_oflags &= ~DTRACE_O_LP64;
 				g_oflags |= DTRACE_O_ILP32;
 				break;
 
+#ifndef VBOX
 			case '6':
 				if (strcmp(optarg, "4") != 0) {
@@ -1209,4 +1321,7 @@
 					return (usage(stderr));
 				}
+#else
+			case 10064:
+#endif
 				g_oflags &= ~DTRACE_O_ILP32;
 				g_oflags |= DTRACE_O_LP64;
@@ -1255,12 +1370,26 @@
 				break;
 
+#ifndef VBOX
 			default:
 				if (strchr(DTRACE_OPTSTR, c) == NULL)
 					return (usage(stderr));
+#else
+			case VINF_GETOPT_NOT_OPTION:
+				g_argv[g_argc++] = (char *)ValueUnion.psz;
+				break;
+
+			default:
+				if (c < 0) { /* Note: Not all options are handled. */
+					RTGetOptPrintError(c, &ValueUnion);
+					return (usage(stderr));
+				}
+#endif
 			}
 		}
 
+#ifndef VBOX
 		if (optind < argc)
 			g_argv[g_argc++] = argv[optind];
+#endif
 	}
 
@@ -1274,4 +1403,5 @@
 		return (printf("%s: %s\n", g_pname, _dtrace_version) <= 0);
 
+#ifndef VBOX
 	/*
 	 * If we're in linker mode and the data model hasn't been specified,
@@ -1323,4 +1453,5 @@
 		}
 	}
+#endif /* !VBOX */
 
 	/*
@@ -1371,6 +1502,14 @@
 	 * this time; these will compiled as part of the fourth processing pass.
 	 */
+#ifndef VBOX
 	for (optind = 1; optind < argc; optind++) {
 		while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) {
+#else
+	RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, 0);
+	while ((c = RTGetOpt(&GetState, &ValueUnion))) {
+		{
+			char *optarg = (char *)ValueUnion.psz;
+#endif
+
 			switch (c) {
 			case 'a':
@@ -1504,7 +1643,15 @@
 				break;
 
+#ifndef VBOX
 			default:
 				if (strchr(DTRACE_OPTSTR, c) == NULL)
 					return (usage(stderr));
+#else
+			default:
+				if (c < 0) { /* Note: Not all options are handled. */
+					RTGetOptPrintError(c, &ValueUnion);
+					return (usage(stderr));
+				}
+#endif
 			}
 		}
@@ -1528,6 +1675,13 @@
 	 * may been affected by any library options set by the second pass.
 	 */
+#ifndef VBOX
 	for (optind = 1; optind < argc; optind++) {
 		while ((c = getopt(argc, argv, DTRACE_OPTSTR)) != EOF) {
+#else
+	RTGetOptInit(&GetState, argc, argv, g_aOptions, RT_ELEMENTS(g_aOptions), 1, 0);
+	while ((c = RTGetOpt(&GetState, &ValueUnion))) {
+		{
+			char *optarg = (char *)ValueUnion.psz;
+#endif
 			switch (c) {
 			case 'c':
@@ -1771,4 +1925,5 @@
 		notice("allowing destructive actions\n");
 
+#ifndef _MSC_VER
 	(void) sigemptyset(&act.sa_mask);
 	act.sa_flags = 0;
@@ -1780,4 +1935,8 @@
 	if (sigaction(SIGTERM, NULL, &oact) == 0 && oact.sa_handler != SIG_IGN)
 		(void) sigaction(SIGTERM, &act, NULL);
+#else
+	signal(SIGINT, intr);
+	signal(SIGTERM, intr);
+#endif
 
 	/*
Index: trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libdtrace/common/dtrace.h
===================================================================
--- trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libdtrace/common/dtrace.h	(revision 53645)
+++ trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libdtrace/common/dtrace.h	(revision 53646)
@@ -28,10 +28,14 @@
 #define	_DTRACE_H
 
+#ifndef VBOX
 #pragma ident	"%Z%%M%	%I%	%E% SMI"
+#endif
 
 #include <sys/dtrace.h>
 #include <stdarg.h>
 #include <stdio.h>
+#ifndef VBOX
 #include <gelf.h>
+#endif
 
 #ifdef	__cplusplus
@@ -431,4 +435,5 @@
  * be flushed and not used subsequently by the client program.
  */
+#ifndef VBOX
 
 #define	DTRACE_OBJ_EXEC	 ((const char *)0L)	/* primary executable file */
@@ -445,4 +450,5 @@
 	int dto_id;				/* object file id (if any) */
 	uint_t dto_flags;			/* object flags (see below) */
+
 	GElf_Addr dto_text_va;			/* address of text section */
 	GElf_Xword dto_text_size;		/* size of text section */
@@ -472,4 +478,5 @@
 extern int dtrace_lookup_by_addr(dtrace_hdl_t *, GElf_Addr addr,
     GElf_Sym *, dtrace_syminfo_t *);
+#endif /* !VBOX */
 
 typedef struct dtrace_typeinfo {
@@ -482,6 +489,8 @@
     dtrace_typeinfo_t *);
 
+#ifndef VBOX
 extern int dtrace_symbol_type(dtrace_hdl_t *, const GElf_Sym *,
     const dtrace_syminfo_t *, dtrace_typeinfo_t *);
+#endif
 
 extern int dtrace_type_strcompile(dtrace_hdl_t *,
@@ -513,4 +522,5 @@
     const dtrace_probedesc_t *, dtrace_probeinfo_t *);
 
+#ifndef VBOX
 /*
  * DTrace Vector Interface
@@ -528,4 +538,5 @@
 	long (*dtv_sysconf)(void *, int);
 };
+#endif /* !VBOX */
 
 /*
