git: c9de267a3525 - main - emulators/virtualbox-ose{,-nox11,-kmod,-additions,-additions-nox11}-legacy: fix build with llvm15+, fix run with PAE on i386

From: Vladimir Druzenko <vvd_at_FreeBSD.org>
Date: Fri, 28 Jun 2024 19:26:18 UTC
The branch main has been updated by vvd:

URL: https://cgit.FreeBSD.org/ports/commit/?id=c9de267a3525a05df601239c02a960cb98445c76

commit c9de267a3525a05df601239c02a960cb98445c76
Author:     Vladimir Druzenko <vvd@FreeBSD.org>
AuthorDate: 2024-06-28 19:08:33 +0000
Commit:     Vladimir Druzenko <vvd@FreeBSD.org>
CommitDate: 2024-06-28 19:08:33 +0000

    emulators/virtualbox-ose{,-nox11,-kmod,-additions,-additions-nox11}-legacy: fix build with llvm15+, fix run with PAE on i386
    
    * Fix build with llvm15+ from ports and from base:
      - ISO C++17 does not allow 'register' storage class specifier;
      - require -fPIC on i386.
    * Fix load kernel modules on host and guest i386 if kernel compiled with
    PAE option: add non-default option PAE to ports.
    Based on patches from mi@.
    
    PR:             279257 224616
    Approved by:    vbox (maintainer, timeout 1 month and 6 years)
---
 emulators/virtualbox-ose-additions-legacy/Makefile |  16 +-
 .../virtualbox-ose-additions-nox11-legacy/Makefile |   2 +-
 emulators/virtualbox-ose-kmod-legacy/Makefile      |  15 +-
 emulators/virtualbox-ose-legacy/Makefile           |  28 +-
 emulators/virtualbox-ose-legacy/files/patch-C++17  | 301 +++++++++++++++++++++
 .../virtualbox-ose-legacy/files/patch-Config.kmk   |  10 +
 emulators/virtualbox-ose-nox11-legacy/Makefile     |   2 +-
 7 files changed, 354 insertions(+), 20 deletions(-)

diff --git a/emulators/virtualbox-ose-additions-legacy/Makefile b/emulators/virtualbox-ose-additions-legacy/Makefile
index 249f4bfa6ef6..8a16ffddefad 100644
--- a/emulators/virtualbox-ose-additions-legacy/Makefile
+++ b/emulators/virtualbox-ose-additions-legacy/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	virtualbox-ose
 PORTVERSION=	5.2.44
-PORTREVISION?=	5
+PORTREVISION?=	6
 CATEGORIES=	emulators
 MASTER_SITES=	https://download.oracle.com/virtualbox/${PORTVERSION}/
 PKGNAMESUFFIX?=	-additions-legacy
@@ -46,12 +46,15 @@ CONFLICTS_INSTALL=	virtualbox-ose \
 			virtualbox-ose-lite \
 			virtualbox-ose-nox11
 
