Implement getting program name for NetBSD in SUPR3HardenedMain

The sysctl(7) version is compatible with NetBSD pre-8.0. Older releases
will need to fallback to procfs way similar to Linux. Older versions are
not planned right now to be supported.

PVM is an internal symbol on NetBSD and it conflicts with PVM from VBox.
The NetBSD one needs to be undefined in order make VBox build properly.

This patch is MIT-licensed.

Author: Kamil Rytarowski
Implement getting program name for NetBSD in SUPR3HardenedMain

The sysctl(7) version is compatible with NetBSD pre-8.0. Older releases will
need to fallback to procfs way similar to Linux. Older versions are not planned
right now to be supported.

PVM is an internal symbol on NetBSD and it conflicts with PVM from VBox.
The NetBSD one needs to be undefined in order make VBox build properly.

This patch is MIT-licensed.

Author: Kamil Rytarowski

Index: src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
===================================================================
--- src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp  (wersja 63343)
+++ src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp  (kopia robocza)
@@ -425,9 +425,12 @@
 #  ifndef CAP_TO_MASK
 #   define CAP_TO_MASK(cap) RT_BIT(cap)
 #  endif
-# elif defined(RT_OS_FREEBSD)
+# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
 #  include <sys/param.h>
 #  include <sys/sysctl.h>
+#  ifdef PVM
+#   undef PVM
+#  endif
 # elif defined(RT_OS_SOLARIS)
 #  include <priv.h>
 # endif
@@ -1221,7 +1224,7 @@
      *
      * Darwin, OS/2 and Windows all have proper APIs for getting the program 
file name.
      */
-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD) || 
defined(RT_OS_SOLARIS)
 # ifdef RT_OS_LINUX
     int cchLink = readlink("/proc/self/exe", &g_szSupLibHardenedExePath[0], 
sizeof(g_szSupLibHardenedExePath) - 1);
 
@@ -1230,12 +1233,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 */
+# else /* RT_OS_FREEBSD || RT_OS_NETBSD */
     int aiName[4];
+#  if defined(RT_OS_FREEBSD)
     aiName[0] = CTL_KERN;
     aiName[1] = KERN_PROC;
     aiName[2] = KERN_PROC_PATHNAME;
     aiName[3] = getpid();
+#  else /* RT_OS_NETBSD */
+    aiName[0] = CTL_KERN;
+    aiName[1] = KERN_PROC_ARGS;
+    aiName[2] = getpid();
+    aiName[3] = KERN_PROC_PATHNAME;
+#  endif
 
     size_t cbPath = sizeof(g_szSupLibHardenedExePath);
     if (sysctl(aiName, RT_ELEMENTS(aiName), g_szSupLibHardenedExePath, 
&cbPath, NULL, 0) < 0)

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
vbox-dev mailing list
vbox-dev@virtualbox.org
https://www.virtualbox.org/mailman/listinfo/vbox-dev

Reply via email to