--- src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp.orig	2009-06-12 14:34:40.000000000 +0200
+++ src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp	2009-12-10 14:16:46.000000000 +0100
@@ -66,6 +66,9 @@
 #  ifndef CAP_TO_MASK
 #   define CAP_TO_MASK(cap) RT_BIT(cap)
 #  endif
+# elif defined(RT_OS_FREEBSD)
+#  include <sys/param.h>
+#  include <sys/sysctl.h>
 # elif defined(RT_OS_SOLARIS)
 #  include <priv.h>
 # endif
@@ -325,7 +328,19 @@
     sprintf(szFileBuf, "/proc/%ld/path/a.out", (long)getpid());
     int cchLink = readlink(szFileBuf, &g_szSupLibHardenedExePath[0], sizeof(g_szSupLibHardenedExePath) - 1);
 # else /* RT_OS_FREEBSD: */
-    int cchLink = readlink("/proc/curproc/file", &g_szSupLibHardenedExePath[0], sizeof(g_szSupLibHardenedExePath) - 1);
+    int name[4];
+    size_t len;
+
+    name[0] = CTL_KERN;
+    name[1] = KERN_PROC;
+    name[2] = KERN_PROC_PATHNAME;
+    name[3] = getpid();
+
+    len = sizeof(g_szSupLibHardenedExePath) - 1;
+    if(sysctl(name, 4, g_szSupLibHardenedExePath, &len, NULL, 0) < 0)
+       supR3HardenedFatal("supR3HardenedExecDir: sysctl failed\n");
+
+    int cchLink = strlen(g_szSupLibHardenedExePath);
 # endif
     if (cchLink < 0 || cchLink == sizeof(g_szSupLibHardenedExePath) - 1)
         supR3HardenedFatal("supR3HardenedExecDir: couldn't read \"%s\", errno=%d cchLink=%d\n",
--- src/VBox/Runtime/VBox/log-vbox.cpp.orig	2009-09-01 13:22:24.000000000 +0200
+++ src/VBox/Runtime/VBox/log-vbox.cpp	2009-12-10 15:10:28.000000000 +0100
@@ -135,6 +135,12 @@
 #  include <Windows.h>
 # elif defined(RT_OS_LINUX)
 #  include <unistd.h>
+# elif defined(RT_OS_FREEBSD)
+#  include <sys/param.h>
+#  include <sys/sysctl.h>
+#  include <sys/user.h>
+#  include <stdlib.h>
+#  include <unistd.h>
 # elif defined(RT_OS_SOLARIS)
 #  define _STRUCTURED_PROC 1
 #  undef _FILE_OFFSET_BITS /* procfs doesn't like this */
@@ -339,12 +345,8 @@
             fclose(pFile);
         }
 
-#  elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
-#   ifdef RT_OS_LINUX
+#  elif defined(RT_OS_LINUX)
         FILE *pFile = fopen("/proc/self/cmdline", "r");
-#   else /* RT_OS_FREEBSD: */
-        FILE *pFile = fopen("/proc/curproc/cmdline", "r");
-#   endif
         if (pFile)
         {
             /* braindead */
@@ -370,6 +372,29 @@
                 RTLogLoggerEx(pLogger, 0, ~0U, "\n");
             fclose(pFile);
         }
+#  elif defined(RT_OS_FREEBSD)
+        char szArgFileBuf[80];
+        int name[4];
+        size_t len;
+
+        name[0] = CTL_KERN;
+        name[1] = KERN_PROC;
+        name[2] = KERN_PROC_ARGS;
+        name[3] = getpid();
+
+        len = strlen(szArgFileBuf) - 1;
+        sysctl(name, 4, szArgFileBuf, &len, NULL, 0);
+
+        /* cmdline is a flattened argument list so we need
+         * to convert all \0 to blanks
+         */
+        for(int i=0; i < len - 1; i++)
+        {
+           if(szArgFileBuf[i] == '\0')
+              szArgFileBuf[i] = ' ';
+        }
+
+        RTLogLoggerEx(pLogger, 0, ~0U, "Commandline: %ls\n", szArgFileBuf);
 
 #  elif defined(RT_OS_L4) || defined(RT_OS_OS2) || defined(RT_OS_DARWIN)
         /* commandline? */
--- src/VBox/Runtime/r3/freebsd/rtProcInitExePath-freebsd.cpp.orig	2009-03-13 11:39:08.000000000 +0100
+++ src/VBox/Runtime/r3/freebsd/rtProcInitExePath-freebsd.cpp	2009-12-10 14:48:34.000000000 +0100
@@ -32,6 +32,8 @@
 *   Header Files                                                               *
 *******************************************************************************/
 #define LOG_GROUP RTLOGGROUP_PROCESS
+#include <sys/param.h>
+#include <sys/sysctl.h>
 #include <unistd.h>
 #include <errno.h>
 #include <dlfcn.h>
@@ -47,14 +49,17 @@
 
 DECLHIDDEN(int) rtProcInitExePath(char *pszPath, size_t cchPath)
 {
-    /*
-     * Read the /proc/curproc/file link, convert to native and return it.
-     */
-    int cchLink = readlink("/proc/curproc/file", pszPath, cchPath - 1);
-    if (cchLink > 0 && (size_t)cchLink <= cchPath - 1)
-    {
-        pszPath[cchLink] = '\0';
+    int name[4];
+    size_t len;
+
+    name[0] = CTL_KERN;
+    name[1] = KERN_PROC;
+    name[2] = KERN_PROC_PATHNAME;
+    name[3] = getpid();
 
+    len = cchPath - 1;
+    if(sysctl(name, 4, pszPath, &len, NULL, 0) == 0)
+    {
         char *pszTmp = NULL;
         int rc = rtPathFromNative(&pszTmp, pszPath);
         AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhsx\n", rc, pszPath, cchLink, pszPath), rc);
@@ -70,35 +75,6 @@
 
     int err = errno;
 
-    /*
-     * Fall back on the dynamic linker since /proc is optional.
-     */
-    void *hExe = dlopen(NULL, 0);
-    if (hExe)
-    {
-        struct link_map const *pLinkMap = 0;
-        if (dlinfo(hExe, RTLD_DI_LINKMAP, &pLinkMap) == 0)
-        {
-            const char *pszImageName = pLinkMap->l_name;
-            if (*pszImageName == '/') /* this may not always be absolute, despite the docs. :-( */
-            {
-                char *pszTmp = NULL;
-                int rc = rtPathFromNative(&pszTmp, pszImageName);
-                AssertMsgRCReturn(rc, ("rc=%Rrc pszImageName=\"%s\"\n", rc, pszImageName), rc);
-
-                size_t cch = strlen(pszTmp);
-                AssertReturn(cch <= cchPath, VERR_BUFFER_OVERFLOW);
-
-                memcpy(pszPath, pszTmp, cch + 1);
-                RTStrFree(pszTmp);
-
-                return VINF_SUCCESS;
-            }
-            /** @todo Try search the PATH for the file name or append the current
-             *        directory, which ever makes sense... */
-        }
-    }
-
     int rc = RTErrConvertFromErrno(err);
     AssertMsgFailed(("rc=%Rrc err=%d cchLink=%d hExe=%p\n", rc, err, cchLink, hExe));
     return rc;