+EXTRACT_AFTER_ARGS=	--exclude tools/*.x86 --exclude tools/*.amd64 --exclude Firmware
 PORTSCOUT=	limit:^5\.
 
-OPTIONS_DEFINE=	DBUS DEBUG X11
+OPTIONS_DEFINE=		DBUS DEBUG X11
+OPTIONS_DEFINE_i386=	PAE
 OPTIONS_DEFAULT=	DBUS X11
-OPTIONS_SUB=	yes
+OPTIONS_SUB=		yes
 
+PAE_DESC=		Build kernel modules for PAE-kernels
 DBUS_CONFIGURE_OFF=	--disable-dbus
 DBUS_LIB_DEPENDS=	libdbus-1.so:devel/dbus
 DEBUG_CONFIGURE_ON=	--build-debug
@@ -131,6 +134,13 @@ post-patch:
 	    ${WRKSRC}/src/VBox/Additions/x11/VBoxClient/Makefile.kmk
 	@${ECHO_CMD} 'VBOX_ICONV_DEFS = LIBICONV_PLUG' >> ${WRKSRC}/LocalConfig.kmk
 .endif
+.if ${PORT_OPTIONS:MPAE}
+	@${ECHO_CMD} 'VBOX_FREEBSD = -DPAE' >> ${WRKSRC}/LocalConfig.kmk
+.endif
+.if ${OPSYS} == FreeBSD && ${OSVERSION} >= 1400093
+	@${REINPLACE_CMD} -e 's|enum vtype|enum enum_vtype_uint8|g' \
+		${WRKSRC}/src/VBox/Additions/freebsd/vboxvfs/vboxvfs*.[ch]
+.endif
 
 post-patch-X11-on:
 	@${ECHO_CMD} 'VBOX_USE_SYSTEM_XORG_HEADERS = 1' >> \
diff --git a/emulators/virtualbox-ose-additions-nox11-legacy/Makefile b/emulators/virtualbox-ose-additions-nox11-legacy/Makefile
index f90f0be0b74d..bbf0e4e133cf 100644
--- a/emulators/virtualbox-ose-additions-nox11-legacy/Makefile
+++ b/emulators/virtualbox-ose-additions-nox11-legacy/Makefile
@@ -1,5 +1,5 @@
 PKGNAMESUFFIX=	-additions-nox11-legacy
-PORTREVISION=	4
+PORTREVISION=	5
 
 OPTIONS_EXCLUDE=	DBUS DEBUG OPENGL X11
 
diff --git a/emulators/virtualbox-ose-kmod-legacy/Makefile b/emulators/virtualbox-ose-kmod-legacy/Makefile
index 40f783cc46d1..5c5b5c4b9d8f 100644
--- a/emulators/virtualbox-ose-kmod-legacy/Makefile
+++ b/emulators/virtualbox-ose-kmod-legacy/Makefile
@@ -43,11 +43,13 @@ CONFLICTS_INSTALL=	virtualbox-ose-kmod
 
 PORTSCOUT=	limit:^5\.
 
-OPTIONS_DEFINE=	DEBUG VIMAGE
-OPTIONS_DEFAULT=VIMAGE
-OPTIONS_SUB=	yes
-DEBUG_DESC=	Debug symbols, additional logs and assertions
-VIMAGE_DESC=	VIMAGE virtual networking support
+OPTIONS_DEFINE=		DEBUG VIMAGE
+OPTIONS_DEFINE_i386=	PAE
+OPTIONS_DEFAULT=	VIMAGE
+OPTIONS_SUB=		yes
+DEBUG_DESC=		Debug symbols, additional logs and assertions
+PAE_DESC=		Build kernel modules for PAE-kernels
+VIMAGE_DESC=		VIMAGE virtual networking support
 
 .include <bsd.port.options.mk>
 
@@ -91,6 +93,9 @@ post-patch:
 	@${ECHO_CMD} 'VBOX_WITH_ADDITIONS =' >> ${WRKSRC}/LocalConfig.kmk
 .if ${PORT_OPTIONS:MVIMAGE}
 	@${ECHO_CMD} 'VBOX_WITH_NETFLT_VIMAGE = 1' >> ${WRKSRC}/LocalConfig.kmk
+.endif
+.if ${PORT_OPTIONS:MPAE}
+	@${ECHO_CMD} 'VBOX_FREEBSD = -DPAE' >> ${WRKSRC}/LocalConfig.kmk
 .endif
 	@${REINPLACE_CMD} -e 's|/usr/local|${LOCALBASE}|g' \
 	    ${WRKSRC}/Config.kmk ${WRKSRC}/configure
diff --git a/emulators/virtualbox-ose-legacy/Makefile b/emulators/virtualbox-ose-legacy/Makefile
index 2ee4220a63dd..2bcb4488401e 100644
--- a/emulators/virtualbox-ose-legacy/Makefile
+++ b/emulators/virtualbox-ose-legacy/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	virtualbox-ose
 PORTVERSION=	5.2.44
-PORTREVISION?=	18
+PORTREVISION?=	19
 CATEGORIES=	emulators
 MASTER_SITES=	https://download.oracle.com/virtualbox/${PORTVERSION}/:src \
 		LOCAL/bofh/emulators/virtualbox-ose-legacy:docs
@@ -110,9 +110,6 @@ X11_USES=		sdl xorg
 X11_USE=		SDL=sdl XORG=x11,xcursor,xext,xinerama,xmu,xorgproto,xt
 X11_CONFIGURE_OFF=	--build-headless
 
-ENV=
-.export ENV
-
 PLIST_SUB=	GUEST_VER=${PORTVERSION} \
 		PYTHON_VERU=${PYTHON_VER:S/./_/}${PYTHON_ABIVER} \
 		VBOXGROUP=${VBOXGROUP}
@@ -194,11 +191,10 @@ KMK_FLAGS+=	-j${MAKE_JOBS_NUMBER}
 .include <bsd.port.pre.mk>
 
 .if ${CHOSEN_COMPILER_TYPE} == clang && ${OPSYS} == FreeBSD && \
-    (${OSVERSION} < 1302505 || (${OSVERSION} >= 1400000 && ${OSVERSION} < 1400079) || \
-    ${OSVERSION} >= 1400091)
-# llvm 13, 14 and 16 included in FreeBSD fails to compile this legacy version of
-# virtualbox-ose, force llvm 15 on all versions of the FreeBSD except lastest 13
-# and several versions of 14 where the llvm 15 is included: PR#265539.
+    (${OSVERSION} < 1302505 || (${OSVERSION} >= 1400000 && ${OSVERSION} < 1400079))
+# llvm before 15 included in old versions of the FreeBSD 13 and 14 fails to compile
+# this legacy version of virtualbox-ose, force llvm 15 on those versions of the
+# FreeBSD: PR#265539, 279257.
 # Keep possibility to define different llvm via VBOX_LLVM_VER in make.conf.
 BUILD_DEPENDS+=	clang${VBOX_LLVM_VER}:devel/llvm${VBOX_LLVM_VER}
 CC=		clang${VBOX_LLVM_VER}
@@ -276,10 +272,15 @@ post-patch:
 	    ${WRKSRC}/LocalConfig.kmk
 	@${ECHO_CMD} 'VBOX_PATH_GSOAP_IMPORT = ${PREFIX}/share/gsoap/import' >> \
 	    ${WRKSRC}/LocalConfig.kmk
-	@${ECHO_CMD} 'VBOX_GCC_PEDANTIC_CXX = -Wshadow $$(VBOX_GCC_WARN) -Wno-long-long' >> \
+	@${ECHO_CMD} 'VBOX_GCC_PEDANTIC_CXX = -Wshadow $$(VBOX_GCC_WARN) -Wno-long-long \
+		-Wno-dynamic-exception-spec -D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION' >> \
 	    ${WRKSRC}/LocalConfig.kmk
 	@${REINPLACE_CMD} -E -e '/soap_socket_errno\(/s/(soap_socket_errno)(\([^)]+\))/\1/' \
 		${WRKSRC}/src/VBox/Main/webservice/vboxweb.cpp
+.else
+	@${ECHO_CMD} 'VBOX_GCC_PEDANTIC_CXX = -Wno-dynamic-exception-spec \
+		-D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION' >> \
+	    ${WRKSRC}/LocalConfig.kmk
 .endif
 	@${REINPLACE_CMD} -e 's| -finline-limit=8000||' \
 	    -e 's| -mpreferred-stack-boundary=2||' \
@@ -304,6 +305,9 @@ post-patch:
 	@${REINPLACE_CMD} -e 's|iconv||' ${WRKSRC}/Config.kmk \
 	    ${WRKSRC}/src/VBox/Runtime/Makefile.kmk
 	@${ECHO_CMD} 'VBOX_ICONV_DEFS = LIBICONV_PLUG' >> ${WRKSRC}/LocalConfig.kmk
+.endif
+.if ${CHOSEN_COMPILER_TYPE} == clang && ${OPSYS} == FreeBSD && ${ARCH} == i386
+	@${ECHO_CMD} 'VBOX_FREEBSD = -fPIC' >> ${WRKSRC}/LocalConfig.kmk
 .endif
 	@${REINPLACE_CMD} -e 's|%%VBOX_DIR%%|${VBOX_DIR}|g' \
 	    -e 's|%%VBOX_ETC%%|${VBOX_ETC}|g' \
@@ -312,6 +316,10 @@ post-patch:
 	@${REINPLACE_CMD} \
 	    -e 's|^versions =.*|versions = ["${PYTHON_VER}${PYTHON_ABIVER}"]|' \
 	    ${WRKSRC}/src/libs/xpcom18a4/python/gen_python_deps.py
+.if ${OPSYS} == FreeBSD && ${OSVERSION} >= 1400093
+	@${REINPLACE_CMD} -e 's|enum vtype|enum enum_vtype_uint8|g' \
+	    ${WRKSRC}/src/VBox/Additions/freebsd/vboxvfs/vboxvfs*.[ch]
+.endif
 
 do-build:
 	cd ${WRKSRC} && ${SH} -c '. ${WRKSRC}/env.sh && \
diff --git a/emulators/virtualbox-ose-legacy/files/patch-C++17 b/emulators/virtualbox-ose-legacy/files/patch-C++17
new file mode 100644
index 000000000000..494705677aba
--- /dev/null
+++ b/emulators/virtualbox-ose-legacy/files/patch-C++17
@@ -0,0 +1,301 @@
+--- src/VBox/Runtime/common/log/logcom.cpp
++++ src/VBox/Runtime/common/log/logcom.cpp
+@@ -121,6 +121,6 @@ 
+     for (pu8 = (const uint8_t *)pach; cb-- > 0; pu8++)
+     {
+-        register unsigned cMaxWait;
+-        register uint8_t  u8;
++        unsigned cMaxWait;
++        uint8_t  u8;
+ 
+         /* expand \n -> \r\n */
+--- src/VBox/Runtime/common/table/avl_Range.cpp.h
++++ src/VBox/Runtime/common/table/avl_Range.cpp.h
+@@ -36,7 +36,7 @@ 
+  * @param     Key     The Key to find matching range for.
+  */
+-KAVL_DECL(PKAVLNODECORE) KAVL_FN(RangeGet)(PPKAVLNODECORE ppTree, register KAVLKEY Key)
++KAVL_DECL(PKAVLNODECORE) KAVL_FN(RangeGet)(PPKAVLNODECORE ppTree, KAVLKEY Key)
+ {
+-    register PKAVLNODECORE  pNode = KAVL_GET_POINTER_NULL(ppTree);
++    PKAVLNODECORE  pNode = KAVL_GET_POINTER_NULL(ppTree);
+     if (pNode)
+     {
+--- src/VBox/Runtime/common/table/avl_GetBestFit.cpp.h
++++ src/VBox/Runtime/common/table/avl_GetBestFit.cpp.h
+@@ -44,5 +44,5 @@ 
+ KAVL_DECL(PKAVLNODECORE) KAVL_FN(GetBestFit)(PPKAVLNODECORE ppTree, KAVLKEY Key, bool fAbove)
+ {
+-    register PKAVLNODECORE  pNode = KAVL_GET_POINTER_NULL(ppTree);
++    PKAVLNODECORE  pNode = KAVL_GET_POINTER_NULL(ppTree);
+     if (pNode)
+     {
+--- src/VBox/Runtime/common/table/avl_Get.cpp.h
++++ src/VBox/Runtime/common/table/avl_Get.cpp.h
+@@ -38,5 +38,5 @@ 
+ KAVL_DECL(PKAVLNODECORE) KAVL_FN(Get)(PPKAVLNODECORE ppTree, KAVLKEY Key)
+ {
+-    register PKAVLNODECORE  pNode = KAVL_GET_POINTER_NULL(ppTree);
++    PKAVLNODECORE  pNode = KAVL_GET_POINTER_NULL(ppTree);
+ 
+     if (pNode)
+--- src/VBox/Runtime/common/table/avl_Base.cpp.h
++++ src/VBox/Runtime/common/table/avl_Base.cpp.h
+@@ -267,5 +267,5 @@ 
+         else
+         {
+-            register unsigned char uchHeight = (unsigned char)(KMAX(uchLeftHeight, uchRightHeight) + 1);
++            unsigned char uchHeight = (unsigned char)(KMAX(uchLeftHeight, uchRightHeight) + 1);
+             if (uchHeight == pNode->uchHeight)
+                 break;
+@@ -301,8 +301,8 @@ 
+     KAVLSTACK               AVLStack;
+     PPKAVLNODECORE          ppCurNode = ppTree;
+-    register PKAVLNODECORE  pCurNode;
+-    register KAVLKEY        Key = pNode->Key; NOREF(Key);
++    PKAVLNODECORE  pCurNode;
++    KAVLKEY        Key = pNode->Key; NOREF(Key);
+ #ifdef KAVL_RANGE
+-    register KAVLKEY        KeyLast = pNode->KeyLast; NOREF(KeyLast);
++    KAVLKEY        KeyLast = pNode->KeyLast; NOREF(KeyLast);
+ #endif
+ 
+@@ -401,5 +401,5 @@ 
+     KAVLSTACK                AVLStack;
+     PPKAVLNODECORE           ppDeleteNode = ppTree;
+-    register PKAVLNODECORE   pDeleteNode;
++    PKAVLNODECORE   pDeleteNode;
+ 
+     AVLStack.cEntries = 0;
+@@ -428,5 +428,5 @@ 
+         const unsigned          iStackEntry = AVLStack.cEntries;
+         PPKAVLNODECORE          ppLeftLeast = &pDeleteNode->pLeft;
+-        register PKAVLNODECORE  pLeftLeast = KAVL_GET_POINTER(ppLeftLeast);
++        PKAVLNODECORE  pLeftLeast = KAVL_GET_POINTER(ppLeftLeast);
+ 
+         while (pLeftLeast->pRight != KAVL_NULL)
+--- src/VBox/Runtime/common/string/utf-16.cpp
++++ src/VBox/Runtime/common/string/utf-16.cpp
+@@ -195,5 +195,5 @@ 
+ 
+ 
+-RTDECL(int) RTUtf16Cmp(register PCRTUTF16 pwsz1, register PCRTUTF16 pwsz2)
++RTDECL(int) RTUtf16Cmp(PCRTUTF16 pwsz1, PCRTUTF16 pwsz2)
+ {
+     if (pwsz1 == pwsz2)
+@@ -206,6 +206,6 @@ 
+     for (;;)
+     {
+-        register RTUTF16  wcs = *pwsz1;
+-        register int     iDiff = wcs - *pwsz2;
++        RTUTF16  wcs = *pwsz1;
++        int     iDiff = wcs - *pwsz2;
+         if (iDiff || !wcs)
+             return iDiff;
+--- src/VBox/Runtime/common/string/utf-16-case.cpp
++++ src/VBox/Runtime/common/string/utf-16-case.cpp
+@@ -40,5 +40,5 @@ 
+ 
+ 
+-RTDECL(int) RTUtf16ICmp(register PCRTUTF16 pwsz1, register PCRTUTF16 pwsz2)
++RTDECL(int) RTUtf16ICmp(PCRTUTF16 pwsz1, PCRTUTF16 pwsz2)
+ {
+     if (pwsz1 == pwsz2)
+@@ -52,7 +52,7 @@ 
+     for (;;)
+     {
+-        register RTUTF16  wc1 = *pwsz1;
+-        register RTUTF16  wc2 = *pwsz2;
+-        register int     iDiff = wc1 - wc2;
++        RTUTF16  wc1 = *pwsz1;
++        RTUTF16  wc2 = *pwsz2;
++        int     iDiff = wc1 - wc2;
+         if (iDiff)
+         {
+@@ -107,5 +107,5 @@ 
+ 
+ 
+-RTDECL(int) RTUtf16BigICmp(register PCRTUTF16 pwsz1, register PCRTUTF16 pwsz2)
++RTDECL(int) RTUtf16BigICmp(PCRTUTF16 pwsz1, PCRTUTF16 pwsz2)
+ {
+     if (pwsz1 == pwsz2)
+@@ -119,7 +119,7 @@ 
+     for (;;)
+     {
+-        register RTUTF16  wc1 = *pwsz1;
+-        register RTUTF16  wc2 = *pwsz2;
+-        register int     iDiff = wc1 - wc2;
++        RTUTF16  wc1 = *pwsz1;
++        RTUTF16  wc2 = *pwsz2;
++        int     iDiff = wc1 - wc2;
+         if (iDiff)
+         {
+@@ -217,5 +217,5 @@ 
+ 
+ 
+-RTDECL(int) RTUtf16NICmp(register PCRTUTF16 pwsz1, register PCRTUTF16 pwsz2, size_t cwcMax)
++RTDECL(int) RTUtf16NICmp(PCRTUTF16 pwsz1, PCRTUTF16 pwsz2, size_t cwcMax)
+ {
+     if (pwsz1 == pwsz2)
+@@ -229,7 +229,7 @@ 
+     while (cwcMax-- > 0)
+     {
+-        register RTUTF16  wc1 = *pwsz1;
+-        register RTUTF16  wc2 = *pwsz2;
+-        register int     iDiff = wc1 - wc2;
++        RTUTF16  wc1 = *pwsz1;
++        RTUTF16  wc2 = *pwsz2;
++        int     iDiff = wc1 - wc2;
+         if (iDiff)
+         {
+@@ -290,5 +290,5 @@ 
+ 
+ 
+-RTDECL(int) RTUtf16BigNICmp(register PCRTUTF16 pwsz1, register PCRTUTF16 pwsz2, size_t cwcMax)
++RTDECL(int) RTUtf16BigNICmp(PCRTUTF16 pwsz1, PCRTUTF16 pwsz2, size_t cwcMax)
+ {
+     if (pwsz1 == pwsz2)
+@@ -302,7 +302,7 @@ 
+     while (cwcMax-- > 0)
+     {
+-        register RTUTF16  wc1 = *pwsz1;
+-        register RTUTF16  wc2 = *pwsz2;
+-        register int     iDiff = wc1 - wc2;
++        RTUTF16  wc1 = *pwsz1;
++        RTUTF16  wc2 = *pwsz2;
++        int     iDiff = wc1 - wc2;
+         if (iDiff)
+         {
+--- src/VBox/HostDrivers/VBoxUSB/USBLib.cpp.orig
++++ src/VBox/HostDrivers/VBoxUSB/USBLib.cpp
+@@ -45,11 +45,11 @@ USBLIB_DECL(uint64_t) USBLibHashSerial(const char *psz
+     if (!pszSerial)
+         pszSerial = "";
+ 
+-    register const uint8_t *pu8 = (const uint8_t *)pszSerial;
+-    register uint64_t u64 = UINT64_C(14695981039346656037);
++    const uint8_t *pu8 = (const uint8_t *)pszSerial;
++    uint64_t u64 = UINT64_C(14695981039346656037);
+     for (;;)
+     {
+-        register uint8_t u8 = *pu8;
++        uint8_t u8 = *pu8;
+         if (!u8)
+             break;
+         u64 = (u64 * UINT64_C(1099511628211)) ^ u8;
+--- src/VBox/Runtime/common/checksum/crc32-zlib.cpp.orig
++++ src/VBox/Runtime/common/checksum/crc32-zlib.cpp
+@@ -51,7 +51,7 @@ static uint32_t rtCrc32ProcessTooBig(uint32_t uCRC32, 
+     return uCRC32;
+ }
+ 
+-RTDECL(uint32_t) RTCrc32(const void *pv, register size_t cb)
++RTDECL(uint32_t) RTCrc32(const void *pv, size_t cb)
+ {
+     uint32_t uCrc = crc32(0, NULL, 0);
+     if (RT_UNLIKELY((uInt)cb == cb))
+--- src/VBox/Devices/Network/DevPCNet.cpp.orig
++++ src/VBox/Devices/Network/DevPCNet.cpp
+@@ -1242,8 +1242,8 @@ static void pcnetSoftReset(PPCNETSTATE pThis)
+  */
+ static void pcnetUpdateIrq(PPCNETSTATE pThis)
+ {
+-    register int      iISR = 0;
+-    register uint16_t csr0 = pThis->aCSR[0];
++    int      iISR = 0;
++    uint16_t csr0 = pThis->aCSR[0];
+ 
+     csr0 &= ~0x0080; /* clear INTR */
+ 
+--- src/VBox/VMM/VMMAll/PGMAllGst.h.orig
++++ src/VBox/VMM/VMMAll/PGMAllGst.h
+@@ -92,7 +92,7 @@ DECLINLINE(int) PGM_GST_NAME(Walk)(PVMCPU pVCpu, RTGCP
+         return PGM_GST_NAME(WalkReturnNotPresent)(pVCpu, pWalk, 8);
+ # endif
+ 
+-    uint32_t register fEffective = X86_PTE_RW | X86_PTE_US | X86_PTE_PWT | X86_PTE_PCD | X86_PTE_A | 1;
++    uint32_t fEffective = X86_PTE_RW | X86_PTE_US | X86_PTE_PWT | X86_PTE_PCD | X86_PTE_A | 1;
+     {
+ # if PGM_GST_TYPE == PGM_TYPE_AMD64
+         /*
+@@ -102,9 +102,9 @@ DECLINLINE(int) PGM_GST_NAME(Walk)(PVMCPU pVCpu, RTGCP
+         if (RT_SUCCESS(rc)) { /* probable */ }
+         else return PGM_GST_NAME(WalkReturnBadPhysAddr)(pVCpu, pWalk, 4, rc);
+ 
+-        PX86PML4E register  pPml4e;
++        PX86PML4E pPml4e;
+         pWalk->pPml4e  = pPml4e  = &pWalk->pPml4->a[(GCPtr >> X86_PML4_SHIFT) & X86_PML4_MASK];
+-        X86PML4E  register  Pml4e;
++        X86PML4E  Pml4e;
+         pWalk->Pml4e.u = Pml4e.u = pPml4e->u;
+ 
+         if (Pml4e.n.u1Present) { /* probable */ }
+@@ -131,9 +131,9 @@ DECLINLINE(int) PGM_GST_NAME(Walk)(PVMCPU pVCpu, RTGCP
+     }
+     {
+ # if PGM_GST_TYPE == PGM_TYPE_AMD64 || PGM_GST_TYPE == PGM_TYPE_PAE
+-        PX86PDPE register   pPdpe;
++        PX86PDPE pPdpe;
+         pWalk->pPdpe  = pPdpe  = &pWalk->pPdpt->a[(GCPtr >> GST_PDPT_SHIFT) & GST_PDPT_MASK];
+-        X86PDPE  register   Pdpe;
++        X86PDPE  Pdpe;
+         pWalk->Pdpe.u = Pdpe.u = pPdpe->u;
+ 
+         if (Pdpe.n.u1Present) { /* probable */ }
+@@ -164,7 +164,7 @@ DECLINLINE(int) PGM_GST_NAME(Walk)(PVMCPU pVCpu, RTGCP
+ # endif
+     }
+     {
+-        PGSTPDE register    pPde;
++        PGSTPDE pPde;
+         pWalk->pPde  = pPde  = &pWalk->pPd->a[(GCPtr >> GST_PD_SHIFT) & GST_PD_MASK];
+         GSTPDE              Pde;
+         pWalk->Pde.u = Pde.u = pPde->u;
+@@ -221,9 +221,9 @@ DECLINLINE(int) PGM_GST_NAME(Walk)(PVMCPU pVCpu, RTGCP
+         else return PGM_GST_NAME(WalkReturnBadPhysAddr)(pVCpu, pWalk, 1, rc);
+     }
+     {
+-        PGSTPTE register    pPte;
++        PGSTPTE pPte;
+         pWalk->pPte  = pPte  = &pWalk->pPt->a[(GCPtr >> GST_PT_SHIFT) & GST_PT_MASK];
+-        GSTPTE  register    Pte;
++        GSTPTE  Pte;
+         pWalk->Pte.u = Pte.u = pPte->u;
+ 
+         if (Pte.n.u1Present) { /* probable */ }
+--- include/VBox/HostServices/Service.h.orig
++++ include/VBox/HostServices/Service.h
+@@ -358,11 +358,11 @@ class AbstractService: public RTCNonCopyable (public)
+             else
+             {
+                 RT_GCC_NO_WARN_DEPRECATED_BEGIN
+-                std::auto_ptr<AbstractService> apService;
++                std::unique_ptr<AbstractService> apService;
+                 /* No exceptions may propagate outside. */
+                 try
+                 {
+-                    apService = std::auto_ptr<AbstractService>(new T(pTable->pHelpers));
++                    apService = std::unique_ptr<AbstractService>(new T(pTable->pHelpers));
+                 } catch (int rcThrown)
+                 {
+                     rc = rcThrown;
+--- src/VBox/Main/src-server/PerformanceImpl.cpp.orig
++++ src/VBox/Main/src-server/PerformanceImpl.cpp
+@@ -699,7 +699,7 @@ void PerformanceCollector::samplerCallback(uint64_t iT
+      * Those should be destroyed now.
+      */
+     Log7Func(("{%p}: before remove_if: toBeCollected.size()=%d\n", this, toBeCollected.size()));
+-    toBeCollected.remove_if(std::mem_fun(&pm::BaseMetric::isUnregistered));
++    toBeCollected.remove_if(std::mem_fn(&pm::BaseMetric::isUnregistered));
+     Log7Func(("{%p}: after remove_if: toBeCollected.size()=%d\n", this, toBeCollected.size()));
+     Log7Func(("{%p}: before remove_if: m.baseMetrics.size()=%d\n", this, m.baseMetrics.size()));
+     for (it = m.baseMetrics.begin(); it != m.baseMetrics.end();)
+@@ -720,7 +720,7 @@ void PerformanceCollector::samplerCallback(uint64_t iT
+ 
+     /* Finally, collect the data */
+     std::for_each(toBeCollected.begin(), toBeCollected.end(),
+-                  std::mem_fun(&pm::BaseMetric::collect));
++                  std::mem_fn(&pm::BaseMetric::collect));
+     Log4Func(("{%p}: LEAVE\n", this));
+ }
+ 
diff --git a/emulators/virtualbox-ose-legacy/files/patch-Config.kmk b/emulators/virtualbox-ose-legacy/files/patch-Config.kmk
index 784ec4295655..d0f88dcff48b 100644
--- a/emulators/virtualbox-ose-legacy/files/patch-Config.kmk
+++ b/emulators/virtualbox-ose-legacy/files/patch-Config.kmk
@@ -93,6 +93,16 @@
  else
   # This is kind of bad, the returned string needs to be re-evaluated before use.
   # The reason for this hack is that the windows kmk_ash cannot deal with $((1+1)).
+@@ -3068,6 +3069,9 @@ ifeq ($(KBUILD_TARGET_ARCH),x86)
+   # (The '<=' operator is for prepending (kmk specific).)
+   VBOX_GCC_OPT <= -march=i586
+  endif
++ ifeq ($(KBUILD_TARGET),freebsd)
++  VBOX_GCC_OPT <= $(VBOX_FREEBSD)
++ endif
+ endif
+ 
+ 
 @@ -4218,6 +4219,7 @@ ifdef VBOX_WITH_RAW_MODE
   TEMPLATE_VBoxRc_TOOL                = $(VBOX_GCC32_TOOL)
   TEMPLATE_VBoxRc_CXXFLAGS            = -fno-pie -nostdinc -g $(VBOX_GCC_pipe) $(VBOX_GCC_WERR) $(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC32_Wno-variadic-macros) -fno-exceptions $(VBOX_GCC_GC_OPT) $(VBOX_GCC_GC_FP) -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -fno-strict-aliasing $(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_fvisibility-hidden) $(VBOX_GCC_fvisibility-inlines-hidden) -fno-rtti $(VBOX_GCC_IPRT_FMT_CHECK)
diff --git a/emulators/virtualbox-ose-nox11-legacy/Makefile b/emulators/virtualbox-ose-nox11-legacy/Makefile
index 679f9e07564c..33102a46f019 100644
--- a/emulators/virtualbox-ose-nox11-legacy/Makefile
+++ b/emulators/virtualbox-ose-nox11-legacy/Makefile
@@ -1,4 +1,4 @@
-PORTREVISION=	16
+PORTREVISION=	17
 PKGNAMESUFFIX=	-nox11-legacy
 
 OPTIONS_EXCLUDE=	ALSA DBUS DEBUG GUESTADDITIONS DOCS NLS PULSEAUDIO