summaryrefslogtreecommitdiff
path: root/emulators/virtualbox-ose-71/files
diff options
context:
space:
mode:
Diffstat (limited to 'emulators/virtualbox-ose-71/files')
-rw-r--r--emulators/virtualbox-ose-71/files/extrapatch-Config.kmk11
-rw-r--r--emulators/virtualbox-ose-71/files/extrapatch-src-VBox-HostDrivers-Support-freebsd-Makefile11
-rw-r--r--emulators/virtualbox-ose-71/files/extrapatch-vboximg-Config.kmk11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-Config.kmk402
-rw-r--r--emulators/virtualbox-ose-71/files/patch-configure138
-rw-r--r--emulators/virtualbox-ose-71/files/patch-doc_manual_en__US_dita_UserManual.ditamap11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-include-iprt-x86.h19
-rw-r--r--emulators/virtualbox-ose-71/files/patch-include_VBox_com_array.h36
-rw-r--r--emulators/virtualbox-ose-71/files/patch-include_VBox_sup.h11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-include_iprt_string.h14
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-VBoxGuest-freebsd.c284
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-freebsd-Makefile27
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-freebsd-files_vboxguest34
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-x11-Installer-98vboxadd-xclient25
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-x11-Installer-vboxclient.desktop10
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Devices-Network-DrvNATlibslirp.cpp10
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Devices-Network-slirp-bsd-sys-mbuf.h12
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-HostDrivers-VBoxNetAdp-Makefile.kmk20
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-HostDrivers-VBoxNetFlt-freebsd-files_vboxnetflt10
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Installer-Makefile.kmk14
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Installer-freebsd-VBox.sh77
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Main-src-server-VirtualBoxImpl.cpp11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Runtime-Makefile.kmk14
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src-VBox-Runtime-r0drv-freebsd-sleepqueue-r0drv-freebsd.h39
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_common_VBoxService_VBoxServiceVMInfo.cpp71
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_common_pam_pam__vbox.cpp20
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_Makefile38
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_Makefile.kmk31
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_drm_vboxvideo__drm.c17
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_Makefile.kmk31
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_mount__vboxvfs.856
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_mount__vboxvfs.c171
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_bcmp.c12
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs.h428
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__prov.c1015
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__vfsops.c645
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__vnops.c1543
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_x11_vboxmouse_Makefile.kmk29
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA.cpp20
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-dx-dx11.cpp11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-glLdr.cpp29
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-glLdr.h11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-ogl.cpp56
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Makefile.kmk44
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_PC_ipxe_Makefile.kmk29
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_USB_USBProxyDevice-freebsd.cpp11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_ExtPacks_VNC_VBoxVNC.cpp58
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Frontends_VBoxHeadless_VBoxHeadless.cpp11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Frontends_VBoxManage_VBoxManageModifyVM.cpp29
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_SUPDrv.cpp13
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_SUPDrvInternal.h11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_Makefile30
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c234
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPLib-freebsd.cpp11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_files__vboxdrv34
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetAdp_freebsd_Makefile11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetAdp_freebsd_VBoxNetAdp-freebsd.c147
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_Makefile.kmk11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_freebsd_Makefile11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_freebsd_VBoxNetFlt-freebsd.c471
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_adpctl_VBoxNetAdpCtl.cpp11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Main_Makefile.kmk10
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Main_include_HostPower.h20
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Main_src-server_HostImpl.cpp11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Main_src-server_freebsd_PerformanceFreeBSD.cpp24
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_Makefile.kmk29
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_alloc-r0drv-freebsd.c58
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_assert-r0drv-freebsd.c29
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_memobj-r0drv-freebsd.c408
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_memuserkernel-r0drv-freebsd.c22
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_mp-r0drv-freebsd.c92
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semevent-r0drv-freebsd.c53
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semeventmulti-r0drv-freebsd.c73
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semfastmutex-r0drv-freebsd.c59
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semmutex-r0drv-freebsd.c80
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_spinlock-r0drv-freebsd.c30
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_the-freebsd-kernel.h48
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_thread-r0drv-freebsd.c91
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_thread2-r0drv-freebsd.c35
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_time-r0drv-freebsd.c43
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_timer-r0drv-freebsd.c68
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r3_freebsd_systemmem-freebsd.cpp39
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r3_posix_process-creation-posix.cpp38
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VBox_VMM_VMMR3_PDMAsyncCompletionFileNormal.cpp59
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_VMM_Config.kmk11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_Makefile.kmk11
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_nsprpub_pr_src_pthreads_ptsynch.c13
-rw-r--r--emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_xpcom_io_nsLocalFileUnix.h17
-rw-r--r--emulators/virtualbox-ose-71/files/pkg-message.in120
-rw-r--r--emulators/virtualbox-ose-71/files/vboxheadless.in140
-rw-r--r--emulators/virtualbox-ose-71/files/vboxinit.in91
-rw-r--r--emulators/virtualbox-ose-71/files/vboxwatchdog.in51
-rw-r--r--emulators/virtualbox-ose-71/files/vboxwebsrv.in47
-rw-r--r--emulators/virtualbox-ose-71/files/virtualbox.desktop17
94 files changed, 8599 insertions, 0 deletions
diff --git a/emulators/virtualbox-ose-71/files/extrapatch-Config.kmk b/emulators/virtualbox-ose-71/files/extrapatch-Config.kmk
new file mode 100644
index 000000000000..775508d23b1b
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/extrapatch-Config.kmk
@@ -0,0 +1,11 @@
+--- Config.kmk.orig 2021-04-28 16:21:25 UTC
++++ Config.kmk
+@@ -4931,7 +4931,7 @@ define TOOL_FREEBSDKMODLD_LINK_SYSMOD_CMDS
+ | xargs -J% objcopy % $(out)
+
+ ## Strip debug info (comment out if debugging or something).
+- objcopy --strip-debug $(out)
++# objcopy --strip-debug $(out)
+ endef
+ else # x86
+ TOOL_FREEBSDKMODLD_LINK_SYSMOD_OUTPUT = $(outbase).kld
diff --git a/emulators/virtualbox-ose-71/files/extrapatch-src-VBox-HostDrivers-Support-freebsd-Makefile b/emulators/virtualbox-ose-71/files/extrapatch-src-VBox-HostDrivers-Support-freebsd-Makefile
new file mode 100644
index 000000000000..67361da543f7
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/extrapatch-src-VBox-HostDrivers-Support-freebsd-Makefile
@@ -0,0 +1,11 @@
+--- src/VBox/HostDrivers/Support/freebsd/Makefile.orig 2012-10-18 16:23:16.000000000 +0200
++++ src/VBox/HostDrivers/Support/freebsd/Makefile 2012-10-20 08:13:07.301179212 +0200
+@@ -27,7 +27,7 @@
+
+ KMOD = vboxdrv
+
+-CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DSUPDRV_WITH_RELEASE_LOGGER -DVBOX -DRT_WITH_VBOX -Iinclude -I. -Ir0drv -w -DVBOX_WITH_HARDENING -DVBOX_WITH_64_BITS_GUESTS
++CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DSUPDRV_WITH_RELEASE_LOGGER -DVBOX -DRT_WITH_VBOX -Iinclude -I. -Ir0drv -w -DVBOX_WITH_HARDENING -DVBOX_WITH_64_BITS_GUESTS -DDEBUG
+
+ .if (${MACHINE_ARCH} == "i386")
+ CFLAGS += -DRT_ARCH_X86
diff --git a/emulators/virtualbox-ose-71/files/extrapatch-vboximg-Config.kmk b/emulators/virtualbox-ose-71/files/extrapatch-vboximg-Config.kmk
new file mode 100644
index 000000000000..d84209faa8cd
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/extrapatch-vboximg-Config.kmk
@@ -0,0 +1,11 @@
+--- Config.kmk.orig 2023-10-12 15:43:35.000000000 +0700
++++ Config.kmk 2023-10-30 22:11:09.119922000 +0700
+@@ -869,7 +869,7 @@
+ # windows versions (only define when buildling win.x86).
+ #VBOX_WITH_MORE_NT4_COMPAT_BINARIES = 1
+ # Set this to enable building of the vboximg-mount FUSE mounting utility.
+-if1of ($(KBUILD_TARGET), darwin linux)
++if1of ($(KBUILD_TARGET), darwin freebsd linux)
+ VBOX_WITH_VBOXIMGMOUNT = 1
+ endif
+ # Set this to enable packaging the fuse related bits into our installer.
diff --git a/emulators/virtualbox-ose-71/files/patch-Config.kmk b/emulators/virtualbox-ose-71/files/patch-Config.kmk
new file mode 100644
index 000000000000..7aaf90147847
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-Config.kmk
@@ -0,0 +1,402 @@
+--- Config.kmk.orig 2025-05-10 18:43:02 UTC
++++ Config.kmk
+@@ -610,11 +610,11 @@ endif
+ # Enable OSS audio support.
+ VBOX_WITH_AUDIO_OSS = 1
+ endif
+-if1of ($(KBUILD_TARGET), linux)
++if1of ($(KBUILD_TARGET), freebsd linux)
+ # Enable ALSA audio support.
+ VBOX_WITH_AUDIO_ALSA = 1
+ endif
+-if1of ($(KBUILD_TARGET), linux)
++if1of ($(KBUILD_TARGET), freebsd linux)
+ # Enable PulseAudio audio support.
+ VBOX_WITH_AUDIO_PULSE = 1
+ endif
+@@ -627,11 +627,11 @@ VBOX_WITH_PCI_PASSTHROUGH =
+ # (disabled with 6.1, since it's not complete/useful enough)
+ VBOX_WITH_PCI_PASSTHROUGH =
+ # Enable statically linked dbus support.
+-if1of ($(KBUILD_TARGET), linux solaris)
++if1of ($(KBUILD_TARGET), freebsd linux solaris)
+ VBOX_WITH_DBUS = 1
+ endif
+ # Enable building PAM modules.
+-if1of ($(KBUILD_TARGET), linux solaris)
++if1of ($(KBUILD_TARGET), freebsd linux solaris)
+ VBOX_WITH_PAM = 1
+ endif
+ # Enable internal networking.
+@@ -639,7 +639,7 @@ VBOX_WITH_VMSVGA = 1
+ # Enable vmsvga (svga2) graphics device variant, 2D part
+ VBOX_WITH_VMSVGA = 1
+ # Enable vmsvga (svga2) graphics device variant, 3D part
+-if1of ($(KBUILD_TARGET), darwin linux win)
++if1of ($(KBUILD_TARGET), darwin freebsd linux win)
+ VBOX_WITH_VMSVGA3D = 1
+ endif
+ # Enable vmsvga (svga2) graphics device variant, 3D part, VGPU10 DX commands
+@@ -825,7 +825,7 @@ VBOX_WITH_VBOXMANAGE_NLS = 1
+ #endif
+ # Set this to prefix all C symbols in XPCOM, to avoid dynamic linking problems
+ # caused by our XPCOM library polluting the symbol namespace for system libs.
+-if1of ($(KBUILD_TARGET), linux solaris)
++if1of ($(KBUILD_TARGET), freebsd linux solaris)
+ VBOX_WITH_XPCOM_NAMESPACE_CLEANUP = 1
+ endif
+ # The webservices api.
+@@ -1357,10 +1357,6 @@ endif
+ endif
+ endif
+
+-ifeq ($(KBUILD_TARGET),freebsd)
+- VBOX_WITH_DOCS =
+-endif
+-
+ ifeq ($(KBUILD_TARGET),haiku)
+ VBOX_WITH_VRDP_RDESKTOP =
+ # Permanent (no working SDL).
+@@ -1545,7 +1541,7 @@ ifdef VBOX_OSE
+ # not yet
+ VBOX_WITH_PLUGIN_CRYPT =
+ VBOX_WITH_DRAG_AND_DROP_PROMISES =
+- ifn1of ($(KBUILD_TARGET), linux)
++ ifn1of ($(KBUILD_TARGET), freebsd linux)
+ VBOX_WITH_DOCS =
+ VBOX_WITH_DOCS_PACKING =
+ endif
+@@ -3680,19 +3676,7 @@ ifndef VBOX_GCC_std
+ #
+ ## @todo consider maxing this out.
+ ifndef VBOX_GCC_std
+- if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), darwin.arm64) # Go straight for c++17 here.
+ VBOX_GCC_std := -std=c++17
+- # else if "$(VBOX_CLANG_VERSION_CXX)" vge 60000 # Most language features complete by v6. Lib stuff was less complete in v6, but hopefully acceptable for out purposes.
+- #VBOX_GCC_std := -std=c++17
+- else if "$(VBOX_CLANG_VERSION_CXX)" vge 50000 # darwin Xcode 5 allegedly knows what C++11 is
+- VBOX_GCC_std := -std=c++11
+- # else if "$(VBOX_GCC_VERSION_CXX)" vge 70000 # Language feature P0512R0 was v8, rest v7 or earlier. Most lib stuff present in 7, complete in v12.
+- #VBOX_GCC_std := -std=gnu++17
+- else if "$(VBOX_GCC_VERSION_CXX)" vge 40800
+- VBOX_GCC_std := -std=c++11
+- else if "$(VBOX_GCC_VERSION_CXX)" vge 40600
+- VBOX_GCC_std := -std=c++0x
+- endif
+ endif
+ ifndef VBOX_VCC_std
+ if $(VBOX_VCC_TOOL_STEM) >= VCC141 # since 2017 15.3
+@@ -5682,11 +5666,11 @@ ifeq ($(VBOX_LDR_FMT),elf)
+ # Solaris driver signing.
+ TEMPLATE_VBoxR0_POST_CMDS = $(VBOX_SIGN_DRIVER_CMDS)
+ else
+- TEMPLATE_VBoxR0_LDFLAGS = -nostdlib -Bsymbolic -g
++ TEMPLATE_VBoxR0_LDFLAGS = -nostdlib -Bsymbolic -g -fuse-ld=bfd
+ ## @todo WTF doesn't the globals work? Debug info is supposed to be split everywhere. GRR
+ TEMPLATE_VBoxR0_LD_DEBUG = split
+ endif
+- if "$(KBUILD_TARGET)" == "linux" && !defined(VBOX_WITH_KMOD_WRAPPED_R0_MODS)
++ if ( "$(KBUILD_TARGET)" == "linux" || "$(KBUILD_TARGET)" == "freebsd") && !defined(VBOX_WITH_KMOD_WRAPPED_R0_MODS)
+ VBOX_WITH_VBOXR0_AS_DLL = 1
+ TEMPLATE_VBoxR0_DLLSUFF = .r0
+ TEMPLATE_VBoxR0_CFLAGS += -fPIC
+@@ -5697,7 +5681,7 @@ ifeq ($(VBOX_LDR_FMT),elf)
+ else
+ TEMPLATE_VBoxR0_CFLAGS.amd64 += -mcmodel=kernel
+ TEMPLATE_VBoxR0_CXXFLAGS.amd64 += -mcmodel=kernel
+- endif
++endif
+ ifdef VBOX_WITH_KMOD_WRAPPED_R0_MODS # For BTF/pahold issue we use -g1
+ TEMPLATE_VBoxR0_DEFS += VBOX_WITH_KMOD_WRAPPED_R0_MODS
+ TEMPLATE_VBoxR0_LDFLAGS.linux += $(PATH_ROOT)/src/VBox/HostDrivers/Support/linux/VBoxR0-wrapped.lds
+@@ -6081,7 +6065,7 @@ ifeq ($(KBUILD_TARGET),freebsd)
+ # x86 FreeBSD (6.2 or something):
+ # cc -O2 -fno-strict-aliasing -pipe -Werror -D_KERNEL -DKLD_MODULE \
+ # -nostdinc -I- -I. -I@ -I@/contrib/altq -I@/../include -I/usr/include \
+- # -finline-limit=8000 -fno-common -mno-align-long-strings -mpreferred-stack-boundary=2 \
++ # -fno-common -mno-align-long-strings \
+ # -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -ffreestanding -Wall -Wredundant-decls -Wnested-externs \
+ # -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -fformat-extensions \
+ # -std=c99 -c ../my.c
+@@ -6092,7 +6076,7 @@ ifeq ($(KBUILD_TARGET),freebsd)
+ #
+ # AMD64 FreeBSD (7.1):
+ # cc -O2 -fno-strict-aliasing -pipe -D_KERNEL -DKLD_MODULE -std=c99 -nostdinc -I. -I@ -I@/contrib/altq \
+- # -finline-limit=8000 --param inline-unit-growth=100 --param large-function-growth=1000 -fno-common \
++ # --param inline-unit-growth=100 --param large-function-growth=1000 -fno-common \
+ # -fno-omit-frame-pointer -mcmodel=kernel -mno-red-zone -mfpmath=387 -mno-sse -mno-sse2 -mno-mmx \
+ # -mno-3dnow -msoft-float -fno-asynchronous-unwind-tables -ffreestanding \
+ # -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign \
+@@ -6174,7 +6158,7 @@ ifeq ($(KBUILD_TARGET),freebsd)
+ | xargs -J% objcopy % $(outbase).kld
+
+ # Link the final .ko (a shared object).
+- ld $(flags) -Bshareable -o $(out) $(outbase).kld
++ ld $(flags) -Bshareable -znotext -o $(out) $(outbase).kld
+ endef
+ endif # x86
+
+@@ -6209,7 +6193,7 @@ ifeq ($(KBUILD_TARGET),netbsd)
+ $(VBOX_GCC_fdiagnostics-show-option) \
+ -Wstrict-prototypes -Wmissing-prototypes -Wstrict-prototypes \
+ -Wimplicit-function-declaration -Werror-implicit-function-declaration \
+- -O2 -ffreestanding -fno-strict-aliasing -fno-common -finline-limit=8000 \
++ -O2 -ffreestanding -fno-strict-aliasing -fno-common \
+ $(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
+ -nostdinc -std=c99 -msoft-float
+ TEMPLATE_VBoxR0Drv_CFLAGS.x86 = -m32 -mno-mmx -mno-sse -mno-avx \
+@@ -6220,7 +6204,7 @@ ifeq ($(KBUILD_TARGET),netbsd)
+ -fno-asynchronous-unwind-tables -mno-fp-ret-in-387
+ TEMPLATE_VBoxR0Drv_CXXFLAGS = -fno-exceptions -fno-rtti \
+ $(VBOX_GCC_WARN) -Wpointer-arith -Winline \
+- -O2 -fno-strict-aliasing -fno-common -finline-limit=8000 \
++ -O2 -fno-strict-aliasing -fno-common \
+ $(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
+ -nostdinc -msoft-float
+ TEMPLATE_VBoxR0Drv_CXXFLAGS.x86 = $(TEMPLATE_VBoxR0Drv_CFLAGS.x86)
+@@ -6528,11 +6512,11 @@ else # the gcc guys
+ TEMPLATE_VBoxR3Exe_LIBS = pthread m rt dl
+ else ifeq ($(KBUILD_TARGET),os2)
+ TEMPLATE_VBoxR3Exe_TOOL = GXX3OMF
+- TEMPLATE_VBoxR3Exe_LIBS = socket iconv
++ TEMPLATE_VBoxR3Exe_LIBS = socket
+ else ifeq ($(KBUILD_TARGET),darwin)
+ TEMPLATE_VBoxR3Exe_TOOL = $(VBOX_GCC_TOOL)
+ TEMPLATE_VBoxR3Exe_LIBS =
+- TEMPLATE_VBoxR3Exe_DEFS += LIBICONV_PLUG # Avoid 3rd party libiconv (from macports).
++ TEMPLATE_VBoxR3Exe_DEFS += LIBICONV_PLUG # Avoid 3rd party lib (from macports).
+ TEMPLATE_VBoxR3Exe_SDKS.darwin = $(VBOX_DARWIN_DEF_SDK_SDKS)
+ TEMPLATE_VBoxR3Exe_DEFS.darwin = $(VBOX_DARWIN_DEF_SDK_DEFS)
+ TEMPLATE_VBoxR3Exe_CFLAGS.darwin = $(VBOX_DARWIN_DEF_SDK_CFLAGS) -fno-common
+@@ -6549,17 +6533,26 @@ else # the gcc guys
+ else ifeq ($(KBUILD_TARGET),haiku)
+ TEMPLATE_VBoxR3Exe_TOOL = GXX3
+ TEMPLATE_VBoxR3Exe_POST_CMDS = $(VBOX_HAIKU_XRES_SETVER_CMDS)
+- TEMPLATE_VBoxR3Exe_LIBS = network iconv stdc++ supc++
++ TEMPLATE_VBoxR3Exe_LIBS = network stdc++ supc++
+ TEMPLATE_VBoxR3Exe_LIBPATH += \
+ /boot/common/lib
+ # Haiku uses PIC by default...
+ TEMPLATE_VBoxR3Exe_CFLAGS += -fno-pic
+ TEMPLATE_VBoxR3Exe_CXXFLAGS += -fno-pic
+ TEMPLATE_VBoxR3Exe_LDFLAGS += -fno-pic
+- else if1of ($(KBUILD_TARGET), freebsd openbsd)
++ else ifeq ($(KBUILD_TARGET), freebsd)
+ TEMPLATE_VBoxR3Exe_TOOL = GXX3
+ TEMPLATE_VBoxR3Exe_LIBS = pthread
++ TEMPLATE_VBoxR3Exe_LDFLAGS = -Wl,-z,noexecstack,-z,relro $(VBOX_LD_as_needed)
++ TEMPLATE_VBoxR3Exe_LDFLAGS.freebsd.x86 = -Wl,-z,notext
+ TEMPLATE_VBoxR3Exe_INCS += \
++ /usr/local/include
++ TEMPLATE_VBoxR3Exe_LIBPATH += \
++ /usr/local/lib
++ else ifeq ($(KBUILD_TARGET), openbsd)
++ TEMPLATE_VBoxR3Exe_TOOL = GXX3
++ TEMPLATE_VBoxR3Exe_LIBS = pthread
++ TEMPLATE_VBoxR3Exe_INCS += \
+ /usr/include \
+ /usr/X11R6/include \
+ /usr/local/include
+@@ -6578,7 +6571,7 @@ else # the gcc guys
+ /usr/X11R7/lib
+ else ifeq ($(KBUILD_TARGET),solaris)
+ TEMPLATE_VBoxR3Exe_TOOL = GXX3PLAIN
+- TEMPLATE_VBoxR3Exe_DEFS += LIBICONV_PLUG _REENTRANT # Avoid the GNU libiconv, for now at least.
++ TEMPLATE_VBoxR3Exe_DEFS += LIBICONV_PLUG _REENTRANT # Avoid the GNU lib, for now at least.
+ if $(VBOX_GCC_VERSION_CC) < 30500
+ TEMPLATE_VBoxR3Exe_CFLAGS += -std=gnu99
+ endif
+@@ -6594,6 +6587,7 @@ else # the gcc guys
+ TEMPLATE_VBoxR3Exe_LDFLAGS += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)'
+ endif
+ ifdef VBOX_WITH_ORIGIN
++ TEMPLATE_VBoxR3Exe_LDFLAGS.freebsd += $(VBOX_GCC_ORIGIN_OPT)
+ TEMPLATE_VBoxR3Exe_LDFLAGS.linux += $(VBOX_GCC_ORIGIN_OPT)
+ endif
+ endif
+@@ -6808,7 +6802,7 @@ else
+ ifdef VBOX_WITH_NOCRT_STATIC
+ TEMPLATE_VBoxR3StaticBase_DEFS += RT_WITH_NOCRT_WRAPPERS
+ endif
+- ifn1of ($(KBUILD_TARGET), darwin linux solaris)
++ ifn1of ($(KBUILD_TARGET), darwin freebsd linux solaris)
+ # The gcc guys sans darwin, linux and solaris (don't depend on statically compiled system libs there)
+ TEMPLATE_VBoxR3StaticBase_CFLAGS = $(TEMPLATE_VBoxR3Exe_CFLAGS) -static
+ TEMPLATE_VBoxR3StaticBase_CXXFLAGS = $(TEMPLATE_VBoxR3Exe_CXXFLAGS) -static
+@@ -6876,7 +6870,7 @@ else
+ $(SDK_VBoxZlib_LIBS) \
+ $(SDK_VBoxLibLzma_LIBS)
+ if1of ($(KBUILD_TARGET), darwin freebsd)
+- TEMPLATE_VBoxR3Static_LIBS += iconv
++ TEMPLATE_VBoxR3Static_LIBS +=
+ else ifeq ($(KBUILD_TARGET),solaris)
+ TEMPLATE_VBoxR3Static_LIBS += kstat
+ endif
+@@ -7048,6 +7042,7 @@ else ifn1of ($(KBUILD_TARGET), os2)
+ else ifn1of ($(KBUILD_TARGET), os2)
+ ifneq ($(KBUILD_TYPE),asan) # Keep RPATH in asan builds so we can find libasan.so.X and libubsan.so.Y.
+ TEMPLATE_VBoxR3HardenedExe_LDFLAGS = $(filter-out '$(VBOX_GCC_RPATH_OPT)%,$(TEMPLATE_VBoxR3Exe_LDFLAGS))
++ TEMPLATE_VBoxR3HardenedExe_LDFLAGS.freebsd = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBoxR3Exe_LDFLAGS.freebsd))
+ TEMPLATE_VBoxR3HardenedExe_LDFLAGS.linux = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBoxR3Exe_LDFLAGS.linux))
+ endif
+ endif
+@@ -7079,6 +7074,7 @@ ifn1of ($(KBUILD_TARGET), win os2)
+ $(if-expr !defined(VBOX_WITHOUT_WINDOWS_KERNEL_CODE_SIGNING_CERT),-IntegrityCheck,)
+ ifn1of ($(KBUILD_TARGET), win os2)
+ TEMPLATE_VBoxR3HardenedTstDll_LDFLAGS = $(filter-out '$(VBOX_GCC_RPATH_OPT)%,$(TEMPLATE_VBoxR3TstDll_LDFLAGS))
++ TEMPLATE_VBoxR3HardenedTstDll_LDFLAGS.freebsd = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBoxR3TstDll_LDFLAGS.freebsd))
+ TEMPLATE_VBoxR3HardenedTstDll_LDFLAGS.linux = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBoxR3TstDll_LDFLAGS.linux))
+ endif
+
+@@ -7102,6 +7098,7 @@ ifndef VBOX_WITH_HARDENING
+ TEMPLATE_VBoxR3SetUidToRoot_LDFLAGS += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)'
+ endif
+ ifdef VBOX_WITH_ORIGIN
++ TEMPLATE_VBoxR3SetUidToRoot_LDFLAGS.freebsd += $(VBOX_GCC_ORIGIN_OPT)
+ TEMPLATE_VBoxR3SetUidToRoot_LDFLAGS.linux += $(VBOX_GCC_ORIGIN_OPT)
+ endif
+ endif
+@@ -7454,7 +7451,7 @@ else # the GCC guys:
+ endif
+ TEMPLATE_VBoxMainExe_CXXFLAGS = -g $(VBOX_GCC_pipe) \
+ $(VBOX_GCC_PEDANTIC_CXX) $(VBOX_GCC_Wno-variadic-macros) $(VBOX_GCC_Wno-multistatement-macros) $(VBOX_GCC_Wno-class-memaccess) -Wshadow \
+- -fshort-wchar -fpermissive -fexceptions -frtti $(VBOX_GCC_OPT) $(VBOX_GCC_FP) -fno-strict-aliasing \
++ -fshort-wchar -fexceptions -frtti $(VBOX_GCC_OPT) $(VBOX_GCC_FP) -fno-strict-aliasing \
+ $(VBOX_GCC_fvisibility-inlines-hidden) $(VBOX_GCC_fvisibility-hidden) $(VBOX_GCC_std) $(VBOX_GCC_IPRT_FMT_CHECK) \
+ $(VBOX_GCC_SANITIZER_FLAGS)
+ if !defined("VBOX_GCC_Wno-delete-non-virtual-dtor") && defined("VBOX_GCC_Wno-non-virtual-dtor")
+@@ -7518,10 +7515,19 @@ else # the GCC guys:
+ else ifeq ($(KBUILD_TARGET),haiku)
+ TEMPLATE_VBoxMainExe_TOOL = GXX3
+ TEMPLATE_VBoxMainExe_LIBS = $(LIB_RUNTIME) network stdc++ supc++
+- else if1of ($(KBUILD_TARGET), freebsd openbsd)
++ else ifeq ($(KBUILD_TARGET), freebsd)
+ TEMPLATE_VBoxMainExe_TOOL = GXX3
+ TEMPLATE_VBoxMainExe_LIBS = $(LIB_RUNTIME)
++ TEMPLATE_VBoxMainExe_LDFLAGS = -Wl,-z,noexecstack,-z,relro $(VBOX_LD_as_needed)
++ TEMPLATE_VBoxMainExe_LDFLAGS.freebsd.x86 = -Wl,-z,notext
+ TEMPLATE_VBoxMainExe_INCS += \
++ /usr/local/include
++ TEMPLATE_VBoxMainExe_LIBPATH += \
++ /usr/local/lib
++ else ifeq ($(KBUILD_TARGET), openbsd)
++ TEMPLATE_VBoxMainExe_TOOL = GXX3
++ TEMPLATE_VBoxMainExe_LIBS = $(LIB_RUNTIME)
++ TEMPLATE_VBoxMainExe_INCS += \
+ /usr/include \
+ /usr/X11R6/include \
+ /usr/local/include
+@@ -7553,6 +7559,7 @@ else # the GCC guys:
+ TEMPLATE_VBoxMainExe_LDFLAGS += '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)'
+ endif
+ ifdef VBOX_WITH_ORIGIN
++ TEMPLATE_VBoxMainExe_LDFLAGS.freebsd += $(VBOX_GCC_ORIGIN_OPT)
+ TEMPLATE_VBoxMainExe_LDFLAGS.linux += $(VBOX_GCC_ORIGIN_OPT)
+ endif
+
+@@ -8181,14 +8188,13 @@ ifdef VBOX_WITH_QTGUI
+ TEMPLATE_VBoxQtGuiExe_LIBPATH += \
+ $(VBOX_LIBPATH_X11)
+ ifeq ($(KBUILD_TARGET),freebsd)
++ TEMPLATE_VBoxQtGuiExe_LDFLAGS += -Wl,-z,noexecstack,-z,relro $(VBOX_LD_as_needed)
++ TEMPLATE_VBoxQtGuiExe_LDFLAGS.freebsd.x86 = -Wl,-z,notext
+ TEMPLATE_VBoxQtGuiExe_INCS += \
+- /usr/include \
+- /usr/X11R6/include \
+ /usr/local/include
+ TEMPLATE_VBoxQtGuiExe_LIBPATH += \
+- /usr/lib \
+- /usr/X11R6/lib \
+ /usr/local/lib
++ TEMPLATE_VBoxQtGuiExe_LIBS += /usr/local/lib/qt6/libQt6PrintSupport.so
+ endif
+ ifeq ($(KBUILD_TARGET),solaris)
+ TEMPLATE_VBoxQtGuiExe_LDFLAGS.solaris = -Wl,-z,ignore # Same as VBOX_LD_as_needed.
+@@ -8460,7 +8466,7 @@ else
+ TEMPLATE_VBoxBldProg_LIBS = pthread m rt dl
+ else ifeq ($(KBUILD_HOST),os2)
+ TEMPLATE_VBoxBldProg_TOOL = GXX3OMF
+- TEMPLATE_VBoxBldProg_LIBS = socket iconv
++ TEMPLATE_VBoxBldProg_LIBS = socket
+ else ifeq ($(KBUILD_HOST),darwin)
+ TEMPLATE_VBoxBldProg_TOOL = $(VBOX_GCC_TOOL)
+ if "$(VBOX_DEF_MACOSX_VERSION_MIN)" == "10.7" || "$(VBOX_DARWIN_HOST_VERSION_MAJOR)" == "7"
+@@ -8500,13 +8506,20 @@ else
+ TEMPLATE_VBoxBldProg_LIBS =
+ else ifeq ($(KBUILD_HOST),haiku)
+ TEMPLATE_VBoxBldProg_TOOL = GXX3
+- TEMPLATE_VBoxBldProg_LIBS = network iconv
++ TEMPLATE_VBoxBldProg_LIBS = network
+ TEMPLATE_VBoxBldProg_LIBPATH += \
+ /boot/common/lib
+- else if1of ($(KBUILD_HOST), freebsd openbsd)
++ else ifeq ($(KBUILD_HOST), freebsd)
+ TEMPLATE_VBoxBldProg_TOOL = $(VBOX_GCC_TOOL)
+ TEMPLATE_VBoxBldProg_LIBS = pthread
+ TEMPLATE_VBoxBldProg_INCS += \
++ /usr/local/include
++ TEMPLATE_VBoxBldProg_LIBPATH += \
++ /usr/local/lib
++ else ifeq ($(KBUILD_HOST), openbsd)
++ TEMPLATE_VBoxBldProg_TOOL = $(VBOX_GCC_TOOL)
++ TEMPLATE_VBoxBldProg_LIBS = pthread
++ TEMPLATE_VBoxBldProg_INCS += \
+ /usr/include \
+ /usr/X11R6/include \
+ /usr/local/include
+@@ -8553,11 +8566,11 @@ TEMPLATE_VBoxAdvBldProg_LIBS.darwin = \
+ $(TEMPLATE_VBoxBldProg_LIBS)
+ TEMPLATE_VBoxAdvBldProg_LIBS.darwin = \
+ $(TEMPLATE_VBoxAdvBldProg_LIBS) \
+- iconv \
++ \
+ $(TEMPLATE_VBoxBldProg_LIBS.darwin)
+ TEMPLATE_VBoxAdvBldProg_LIBS.freebsd = \
+ $(TEMPLATE_VBoxAdvBldProg_LIBS) \
+- iconv \
++ \
+ rt \
+ $(TEMPLATE_VBoxBldProg_LIBS.freebsd)
+ TEMPLATE_VBoxAdvBldProg_LIBS.linux = \
+@@ -8648,6 +8661,7 @@ else # the gcc guys
+ # Do not inherit sanitizer flags from VBoxR3Exe in guest executables. Deal with them separately.
+ TEMPLATE_VBoxGuestR3ExeBase_CXXFLAGS.debug = $(NO_SUCH_VARIABLE)
+ TEMPLATE_VBoxGuestR3ExeBase_CFLAGS.debug = $(NO_SUCH_VARIABLE)
++ TEMPLATE_VBoxGuestR3ExeBase_LDFLAGS.freebsd = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_$(TEMPLATE_VBoxGuestR3ExeBase_EXTENDS)_LDFLAGS.freebsd))
+ TEMPLATE_VBoxGuestR3ExeBase_LDFLAGS.linux = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_$(TEMPLATE_VBoxGuestR3ExeBase_EXTENDS)_LDFLAGS.linux))
+ TEMPLATE_VBoxGuestR3ExeBase_LDFLAGS.debug = $(NO_SUCH_VARIABLE)
+ TEMPLATE_VBoxGuestR3ExeBase_LDFLAGS = $(filter-out '$(VBOX_GCC_RPATH_OPT)%,$(TEMPLATE_$(TEMPLATE_VBoxGuestR3ExeBase_EXTENDS)_LDFLAGS))
+@@ -8671,7 +8685,7 @@ else if1of ($(KBUILD_TARGET), darwin freebsd openbsd)
+ ifeq ($(KBUILD_TARGET),linux) # As few libs as possible on linux.
+ TEMPLATE_VBoxGuestR3ExeBase_LIBS = pthread rt m dl
+ else if1of ($(KBUILD_TARGET), darwin freebsd openbsd)
+- TEMPLATE_VBoxGuestR3ExeBase_LIBS = $(TEMPLATE_$(TEMPLATE_VBoxGuestR3ExeBase_EXTENDS)_LIBS) iconv
++ TEMPLATE_VBoxGuestR3ExeBase_LIBS = $(TEMPLATE_$(TEMPLATE_VBoxGuestR3ExeBase_EXTENDS)_LIBS)
+ else ifeq ($(KBUILD_TARGET),solaris)
+ TEMPLATE_VBoxGuestR3ExeBase_LIBS = $(TEMPLATE_$(TEMPLATE_VBoxGuestR3ExeBase_EXTENDS)_LIBS) nsl
+ endif
+@@ -8684,6 +8698,7 @@ TEMPLATE_VBoxGuestR3ExeBase_CFLAGS.linux = $(TEMP
+ $(VBOX_GCC_fno-stack-protector)
+ TEMPLATE_VBoxGuestR3ExeBase_CFLAGS.linux = $(TEMPLATE_VBoxGuestR3ExeBase_CXXFLAGS.linux)
+ # The GNU_HASH ELF tag is not supported by older systems.
++TEMPLATE_VBoxGuestR3ExeBase_LDFLAGS.freebsd += $(VBOX_LD_hash_style_sysv)
+ TEMPLATE_VBoxGuestR3ExeBase_LDFLAGS.linux += $(VBOX_LD_hash_style_sysv)
+
+
+@@ -8929,6 +8944,7 @@ TEMPLATE_VBoxGuestR3XFree86Mod_LDFLAGS.$(KBUILD_TARGET
+ TEMPLATE_VBoxGuestR3XFree86Mod_CXXFLAGS.linux = $(VBOX_GCC_fno-stack-protector) # Remove symvers.h
+ TEMPLATE_VBoxGuestR3XFree86Mod_LDFLAGS.$(KBUILD_TARGET) = $(NO_SUCH_VARIABLE)
+ # The GNU_HASH ELF tag is not supported by older glibc dynamic linkers.
++TEMPLATE_VBoxGuestR3XFree86Mod_LDFLAGS.freebsd = $(subst -Wl$(COMMA),,$(VBOX_LD_hash_style_sysv))
+ TEMPLATE_VBoxGuestR3XFree86Mod_LDFLAGS.linux = $(subst -Wl$(COMMA),,$(VBOX_LD_hash_style_sysv))
+ TEMPLATE_VBoxGuestR3XFree86Mod_LDFLAGS.$(KBUILD_TYPE) = $(NO_SUCH_VARIABLE)
+ TEMPLATE_VBoxGuestR3XFree86Mod_LDFLAGS := -r
+@@ -8970,7 +8986,7 @@ TEMPLATE_VBoxGuestR3XOrgMod_LIBS.$(KBUILD_TARGET) =
+ TEMPLATE_VBoxGuestR3XOrgMod_LIBS = $(VBOX_LIB_VBGL_R3_XORG)
+ TEMPLATE_VBoxGuestR3XOrgMod_LIBS.$(KBUILD_TYPE) = $(NO_SUCH_VARIABLE)
+ TEMPLATE_VBoxGuestR3XOrgMod_LIBS.$(KBUILD_TARGET) = $(NO_SUCH_VARIABLE)
+-TEMPLATE_VBoxGuestR3XOrgMod_LIBS.freebsd += iconv
++TEMPLATE_VBoxGuestR3XOrgMod_LIBS.freebsd +=
+
+
+ #
diff --git a/emulators/virtualbox-ose-71/files/patch-configure b/emulators/virtualbox-ose-71/files/patch-configure
new file mode 100644
index 000000000000..3645d1236ea8
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-configure
@@ -0,0 +1,138 @@
+--- configure.orig 2025-04-14 17:41:37 UTC
++++ configure
+@@ -158,10 +158,14 @@ if [ "$OS" = "freebsd" ]; then
+ if [ "$OS" = "freebsd" ]; then
+ INCCURL="-I/usr/local/include"
+ LIBCURL="-L/usr/local/lib -lcurl"
++ INCALSA="-I/usr/local/include"
++ LIBALSA="-L/usr/local/lib"
+ INCPULSE="-I/usr/local/include"
+ LIBPULSE="-L/usr/local/lib"
+ INCPNG="-I/usr/local/include"
+ LIBPNG="-L/usr/local/lib -lpng"
++ INCVNCSERVER="-I/usr/local/include"
++ LIBVNCSERVER="-L/usr/local/lib"
+ else
+ INCCURL=""
+ LIBCURL="-lcurl"
+@@ -1211,6 +1215,9 @@ extern "C" int main(int argc, char** argv)
+ printf("found version %d.%d.%d",
+ SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
+ #if SDL_VERSION_ATLEAST(1,2,7)
++#if !defined(SDL_VIDEO_DRIVER_X11)
++#error SDL must be compiled with X11 support
++#endif
+ printf(", OK.\n");
+ return 0;
+ #else
+@@ -1295,7 +1302,7 @@ EOF
+ #endif
+ }
+ EOF
+- if test_compile "-lasound" asound asound; then
++ if test_compile "$INCALSA $LIBALSA -lasound" asound asound; then
+ test_execute
+ fi
+ }
+@@ -1599,6 +1606,7 @@ EOF
+ SDKQT6=$PATH_SDK_QT6
+ fi
+ FLGQT6="-framework QtCore -std=c++17 -Wl,-rpath,`L_to_PATH "$LIBQT6"`"
++ FLGQT6="$FLGQT6 -std=c++11"
+ else
+ log_failure "Qt6 framework not found (can be disabled using --disable-qt)"
+ fail
+@@ -1875,9 +1883,9 @@ check_libvorbis()
+ if which_wrapper pkg-config > /dev/null; then
+ libvorbis_ver=`pkg-config vorbis --modversion 2>> $LOG`
+ if [ $? -eq 0 ]; then
+- FLGVRB=`pkg-config vorbis --cflags`
++ FLGVRB=`pkg-config vorbis vorbisenc --cflags`
+ INCVRB=`strip_I "$FLGVRB"`
+- LIBVRB=`pkg-config vorbis --libs`
++ LIBVRB=`pkg-config vorbis vorbisenc --libs`
+ fi
+ cat > $ODIR.tmp_src.cc << EOF
+ #include <cstdio>
+@@ -1927,7 +1935,7 @@ EOF
+ return 0;
+ }
+ EOF
+- [ -n "$INCOGG" ] && I_INCVRB=`prefix_I "$INCOGG"`
++ [ -n "$INCOGG" ] && I_INCOGG=`prefix_I "$INCOGG"`
+ if test_compile "$LIBOGG $I_INCOGG" ogg ogg nofatal; then
+ if test_execute; then
+ cnf_append "SDK_VBoxLibOgg_INCS" "$INCOGG"
+@@ -2194,8 +2202,8 @@ EOF
+ echo "compiling the following source file:" >> $LOG
+ cat $ODIR.tmp_src.cc >> $LOG
+ echo "using the following command line:" >> $LOG
+- echo "$CXX -O -Wall -o $ODIR.tmp_out $ODIR.tmp_src.cc -I$p/include/$d $p/$b/lib$d.so" >> $LOG
+- $CXX -O -Wall -o $ODIR.tmp_out $ODIR.tmp_src.cc -I$p/include/$d $p/$b/lib$d.so >> $LOG 2>&1
++ echo "$CXX -O -Wall -o $ODIR.tmp_out $ODIR.tmp_src.cc -I$p/include/$d $p/$b/lib$d.so -pthread" >> $LOG
++ $CXX -O -Wall -o $ODIR.tmp_out $ODIR.tmp_src.cc -I$p/include/$d $p/$b/lib$d.so -pthread >> $LOG 2>&1
+ if [ $? -eq 0 ]; then
+ found=1
+ break
+@@ -2311,7 +2319,7 @@ check_gsoap()
+ else
+ cnf_append "VBOX_GSOAP_CXX_SOURCES" ""
+ fi
+- cnf_append "VBOX_GSOAP_CXX_LIBS" "`strip_l "$GSOAP_CXX_LIBS"`"
++ cnf_append "VBOX_GSOAP_CXX_LIBS" "`strip_l "$GSOAP_CXX_LIBS"` z"
+ gsoap_version=`pkg-config gsoapssl++ --modversion`
+ log_success "found version $gsoap_version"
+ return
+@@ -2687,7 +2695,7 @@ for option in "$@"; do
+ --with-openssl-dir=*)
+ OPENSSLDIR=`echo $option | cut -d'=' -f2`
+ INCCRYPTO="-I${OPENSSLDIR}/include"
+- LIBCRYPTO="${OPENSSLDIR}/lib/libssl.a ${OPENSSLDIR}/lib/libcrypto.a"
++ LIBCRYPTO="-L${OPENSSLDIR}/lib -lssl -lcrypto"
+ # On Darwin (at least for macports) static OpenSSL also needs zlib.
+ [ "$OS" = "darwin" ] && LIBCRYPTO="$LIBCRYPTO ${OPENSSLDIR}/lib/libz.a"
+ # On Linux static OpenSSL typically needs a few additional libraries.
+@@ -3054,12 +3062,22 @@ if [ $ONLY_ADDITIONS -eq 0 ]; then
+ [ $WITH_JAVA -eq 1 ] && check_java
+
+ # PulseAudio
+- if [ $WITH_PULSE -eq 1 ]; then
+- check_pulse
+- elif [ $WITH_PULSE -eq 0 ]; then # Force disabling PulseAudio.
+- cnf_append "VBOX_WITH_AUDIO_PULSE" ""
+- elif [ $WITH_PULSE -eq 2 ]; then # --enable-pulse was passed, force PulseAudio.
+- cnf_append "VBOX_WITH_AUDIO_PULSE" "1"
++ if [ "$OS" = "linux" -o "$OS" = "freebsd" -o "$OS" = "netbsd" ]; then
++ if [ $WITH_ALSA -eq 1 ]; then
++ check_alsa
++ else
++ cnf_append "VBOX_WITH_AUDIO_ALSA" ""
++ fi
++ if [ $WITH_PULSE -eq 1 ]; then
++ check_pulse
++ elif [ $WITH_PULSE -eq 0 ]; then # Force disabling PulseAudio.
++ cnf_append "VBOX_WITH_AUDIO_PULSE" ""
++ elif [ $WITH_PULSE -eq 2 ]; then # --enable-pulse was passed, force PulseAudio.
++ cnf_append "VBOX_WITH_AUDIO_PULSE" "1"
++ fi
++ if [ $WITH_DBUS -eq 0 ]; then
++ cnf_append "VBOX_WITH_DBUS" ""
++ fi
+ fi
+ fi
+
+@@ -3075,14 +3093,6 @@ if [ "$OS" = "linux" ]; then
+ cnf_append "VBOX_WITHOUT_LINUX_TEST_BUILDS" "1"
+ fi
+ if [ $ONLY_ADDITIONS -eq 0 ]; then
+- if [ $WITH_ALSA -eq 1 ]; then
+- check_alsa
+- else
+- cnf_append "VBOX_WITH_AUDIO_ALSA" ""
+- fi
+- if [ $WITH_DBUS -eq 0 ]; then
+- cnf_append "VBOX_WITH_DBUS" ""
+- fi
+ if [ $WITH_DEVMAPPER -eq 1 ]; then
+ check_libdevmapper
+ else
diff --git a/emulators/virtualbox-ose-71/files/patch-doc_manual_en__US_dita_UserManual.ditamap b/emulators/virtualbox-ose-71/files/patch-doc_manual_en__US_dita_UserManual.ditamap
new file mode 100644
index 000000000000..93550ddbf766
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-doc_manual_en__US_dita_UserManual.ditamap
@@ -0,0 +1,11 @@
+--- doc/manual/en_US/dita/UserManual.ditamap.orig 2025-04-14 17:41:38 UTC
++++ doc/manual/en_US/dita/UserManual.ditamap
+@@ -613,7 +613,7 @@
+ <topicref href="topics/security-model.dita"/>
+ <topicref href="topics/secure-config-vms.dita">
+ <topicref href="topics/security-networking.dita"/>
+- <topicref href="topics/security-of-remote-vms.dita"/>
++<!-- <topicref href="topics/security-of-remote-vms.dita"/> -->
+ <topicref href="topics/security-vrdp-auth.dita"/>
+ <topicref href="topics/security_clipboard.dita"/>
+ <topicref href="topics/security-shared-folders.dita"/>
diff --git a/emulators/virtualbox-ose-71/files/patch-include-iprt-x86.h b/emulators/virtualbox-ose-71/files/patch-include-iprt-x86.h
new file mode 100644
index 000000000000..ca73a306df88
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-include-iprt-x86.h
@@ -0,0 +1,19 @@
+--- include/iprt/x86.h.orig 2021-04-20 04:22:23 UTC
++++ include/iprt/x86.h
+@@ -38,6 +38,16 @@
+ # pragma D depends_on library vbox-types.d
+ #endif
+
++/* Workaround for FreeBSD machine/specialreg.h defining MSRs */
++#ifdef RT_OS_FREEBSD
++# undef MSR_P5_MC_ADDR
++# undef MSR_P5_MC_TYPE
++# undef MSR_IA32_PLATFORM_ID
++# undef MSR_BBL_CR_CTL3
++# undef MSR_IA32_MISC_ENABLE
++# undef MSR_IA32_FEATURE_CONTROL
++#endif
++
+ /** Workaround for Solaris sys/regset.h defining CS, DS and sys/controlregs.h
+ * defining MSR_IA32_FLUSH_CMD */
+ #ifdef RT_OS_SOLARIS
diff --git a/emulators/virtualbox-ose-71/files/patch-include_VBox_com_array.h b/emulators/virtualbox-ose-71/files/patch-include_VBox_com_array.h
new file mode 100644
index 000000000000..9d65058e6b50
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-include_VBox_com_array.h
@@ -0,0 +1,36 @@
+--- include/VBox/com/array.h.orig 2021-01-07 15:31:25 UTC
++++ include/VBox/com/array.h
+@@ -171,7 +171,7 @@
+
+ #include "VBox/com/defs.h"
+
+-#if RT_GNUC_PREREQ(4, 6) || (defined(_MSC_VER) && (_MSC_VER >= 1600))
++#if RT_GNUC_PREREQ(4, 6) || (defined(_MSC_VER) && (_MSC_VER >= 1600)) || defined(_LIBCPP_VERSION)
+ /** @def VBOX_WITH_TYPE_TRAITS
+ * Type traits are a C++ 11 feature, so not available everywhere (yet).
+ * Only GCC 4.6 or newer and MSVC++ 16.0 (Visual Studio 2010) or newer.
+@@ -960,12 +960,12 @@ class SafeArray : public Traits (public)
+ {
+ /** @todo r=klaus should do this as a AssertCompile, but cannot find a way which works. */
+ Assert(sizeof(T) <= sizeof(Zeroes));
+- AssertReturn(m.arr != NULL, *(T *)&Zeroes[0]);
+- AssertReturn(aIdx < size(), *(T *)&Zeroes[0]);
++ AssertReturn(m.arr != NULL, *((T *)1));
++ AssertReturn(aIdx < size(), *((T *)1));
+ #ifdef VBOX_WITH_XPCOM
+ return m.arr[aIdx];
+ #else
+- AssertReturn(m.raw != NULL, *(T *)&Zeroes[0]);
++ AssertReturn(m.raw != NULL, *((T *)1));
+ return m.raw[aIdx];
+ #endif
+ }
+@@ -980,7 +980,7 @@ class SafeArray : public Traits (public)
+ #ifdef VBOX_WITH_XPCOM
+ return m.arr[aIdx];
+ #else
+- AssertReturn(m.raw != NULL, *(const T *)&Zeroes[0]);
++ AssertReturn(m.raw != NULL, *((T *)1));
+ return m.raw[aIdx];
+ #endif
+ }
diff --git a/emulators/virtualbox-ose-71/files/patch-include_VBox_sup.h b/emulators/virtualbox-ose-71/files/patch-include_VBox_sup.h
new file mode 100644
index 000000000000..9cf3fabe63f1
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-include_VBox_sup.h
@@ -0,0 +1,11 @@
+--- include/VBox/sup.h.orig 2024-12-27 04:08:45.986426000 +0100
++++ include/VBox/sup.h 2024-12-27 04:09:08.925387000 +0100
+@@ -2248,7 +2248,7 @@
+
+ SUPR0DECL(void) SUPR0BadContext(PSUPDRVSESSION pSession, const char *pszFile, uint32_t uLine, const char *pszExpr);
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
+ /**
+ * Translates a physical address to a virtual mapping (valid up to end of page).
+ * @returns VBox status code.
diff --git a/emulators/virtualbox-ose-71/files/patch-include_iprt_string.h b/emulators/virtualbox-ose-71/files/patch-include_iprt_string.h
new file mode 100644
index 000000000000..95119057d1ca
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-include_iprt_string.h
@@ -0,0 +1,14 @@
+--- include/iprt/string.h.orig 2021-01-07 15:31:33 UTC
++++ include/iprt/string.h
+@@ -46,6 +46,11 @@
+ #elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
+ RT_C_DECLS_BEGIN
+ # include <sys/libkern.h>
++ /*
++ * Kludge for the FreeBSD kernel:
++ * sys/libkern.h includes sys/param.h via sys/systm.h since r335879.
++ */
++# undef PVM
+ RT_C_DECLS_END
+
+ #elif defined(RT_OS_NETBSD) && defined(_KERNEL)
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-VBoxGuest-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-VBoxGuest-freebsd.c
new file mode 100644
index 000000000000..e790f372f95f
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-VBoxGuest-freebsd.c
@@ -0,0 +1,284 @@
+--- src/VBox/Additions/common/VBoxGuest/VBoxGuest-freebsd.c.orig 2022-10-06 19:03:06.000000000 +0200
++++ src/VBox/Additions/common/VBoxGuest/VBoxGuest-freebsd.c 2024-12-26 15:28:38.066230000 +0100
+@@ -55,6 +55,7 @@
+ #include <sys/uio.h>
+ #include <sys/bus.h>
+ #include <sys/poll.h>
++#include <sys/proc.h>
+ #include <sys/selinfo.h>
+ #include <sys/queue.h>
+ #include <sys/lock.h>
+@@ -71,6 +72,7 @@
+ #include <VBox/version.h>
+ #include <VBox/log.h>
+ #include <iprt/assert.h>
++#include <iprt/err.h>
+ #include <iprt/initterm.h>
+ #include <iprt/process.h>
+ #include <iprt/string.h>
+@@ -112,8 +114,6 @@
+ struct resource *pIrqRes;
+ /** Pointer to the IRQ handler. */
+ void *pfnIrqHandler;
+- /** VMMDev version */
+- uint32_t u32Version;
+ };
+
+
+@@ -123,8 +123,7 @@
+ /*
+ * Character device file handlers.
+ */
+-static d_fdopen_t vgdrvFreeBSDOpen;
+-static d_close_t vgdrvFreeBSDClose;
++static d_open_t vgdrvFreeBSDOpen;
+ static d_ioctl_t vgdrvFreeBSDIOCtl;
+ static int vgdrvFreeBSDIOCtlSlow(PVBOXGUESTSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd);
+ static d_write_t vgdrvFreeBSDWrite;
+@@ -155,8 +154,7 @@
+ {
+ .d_version = D_VERSION,
+ .d_flags = D_TRACKCLOSE | D_NEEDMINOR,
+- .d_fdopen = vgdrvFreeBSDOpen,
+- .d_close = vgdrvFreeBSDClose,
++ .d_open = vgdrvFreeBSDOpen,
+ .d_ioctl = vgdrvFreeBSDIOCtl,
+ .d_read = vgdrvFreeBSDRead,
+ .d_write = vgdrvFreeBSDWrite,
+@@ -164,81 +162,28 @@
+ .d_name = "vboxguest"
+ };
+
++/** Device structure. */
++static struct cdev *g_pDev;
++
+ /** Device extention & session data association structure. */
+ static VBOXGUESTDEVEXT g_DevExt;
+
+-/** List of cloned device. Managed by the kernel. */
+-static struct clonedevs *g_pvgdrvFreeBSDClones;
+-/** The dev_clone event handler tag. */
+-static eventhandler_tag g_vgdrvFreeBSDEHTag;
+ /** Reference counter */
+ static volatile uint32_t cUsers;
+ /** selinfo structure used for polling. */
+ static struct selinfo g_SelInfo;
+
+-/**
+- * DEVFS event handler.
+- */
+-static void vgdrvFreeBSDClone(void *pvArg, struct ucred *pCred, char *pszName, int cchName, struct cdev **ppDev)
++static void vgdrvFreeBSDDtr(void *pSession)
+ {
+- int iUnit;
+- int rc;
+-
+- Log(("vgdrvFreeBSDClone: pszName=%s ppDev=%p\n", pszName, ppDev));
+-
+- /*
+- * One device node per user, si_drv1 points to the session.
+- * /dev/vboxguest<N> where N = {0...255}.
+- */
+- if (!ppDev)
+- return;
+- if (strcmp(pszName, "vboxguest") == 0)
+- iUnit = -1;
+- else if (dev_stdclone(pszName, NULL, "vboxguest", &iUnit) != 1)
+- return;
+- if (iUnit >= 256)
+- {
+- Log(("vgdrvFreeBSDClone: iUnit=%d >= 256 - rejected\n", iUnit));
+- return;
+- }
+-
+- Log(("vgdrvFreeBSDClone: pszName=%s iUnit=%d\n", pszName, iUnit));
+-
+- rc = clone_create(&g_pvgdrvFreeBSDClones, &g_vgdrvFreeBSDChrDevSW, &iUnit, ppDev, 0);
+- Log(("vgdrvFreeBSDClone: clone_create -> %d; iUnit=%d\n", rc, iUnit));
+- if (rc)
+- {
+- *ppDev = make_dev(&g_vgdrvFreeBSDChrDevSW,
+- iUnit,
+- UID_ROOT,
+- GID_WHEEL,
+- 0664,
+- "vboxguest%d", iUnit);
+- if (*ppDev)
+- {
+- dev_ref(*ppDev);
+- (*ppDev)->si_flags |= SI_CHEAPCLONE;
+- Log(("vgdrvFreeBSDClone: Created *ppDev=%p iUnit=%d si_drv1=%p si_drv2=%p\n",
+- *ppDev, iUnit, (*ppDev)->si_drv1, (*ppDev)->si_drv2));
+- (*ppDev)->si_drv1 = (*ppDev)->si_drv2 = NULL;
+- }
+- else
+- Log(("vgdrvFreeBSDClone: make_dev iUnit=%d failed\n", iUnit));
+- }
+- else
+- Log(("vgdrvFreeBSDClone: Existing *ppDev=%p iUnit=%d si_drv1=%p si_drv2=%p\n",
+- *ppDev, iUnit, (*ppDev)->si_drv1, (*ppDev)->si_drv2));
++ VGDrvCommonCloseSession(&g_DevExt, pSession);
++ ASMAtomicDecU32(&cUsers);
+ }
+
+ /**
+ * File open handler
+ *
+ */
+-#if __FreeBSD_version >= 700000
+-static int vgdrvFreeBSDOpen(struct cdev *pDev, int fOpen, struct thread *pTd, struct file *pFd)
+-#else
+-static int vgdrvFreeBSDOpen(struct cdev *pDev, int fOpen, struct thread *pTd)
+-#endif
++static int vgdrvFreeBSDOpen(struct cdev *pDev, int fOpen, int DevType, struct thread *pTd)
+ {
+ int rc;
+ PVBOXGUESTSESSION pSession;
+@@ -250,12 +195,6 @@
+ LogFlow(("vgdrvFreeBSDOpen:\n"));
+
+ /*
+- * Try grab it (we don't grab the giant, remember).
+- */
+- if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, (void *)0x42, NULL))
+- return EBUSY;
+-
+- /*
+ * Create a new session.
+ */
+ fRequestor = VMMDEV_REQUESTOR_USERMODE | VMMDEV_REQUESTOR_TRUST_NOT_GIVEN;
+@@ -272,47 +211,20 @@
+ rc = VGDrvCommonCreateUserSession(&g_DevExt, fRequestor, &pSession);
+ if (RT_SUCCESS(rc))
+ {
+- if (ASMAtomicCmpXchgPtr(&pDev->si_drv1, pSession, (void *)0x42))
+- {
+- Log(("vgdrvFreeBSDOpen: success - g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, (int)RTProcSelf()));
++ Log(("vgdrvFreeBSDOpen: success - g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, (int)RTProcSelf()));
++ rc = devfs_set_cdevpriv(pSession, vgdrvFreeBSDDtr);
++ if (rc)
++ VGDrvCommonCloseSession(&g_DevExt, pSession);
++ else
+ ASMAtomicIncU32(&cUsers);
+- return 0;
+- }
+-
+- VGDrvCommonCloseSession(&g_DevExt, pSession);
++ return rc;
+ }
+
+ LogRel(("vgdrvFreeBSDOpen: failed. rc=%d\n", rc));
+ return RTErrConvertToErrno(rc);
+ }
+
+-/**
+- * File close handler
+- *
+- */
+-static int vgdrvFreeBSDClose(struct cdev *pDev, int fFile, int DevType, struct thread *pTd)
+-{
+- PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pDev->si_drv1;
+- Log(("vgdrvFreeBSDClose: fFile=%#x pSession=%p\n", fFile, pSession));
+
+- /*
+- * Close the session if it's still hanging on to the device...
+- */
+- if (RT_VALID_PTR(pSession))
+- {
+- VGDrvCommonCloseSession(&g_DevExt, pSession);
+- if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, NULL, pSession))
+- Log(("vgdrvFreeBSDClose: si_drv1=%p expected %p!\n", pDev->si_drv1, pSession));
+- ASMAtomicDecU32(&cUsers);
+- /* Don't use destroy_dev here because it may sleep resulting in a hanging user process. */
+- destroy_dev_sched(pDev);
+- }
+- else
+- Log(("vgdrvFreeBSDClose: si_drv1=%p!\n", pSession));
+- return 0;
+-}
+-
+-
+ /**
+ * I/O control request.
+ *
+@@ -326,8 +238,12 @@
+ static int vgdrvFreeBSDIOCtl(struct cdev *pDev, u_long ulCmd, caddr_t pvData, int fFile, struct thread *pTd)
+ {
+ PVBOXGUESTSESSION pSession;
+- devfs_get_cdevpriv((void **)&pSession);
++ int rc;
+
++ rc = devfs_get_cdevpriv((void **)&pSession);
++ if (rc)
++ return rc;
++
+ /*
+ * Deal with the fast ioctl path first.
+ */
+@@ -526,8 +442,10 @@
+
+ LogFlow(("vgdrvFreeBSDPoll: fEvents=%d\n", fEvents));
+
+- PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pDev->si_drv1;
+- if (RT_UNLIKELY(!RT_VALID_PTR(pSession))) {
++
++ rc = devfs_get_cdevpriv((void **)&pSession);
++ if (rc)
++ {
+ Log(("vgdrvFreeBSDPoll: no state data for %s\n", devtoname(pDev)));
+ return (fEvents & (POLLHUP|POLLIN|POLLRDNORM|POLLOUT|POLLWRNORM));
+ }
+@@ -568,11 +486,8 @@
+ /*
+ * Reverse what we did in vgdrvFreeBSDAttach.
+ */
+- if (g_vgdrvFreeBSDEHTag != NULL)
+- EVENTHANDLER_DEREGISTER(dev_clone, g_vgdrvFreeBSDEHTag);
++ destroy_dev(g_pDev);
+
+- clone_cleanup(&g_pvgdrvFreeBSDClones);
+-
+ vgdrvFreeBSDRemoveIRQ(pDevice, pState);
+
+ if (pState->pVMMDevMemRes)
+@@ -737,18 +652,21 @@
+ VGDrvCommonProcessOptionsFromHost(&g_DevExt);
+
+ /*
+- * Configure device cloning.
++ * Configure device.
+ */
+- clone_setup(&g_pvgdrvFreeBSDClones);
+- g_vgdrvFreeBSDEHTag = EVENTHANDLER_REGISTER(dev_clone, vgdrvFreeBSDClone, 0, 1000);
+- if (g_vgdrvFreeBSDEHTag)
++ g_pDev = make_dev(&g_vgdrvFreeBSDChrDevSW,
++ 0,
++ UID_ROOT,
++ GID_WHEEL,
++ 0664,
++ "vboxguest");
++ if (g_pDev)
+ {
+ printf(DEVICE_NAME ": loaded successfully\n");
+ return 0;
+ }
+
+- printf(DEVICE_NAME ": EVENTHANDLER_REGISTER(dev_clone,,,) failed\n");
+- clone_cleanup(&g_pvgdrvFreeBSDClones);
++ printf(DEVICE_NAME ": make_dev failed\n");
+ vgdrvFreeBSDRemoveIRQ(pDevice, pState);
+ }
+ else
+@@ -792,8 +710,12 @@
+ sizeof(struct VBoxGuestDeviceState),
+ };
+
++#if __FreeBSD_version >= 1400058
++DRIVER_MODULE(vboxguest, pci, vgdrvFreeBSDDriver, 0, 0);
++#else
+ static devclass_t vgdrvFreeBSDClass;
+
+ DRIVER_MODULE(vboxguest, pci, vgdrvFreeBSDDriver, vgdrvFreeBSDClass, 0, 0);
++#endif
+ MODULE_VERSION(vboxguest, 1);
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-freebsd-Makefile b/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-freebsd-Makefile
new file mode 100644
index 000000000000..476346a59b13
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-freebsd-Makefile
@@ -0,0 +1,27 @@
+--- src/VBox/Additions/common/VBoxGuest/freebsd/Makefile.orig 2019-04-16 10:09:09 UTC
++++ src/VBox/Additions/common/VBoxGuest/freebsd/Makefile
+@@ -25,7 +25,7 @@
+ #
+ KMOD = vboxguest
+
+-CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -Iinclude -I. -Ir0drv -w -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM -DVBOX_WITH_64_BITS_GUESTS
++CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DIN_RT_R0 -DIN_GUEST -DIN_GUEST_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -Iinclude -I. -Ir0drv -w -DVBGL_VBOXGUEST -DVBOX_WITH_HGCM -DVBOX_WITH_64_BITS_GUESTS
+
+ .if (${MACHINE_ARCH} == "i386")
+ CFLAGS += -DRT_ARCH_X86
+@@ -80,6 +80,7 @@ SRCS += \
+ handletable.c \
+ handletablectx.c \
+ once.c \
++ term.c \
+ thread.c
+
+ .PATH: ${.CURDIR}/common/string
+@@ -147,6 +148,7 @@ SRCS += \
+
+ .PATH: ${.CURDIR}/r0drv
+ SRCS += \
++ alloc-ef-r0drv.c \
+ alloc-r0drv.c \
+ initterm-r0drv.c \
+ memobj-r0drv.c \
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-freebsd-files_vboxguest b/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-freebsd-files_vboxguest
new file mode 100644
index 000000000000..faecf870532b
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-common-VBoxGuest-freebsd-files_vboxguest
@@ -0,0 +1,34 @@
+--- src/VBox/Additions/common/VBoxGuest/freebsd/files_vboxguest.orig 2019-01-25 18:12:28 UTC
++++ src/VBox/Additions/common/VBoxGuest/freebsd/files_vboxguest
+@@ -63,6 +63,7 @@ FILES_VBOXGUEST_NOBIN=" \
+ ${PATH_ROOT}/include/iprt/time.h=>include/iprt/time.h \
+ ${PATH_ROOT}/include/iprt/timer.h=>include/iprt/timer.h \
+ ${PATH_ROOT}/include/iprt/types.h=>include/iprt/types.h \
++ ${PATH_ROOT}/include/iprt/uni.h=>include/iprt/uni.h \
+ ${PATH_ROOT}/include/iprt/utf16.h=>include/iprt/utf16.h \
+ ${PATH_ROOT}/include/iprt/uuid.h=>include/iprt/uuid.h \
+ ${PATH_ROOT}/include/iprt/crc.h=>include/iprt/crc.h \
+@@ -111,6 +112,7 @@ FILES_VBOXGUEST_NOBIN=" \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/handletable.h=>common/misc/handletable.h \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/handletablectx.cpp=>common/misc/handletablectx.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/once.cpp=>common/misc/once.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/term.cpp=>common/misc/term.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/thread.cpp=>common/misc/thread.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg1Weak.cpp=>common/misc/RTAssertMsg1Weak.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2.cpp=>common/misc/RTAssertMsg2.c \
+@@ -181,6 +183,7 @@ FILES_VBOXGUEST_NOBIN=" \
+ ${PATH_ROOT}/src/VBox/Runtime/generic/errvars-generic.cpp=>generic/errvars-generic.c \
+ ${PATH_ROOT}/src/VBox/Runtime/generic/timer-generic.cpp=>generic/timer-generic.c \
+ ${PATH_ROOT}/src/VBox/Runtime/generic/mppresent-generic.cpp=>generic/mppresent-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/alloc-ef-r0drv.cpp=>r0drv/alloc-ef-r0drv.c \
+ ${PATH_ROOT}/src/VBox/Runtime/r0drv/alloc-r0drv.cpp=>r0drv/alloc-r0drv.c \
+ ${PATH_ROOT}/src/VBox/Runtime/r0drv/alloc-r0drv.h=>r0drv/alloc-r0drv.h \
+ ${PATH_ROOT}/src/VBox/Runtime/r0drv/initterm-r0drv.cpp=>r0drv/initterm-r0drv.c \
+@@ -207,6 +210,7 @@ FILES_VBOXGUEST_NOBIN=" \
+ ${PATH_ROOT}/src/VBox/Runtime/r0drv/freebsd/sleepqueue-r0drv-freebsd.h=>r0drv/freebsd/sleepqueue-r0drv-freebsd.h \
+ ${PATH_ROOT}/src/VBox/Runtime/r0drv/generic/semspinmutex-r0drv-generic.c=>r0drv/generic/semspinmutex-r0drv-generic.c \
+ ${PATH_ROOT}/src/VBox/Runtime/r0drv/generic/mpnotification-r0drv-generic.cpp=>r0drv/generic/mpnotification-r0drv-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/generic/threadctxhooks-r0drv-generic.cpp=>r0drv/generic/threadctxhooks-r0drv-generic.c \
+ ${PATH_ROOT}/src/VBox/Runtime/r0drv/generic/RTMpIsCpuWorkPending-r0drv-generic.cpp=>r0drv/generic/RTMpIsCpuWorkPending-r0drv-generic.c \
+ ${PATH_ROOT}/src/VBox/Runtime/r0drv/memobj-r0drv.cpp=>r0drv/memobj-r0drv.c \
+ ${PATH_ROOT}/src/VBox/Runtime/VBox/log-vbox.cpp=>VBox/log-vbox.c \
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-x11-Installer-98vboxadd-xclient b/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-x11-Installer-98vboxadd-xclient
new file mode 100644
index 000000000000..56225943a922
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-x11-Installer-98vboxadd-xclient
@@ -0,0 +1,25 @@
+--- src/VBox/Additions/x11/Installer/98vboxadd-xclient.orig 2025-01-21 19:49:30.000000000 +0700
++++ src/VBox/Additions/x11/Installer/98vboxadd-xclient 2025-01-23 00:43:43.597269000 +0700
+@@ -42,15 +42,15 @@
+ # not use "exit" here as this script is "source"d, not executed.
+
+ # Check wheather X11 or Wayland version of VBoxClient should be started.
+- vbox_wl_check=$(/usr/bin/vboxwl --check 2> /dev/null)
++ vbox_wl_check=$(/usr/local/bin/vboxwl --check 2> /dev/null)
+ if test "$vbox_wl_check" = "WL"; then
+- /usr/bin/VBoxClient --wayland
++ /usr/local/bin/VBoxClient --wayland
+ else
+- /usr/bin/VBoxClient --clipboard
+- /usr/bin/VBoxClient --seamless
+- /usr/bin/VBoxClient --draganddrop
++ /usr/local/bin/VBoxClient --clipboard
++ /usr/local/bin/VBoxClient --seamless
++ /usr/local/bin/VBoxClient --draganddrop
+ fi
+
+- /usr/bin/VBoxClient --checkhostversion
+- /usr/bin/VBoxClient --vmsvga-session # In case VMSVGA emulation is enabled
++ /usr/local/bin/VBoxClient --checkhostversion
++ /usr/local/bin/VBoxClient --vmsvga-session # In case VMSVGA emulation is enabled
+ fi
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-x11-Installer-vboxclient.desktop b/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-x11-Installer-vboxclient.desktop
new file mode 100644
index 000000000000..a76eb7616038
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Additions-x11-Installer-vboxclient.desktop
@@ -0,0 +1,10 @@
+--- src/VBox/Additions/x11/Installer/vboxclient.desktop.orig 2020-05-13 19:37:09 UTC
++++ src/VBox/Additions/x11/Installer/vboxclient.desktop
+@@ -8,6 +8,6 @@ Comment[C]=VirtualBox User Session Services
+ Comment=VirtualBox User Session Services
+ Comment[it]=Servizi di sessione utente di VirtualBox
+ Comment[pl]=Usługi sesji użytkownika VirtualBox
+-Exec=/usr/bin/VBoxClient-all
++Exec=/usr/local/bin/VBoxClient-all
+ X-GNOME-Autostart-enabled=true
+ X-KDE-autostart-after=panel
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Devices-Network-DrvNATlibslirp.cpp b/emulators/virtualbox-ose-71/files/patch-src-VBox-Devices-Network-DrvNATlibslirp.cpp
new file mode 100644
index 000000000000..11ee43504054
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Devices-Network-DrvNATlibslirp.cpp
@@ -0,0 +1,10 @@
+--- src/VBox/Devices/Network/DrvNATlibslirp.cpp.orig 2025-01-25 00:56:57.537046000 +0700
++++ src/VBox/Devices/Network/DrvNATlibslirp.cpp 2025-01-25 00:58:05.112538000 +0700
+@@ -57,6 +57,7 @@
+
+ #ifdef RT_OS_FREEBSD
+ # include <netinet/in.h>
++# include <sys/socket.h>
+ #endif
+
+ #include <iprt/asm.h>
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Devices-Network-slirp-bsd-sys-mbuf.h b/emulators/virtualbox-ose-71/files/patch-src-VBox-Devices-Network-slirp-bsd-sys-mbuf.h
new file mode 100644
index 000000000000..b6ed2d2915db
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Devices-Network-slirp-bsd-sys-mbuf.h
@@ -0,0 +1,12 @@
+--- src/VBox/Devices/Network/slirp/bsd/sys/mbuf.h.orig 2020-05-13 19:42:23 UTC
++++ src/VBox/Devices/Network/slirp/bsd/sys/mbuf.h
+@@ -245,6 +245,9 @@ struct mbuf {
+ #define M_FRAG 0x00000800 /* packet is a fragment of a larger packet */
+ #define M_FIRSTFRAG 0x00001000 /* packet is first fragment */
+ #define M_LASTFRAG 0x00002000 /* packet is last fragment */
++#ifdef M_SKIP_FIREWALL
++#undef M_SKIP_FIREWALL
++#endif
+ #define M_SKIP_FIREWALL 0x00004000 /* skip firewall processing */
+ #define M_FREELIST 0x00008000 /* mbuf is on the free list */
+ #define M_VLANTAG 0x00010000 /* ether_vtag is valid */
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-HostDrivers-VBoxNetAdp-Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src-VBox-HostDrivers-VBoxNetAdp-Makefile.kmk
new file mode 100644
index 000000000000..5b96ab56a61b
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-HostDrivers-VBoxNetAdp-Makefile.kmk
@@ -0,0 +1,20 @@
+--- src/VBox/HostDrivers/VBoxNetAdp/Makefile.kmk.orig 2019-05-13 13:33:07 UTC
++++ src/VBox/HostDrivers/VBoxNetAdp/Makefile.kmk
+@@ -206,10 +206,14 @@ $$(VBoxNetAdp-src_0_OUTDIR)/Makefile: \
+ $$(if $$(eq $$(VBoxNetAdp/freebsd/Makefile_VBOX_HARDENED),$$(VBOX_WITH_HARDENING)),,FORCE) \
+ | $$(dir $$@)
+ $(QUIET)$(RM) -f -- $@
+- ifndef VBOX_WITH_HARDENING
+- $(QUIET)$(SED) -e "s;VBOX_WITH_HARDENING;;g" --output $@ $<
+- else
+ $(QUIET)$(CP) -f $< $@
++ ifndef VBOX_WITH_HARDENING
++ $(QUIET)$(SED) -e "s;-DVBOX_WITH_HARDENING;;g" --output $@.tmp $@
++ $(QUIET)$(MV) -f $@.tmp $@
++ endif
++ ifndef VBOX_WITH_NETFLT_VIMAGE
++ $(QUIET)$(SED) -e "s;-DVIMAGE;;g" --output $@.tmp $@
++ $(QUIET)$(MV) -f $@.tmp $@
+ endif
+
+ endif # freebsd
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-HostDrivers-VBoxNetFlt-freebsd-files_vboxnetflt b/emulators/virtualbox-ose-71/files/patch-src-VBox-HostDrivers-VBoxNetFlt-freebsd-files_vboxnetflt
new file mode 100644
index 000000000000..dc4e779fb6b0
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-HostDrivers-VBoxNetFlt-freebsd-files_vboxnetflt
@@ -0,0 +1,10 @@
+--- src/VBox/HostDrivers/VBoxNetFlt/freebsd/files_vboxnetflt.orig 2022-10-06 19:11:15.000000000 +0200
++++ src/VBox/HostDrivers/VBoxNetFlt/freebsd/files_vboxnetflt 2024-12-26 15:41:50.870345000 +0100
+@@ -72,6 +72,7 @@
+ ${PATH_ROOT}/include/iprt/uni.h=>include/iprt/uni.h \
+ ${PATH_ROOT}/include/iprt/utf16.h=>include/iprt/utf16.h \
+ ${PATH_ROOT}/include/iprt/uuid.h=>include/iprt/uuid.h \
++ ${PATH_ROOT}/include/iprt/x86.h=>include/iprt/x86.h \
+ ${PATH_ROOT}/include/iprt/x86-helpers.h=>include/iprt/x86-helpers.h \
+ ${PATH_ROOT}/include/iprt/nocrt/limits.h=>include/iprt/nocrt/limits.h \
+ ${PATH_ROOT}/include/VBox/cdefs.h=>include/VBox/cdefs.h \
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Installer-Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src-VBox-Installer-Makefile.kmk
new file mode 100644
index 000000000000..45546433c627
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Installer-Makefile.kmk
@@ -0,0 +1,14 @@
+--- src/VBox/Installer/Makefile.kmk.orig 2020-05-13 19:44:01 UTC
++++ src/VBox/Installer/Makefile.kmk
+@@ -41,9 +41,11 @@ ifndef VBOX_ONLY_SDK
+ if "$(KBUILD_TARGET)" == "win" && "$(KBUILD_HOST)" == "win"
+ include $(PATH_SUB_CURRENT)/win/Makefile.kmk
+ endif
++if 0
+ if "$(KBUILD_TARGET)" == "freebsd" && "$(KBUILD_HOST)" == "freebsd"
+ include $(PATH_SUB_CURRENT)/freebsd/Makefile.kmk
+ endif
++endif
+ endif
+
+ include $(PATH_SUB_CURRENT)/common/Makefile.kmk
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Installer-freebsd-VBox.sh b/emulators/virtualbox-ose-71/files/patch-src-VBox-Installer-freebsd-VBox.sh
new file mode 100644
index 000000000000..b4c177a54d1c
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Installer-freebsd-VBox.sh
@@ -0,0 +1,77 @@
+--- src/VBox/Installer/freebsd/VBox.sh.orig 2016-08-27 05:10:34 UTC
++++ src/VBox/Installer/freebsd/VBox.sh
+@@ -0,0 +1,74 @@
++#!/bin/sh
++#
++# Oracle VM VirtualBox startup script, FreeBSD hosts.
++#
++# Copyright (C) 2006-2012 Oracle Corporation
++#
++# This file is part of VirtualBox Open Source Edition (OSE), as
++# available from http://www.virtualbox.org. This file is free software;
++# you can redistribute it and/or modify it under the terms of the GNU
++# General Public License (GPL) as published by the Free Software
++# Foundation, in version 2 as it comes in the "COPYING" file of the
++# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
++# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
++#
++
++PATH="/sbin:/bin:/usr/sbin:/usr/bin:%%LOCALBASE%%/sbin:%%LOCALBASE%%/bin"
++CONFIG="%%VBOX_ETC%%/vbox.cfg"
++
++test -r "${CONFIG}" &&
++ . "${CONFIG}"
++test -z "${INSTALL_DIR}" &&
++ if test -d %%VBOX_DIR%% &&
++ test -f %%VBOX_DIR%%/VBoxRT.so; then
++ INSTALL_DIR=%%VBOX_DIR%%
++ else
++ >&2 echo "Could not find VirtualBox installation. Please reinstall."
++ exit 1
++ fi
++
++if [ -d /etc/vbox ]; then
++ >&2 cat <<-EOH
++ WARNING: Directory /etc/vbox found, but ignored. VirtualBox
++ configuration files are stored in %%VBOX_ETC%%/.
++ EOH
++fi
++
++# workaround for the KDE dialog problem
++KDE_FORK_SLAVES=1; export KDE_FORK_SLAVES
++
++APP=`basename $0`
++case "$APP" in
++ VirtualBox|virtualbox)
++ exec "$INSTALL_DIR/VirtualBox" "$@"
++ ;;
++ VirtualBoxVM|virtualboxvm)
++ exec "$INSTALL_DIR/VirtualBoxVM" "$@"
++ ;;
++ VBoxManage|vboxmanage)
++ exec "$INSTALL_DIR/VBoxManage" "$@"
++ ;;
++ VBoxSDL|vboxsdl)
++ exec "$INSTALL_DIR/VBoxSDL" "$@"
++ ;;
++ VBoxVRDP|VBoxHeadless|vboxheadless)
++ exec "$INSTALL_DIR/VBoxHeadless" "$@"
++ ;;
++ VBoxAutostart|vboxautostart)
++ exec "$INSTALL_DIR/VBoxAutostart" "$@"
++ ;;
++ VBoxBalloonCtrl|vboxballoonctrl)
++ exec "$INSTALL_DIR/VBoxBalloonCtrl" "$@"
++ ;;
++ VBoxBugReport|vboxbugreport)
++ exec "$INSTALL_DIR/VBoxBugReport" "$@"
++ ;;
++ vboxwebsrv)
++ exec "$INSTALL_DIR/vboxwebsrv" "$@"
++ ;;
++ *)
++ >&2 echo "Unknown application - $APP"
++ exit 1
++ ;;
++esac
++exit 0
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Main-src-server-VirtualBoxImpl.cpp b/emulators/virtualbox-ose-71/files/patch-src-VBox-Main-src-server-VirtualBoxImpl.cpp
new file mode 100644
index 000000000000..4cd8b7492ed9
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Main-src-server-VirtualBoxImpl.cpp
@@ -0,0 +1,11 @@
+--- src/VBox/Main/src-server/VirtualBoxImpl.cpp.orig 2021-01-07 15:41:43 UTC
++++ src/VBox/Main/src-server/VirtualBoxImpl.cpp
+@@ -2663,7 +2663,7 @@ int VirtualBox::i_encryptSettingBytes(const uint8_t *a
+ if (aCiphertextSize < 32)
+ return VERR_INVALID_PARAMETER;
+
+- AssertCompile(sizeof(m->SettingsCipherKey) >= 32);
++ // AssertCompile(sizeof(m->SettingsCipherKey) >= 32);
+
+ /* store the first 8 bytes of the cipherkey for verification */
+ for (i = 0, j = 0; i < 8; i++, j++)
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Runtime-Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src-VBox-Runtime-Makefile.kmk
new file mode 100644
index 000000000000..f13be222ea9a
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Runtime-Makefile.kmk
@@ -0,0 +1,14 @@
+--- src/VBox/Runtime/Makefile.kmk.orig 2021-01-07 15:41:50 UTC
++++ src/VBox/Runtime/Makefile.kmk
+@@ -177,6 +177,11 @@ $(IPRT_OUT_DIR)/oiddb.h.ts +| $(IPRT_OUT_DIR)/oiddb.h:
+
+
+ #
++# Set the defines that utf8-posix.cpp needs. It's used by several targets.
++#
++r3/posix/utf8-posix.cpp_DEFS.freebsd = $(VBOX_ICONV_DEFS)
++
++#
+ # Unicode Specification reader used to regenerate unidata-*.cpp.
+ #
+ uniread_TEMPLATE = VBoxBldProg
diff --git a/emulators/virtualbox-ose-71/files/patch-src-VBox-Runtime-r0drv-freebsd-sleepqueue-r0drv-freebsd.h b/emulators/virtualbox-ose-71/files/patch-src-VBox-Runtime-r0drv-freebsd-sleepqueue-r0drv-freebsd.h
new file mode 100644
index 000000000000..c18492ebdf9b
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src-VBox-Runtime-r0drv-freebsd-sleepqueue-r0drv-freebsd.h
@@ -0,0 +1,39 @@
+Without the first part of this patch, any waits for periods shorter than a
+single tick return immediately leading to a lot of unnecessary spinning. For
+example, I observe that my guest's idle loop does a lot of sleeps with periods
+slightly shorter than 1 ms (1/hz), e.g. 900us. All that waiting turns into pure
+spinning and VirtualBox eats 100% of a core.
+
+The clamping improves the situation significantly. Also, it (approximately)
+follows what tvtohz does. The rest of the patch just chases an upstream
+KPI change.
+
+Submitted by: Andriy Gapon <avg@FreeBSD.org>
+--- src/VBox/Runtime/r0drv/freebsd/sleepqueue-r0drv-freebsd.h.orig 2024-07-29 13:10:32 UTC
++++ src/VBox/Runtime/r0drv/freebsd/sleepqueue-r0drv-freebsd.h
+@@ -84,6 +84,8 @@ DECLINLINE(uint32_t) rtR0SemBsdWaitUpdateTimeout(PRTR0
+ uint64_t cTicks = ASMMultU64ByU32DivByU32(uTimeout, hz, UINT32_C(1000000000));
+ if (cTicks >= INT_MAX)
+ return RTSEMWAIT_FLAGS_INDEFINITE;
++ else if (cTicks == 0 && uTimeout > 0)
++ pWait->iTimeout = 1;
+ else
+ pWait->iTimeout = (int)cTicks;
+ #endif
+@@ -300,10 +302,16 @@ DECLINLINE(void) rtR0SemBsdSignal(void *pvWaitChan)
+ DECLINLINE(void) rtR0SemBsdSignal(void *pvWaitChan)
+ {
+ sleepq_lock(pvWaitChan);
++#if __FreeBSD_version < 1500022
+ int fWakeupSwapProc = sleepq_signal(pvWaitChan, SLEEPQ_CONDVAR, 0, 0);
++#else
++ sleepq_signal(pvWaitChan, SLEEPQ_CONDVAR, 0, 0);
++#endif
+ sleepq_release(pvWaitChan);
++#if __FreeBSD_version < 1500022
+ if (fWakeupSwapProc)
+ kick_proc0();
++#endif
+ }
+
+ /**
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_common_VBoxService_VBoxServiceVMInfo.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_common_VBoxService_VBoxServiceVMInfo.cpp
new file mode 100644
index 000000000000..70b459e94da7
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_common_VBoxService_VBoxServiceVMInfo.cpp
@@ -0,0 +1,71 @@
+--- src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp.orig 2021-01-07 15:34:20 UTC
++++ src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
+@@ -67,8 +67,8 @@
+ # include <net/if.h>
+ # include <pwd.h> /* getpwuid */
+ # include <unistd.h>
+-# if !defined(RT_OS_OS2) && !defined(RT_OS_FREEBSD) && !defined(RT_OS_HAIKU)
+-# include <utmpx.h> /** @todo FreeBSD 9 should have this. */
++# if !defined(RT_OS_OS2) && !defined(RT_OS_HAIKU)
++# include <utmpx.h>
+ # endif
+ # ifdef RT_OS_OS2
+ # include <net/if_dl.h>
+@@ -528,7 +528,7 @@ static void vgsvcVMInfoWriteFixedProperties(void)
+ }
+
+
+-#if defined(VBOX_WITH_DBUS) && defined(RT_OS_LINUX) /* Not yet for Solaris/FreeBSB. */
++#if defined(VBOX_WITH_DBUS) && (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) /* Not yet for Solaris. */
+ /*
+ * Simple wrapper to work around compiler-specific va_list madness.
+ */
+@@ -555,12 +555,6 @@ static int vgsvcVMInfoWriteUsers(void)
+ #ifdef RT_OS_WINDOWS
+ rc = VGSvcVMInfoWinWriteUsers(&g_VMInfoPropCache, &pszUserList, &cUsersInList);
+
+-#elif defined(RT_OS_FREEBSD)
+- /** @todo FreeBSD: Port logged on user info retrieval.
+- * However, FreeBSD 9 supports utmpx, so we could use the code
+- * block below (?). */
+- rc = VERR_NOT_IMPLEMENTED;
+-
+ #elif defined(RT_OS_HAIKU)
+ /** @todo Haiku: Port logged on user info retrieval. */
+ rc = VERR_NOT_IMPLEMENTED;
+@@ -586,7 +580,7 @@ static int vgsvcVMInfoWriteUsers(void)
+ while ( (ut_user = getutxent())
+ && RT_SUCCESS(rc))
+ {
+-# ifdef RT_OS_DARWIN /* No ut_user->ut_session on Darwin */
++# if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) /* No ut_user->ut_session on Darwin/FreeBSD */
+ VGSvcVerbose(4, "Found entry '%s' (type: %d, PID: %RU32)\n", ut_user->ut_user, ut_user->ut_type, ut_user->ut_pid);
+ # else
+ VGSvcVerbose(4, "Found entry '%s' (type: %d, PID: %RU32, session: %RU32)\n",
+@@ -621,7 +615,7 @@ static int vgsvcVMInfoWriteUsers(void)
+ }
+
+ # ifdef VBOX_WITH_DBUS
+-# if defined(RT_OS_LINUX) /* Not yet for Solaris/FreeBSB. */
++# if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) /* Not yet for Solaris. */
+ DBusError dbErr;
+ DBusConnection *pConnection = NULL;
+ int rc2 = RTDBusLoadLib();
+@@ -830,7 +824,7 @@ static int vgsvcVMInfoWriteUsers(void)
+ if ( fHaveLibDbus
+ && dbus_error_is_set(&dbErr))
+ dbus_error_free(&dbErr);
+-# endif /* RT_OS_LINUX */
++# endif /* RT_OS_LINUX || RT_OS_FREEBSD */
+ # endif /* VBOX_WITH_DBUS */
+
+ /** @todo Fedora/others: Handle systemd-loginctl. */
+@@ -867,7 +861,7 @@ static int vgsvcVMInfoWriteUsers(void)
+ RTMemFree(papszUsers);
+
+ endutxent(); /* Close utmpx file. */
+-#endif /* !RT_OS_WINDOWS && !RT_OS_FREEBSD && !RT_OS_HAIKU && !RT_OS_OS2 */
++#endif /* !RT_OS_WINDOWS && !RT_OS_HAIKU && !RT_OS_OS2 */
+
+ Assert(RT_FAILURE(rc) || cUsersInList == 0 || (pszUserList && *pszUserList));
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_common_pam_pam__vbox.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_common_pam_pam__vbox.cpp
new file mode 100644
index 000000000000..bd667880358f
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_common_pam_pam__vbox.cpp
@@ -0,0 +1,20 @@
+--- src/VBox/Additions/common/pam/pam_vbox.cpp.orig 2021-01-07 15:34:21 UTC
++++ src/VBox/Additions/common/pam/pam_vbox.cpp
+@@ -104,7 +104,7 @@ static void pam_vbox_writesyslog(char *pszBuf)
+ openlog("pam_vbox", LOG_PID, LOG_AUTHPRIV);
+ syslog(LOG_ERR, "%s", pszBuf);
+ closelog();
+-#elif defined(RT_OS_SOLARIS)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
+ syslog(LOG_ERR, "pam_vbox: %s\n", pszBuf);
+ #endif
+ }
+@@ -183,7 +183,7 @@ static int vbox_set_msg(pam_handle_t *hPAM, int iStyle
+
+ pam_message msg;
+ msg.msg_style = iStyle;
+-#ifdef RT_OS_SOLARIS
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
+ msg.msg = (char*)pszText;
+ #else
+ msg.msg = pszText;
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_Makefile b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_Makefile
new file mode 100644
index 000000000000..c38d8013a6d6
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_Makefile
@@ -0,0 +1,38 @@
+--- src/VBox/Additions/freebsd/Makefile.orig 2020-05-13 19:37:06 UTC
++++ src/VBox/Additions/freebsd/Makefile
+@@ -30,6 +30,14 @@ all:
+ cp vboxvfs/vboxvfs.ko .; \
+ fi; \
+ fi
++ @echo
++ @if [ -d mount_vboxvfs ]; then \
++ echo "=== Building mount_vboxvfs binary ==="; \
++ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C mount_vboxvfs clean obj depend all; \
++ if [ -f mount_vboxvfs ]; then \
++ cp mount_vboxvfs/mount_vboxvfs .; \
++ fi; \
++ fi
+
+
+ install:
+@@ -37,13 +45,19 @@ install:
+ @if [ -d vboxvfs ]; then \
+ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxvfs install; \
+ fi
++ @if [ -d mount_vboxvfs ]; then \
++ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C mount_vboxvfs install; \
++ fi
+
+ clean:
+ @$(MAKE) -C vboxguest clean
+ @if [ -d vboxvfs ]; then \
+ $(MAKE) -C vboxvfs clean; \
+ fi
+- rm -f vboxguest.*o vboxvfs.*o
++ @if [ -d mount_vboxvfs ]; then \
++ $(MAKE) -C mount_vboxvfs clean; \
++ fi
++ rm -f vboxguest.*o vboxvfs.*o mount_vboxvfs
+
+ load:
+ @/sbin/kldunload vboxvfs || true
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_Makefile.kmk
new file mode 100644
index 000000000000..f9d19d679e4a
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_Makefile.kmk
@@ -0,0 +1,31 @@
+--- src/VBox/Additions/freebsd/Makefile.kmk.orig 2021-01-07 15:34:22 UTC
++++ src/VBox/Additions/freebsd/Makefile.kmk
+@@ -23,8 +23,9 @@ $(error "The FreeBSD guest additions installer can onl
+ endif
+
+ # Include sub-makefiles.
+-#include $(PATH_SUB_CURRENT)/vboxvfs/Makefile.kmk
+-include $(PATH_SUB_CURRENT)/drm/Makefile.kmk
++include $(PATH_SUB_CURRENT)/vboxvfs/Makefile.kmk
++#include $(PATH_SUB_CURRENT)/drm/Makefile.kmk
++include $(PATH_SUB_CURRENT)/mount_vboxvfs/Makefile.kmk
+
+ #
+ # Globals
+@@ -66,11 +67,14 @@ VBOX_FBSD_ADD_STRIP_BIN = \
+ vboxvideo_drv_14.so \
+ vboxvideo_drv_15.so \
+ vboxvideo_drv_16.so \
+- vboxvideo_drv_17.so
++ vboxvideo_drv_17.so \
++ $(if $(VBOX_WITH_PAM),pam_vbox.so,) \
++ VBoxOGL.so \
++ mount_vboxvfs
+
+ VBOX_FBSD_ADD_MODULES = \
+ vboxguest \
+- vboxvideo_drm
++ vboxvfs
+
+ #
+ # All the bin files that go into the archives.
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_drm_vboxvideo__drm.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_drm_vboxvideo__drm.c
new file mode 100644
index 000000000000..d4e5f3fc5a33
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_drm_vboxvideo__drm.c
@@ -0,0 +1,17 @@
+--- src/VBox/Additions/freebsd/drm/vboxvideo_drm.c.orig 2022-07-26 18:05:21 UTC
++++ src/VBox/Additions/freebsd/drm/vboxvideo_drm.c
+@@ -154,10 +154,14 @@ static driver_t vboxvideo_driver = {
+ sizeof(struct drm_device)
+ };
+
++#if __FreeBSD_version >= 1400058
++DRIVER_MODULE(vboxvideo, vgapci, vboxvideo_driver, 0, 0);
++#else
+ extern devclass_t drm_devclass;
+ #if __FreeBSD_version >= 700010
+ DRIVER_MODULE(vboxvideo, vgapci, vboxvideo_driver, drm_devclass, 0, 0);
+ #else
+ DRIVER_MODULE(vboxvideo, pci, vboxvideo_driver, drm_devclass, 0, 0);
++#endif
+ #endif
+ MODULE_DEPEND(vboxvideo, drm, 1, 1, 1);
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_Makefile.kmk
new file mode 100644
index 000000000000..270472c045e3
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_Makefile.kmk
@@ -0,0 +1,31 @@
+--- src/VBox/Additions/freebsd/mount_vboxvfs/Makefile.kmk.orig 2025-05-11 03:54:13 UTC
++++ src/VBox/Additions/freebsd/mount_vboxvfs/Makefile.kmk
+@@ -0,0 +1,28 @@
++# $Id: Makefile.kmk $
++## @file
++# Sub-Makefile for the FreeBSD Shared folder mount utility.
++#
++
++SUB_DEPTH = ../../../../..
++include $(KBUILD_PATH)/subheader.kmk
++
++ifneq ($(KBUILD_HOST),freebsd)
++$(error "The FreeBSD guest additions can only be built on FreeBSD!")
++endif
++
++MOUNT= $(VBOX_FREEBSD_SRC)/../sbin/mount
++
++CFLAGS+=-I$(MOUNT)
++
++PROGRAMS += mount_vboxvfs
++mount_vboxvfs_TEMPLATE = NewVBoxGuestR3Exe
++mount_vboxvfs_SOURCES = mount_vboxvfs.c
++
++ifdef HAVE_MNTOPTS_IN_LIBUTIL
++mount_vboxvfs_LIBS = util
++else
++mount_vboxvfs_SOURCES += $(MOUNT)/getmntopts.c
++endif
++
++include $(FILE_KBUILD_SUB_FOOTER)
++
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_mount__vboxvfs.8 b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_mount__vboxvfs.8
new file mode 100644
index 000000000000..88460e155de3
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_mount__vboxvfs.8
@@ -0,0 +1,56 @@
+--- src/VBox/Additions/freebsd/mount_vboxvfs/mount_vboxvfs.8.orig 1970-01-01 01:00:00.000000000 +0100
++++ src/VBox/Additions/freebsd/mount_vboxvfs/mount_vboxvfs.8 2017-07-12 19:24:26.106029000 +0200
+@@ -0,0 +1,53 @@
++.\"
++.\" Copyright (c) 1992, 1993, 1994
++.\" The Regents of the University of California. All rights reserved.
++.\"
++.\" Redistribution and use in source and binary forms, with or without
++.\" modification, are permitted provided that the following conditions
++.\" are met:
++.\" 1. Redistributions of source code must retain the above copyright
++.\" notice, this list of conditions and the following disclaimer.
++.\" 2. Redistributions in binary form must reproduce the above copyright
++.\" notice, this list of conditions and the following disclaimer in the
++.\" documentation and/or other materials provided with the distribution.
++.\" 4. Neither the name of the University nor the names of its contributors
++.\" may be used to endorse or promote products derived from this software
++.\" without specific prior written permission.
++.\"
++.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
++.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
++.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
++.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
++.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
++.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
++.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
++.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
++.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
++.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
++.\" SUCH DAMAGE.
++.\"
++.Dd August 5, 2013
++.Dt MOUNT_VBOXFS 8
++.Os
++.Sh NAME
++.Nm mount_vboxfs
++.Nd "Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT"
++.Sh SYNOPSIS
++.Nm
++.Op Fl o Ar options
++.Ar NAME
++.Ar MOUNTPOINT
++.Sh DESCRIPTION
++The
++.Nm
++Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT
++.Pp
++The options are as follows:
++.Bl -tag -width indent
++.Fl w
++mount the shared folder writably (the default)
++.Fl r
++mount the shared folder read-only
++.Fl o
++OPTION[,OPTION...] use the mount options specified
++.El
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_mount__vboxvfs.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_mount__vboxvfs.c
new file mode 100644
index 000000000000..7dd7e6271e03
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_mount__vboxvfs_mount__vboxvfs.c
@@ -0,0 +1,171 @@
+--- src/VBox/Additions/freebsd/mount_vboxvfs/mount_vboxvfs.c.orig 1970-01-01 01:00:00.000000000 +0100
++++ src/VBox/Additions/freebsd/mount_vboxvfs/mount_vboxvfs.c 2017-07-12 19:24:26.106029000 +0200
+@@ -0,0 +1,168 @@
++/*
++* Copyright (c) 1992, 1993, 1994
++* The Regents of the University of California. All rights reserved.
++*
++* Redistribution and use in source and binary forms, with or without
++* modification, are permitted provided that the following conditions
++* are met:
++* 1. Redistributions of source code must retain the above copyright
++* notice, this list of conditions and the following disclaimer.
++* 2. Redistributions in binary form must reproduce the above copyright
++* notice, this list of conditions and the following disclaimer in the
++* documentation and/or other materials provided with the distribution.
++* 4. Neither the name of the University nor the names of its contributors
++* may be used to endorse or promote products derived from this software
++* without specific prior written permission.
++*
++* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
++* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
++* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
++* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
++* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
++* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
++* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
++* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
++* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
++* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
++* SUCH DAMAGE.
++*/
++
++#include <sys/cdio.h>
++#include <sys/stat.h>
++#include <sys/file.h>
++#include <sys/iconv.h>
++#include <sys/param.h>
++#include <sys/linker.h>
++#include <sys/module.h>
++#include <sys/mount.h>
++#include <sys/uio.h>
++
++#include <err.h>
++#include <errno.h>
++#include <stdlib.h>
++#include <stdio.h>
++#include <string.h>
++#include <sysexits.h>
++#include <unistd.h>
++
++#include "mntopts.h"
++
++#define MAX_HOST_NAME 256
++static char mount_point[MAXPATHLEN + 1];
++static char vboxfs_vfsname[] = "vboxvfs";
++static struct mntopt mopts[] = {
++ MOPT_STDOPTS,
++ MOPT_END
++};
++
++static void usage(void) __dead2;
++
++static void
++usage(void)
++{
++ fprintf(stderr,
++ "Usage: [OPTIONS] NAME MOUNTPOINT\n"
++ "Mount the VirtualBox shared folder NAME to MOUNTPOINT.\n"
++ "\nOptions:\n"
++ " -w mount the shared folder writable \n"
++ " -r mount the shared folder read-only (the default)\n");
++ exit(1);
++}
++
++int
++main(int argc, char *argv[])
++{
++ struct iovec *iov;
++ struct stat st;
++ char *host_name;
++ char errmsg[255];
++ uid_t uid;
++ gid_t gid;
++ mode_t dir_mode, file_mode;
++ int iovlen;
++ int ronly = 0;
++ int error, ch;
++ int mntflags = 0;
++
++ iov = NULL;
++ iovlen = 0;
++ errmsg[0] = '\0';
++ uid = (uid_t)-1;
++ gid = (gid_t)-1;
++ file_mode = 0;
++ dir_mode = 0;
++
++ while ((ch = getopt(argc, argv, "rwo:h")) != -1)
++ switch(ch) {
++ default:
++ fprintf(stderr, "unknown option `%c:%#x'\n", ch, ch);
++ return (1);
++
++ case '?':
++ case 'h':
++ usage();
++ case 'r':
++ ronly = 1;
++ break;
++ case 'w':
++ ronly = 0;
++ break;
++ case 'o':
++ getmntopts(optarg, mopts, &mntflags, 0);
++ break;
++ }
++
++ if (argc - optind < 2)
++ usage();
++
++ host_name = argv[optind];
++ realpath(argv[optind+1], mount_point);
++
++ if (stat(mount_point, &st) == -1)
++ err(EX_OSERR, "could not find mount point %s", mount_point);
++
++ if (!S_ISDIR(st.st_mode)) {
++ errno = ENOTDIR;
++ err(EX_OSERR, "can't mount on %s", mount_point);
++ }
++
++ if (strlen(host_name) > MAX_HOST_NAME - 1)
++ err(EX_OSERR, "host name is too big %s", host_name);
++
++ if (ronly == 0)
++ mntflags |= MNT_ASYNC;
++ if (uid == (uid_t)-1)
++ uid = st.st_uid;
++ if (gid == (gid_t)-1)
++ gid = st.st_gid;
++ if (file_mode == 0)
++ file_mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
++ if (dir_mode == 0) {
++ dir_mode = file_mode;
++ if (dir_mode & S_IRUSR)
++ dir_mode |= S_IXUSR;
++ if (dir_mode & S_IRGRP)
++ dir_mode |= S_IXGRP;
++ if (dir_mode & S_IROTH)
++ dir_mode |= S_IXOTH;
++ }
++
++ build_iovec(&iov, &iovlen, "fstype", vboxfs_vfsname, (size_t)-1);
++ build_iovec(&iov, &iovlen, "fspath", mount_point, (size_t)-1);
++ build_iovec(&iov, &iovlen, "from", host_name, (size_t)-1);
++ build_iovec_argf(&iov, &iovlen, "uid", "%d", uid);
++ build_iovec_argf(&iov, &iovlen, "gid", "%d", gid);
++ build_iovec_argf(&iov, &iovlen, "file_mode", "%o", file_mode);
++ build_iovec_argf(&iov, &iovlen, "dir_mode", "%o", dir_mode);
++ build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg));
++
++ error = nmount(iov, iovlen, mntflags);
++ if (error == -1) {
++ if (errmsg[0] != '\0')
++ err(1, "%s: error: %s", mount_point, errmsg);
++ else
++ err(1, "%s: error %d", mount_point, error);
++ }
++
++ return (0);
++}
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_bcmp.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_bcmp.c
new file mode 100644
index 000000000000..fb4d7fac8c06
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_bcmp.c
@@ -0,0 +1,12 @@
+--- src/VBox/Additions/freebsd/vboxvfs/bcmp.c.orig 2021-02-21 19:09:22 UTC
++++ src/VBox/Additions/freebsd/vboxvfs/bcmp.c
+@@ -0,0 +1,9 @@
++#include <sys/types.h>
++
++int bcmp(const void *b1, const void *b2, size_t len);
++
++int
++bcmp(const void *b1, const void *b2, size_t len)
++{
++ return __builtin_memcmp((b1), (b2), (len));
++}
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs.h b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs.h
new file mode 100644
index 000000000000..858e894c7b6b
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs.h
@@ -0,0 +1,428 @@
+--- src/VBox/Additions/freebsd/vboxvfs/vboxvfs.h.orig 2021-01-07 15:34:22 UTC
++++ src/VBox/Additions/freebsd/vboxvfs/vboxvfs.h
+@@ -1,8 +1,3 @@
+-/* $Id: vboxvfs.h $ */
+-/** @file
+- * Description.
+- */
+-
+ /*
+ * Copyright (C) 2010-2020 Oracle Corporation
+ *
+@@ -24,72 +19,378 @@
+ #define VBOXVFS_VFSNAME "vboxvfs"
+ #define VBOXVFS_VERSION 1
+
+-#define MAX_HOST_NAME 256
+-#define MAX_NLS_NAME 32
++#define MAX_HOST_NAME 256
++#define MAX_NLS_NAME 32
++//#define MODEMASK 07777 /* mode bits plus permission bits */
++/** Helper macros */
++#define VFSTOVBOXFS(mp) ((struct vboxfs_mnt *)((mp)->mnt_data))
++#define VP_TO_VBOXFS_NODE(vp) ((struct vboxfs_node *)(vp)->v_data)
++#define VBOXTOV(np) ((struct vnode *)(np)->n_vnode)
+
+-struct vboxvfs_mount_info {
+- char name[MAX_HOST_NAME];
+- char nls_name[MAX_NLS_NAME];
+- int uid;
+- int gid;
+- int ttl;
+-};
++#define ROOTDIR_INO 1
++#define THEFILE_INO 2
++#define THEFILE_NAME "thefile"
+
++#define VBOXFS_NODE_LOCK(node) mtx_lock(&(node)->sf_interlock)
++#define VBOXFS_NODE_UNLOCK(node) mtx_unlock(&(node)->sf_interlock)
++#define VBOXFS_NODE_MTX(node) (&(node)->sf_interlock)
++#define VBOXFS_NODE_ASSERT_LOCKED(node) mtx_assert(VBOXFS_NODE_MTX(node), \
++ MA_OWNED)
++
++#ifdef INVARIANTS
++#define VBOXFS_ASSERT_LOCKED(node) do { \
++ MPASS(node != NULL); \
++ MPASS(node->sf_vnode != NULL); \
++ if (!VOP_ISLOCKED(node->sf_vnode) && \
++ !mtx_owned(VBOXFS_NODE_MTX(node))) \
++ panic("vboxfs: node is not locked: %p", node); \
++ } while (0)
++#define VBOXFS_ASSERT_ELOCKED(node) do { \
++ MPASS((node) != NULL); \
++ MPASS((node)->sf_vnode != NULL); \
++ mtx_assert(VBOXFS_NODE_MTX(node), MA_OWNED); \
++ ASSERT_VOP_LOCKED((node)->sf_vnode, "vboxfs"); \
++ } while (0)
++#else
++#define VBOXFS_ASSERT_LOCKED(node) (void)0
++#define VBOXFS_ASSERT_ELOCKED(node) (void)0
++#endif
++
++#define VBOXFS_VNODE_ALLOCATING 1
++#define VBOXFS_VNODE_WANT 2
++#define VBOXFS_VNODE_DOOMED 4
++#define VBOXFS_VNODE_WRECLAIM 8
++
++MALLOC_DECLARE(M_VBOXVFS);
++
+ #ifdef _KERNEL
++#ifndef FREEBSD_STYLE
++#include "../../../../../include/iprt/nocrt/limits.h"
++#include "../../../../../include/iprt/alloc.h"
++#include "../../../../../include/iprt/asm.h"
++#include "../../../../../include/iprt/asm-amd64-x86.h"
++#include "../../../../../include/iprt/asm-math.h"
++#include "../../../../../include/iprt/assert.h"
++#include "../../../../../include/iprt/cdefs.h"
++#include "../../../../../include/iprt/err.h"
++#include "../../../../../include/iprt/fs.h"
++#include "../../../../../include/iprt/log.h"
++#include "../../../../../include/iprt/mem.h"
++#include "../../../../../include/iprt/param.h"
++#include "../../../../../include/iprt/path.h"
++#include "../../../../../include/iprt/semaphore.h"
++#include "../../../../../include/iprt/stdarg.h"
++#include "../../../../../include/iprt/stdint.h"
++#include "../../../../../include/iprt/string.h"
++#include "../../../../../include/iprt/time.h"
++#include "../../../../../include/iprt/types.h"
++#include "../../../../../include/iprt/uni.h"
+
+-#include <VBox/VBoxGuestLibSharedFolders.h>
++#else
++
++#include "iprt/nocrt/limits.h"
++#include "iprt/alloc.h"
++#include "iprt/asm.h"
++#include "iprt/asm-amd64-x86.h"
++#include "iprt/asm-math.h"
++#include "iprt/assert.h"
++#include "iprt/cdefs.h"
++#include "iprt/err.h"
++#include "iprt/fs.h"
++#include "iprt/log.h"
++#include "iprt/mem.h"
++#include "iprt/param.h"
++#include "iprt/path.h"
++#include "iprt/semaphore.h"
++#include "iprt/stdarg.h"
++#include "iprt/stdint.h"
++#include "iprt/string.h"
++#include "iprt/time.h"
++#include "iprt/types.h"
++#include "iprt/uni.h"
++
++#include "common/VBoxGuestLib/SysHlp.h"
++
++#endif /* !FREEBSD_STYLE */
++
+ #include <sys/mount.h>
+ #include <sys/vnode.h>
++#include <sys/_timespec.h>
+
+-struct vboxvfsmount {
+- uid_t uid;
+- gid_t gid;
+- mode_t file_mode;
+- mode_t dir_mode;
+- struct mount *mp;
+- struct ucred *owner;
+- u_int flags;
+- long nextino;
+- int caseopt;
+- int didrele;
++#include <VBox/VBoxGuestLibSharedFolders.h>
++
++#if __FreeBSD_version >= 1400093
++typedef __enum_uint8(vtype) enum_vtype_t;
++#else
++typedef enum vtype enum_vtype_t;
++#endif
++
++#define VBOXVFS_DEBUG(lvl, ...) do { \
++ if (vboxvfs_debug >= (lvl)) { \
++ printf("VBOXVFS[%u]: ", lvl); \
++ printf(__VA_ARGS__); \
++ printf("\n"); \
++ } \
++} while (0)
++
++/*
++ * representation of an active mount point
++ */
++struct sfp_mount {
++ VBGLSFMAP map;
+ };
+
+-/* structs - stolen from the linux shared module code */
++/*
++ * Mount / Unmount a shared folder.
++ *
++ * sfprov_mount() takes as input the connection pointer and the name of
++ * the shared folder. On success, it returns zero and supplies an
++ * sfp_mount_t handle. On failure it returns any relevant errno value.
++ *
++ * sfprov_unmount() unmounts the mounted file system. It returns 0 on
++ * success and any relevant errno on failure.
++ */
++typedef struct sfp_mount sfp_mount_t;
++
++struct sfp_file {
++ SHFLHANDLE handle;
++ VBGLSFMAP map; /* need this again for the close operation */
++};
++
++typedef struct sfp_file sfp_file_t;
++
++/*
++ * File operations: open/close/read/write/etc.
++ *
++ * open/create can return any relevant errno, however ENOENT
++ * generally means that the host file didn't exist.
++ */
++typedef struct sffs_stat {
++ mode_t sf_mode;
++ off_t sf_size;
++ off_t sf_alloc;
++ struct timespec sf_atime;
++ struct timespec sf_mtime;
++ struct timespec sf_ctime;
++} sffs_stat_t;
++
++/*
++ * Read directory entries.
++ */
++/*
++ * a singly linked list of buffers, each containing an array of stat's+dirent's.
++ * sf_len is length of the sf_entries array, in bytes.
++ */
++typedef struct sffs_dirents {
++ struct sffs_dirents *sf_next;
++ long long sf_len;
++ struct sffs_dirent {
++ sffs_stat_t sf_stat;
++ struct dirent sf_entry; /* this is variable length */
++ off_t sf_off;
++ } sf_entries[1];
++} sffs_dirents_t;
++
++/*
++ * Shared Folders filesystem per-mount data structure.
++ */
++struct vboxfs_mnt {
++ struct mount *sf_vfsp; /* filesystem's vfs struct */
++ sfp_mount_t *sf_handle; /* guest-host communication handle */
++ uid_t sf_uid; /* owner of all shared folders */
++ gid_t sf_gid; /* group of all shared folders */
++ mode_t sf_dmode; /* mode of all directories */
++ mode_t sf_fmode; /* mode of all files */
++ mode_t sf_dmask; /* mask of all directories */
++ mode_t sf_fmask; /* mask of all files */
++ int sf_stat_ttl; /* ttl for stat caches (in ms) */
++ int sf_fsync; /* whether to honor fsync or not */
++ uint64_t sf_ino; /* per FS ino generator */
++ uma_zone_t sf_node_pool;
++ struct vboxfs_node *sf_root;
++};
++
++/*
++ * vboxfs_node is the file system dependent vnode data for vboxfs.
++ * vboxfs_node's also track all files ever accessed, both open and closed.
++ * It duplicates some of the information in vnode, since it holds
++ * information for files that may have been completely closed.
++ *
++ */
++struct vboxfs_node {
++ struct vboxfs_mnt *vboxfsmp; /* containing mounted file system */
++ char *sf_path; /* full pathname to file or dir */
++ uint64_t sf_ino; /* assigned unique ID number */
++ struct vnode *sf_vnode; /* vnode if active */
++ sfp_file_t *sf_file; /* non NULL if open */
++ struct vboxfs_node *sf_parent; /* parent sfnode of this one */
++ uint32_t sf_opencnt; /* sf_file reference counter */
++ uint16_t sf_children; /* number of children sfnodes */
++ uint8_t sf_type; /* VDIR or VREG */
++ uint8_t sf_vpstate; /* XXX: ADD COMMENT */
++ uint8_t sf_is_stale; /* this is stale and should be purged */
++ sffs_stat_t sf_stat; /* cached file attrs for this node */
++ uint64_t sf_stat_time; /* last-modified time of sf_stat */
++ sffs_dirents_t *sf_dir_list; /* list of entries for this directory */
++
++ /* interlock to protect sf_vpstate, sf_file and sf_opencnt */
++ struct mtx sf_interlock;
++};
++
++struct vboxfs_mount_info {
++ char name[MAX_HOST_NAME]; /* share name */
++ char nls_name[MAX_NLS_NAME];/* name of an I/O charset */
++ int uid; /* user ID for all entries, default 0=root */
++ int gid; /* group ID for all entries, default 0=root */
++ int ttl; /* time to live */
++ int dmode; /* mode for directories if != 0xffffffff */
++ int fmode; /* mode for regular files if != 0xffffffff */
++ int dmask; /* umask applied to directories */
++ int fmask; /* umask applied to regular files */
++};
++
+ struct sf_glob_info {
+- VBGLSFMAP map;
+-/* struct nls_table *nls;*/
+- int ttl;
+- int uid;
+- int gid;
+- struct vnode *vnode_root;
++ VBGLSFMAP map;
++/* struct nls_table *nls;*/
++ int ttl;
++ int uid;
++ int gid;
++ struct vnode *vnode_root;
+ };
+
++/** Per-file system mount instance data. */
++typedef struct vboxfs_globinfo
++{
++ VBGLSFMAP Map;
++ int Ttl;
++ int Uid;
++ int Gid;
++ struct mount *pVFS;
++ struct vboxfs_node *pVNodeRoot;
++} vboxfs_globinfo_t;
++
+ struct sf_inode_info {
+- SHFLSTRING *path;
+- int force_restat;
++ SHFLSTRING *path;
++ int force_restat;
+ };
+
+ #if 0
+ struct sf_dir_info {
+- struct list_head info_list;
++ struct list_head info_list;
+ };
+ #endif
+
+ struct sf_dir_buf {
+- size_t nb_entries;
+- size_t free_bytes;
+- size_t used_bytes;
+- void *buf;
++ size_t nb_entries;
++ size_t free_bytes;
++ size_t used_bytes;
++ void *buf;
+ #if 0
+- struct list_head head;
++ struct list_head head;
+ #endif
+ };
+
+ struct sf_reg_info {
+- SHFLHANDLE handle;
++ SHFLHANDLE handle;
+ };
+
++int vboxfs_alloc_vp(struct mount *, struct vboxfs_node *, int,
++ struct vnode **);
++void vboxfs_free_vp(struct vnode *);
++
++int vboxfs_alloc_node(struct mount *, struct vboxfs_mnt *, const char*,
++ enum_vtype_t, uid_t, gid_t, mode_t, struct vboxfs_node *,
++ struct vboxfs_node **);
++void vboxfs_free_node(struct vboxfs_mnt *, struct vboxfs_node *);
++
++/*
++ * These are the provider interfaces used by sffs to access the underlying
++ * shared file system.
++ */
++#define SFPROV_VERSION 1
++
++/*
++ * Initialization and termination.
++ * sfprov_connect() is called once before any other interfaces and returns
++ * a handle used in further calls. The argument should be SFPROV_VERSION
++ * from above. On failure it returns a NULL pointer.
++ *
++ * sfprov_disconnect() must only be called after all sf file systems have been
++ * unmounted.
++ */
++typedef struct sfp_connection sfp_connection_t;
++
++extern sfp_connection_t *sfprov_connect(int);
++extern void sfprov_disconnect(void);
++
++extern int sfprov_mount(char *, sfp_mount_t **);
++extern int sfprov_unmount(sfp_mount_t *);
++
++/*
++ * query information about a mounted file system
++ */
++typedef struct sffs_fsinfo {
++ uint64_t blksize;
++ uint64_t blksused;
++ uint64_t blksavail;
++ uint32_t maxnamesize;
++ uint32_t readonly;
++ uint32_t serial;
++} sffs_fsinfo_t;
++
++extern int sfprov_get_fsinfo(sfp_mount_t *, sffs_fsinfo_t *);
++
++extern int sfprov_create(sfp_mount_t *, char *path, mode_t mode,
++ sffs_stat_t *stat);
++extern int sfprov_open(sfp_mount_t *, char *path, sfp_file_t **fp);
++extern int sfprov_close(sfp_file_t *fp);
++extern int sfprov_read(sfp_file_t *, char * buffer, uint64_t offset,
++ uint32_t *numbytes, int buflocked);
++extern int sfprov_write(sfp_file_t *, char * buffer, uint64_t offset,
++ uint32_t *numbytes, int buflocked);
++extern int sfprov_fsync(sfp_file_t *fp);
++
++
++/*
++ * get/set information about a file (or directory) using pathname
++ */
++extern int sfprov_get_mode(sfp_mount_t *, char *, mode_t *);
++extern int sfprov_get_size(sfp_mount_t *, char *, uint64_t *);
++extern int sfprov_get_atime(sfp_mount_t *, char *, struct timespec *);
++extern int sfprov_get_mtime(sfp_mount_t *, char *, struct timespec *);
++extern int sfprov_get_ctime(sfp_mount_t *, char *, struct timespec *);
++extern int sfprov_get_attr(sfp_mount_t *, char *, sffs_stat_t *);
++extern int sfprov_set_attr(sfp_mount_t *, char *, mode_t,
++ struct timespec, struct timespec, struct timespec);
++extern int sfprov_set_size(sfp_mount_t *, char *, uint64_t);
++
++
++/*
++ * File/Directory operations
++ */
++extern int sfprov_trunc(sfp_mount_t *, char *);
++extern int sfprov_remove(sfp_mount_t *, char *path, u_int is_link);
++extern int sfprov_mkdir(sfp_mount_t *, char *path, mode_t mode,
++ sffs_stat_t *stat);
++extern int sfprov_rmdir(sfp_mount_t *, char *path);
++extern int sfprov_rename(sfp_mount_t *, char *from, char *to, u_int is_dir);
++
++
++/*
++ * Symbolic link operations
++ */
++extern int sfprov_set_show_symlinks(void);
++extern int sfprov_readlink(sfp_mount_t *, char *path, char *target,
++ size_t tgt_size);
++extern int sfprov_symlink(sfp_mount_t *, char *linkname, char *target,
++ sffs_stat_t *stat);
++
++#define SFFS_DIRENTS_SIZE 8192
++#define SFFS_DIRENTS_OFF (offsetof(sffs_dirents_t, sf_entries[0]))
++
++extern int sfprov_readdir(sfp_mount_t *mnt, char *path,
++ sffs_dirents_t **dirents);
++
+ #endif /* KERNEL */
+
+ #endif /* !GA_INCLUDED_SRC_freebsd_vboxvfs_vboxvfs_h */
+-
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__prov.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__prov.c
new file mode 100644
index 000000000000..e606c4f1de6f
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__prov.c
@@ -0,0 +1,1015 @@
+--- src/VBox/Additions/freebsd/vboxvfs/vboxvfs_prov.c.orig 2024-08-15 13:18:37.777504000 +0900
++++ src/VBox/Additions/freebsd/vboxvfs/vboxvfs_prov.c 2024-08-15 13:18:37.777446000 +0900
+@@ -0,0 +1,1012 @@
++/*
++ * Copyright (C) 2008-2016 Oracle Corporation
++ *
++ * This file is part of VirtualBox Open Source Edition (OSE), as
++ * available from http://www.virtualbox.org. This file is free software;
++ * you can redistribute it and/or modify it under the terms of the GNU
++ * General Public License (GPL) as published by the Free Software
++ * Foundation, in version 2 as it comes in the "COPYING" file of the
++ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
++ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
++ *
++ * The contents of this file may alternatively be used under the terms
++ * of the Common Development and Distribution License Version 1.0
++ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
++ * VirtualBox OSE distribution, in which case the provisions of the
++ * CDDL are applicable instead of those of the GPL.
++ *
++ * You may elect to license modified versions of this file under the
++ * terms and conditions of either the GPL or the CDDL or both.
++ */
++
++/*
++ * Provider interfaces for shared folder file system.
++ */
++
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <sys/param.h>
++#include <sys/systm.h>
++#include <sys/kernel.h>
++#include <sys/malloc.h>
++#include <sys/mount.h>
++#include <sys/vnode.h>
++#include <sys/dirent.h>
++#include <sys/proc.h>
++#include <vm/vm.h>
++#include <vm/pmap.h>
++#include <vm/vm_kern.h>
++#include <vm/vm_map.h>
++#include <vm/vm_object.h>
++#include <vm/vm_extern.h>
++#include <vm/uma.h>
++#include "vboxvfs.h"
++
++#define DIRENT_RECLEN(namelen) \
++ ((offsetof(struct dirent, d_name[0]) + 1 + (namelen) + 7) & ~ 7)
++#define DIRENT_NAMELEN(reclen) \
++ ((reclen) - (offsetof(struct dirent, d_name[0])))
++
++static VBGLSFCLIENT vbox_client;
++
++extern u_int vboxvfs_debug;
++
++static int
++sfprov_vbox2errno(int rc)
++{
++ if (rc == VERR_ACCESS_DENIED)
++ return (EACCES);
++ if (rc == VERR_INVALID_NAME)
++ return (ENOENT);
++ return (RTErrConvertToErrno(rc));
++}
++
++/*
++ * utility to create strings
++ */
++static SHFLSTRING *
++sfprov_string(char *path, int *sz)
++{
++ SHFLSTRING *str;
++ int len = strlen(path);
++
++ *sz = len + 1 + sizeof (*str) - sizeof (str->String);
++ str = malloc(*sz, M_VBOXVFS, M_WAITOK | M_ZERO);
++ str->u16Size = len + 1;
++ str->u16Length = len;
++ strcpy(str->String.utf8, path);
++ return (str);
++}
++
++sfp_connection_t *
++sfprov_connect(int version)
++{
++ /* only one version for now, so must match */
++ int error = -1;
++
++ if (version != SFPROV_VERSION) {
++ printf("%s: version mismatch (%d, expected %d)\n", __func__,
++ version, SFPROV_VERSION);
++ return (NULL);
++ }
++
++ if (RT_FAILURE(VbglR0SfInit()))
++ return (NULL);
++
++ if (RT_FAILURE(VbglR0SfConnect(&vbox_client))) {
++ VbglR0SfTerm();
++ return (NULL);
++ }
++
++ if (RT_FAILURE(VbglR0SfSetUtf8(&vbox_client))) {
++ VbglR0SfDisconnect(&vbox_client);
++ VbglR0SfTerm();
++ return (NULL);
++ }
++ return ((sfp_connection_t *)&vbox_client);
++}
++
++void
++sfprov_disconnect()
++{
++ VbglR0SfDisconnect(&vbox_client);
++ VbglR0SfTerm();
++}
++
++int
++sfprov_mount(char *path, sfp_mount_t **mnt)
++{
++ sfp_mount_t *m;
++ SHFLSTRING *str;
++ int size;
++ int rc;
++
++ VBOXVFS_DEBUG(1, "%s: Enter", __FUNCTION__);
++ VBOXVFS_DEBUG(1, "%s: path: [%s]", __FUNCTION__, path);
++
++ m = malloc(sizeof (*m), M_VBOXVFS, M_WAITOK | M_ZERO);
++ str = sfprov_string(path, &size);
++
++ int error;
++ rc = VbglR0SfMapFolder(&vbox_client, str, &m->map);
++ if (RT_FAILURE(rc)) {
++ free(m, M_VBOXVFS);
++ *mnt = NULL;
++ error = sfprov_vbox2errno(rc);
++ } else {
++ *mnt = m;
++ error = 0;
++ }
++ free(str, M_VBOXVFS);
++ printf("%s(%s): error=%d rc=%d\n", __func__, path, error, rc);
++ return (error);
++}
++
++int
++sfprov_unmount(sfp_mount_t *mnt)
++{
++ int rc;
++
++ rc = VbglR0SfUnmapFolder(&vbox_client, &mnt->map);
++ if (RT_FAILURE(rc)) {
++ printf("sfprov_unmount: VbglR0SfUnmapFolder() failed rc=%d\n", rc);
++ rc = sfprov_vbox2errno(rc);
++ } else {
++ rc = 0;
++ }
++
++ free(mnt, M_VBOXVFS);
++ return (rc);
++}
++
++/*
++ * query information about a mounted file system
++ */
++int
++sfprov_get_fsinfo(sfp_mount_t *mnt, sffs_fsinfo_t *fsinfo)
++{
++ int rc;
++ SHFLVOLINFO info;
++ uint32_t bytes = sizeof(SHFLVOLINFO);
++ size_t bytesused;
++
++ rc = VbglR0SfFsInfo(&vbox_client, &mnt->map, 0,
++ (SHFL_INFO_GET | SHFL_INFO_VOLUME), &bytes, (SHFLDIRINFO *)&info);
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++
++ fsinfo->blksize = info.ulBytesPerAllocationUnit;
++ bytesused =
++ info.ullTotalAllocationBytes - info.ullAvailableAllocationBytes;
++ fsinfo->blksused = bytesused / info.ulBytesPerAllocationUnit;
++ fsinfo->blksavail = info.ullAvailableAllocationBytes /
++ info.ulBytesPerAllocationUnit;
++ fsinfo->maxnamesize = info.fsProperties.cbMaxComponent;
++ fsinfo->readonly = info.fsProperties.fReadOnly;
++ fsinfo->serial = info.ulSerial;
++ return (0);
++}
++
++/*
++ * file/directory information conversions.
++ */
++static void
++sfprov_fmode_from_mode(RTFMODE *fMode, mode_t mode)
++{
++ RTFMODE m = 0;
++
++#define mode_set(r) ((mode & (S_##r)) ? RTFS_UNIX_##r : 0)
++ m = mode_set (ISUID);
++ m |= mode_set (ISGID);
++ m |= (mode & S_ISVTX) ? RTFS_UNIX_ISTXT : 0;
++ m |= mode_set (IRUSR);
++ m |= mode_set (IWUSR);
++ m |= mode_set (IXUSR);
++ m |= mode_set (IRGRP);
++ m |= mode_set (IWGRP);
++ m |= mode_set (IXGRP);
++ m |= mode_set (IROTH);
++ m |= mode_set (IWOTH);
++ m |= mode_set (IXOTH);
++
++ if (S_ISDIR(mode))
++ m |= RTFS_TYPE_DIRECTORY;
++ else if (S_ISREG(mode))
++ m |= RTFS_TYPE_FILE;
++ else if (S_ISFIFO(mode))
++ m |= RTFS_TYPE_FIFO;
++ else if (S_ISCHR(mode))
++ m |= RTFS_TYPE_DEV_CHAR;
++ else if (S_ISBLK(mode))
++ m |= RTFS_TYPE_DEV_BLOCK;
++ else if (S_ISLNK(mode))
++ m |= RTFS_TYPE_SYMLINK;
++ else if (S_ISSOCK(mode))
++ m |= RTFS_TYPE_SOCKET;
++ else
++ m |= RTFS_TYPE_FILE;
++
++ *fMode = m;
++}
++
++static void
++sfprov_mode_from_fmode(mode_t *mode, RTFMODE fMode)
++{
++ mode_t m = 0;
++
++ if (RTFS_IS_DIRECTORY(fMode))
++ m |= S_IFDIR;
++ else if (RTFS_IS_FILE(fMode))
++ m |= S_IFREG;
++ else if (RTFS_IS_FIFO(fMode))
++ m |= S_IFIFO;
++ else if (RTFS_IS_DEV_CHAR(fMode))
++ m |= S_IFCHR;
++ else if (RTFS_IS_DEV_BLOCK(fMode))
++ m |= S_IFBLK;
++ else if (RTFS_IS_SYMLINK(fMode))
++ m |= S_IFLNK;
++ else if (RTFS_IS_SOCKET(fMode))
++ m |= S_IFSOCK;
++
++ if (fMode & RTFS_UNIX_IRUSR)
++ m |= S_IRUSR;
++ if (fMode & RTFS_UNIX_IWUSR)
++ m |= S_IWUSR;
++ if (fMode & RTFS_UNIX_IXUSR)
++ m |= S_IXUSR;
++ if (fMode & RTFS_UNIX_IRGRP)
++ m |= S_IRGRP;
++ if (fMode & RTFS_UNIX_IWGRP)
++ m |= S_IWGRP;
++ if (fMode & RTFS_UNIX_IXGRP)
++ m |= S_IXGRP;
++ if (fMode & RTFS_UNIX_IROTH)
++ m |= S_IROTH;
++ if (fMode & RTFS_UNIX_IWOTH)
++ m |= S_IWOTH;
++ if (fMode & RTFS_UNIX_IXOTH)
++ m |= S_IXOTH;
++ if (fMode & RTFS_UNIX_ISUID)
++ m |= S_ISUID;
++ if (fMode & RTFS_UNIX_ISGID)
++ m |= S_ISGID;
++ if (fMode & RTFS_UNIX_ISTXT)
++ m |= S_ISVTX;
++ *mode = m;
++}
++
++static void
++sfprov_ftime_from_timespec(struct timespec *time, RTTIMESPEC *ts)
++{
++ uint64_t nanosec = RTTimeSpecGetNano(ts);
++ time->tv_sec = nanosec / UINT64_C(1000000000);
++ time->tv_nsec = nanosec % UINT64_C(1000000000);
++}
++
++static void
++sfprov_stat_from_info(sffs_stat_t *stat, SHFLFSOBJINFO *info)
++{
++ sfprov_mode_from_fmode(&stat->sf_mode, info->Attr.fMode);
++ stat->sf_size = info->cbObject;
++ stat->sf_alloc = info->cbAllocated;
++ sfprov_ftime_from_timespec(&stat->sf_atime, &info->AccessTime);
++ sfprov_ftime_from_timespec(&stat->sf_mtime, &info->ModificationTime);
++ sfprov_ftime_from_timespec(&stat->sf_ctime, &info->ChangeTime);
++}
++
++/*
++ * File operations: open/close/read/write/etc.
++ *
++ * open/create can return any relevant errno, however ENOENT
++ * generally means that the host file didn't exist.
++ */
++int
++sfprov_create(
++ sfp_mount_t *mnt,
++ char *path,
++ mode_t mode,
++ sffs_stat_t *stat)
++{
++ int rc;
++ SHFLCREATEPARMS parms;
++ SHFLSTRING *str;
++ int size;
++ sfp_file_t *newfp;
++
++ str = sfprov_string(path, &size);
++ parms.Handle = SHFL_HANDLE_NIL;
++ parms.Info.cbObject = 0;
++ sfprov_fmode_from_mode(&parms.Info.Attr.fMode, mode);
++ parms.CreateFlags = SHFL_CF_ACT_CREATE_IF_NEW |
++ SHFL_CF_ACT_REPLACE_IF_EXISTS | SHFL_CF_ACCESS_READWRITE;
++ rc = VbglR0SfCreate(&vbox_client, &mnt->map, str, &parms);
++ free(str, M_VBOXVFS);
++
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++ if (parms.Handle == SHFL_HANDLE_NIL) {
++ if (parms.Result == SHFL_FILE_EXISTS)
++ return (EEXIST);
++ return (ENOENT);
++ }
++ (void)VbglR0SfClose(&vbox_client, &mnt->map, parms.Handle);
++ sfprov_stat_from_info(stat, &parms.Info);
++ return (0);
++}
++
++int
++sfprov_open(sfp_mount_t *mnt, char *path, sfp_file_t **fp)
++{
++ int rc;
++ SHFLCREATEPARMS parms;
++ SHFLSTRING *str;
++ int size;
++ sfp_file_t *newfp;
++
++ /*
++ * First we attempt to open it read/write. If that fails we
++ * try read only.
++ */
++ bzero(&parms, sizeof(parms));
++ str = sfprov_string(path, &size);
++ parms.Handle = SHFL_HANDLE_NIL;
++ parms.Info.cbObject = 0;
++ parms.CreateFlags = SHFL_CF_ACT_FAIL_IF_NEW | SHFL_CF_ACCESS_READWRITE;
++ rc = VbglR0SfCreate(&vbox_client, &mnt->map, str, &parms);
++ if (RT_FAILURE(rc) && rc != VERR_ACCESS_DENIED) {
++ free(str, M_VBOXVFS);
++ return (sfprov_vbox2errno(rc));
++ }
++ if (parms.Handle == SHFL_HANDLE_NIL) {
++ if (parms.Result == SHFL_PATH_NOT_FOUND ||
++ parms.Result == SHFL_FILE_NOT_FOUND) {
++ free(str, M_VBOXVFS);
++ return (ENOENT);
++ }
++ parms.CreateFlags =
++ SHFL_CF_ACT_FAIL_IF_NEW | SHFL_CF_ACCESS_READ;
++ rc = VbglR0SfCreate(&vbox_client, &mnt->map, str, &parms);
++ if (RT_FAILURE(rc)) {
++ free(str, M_VBOXVFS);
++ return (sfprov_vbox2errno(rc));
++ }
++ if (parms.Handle == SHFL_HANDLE_NIL) {
++ free(str, M_VBOXVFS);
++ return (ENOENT);
++ }
++ }
++ else
++ free(str, M_VBOXVFS);
++ newfp = malloc(sizeof(sfp_file_t), M_VBOXVFS, M_WAITOK | M_ZERO);
++ newfp->handle = parms.Handle;
++ newfp->map = mnt->map;
++ *fp = newfp;
++ return (0);
++}
++
++int
++sfprov_trunc(sfp_mount_t *mnt, char *path)
++{
++ int rc;
++ SHFLCREATEPARMS parms;
++ SHFLSTRING *str;
++ int size;
++
++ /*
++ * open it read/write.
++ */
++ str = sfprov_string(path, &size);
++ parms.Handle = 0;
++ parms.Info.cbObject = 0;
++ parms.CreateFlags = SHFL_CF_ACT_FAIL_IF_NEW | SHFL_CF_ACCESS_READWRITE |
++ SHFL_CF_ACT_OVERWRITE_IF_EXISTS;
++ rc = VbglR0SfCreate(&vbox_client, &mnt->map, str, &parms);
++ free(str, M_VBOXVFS);
++
++ if (RT_FAILURE(rc)) {
++ return (sfprov_vbox2errno(rc));
++ }
++ (void)VbglR0SfClose(&vbox_client, &mnt->map, parms.Handle);
++ return (0);
++}
++
++int
++sfprov_close(sfp_file_t *fp)
++{
++ int rc;
++
++ rc = VbglR0SfClose(&vbox_client, &fp->map, fp->handle);
++ free(fp, M_VBOXVFS);
++ return (0);
++}
++
++int
++sfprov_read(sfp_file_t *fp, char *buffer, uint64_t offset, uint32_t *numbytes,
++ int buflocked)
++{
++ int rc;
++
++ rc = VbglR0SfRead(&vbox_client, &fp->map, fp->handle, offset,
++ numbytes, (uint8_t *)buffer, buflocked);
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++ return (0);
++}
++
++int
++sfprov_write(sfp_file_t *fp, char *buffer, uint64_t offset, uint32_t *numbytes,
++ int buflocked)
++{
++ int rc;
++
++ rc = VbglR0SfWrite(&vbox_client, &fp->map, fp->handle, offset,
++ numbytes, (uint8_t *)buffer, buflocked);
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++ return (0);
++}
++
++int
++sfprov_fsync(sfp_file_t *fp)
++{
++ int rc;
++
++ rc = VbglR0SfFlush(&vbox_client, &fp->map, fp->handle);
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++ return (0);
++}
++
++
++static int
++sfprov_getinfo(sfp_mount_t *mnt, char *path, PSHFLFSOBJINFO info)
++{
++ int rc;
++ SHFLCREATEPARMS parms;
++ SHFLSTRING *str;
++ int size;
++
++ str = sfprov_string(path, &size);
++ parms.Handle = 0;
++ parms.Info.cbObject = 0;
++ parms.CreateFlags = SHFL_CF_LOOKUP | SHFL_CF_ACT_FAIL_IF_NEW;
++ rc = VbglR0SfCreate(&vbox_client, &mnt->map, str, &parms);
++ free(str, M_VBOXVFS);
++
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++ if (parms.Result != SHFL_FILE_EXISTS)
++ return (ENOENT);
++ *info = parms.Info;
++ return (0);
++}
++
++/*
++ * get information about a file (or directory)
++ */
++int
++sfprov_get_mode(sfp_mount_t *mnt, char *path, mode_t *mode)
++{
++ int rc;
++ SHFLFSOBJINFO info;
++
++ rc = sfprov_getinfo(mnt, path, &info);
++ if (rc)
++ return (rc);
++ sfprov_mode_from_fmode(mode, info.Attr.fMode);
++ return (0);
++}
++
++int
++sfprov_get_size(sfp_mount_t *mnt, char *path, uint64_t *size)
++{
++ int rc;
++ SHFLFSOBJINFO info;
++
++ rc = sfprov_getinfo(mnt, path, &info);
++ if (rc)
++ return (rc);
++ *size = info.cbObject;
++ return (0);
++}
++
++
++int
++sfprov_get_atime(sfp_mount_t *mnt, char *path, struct timespec *time)
++{
++ int rc;
++ SHFLFSOBJINFO info;
++
++ rc = sfprov_getinfo(mnt, path, &info);
++ if (rc)
++ return (rc);
++ sfprov_ftime_from_timespec(time, &info.AccessTime);
++ return (0);
++}
++
++int
++sfprov_get_mtime(sfp_mount_t *mnt, char *path, struct timespec *time)
++{
++ int rc;
++ SHFLFSOBJINFO info;
++
++ rc = sfprov_getinfo(mnt, path, &info);
++ if (rc)
++ return (rc);
++ sfprov_ftime_from_timespec(time, &info.ModificationTime);
++ return (0);
++}
++
++int
++sfprov_get_ctime(sfp_mount_t *mnt, char *path, struct timespec *time)
++{
++ int rc;
++ SHFLFSOBJINFO info;
++
++ rc = sfprov_getinfo(mnt, path, &info);
++ if (rc)
++ return (rc);
++ sfprov_ftime_from_timespec(time, &info.ChangeTime);
++ return (0);
++}
++
++int
++sfprov_get_attr(sfp_mount_t *mnt, char *path, sffs_stat_t *attr)
++{
++ int rc;
++ SHFLFSOBJINFO info;
++
++ rc = sfprov_getinfo(mnt, path, &info);
++ if (rc)
++ return (rc);
++ sfprov_stat_from_info(attr, &info);
++ return (0);
++}
++
++static void
++sfprov_timespec_from_ftime(RTTIMESPEC *ts, struct timespec time)
++{
++ uint64_t nanosec = UINT64_C(1000000000) * time.tv_sec + time.tv_nsec;
++ RTTimeSpecSetNano(ts, nanosec);
++}
++
++int
++sfprov_set_attr(
++ sfp_mount_t *mnt,
++ char *path,
++ mode_t mode,
++ struct timespec atime,
++ struct timespec mtime,
++ struct timespec ctime)
++{
++ int rc, err;
++ SHFLCREATEPARMS parms;
++ SHFLSTRING *str;
++ SHFLFSOBJINFO info;
++ uint32_t bytes;
++ int str_size;
++
++ str = sfprov_string(path, &str_size);
++ parms.Handle = 0;
++ parms.Info.cbObject = 0;
++ parms.CreateFlags = SHFL_CF_ACT_OPEN_IF_EXISTS
++ | SHFL_CF_ACT_FAIL_IF_NEW
++ | SHFL_CF_ACCESS_ATTR_WRITE;
++
++ rc = VbglR0SfCreate(&vbox_client, &mnt->map, str, &parms);
++
++ if (RT_FAILURE(rc)) {
++ printf("sfprov_set_attr: VbglR0SfCreate(%s) failed rc=%d\n",
++ path, rc);
++ err = sfprov_vbox2errno(rc);
++ goto fail2;
++ }
++ if (parms.Result != SHFL_FILE_EXISTS) {
++ err = ENOENT;
++ goto fail1;
++ }
++
++ RT_ZERO(info);
++#if 0
++ if (mask & AT_MODE)
++ sfprov_fmode_from_mode(&info.Attr.fMode, mode);
++ if (mask & AT_ATIME)
++ sfprov_timespec_from_ftime(&info.AccessTime, atime);
++ if (mask & AT_MTIME)
++ sfprov_timespec_from_ftime(&info.ModificationTime, mtime);
++ if (mask & AT_CTIME)
++ sfprov_timespec_from_ftime(&info.ChangeTime, ctime);
++#endif
++ bytes = sizeof(info);
++ rc = VbglR0SfFsInfo(&vbox_client, &mnt->map, parms.Handle,
++ (SHFL_INFO_SET | SHFL_INFO_FILE), &bytes, (SHFLDIRINFO *)&info);
++ if (RT_FAILURE(rc)) {
++ if (rc != VERR_ACCESS_DENIED && rc != VERR_WRITE_PROTECT)
++ {
++ printf("sfprov_set_attr: VbglR0SfFsInfo(%s, FILE) failed rc=%d\n",
++ path, rc);
++ }
++ err = sfprov_vbox2errno(rc);
++ goto fail1;
++ }
++
++ err = 0;
++
++fail1:
++ rc = VbglR0SfClose(&vbox_client, &mnt->map, parms.Handle);
++ if (RT_FAILURE(rc)) {
++ printf("sfprov_set_attr: VbglR0SfClose(%s) failed rc=%d\n",
++ path, rc);
++ }
++fail2:
++ free(str, M_VBOXVFS);
++ return err;
++}
++
++int
++sfprov_set_size(sfp_mount_t *mnt, char *path, uint64_t size)
++{
++ int rc, err;
++ SHFLCREATEPARMS parms;
++ SHFLSTRING *str;
++ SHFLFSOBJINFO info;
++ uint32_t bytes;
++ int str_size;
++
++ str = sfprov_string(path, &str_size);
++ parms.Handle = 0;
++ parms.Info.cbObject = 0;
++ parms.CreateFlags = SHFL_CF_ACT_OPEN_IF_EXISTS
++ | SHFL_CF_ACT_FAIL_IF_NEW
++ | SHFL_CF_ACCESS_WRITE;
++
++ rc = VbglR0SfCreate(&vbox_client, &mnt->map, str, &parms);
++
++ if (RT_FAILURE(rc)) {
++ printf("sfprov_set_size: VbglR0SfCreate(%s) failed rc=%d\n",
++ path, rc);
++ err = sfprov_vbox2errno(rc);
++ goto fail2;
++ }
++ if (parms.Result != SHFL_FILE_EXISTS) {
++ err = ENOENT;
++ goto fail1;
++ }
++
++ RT_ZERO(info);
++ info.cbObject = size;
++ bytes = sizeof(info);
++ rc = VbglR0SfFsInfo(&vbox_client, &mnt->map, parms.Handle,
++ (SHFL_INFO_SET | SHFL_INFO_SIZE), &bytes, (SHFLDIRINFO *)&info);
++ if (RT_FAILURE(rc)) {
++ printf("sfprov_set_size: VbglR0SfFsInfo(%s, SIZE) failed rc=%d\n",
++ path, rc);
++ err = sfprov_vbox2errno(rc);
++ goto fail1;
++ }
++
++ err = 0;
++
++fail1:
++ rc = VbglR0SfClose(&vbox_client, &mnt->map, parms.Handle);
++ if (RT_FAILURE(rc)) {
++ printf("sfprov_set_size: VbglR0SfClose(%s) failed rc=%d\n",
++ path, rc);
++ }
++fail2:
++ free(str, M_VBOXVFS);
++ return err;
++}
++
++/*
++ * Directory operations
++ */
++int
++sfprov_mkdir(
++ sfp_mount_t *mnt,
++ char *path,
++ mode_t mode,
++ sffs_stat_t *stat)
++{
++ int rc;
++ SHFLCREATEPARMS parms;
++ SHFLSTRING *str;
++ int size;
++
++ str = sfprov_string(path, &size);
++ parms.Handle = SHFL_HANDLE_NIL;
++ parms.Info.cbObject = 0;
++ sfprov_fmode_from_mode(&parms.Info.Attr.fMode, mode);
++ parms.CreateFlags = SHFL_CF_DIRECTORY | SHFL_CF_ACT_CREATE_IF_NEW |
++ SHFL_CF_ACT_FAIL_IF_EXISTS | SHFL_CF_ACCESS_READ;
++ rc = VbglR0SfCreate(&vbox_client, &mnt->map, str, &parms);
++ free(str, M_VBOXVFS);
++
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++ if (parms.Handle == SHFL_HANDLE_NIL) {
++ if (parms.Result == SHFL_FILE_EXISTS)
++ return (EEXIST);
++ return (ENOENT);
++ }
++ (void)VbglR0SfClose(&vbox_client, &mnt->map, parms.Handle);
++ sfprov_stat_from_info(stat, &parms.Info);
++ return (0);
++}
++
++int
++sfprov_set_show_symlinks(void)
++{
++ int rc;
++
++ rc = VbglR0SfSetSymlinks(&vbox_client);
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++
++ return (0);
++}
++
++int
++sfprov_remove(sfp_mount_t *mnt, char *path, u_int is_link)
++{
++ int rc;
++ SHFLSTRING *str;
++ int size;
++
++ str = sfprov_string(path, &size);
++ rc = VbglR0SfRemove(&vbox_client, &mnt->map, str,
++ SHFL_REMOVE_FILE | (is_link ? SHFL_REMOVE_SYMLINK : 0));
++ free(str, M_VBOXVFS);
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++ return (0);
++}
++
++int
++sfprov_readlink(
++ sfp_mount_t *mnt,
++ char *path,
++ char *target,
++ size_t tgt_size)
++{
++ int rc;
++ SHFLSTRING *str;
++ int size;
++
++ str = sfprov_string(path, &size);
++
++ rc = VbglR0SfReadLink(&vbox_client, &mnt->map, str, (uint32_t) tgt_size,
++ target);
++ if (RT_FAILURE(rc))
++ rc = sfprov_vbox2errno(rc);
++
++ free(str, M_VBOXVFS);
++ return (rc);
++}
++
++int
++sfprov_symlink(
++ sfp_mount_t *mnt,
++ char *linkname,
++ char *target,
++ sffs_stat_t *stat)
++{
++ int rc;
++ SHFLSTRING *lnk, *tgt;
++ int lnk_size, tgt_size;
++ SHFLFSOBJINFO info;
++
++ lnk = sfprov_string(linkname, &lnk_size);
++ tgt = sfprov_string(target, &tgt_size);
++
++ rc = VbglR0SfSymlink(&vbox_client, &mnt->map, lnk, tgt, &info);
++ if (RT_FAILURE(rc)) {
++ rc = sfprov_vbox2errno(rc);
++ goto done;
++ }
++
++ if (stat != NULL)
++ sfprov_stat_from_info(stat, &info);
++
++done:
++ free(lnk, M_VBOXVFS);
++ free(tgt, M_VBOXVFS);
++
++ return (rc);
++}
++
++int
++sfprov_rmdir(sfp_mount_t *mnt, char *path)
++{
++ int rc;
++ SHFLSTRING *str;
++ int size;
++
++ str = sfprov_string(path, &size);
++ rc = VbglR0SfRemove(&vbox_client, &mnt->map, str, SHFL_REMOVE_DIR);
++ free(str, M_VBOXVFS);
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++ return (0);
++}
++
++int
++sfprov_rename(sfp_mount_t *mnt, char *from, char *to, u_int is_dir)
++{
++ int rc;
++ SHFLSTRING *old, *new;
++ int old_size, new_size;
++
++ old = sfprov_string(from, &old_size);
++ new = sfprov_string(to, &new_size);
++ rc = VbglR0SfRename(&vbox_client, &mnt->map, old, new,
++ (is_dir ? SHFL_RENAME_DIR : SHFL_RENAME_FILE) |
++ SHFL_RENAME_REPLACE_IF_EXISTS);
++ free(old, M_VBOXVFS);
++ free(new, M_VBOXVFS);
++ if (RT_FAILURE(rc))
++ return (sfprov_vbox2errno(rc));
++ return (0);
++}
++
++/*
++ * Read all filenames in a directory.
++ *
++ * - success - all entries read and returned
++ * - ENOENT - Couldn't open the directory for reading
++ * - EINVAL - Internal error of some kind
++ *
++ * On successful return, *dirents points to a list of sffs_dirents_t;
++ * for each dirent, all fields except the d_ino will be set appropriately.
++ * The caller is responsible for freeing the dirents buffer.
++ */
++int
++sfprov_readdir(
++ sfp_mount_t *mnt,
++ char *path,
++ sffs_dirents_t **dirents)
++{
++ int error;
++ char *cp;
++ int len;
++ SHFLSTRING *mask_str = NULL; /* must be path with "/" appended */
++ int mask_size;
++ sfp_file_t *fp;
++ uint32_t infobuff_alloc = 16384;
++ SHFLDIRINFO *infobuff = NULL, *info;
++ uint32_t numbytes;
++ uint32_t nents;
++ uint32_t size;
++ off_t offset;
++ sffs_dirents_t *cur_buf;
++ struct sffs_dirent *dirent;
++ unsigned short reclen;
++ unsigned short entlen;
++
++ *dirents = NULL;
++
++ error = sfprov_open(mnt, path, &fp);
++ if (error != 0)
++ return (ENOENT);
++
++ /*
++ * Allocate the first dirents buffers.
++ */
++ *dirents = malloc(SFFS_DIRENTS_SIZE, M_VBOXVFS, M_WAITOK | M_ZERO);
++ if (*dirents == NULL) {
++ error = (ENOSPC);
++ goto done;
++ }
++ cur_buf = *dirents;
++ cur_buf->sf_next = NULL;
++ cur_buf->sf_len = 0;
++
++ /*
++ * Create mask that VBox expects. This needs to be the directory path,
++ * plus a "*" wildcard to get all files.
++ */
++ len = strlen(path) + 3;
++ cp = malloc(len, M_VBOXVFS, M_WAITOK | M_ZERO);
++ if (cp == NULL) {
++ error = (ENOSPC);
++ goto done;
++ }
++ strcpy(cp, path);
++ strcat(cp, "/*");
++ mask_str = sfprov_string(cp, &mask_size);
++ free(cp, M_VBOXVFS);
++
++ /*
++ * Now loop using VbglR0SfDirInfo
++ */
++ infobuff = malloc(infobuff_alloc, M_VBOXVFS, M_WAITOK | M_ZERO);
++ if (infobuff == NULL) {
++ error = (ENOSPC);
++ goto done;
++ }
++
++ offset = 0;
++ for (;;) {
++ numbytes = infobuff_alloc;
++ error = VbglR0SfDirInfo(&vbox_client, &fp->map, fp->handle,
++ mask_str, 0, 0, &numbytes, infobuff, &nents);
++
++ switch (error) {
++ case VINF_SUCCESS:
++ /* fallthrough */
++ case VERR_NO_MORE_FILES:
++ break;
++ case VERR_NO_TRANSLATION:
++ /* XXX ??? */
++ break;
++ default:
++ error = sfprov_vbox2errno(error);
++ goto done;
++ }
++
++ /*
++ * Create the dirent_t's and save the stats for each name
++ */
++ for (info = infobuff; (char *) info < (char *) infobuff + numbytes; nents--) {
++ size_t buflen;
++
++ /* expand buffers if we need more space */
++ reclen = DIRENT_RECLEN(strlen(info->name.String.utf8));
++ entlen = sizeof(struct sffs_dirent) + reclen;
++ buflen = SFFS_DIRENTS_OFF + cur_buf->sf_len + entlen;
++ if (buflen > SFFS_DIRENTS_SIZE) {
++ cur_buf->sf_next = malloc(SFFS_DIRENTS_SIZE,
++ M_VBOXVFS, M_WAITOK | M_ZERO);
++ if (cur_buf->sf_next == NULL) {
++ error = ENOSPC;
++ goto done;
++ }
++ cur_buf = cur_buf->sf_next;
++ cur_buf->sf_next = NULL;
++ cur_buf->sf_len = 0;
++ }
++
++ /* create the dirent with the name, offset, and len */
++ dirent = (struct sffs_dirent *)
++ (((char *) &cur_buf->sf_entries[0]) + cur_buf->sf_len);
++ strncpy(&dirent->sf_entry.d_name[0],
++ info->name.String.utf8, DIRENT_NAMELEN(reclen));
++ dirent->sf_entry.d_reclen = reclen;
++ dirent->sf_entry.d_namlen = strlen(info->name.String.utf8);
++ dirent->sf_entry.d_name[dirent->sf_entry.d_namlen] = 0;
++ offset += entlen;
++ dirent->sf_off = offset;
++
++ /* save the stats */
++ sfprov_stat_from_info(&dirent->sf_stat, &info->Info);
++
++ /* next info */
++ cur_buf->sf_len += entlen;
++ size = offsetof (SHFLDIRINFO, name.String) + info->name.u16Size;
++ info = (SHFLDIRINFO *) ((uintptr_t) info + size);
++ }
++ KASSERT(nents == 0, ("nents != 0"));
++ KASSERT((char *) info == (char *) infobuff + numbytes, "(char *) info != (char *) infobuff + numbytes");
++
++ if (error == VERR_NO_MORE_FILES)
++ break;
++ }
++ error = 0;
++
++done:
++ if (error != 0) {
++ while (*dirents) {
++ cur_buf = (*dirents)->sf_next;
++ free(*dirents, M_VBOXVFS);
++ *dirents = cur_buf;
++ }
++ }
++ if (infobuff != NULL)
++ free(infobuff, M_VBOXVFS);
++ if (mask_str != NULL)
++ free(mask_str, M_VBOXVFS);
++ sfprov_close(fp);
++
++ return (error);
++}
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__vfsops.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__vfsops.c
new file mode 100644
index 000000000000..8fa76bdf2b8a
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__vfsops.c
@@ -0,0 +1,645 @@
+--- src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c.orig 2021-04-28 16:24:46 UTC
++++ src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c
+@@ -1,8 +1,3 @@
+-/* $Id: vboxvfs_vfsops.c $ */
+-/** @file
+- * Description.
+- */
+-
+ /*
+ * Copyright (C) 2008-2020 Oracle Corporation
+ *
+@@ -14,245 +9,478 @@
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+-
+-#include "vboxvfs.h"
++#include <sys/types.h>
+ #include <sys/param.h>
+ #include <sys/systm.h>
+ #include <sys/proc.h>
+ #include <sys/bio.h>
+ #include <sys/buf.h>
++#include <sys/conf.h>
++#include <sys/dirent.h>
+ #include <sys/kernel.h>
+ #include <sys/sysctl.h>
+ #include <sys/vnode.h>
+ #include <sys/mount.h>
++#include <sys/namei.h>
++#include <sys/fcntl.h>
++#include <sys/priv.h>
+ #include <sys/stat.h>
+ #include <sys/malloc.h>
+ #include <sys/module.h>
++#include <sys/sbuf.h>
+
+-#include <iprt/mem.h>
++#include <geom/geom.h>
++#include <geom/geom_vfs.h>
+-
++#include <vm/uma.h>
++#include "vboxvfs.h"
++
+ #define VFSMP2SFGLOBINFO(mp) ((struct sf_glob_info *)mp->mnt_data)
+
+-static int vboxvfs_version = VBOXVFS_VERSION;
++#ifdef MALLOC_DECLARE
++MALLOC_DEFINE(M_VBOXVFS, "vboxvfs", "VBOX VFS");
++#endif
+
+-SYSCTL_NODE(_vfs, OID_AUTO, vboxvfs, CTLFLAG_RW, 0, "VirtualBox shared filesystem");
+-SYSCTL_INT(_vfs_vboxvfs, OID_AUTO, version, CTLFLAG_RD, &vboxvfs_version, 0, "");
++static sfp_connection_t *sfprov = NULL;
+
+-/* global connection to the host service. */
+-static VBGLSFCLIENT g_vboxSFClient;
++static int vboxfs_version = VBOXVFS_VERSION;
++u_int vboxvfs_debug = 1;
+
+-static vfs_init_t vboxvfs_init;
+-static vfs_uninit_t vboxvfs_uninit;
+-static vfs_cmount_t vboxvfs_cmount;
+-static vfs_mount_t vboxvfs_mount;
+-static vfs_root_t vboxvfs_root;
+-static vfs_quotactl_t vboxvfs_quotactl;
+-static vfs_statfs_t vboxvfs_statfs;
+-static vfs_unmount_t vboxvfs_unmount;
++SYSCTL_NODE(_vfs, OID_AUTO, vboxfs, CTLFLAG_RW, 0, "VirtualBox shared filesystem");
++SYSCTL_INT(_vfs_vboxfs, OID_AUTO, version, CTLFLAG_RD, &vboxfs_version, 0, "");
++SYSCTL_UINT(_vfs_vboxfs, OID_AUTO, debug, CTLFLAG_RW, &vboxvfs_debug, 0, "Debug level");
+
+-static struct vfsops vboxvfs_vfsops = {
+- .vfs_init = vboxvfs_init,
+- .vfs_cmount = vboxvfs_cmount,
+- .vfs_mount = vboxvfs_mount,
+- .vfs_quotactl = vboxvfs_quotactl,
+- .vfs_root = vboxvfs_root,
+- .vfs_statfs = vboxvfs_statfs,
+- .vfs_sync = vfs_stdsync,
+- .vfs_uninit = vboxvfs_uninit,
+- .vfs_unmount = vboxvfs_unmount,
++static vfs_init_t vboxfs_init;
++static vfs_uninit_t vboxfs_uninit;
++static vfs_cmount_t vboxfs_cmount;
++static vfs_mount_t vboxfs_mount;
++static vfs_root_t vboxfs_root;
++static vfs_quotactl_t vboxfs_quotactl;
++static vfs_statfs_t vboxfs_statfs;
++static vfs_unmount_t vboxfs_unmount;
++
++static struct vfsops vboxfs_vfsops = {
++ .vfs_init = vboxfs_init,
++ .vfs_cmount = vboxfs_cmount,
++ .vfs_mount = vboxfs_mount,
++ .vfs_quotactl = vboxfs_quotactl,
++ .vfs_root = vboxfs_root,
++ .vfs_statfs = vboxfs_statfs,
++ .vfs_sync = vfs_stdsync,
++ .vfs_uninit = vboxfs_uninit,
++ .vfs_unmount = vboxfs_unmount
+ };
+
+
+-VFS_SET(vboxvfs_vfsops, vboxvfs, VFCF_NETWORK);
++VFS_SET(vboxfs_vfsops, vboxvfs, VFCF_NETWORK);
+ MODULE_DEPEND(vboxvfs, vboxguest, 1, 1, 1);
+
+-static int vboxvfs_cmount(struct mntarg *ma, void * data, int flags, struct thread *td)
++/*
++ * Allocates a new node of type 'type' inside the 'tmp' mount point, with
++ * its owner set to 'uid', its group to 'gid' and its mode set to 'mode',
++ * using the credentials of the process 'p'.
++ *
++ * If the node type is set to 'VDIR', then the parent parameter must point
++ * to the parent directory of the node being created. It may only be NULL
++ * while allocating the root node.
++ *
++ * If the node type is set to 'VBLK' or 'VCHR', then the rdev parameter
++ * specifies the device the node represents.
++ *
++ * If the node type is set to 'VLNK', then the parameter target specifies
++ * the file name of the target file for the symbolic link that is being
++ * created.
++ *
++ * Note that new nodes are retrieved from the available list if it has
++ * items or, if it is empty, from the node pool as long as there is enough
++ * space to create them.
++ *
++ * Returns zero on success or an appropriate error code on failure.
++ */
++int
++vboxfs_alloc_node(struct mount *mp, struct vboxfs_mnt *vsfmp, const char *fullpath,
++ enum_vtype_t type, uid_t uid, gid_t gid, mode_t mode, struct vboxfs_node *parent,
++ struct vboxfs_node **node)
+ {
+- struct vboxvfs_mount_info args;
+- int rc = 0;
++ struct vboxfs_node *nnode;
+
+- printf("%s: Enter\n", __FUNCTION__);
++ if ((mp->mnt_kern_flag & MNTK_UNMOUNT) != 0) {
++ /*
++ * When a new tmpfs node is created for fully
++ * constructed mount point, there must be a parent
++ * node, which vnode is locked exclusively. As
++ * consequence, if the unmount is executing in
++ * parallel, vflush() cannot reclaim the parent vnode.
++ * Due to this, the check for MNTK_UNMOUNT flag is not
++ * racy: if we did not see MNTK_UNMOUNT flag, then tmp
++ * cannot be destroyed until node construction is
++ * finished and the parent vnode unlocked.
++ *
++ * Tmpfs does not need to instantiate new nodes during
++ * unmount.
++ */
++ return (EBUSY);
++ }
+
+- rc = copyin(data, &args, sizeof(struct vboxvfs_mount_info));
+- if (rc)
+- return rc;
++ nnode = (struct vboxfs_node *)uma_zalloc_arg(
++ vsfmp->sf_node_pool, vsfmp, M_WAITOK);
+
+- ma = mount_argf(ma, "uid", "%d", args.uid);
+- ma = mount_argf(ma, "gid", "%d", args.gid);
+- ma = mount_arg(ma, "from", args.name, -1);
++ /* Generic initialization. */
++ nnode->sf_type = type;
++ nnode->sf_ino = vsfmp->sf_ino++;
++ nnode->sf_path = strdup(fullpath, M_VBOXVFS);
++ nnode->sf_parent = parent;
++ nnode->vboxfsmp = vsfmp;
+
+- rc = kernel_mount(ma, flags);
++ /* Type-specific initialization. */
++ switch (nnode->sf_type) {
++ case VBLK:
++ case VCHR:
++ case VDIR:
++ case VFIFO:
++ case VSOCK:
++ case VLNK:
++ case VREG:
++ break;
+
+- printf("%s: Leave rc=%d\n", __FUNCTION__, rc);
++ default:
++ panic("vboxfs_alloc_node: type %p %d", nnode, (int)nnode->sf_type);
++ }
+
+- return rc;
++ *node = nnode;
++ return 0;
+ }
+
+-static const char *vboxvfs_opts[] = {
+- "uid", "gid", "from", "fstype", "fspath", "errmsg", NULL
+-};
+-
+-static int vboxvfs_mount(struct mount *mp, struct thread *td)
++void
++vboxfs_free_node(struct vboxfs_mnt *vboxfs, struct vboxfs_node *node)
+ {
+- int rc;
+- char *pszShare;
+- int cbShare, cbOption;
+- int uid = 0, gid = 0;
+- struct sf_glob_info *pShFlGlobalInfo;
+- SHFLSTRING *pShFlShareName = NULL;
+- int cbShFlShareName;
+
+- printf("%s: Enter\n", __FUNCTION__);
++#ifdef INVARIANTS
++ TMPFS_NODE_LOCK(node);
++ MPASS(node->sf_vnode == NULL);
++ MPASS((node->sf_vpstate & TMPFS_VNODE_ALLOCATING) == 0);
++ TMPFS_NODE_UNLOCK(node);
++#endif
++ if (node->sf_path)
++ free(node->sf_path, M_VBOXVFS);
+
+- if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS))
+- return EOPNOTSUPP;
++ uma_zfree(vboxfs->sf_node_pool, node);
++}
+
+- if (vfs_filteropt(mp->mnt_optnew, vboxvfs_opts))
+- {
+- vfs_mount_error(mp, "%s", "Invalid option");
+- return EINVAL;
+- }
++static int
++vboxfs_cmount(struct mntarg *ma, void *data, uint64_t flags)
++{
++ struct vboxfs_mount_info args;
++ int error = 0;
+
+- rc = vfs_getopt(mp->mnt_optnew, "from", (void **)&pszShare, &cbShare);
+- if (rc || pszShare[cbShare-1] != '\0' || cbShare > 0xfffe)
+- return EINVAL;
++ if (data == NULL)
++ return (EINVAL);
++ error = copyin(data, &args, sizeof(struct vboxfs_mount_info));
++ if (error)
++ return (error);
+
+- rc = vfs_getopt(mp->mnt_optnew, "gid", (void **)&gid, &cbOption);
+- if ((rc != ENOENT) && (rc || cbOption != sizeof(gid)))
+- return EINVAL;
++ ma = mount_argf(ma, "uid", "%d", args.uid);
++ ma = mount_argf(ma, "gid", "%d", args.gid);
++ ma = mount_argf(ma, "file_mode", "%d", args.fmode);
++ ma = mount_argf(ma, "dir_mode", "%d", args.dmode);
++ ma = mount_arg(ma, "from", args.name, -1);
+
+- rc = vfs_getopt(mp->mnt_optnew, "uid", (void **)&uid, &cbOption);
+- if ((rc != ENOENT) && (rc || cbOption != sizeof(uid)))
+- return EINVAL;
++ return (kernel_mount(ma, flags));
++}
+
+- pShFlGlobalInfo = RTMemAllocZ(sizeof(struct sf_glob_info));
+- if (!pShFlGlobalInfo)
+- return ENOMEM;
++static const char *vboxfs_opts[] = {
++ "fstype",
++ "fspath",
++ "from",
++ "uid",
++ "gid",
++ "file_mode",
++ "dir_mode",
++ "errmsg",
++ NULL
++};
+
+- cbShFlShareName = offsetof (SHFLSTRING, String.utf8) + cbShare + 1;
+- pShFlShareName = RTMemAllocZ(cbShFlShareName);
+- if (!pShFlShareName)
+- return VERR_NO_MEMORY;
++#define VBOX_INTOPT(optname, val, base) do { \
++ char *ep, *optarg = NULL; \
++ if (vfs_getopt(opts, optname, (void **)&optarg, NULL) == 0) { \
++ if (optarg != NULL && *optarg == '\0') \
++ optarg = NULL; \
++ if (optarg != NULL) \
++ val = strtoul(optarg, &ep, base); \
++ if (optarg == NULL || *ep != '\0') { \
++ struct sbuf *sb = sbuf_new_auto(); \
++ sbuf_printf(sb, "Invalid %s: \"%s\"", optname, \
++ optarg); \
++ sbuf_finish(sb); \
++ vfs_mount_error(mp, sbuf_data(sb)); \
++ sbuf_delete(sb); \
++ return (EINVAL); \
++ } \
++ } \
++} while (0)
+
+- pShFlShareName->u16Length = cbShare;
+- pShFlShareName->u16Size = cbShare + 1;
+- memcpy (pShFlShareName->String.utf8, pszShare, cbShare + 1);
++static int
++vboxfs_node_ctor(void *mem, int size, void *arg, int flags)
++{
++ struct vboxfs_node *node = (struct vboxfs_node *)mem;
+
+- rc = VbglR0SfMapFolder (&g_vboxSFClient, pShFlShareName, &pShFlGlobalInfo->map);
+- RTMemFree(pShFlShareName);
++ node->sf_vnode = NULL;
++ node->sf_vpstate = 0;
+
+- if (RT_FAILURE (rc))
+- {
+- RTMemFree(pShFlGlobalInfo);
+- printf("VbglR0SfMapFolder failed rc=%d\n", rc);
+- return EPROTO;
+- }
++ return (0);
++}
+
+- pShFlGlobalInfo->uid = uid;
+- pShFlGlobalInfo->gid = gid;
++static void
++vboxfs_node_dtor(void *mem, int size, void *arg)
++{
++ struct vboxfs_node *node = (struct vboxfs_node *)mem;
++ node->sf_type = VNON;
++}
+
+- mp->mnt_data = pShFlGlobalInfo;
++static int
++vboxfs_node_init(void *mem, int size, int flags)
++{
++ struct vboxfs_node *node = (struct vboxfs_node *)mem;
++ node->sf_ino = 0;
+
+- /** @todo root vnode. */
++ mtx_init(&node->sf_interlock, "tmpfs node interlock", NULL, MTX_DEF);
+
+- vfs_getnewfsid(mp);
+- vfs_mountedfrom(mp, pszShare);
++ return (0);
++}
+
+- printf("%s: Leave rc=0\n", __FUNCTION__);
++static void
++vboxfs_node_fini(void *mem, int size)
++{
++ struct vboxfs_node *node = (struct vboxfs_node *)mem;
+
+- return 0;
++ mtx_destroy(&node->sf_interlock);
+ }
+
+-static int vboxvfs_unmount(struct mount *mp, int mntflags, struct thread *td)
++static int
++vboxfs_mount(struct mount *mp)
+ {
+- struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp);
+- int rc;
+- int flags = 0;
++ struct vboxfs_mnt *vboxfsmp = NULL;
++ struct vfsoptlist *opts = mp->mnt_optnew;
++ sfp_mount_t *handle = NULL;
++ int readonly = 0;
++ sffs_fsinfo_t fsinfo;
++ int error, share_len;
++ char *share_name;
++ mode_t file_mode = 0, dir_mode = 0;
++ uid_t uid = 0;
++ gid_t gid = 0;
++ struct vboxfs_node *root;
+
+- rc = VbglR0SfUnmapFolder(&g_vboxSFClient, &pShFlGlobalInfo->map);
+- if (RT_FAILURE(rc))
+- printf("Failed to unmap shared folder\n");
++ if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS))
++ return (EOPNOTSUPP);
+
+- if (mntflags & MNT_FORCE)
+- flags |= FORCECLOSE;
++ if (vfs_filteropt(opts, vboxfs_opts)) {
++ vfs_mount_error(mp, "%s", "Invalid option");
++ return (EINVAL);
++ }
+
+- /* There is 1 extra root vnode reference (vnode_root). */
+- rc = vflush(mp, 1, flags, td);
+- if (rc)
+- return rc;
++ VBOX_INTOPT("uid", uid, 10);
++ VBOX_INTOPT("gid", gid, 10);
++ VBOX_INTOPT("file_mode", file_mode, 8);
++ VBOX_INTOPT("dir_mode", dir_mode, 8);
++ VBOX_INTOPT("ro", readonly, 10);
+
++ error = vfs_getopt(opts, "from", (void **)&share_name, &share_len);
++ if (error != 0 || share_len == 0) {
++ vfs_mount_error(mp, "Invalid from");
++ return (EINVAL);
++ }
+
+- RTMemFree(pShFlGlobalInfo);
+- mp->mnt_data = NULL;
++ vboxfsmp = malloc(sizeof(struct vboxfs_mnt), M_VBOXVFS, M_WAITOK | M_ZERO);
++ vboxfsmp->sf_uid = uid;
++ vboxfsmp->sf_gid = gid;
++ vboxfsmp->sf_fmode = file_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
++ vboxfsmp->sf_dmode = dir_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
++ vboxfsmp->sf_ino = 3;
++ vboxfsmp->sf_stat_ttl = 200;
+
+- return 0;
++ /* Invoke Hypervisor mount interface before proceeding */
++ error = sfprov_mount(share_name, &handle);
++ if (error)
++ return (error);
++
++ /* Determine whether the filesystem must be read-only. */
++ error = sfprov_get_fsinfo(handle, &fsinfo);
++ if (error != 0) {
++ sfprov_unmount(handle);
++ return (error);
++ }
++ if (readonly == 0)
++ readonly = (fsinfo.readonly != 0);
++
++ vboxfsmp->sf_handle = handle;
++ vboxfsmp->sf_vfsp = mp;
++
++ vboxfsmp->sf_node_pool = uma_zcreate("VBOXFS node",
++ sizeof(struct vboxfs_node),
++ vboxfs_node_ctor, vboxfs_node_dtor,
++ vboxfs_node_init, vboxfs_node_fini,
++ UMA_ALIGN_PTR, 0);
++
++ /* Allocate the root node. */
++ error = vboxfs_alloc_node(mp, vboxfsmp, "", VDIR, 0,
++ 0, 0755, NULL, &root);
++
++ if (error != 0 || root == NULL) {
++ uma_zdestroy(vboxfsmp->sf_node_pool);
++ free(vboxfsmp, M_VBOXVFS);
++ return error;
++ }
++
++ root->sf_parent = root;
++ vboxfsmp->sf_root = root;
++
++ MNT_ILOCK(mp);
++ mp->mnt_data = vboxfsmp;
++ mp->mnt_stat.f_fsid.val[0] = fsinfo.serial;
++ mp->mnt_stat.f_fsid.val[1] = 0;
++ mp->mnt_flag |= MNT_LOCAL;
++ if (readonly != 0)
++ mp->mnt_flag |= MNT_RDONLY;
++
++ mp->mnt_kern_flag |= MNTK_LOOKUP_SHARED | MNTK_EXTENDED_SHARED;
++ MNT_IUNLOCK(mp);
++ vfs_mountedfrom(mp, share_name);
++
++ return (0);
+ }
+
+-static int vboxvfs_root(struct mount *mp, int flags, struct vnode **vpp, struct thread *td)
++/*
++ * Unmount a shared folder.
++ *
++ * vboxfs_unmount umounts the mounted file system. It return 0
++ * on sucess and any relevant errno on failure.
++ */
++static int
++vboxfs_unmount(struct mount *mp, int mntflags)
+ {
+- int rc = 0;
+- struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp);
+- struct vnode *vp;
++ struct vboxfs_mnt *vboxfsmp;
++ struct thread *td;
++ int error;
++ int flags;
+
+- printf("%s: Enter\n", __FUNCTION__);
++ vboxfsmp = VFSTOVBOXFS(mp);
++ td = curthread;
++ flags = 0;
++ if (mntflags & MNT_FORCE)
++ flags |= FORCECLOSE;
+
+- vp = pShFlGlobalInfo->vnode_root;
+- VREF(vp);
++ error = vflush(mp, 0, flags, td);
++ if (error)
++ return (error);
+
+- vn_lock(vp, flags | LK_RETRY, td);
+- *vpp = vp;
++ /* Invoke Hypervisor unmount interface before proceeding */
++ error = sfprov_unmount(vboxfsmp->sf_handle);
++ if (error != 0) {
++ /* TBD anything here? */
++ }
+
+- printf("%s: Leave\n", __FUNCTION__);
++ uma_zdestroy(vboxfsmp->sf_node_pool);
+
+- return rc;
++ free(vboxfsmp, M_VBOXVFS);
++ MNT_ILOCK(mp);
++ mp->mnt_data = NULL;
++ mp->mnt_flag &= ~MNT_LOCAL;
++ MNT_IUNLOCK(mp);
++
++ return (0);
+ }
+
+-static int vboxvfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg, struct thread *td)
++static int
++vboxfs_root(struct mount *mp, int flags, struct vnode **vpp)
+ {
+- return EOPNOTSUPP;
++ int error;
++ error = vboxfs_alloc_vp(mp, VFSTOVBOXFS(mp)->sf_root, flags, vpp);
++
++ if (!error)
++ (*vpp)->v_vflag |= VV_ROOT;
++
++ return error;
+ }
+
+-int vboxvfs_init(struct vfsconf *vfsp)
++/*
++ * Do operation associated with quotas, not supported
++ */
++static int
++vboxfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg
++#if __FreeBSD_version >= 1400018
++ , bool *mp_busy
++#endif
++ )
+ {
+- int rc;
++ return (EOPNOTSUPP);
++}
+
+- /* Initialize the R0 guest library. */
+- rc = VbglR0SfInit();
+- if (RT_FAILURE(rc))
+- return ENXIO;
++/*
++ * Initialize the filesystem globals.
++ */
++static int
++vboxfs_init(struct vfsconf *vfsp)
++{
++ int error;
+
+- /* Connect to the host service. */
+- rc = VbglR0SfConnect(&g_vboxSFClient);
+- if (RT_FAILURE(rc))
+- {
+- printf("Failed to get connection to host! rc=%d\n", rc);
+- VbglR0SfTerm();
+- return ENXIO;
+- }
++ DROP_GIANT();
+
+- rc = VbglR0SfSetUtf8(&g_vboxSFClient);
+- if (RT_FAILURE (rc))
+- {
+- printf("VbglR0SfSetUtf8 failed, rc=%d\n", rc);
+- VbglR0SfDisconnect(&g_vboxSFClient);
+- VbglR0SfTerm();
+- return EPROTO;
+- }
++ sfprov = sfprov_connect(SFPROV_VERSION);
++ if (sfprov == NULL) {
++ printf("%s: couldn't connect to sf provider", __func__);
++ return (ENODEV);
++ }
+
+- printf("Successfully loaded shared folder module\n");
++ error = sfprov_set_show_symlinks();
++ if (error != 0)
++ printf("%s: host unable to show symlinks, error=%d\n",
++ __func__, error);
+
+- return 0;
++ PICKUP_GIANT();
++ return (0);
+ }
+
+-int vboxvfs_uninit(struct vfsconf *vfsp)
++/*
++ * Undo the work of vboxfs_init().
++ */
++static int
++vboxfs_uninit(struct vfsconf *vfsp)
+ {
+- VbglR0SfDisconnect(&g_vboxSFClient);
+- VbglR0SfTerm();
+
+- return 0;
++ DROP_GIANT();
++ sfprov_disconnect();
++ PICKUP_GIANT();
++ return (0);
+ }
+
+-int vboxvfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
++/*
++ * Get filesystem statistics.
++ */
++static int
++vboxfs_statfs(struct mount *mp, struct statfs *sbp)
+ {
+- return 0;
++ struct vboxfs_mnt *vboxfsmp;
++ sffs_fsinfo_t fsinfo;
++ int error;
++
++ vboxfsmp = VFSTOVBOXFS(mp);
++
++ error = sfprov_get_fsinfo(vboxfsmp->sf_handle, &fsinfo);
++ if (error != 0)
++ return (error);
++
++ sbp->f_iosize = fsinfo.blksize;
++ sbp->f_bsize = fsinfo.blksize;
++
++ sbp->f_bfree = fsinfo.blksavail;
++ sbp->f_bavail = fsinfo.blksavail;
++ sbp->f_files = fsinfo.blksavail / 4; /* some kind of reasonable value */
++ sbp->f_ffree = fsinfo.blksavail / 4;
++
++ sbp->f_blocks = fsinfo.blksused + sbp->f_bavail;
++ sbp->f_fsid.val[0] = mp->mnt_stat.f_fsid.val[0];
++ sbp->f_fsid.val[1] = mp->mnt_stat.f_fsid.val[1];
++ sbp->f_namemax = fsinfo.maxnamesize;
++
++ return (0);
+ }
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__vnops.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__vnops.c
new file mode 100644
index 000000000000..edd43c7c03c7
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_freebsd_vboxvfs_vboxvfs__vnops.c
@@ -0,0 +1,1543 @@
+--- src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vnops.c.orig 2023-07-12 15:59:35 UTC
++++ src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vnops.c
+@@ -14,228 +14,1416 @@
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+-
+-#include "vboxvfs.h"
+ #include <sys/param.h>
+ #include <sys/systm.h>
+ #include <sys/namei.h>
+ #include <sys/kernel.h>
+-#include <sys/proc.h>
++#include <sys/types.h>
++#include <sys/malloc.h>
++#include <sys/stat.h>
+ #include <sys/bio.h>
++#include <sys/conf.h>
+ #include <sys/buf.h>
+-#include <sys/fcntl.h>
++#include <sys/iconv.h>
+ #include <sys/mount.h>
+-#include <sys/unistd.h>
+ #include <sys/vnode.h>
+-#include <sys/limits.h>
+-#include <sys/lockf.h>
+-#include <sys/stat.h>
++#include <sys/dirent.h>
++#include <sys/queue.h>
++#include <sys/unistd.h>
++#include <sys/endian.h>
+
+-#include <vm/vm.h>
+-#include <vm/vm_extern.h>
++#include <vm/uma.h>
+
++#include "vboxvfs.h"
++
++#if __FreeBSD_version < 1300063
++#define VN_IS_DOOMED(vp) (((vp)->v_iflag & VI_DOOMED) != 0)
++#endif
++
+ /*
+ * Prototypes for VBOXVFS vnode operations
+ */
+-static vop_create_t vboxvfs_create;
+-static vop_mknod_t vboxvfs_mknod;
+-static vop_open_t vboxvfs_open;
+-static vop_close_t vboxvfs_close;
+-static vop_access_t vboxvfs_access;
+-static vop_getattr_t vboxvfs_getattr;
+-static vop_setattr_t vboxvfs_setattr;
+-static vop_read_t vboxvfs_read;
+-static vop_write_t vboxvfs_write;
+-static vop_fsync_t vboxvfs_fsync;
+-static vop_remove_t vboxvfs_remove;
+-static vop_link_t vboxvfs_link;
+-static vop_lookup_t vboxvfs_lookup;
+-static vop_rename_t vboxvfs_rename;
+-static vop_mkdir_t vboxvfs_mkdir;
+-static vop_rmdir_t vboxvfs_rmdir;
+-static vop_symlink_t vboxvfs_symlink;
+-static vop_readdir_t vboxvfs_readdir;
+-static vop_strategy_t vboxvfs_strategy;
+-static vop_print_t vboxvfs_print;
+-static vop_pathconf_t vboxvfs_pathconf;
+-static vop_advlock_t vboxvfs_advlock;
+-static vop_getextattr_t vboxvfs_getextattr;
+-static vop_ioctl_t vboxvfs_ioctl;
+-static vop_getpages_t vboxvfs_getpages;
+-static vop_inactive_t vboxvfs_inactive;
+-static vop_putpages_t vboxvfs_putpages;
+-static vop_reclaim_t vboxvfs_reclaim;
++static vop_create_t vboxfs_create;
++static vop_open_t vboxfs_open;
++static vop_close_t vboxfs_close;
++static vop_access_t vboxfs_access;
++static vop_getattr_t vboxfs_getattr;
++static vop_setattr_t vboxfs_setattr;
++static vop_read_t vboxfs_read;
++static vop_readlink_t vboxfs_readlink;
++static vop_write_t vboxfs_write;
++static vop_fsync_t vboxfs_fsync;
++static vop_remove_t vboxfs_remove;
++static vop_link_t vboxfs_link;
++static vop_lookup_t vboxfs_lookup;
++static vop_cachedlookup_t vboxfs_cachedlookup;
++static vop_rename_t vboxfs_rename;
++static vop_mkdir_t vboxfs_mkdir;
++static vop_rmdir_t vboxfs_rmdir;
++static vop_symlink_t vboxfs_symlink;
++static vop_readdir_t vboxfs_readdir;
++static vop_print_t vboxfs_print;
++static vop_pathconf_t vboxfs_pathconf;
++static vop_advlock_t vboxfs_advlock;
++static vop_ioctl_t vboxfs_ioctl;
++static vop_inactive_t vboxfs_inactive;
++static vop_reclaim_t vboxfs_reclaim;
++static vop_vptofh_t vboxfs_vptofh;
+
+-struct vop_vector vboxvfs_vnodeops = {
+- .vop_default = &default_vnodeops,
++struct vop_vector vboxfs_vnodeops = {
++ .vop_default = &default_vnodeops,
+
+- .vop_access = vboxvfs_access,
+- .vop_advlock = vboxvfs_advlock,
+- .vop_close = vboxvfs_close,
+- .vop_create = vboxvfs_create,
+- .vop_fsync = vboxvfs_fsync,
+- .vop_getattr = vboxvfs_getattr,
+- .vop_getextattr = vboxvfs_getextattr,
+- .vop_getpages = vboxvfs_getpages,
+- .vop_inactive = vboxvfs_inactive,
+- .vop_ioctl = vboxvfs_ioctl,
+- .vop_link = vboxvfs_link,
+- .vop_lookup = vboxvfs_lookup,
+- .vop_mkdir = vboxvfs_mkdir,
+- .vop_mknod = vboxvfs_mknod,
+- .vop_open = vboxvfs_open,
+- .vop_pathconf = vboxvfs_pathconf,
+- .vop_print = vboxvfs_print,
+- .vop_putpages = vboxvfs_putpages,
+- .vop_read = vboxvfs_read,
+- .vop_readdir = vboxvfs_readdir,
+- .vop_reclaim = vboxvfs_reclaim,
+- .vop_remove = vboxvfs_remove,
+- .vop_rename = vboxvfs_rename,
+- .vop_rmdir = vboxvfs_rmdir,
+- .vop_setattr = vboxvfs_setattr,
+- .vop_strategy = vboxvfs_strategy,
+- .vop_symlink = vboxvfs_symlink,
+- .vop_write = vboxvfs_write,
++ .vop_access = vboxfs_access,
++ .vop_advlock = VOP_EOPNOTSUPP,
++ .vop_close = vboxfs_close,
++ .vop_create = vboxfs_create,
++ .vop_fsync = vboxfs_fsync,
++ .vop_getattr = vboxfs_getattr,
++ .vop_getextattr = VOP_EOPNOTSUPP,
++ .vop_inactive = vboxfs_inactive,
++ .vop_ioctl = vboxfs_ioctl,
++ .vop_link = vboxfs_link,
++ .vop_lookup = vboxfs_lookup,
++ .vop_cachedlookup = vboxfs_cachedlookup,
++ .vop_mkdir = vboxfs_mkdir,
++ .vop_mknod = VOP_EOPNOTSUPP,
++ .vop_open = vboxfs_open,
++ .vop_pathconf = vboxfs_pathconf,
++ .vop_print = vboxfs_print,
++ .vop_read = vboxfs_read,
++ .vop_readdir = vboxfs_readdir,
++ .vop_readlink = vboxfs_readlink,
++ .vop_reclaim = vboxfs_reclaim,
++ .vop_remove = vboxfs_remove,
++ .vop_rename = vboxfs_rename,
++ .vop_rmdir = vboxfs_rmdir,
++ .vop_setattr = vboxfs_setattr,
++ .vop_vptofh = vboxfs_vptofh,
++ .vop_symlink = vboxfs_symlink,
++ .vop_write = vboxfs_write,
++ .vop_bmap = VOP_EOPNOTSUPP
+ };
++#if __FreeBSD_version > 1300068
++VFS_VOP_VECTOR_REGISTER(vboxfs_vnodeops);
++#endif
+
+-static int vboxvfs_access(struct vop_access_args *ap)
++static uint64_t
++vsfnode_cur_time_usec(void)
+ {
+- return 0;
++ struct timeval now;
++
++ getmicrotime(&now);
++
++ return (now.tv_sec*1000 + now.tv_usec);
+ }
+
+-static int vboxvfs_open(struct vop_open_args *ap)
++static int
++vsfnode_stat_cached(struct vboxfs_node *np)
+ {
+- return 0;
++ return (vsfnode_cur_time_usec() - np->sf_stat_time) <
++ np->vboxfsmp->sf_stat_ttl * 1000UL;
+ }
+
+-static int vboxvfs_close(struct vop_close_args *ap)
++static int
++vsfnode_update_stat_cache(struct vboxfs_node *np)
+ {
+- return 0;
++ int error;
++
++ error = sfprov_get_attr(np->vboxfsmp->sf_handle, np->sf_path,
++ &np->sf_stat);
++#if 0
++ if (error == ENOENT)
++ sfnode_make_stale(node);
++#endif
++ if (error == 0)
++ np->sf_stat_time = vsfnode_cur_time_usec();
++
++ return (error);
+ }
+
+-static int vboxvfs_getattr(struct vop_getattr_args *ap)
++/*
++ * Need to clear v_object for insmntque failure.
++ */
++static void
++vboxfs_insmntque_dtr(struct vnode *vp, void *dtr_arg)
+ {
+- return 0;
++
++ // XXX: vboxfs_destroy_vobject(vp, vp->v_object);
++ vp->v_object = NULL;
++ vp->v_data = NULL;
++ vp->v_op = &dead_vnodeops;
++ vgone(vp);
++ vput(vp);
+ }
+
+-static int vboxvfs_setattr(struct vop_setattr_args *ap)
++/*
++ * Allocates a new vnode for the node node or returns a new reference to
++ * an existing one if the node had already a vnode referencing it. The
++ * resulting locked vnode is returned in *vpp.
++ *
++ * Returns zero on success or an appropriate error code on failure.
++ */
++int
++vboxfs_alloc_vp(struct mount *mp, struct vboxfs_node *node, int lkflag,
++ struct vnode **vpp)
+ {
+- return 0;
++ struct vnode *vp;
++ int error;
++
++ error = 0;
++loop:
++ VBOXFS_NODE_LOCK(node);
++loop1:
++ if ((vp = node->sf_vnode) != NULL) {
++ MPASS((node->sf_vpstate & VBOXFS_VNODE_DOOMED) == 0);
++ VI_LOCK(vp);
++ if ((node->sf_type == VDIR && node->sf_parent == NULL) ||
++ (VN_IS_DOOMED(vp) &&
++ (lkflag & LK_NOWAIT) != 0)) {
++ VI_UNLOCK(vp);
++ VBOXFS_NODE_UNLOCK(node);
++ error = ENOENT;
++ vp = NULL;
++ goto out;
++ }
++ if (VN_IS_DOOMED(vp)) {
++ VI_UNLOCK(vp);
++ node->sf_vpstate |= VBOXFS_VNODE_WRECLAIM;
++ while ((node->sf_vpstate & VBOXFS_VNODE_WRECLAIM) != 0) {
++ msleep(&node->sf_vnode, VBOXFS_NODE_MTX(node),
++ 0, "vsfE", 0);
++ }
++ goto loop1;
++ }
++ VBOXFS_NODE_UNLOCK(node);
++#if __FreeBSD_version < 1300109
++ error = vget(vp, lkflag | LK_INTERLOCK, curthread);
++#else
++ error = vget(vp, lkflag | LK_INTERLOCK);
++#endif
++ if (error == ENOENT)
++ goto loop;
++ if (error != 0) {
++ vp = NULL;
++ goto out;
++ }
++
++ /*
++ * Make sure the vnode is still there after
++ * getting the interlock to avoid racing a free.
++ */
++ if (node->sf_vnode == NULL || node->sf_vnode != vp) {
++ vput(vp);
++ goto loop;
++ }
++
++ goto out;
++ }
++
++ if ((node->sf_vpstate & VBOXFS_VNODE_DOOMED) ||
++ (node->sf_type == VDIR && node->sf_parent == NULL)) {
++ VBOXFS_NODE_UNLOCK(node);
++ error = ENOENT;
++ vp = NULL;
++ goto out;
++ }
++
++ /*
++ * otherwise lock the vp list while we call getnewvnode
++ * since that can block.
++ */
++ if (node->sf_vpstate & VBOXFS_VNODE_ALLOCATING) {
++ node->sf_vpstate |= VBOXFS_VNODE_WANT;
++ error = msleep((caddr_t) &node->sf_vpstate,
++ VBOXFS_NODE_MTX(node), PDROP | PCATCH,
++ "vboxfs_alloc_vp", 0);
++ if (error)
++ return error;
++
++ goto loop;
++ } else
++ node->sf_vpstate |= VBOXFS_VNODE_ALLOCATING;
++
++ VBOXFS_NODE_UNLOCK(node);
++
++ /* Get a new vnode and associate it with our node. */
++ error = getnewvnode("vboxfs", mp, &vboxfs_vnodeops, &vp);
++ if (error != 0)
++ goto unlock;
++ MPASS(vp != NULL);
++
++ /* lkflag is ignored, the lock is exclusive */
++ (void) vn_lock(vp, lkflag | LK_RETRY);
++
++ vp->v_data = node;
++ vp->v_type = node->sf_type;
++
++ /* Type-specific initialization. */
++ switch (node->sf_type) {
++ case VBLK:
++ /* FALLTHROUGH */
++ case VCHR:
++ /* FALLTHROUGH */
++ case VLNK:
++ /* FALLTHROUGH */
++ case VSOCK:
++ /* FALLTHROUGH */
++ case VFIFO:
++ /* FALLTHROUGH */
++ case VREG:
++ break;
++ case VDIR:
++ MPASS(node->sf_parent != NULL);
++ if (node->sf_parent == node)
++ vp->v_vflag |= VV_ROOT;
++ break;
++
++ default:
++ panic("vboxfs_alloc_vp: type %p %d", node, (int)node->sf_type);
++ }
++
++ if (vp->v_type != VFIFO)
++ VN_LOCK_ASHARE(vp);
++
++#if __FreeBSD_version < 1400051
++ error = insmntque1(vp, mp, vboxfs_insmntque_dtr, NULL);
++#else
++ error = insmntque(vp, mp);
++#endif
++ if (error) {
++#if __FreeBSD_version >= 1400051
++ vboxfs_insmntque_dtr(vp, NULL);
++#endif
++ vp = NULL;
++ }
++
++unlock:
++ VBOXFS_NODE_LOCK(node);
++
++ MPASS(node->sf_vpstate & VBOXFS_VNODE_ALLOCATING);
++ node->sf_vpstate &= ~VBOXFS_VNODE_ALLOCATING;
++ node->sf_vnode = vp;
++
++ if (node->sf_vpstate & VBOXFS_VNODE_WANT) {
++ node->sf_vpstate &= ~VBOXFS_VNODE_WANT;
++ VBOXFS_NODE_UNLOCK(node);
++ wakeup((caddr_t) &node->sf_vpstate);
++ } else
++ VBOXFS_NODE_UNLOCK(node);
++
++out:
++ *vpp = vp;
++
++#ifdef INVARIANTS
++ if (error == 0) {
++ MPASS(*vpp != NULL && VOP_ISLOCKED(*vpp));
++ VBOXFS_NODE_LOCK(node);
++ MPASS(*vpp == node->sf_vnode);
++ VBOXFS_NODE_UNLOCK(node);
++ }
++#endif
++
++ return error;
+ }
+
+-static int vboxvfs_read(struct vop_read_args *ap)
++/*
++ * Destroys the association between the vnode vp and the node it
++ * references.
++ */
++void
++vboxfs_free_vp(struct vnode *vp)
+ {
+- return 0;
++ struct vboxfs_node *node;
++
++ node = VP_TO_VBOXFS_NODE(vp);
++
++ VBOXFS_NODE_ASSERT_LOCKED(node);
++ node->sf_vnode = NULL;
++ if ((node->sf_vpstate & VBOXFS_VNODE_WRECLAIM) != 0)
++ wakeup(&node->sf_vnode);
++ node->sf_vpstate &= ~VBOXFS_VNODE_WRECLAIM;
++ vp->v_data = NULL;
+ }
+
+-static int vboxvfs_write(struct vop_write_args *ap)
++/*
++ * Allocate new vboxfs_node and vnode for given file
++ */
++static int
++vboxfs_alloc_file(struct vboxfs_mnt *vboxfsmp, const char *fullpath,
++ enum_vtype_t type, mode_t mode, struct vboxfs_node *parent,
++ int lkflag, struct vnode **vpp)
+ {
+- return 0;
++ int error;
++ struct vboxfs_node *unode;
++
++ error = vboxfs_alloc_node(vboxfsmp->sf_vfsp, vboxfsmp, fullpath, type,
++ vboxfsmp->sf_uid, vboxfsmp->sf_gid, mode, parent, &unode);
++
++ if (error)
++ goto out;
++
++ error = vboxfs_alloc_vp(vboxfsmp->sf_vfsp, unode, lkflag, vpp);
++ if (error)
++ vboxfs_free_node(vboxfsmp, unode);
++
++out:
++ return (error);
+ }
+
+-static int vboxvfs_create(struct vop_create_args *ap)
++static int
++vboxfs_vn_get_ino_alloc(struct mount *mp, void *arg, int lkflags,
++ struct vnode **rvp)
+ {
+- return 0;
++
++ return (vboxfs_alloc_vp(mp, arg, lkflags, rvp));
+ }
+
+-static int vboxvfs_remove(struct vop_remove_args *ap)
++/*
++ * Construct a new pathname given an sfnode plus an optional tail
++ * component of length len
++ * This handles ".." and "."
++ */
++static char *
++sfnode_construct_path(struct vboxfs_node *node, char *tail, int len)
+ {
+- return 0;
++ char *p;
++ size_t dstsz;
++
++ if (len <= 2 && tail[0] == '.' && (len == 1 || tail[1] == '.'))
++ panic("construct path for %s", tail);
++ dstsz = strlen(node->sf_path) + 1 + len + 1;
++ p = malloc(dstsz, M_VBOXVFS, M_WAITOK);
++ strcpy(p, node->sf_path);
++ strcat(p, "/");
++ strlcat(p, tail, dstsz);
++ return (p);
+ }
+
+-static int vboxvfs_rename(struct vop_rename_args *ap)
++static int
++vboxfs_access(struct vop_access_args *ap)
+ {
+- return 0;
++ struct vnode *vp = ap->a_vp;
++ accmode_t accmode = ap->a_accmode;
++ struct vboxfs_node *node;
++ int error;
++ mode_t m;
++
++ MPASS(VOP_ISLOCKED(vp));
++
++ node = VP_TO_VBOXFS_NODE(vp);
++
++ if ((accmode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) {
++ switch (vp->v_type) {
++ case VDIR:
++ case VLNK:
++ case VREG:
++ return (EROFS);
++ /* NOT REACHED */
++ default:
++ break;
++ }
++ }
++
++ if (vsfnode_stat_cached(node))
++ error = 0;
++ else
++ error = vsfnode_update_stat_cache(node);
++ m = (error == 0) ? node->sf_stat.sf_mode : 0;
++
++#if __FreeBSD_version < 1300105
++ return (vaccess(vp->v_type, m, node->vboxfsmp->sf_uid,
++ node->vboxfsmp->sf_gid, accmode, ap->a_cred, NULL));
++#else
++ return (vaccess(vp->v_type, m, node->vboxfsmp->sf_uid,
++ node->vboxfsmp->sf_gid, accmode, ap->a_cred));
++#endif
+ }
+
+-static int vboxvfs_link(struct vop_link_args *ap)
++/*
++ * Clears the (cached) directory listing for the node.
++ */
++static void
++vfsnode_clear_dir_list(struct vboxfs_node *np)
+ {
+- return EOPNOTSUPP;
++ while (np->sf_dir_list != NULL) {
++ sffs_dirents_t *next = np->sf_dir_list->sf_next;
++ free(np->sf_dir_list, M_VBOXVFS);
++ np->sf_dir_list = next;
++ }
+ }
+
+-static int vboxvfs_symlink(struct vop_symlink_args *ap)
++static int
++vboxfs_get_sfp_file(struct vboxfs_node *np)
+ {
+- return EOPNOTSUPP;
++ sfp_file_t *fp;
++ int error;
++
++ fp = NULL;
++ VBOXFS_NODE_LOCK(np);
++ for (;;) {
++ if (np->sf_file != NULL) {
++ if (fp != NULL)
++ (void) sfprov_close(fp);
++ np->sf_opencnt++;
++ fp = np->sf_file;
++ break;
++ } else if (fp != NULL) {
++ np->sf_file = fp;
++ KASSERT(np->sf_opencnt == 0,
++ ("np %p opencnt (%d) must be zero.",
++ np, np->sf_opencnt));
++ np->sf_opencnt = 1;
++ break;
++ }
++ VBOXFS_NODE_UNLOCK(np);
++ error = sfprov_open(np->vboxfsmp->sf_handle, np->sf_path, &fp);
++ if (error != 0)
++ return (error);
++ VBOXFS_NODE_LOCK(np);
++ }
++ VBOXFS_NODE_UNLOCK(np);
++
++ return (0);
+ }
+
+-static int vboxvfs_mknod(struct vop_mknod_args *ap)
++static void
++vboxfs_put_sfp_file(struct vboxfs_node *np)
+ {
+- return EOPNOTSUPP;
++ VBOXFS_NODE_LOCK(np);
++ np->sf_opencnt--;
++ if (np->sf_opencnt == 0) {
++ (void) sfprov_close(np->sf_file);
++ np->sf_file = NULL;
++ }
++ VBOXFS_NODE_UNLOCK(np);
+ }
+
+-static int vboxvfs_mkdir(struct vop_mkdir_args *ap)
++static int
++vboxfs_open(struct vop_open_args *ap)
+ {
+- return 0;
++ struct vboxfs_node *np;
++ int error;
++
++ MPASS(VOP_ISLOCKED(vp));
++
++ np = VP_TO_VBOXFS_NODE(ap->a_vp);
++ error = vboxfs_get_sfp_file(np);
++ if (error != 0)
++ goto out;
++
++ vnode_create_vobject(ap->a_vp, 0, ap->a_td);
++out:
++ MPASS(VOP_ISLOCKED(vp));
++
++ return (error);
+ }
+
+-static int vboxvfs_rmdir(struct vop_rmdir_args *ap)
++static void
++vfsnode_invalidate_stat_cache(struct vboxfs_node *np)
+ {
+- return 0;
++ np->sf_stat_time = 0;
+ }
+
+-static int vboxvfs_readdir(struct vop_readdir_args *ap)
++static int
++vboxfs_close(struct vop_close_args *ap)
+ {
+- return 0;
++ struct vnode *vp = ap->a_vp;
++ struct vboxfs_node *np;
++
++ np = VP_TO_VBOXFS_NODE(vp);
++
++ /*
++ * Free the directory entries for the node. We do this on this call
++ * here because the directory node may not become inactive for a long
++ * time after the readdir is over. Case in point, if somebody cd's into
++ * the directory then it won't become inactive until they cd away again.
++ * In such a case we would end up with the directory listing not getting
++ * updated (i.e. the result of 'ls' always being the same) until they
++ * change the working directory.
++ */
++ vfsnode_clear_dir_list(np);
++
++ vfsnode_invalidate_stat_cache(np);
++
++ vboxfs_put_sfp_file(np);
++
++ return (0);
+ }
+
+-static int vboxvfs_fsync(struct vop_fsync_args *ap)
++static int
++vboxfs_getattr(struct vop_getattr_args *ap)
+ {
+- return 0;
++ struct vnode *vp = ap->a_vp;
++ struct vattr *vap = ap->a_vap;
++ struct vboxfs_node *np = VP_TO_VBOXFS_NODE(vp);
++ struct vboxfs_mnt *mp = np->vboxfsmp;
++ mode_t mode;
++ int error = 0;
++
++ mode = 0;
++ vap->va_type = vp->v_type;
++
++ vap->va_nlink = 1; /* number of references to file */
++ vap->va_uid = mp->sf_uid; /* owner user id */
++ vap->va_gid = mp->sf_gid; /* owner group id */
++ vap->va_rdev = NODEV; /* device the special file represents */
++ vap->va_gen = VNOVAL; /* generation number of file */
++ vap->va_flags = 0; /* flags defined for file */
++ vap->va_filerev = 0; /* file modification number */
++ vap->va_vaflags = 0; /* operations flags */
++ vap->va_fileid = np->sf_ino; /* file id */
++ vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
++ if (vap->va_fileid == 0)
++ vap->va_fileid = 2;
++
++ vap->va_atime.tv_sec = VNOVAL;
++ vap->va_atime.tv_nsec = VNOVAL;
++ vap->va_mtime.tv_sec = VNOVAL;
++ vap->va_mtime.tv_nsec = VNOVAL;
++ vap->va_ctime.tv_sec = VNOVAL;
++ vap->va_ctime.tv_nsec = VNOVAL;
++
++ if (!vsfnode_stat_cached(np)) {
++ error = vsfnode_update_stat_cache(np);
++ if (error != 0)
++ goto done;
++ }
++
++ vap->va_atime = np->sf_stat.sf_atime;
++ vap->va_mtime = np->sf_stat.sf_mtime;
++ vap->va_ctime = np->sf_stat.sf_ctime;
++
++ mode = np->sf_stat.sf_mode;
++
++ vap->va_mode = mode;
++ if (S_ISDIR(mode)) {
++ vap->va_type = VDIR; /* vnode type (for create) */
++ vap->va_mode = mp->sf_dmode != 0 ? (mp->sf_dmode & 0777) : vap->va_mode;
++ vap->va_mode &= ~mp->sf_dmask;
++ vap->va_mode |= S_IFDIR;
++ } else if (S_ISREG(mode)) {
++ vap->va_type = VREG;
++ vap->va_mode = mp->sf_fmode != 0 ? (mp->sf_fmode & 0777) : vap->va_mode;
++ vap->va_mode &= ~mp->sf_fmask;
++ vap->va_mode |= S_IFREG;
++ } else if (S_ISFIFO(mode))
++ vap->va_type = VFIFO;
++ else if (S_ISCHR(mode))
++ vap->va_type = VCHR;
++ else if (S_ISBLK(mode))
++ vap->va_type = VBLK;
++ else if (S_ISLNK(mode)) {
++ vap->va_type = VLNK;
++ vap->va_mode = mp->sf_fmode != 0 ? (mp->sf_fmode & 0777) : vap->va_mode;
++ vap->va_mode &= ~mp->sf_fmask;
++ vap->va_mode |= S_IFLNK;
++ } else if (S_ISSOCK(mode))
++ vap->va_type = VSOCK;
++
++ vap->va_size = np->sf_stat.sf_size;
++ vap->va_blocksize = 512;
++ /* bytes of disk space held by file */
++ vap->va_bytes = (np->sf_stat.sf_alloc + 511) / 512;
++
++done:
++ return (error);
+ }
+
+-static int vboxvfs_print (struct vop_print_args *ap)
++static int
++vboxfs_setattr(struct vop_setattr_args *ap)
+ {
+- return 0;
++ struct vnode *vp = ap->a_vp;
++ struct vattr *vap = ap->a_vap;
++ struct vboxfs_node *np = VP_TO_VBOXFS_NODE(vp);
++ int error;
++ mode_t mode;
++
++ mode = vap->va_mode;
++ if (vp->v_type == VREG)
++ mode |= S_IFREG;
++ else if (vp->v_type == VDIR)
++ mode |= S_IFDIR;
++ else if (vp->v_type == VBLK)
++ mode |= S_IFBLK;
++ else if (vp->v_type == VCHR)
++ mode |= S_IFCHR;
++ else if (vp->v_type == VLNK)
++ mode |= S_IFLNK;
++ else if (vp->v_type == VFIFO)
++ mode |= S_IFIFO;
++ else if (vp->v_type == VSOCK)
++ mode |= S_IFSOCK;
++
++ vfsnode_invalidate_stat_cache(np);
++
++ error = sfprov_set_attr(np->vboxfsmp->sf_handle, np->sf_path,
++ mode, vap->va_atime, vap->va_mtime, vap->va_ctime);
++#if 0
++ if (error == ENOENT)
++ sfnode_make_stale(np);
++#endif
++ if (vap->va_size != (u_quad_t)VNOVAL) {
++ switch (vp->v_type) {
++ case VDIR:
++ return (EISDIR);
++ case VLNK:
++ /* FALLTHROUGH */
++ case VREG:
++ error = sfprov_set_size(np->vboxfsmp->sf_handle, np->sf_path, vap->va_size);
++ break;
++ case VCHR:
++ /* FALLTHROUGH */
++ case VBLK:
++ /* FALLTHROUGH */
++ case VSOCK:
++ /* FALLTHROUGH */
++ case VFIFO:
++ /* FALLTHROUGH */
++ case VNON:
++ /* FALLTHROUGH */
++ case VBAD:
++ /* FALLTHROUGH */
++ case VMARKER:
++ return (0);
++ }
++ }
++
++ return (error);
+ }
+
+-static int vboxvfs_pathconf (struct vop_pathconf_args *ap)
++#define blkoff(vboxfsmp, loc) ((loc) & (vboxfsmp)->bmask)
++
++static int
++vboxfs_read(struct vop_read_args *ap)
+ {
+- return 0;
++ struct vnode *vp = ap->a_vp;
++ struct uio *uio = ap->a_uio;
++ struct vboxfs_node *np = VP_TO_VBOXFS_NODE(vp);
++ int error = 0;
++ uint32_t bytes;
++ uint32_t done;
++ unsigned long offset;
++ ssize_t total;
++ void *tmpbuf;
++
++ if (vp->v_type == VDIR)
++ return (EISDIR);
++
++ if (vp->v_type != VREG)
++ return (EINVAL);
++
++ if (uio->uio_offset < 0)
++ return (EINVAL);
++
++ total = uio->uio_resid;
++ if (total == 0)
++ return (0);
++
++ /*
++ * XXXGONZO: this is just to get things working
++ * should be optimized
++ */
++ tmpbuf = contigmalloc(PAGE_SIZE, M_DEVBUF, M_WAITOK, 0, ~0, PAGE_SIZE, 0);
++ if (tmpbuf == 0)
++ return (ENOMEM);
++
++ /*
++ * XXX VOP_READ() is called without VOP_OPEN() on exec case.
++ * We need to ensure the file is opened here.
++ */
++ error = vboxfs_get_sfp_file(np);
++ if (error != 0) /* Maybe removed on the host. */
++ return (EIO);
++ do {
++ offset = uio->uio_offset;
++ done = bytes = min(PAGE_SIZE, uio->uio_resid);
++ error = sfprov_read(np->sf_file, tmpbuf,
++ offset, &done, 0);
++ if (error == 0 && done > 0)
++ error = uiomove(tmpbuf, done, uio);
++ } while (error == 0 && uio->uio_resid > 0 && done > 0);
++ vboxfs_put_sfp_file(np);
++
++ contigfree(tmpbuf, PAGE_SIZE, M_DEVBUF);
++
++ /* a partial read is never an error */
++ if (total != uio->uio_resid)
++ error = 0;
++
++ return (error);
+ }
+
+-static int vboxvfs_strategy (struct vop_strategy_args *ap)
++static int
++vboxfs_write(struct vop_write_args *ap)
+ {
+- return 0;
++ struct vnode *vp = ap->a_vp;
++ struct uio *uio = ap->a_uio;
++ struct vboxfs_node *np = VP_TO_VBOXFS_NODE(vp);
++ int error = 0;
++ uint32_t bytes;
++ uint32_t done;
++ unsigned long offset;
++ ssize_t total;
++ void *tmpbuf;
++
++ if (vp->v_type == VDIR)
++ return (EISDIR);
++
++ if (vp->v_type != VREG)
++ return (EINVAL);
++
++ if (uio->uio_offset < 0)
++ return (EINVAL);
++
++ total = uio->uio_resid;
++ if (total == 0)
++ return (0);
++
++ /*
++ * XXXGONZO: this is just to get things working
++ * should be optimized
++ */
++ tmpbuf = contigmalloc(PAGE_SIZE, M_DEVBUF, M_WAITOK, 0, ~0, PAGE_SIZE, 0);
++ if (tmpbuf == 0)
++ return (ENOMEM);
++
++ do {
++ offset = uio->uio_offset;
++ bytes = min(PAGE_SIZE, uio->uio_resid);
++ error = uiomove(tmpbuf, bytes, uio);
++ if (error != 0)
++ break;
++ done = bytes;
++ error = sfprov_write(np->sf_file, tmpbuf,
++ offset, &done, 0);
++ if (error != 0)
++ break;
++ total -= done;
++ if (done != bytes)
++ uio->uio_resid += bytes - done;
++ } while (error == 0 && uio->uio_resid > 0 && done > 0);
++
++ contigfree(tmpbuf, PAGE_SIZE, M_DEVBUF);
++
++ /* a partial write is never an error */
++ if (total != uio->uio_resid)
++ error = 0;
++
++ return (error);
+ }
+
+-static int vboxvfs_ioctl(struct vop_ioctl_args *ap)
++static int
++vboxfs_create(struct vop_create_args *ap)
+ {
+- return ENOTTY;
++ struct vnode *dvp = ap->a_dvp;
++ struct vnode **vpp = ap->a_vpp;
++ struct componentname *cnp = ap->a_cnp;
++ struct vattr *vap = ap->a_vap;
++ sffs_stat_t stat;
++ char *fullpath = NULL;
++ struct vboxfs_node *dir = VP_TO_VBOXFS_NODE(dvp);
++ int error;
++ struct vboxfs_mnt *vboxfsmp = dir->vboxfsmp;
++
++ MPASS(vap->va_type == VREG);
++
++ fullpath = sfnode_construct_path(dir, cnp->cn_nameptr, cnp->cn_namelen);
++ error = sfprov_create(dir->vboxfsmp->sf_handle, fullpath, vap->va_mode,
++ &stat);
++
++ if (error)
++ goto out;
++
++ error = vboxfs_alloc_file(vboxfsmp, fullpath, VREG, vap->va_mode, dir, cnp->cn_lkflags, vpp);
++
++out:
++ if (fullpath)
++ free(fullpath, M_VBOXVFS);
++
++ if (error == 0) {
++ vfsnode_clear_dir_list(dir);
++ if ((cnp->cn_flags & MAKEENTRY) != 0)
++ cache_enter(dvp, *vpp, cnp);
++ }
++
++ return (error);
+ }
+
+-static int vboxvfs_getextattr(struct vop_getextattr_args *ap)
++static int
++vboxfs_remove(struct vop_remove_args *ap)
+ {
+- return 0;
++ struct vnode *dvp = ap->a_dvp;
++ struct vnode *vp = ap->a_vp;
++ struct vboxfs_node *np, *dir;
++
++ int error;
++
++ MPASS(VOP_ISLOCKED(dvp));
++ MPASS(VOP_ISLOCKED(vp));
++
++ error = 0;
++
++ np = VP_TO_VBOXFS_NODE(vp);
++ dir = VP_TO_VBOXFS_NODE(vp);
++
++ error = sfprov_remove(np->vboxfsmp->sf_handle, np->sf_path,
++ np->sf_type == VLNK);
++
++#if 0
++ if (error == ENOENT || error == 0)
++ sfnode_make_stale(np);
++#endif
++
++ if (error == 0)
++ vfsnode_clear_dir_list(dir);
++
++out:
++ return (error);
+ }
+
+-static int vboxvfs_advlock(struct vop_advlock_args *ap)
++static int
++vboxfs_rename(struct vop_rename_args *ap)
+ {
+- return 0;
++ struct vnode *fvp;
++ struct vnode *fdvp;
++ struct vnode *tvp;
++ struct vnode *tdvp;
++ struct componentname *fcnp;
++ struct componentname *tcnp;
++ struct vboxfs_node *np;
++ int ret;
++
++ fvp = ap->a_fvp;
++ fdvp = ap->a_fdvp;
++ tvp = ap->a_tvp;
++ tdvp = ap->a_tdvp;
++ fcnp = ap->a_fcnp;
++ tcnp = ap->a_tcnp;
++
++ /* Check for cross-device rename */
++ if ((fvp->v_mount != tdvp->v_mount) ||
++ (tvp && (fvp->v_mount != tvp->v_mount))) {
++ ret = EXDEV;
++ goto out;
++ }
++ np = VP_TO_VBOXFS_NODE(fvp);
++ if (np == NULL)
++ return (0);
++ ret = sfprov_rename(np->vboxfsmp->sf_handle,
++ fcnp->cn_nameptr, tcnp->cn_nameptr, fvp->v_type == VDIR);
++out:
++ if (tdvp == tvp)
++ vrele(tdvp);
++ else
++ vput(tdvp);
++ if (tvp)
++ vput(tvp);
++ vrele(fdvp);
++ vrele(fvp);
++ return (ret);
+ }
+
+-static int vboxvfs_lookup(struct vop_lookup_args *ap)
++static int
++vboxfs_link(struct vop_link_args *ap)
+ {
+- return 0;
++ return (EOPNOTSUPP);
+ }
+
+-static int vboxvfs_inactive(struct vop_inactive_args *ap)
++static int
++vboxfs_symlink(struct vop_symlink_args *ap)
+ {
+- return 0;
++ struct vnode *dvp = ap->a_dvp;
++ struct vnode **vpp = ap->a_vpp;
++ struct componentname *cnp = ap->a_cnp;
++ struct vattr *vap = ap->a_vap;
++ sffs_stat_t stat;
++ char *fullpath = NULL;
++ struct vboxfs_node *dir = VP_TO_VBOXFS_NODE(dvp);
++ int error;
++ struct vboxfs_mnt *vboxfsmp = dir->vboxfsmp;
++
++ MPASS(vap->va_type == VLNK);
++
++ fullpath = sfnode_construct_path(dir, cnp->cn_nameptr, cnp->cn_namelen);
++ error = sfprov_symlink(dir->vboxfsmp->sf_handle, fullpath, ap->a_target, &stat);
++
++ if (error)
++ goto out;
++
++ error = vboxfs_alloc_file(vboxfsmp, fullpath, VLNK, vap->va_mode, dir, cnp->cn_lkflags, vpp);
++
++out:
++ if (fullpath)
++ free(fullpath, M_VBOXVFS);
++
++ if (error == 0)
++ vfsnode_clear_dir_list(dir);
++
++ return (error);
+ }
+
+-static int vboxvfs_reclaim(struct vop_reclaim_args *ap)
++static int
++vboxfs_mkdir(struct vop_mkdir_args *ap)
+ {
+- return 0;
++ struct vnode *dvp = ap->a_dvp;
++ struct vnode **vpp = ap->a_vpp;
++ struct componentname *cnp = ap->a_cnp;
++ struct vattr *vap = ap->a_vap;
++ sffs_stat_t stat;
++ char *fullpath = NULL;
++ struct vboxfs_node *dir = VP_TO_VBOXFS_NODE(dvp);
++ int error;
++ struct vboxfs_mnt *vboxfsmp = dir->vboxfsmp;
++
++ MPASS(vap->va_type == VDIR);
++
++ fullpath = sfnode_construct_path(dir, cnp->cn_nameptr, cnp->cn_namelen);
++ error = sfprov_mkdir(dir->vboxfsmp->sf_handle, fullpath, vap->va_mode,
++ &stat);
++
++ if (error)
++ goto out;
++
++ error = vboxfs_alloc_file(vboxfsmp, fullpath, VDIR, vap->va_mode, dir, cnp->cn_lkflags, vpp);
++
++out:
++ if (fullpath)
++ free(fullpath, M_VBOXVFS);
++
++ if (error == 0)
++ vfsnode_clear_dir_list(dir);
++
++ return (error);
+ }
+
+-static int vboxvfs_getpages(struct vop_getpages_args *ap)
++static int
++vboxfs_rmdir(struct vop_rmdir_args *ap)
+ {
+- return 0;
++ struct vnode *dvp = ap->a_dvp;
++ struct vnode *vp = ap->a_vp;
++ struct vboxfs_node *np, *dir;
++
++ int error;
++
++ MPASS(VOP_ISLOCKED(dvp));
++ MPASS(VOP_ISLOCKED(vp));
++
++ error = 0;
++
++ np = VP_TO_VBOXFS_NODE(vp);
++ dir = VP_TO_VBOXFS_NODE(vp);
++
++ error = sfprov_rmdir(np->vboxfsmp->sf_handle, np->sf_path);
++
++#if 0
++ if (error == ENOENT || error == 0)
++ sfnode_make_stale(np);
++#endif
++
++ if (error == 0)
++ vfsnode_clear_dir_list(dir);
++
++out:
++ return (error);
+ }
+
+-static int vboxvfs_putpages(struct vop_putpages_args *ap)
++static int
++vboxfs_readdir(struct vop_readdir_args *ap)
+ {
+- return 0;
++ int *eofp = ap->a_eofflag;
++ struct vnode *vp = ap->a_vp;
++ struct uio *uio = ap->a_uio;
++ struct vboxfs_node *dir = VP_TO_VBOXFS_NODE(vp);
++ struct vboxfs_node *node = NULL;
++ struct sffs_dirent *dirent = NULL;
++ sffs_dirents_t *cur_buf;
++ off_t offset = 0;
++ off_t orig_off = uio->uio_offset;
++ int error = 0;
++ int dummy_eof;
++
++ if (vp->v_type != VDIR)
++ return (ENOTDIR);
++
++ if (eofp == NULL)
++ eofp = &dummy_eof;
++ *eofp = 0;
++
++ /*
++ * Get the directory entry names from the host. This gets all
++ * entries. These are stored in a linked list of sffs_dirents_t
++ * buffers, each of which contains a list of dirent64_t's.
++ */
++ if (dir->sf_dir_list == NULL) {
++ error = sfprov_readdir(dir->vboxfsmp->sf_handle, dir->sf_path,
++ &dir->sf_dir_list);
++ if (error != 0)
++ goto done;
++ }
++
++ /*
++ * Validate and skip to the desired offset.
++ */
++ cur_buf = dir->sf_dir_list;
++ offset = 0;
++
++ while (cur_buf != NULL && offset + cur_buf->sf_len <= uio->uio_offset) {
++ offset += cur_buf->sf_len;
++ cur_buf = cur_buf->sf_next;
++ }
++
++ if (cur_buf == NULL && offset != uio->uio_offset) {
++ error = EINVAL;
++ goto done;
++ }
++
++ if (cur_buf != NULL && offset != uio->uio_offset) {
++ off_t off = offset;
++ int step;
++ dirent = &cur_buf->sf_entries[0];
++
++ while (off < uio->uio_offset) {
++ if (dirent->sf_off == uio->uio_offset)
++ break;
++ step = sizeof(struct sffs_dirent) + dirent->sf_entry.d_reclen;
++ dirent = (struct sffs_dirent *) (((char *) dirent) + step);
++ off += step;
++ }
++
++ if (off >= uio->uio_offset) {
++ error = EINVAL;
++ goto done;
++ }
++ }
++
++ offset = uio->uio_offset - offset;
++
++ /*
++ * Lookup each of the names, so that we have ino's, and copy to
++ * result buffer.
++ */
++ while (cur_buf != NULL) {
++ if (offset >= cur_buf->sf_len) {
++ cur_buf = cur_buf->sf_next;
++ offset = 0;
++ continue;
++ }
++
++ dirent = (struct sffs_dirent *)
++ (((char *) &cur_buf->sf_entries[0]) + offset);
++ if (dirent->sf_entry.d_reclen > uio->uio_resid)
++ break;
++
++ if (strcmp(dirent->sf_entry.d_name, ".") == 0) {
++ node = dir;
++ } else if (strcmp(dirent->sf_entry.d_name, "..") == 0) {
++ node = dir->sf_parent;
++ if (node == NULL)
++ node = dir;
++ } else {
++#if 0
++ node = vsfnode_lookup(dir, dirent->sf_entry.d_name, VNON,
++ 0, &dirent->sf_stat, vsfnode_cur_time_usec(), NULL);
++ if (node == NULL)
++ panic("sffs_readdir() lookup failed");
++#endif
++ }
++
++ if (node)
++ dirent->sf_entry.d_fileno = node->sf_ino;
++ else
++ dirent->sf_entry.d_fileno = 0xdeadbeef;
++
++ error = uiomove(&dirent->sf_entry, dirent->sf_entry.d_reclen, uio);
++ if (error != 0)
++ break;
++
++ uio->uio_offset = dirent->sf_off;
++ offset += sizeof(struct sffs_dirent) + dirent->sf_entry.d_reclen;
++ }
++
++ if (error == 0 && cur_buf == NULL)
++ *eofp = 1;
++done:
++ if (error != 0)
++ uio->uio_offset = orig_off;
++ return (error);
+ }
+
++static int
++vboxfs_readlink(struct vop_readlink_args *v)
++{
++ struct vnode *vp = v->a_vp;
++ struct uio *uio = v->a_uio;
++
++ int error;
++ struct vboxfs_node *np;
++ void *tmpbuf;
++
++ MPASS(uio->uio_offset == 0);
++ MPASS(vp->v_type == VLNK);
++
++ np = VP_TO_VBOXFS_NODE(vp);
++
++ tmpbuf = contigmalloc(MAXPATHLEN, M_DEVBUF, M_WAITOK, 0, ~0, 1, 0);
++ if (tmpbuf == NULL)
++ return (ENOMEM);
++
++ error = sfprov_readlink(np->vboxfsmp->sf_handle, np->sf_path, tmpbuf,
++ MAXPATHLEN);
++ if (error)
++ goto done;
++
++ error = uiomove(tmpbuf, strlen(tmpbuf), uio);
++
++done:
++ if (tmpbuf)
++ contigfree(tmpbuf, MAXPATHLEN, M_DEVBUF);
++ return (error);
++}
++
++static int
++vboxfs_fsync(struct vop_fsync_args *ap)
++{
++ struct vnode *vp;
++ struct vboxfs_node *np;
++ int ret;
++
++ vp = ap->a_vp;
++ np = VP_TO_VBOXFS_NODE(vp);
++ if (np == NULL)
++ return (0);
++ ret = sfprov_fsync(np->sf_file);
++ return (ret);
++}
++
++static int
++vboxfs_print(struct vop_print_args *ap)
++{
++ struct vnode *vp = ap->a_vp;
++ struct vboxfs_node *np;
++
++ np = VP_TO_VBOXFS_NODE(vp);
++
++ if (np == NULL) {
++ printf("No vboxfs_node data\n");
++ return (0);
++ }
++
++ printf("\tpath = %s, parent = %p", np->sf_path,
++ np->sf_parent ? np->sf_parent : NULL);
++ printf("\n");
++ return (0);
++}
++
++static int
++vboxfs_pathconf(struct vop_pathconf_args *ap)
++{
++ register_t *retval = ap->a_retval;
++ int error = 0;
++
++ switch (ap->a_name) {
++ case _PC_LINK_MAX:
++ *retval = 65535;
++ break;
++ case _PC_NAME_MAX:
++ *retval = NAME_MAX;
++ break;
++ case _PC_PATH_MAX:
++ *retval = PATH_MAX;
++ break;
++ default:
++ error = EINVAL;
++ break;
++ }
++ return (error);
++}
++
++/*
++ * File specific ioctls.
++ */
++static int
++vboxfs_ioctl(struct vop_ioctl_args *ap)
++{
++ return (ENOTTY);
++}
++
++/*
++ * Lookup an entry in a directory and create a new vnode if found.
++ */
++static int
++vboxfs_lookup1(struct vnode *dvp, struct vnode **vpp,
++ struct componentname *cnp)
++{
++ char *nameptr = cnp->cn_nameptr; /* the name of the file or directory */
++ struct vnode *tdp = NULL;
++ struct vboxfs_node *node = VP_TO_VBOXFS_NODE(dvp);
++ struct vboxfs_mnt *vboxfsmp = node->vboxfsmp;
++ u_long nameiop = cnp->cn_nameiop;
++ u_long flags = cnp->cn_flags;
++ sffs_stat_t stat;
++ //long namelen;
++ ino_t id = 0;
++ int ltype, type, error = 0;
++ int lkflags = cnp->cn_lkflags;
++ char *fullpath = NULL;
++
++ *vpp = NULLVP;
++ error = ENOENT;
++ if (cnp->cn_flags & ISDOTDOT) {
++ error = vn_vget_ino_gen(dvp, vboxfs_vn_get_ino_alloc,
++ node->sf_parent, cnp->cn_lkflags, vpp);
++ error = ENOENT;
++ if (error != 0)
++ goto out;
++
++ } else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
++ VREF(dvp);
++ *vpp = dvp;
++ error = 0;
++ } else {
++ mode_t m;
++ type = VNON;
++ fullpath = sfnode_construct_path(node, cnp->cn_nameptr, cnp->cn_namelen);
++ error = sfprov_get_attr(node->vboxfsmp->sf_handle,
++ fullpath, &stat);
++ // stat_time = vsfnode_cur_time_usec();
++
++ m = stat.sf_mode;
++ if (error != 0) {
++ /* The entry was not found in the directory.
++ * This is OK if we are creating or renaming an
++ * entry and are working on the last component of
++ * the path name. */
++ if ((cnp->cn_flags & ISLASTCN) &&
++ (cnp->cn_nameiop == CREATE || \
++ cnp->cn_nameiop == RENAME ||
++ (cnp->cn_nameiop == DELETE &&
++ cnp->cn_flags & DOWHITEOUT &&
++ cnp->cn_flags & ISWHITEOUT))) {
++ error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred,
++#if __FreeBSD_version < 1400037
++ cnp->cn_thread);
++#else
++ curthread);
++#endif
++ if (error != 0)
++ goto out;
++
++#if __FreeBSD_version < 1400068
++ /* Keep the component name in the buffer for
++ * future uses. */
++ cnp->cn_flags |= SAVENAME;
++#endif
++
++ error = EJUSTRETURN;
++ } else
++ error = ENOENT;
++ }
++ else {
++ if (S_ISDIR(m))
++ type = VDIR;
++ else if (S_ISREG(m))
++ type = VREG;
++ else if (S_ISLNK(m))
++ type = VLNK;
++ error = vboxfs_alloc_file(vboxfsmp, fullpath, type, 0755, node, cnp->cn_lkflags, vpp);
++ }
++ }
++
++ if ((cnp->cn_flags & MAKEENTRY) != 0)
++ cache_enter(dvp, *vpp, cnp);
++out:
++ if (fullpath)
++ free(fullpath, M_VBOXVFS);
++
++ return (error);
++}
++
++static int
++vboxfs_cachedlookup(struct vop_cachedlookup_args *ap)
++{
++ return (vboxfs_lookup1(ap->a_dvp, ap->a_vpp, ap->a_cnp));
++}
++
++static int
++vboxfs_lookup(struct vop_lookup_args *ap)
++{
++ struct vnode *dvp = ap->a_dvp;
++ struct componentname *cnp = ap->a_cnp;
++ struct vboxfs_node *np = VP_TO_VBOXFS_NODE(dvp);
++ struct timespec mtime;
++ int flags = cnp->cn_flags;
++ int error;
++
++ if (dvp->v_type != VDIR)
++ return (ENOTDIR);
++
++ if ((flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
++ (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
++ return (EROFS);
++
++ error = vn_dir_check_exec(dvp, cnp);
++ if (error != 0)
++ return (error);
++
++ /* Check if the directory is unmodified on the host. */
++ mtime = np->sf_stat.sf_mtime;
++ error = vsfnode_update_stat_cache(np);
++ if (error == 0) {
++ if (mtime.tv_sec == np->sf_stat.sf_mtime.tv_sec &&
++ mtime.tv_nsec == np->sf_stat.sf_mtime.tv_nsec)
++ return (vfs_cache_lookup(ap));
++ }
++
++ cache_purge(dvp);
++
++ return (vboxfs_lookup1(ap->a_dvp, ap->a_vpp, ap->a_cnp));
++}
++
++static int
++vboxfs_inactive(struct vop_inactive_args *ap)
++{
++ return (0);
++}
++
++static int
++vboxfs_reclaim(struct vop_reclaim_args *ap)
++{
++ struct vnode *vp;
++ struct vboxfs_node *node;
++ struct vboxfs_mnt *vboxfsmp;
++
++ vp = ap->a_vp;
++ node = VP_TO_VBOXFS_NODE(vp);
++ vboxfsmp = node->vboxfsmp;
++
++ vnode_destroy_vobject(vp);
++ vp->v_object = NULL;
++ cache_purge(vp);
++
++ VBOXFS_NODE_LOCK(node);
++ VBOXFS_ASSERT_ELOCKED(node);
++ vboxfs_free_vp(vp);
++
++ /* If the node referenced by this vnode was deleted by the user,
++ * we must free its associated data structures (now that the vnode
++ * is being reclaimed). */
++ if ((node->sf_vpstate & VBOXFS_VNODE_ALLOCATING) == 0) {
++ node->sf_vpstate = VBOXFS_VNODE_DOOMED;
++ VBOXFS_NODE_UNLOCK(node);
++ vboxfs_free_node(vboxfsmp, node);
++ } else
++ VBOXFS_NODE_UNLOCK(node);
++
++ MPASS(vp->v_data == NULL);
++
++ return (0);
++}
++
++static int
++vboxfs_vptofh(struct vop_vptofh_args *ap)
++{
++
++ return (EOPNOTSUPP);
++}
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_x11_vboxmouse_Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_x11_vboxmouse_Makefile.kmk
new file mode 100644
index 000000000000..afb19c804d7a
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Additions_x11_vboxmouse_Makefile.kmk
@@ -0,0 +1,29 @@
+--- src/VBox/Additions/x11/vboxmouse/Makefile.kmk.orig 2019-01-25 18:24:30 UTC
++++ src/VBox/Additions/x11/vboxmouse/Makefile.kmk
+@@ -227,10 +227,22 @@ endif # neq ($(KBUILD_TARGET),linux)
+
+
+ ifdef VBOX_USE_SYSTEM_XORG_HEADERS
+- # As vboxmouse_drv is not needed at all for X.Org Server 1.7 and later do not
+- # build it in this case.
+- DLLS := $(filter-out vboxmouse_drv_%,$(DLLS))
+- SYSMODS := $(filter-out vboxmouse_drv%,$(SYSMODS))
++ ifeq ($(KBUILD_TARGET),freebsd)
++ DLLS += vboxmouse_drv_system
++ vboxmouse_drv_system_TEMPLATE = VBOXGUESTR3XORGMOD
++ vboxmouse_drv_system_DEFS := $(vboxmouse_drv_70_DEFS) NO_ANSIC
++ vboxmouse_drv_system_INCS := \
++ /usr/local/include/pixman-1 \
++ /usr/local/include/xorg \
++ $(PATH_SUB_CURRENT)
++ vboxmouse_drv_system_SOURCES = \
++ vboxmouse.c
++ else
++ # As vboxmouse_drv is not needed at all for X.Org Server 1.7 and later do not
++ # build it in this case.
++ DLLS := $(filter-out vboxmouse_drv_%,$(DLLS))
++ SYSMODS := $(filter-out vboxmouse_drv%,$(SYSMODS))
++ endif
+ endif
+
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA.cpp
new file mode 100644
index 000000000000..5ce43e5ce2d0
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA.cpp
@@ -0,0 +1,20 @@
+--- src/VBox/Devices/Graphics/DevVGA-SVGA.cpp.orig 2025-04-14 17:55:41 UTC
++++ src/VBox/Devices/Graphics/DevVGA-SVGA.cpp
+@@ -178,7 +178,7 @@
+ # ifdef RT_OS_DARWIN
+ # include "DevVGA-SVGA3d-cocoa.h"
+ # endif
+-# ifdef RT_OS_LINUX
++# if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
+ # ifdef IN_RING3
+ # include "DevVGA-SVGA3d-glLdr.h"
+ # endif
+@@ -7685,7 +7685,7 @@ static void vmsvgaR3PowerOnDevice(PPDMDEVINS pDevIns,
+ }
+ # endif
+
+-# if defined(VBOX_WITH_VMSVGA3D) && defined(RT_OS_LINUX)
++# if defined(VBOX_WITH_VMSVGA3D) && (defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX))
+ if (pThis->svga.f3DEnabled)
+ {
+ /* The FIFO thread may use X API for accelerated screen output. */
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-dx-dx11.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-dx-dx11.cpp
new file mode 100644
index 000000000000..3a0a22e2ef76
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-dx-dx11.cpp
@@ -0,0 +1,11 @@
+--- src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx-dx11.cpp.orig 2025-05-12 17:49:35 UTC
++++ src/VBox/Devices/Graphics/DevVGA-SVGA3d-dx-dx11.cpp
+@@ -3363,7 +3363,7 @@ static DECLCALLBACK(int) vmsvga3dBackInit(PPDMDEVINS p
+ RT_NOREF(pDevIns, pThis);
+
+ int rc;
+-#ifdef RT_OS_LINUX /** @todo Remove, this is currently needed for loading the X11 library in order to call XInitThreads(). */
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) /** @todo Remove, this is currently needed for loading the X11 library in order to call XInitThreads(). */
+ rc = glLdrInit(pDevIns);
+ if (RT_FAILURE(rc))
+ {
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-glLdr.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-glLdr.cpp
new file mode 100644
index 000000000000..e9ae5d0b71f9
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-glLdr.cpp
@@ -0,0 +1,29 @@
+--- src/VBox/Devices/Graphics/DevVGA-SVGA3d-glLdr.cpp.orig 2025-04-14 17:55:41 UTC
++++ src/VBox/Devices/Graphics/DevVGA-SVGA3d-glLdr.cpp
+@@ -196,7 +196,7 @@ int glLdrInit(PPDMDEVINS pDevIns)
+ pfn_wglDeleteContext = 0;
+ pfn_wglMakeCurrent = 0;
+ pfn_wglShareLists = 0;
+-#elif defined(RT_OS_LINUX)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
+ pfn_XConfigureWindow = 0;
+ pfn_XCloseDisplay = 0;
+ pfn_XCreateColormap = 0;
+@@ -306,7 +306,7 @@ int glLdrInit(PPDMDEVINS pDevIns)
+ GLGETPROC_(wglDeleteContext, "");
+ GLGETPROC_(wglMakeCurrent, "");
+ GLGETPROC_(wglShareLists, "");
+-#elif defined(RT_OS_LINUX)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
+ X11GETPROC_(XConfigureWindow);
+ X11GETPROC_(XCloseDisplay);
+ X11GETPROC_(XCreateColormap);
+@@ -407,7 +407,7 @@ int glLdrInit(PPDMDEVINS pDevIns)
+ GLGETPROC_(glVertexPointer, "");
+ GLGETPROC_(glViewport, "");
+
+-#ifdef RT_OS_LINUX
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
+ XInitThreads();
+ #endif
+ return VINF_SUCCESS;
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-glLdr.h b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-glLdr.h
new file mode 100644
index 000000000000..52d86f546033
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-glLdr.h
@@ -0,0 +1,11 @@
+--- src/VBox/Devices/Graphics/DevVGA-SVGA3d-glLdr.h.orig 2025-04-14 17:55:41 UTC
++++ src/VBox/Devices/Graphics/DevVGA-SVGA3d-glLdr.h
+@@ -346,7 +346,7 @@ GLPFN BOOL (WINAPI *pfn_wglShareLists)(HGLRC, HGLRC);
+ GLPFN BOOL (WINAPI *pfn_wglShareLists)(HGLRC, HGLRC);
+ #define wglShareLists pfn_wglShareLists
+
+-#elif defined(RT_OS_LINUX)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
+ /*
+ * GLX
+ */
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-ogl.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-ogl.cpp
new file mode 100644
index 000000000000..74106db011ff
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Graphics_DevVGA-SVGA3d-ogl.cpp
@@ -0,0 +1,56 @@
+--- src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp.orig 2025-04-14 17:55:42 UTC
++++ src/VBox/Devices/Graphics/DevVGA-SVGA3d-ogl.cpp
+@@ -1198,7 +1198,7 @@ static DECLCALLBACK(int) vmsvga3dBackTerminate(PVGASTA
+ RTSemEventDestroy(pState->WndRequestSem);
+ #elif defined(RT_OS_DARWIN)
+
+-#elif defined(RT_OS_LINUX)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
+ /* signal to the thread that it is supposed to exit */
+ pState->bTerminate = true;
+ /* wait for it to terminate */
+@@ -3216,7 +3216,7 @@ static DECLCALLBACK(int) vmsvga3dBackGenerateMipmaps(P
+ }
+
+
+-#ifdef RT_OS_LINUX
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
+ /**
+ * X11 event handling thread.
+ *
+@@ -3246,7 +3246,7 @@ static DECLCALLBACK(int) vmsvga3dXEventThread(RTTHREAD
+ }
+ return VINF_SUCCESS;
+ }
+-#endif // RT_OS_LINUX
++#endif // RT_OS_FREEBSD || RT_OS_LINUX
+
+
+ /**
+@@ -3484,7 +3484,7 @@ int vmsvga3dContextDefineOgl(PVGASTATECC pThisCC, uint
+ return VINF_SUCCESS;
+ }
+
+-#if defined(RT_OS_LINUX)
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
+ /*
+ * HW accelerated graphics output.
+ */
+@@ -3976,7 +3976,7 @@ static DECLCALLBACK(int) vmsvga3dBackSurfaceBlitToScre
+ return VINF_SUCCESS;
+ }
+
+-#else /* !RT_OS_LINUX */
++#else /* !RT_OS_FREEBSD && !RT_OS_LINUX */
+
+ static DECLCALLBACK(int) vmsvga3dBackDefineScreen(PVGASTATE pThis, PVGASTATECC pThisCC, VMSVGASCREENOBJECT *pScreen)
+ {
+@@ -4096,7 +4096,7 @@ static int vmsvga3dContextDestroyOgl(PVGASTATECC pThis
+ AssertRC(rc);
+ #elif defined(RT_OS_DARWIN)
+ vmsvga3dCocoaDestroyViewAndContext(pContext->cocoaView, pContext->cocoaContext);
+-#elif defined(RT_OS_LINUX)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
+ glXMakeCurrent(pState->display, None, NULL);
+ glXDestroyContext(pState->display, pContext->glxContext);
+ XDestroyWindow(pState->display, pContext->window);
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Makefile.kmk
new file mode 100644
index 000000000000..021d004d5a00
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_Makefile.kmk
@@ -0,0 +1,44 @@
+--- src/VBox/Devices/Makefile.kmk.orig 2024-10-10 20:29:17.000000000 +0200
++++ src/VBox/Devices/Makefile.kmk 2024-12-27 13:26:17.132294000 +0100
+@@ -132,6 +132,7 @@
+ VBoxDDU_LDFLAGS.darwin += -framework IOKit
+ endif
+
++ VBoxDDU_LDFLAGS.freebsd = $(VBOX_GCC_NO_UNDEFINED)
+ VBoxDDU_LDFLAGS.linux = $(VBOX_GCC_NO_UNDEFINED)
+ $(call VBOX_SET_VER_INFO_DLL,VBoxDDU,VirtualBox VMM Devices and Drivers Utilities)
+
+@@ -286,6 +287,7 @@
+ -framework SystemConfiguration \
+ -framework AVFoundation \
+ -framework Foundation
++ VBoxDD_LDFLAGS.freebsd = $(VBOX_GCC_NO_UNDEFINED)
+ VBoxDD_LDFLAGS.linux = $(VBOX_GCC_NO_UNDEFINED)
+
+ # --- Tracing bits. ---
+@@ -331,7 +333,7 @@
+ Graphics/DevVGA-SVGA-cmd.cpp
+ endif
+ ifdef VBOX_WITH_VMSVGA3D
+- if1of ($(KBUILD_TARGET), linux win)
++ if1of ($(KBUILD_TARGET), linux win freebsd)
+ # Dynamically load 3D library (opengl32, libGL).
+ # This is a temporary solution. In future the 3D backend will be in a separate library.
+ VBOX_WITH_VMSVGA3D_DYNAMIC_LOAD = 1
+@@ -390,6 +392,7 @@
+ Graphics/DevVGA-SVGA3d-glLdr.cpp
+ else
+ VBoxDD_LIBS.linux += X11 GL
++ VBoxDD_LIBS.freebsd += X11 GL
+ VBoxDD_LIBS.win += $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/Opengl32.lib
+ endif
+ VBoxDD_LDFLAGS.darwin += -framework OpenGL
+@@ -1701,6 +1704,8 @@
+ VBoxSVGA3D_INCS = $(VBOX_GRAPHICS_INCS)
+ VBoxSVGA3D_INCS.win := \
+ Graphics/shaderlib/libWineStub/include
++ VBoxSVGA3D_INCS.freebsd := \
++ Graphics/shaderlib/wine/include
+ VBoxSVGA3D_INCS.linux := \
+ Graphics/shaderlib/wine/include
+ VBoxSVGA3D_INCS.darwin := \
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_PC_ipxe_Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_PC_ipxe_Makefile.kmk
new file mode 100644
index 000000000000..d59d98da3b83
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_PC_ipxe_Makefile.kmk
@@ -0,0 +1,29 @@
+--- src/VBox/Devices/PC/ipxe/Makefile.kmk.orig 2025-01-21 19:56:40.000000000 +0700
++++ src/VBox/Devices/PC/ipxe/Makefile.kmk 2025-01-23 00:47:50.818978000 +0700
+@@ -45,7 +45,7 @@
+ iPxeBiosBin_CLEAN = \
+ $(iPxeBiosBin_0_OUTDIR)/iPxeBiosBin.c \
+
+-if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), darwin.amd64 darwin.arm64 linux.arm64 os2.x86 solaris.amd64 win.amd64 win.arm64)
++if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), darwin.amd64 darwin.arm64 linux.arm64 os2.x86 solaris.amd64 win.amd64 win.arm64 linux.amd64 freebsd.amd64)
+ $$(iPxeBiosBin_0_OUTDIR)/iPxeBiosBin.c: $(PATH_SUB_CURRENT)/iPxeBiosBin.rom $(VBOX_BIN2C) | $$(dir $$@)
+ $(call MSG_TOOL,bin2c,iPxeBiosBin,$<,$@)
+ $(QUIET)$(VBOX_BIN2C) -min 32 -max 56 -mask 0x1ff -export NetBiosBinary $< $@
+@@ -131,7 +131,7 @@
+ -falign-loops=1 \
+ -Os \
+ -falign-functions=1 \
+- -mpreferred-stack-boundary=2 \
++ -mstack-alignment=2 \
+ -mregparm=3 \
+ -mrtd \
+ -freg-struct-return \
+@@ -154,7 +154,7 @@
+ -falign-jumps=1 \
+ -falign-loops=1 \
+ -falign-functions=1 \
+- -mpreferred-stack-boundary=2 \
++ -mstack-alignment=2 \
+ -mregparm=3 \
+ -mrtd \
+ -freg-struct-return \
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_USB_USBProxyDevice-freebsd.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_USB_USBProxyDevice-freebsd.cpp
new file mode 100644
index 000000000000..045e328d5c48
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Devices_USB_USBProxyDevice-freebsd.cpp
@@ -0,0 +1,11 @@
+--- src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp.orig 2024-01-11 12:23:15 UTC
++++ src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp
+@@ -57,7 +57,7 @@
+ #include "../USBProxyDevice.h"
+
+ /** Maximum endpoints supported. */
+-#define USBFBSD_MAXENDPOINTS 127
++#define USBFBSD_MAXENDPOINTS 126
+ #define USBFBSD_MAXFRAMES 56
+
+ /** This really needs to be defined in vusb.h! */
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_ExtPacks_VNC_VBoxVNC.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_ExtPacks_VNC_VBoxVNC.cpp
new file mode 100644
index 000000000000..f364e261f40b
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_ExtPacks_VNC_VBoxVNC.cpp
@@ -0,0 +1,58 @@
+--- src/VBox/ExtPacks/VNC/VBoxVNC.cpp.orig 2024-01-11 12:24:04 UTC
++++ src/VBox/ExtPacks/VNC/VBoxVNC.cpp
+@@ -45,7 +45,7 @@
+
+ #ifdef LIBVNCSERVER_IPv6
+ // enable manually!
+-// #define VBOX_USE_IPV6
++#define VBOX_USE_IPV6
+ #endif
+
+
+@@ -421,7 +421,7 @@ DECLCALLBACK(int) VNCServerImpl::VRDEEnableConnections
+
+ // get address
+ char *pszTCPAddress = (char *)RTMemTmpAllocZ(VNC_ADDRESS_OPTION_MAX);
+- rc = instance->mCallbacks->VRDECallbackProperty(instance->mCallback,
++ int rc = instance->mCallbacks->VRDECallbackProperty(instance->mCallback,
+ VRDE_QP_NETWORK_ADDRESS,
+ pszTCPAddress,
+ VNC_ADDRESS_OPTION_MAX,
+@@ -582,19 +582,35 @@ DECLCALLBACK(int) VNCServerImpl::VRDEEnableConnections
+ pszServerAddress6 = szIPv6ListenAll;
+ }
+
+- if (pszVNCPort4 && uServerPort4 == 0)
++ if (strlen(pszVNCPort4) > 0 && uServerPort4 == 0)
+ {
+ rc = RTStrToUInt32Ex(pszVNCPort4, NULL, 10, &uServerPort4);
+ if (!RT_SUCCESS(rc) || uServerPort4 > 65535)
+ uServerPort4 = 0;
+ }
+
+- if (pszVNCPort6 && uServerPort6 == 0)
++ if (strlen(pszVNCPort6) > 0 && uServerPort6 == 0)
+ {
+ rc = RTStrToUInt32Ex(pszVNCPort6, NULL, 10, &uServerPort6);
+ if (!RT_SUCCESS(rc) || uServerPort6 > 65535)
+ uServerPort6 = 0;
+ }
++
++/* Backward compatibility with set port in "TCP/Ports" only { */
++ if (uServerPort4 == 0 && strlen(pszTCPPort) > 0)
++ {
++ rc = RTStrToUInt32Ex(pszTCPPort, NULL, 10, &uServerPort4);
++ if (!RT_SUCCESS(rc) || uServerPort4 > 65535)
++ uServerPort4 = 0;
++ }
++
++ if (uServerPort6 == 0 && strlen(pszTCPPort) > 0)
++ {
++ rc = RTStrToUInt32Ex(pszTCPPort, NULL, 10, &uServerPort6);
++ if (!RT_SUCCESS(rc) || uServerPort6 > 65535)
++ uServerPort6 = 0;
++ }
++/* } */
+
+ if (uServerPort4 == 0 || uServerPort6 == 0)
+ vncServer->autoPort = 1;
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Frontends_VBoxHeadless_VBoxHeadless.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Frontends_VBoxHeadless_VBoxHeadless.cpp
new file mode 100644
index 000000000000..ca03e57922b4
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Frontends_VBoxHeadless_VBoxHeadless.cpp
@@ -0,0 +1,11 @@
+--- src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp.orig 2024-12-26 22:32:13.106542000 +0100
++++ src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp 2024-12-26 22:32:32.805126000 +0100
+@@ -61,7 +61,7 @@
+ # include <iprt/process.h>
+ #endif
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+ # include <cerrno>
+ #endif
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Frontends_VBoxManage_VBoxManageModifyVM.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Frontends_VBoxManage_VBoxManageModifyVM.cpp
new file mode 100644
index 000000000000..fc1639b58302
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Frontends_VBoxManage_VBoxManageModifyVM.cpp
@@ -0,0 +1,29 @@
+--- src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp.orig 2022-10-06 19:10:28.000000000 +0200
++++ src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp 2024-12-26 16:08:30.624183000 +0100
+@@ -170,7 +170,7 @@
+ MODIFYVM_UARTMODE,
+ MODIFYVM_UARTTYPE,
+ MODIFYVM_UART,
+-#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
+ MODIFYVM_LPTMODE,
+ MODIFYVM_LPT,
+ #endif
+@@ -382,7 +382,7 @@
+ OPT2("--uart-mode", "--uartmode", MODIFYVM_UARTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
+ OPT2("--uart-type", "--uarttype", MODIFYVM_UARTTYPE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
+ OPT1("--uart", MODIFYVM_UART, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
+-#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
++#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS) || defined(RT_OS_FREEBSD)
+ OPT2("--lpt-mode", "--lptmode", MODIFYVM_LPTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
+ OPT1("--lpt", MODIFYVM_LPT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX),
+ #endif
+@@ -2496,7 +2496,7 @@
+ break;
+ }
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
+ case MODIFYVM_LPTMODE:
+ {
+ ComPtr<IParallelPort> lpt;
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_SUPDrv.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_SUPDrv.cpp
new file mode 100644
index 000000000000..4139a88a9929
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_SUPDrv.cpp
@@ -0,0 +1,13 @@
+--- src/VBox/HostDrivers/Support/SUPDrv.cpp.orig 2024-12-27 08:34:02.157677000 +0100
++++ src/VBox/HostDrivers/Support/SUPDrv.cpp 2024-12-27 08:34:25.419134000 +0100
+@@ -317,8 +317,8 @@
+ SUPEXP_STK_BACK( 2, SUPR0PageFree),
+ SUPEXP_STK_BACK( 6, SUPR0PageMapKernel),
+ SUPEXP_STK_BACK( 6, SUPR0PageProtect),
+-#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+- SUPEXP_STK_OKAY( 2, SUPR0HCPhysToVirt), /* only-linux, only-solaris, only-freebsd */
++#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
++ SUPEXP_STK_OKAY( 2, SUPR0HCPhysToVirt), /* only-linux, only-solaris */
+ #endif
+ SUPEXP_STK_BACK( 2, SUPR0PrintfV),
+ SUPEXP_STK_BACK( 1, SUPR0GetSessionGVM),
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_SUPDrvInternal.h b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_SUPDrvInternal.h
new file mode 100644
index 000000000000..7376ad6fbddd
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_SUPDrvInternal.h
@@ -0,0 +1,11 @@
+--- src/VBox/HostDrivers/Support/SUPDrvInternal.h.orig 2021-01-07 15:41:25 UTC
++++ src/VBox/HostDrivers/Support/SUPDrvInternal.h
+@@ -217,7 +217,7 @@
+ # define SUPDRV_WITHOUT_MSR_PROBER
+ #endif
+
+-#if 1
++#if 0
+ /** @def SUPDRV_USE_TSC_DELTA_THREAD
+ * Use a dedicated kernel thread to service TSC-delta measurement requests.
+ * @todo Test on servers with many CPUs and sockets. */
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_Makefile b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_Makefile
new file mode 100644
index 000000000000..a3b6a032b529
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_Makefile
@@ -0,0 +1,30 @@
+--- src/VBox/HostDrivers/Support/freebsd/Makefile.orig 2025-01-21 19:58:52.000000000 +0700
++++ src/VBox/HostDrivers/Support/freebsd/Makefile 2025-03-22 22:28:21.276497000 +0700
+@@ -93,6 +93,7 @@
+ assert.c \
+ handletable.c \
+ handletablectx.c \
++ handletablesimple.c \
+ once.c \
+ term.c \
+ thread.c
+@@ -117,7 +118,8 @@
+ strprintf2-ellipsis.c \
+ strtonum.c \
+ memchr.c \
+- stringalloc.c
++ stringalloc.c \
++ utf-8.c
+
+ .PATH: ${.CURDIR}/common/rand
+ SRCS += \
+@@ -163,7 +165,8 @@
+ rtStrFormatKernelAddress-generic.c \
+ errvars-generic.c \
+ mppresent-generic.c \
+- timer-generic.c
++ timer-generic.c \
++ system-page-size-generic.c
+
+ .PATH: ${.CURDIR}/r0drv
+ SRCS += \
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c
new file mode 100644
index 000000000000..7faa07739f14
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPDrv-freebsd.c
@@ -0,0 +1,234 @@
+--- src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c.orig 2025-01-21 14:06:14 UTC
++++ src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c
+@@ -44,9 +44,13 @@
+ #include <sys/fcntl.h>
+ #include <sys/conf.h>
+ #include <sys/uio.h>
++#include <vm/vm.h>
+ #include <vm/pmap.h> /* for pmap_map() */
++#include <sys/mutex.h>
++#include <sys/smp.h> /* mp_maxcpus */
+
+ #include "../SUPDrvInternal.h"
++#include "freebsd/the-freebsd-kernel.h"
+ #include <VBox/version.h>
+ #include <iprt/initterm.h>
+ #include <iprt/string.h>
+@@ -58,7 +62,15 @@
+ #include <iprt/alloc.h>
+ #include <iprt/err.h>
+ #include <iprt/asm.h>
++#include <iprt/x86.h>
+
++
++#ifdef VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV
++# include <machine/cpufunc.h>
++# include <machine/md_var.h>
++# include <machine/specialreg.h>
++#endif
++
+ #ifdef VBOX_WITH_HARDENING
+ # define VBOXDRV_PERM 0600
+ #else
+@@ -77,7 +89,9 @@ static d_ioctl_t VBoxDrvFreeBSDIOCtl;
+ static d_open_t VBoxDrvFreeBSDOpenSys;
+ static void vboxdrvFreeBSDDtr(void *pvData);
+ static d_ioctl_t VBoxDrvFreeBSDIOCtl;
++static d_ioctl_t VBoxDrvFreeBSDIOCtlSMAP;
+ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd);
++static bool VBoxDrvFreeBSDCpuHasSMAP(void);
+
+
+ /*********************************************************************************************************************************
+@@ -94,7 +108,8 @@ static moduledata_t g_VBoxDrvFreeBSDModule =
+ };
+
+ /** Declare the module as a pseudo device. */
+-DECLARE_MODULE(vboxdrv, g_VBoxDrvFreeBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY);
++#define KERNEL_RELBRANCHEND (roundup(__FreeBSD_version, 500) - 1)
++DECLARE_MODULE_WITH_MAXVER(vboxdrv, g_VBoxDrvFreeBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY, KERNEL_RELBRANCHEND);
+ MODULE_VERSION(vboxdrv, 1);
+
+ /**
+@@ -141,6 +156,13 @@ static int VBoxDrvFreeBSDModuleEvent(struct module *pM
+ static int VBoxDrvFreeBSDModuleEvent(struct module *pMod, int enmEventType, void *pvArg)
+ {
+ int rc;
++
++ /* Refuse to load if mp_maxcpus is wrong */
++ if (MAXCPU != mp_maxcpus) {
++ printf("vboxdrv: MAXCPU != mp_maxcpus (%d != %d)\n", MAXCPU, mp_maxcpus);
++ return EINVAL;
++ }
++
+ switch (enmEventType)
+ {
+ case MOD_LOAD:
+@@ -183,6 +205,13 @@ static int VBoxDrvFreeBSDLoad(void)
+ rc = supdrvInitDevExt(&g_VBoxDrvFreeBSDDevExt, sizeof(SUPDRVSESSION));
+ if (RT_SUCCESS(rc))
+ {
++ if (VBoxDrvFreeBSDCpuHasSMAP())
++ {
++ LogRel(("disabling SMAP for VBoxDrvFreeBSDIOCtl\n"));
++ g_VBoxDrvFreeBSDChrDevSwSys.d_ioctl = VBoxDrvFreeBSDIOCtlSMAP;
++ g_VBoxDrvFreeBSDChrDevSwUsr.d_ioctl = VBoxDrvFreeBSDIOCtlSMAP;
++ }
++
+ /*
+ * Configure character devices. Add symbolic links for compatibility.
+ */
+@@ -322,7 +351,45 @@ static int VBoxDrvFreeBSDIOCtl(struct cdev *pDev, u_lo
+ return VBoxDrvFreeBSDIOCtlSlow(pSession, ulCmd, pvData, pTd);
+ }
+
++/**
++ * Alternative Device I/O Control entry point on hosts with SMAP support.
++ *
++ * @returns depends...
++ * @param pDev The device.
++ * @param ulCmd The command.
++ * @param pvData Pointer to the data.
++ * @param fFile The file descriptor flags.
++ * @param pTd The calling thread.
++ */
++static int VBoxDrvFreeBSDIOCtlSMAP(struct cdev *pDev, u_long ulCmd, caddr_t pvData, int fFile, struct thread *pTd)
++{
++ /*
++ * Allow VBox R0 code to touch R3 memory. Setting the AC bit disables the
++ * SMAP check.
++ */
++ RTCCUINTREG fSavedEfl = ASMAddFlags(X86_EFL_AC);
+
++ int rc = VBoxDrvFreeBSDIOCtl(pDev, ulCmd, pvData, fFile, pTd);
++
++#ifdef VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV
++ /*
++ * Before we restore AC and the rest of EFLAGS, check if the IOCtl handler code
++ * accidentially modified it or some other important flag.
++ */
++ if (RT_UNLIKELY( (ASMGetFlags() & (X86_EFL_AC | X86_EFL_IF | X86_EFL_DF | X86_EFL_IOPL))
++ != ((fSavedEfl & (X86_EFL_AC | X86_EFL_IF | X86_EFL_DF | X86_EFL_IOPL)) | X86_EFL_AC) ))
++ {
++ char szTmp[48];
++ RTStrPrintf(szTmp, sizeof(szTmp), "ulCmd=%#x: %#x->%#x!", ulCmd, (uint32_t)fSavedEfl, (uint32_t)ASMGetFlags());
++ supdrvBadContext(&g_VBoxDrvFreeBSDDevExt, "SUPDrv-freebsd.c", __LINE__, szTmp);
++ }
++#endif
++
++ ASMSetFlags(fSavedEfl);
++ return rc;
++}
++
++
+ /**
+ * Deal with the 'slow' I/O control requests.
+ *
+@@ -372,11 +439,10 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
+ */
+ SUPREQHDR Hdr;
+ pvUser = *(void **)pvData;
+- int rc = copyin(pvUser, &Hdr, sizeof(Hdr));
+- if (RT_UNLIKELY(rc))
++ if (RT_FAILURE(RTR0MemUserCopyFrom(&Hdr, (uintptr_t)pvUser, sizeof(Hdr))))
+ {
+- OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,Hdr,) -> %#x; ulCmd=%#lx\n", pvUser, rc, ulCmd));
+- return rc;
++ OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,Hdr,); ulCmd=%#lx\n", pvUser, ulCmd));
++ return EFAULT;
+ }
+ if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
+ {
+@@ -401,13 +467,12 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
+ OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: failed to allocate buffer of %d bytes; ulCmd=%#lx\n", cbReq, ulCmd));
+ return ENOMEM;
+ }
+- rc = copyin(pvUser, pHdr, Hdr.cbIn);
+- if (RT_UNLIKELY(rc))
++ if (RT_FAILURE(RTR0MemUserCopyFrom(pHdr, (uintptr_t)pvUser, Hdr.cbIn)))
+ {
+- OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,%p,%#x) -> %#x; ulCmd=%#lx\n",
+- pvUser, pHdr, Hdr.cbIn, rc, ulCmd));
++ OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyin(%p,%p,%#x); ulCmd=%#lx\n",
++ pvUser, pHdr, Hdr.cbIn, ulCmd));
+ RTMemTmpFree(pHdr);
+- return rc;
++ return EFAULT;
+ }
+ if (Hdr.cbIn < cbReq)
+ RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn);
+@@ -435,9 +500,8 @@ static int VBoxDrvFreeBSDIOCtlSlow(PSUPDRVSESSION pSes
+ OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cbReq, ulCmd));
+ cbOut = cbReq;
+ }
+- rc = copyout(pHdr, pvUser, cbOut);
+- if (RT_UNLIKELY(rc))
+- OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyout(%p,%p,%#x) -> %d; uCmd=%#lx!\n", pHdr, pvUser, cbOut, rc, ulCmd));
++ if (RT_FAILURE(RTR0MemUserCopyTo((uintptr_t)pvUser, pHdr, cbOut)))
++ OSDBGPRINT(("VBoxDrvFreeBSDIOCtlSlow: copyout(%p,%p,%#x); uCmd=%#lx!\n", pHdr, pvUser, cbOut, ulCmd));
+
+ Log(("VBoxDrvFreeBSDIOCtlSlow: returns %d / %d ulCmd=%lx\n", 0, pHdr->rc, ulCmd));
+
+@@ -540,8 +604,7 @@ bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void)
+
+ bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void)
+ {
+- /** @todo verify this. */
+- return false;
++ return true;
+ }
+
+
+@@ -637,31 +700,44 @@ int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu,
+ #endif /* SUPDRV_WITH_MSR_PROBER */
+
+
+-#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64)
+-SUPR0DECL(int) SUPR0HCPhysToVirt(RTHCPHYS HCPhys, void **ppv)
++/**
++ * Check if the CPU has SMAP support.
++ */
++static bool VBoxDrvFreeBSDCpuHasSMAP(void)
+ {
+- AssertReturn(!(HCPhys & PAGE_OFFSET_MASK), VERR_INVALID_POINTER);
+- AssertReturn(HCPhys != NIL_RTHCPHYS, VERR_INVALID_POINTER);
+- *ppv = (void *)(uintptr_t)pmap_map(NULL, HCPhys, (HCPhys | PAGE_OFFSET_MASK) + 1, VM_PROT_WRITE | VM_PROT_READ);
+- return VINF_SUCCESS;
+-}
++#ifdef VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV
++ if ((cpu_stdext_feature & CPUID_STDEXT_SMAP) != 0)
++ return true;
+ #endif
++ return false;
++}
+
+
+ SUPR0DECL(int) SUPR0PrintfV(const char *pszFormat, va_list va)
+ {
+ char szMsg[256];
++ IPRT_FREEBSD_SAVE_EFL_AC();
++
+ RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, va);
+ szMsg[sizeof(szMsg) - 1] = '\0';
+
+ printf("%s", szMsg);
++
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return 0;
+ }
+
+
+ SUPR0DECL(uint32_t) SUPR0GetKernelFeatures(void)
+ {
+- return 0;
++ uint32_t fFlags = 0;
++#ifdef VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV
++ if (g_VBoxDrvFreeBSDChrDevSwSys.d_ioctl == VBoxDrvFreeBSDIOCtlSMAP)
++ fFlags |= SUPKERNELFEATURES_SMAP;
++ else
++ Assert(!(ASMGetCR4() & X86_CR4_SMAP));
++#endif
++ return fFlags;
+ }
+
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPLib-freebsd.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPLib-freebsd.cpp
new file mode 100644
index 000000000000..95cbe0e2a32c
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_SUPLib-freebsd.cpp
@@ -0,0 +1,11 @@
+--- src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp.orig 2024-10-10 20:31:28.000000000 +0200
++++ src/VBox/HostDrivers/Support/freebsd/SUPLib-freebsd.cpp 2024-11-17 18:27:46.400938000 +0100
+@@ -88,7 +88,7 @@
+ /*
+ * Try open the BSD device.
+ */
+- const char * const *pszDeviceNm = fFlags & SUPR3INIT_F_UNRESTRICTED ? DEVICE_NAME_SYS : DEVICE_NAME_USR;
++ const char * pszDeviceNm = fFlags & SUPR3INIT_F_UNRESTRICTED ? DEVICE_NAME_SYS : DEVICE_NAME_USR;
+ int hDevice = open(pszDeviceNm, O_RDWR, 0);
+ if (hDevice < 0)
+ {
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_files__vboxdrv b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_files__vboxdrv
new file mode 100644
index 000000000000..c5abc9bfadd1
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_Support_freebsd_files__vboxdrv
@@ -0,0 +1,34 @@
+--- src/VBox/HostDrivers/Support/freebsd//files_vboxdrv.orig 2025-01-21 19:58:53.000000000 +0700
++++ src/VBox/HostDrivers/Support/freebsd//files_vboxdrv 2025-03-17 00:31:16.880317000 +0700
+@@ -71,6 +71,7 @@
+ ${PATH_ROOT}/include/iprt/stdarg.h=>include/iprt/stdarg.h \
+ ${PATH_ROOT}/include/iprt/stdint.h=>include/iprt/stdint.h \
+ ${PATH_ROOT}/include/iprt/string.h=>include/iprt/string.h \
++ ${PATH_ROOT}/include/iprt/system.h=>include/iprt/system.h \
+ ${PATH_ROOT}/include/iprt/thread.h=>include/iprt/thread.h \
+ ${PATH_ROOT}/include/iprt/time.h=>include/iprt/time.h \
+ ${PATH_ROOT}/include/iprt/timer.h=>include/iprt/timer.h \
+@@ -133,6 +134,7 @@
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/handletable.cpp=>common/misc/handletable.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/handletable.h=>common/misc/handletable.h \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/handletablectx.cpp=>common/misc/handletablectx.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/handletablesimple.cpp=>common/misc/handletablesimple.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/once.cpp=>common/misc/once.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/term.cpp=>common/misc/term.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/misc/thread.cpp=>common/misc/thread.c \
+@@ -154,6 +156,7 @@
+ ${PATH_ROOT}/src/VBox/Runtime/common/string/strprintf2-ellipsis.cpp=>common/string/strprintf2-ellipsis.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/string/strtonum.cpp=>common/string/strtonum.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/string/memchr.cpp=>common/string/memchr.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/utf-8.cpp=>common/string/utf-8.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/string/stringalloc.cpp=>common/string/stringalloc.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/rand/rand.cpp=>common/rand/rand.c \
+ ${PATH_ROOT}/src/VBox/Runtime/common/rand/randadv.cpp=>common/rand/randadv.c \
+@@ -200,6 +203,7 @@
+ ${PATH_ROOT}/src/VBox/Runtime/generic/RTMpOnPair-generic.cpp=>generic/RTMpOnPair-generic.c \
+ ${PATH_ROOT}/src/VBox/Runtime/generic/errvars-generic.cpp=>generic/errvars-generic.c \
+ ${PATH_ROOT}/src/VBox/Runtime/generic/mppresent-generic.cpp=>generic/mppresent-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/system-page-size-generic.cpp=>generic/system-page-size-generic.c \
+ ${PATH_ROOT}/src/VBox/Runtime/generic/timer-generic.cpp=>generic/timer-generic.c \
+ ${PATH_ROOT}/src/VBox/Runtime/generic/uuid-generic.cpp=>generic/uuid-generic.c \
+ ${PATH_ROOT}/src/VBox/Runtime/r0drv/alloc-r0drv.cpp=>r0drv/alloc-r0drv.c \
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetAdp_freebsd_Makefile b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetAdp_freebsd_Makefile
new file mode 100644
index 000000000000..e94dc6f85e27
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetAdp_freebsd_Makefile
@@ -0,0 +1,11 @@
+--- src/VBox/HostDrivers/VBoxNetAdp/freebsd/Makefile.orig 2019-05-13 13:33:07 UTC
++++ src/VBox/HostDrivers/VBoxNetAdp/freebsd/Makefile
+@@ -26,7 +26,7 @@
+
+ KMOD = vboxnetadp
+
+-CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -Iinclude -I. -Ir0drv -w -DVBOX_WITH_HARDENING -DVIMAGE
++CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING -DVBOX_WITH_64_BITS_GUESTS -DVIMAGE -Iinclude -I. -Ir0drv -w
+
+ .if (${MACHINE_ARCH} == "i386")
+ CFLAGS += -DRT_ARCH_X86
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetAdp_freebsd_VBoxNetAdp-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetAdp_freebsd_VBoxNetAdp-freebsd.c
new file mode 100644
index 000000000000..8da432449fe1
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetAdp_freebsd_VBoxNetAdp-freebsd.c
@@ -0,0 +1,147 @@
+--- src/VBox/HostDrivers/VBoxNetAdp/freebsd/VBoxNetAdp-freebsd.c.orig 2024-01-11 12:25:08 UTC
++++ src/VBox/HostDrivers/VBoxNetAdp/freebsd/VBoxNetAdp-freebsd.c
+@@ -216,7 +216,11 @@ static void VBoxNetAdpFreeBSDNetinit(void *priv)
+ PVBOXNETADP pThis = priv;
+ struct ifnet *ifp = pThis->u.s.ifp;
+
++#if __FreeBSD_version >= 1500000
++ if_setdrvflagbits(ifp, IFF_DRV_RUNNING, 0);
++#else
+ ifp->if_drv_flags |= IFF_DRV_RUNNING;
++#endif
+ }
+
+ /**
+@@ -226,25 +230,46 @@ static void VBoxNetAdpFreeBSDNetstart(struct ifnet *if
+ */
+ static void VBoxNetAdpFreeBSDNetstart(struct ifnet *ifp)
+ {
++#if __FreeBSD_version >= 1500000
++ PVBOXNETADP pThis = if_getsoftc(ifp);
++#else
+ PVBOXNETADP pThis = ifp->if_softc;
++#endif
+ struct mbuf *m;
+
++#if __FreeBSD_version >= 1500000
++ if ((if_getdrvflags(ifp) & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING)
++#else
+ if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING)
++#endif
+ return;
+
++#if __FreeBSD_version >= 1500000
++ if_setdrvflagbits(ifp, IFF_DRV_OACTIVE, 0);
++ while (!if_sendq_empty(ifp))
++#else
+ ifp->if_drv_flags |= IFF_DRV_OACTIVE;
+ while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
++#endif
+ {
+ #if __FreeBSD_version >= 1100036
+ if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1);
+ #else
+ ifp->if_opackets++;
+ #endif
++#if __FreeBSD_version >= 1500000
++ m = if_dequeue(ifp);
++#else
+ IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
++#endif
+ BPF_MTAP(ifp, m);
+ m_freem(m);
+ }
++#if __FreeBSD_version >= 1500000
++ if_setdrvflagbits(ifp, 0, IFF_DRV_OACTIVE);
++#else
+ ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
++#endif
+ }
+
+ /**
+@@ -257,6 +282,18 @@ static int VBoxNetAdpFreeBSDNetioctl(struct ifnet *ifp
+ switch (cmd)
+ {
+ case SIOCSIFFLAGS:
++#if __FreeBSD_version >= 1500000
++ if (if_getflags(ifp) & IFF_UP)
++ {
++ if (!(if_getdrvflags(ifp) & IFF_DRV_RUNNING))
++ if_init(ifp, if_getsoftc(ifp));
++ }
++ else
++ {
++ if (if_getdrvflags(ifp) & IFF_DRV_RUNNING)
++ if_setdrvflagbits(ifp, 0, IFF_DRV_RUNNING);
++ }
++#else
+ if (ifp->if_flags & IFF_UP)
+ {
+ if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
+@@ -267,6 +304,7 @@ static int VBoxNetAdpFreeBSDNetioctl(struct ifnet *ifp
+ if (ifp->if_drv_flags & IFF_DRV_RUNNING)
+ ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+ }
++#endif
+ break;
+ case SIOCGIFMEDIA:
+ {
+@@ -301,7 +339,11 @@ int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac
+
+ int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac)
+ {
++#if __FreeBSD_version >= 1500000
++ if_t ifp;
++#else
+ struct ifnet *ifp;
++#endif
+
+ VBOXCURVNET_SET_FROM_UCRED();
+ ifp = if_alloc(IFT_ETHER);
+@@ -309,6 +351,16 @@ int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac
+ return VERR_NO_MEMORY;
+
+ if_initname(ifp, VBOXNETADP_NAME, pThis->iUnit);
++#if __FreeBSD_version >= 1500000
++ if_setsoftc(ifp, pThis);
++ if_setmtu(ifp, ETHERMTU);
++ if_setflagbits(ifp, IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST, 0);
++ if_setioctlfn(ifp, VBoxNetAdpFreeBSDNetioctl);
++ if_setstartfn(ifp, VBoxNetAdpFreeBSDNetstart);
++ if_setinitfn(ifp, VBoxNetAdpFreeBSDNetinit);
++ if_setsendqlen(ifp, IFQ_MAXLEN);
++ if_setsendqready(ifp);
++#else
+ ifp->if_softc = pThis;
+ ifp->if_mtu = ETHERMTU;
+ ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
+@@ -318,10 +370,17 @@ int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac
+ IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
+ ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
+ IFQ_SET_READY(&ifp->if_snd);
++#endif
+ ether_ifattach(ifp, (void *)pMac);
++#if __FreeBSD_version >= 1500000
++ (void)if_setbaudrate(ifp, 0);
++
++ strncpy(pThis->szName, if_name(ifp), VBOXNETADP_MAX_NAME_LEN);
++#else
+ ifp->if_baudrate = 0;
+
+ strncpy(pThis->szName, ifp->if_xname, VBOXNETADP_MAX_NAME_LEN);
++#endif
+ pThis->u.s.ifp = ifp;
+ VBOXCURVNET_RESTORE();
+ return 0;
+@@ -332,7 +391,11 @@ void vboxNetAdpOsDestroy(PVBOXNETADP pThis)
+ struct ifnet *ifp;
+
+ ifp = pThis->u.s.ifp;
++#if __FreeBSD_version >= 1500000
++ VBOXCURVNET_SET(if_getvnet(ifp));
++#else
+ VBOXCURVNET_SET(ifp->if_vnet);
++#endif
+ ether_ifdetach(ifp);
+ if_free(ifp);
+ VBOXCURVNET_RESTORE();
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_Makefile.kmk
new file mode 100644
index 000000000000..9c7ab624c52a
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_Makefile.kmk
@@ -0,0 +1,11 @@
+--- src/VBox/HostDrivers/VBoxNetFlt/Makefile.kmk.orig 2019-05-13 13:33:07 UTC
++++ src/VBox/HostDrivers/VBoxNetFlt/Makefile.kmk
+@@ -565,7 +565,7 @@ $(PATH_OUT)/opt_netgraph.h:
+ $(QUIET)$(RM) -f -- $@
+ $(QUIET)$(CP) -f $< $@
+ ifndef VBOX_WITH_HARDENING
+- $(QUIET)$(SED) -e "s;VBOX_WITH_HARDENING;;g" --output $@.tmp $@
++ $(QUIET)$(SED) -e "s;-DVBOX_WITH_HARDENING;;g" --output $@.tmp $@
+ ${QUIET}$(MV) -f $@.tmp $@
+ endif
+ ifndef VBOX_WITH_NETFLT_VIMAGE
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_freebsd_Makefile b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_freebsd_Makefile
new file mode 100644
index 000000000000..e819561ab9a8
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_freebsd_Makefile
@@ -0,0 +1,11 @@
+--- src/VBox/HostDrivers/VBoxNetFlt/freebsd/Makefile.orig 2019-05-13 13:33:07 UTC
++++ src/VBox/HostDrivers/VBoxNetFlt/freebsd/Makefile
+@@ -26,7 +26,7 @@
+
+ KMOD = vboxnetflt
+
+-CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -Iinclude -I. -Ir0drv -w -DVBOX_WITH_HARDENING -DVIMAGE
++CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING -DVBOX_WITH_64_BITS_GUESTS -DVIMAGE -Iinclude -I. -Ir0drv -w
+
+ .if (${MACHINE_ARCH} == "i386")
+ CFLAGS += -DRT_ARCH_X86
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_freebsd_VBoxNetFlt-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_freebsd_VBoxNetFlt-freebsd.c
new file mode 100644
index 000000000000..6e3d40a42e43
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_VBoxNetFlt_freebsd_VBoxNetFlt-freebsd.c
@@ -0,0 +1,471 @@
+--- src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c.orig 2024-01-11 12:25:08 UTC
++++ src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c
+@@ -52,6 +52,7 @@
+ #include <net/if_dl.h>
+ #include <net/if_types.h>
+ #include <net/ethernet.h>
++#include <net/if_vlan_var.h>
+
+ #include <netgraph/ng_message.h>
+ #include <netgraph/netgraph.h>
+@@ -73,6 +74,7 @@
+
+ #define VBOXNETFLT_OS_SPECFIC 1
+ #include "../VBoxNetFltInternal.h"
++#include "freebsd/the-freebsd-kernel.h"
+
+ static int vboxnetflt_modevent(struct module *, int, void *);
+ static ng_constructor_t ng_vboxnetflt_constructor;
+@@ -149,6 +151,7 @@ MODULE_DEPEND(ng_vboxnetflt, vboxdrv, 1, 1, 1);
+ */
+ MODULE_VERSION(vboxnetflt, 1);
+ MODULE_DEPEND(ng_vboxnetflt, vboxdrv, 1, 1, 1);
++MODULE_DEPEND(ng_vboxnetflt, ng_ether, 1, 1, 1);
+
+ /**
+ * The (common) global data.
+@@ -181,8 +184,6 @@ static int vboxnetflt_modevent(struct module *pMod, in
+ printf("vboxNetFltInitGlobalsAndIdc failed %d\n", rc);
+ return RTErrConvertToErrno(rc);
+ }
+- /* No MODULE_VERSION in ng_ether so we can't MODULE_DEPEND it */
+- kern_kldload(curthread, "ng_ether", NULL);
+ break;
+
+ case MOD_UNLOAD:
+@@ -334,12 +335,20 @@ static int ng_vboxnetflt_rcvdata(hook_p hook, item_p i
+ {
+ const node_p node = NG_HOOK_NODE(hook);
+ PVBOXNETFLTINS pThis = NG_NODE_PRIVATE(node);
++#if __FreeBSD_version >= 1500000
++ if_t ifp = pThis->u.s.ifp;
++#else
+ struct ifnet *ifp = pThis->u.s.ifp;
++#endif
+ struct mbuf *m;
+ struct m_tag *mtag;
+ bool fActive;
+
++#if __FreeBSD_version >= 1500000
++ VBOXCURVNET_SET(if_getvnet(ifp));
++#else
+ VBOXCURVNET_SET(ifp->if_vnet);
++#endif
+ fActive = vboxNetFltTryRetainBusyActive(pThis);
+
+ NGI_GET_M(item, m);
+@@ -361,7 +370,14 @@ static int ng_vboxnetflt_rcvdata(hook_p hook, item_p i
+ {
+ if (mtag != NULL || !fActive)
+ {
++#if __FreeBSD_version >= 1300049
++ struct epoch_tracker et;
++ NET_EPOCH_ENTER(et);
++#endif
+ ether_demux(ifp, m);
++#if __FreeBSD_version >= 1300049
++ NET_EPOCH_EXIT(et);
++#endif
+ if (fActive)
+ vboxNetFltRelease(pThis, true /*fBusy*/);
+ VBOXCURVNET_RESTORE();
+@@ -433,12 +449,22 @@ static void vboxNetFltFreeBSDinput(void *arg, int pend
+ {
+ PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)arg;
+ struct mbuf *m, *m0;
++#if __FreeBSD_version >= 1500000
++ if_t ifp = pThis->u.s.ifp;
++#else
+ struct ifnet *ifp = pThis->u.s.ifp;
++#endif
+ unsigned int cSegs = 0;
+ bool fDropIt = false, fActive;
++ bool is_vl_tagged = false;
++ uint16_t vl_tag;
+ PINTNETSG pSG;
+
++#if __FreeBSD_version >= 1500000
++ VBOXCURVNET_SET(if_getvnet(ifp));
++#else
+ VBOXCURVNET_SET(ifp->if_vnet);
++#endif
+ vboxNetFltRetain(pThis, true /* fBusy */);
+ for (;;)
+ {
+@@ -448,6 +474,19 @@ static void vboxNetFltFreeBSDinput(void *arg, int pend
+ if (m == NULL)
+ break;
+
++ /* Prepend a VLAN header for consumption by the virtual switch */
++ if (m->m_flags & M_VLANTAG) {
++ vl_tag = m->m_pkthdr.ether_vtag;
++ is_vl_tagged = true;
++
++ m = ether_vlanencap(m, m->m_pkthdr.ether_vtag);
++ if (m == NULL) {
++ printf("vboxflt: unable to prepend VLAN header\n");
++ break;
++ }
++ m->m_flags &= ~M_VLANTAG;
++ }
++
+ for (m0 = m; m0 != NULL; m0 = m0->m_next)
+ if (m0->m_len > 0)
+ cSegs++;
+@@ -462,10 +501,39 @@ static void vboxNetFltFreeBSDinput(void *arg, int pend
+ vboxNetFltFreeBSDMBufToSG(pThis, m, pSG, cSegs, 0);
+ fDropIt = pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, NULL /* pvIf */, pSG, INTNETTRUNKDIR_WIRE);
+ RTMemTmpFree(pSG);
++
++ /* Restore the VLAN flags before re-injecting the packet */
++ if (is_vl_tagged && !fDropIt) {
++ struct ether_vlan_header *vl_hdr;
++
++ /* This shouldn't fail, as the header was just prepended */
++ if (m->m_len < sizeof(*vl_hdr) && (m = m_pullup(m, sizeof(*vl_hdr))) == NULL) {
++ printf("vboxflt: unable to pullup VLAN header\n");
++ m_freem(m);
++ break;
++ }
++
++ /* Copy the MAC dhost/shost over the 802.1q field */
++ vl_hdr = mtod(m, struct ether_vlan_header *);
++ bcopy((char *)vl_hdr, (char *)vl_hdr + ETHER_VLAN_ENCAP_LEN, ETHER_HDR_LEN - ETHER_TYPE_LEN);
++ m_adj(m, ETHER_VLAN_ENCAP_LEN);
++
++ m->m_pkthdr.ether_vtag = vl_tag;
++ m->m_flags |= M_VLANTAG;
++ }
++
+ if (fDropIt)
+ m_freem(m);
+- else
++ else {
++#if __FreeBSD_version >= 1300049
++ struct epoch_tracker et;
++ NET_EPOCH_ENTER(et);
++#endif
+ ether_demux(ifp, m);
++#if __FreeBSD_version >= 1300049
++ NET_EPOCH_EXIT(et);
++#endif
++ }
+ }
+ vboxNetFltRelease(pThis, true /* fBusy */);
+ VBOXCURVNET_RESTORE();
+@@ -478,12 +546,20 @@ static void vboxNetFltFreeBSDoutput(void *arg, int pen
+ {
+ PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)arg;
+ struct mbuf *m, *m0;
++#if __FreeBSD_version >= 1500000
++ if_t ifp = pThis->u.s.ifp;
++#else
+ struct ifnet *ifp = pThis->u.s.ifp;
++#endif
+ unsigned int cSegs = 0;
+ bool fDropIt = false, fActive;
+ PINTNETSG pSG;
+
++#if __FreeBSD_version >= 1500000
++ VBOXCURVNET_SET(if_getvnet(ifp));
++#else
+ VBOXCURVNET_SET(ifp->if_vnet);
++#endif
+ vboxNetFltRetain(pThis, true /* fBusy */);
+ for (;;)
+ {
+@@ -521,26 +597,41 @@ int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *p
+ */
+ int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *pvIfData, PINTNETSG pSG, uint32_t fDst)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ NOREF(pvIfData);
+
+ void (*input_f)(struct ifnet *, struct mbuf *);
++#if __FreeBSD_version >= 1500000
++ if_t ifp;
++#else
+ struct ifnet *ifp;
++#endif
+ struct mbuf *m;
+ struct m_tag *mtag;
+ bool fActive;
+ int error;
+
+ ifp = ASMAtomicUoReadPtrT(&pThis->u.s.ifp, struct ifnet *);
++#if __FreeBSD_version >= 1500000
++ VBOXCURVNET_SET(if_getvnet(ifp));
++#else
+ VBOXCURVNET_SET(ifp->if_vnet);
++#endif
+
+ if (fDst & INTNETTRUNKDIR_WIRE)
+ {
+ m = vboxNetFltFreeBSDSGMBufFromSG(pThis, pSG);
+ if (m == NULL)
++ {
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
++ }
+ m = m_pullup(m, ETHER_HDR_LEN);
+ if (m == NULL)
++ {
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
++ }
+
+ m->m_flags |= M_PKTHDR;
+ ether_output_frame(ifp, m);
+@@ -550,10 +641,16 @@ int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *p
+ {
+ m = vboxNetFltFreeBSDSGMBufFromSG(pThis, pSG);
+ if (m == NULL)
++ {
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
++ }
+ m = m_pullup(m, ETHER_HDR_LEN);
+ if (m == NULL)
++ {
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
++ }
+ /*
+ * Delivering packets to the host will be captured by the
+ * input hook. Tag the packet with a mbuf tag so that we
+@@ -564,6 +661,7 @@ int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *p
+ if (mtag == NULL)
+ {
+ m_freem(m);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+@@ -571,9 +669,21 @@ int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *p
+ m_tag_prepend(m, mtag);
+ m->m_flags |= M_PKTHDR;
+ m->m_pkthdr.rcvif = ifp;
++#if __FreeBSD_version >= 1300049
++ struct epoch_tracker et;
++ NET_EPOCH_ENTER(et);
++#endif
++#if __FreeBSD_version >= 1500000
++ if_input(ifp, m);
++#else
+ ifp->if_input(ifp, m);
++#endif
++#if __FreeBSD_version >= 1300049
++ NET_EPOCH_EXIT(et);
++#endif
+ }
+ VBOXCURVNET_RESTORE();
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -586,15 +696,23 @@ int vboxNetFltOsInitInstance(PVBOXNETFLTINS pThis, voi
+
+ int vboxNetFltOsInitInstance(PVBOXNETFLTINS pThis, void *pvContext)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ char nam[NG_NODESIZ];
++#if __FreeBSD_version >= 1500000
++ if_t ifp;
++#else
+ struct ifnet *ifp;
++#endif
+ node_p node;
+
+ VBOXCURVNET_SET_FROM_UCRED();
+ NOREF(pvContext);
+ ifp = ifunit(pThis->szName);
+ if (ifp == NULL)
++ {
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_INTNET_FLT_IF_NOT_FOUND;
++ }
+
+ /* Create a new netgraph node for this instance */
+ if (ng_make_node_common(&ng_vboxnetflt_typestruct, &node) != 0)
+@@ -604,7 +722,11 @@ int vboxNetFltOsInitInstance(PVBOXNETFLTINS pThis, voi
+
+ ASMAtomicUoWritePtr(&pThis->u.s.ifp, ifp);
+ pThis->u.s.node = node;
++#if __FreeBSD_version >= 1500000
++ bcopy(if_getlladdr(ifp), &pThis->u.s.MacAddr, ETHER_ADDR_LEN);
++#else
+ bcopy(IF_LLADDR(ifp), &pThis->u.s.MacAddr, ETHER_ADDR_LEN);
++#endif
+ ASMAtomicUoWriteBool(&pThis->fDisconnectedFromHost, false);
+
+ /* Initialize deferred input queue */
+@@ -638,16 +760,26 @@ int vboxNetFltOsInitInstance(PVBOXNETFLTINS pThis, voi
+ vboxNetFltRelease(pThis, true /*fBusy*/);
+ }
+ VBOXCURVNET_RESTORE();
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+
+ return VINF_SUCCESS;
+ }
+
+ bool vboxNetFltOsMaybeRediscovered(PVBOXNETFLTINS pThis)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
++#if __FreeBSD_version >= 1500000
++ if_t ifp, ifp0;
++#else
+ struct ifnet *ifp, *ifp0;
++#endif
+
+ ifp = ASMAtomicUoReadPtrT(&pThis->u.s.ifp, struct ifnet *);
++#if __FreeBSD_version >= 1500000
++ VBOXCURVNET_SET(if_getvnet(ifp));
++#else
+ VBOXCURVNET_SET(ifp->if_vnet);
++#endif
+ /*
+ * Attempt to check if the interface is still there and re-initialize if
+ * something has changed.
+@@ -660,6 +792,7 @@ bool vboxNetFltOsMaybeRediscovered(PVBOXNETFLTINS pThi
+ pThis->u.s.node = NULL;
+ }
+ VBOXCURVNET_RESTORE();
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+
+ if (ifp0 != NULL)
+ {
+@@ -672,6 +805,7 @@ void vboxNetFltOsDeleteInstance(PVBOXNETFLTINS pThis)
+
+ void vboxNetFltOsDeleteInstance(PVBOXNETFLTINS pThis)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ taskqueue_drain(taskqueue_fast, &pThis->u.s.tskin);
+ taskqueue_drain(taskqueue_fast, &pThis->u.s.tskout);
+@@ -684,6 +818,7 @@ void vboxNetFltOsDeleteInstance(PVBOXNETFLTINS pThis)
+ ng_rmnode_self(pThis->u.s.node);
+ VBOXCURVNET_RESTORE();
+ pThis->u.s.node = NULL;
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ }
+
+ int vboxNetFltOsPreInitInstance(PVBOXNETFLTINS pThis)
+@@ -697,7 +832,12 @@ void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, b
+
+ void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, bool fActive)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
++#if __FreeBSD_version >= 1500000
++ if_t ifp;
++#else
+ struct ifnet *ifp;
++#endif
+ struct ifreq ifreq;
+ int error;
+ node_p node;
+@@ -709,18 +849,30 @@ void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, b
+ Log(("%s: fActive:%d\n", __func__, fActive));
+
+ ifp = ASMAtomicUoReadPtrT(&pThis->u.s.ifp, struct ifnet *);
++#if __FreeBSD_version >= 1500000
++ VBOXCURVNET_SET(if_getvnet(ifp));
++#else
+ VBOXCURVNET_SET(ifp->if_vnet);
++#endif
+ node = ASMAtomicUoReadPtrT(&pThis->u.s.node, node_p);
+
+ memset(&ifreq, 0, sizeof(struct ifreq));
+ /* Activate interface */
+ if (fActive)
+ {
++#if __FreeBSD_version >= 1500000
++ pThis->u.s.flags = if_getflags(ifp);
++#else
+ pThis->u.s.flags = ifp->if_flags;
++#endif
+ ifpromisc(ifp, 1);
+
+ /* ng_ether nodes are named after the interface name */
++#if __FreeBSD_version >= 1500000
++ snprintf(path, sizeof(path), "%s:", if_name(ifp));
++#else
+ snprintf(path, sizeof(path), "%s:", ifp->if_xname);
++#endif
+
+ /*
+ * Send a netgraph connect message to the ng_ether node
+@@ -730,9 +882,16 @@ void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, b
+ NG_MKMESSAGE(msg, NGM_GENERIC_COOKIE, NGM_CONNECT,
+ sizeof(struct ngm_connect), M_NOWAIT);
+ if (msg == NULL)
++ {
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return;
++ }
+ con = (struct ngm_connect *)msg->data;
++#if __FreeBSD_version >= 1500000
++ snprintf(con->path, NG_PATHSIZ, "vboxnetflt_%s:", if_name(ifp));
++#else
+ snprintf(con->path, NG_PATHSIZ, "vboxnetflt_%s:", ifp->if_xname);
++#endif
+ strlcpy(con->ourhook, "lower", NG_HOOKSIZ);
+ strlcpy(con->peerhook, "input", NG_HOOKSIZ);
+ NG_SEND_MSG_PATH(error, node, msg, path, 0);
+@@ -744,10 +903,17 @@ void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, b
+ NG_MKMESSAGE(msg, NGM_GENERIC_COOKIE, NGM_CONNECT,
+ sizeof(struct ngm_connect), M_NOWAIT);
+ if (msg == NULL)
++ {
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return;
++ }
+ con = (struct ngm_connect *)msg->data;
+ snprintf(con->path, NG_PATHSIZ, "vboxnetflt_%s:",
++#if __FreeBSD_version >= 1500000
++ if_name(ifp));
++#else
+ ifp->if_xname);
++#endif
+ strlcpy(con->ourhook, "upper", sizeof(con->ourhook));
+ strlcpy(con->peerhook, "output", sizeof(con->peerhook));
+ NG_SEND_MSG_PATH(error, node, msg, path, 0);
+@@ -759,7 +925,11 @@ void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, b
+ ifpromisc(ifp, 0);
+
+ /* Disconnect msgs are addressed to ourself */
++#if __FreeBSD_version >= 1500000
++ snprintf(path, sizeof(path), "vboxnetflt_%s:", if_name(ifp));
++#else
+ snprintf(path, sizeof(path), "vboxnetflt_%s:", ifp->if_xname);
++#endif
+
+ /*
+ * Send a netgraph message to disconnect our 'input' hook
+@@ -767,7 +937,10 @@ void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, b
+ NG_MKMESSAGE(msg, NGM_GENERIC_COOKIE, NGM_RMHOOK,
+ sizeof(struct ngm_rmhook), M_NOWAIT);
+ if (msg == NULL)
++ {
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return;
++ }
+ rm = (struct ngm_rmhook *)msg->data;
+ strlcpy(rm->ourhook, "input", NG_HOOKSIZ);
+ NG_SEND_MSG_PATH(error, node, msg, path, 0);
+@@ -778,12 +951,16 @@ void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, b
+ NG_MKMESSAGE(msg, NGM_GENERIC_COOKIE, NGM_RMHOOK,
+ sizeof(struct ngm_rmhook), M_NOWAIT);
+ if (msg == NULL)
++ {
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return;
++ }
+ rm = (struct ngm_rmhook *)msg->data;
+ strlcpy(rm->ourhook, "output", NG_HOOKSIZ);
+ NG_SEND_MSG_PATH(error, node, msg, path, 0);
+ }
+ VBOXCURVNET_RESTORE();
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ }
+
+ int vboxNetFltOsDisconnectIt(PVBOXNETFLTINS pThis)
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_adpctl_VBoxNetAdpCtl.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_adpctl_VBoxNetAdpCtl.cpp
new file mode 100644
index 000000000000..67573dc080a4
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_HostDrivers_adpctl_VBoxNetAdpCtl.cpp
@@ -0,0 +1,11 @@
+--- src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp.orig 2022-01-13 18:57:40 UTC
++++ src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp
+@@ -737,7 +737,7 @@ int Adapter::doIOCtl(unsigned long iCmd, VBOXNETADPREQ
+ * Global config file implementation *
+ *********************************************************************************************************************************/
+
+-#define VBOX_GLOBAL_NETWORK_CONFIG_PATH "/etc/vbox/networks.conf"
++#define VBOX_GLOBAL_NETWORK_CONFIG_PATH "%%VBOX_ETC%%/networks.conf"
+ #define VBOXNET_DEFAULT_IPV4MASK "255.255.255.0"
+
+ class NetworkAddress
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_Makefile.kmk
new file mode 100644
index 000000000000..f5693ffb72b4
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_Makefile.kmk
@@ -0,0 +1,10 @@
+--- src/VBox/Main/Makefile.kmk.orig 2024-10-10 20:31:38.000000000 +0200
++++ src/VBox/Main/Makefile.kmk 2024-12-27 13:32:31.610875000 +0100
+@@ -761,6 +761,7 @@
+
+ VBoxSVC_SOURCES.freebsd = \
+ src-server/freebsd/HostHardwareFreeBSD.cpp \
++ $(if $(VBOX_WITH_DBUS),src-server/linux/HostPowerLinux.cpp) \
+ src-server/HostDnsServiceResolvConf.cpp
+
+ VBoxSVC_LDFLAGS.freebsd += -lcam
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_include_HostPower.h b/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_include_HostPower.h
new file mode 100644
index 000000000000..5718fe987ce4
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_include_HostPower.h
@@ -0,0 +1,20 @@
+--- src/VBox/Main/include/HostPower.h.orig 2021-01-07 15:41:38 UTC
++++ src/VBox/Main/include/HostPower.h
+@@ -31,7 +31,7 @@
+
+ #include <vector>
+
+-#ifdef RT_OS_LINUX
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
+ # include <VBox/dbus.h>
+ #endif
+
+@@ -67,7 +67,7 @@ class HostPowerServiceWin : public HostPowerService (p
+ RTTHREAD mThread;
+ };
+ # endif
+-# if defined(RT_OS_LINUX) || defined(DOXYGEN_RUNNING)
++# if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(DOXYGEN_RUNNING)
+ /**
+ * The Linux hosted Power Service.
+ */
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_src-server_HostImpl.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_src-server_HostImpl.cpp
new file mode 100644
index 000000000000..d4c018b2fc23
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_src-server_HostImpl.cpp
@@ -0,0 +1,11 @@
+--- src/VBox/Main/src-server/HostImpl.cpp.orig 2021-01-07 15:41:42 UTC
++++ src/VBox/Main/src-server/HostImpl.cpp
+@@ -286,7 +286,7 @@ HRESULT Host::init(VirtualBox *aParent)
+
+ #if defined(RT_OS_WINDOWS)
+ m->pHostPowerService = new HostPowerServiceWin(m->pParent);
+-#elif defined(RT_OS_LINUX) && defined(VBOX_WITH_DBUS)
++#elif (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && defined(VBOX_WITH_DBUS)
+ m->pHostPowerService = new HostPowerServiceLinux(m->pParent);
+ #elif defined(RT_OS_DARWIN)
+ m->pHostPowerService = new HostPowerServiceDarwin(m->pParent);
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_src-server_freebsd_PerformanceFreeBSD.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_src-server_freebsd_PerformanceFreeBSD.cpp
new file mode 100644
index 000000000000..631547ac9cee
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Main_src-server_freebsd_PerformanceFreeBSD.cpp
@@ -0,0 +1,24 @@
+--- src/VBox/Main/src-server/freebsd/PerformanceFreeBSD.cpp.orig 2017-07-27 13:18:27 UTC
++++ src/VBox/Main/src-server/freebsd/PerformanceFreeBSD.cpp
+@@ -80,8 +80,10 @@ int CollectorFreeBSD::getHostMemoryUsage(ULONG *total,
+ cbParameter = sizeof(cPagesMemInactive);
+ if (!sysctlbyname("vm.stats.vm.v_inactive_count", &cPagesMemInactive, &cbParameter, NULL, 0))
+ cProcessed++;
++#if __FreeBSD_version < 1200016
+ cbParameter = sizeof(cPagesMemCached);
+ if (!sysctlbyname("vm.stats.vm.v_cache_count", &cPagesMemCached, &cbParameter, NULL, 0))
++#endif
+ cProcessed++;
+ cbParameter = sizeof(cbPage);
+ if (!sysctlbyname("hw.pagesize", &cbPage, &cbParameter, NULL, 0))
+@@ -90,8 +92,8 @@ int CollectorFreeBSD::getHostMemoryUsage(ULONG *total,
+ if (cProcessed == 6)
+ {
+ *total = cbMemPhys / _1K;
+- *used = cPagesMemUsed * (cbPage / _1K);
+- *available = (cPagesMemFree + cPagesMemInactive + cPagesMemCached ) * (cbPage / _1K);
++ *used = (uint64_t)cPagesMemUsed * (cbPage / _1K);
++ *available = ((uint64_t)cPagesMemFree + cPagesMemInactive + cPagesMemCached) * (cbPage / _1K);
+ }
+ else
+ rc = VERR_NOT_SUPPORTED;
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_Makefile.kmk
new file mode 100644
index 000000000000..3133e4cbd207
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_Makefile.kmk
@@ -0,0 +1,29 @@
+--- src/VBox/Runtime/Makefile.kmk.orig 2025-01-21 19:59:19.000000000 +0700
++++ src/VBox/Runtime/Makefile.kmk 2025-03-23 20:54:34.250024000 +0700
+@@ -225,6 +225,9 @@
+ $(QUIET)$(oiddb2c_1_TARGET) "$@" $(filter %.cfg,$^)
+ $(QUIET)$(CP) --changed -fv "$@" "$(IPRT_OUT_DIR)/oiddb.h"
+
++# Set the defines that utf8-posix.cpp needs. It's used by several targets.
++#
++r3/posix/utf8-posix.cpp_DEFS.freebsd = $(VBOX_ICONV_DEFS)
+
+ #
+ # Unicode Specification reader used to regenerate unidata-*.cpp.
+@@ -1468,6 +1471,7 @@
+ generic/RTProcDaemonize-generic.cpp \
+ generic/RTProcIsRunningByName-generic.cpp \
+ generic/RTThreadGetNativeState-generic.cpp \
++ generic/system-page-size-generic.cpp \
+ r3/freebsd/fileaio-freebsd.cpp \
+ r3/freebsd/RTFileQuerySectorSize-freebsd.cpp \
+ r3/freebsd/mp-freebsd.cpp \
+@@ -3011,6 +3015,8 @@
+ /delayload:ole32.dll \
+ /delayload:oleaut32.dll \
+ /delayload:advapi32.dll
++VBoxRT_LDFLAGS.freebsd = \
++ -Wl,--allow-multiple-definition
+
+ if1of (VBoxRT, $(DLLS))
+ $(call VBOX_SET_VER_INFO_DLL,VBoxRT,VirtualBox Runtime)
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_alloc-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_alloc-r0drv-freebsd.c
new file mode 100644
index 000000000000..0ae2d847c0f6
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_alloc-r0drv-freebsd.c
@@ -0,0 +1,58 @@
+--- src/VBox/Runtime/r0drv/freebsd/alloc-r0drv-freebsd.c.orig 2024-10-10 20:32:14.000000000 +0200
++++ src/VBox/Runtime/r0drv/freebsd/alloc-r0drv-freebsd.c 2024-12-27 13:39:49.059878000 +0100
+@@ -88,6 +88,7 @@
+
+ DECLHIDDEN(int) rtR0MemAllocEx(size_t cb, uint32_t fFlags, PRTMEMHDR *ppHdr)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ size_t cbAllocated = cb;
+ PRTMEMHDR pHdr = (PRTMEMHDR)malloc(cb + sizeof(RTMEMHDR), M_IPRTHEAP,
+ fFlags & RTMEMHDR_FLAG_ZEROED ? M_NOWAIT | M_ZERO : M_NOWAIT);
+@@ -99,21 +100,28 @@
+ pHdr->cbReq = cb;
+
+ *ppHdr = pHdr;
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+- }
++ }
++
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+
+ DECLHIDDEN(void) rtR0MemFree(PRTMEMHDR pHdr)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
++
+ pHdr->u32Magic += 1;
+ free(pHdr, M_IPRTHEAP);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ }
+
+
+ RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ void *pv;
+
+ /*
+@@ -138,6 +146,7 @@
+ *pPhys = vtophys(pv);
+ Assert(!(*pPhys & PAGE_OFFSET_MASK));
+ }
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return pv;
+ }
+
+@@ -147,7 +156,9 @@
+ if (pv)
+ {
+ AssertMsg(!((uintptr_t)pv & PAGE_OFFSET_MASK), ("pv=%p\n", pv));
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ contigfree(pv, cb, M_IPRTCONT);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ }
+ }
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_assert-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_assert-r0drv-freebsd.c
new file mode 100644
index 000000000000..4c628cbe47a5
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_assert-r0drv-freebsd.c
@@ -0,0 +1,29 @@
+--- src/VBox/Runtime/r0drv/freebsd/assert-r0drv-freebsd.c.orig 2021-01-07 15:42:08 UTC
++++ src/VBox/Runtime/r0drv/freebsd/assert-r0drv-freebsd.c
+@@ -68,15 +68,18 @@
+
+ DECLHIDDEN(void) rtR0AssertNativeMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ printf("\r\n!!Assertion Failed!!\r\n"
+ "Expression: %s\r\n"
+ "Location : %s(%d) %s\r\n",
+ pszExpr, pszFile, uLine, pszFunction);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ }
+
+
+ DECLHIDDEN(void) rtR0AssertNativeMsg2V(bool fInitial, const char *pszFormat, va_list va)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ char szMsg[256];
+
+ RTStrPrintfV(szMsg, sizeof(szMsg) - 1, pszFormat, va);
+@@ -84,6 +87,7 @@ DECLHIDDEN(void) rtR0AssertNativeMsg2V(bool fInitial,
+ printf("%s", szMsg);
+
+ NOREF(fInitial);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ }
+
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_memobj-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_memobj-r0drv-freebsd.c
new file mode 100644
index 000000000000..4c0ed355709c
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_memobj-r0drv-freebsd.c
@@ -0,0 +1,408 @@
+--- src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c.orig 2025-04-14 17:59:13 UTC
++++ src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
+@@ -140,8 +140,10 @@ DECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
+
+ DECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)pMem;
+ int rc;
++ vm_map_t pMap;
+
+ switch (pMemFreeBSD->Core.enmType)
+ {
+@@ -156,8 +158,6 @@ DECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
+
+ case RTR0MEMOBJTYPE_LOCK:
+ {
+- vm_map_t pMap = kernel_map;
+-
+ if (pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
+ pMap = &((struct proc *)pMemFreeBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map;
+
+@@ -198,6 +198,7 @@ DECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
+ case RTR0MEMOBJTYPE_PHYS_NC:
+ {
+ VM_OBJECT_WLOCK(pMemFreeBSD->pObject);
++#if __FreeBSD_version < 1500038
+ vm_page_t pPage = vm_page_find_least(pMemFreeBSD->pObject, 0);
+ #if __FreeBSD_version < 1000000
+ vm_page_lock_queues();
+@@ -211,6 +212,14 @@ DECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
+ #if __FreeBSD_version < 1000000
+ vm_page_unlock_queues();
+ #endif
++#else /* __FreeBSD_version >= 1500038 */
++ struct pctrie_iter pages;
++ vm_page_t page;
++
++ vm_page_iter_init(&pages, pMemFreeBSD->pObject);
++ VM_RADIX_FORALL(page, &pages)
++ (void)vm_page_unwire_noq(page);
++#endif
+ VM_OBJECT_WUNLOCK(pMemFreeBSD->pObject);
+ vm_object_deallocate(pMemFreeBSD->pObject);
+ break;
+@@ -221,6 +230,7 @@ DECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
+ return VERR_INTERNAL_ERROR;
+ }
+
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -330,7 +340,8 @@ static int rtR0MemObjFreeBSDAllocHelper(PRTR0MEMOBJFRE
+ size_t cPages = atop(pMemFreeBSD->Core.cb);
+ int rc;
+
+- pMemFreeBSD->pObject = vm_object_allocate(OBJT_PHYS, cPages);
++ pMemFreeBSD->pObject = vm_pager_allocate(OBJT_PHYS, NULL,
++ pMemFreeBSD->Core.cb, VM_PROT_ALL, 0, curthread->td_ucred);
+
+ /* No additional object reference for auto-deallocation upon unmapping. */
+ #if __FreeBSD_version >= 1000055
+@@ -372,6 +383,7 @@ DECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJ
+
+ DECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_PAGE,
+ NULL, cb, pszTag);
+ if (pMemFreeBSD)
+@@ -381,8 +393,10 @@ DECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJ
+ *ppMem = &pMemFreeBSD->Core;
+ else
+ rtR0MemObjDelete(&pMemFreeBSD->Core);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return rc;
+ }
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+@@ -396,6 +410,7 @@ DECLHIDDEN(int) rtR0MemObjNativeAllocLow(PPRTR0MEMOBJI
+
+ DECLHIDDEN(int) rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, const char *pszTag)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_LOW, NULL, cb, pszTag);
+ if (pMemFreeBSD)
+ {
+@@ -404,8 +419,10 @@ DECLHIDDEN(int) rtR0MemObjNativeAllocLow(PPRTR0MEMOBJI
+ *ppMem = &pMemFreeBSD->Core;
+ else
+ rtR0MemObjDelete(&pMemFreeBSD->Core);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return rc;
+ }
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+@@ -413,6 +430,7 @@ DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJ
+ DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHigest,
+ bool fExecutable, const char *pszTag)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_CONT,
+ NULL, cb, pszTag);
+ if (pMemFreeBSD)
+@@ -425,8 +443,10 @@ DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJ
+ }
+ else
+ rtR0MemObjDelete(&pMemFreeBSD->Core);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return rc;
+ }
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+@@ -434,6 +454,7 @@ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOB
+ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJTYPE enmType, size_t cb, RTHCPHYS PhysHighest,
+ size_t uAlignment, bool fContiguous, int rcNoMem, const char *pszTag)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ /* create the object. */
+ PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), enmType, NULL, cb, pszTag);
+ if (pMemFreeBSD)
+@@ -441,7 +462,8 @@ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOB
+ vm_paddr_t const VmPhysAddrHigh = PhysHighest != NIL_RTHCPHYS ? PhysHighest : ~(vm_paddr_t)0;
+ u_long const cPages = atop(cb);
+
+- pMemFreeBSD->pObject = vm_object_allocate(OBJT_PHYS, cPages);
++ pMemFreeBSD->pObject = vm_pager_allocate(OBJT_PHYS, NULL,
++ pMemFreeBSD->Core.cb, VM_PROT_ALL, 0, curthread->td_ucred);
+
+ int rc = rtR0MemObjFreeBSDPhysAllocHelper(pMemFreeBSD->pObject, cPages, VmPhysAddrHigh,
+ uAlignment, fContiguous, true, rcNoMem);
+@@ -451,7 +473,7 @@ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOB
+ {
+ Assert(enmType == RTR0MEMOBJTYPE_PHYS);
+ VM_OBJECT_WLOCK(pMemFreeBSD->pObject);
+- pMemFreeBSD->Core.u.Phys.PhysBase = VM_PAGE_TO_PHYS(vm_page_find_least(pMemFreeBSD->pObject, 0));
++ pMemFreeBSD->Core.u.Phys.PhysBase = VM_PAGE_TO_PHYS(vm_radix_lookup_ge(&pMemFreeBSD->pObject->rtree, 0));
+ VM_OBJECT_WUNLOCK(pMemFreeBSD->pObject);
+ pMemFreeBSD->Core.u.Phys.fAllocated = true;
+ }
+@@ -464,8 +486,10 @@ static int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOB
+ vm_object_deallocate(pMemFreeBSD->pObject);
+ rtR0MemObjDelete(&pMemFreeBSD->Core);
+ }
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return rc;
+ }
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+@@ -488,6 +512,7 @@ DECLHIDDEN(int) rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJ
+ const char *pszTag)
+ {
+ AssertReturn(uCachePolicy == RTMEM_CACHE_POLICY_DONT_CARE, VERR_NOT_SUPPORTED);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ /* create the object. */
+ PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_PHYS,
+@@ -499,8 +524,10 @@ DECLHIDDEN(int) rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJ
+ pMemFreeBSD->Core.u.Phys.PhysBase = Phys;
+ pMemFreeBSD->Core.u.Phys.uCachePolicy = uCachePolicy;
+ *ppMem = &pMemFreeBSD->Core;
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+@@ -512,6 +539,7 @@ static int rtR0MemObjNativeLockInMap(PPRTR0MEMOBJINTER
+ vm_offset_t AddrStart, size_t cb, uint32_t fAccess,
+ RTR0PROCESS R0Process, int fFlags, const char *pszTag)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ int rc;
+ NOREF(fAccess);
+
+@@ -521,21 +549,28 @@ static int rtR0MemObjNativeLockInMap(PPRTR0MEMOBJINTER
+ if (!pMemFreeBSD)
+ return VERR_NO_MEMORY;
+
+- /*
+- * We could've used vslock here, but we don't wish to be subject to
+- * resource usage restrictions, so we'll call vm_map_wire directly.
+- */
+- rc = vm_map_wire(pVmMap, /* the map */
+- AddrStart, /* start */
+- AddrStart + cb, /* end */
+- fFlags); /* flags */
++ if (pVmMap != kernel_map) {
++ /*
++ * We could've used vslock here, but we don't wish to be subject to
++ * resource usage restrictions, so we'll call vm_map_wire directly.
++ */
++ rc = vm_map_wire(pVmMap, /* the map */
++ AddrStart, /* start */
++ AddrStart + cb, /* end */
++ fFlags); /* flags */
++ }
++ else
++ rc = KERN_SUCCESS;
++
+ if (rc == KERN_SUCCESS)
+ {
+ pMemFreeBSD->Core.u.Lock.R0Process = R0Process;
+ *ppMem = &pMemFreeBSD->Core;
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+ rtR0MemObjDelete(&pMemFreeBSD->Core);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;/** @todo fix mach -> vbox error conversion for freebsd. */
+ }
+
+@@ -575,6 +610,7 @@ static int rtR0MemObjNativeReserveInMap(PPRTR0MEMOBJIN
+ static int rtR0MemObjNativeReserveInMap(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment,
+ RTR0PROCESS R0Process, vm_map_t pMap, const char *pszTag)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ int rc;
+
+ /*
+@@ -633,11 +669,13 @@ static int rtR0MemObjNativeReserveInMap(PPRTR0MEMOBJIN
+ pMemFreeBSD->Core.pv = (void *)MapAddress;
+ pMemFreeBSD->Core.u.ResVirt.R0Process = R0Process;
+ *ppMem = &pMemFreeBSD->Core;
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+ rc = VERR_NO_MEMORY; /** @todo fix translation (borrow from darwin) */
+ rtR0MemObjDelete(&pMemFreeBSD->Core);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return rc;
+
+ }
+@@ -661,6 +699,8 @@ DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJ
+ DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
+ unsigned fProt, size_t offSub, size_t cbSub, const char *pszTag)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
++
+ // AssertMsgReturn(!offSub && !cbSub, ("%#x %#x\n", offSub, cbSub), VERR_NOT_SUPPORTED);
+ AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED);
+
+@@ -715,6 +755,7 @@ DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJ
+ Assert((vm_offset_t)pMemFreeBSD->Core.pv == Addr);
+ pMemFreeBSD->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;
+ *ppMem = &pMemFreeBSD->Core;
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+ rc = vm_map_remove(kernel_map, Addr, Addr + cbSub);
+@@ -723,6 +764,7 @@ DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJ
+ else
+ vm_object_deallocate(pMemToMapFreeBSD->pObject);
+
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+@@ -730,6 +772,8 @@ DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJIN
+ DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
+ unsigned fProt, RTR0PROCESS R0Process, size_t offSub, size_t cbSub, const char *pszTag)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
++
+ /*
+ * Check for unsupported stuff.
+ */
+@@ -787,44 +831,50 @@ DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJIN
+
+ if (rc == KERN_SUCCESS)
+ {
+- rc = vm_map_wire(pProcMap, AddrR3, AddrR3 + pMemToMap->cb, VM_MAP_WIRE_USER|VM_MAP_WIRE_NOHOLES);
++ rc = vm_map_wire(pProcMap, AddrR3, AddrR3 + cbSub, VM_MAP_WIRE_USER|VM_MAP_WIRE_NOHOLES);
+ AssertMsg(rc == KERN_SUCCESS, ("%#x\n", rc));
+
+- rc = vm_map_inherit(pProcMap, AddrR3, AddrR3 + pMemToMap->cb, VM_INHERIT_SHARE);
++ rc = vm_map_inherit(pProcMap, AddrR3, AddrR3 + cbSub, VM_INHERIT_SHARE);
+ AssertMsg(rc == KERN_SUCCESS, ("%#x\n", rc));
+
+ /*
+ * Create a mapping object for it.
+ */
+ PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(RTR0MEMOBJFREEBSD), RTR0MEMOBJTYPE_MAPPING,
+- (void *)AddrR3, pMemToMap->cb, pszTag);
++ (void *)AddrR3, cbSub, pszTag);
+ if (pMemFreeBSD)
+ {
+ Assert((vm_offset_t)pMemFreeBSD->Core.pv == AddrR3);
+ pMemFreeBSD->Core.u.Mapping.R0Process = R0Process;
+ *ppMem = &pMemFreeBSD->Core;
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+- rc = vm_map_remove(pProcMap, AddrR3, AddrR3 + pMemToMap->cb);
++ rc = vm_map_remove(pProcMap, AddrR3, AddrR3 + cbSub);
+ AssertMsg(rc == KERN_SUCCESS, ("Deleting mapping failed\n"));
+ }
+ else
+ vm_object_deallocate(pMemToMapFreeBSD->pObject);
+
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+
+ DECLHIDDEN(int) rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ vm_prot_t ProtectionFlags = 0;
+ vm_offset_t AddrStart = (uintptr_t)pMem->pv + offSub;
+ vm_offset_t AddrEnd = AddrStart + cbSub;
+ vm_map_t pVmMap = rtR0MemObjFreeBSDGetMap(pMem);
+
+ if (!pVmMap)
++ {
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NOT_SUPPORTED;
++ }
+
+ if ((fProt & RTMEM_PROT_NONE) == RTMEM_PROT_NONE)
+ ProtectionFlags = VM_PROT_NONE;
+@@ -835,7 +885,12 @@ DECLHIDDEN(int) rtR0MemObjNativeProtect(PRTR0MEMOBJINT
+ if ((fProt & RTMEM_PROT_EXEC) == RTMEM_PROT_EXEC)
+ ProtectionFlags |= VM_PROT_EXECUTE;
+
++#if __FreeBSD_version >= 1300135
++ int krc = vm_map_protect(pVmMap, AddrStart, AddrEnd, ProtectionFlags, 0, VM_MAP_PROTECT_SET_PROT);
++#else
+ int krc = vm_map_protect(pVmMap, AddrStart, AddrEnd, ProtectionFlags, FALSE);
++#endif
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ if (krc == KERN_SUCCESS)
+ return VINF_SUCCESS;
+
+@@ -860,11 +915,19 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P
+
+ vm_offset_t pb = (vm_offset_t)pMemFreeBSD->Core.pv + ptoa(iPage);
+
+- struct proc *pProc = (struct proc *)pMemFreeBSD->Core.u.Lock.R0Process;
+- struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
+- pmap_t pPhysicalMap = vm_map_pmap(pProcMap);
++ if (pMemFreeBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS)
++ {
++ RTHCPHYS addr;
++ IPRT_FREEBSD_SAVE_EFL_AC();
++ struct proc *pProc = (struct proc *)pMemFreeBSD->Core.u.Lock.R0Process;
++ struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
++ pmap_t pPhysicalMap = vm_map_pmap(pProcMap);
+
+- return pmap_extract(pPhysicalMap, pb);
++ addr = pmap_extract(pPhysicalMap, pb);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
++ return addr;
++ }
++ return vtophys(pb);
+ }
+
+ case RTR0MEMOBJTYPE_MAPPING:
+@@ -873,11 +936,15 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P
+
+ if (pMemFreeBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS)
+ {
++ RTHCPHYS addr;
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ struct proc *pProc = (struct proc *)pMemFreeBSD->Core.u.Mapping.R0Process;
+ struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
+ pmap_t pPhysicalMap = vm_map_pmap(pProcMap);
+
+- return pmap_extract(pPhysicalMap, pb);
++ addr = pmap_extract(pPhysicalMap, pb);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
++ return addr;
+ }
+ return vtophys(pb);
+ }
+@@ -888,9 +955,11 @@ DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(P
+ {
+ RTHCPHYS addr;
+
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ VM_OBJECT_WLOCK(pMemFreeBSD->pObject);
+ addr = VM_PAGE_TO_PHYS(vm_page_lookup(pMemFreeBSD->pObject, iPage));
+ VM_OBJECT_WUNLOCK(pMemFreeBSD->pObject);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return addr;
+ }
+
+@@ -910,7 +979,7 @@ DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping
+ DECLHIDDEN(int) rtR0MemObjNativeZeroInitWithoutMapping(PRTR0MEMOBJINTERNAL pMem)
+ {
+ PRTR0MEMOBJFREEBSD const pMemFreeBsd = (PRTR0MEMOBJFREEBSD)pMem;
+- size_t const cPages = pMemSolaris->Core.cb >> PAGE_SHIFT;
++ size_t const cPages = atop(pMemFreeBsd->Core.cb);
+ size_t iPage;
+ for (iPage = 0; iPage < cPages; iPage++)
+ {
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_memuserkernel-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_memuserkernel-r0drv-freebsd.c
new file mode 100644
index 000000000000..53bac187bde0
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_memuserkernel-r0drv-freebsd.c
@@ -0,0 +1,22 @@
+--- src/VBox/Runtime/r0drv/freebsd/memuserkernel-r0drv-freebsd.c.orig 2018-10-15 14:31:31 UTC
++++ src/VBox/Runtime/r0drv/freebsd/memuserkernel-r0drv-freebsd.c
+@@ -36,7 +36,9 @@
+
+ RTR0DECL(int) RTR0MemUserCopyFrom(void *pvDst, RTR3PTR R3PtrSrc, size_t cb)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ int rc = copyin((const void *)R3PtrSrc, pvDst, cb);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ if (RT_LIKELY(rc == 0))
+ return VINF_SUCCESS;
+ return VERR_ACCESS_DENIED;
+@@ -45,7 +47,9 @@ RTR0DECL(int) RTR0MemUserCopyFrom(void *pvDst, RTR3PTR
+
+ RTR0DECL(int) RTR0MemUserCopyTo(RTR3PTR R3PtrDst, void const *pvSrc, size_t cb)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ int rc = copyout(pvSrc, (void *)R3PtrDst, cb);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ if (RT_LIKELY(rc == 0))
+ return VINF_SUCCESS;
+ return VERR_ACCESS_DENIED;
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_mp-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_mp-r0drv-freebsd.c
new file mode 100644
index 000000000000..8c68cae63a34
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_mp-r0drv-freebsd.c
@@ -0,0 +1,92 @@
+--- src/VBox/Runtime/r0drv/freebsd/mp-r0drv-freebsd.c.orig 2019-04-16 10:17:21 UTC
++++ src/VBox/Runtime/r0drv/freebsd/mp-r0drv-freebsd.c
+@@ -147,7 +147,9 @@ RTDECL(RTCPUID) RTMpGetOnlineCount(void)
+ static void rtmpOnAllFreeBSDWrapper(void *pvArg)
+ {
+ PRTMPARGS pArgs = (PRTMPARGS)pvArg;
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ pArgs->pfnWorker(curcpu, pArgs->pvUser1, pArgs->pvUser2);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ }
+
+
+@@ -159,7 +161,9 @@ RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *p
+ Args.pvUser2 = pvUser2;
+ Args.idCpu = NIL_RTCPUID;
+ Args.cHits = 0;
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ smp_rendezvous(NULL, rtmpOnAllFreeBSDWrapper, smp_no_rendezvous_barrier, &Args);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -175,7 +179,11 @@ static void rtmpOnOthersFreeBSDWrapper(void *pvArg)
+ PRTMPARGS pArgs = (PRTMPARGS)pvArg;
+ RTCPUID idCpu = curcpu;
+ if (pArgs->idCpu != idCpu)
++ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
++ }
+ }
+
+
+@@ -196,6 +204,7 @@ RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void
+ Args.pvUser2 = pvUser2;
+ Args.idCpu = RTMpCpuId();
+ Args.cHits = 0;
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ #if __FreeBSD_version >= 700000
+ # if __FreeBSD_version >= 900000
+ Mask = all_cpus;
+@@ -207,6 +216,7 @@ RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void
+ #else
+ smp_rendezvous(NULL, rtmpOnOthersFreeBSDWrapper, NULL, &Args);
+ #endif
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ }
+ return VINF_SUCCESS;
+ }
+@@ -224,8 +234,10 @@ static void rtmpOnSpecificFreeBSDWrapper(void *pvArg)
+ RTCPUID idCpu = curcpu;
+ if (pArgs->idCpu == idCpu)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
+ ASMAtomicIncU32(&pArgs->cHits);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ }
+ }
+
+@@ -248,6 +260,7 @@ RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKE
+ Args.pvUser2 = pvUser2;
+ Args.idCpu = idCpu;
+ Args.cHits = 0;
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ #if __FreeBSD_version >= 700000
+ # if __FreeBSD_version >= 900000
+ CPU_SETOF(idCpu, &Mask);
+@@ -258,6 +271,7 @@ RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKE
+ #else
+ smp_rendezvous(NULL, rtmpOnSpecificFreeBSDWrapper, NULL, &Args);
+ #endif
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return Args.cHits == 1
+ ? VINF_SUCCESS
+ : VERR_CPU_NOT_FOUND;
+@@ -287,12 +301,14 @@ RTDECL(int) RTMpPokeCpu(RTCPUID idCpu)
+ if (!RTMpIsCpuOnline(idCpu))
+ return VERR_CPU_NOT_FOUND;
+
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ # if __FreeBSD_version >= 900000
+ CPU_SETOF(idCpu, &Mask);
+ # else
+ Mask = (cpumask_t)1 << idCpu;
+ # endif
+ smp_rendezvous_cpus(Mask, NULL, rtmpFreeBSDPokeCallback, smp_no_rendezvous_barrier, NULL);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+
+ return VINF_SUCCESS;
+ }
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semevent-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semevent-r0drv-freebsd.c
new file mode 100644
index 000000000000..c84313e2f5e2
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semevent-r0drv-freebsd.c
@@ -0,0 +1,53 @@
+--- src/VBox/Runtime/r0drv/freebsd/semevent-r0drv-freebsd.c.orig 2021-01-07 15:42:08 UTC
++++ src/VBox/Runtime/r0drv/freebsd/semevent-r0drv-freebsd.c
+@@ -101,7 +101,9 @@ RTDECL(int) RTSemEventCreateEx(PRTSEMEVENT phEventSem
+ Assert(!(fFlags & RTSEMEVENT_FLAGS_BOOTSTRAP_HACK) || (fFlags & RTSEMEVENT_FLAGS_NO_LOCK_VAL));
+ AssertPtrReturn(phEventSem, VERR_INVALID_POINTER);
+
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)RTMemAllocZ(sizeof(*pThis));
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ if (!pThis)
+ return VERR_NO_MEMORY;
+
+@@ -152,10 +154,12 @@ RTDECL(int) RTSemEventDestroy(RTSEMEVENT hEventSem)
+ /*
+ * Invalidate it and signal the object just in case.
+ */
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ ASMAtomicWriteU32(&pThis->u32Magic, ~RTSEMEVENT_MAGIC);
+ ASMAtomicWriteU32(&pThis->fState, 0);
+ rtR0SemBsdBroadcast(pThis);
+ rtR0SemEventBsdRelease(pThis);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -173,9 +177,11 @@ RTDECL(int) RTSemEventSignal(RTSEMEVENT hEventSem)
+ /*
+ * Signal the event object.
+ */
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ ASMAtomicWriteU32(&pThis->fState, 1);
+ rtR0SemBsdSignal(pThis);
+ rtR0SemEventBsdRelease(pThis);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -199,6 +205,7 @@ static int rtR0SemEventWait(PRTSEMEVENTINTERNAL pThis,
+ AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
+ AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
+ AssertReturn(RTSEMWAIT_FLAGS_ARE_VALID(fFlags), VERR_INVALID_PARAMETER);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ rtR0SemEventBsdRetain(pThis);
+
+ /*
+@@ -248,6 +255,7 @@ static int rtR0SemEventWait(PRTSEMEVENTINTERNAL pThis,
+ }
+
+ rtR0SemEventBsdRelease(pThis);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return rc;
+ }
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semeventmulti-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semeventmulti-r0drv-freebsd.c
new file mode 100644
index 000000000000..d3571a937b1f
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semeventmulti-r0drv-freebsd.c
@@ -0,0 +1,73 @@
+--- src/VBox/Runtime/r0drv/freebsd/semeventmulti-r0drv-freebsd.c.orig 2021-01-07 15:42:08 UTC
++++ src/VBox/Runtime/r0drv/freebsd/semeventmulti-r0drv-freebsd.c
+@@ -120,7 +120,9 @@ RTDECL(int) RTSemEventMultiCreateEx(PRTSEMEVENTMULTI
+ PRTSEMEVENTMULTIINTERNAL pThis;
+
+ AssertReturn(!(fFlags & ~RTSEMEVENTMULTI_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ pThis = (PRTSEMEVENTMULTIINTERNAL)RTMemAlloc(sizeof(*pThis));
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ if (pThis)
+ {
+ pThis->u32Magic = RTSEMEVENTMULTI_MAGIC;
+@@ -176,10 +178,12 @@ RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI hE
+ /*
+ * Invalidate it and signal the object just in case.
+ */
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ ASMAtomicWriteU32(&pThis->u32Magic, ~RTSEMEVENTMULTI_MAGIC);
+ ASMAtomicAndU32(&pThis->fStateAndGen, RTSEMEVENTMULTIBSD_GEN_MASK);
+ rtR0SemBsdBroadcast(pThis);
+ rtR0SemEventMultiBsdRelease(pThis);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -188,6 +192,7 @@ RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI hEv
+ {
+ uint32_t fNew;
+ uint32_t fOld;
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ /*
+ * Validate input.
+@@ -214,12 +219,15 @@ RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI hEv
+
+ rtR0SemBsdBroadcast(pThis);
+ rtR0SemEventMultiBsdRelease(pThis);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+
+ RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI hEventMultiSem)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
++
+ /*
+ * Validate input.
+ */
+@@ -236,6 +244,7 @@ RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI hEve
+ ASMAtomicAndU32(&pThis->fStateAndGen, ~RTSEMEVENTMULTIBSD_STATE_MASK);
+
+ rtR0SemEventMultiBsdRelease(pThis);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -252,6 +261,7 @@ RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI hEve
+ static int rtR0SemEventMultiBsdWait(PRTSEMEVENTMULTIINTERNAL pThis, uint32_t fFlags, uint64_t uTimeout,
+ PCRTLOCKVALSRCPOS pSrcPos)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ uint32_t fOrgStateAndGen;
+ int rc;
+
+@@ -311,6 +321,7 @@ static int rtR0SemEventMultiBsdWait(PRTSEMEVENTMULTIIN
+ }
+
+ rtR0SemEventMultiBsdRelease(pThis);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return rc;
+ }
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semfastmutex-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semfastmutex-r0drv-freebsd.c
new file mode 100644
index 000000000000..aeab0a76e37c
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semfastmutex-r0drv-freebsd.c
@@ -0,0 +1,59 @@
+--- src/VBox/Runtime/r0drv/freebsd/semfastmutex-r0drv-freebsd.c.orig 2021-01-07 15:42:08 UTC
++++ src/VBox/Runtime/r0drv/freebsd/semfastmutex-r0drv-freebsd.c
+@@ -86,6 +86,7 @@ RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFa
+ {
+ AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
+ AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAllocZ(sizeof(*pThis));
+ if (pThis)
+@@ -94,8 +95,10 @@ RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFa
+ sx_init_flags(&pThis->SxLock, "IPRT Fast Mutex Semaphore", SX_DUPOK);
+
+ *phFastMtx = pThis;
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+@@ -107,11 +110,13 @@ RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFas
+ return VINF_SUCCESS;
+ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
+ AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
+ sx_destroy(&pThis->SxLock);
+ RTMemFree(pThis);
+
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -121,8 +126,11 @@ RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFas
+ PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
+ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
+ AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ sx_xlock(&pThis->SxLock);
++
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -132,8 +140,11 @@ RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFas
+ PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
+ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
+ AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ sx_xunlock(&pThis->SxLock);
++
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semmutex-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semmutex-r0drv-freebsd.c
new file mode 100644
index 000000000000..6345ae10c562
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_semmutex-r0drv-freebsd.c
@@ -0,0 +1,80 @@
+--- src/VBox/Runtime/r0drv/freebsd/semmutex-r0drv-freebsd.c.orig 2018-10-15 14:31:31 UTC
++++ src/VBox/Runtime/r0drv/freebsd/semmutex-r0drv-freebsd.c
+@@ -62,6 +62,7 @@ RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX phMutexSem)
+ {
+ AssertCompile(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));
+ AssertPtrReturn(phMutexSem, VERR_INVALID_POINTER);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)RTMemAllocZ(sizeof(*pThis));
+ if (pThis)
+@@ -70,8 +71,10 @@ RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX phMutexSem)
+ sx_init_flags(&pThis->SxLock, "IPRT Mutex Semaphore", SX_RECURSE);
+
+ *phMutexSem = pThis;
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VERR_NO_MEMORY;
+ }
+
+@@ -83,12 +86,14 @@ RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX hMutexSem)
+ return VINF_SUCCESS;
+ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
+ AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);
+
+ sx_destroy(&pThis->SxLock);
+ RTMemFree(pThis);
+
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -99,6 +104,7 @@ RTDECL(int) RTSemMutexRequest(RTSEMMUTEX hMutexSem, R
+ int rc;
+ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
+ AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ if (cMillies == RT_INDEFINITE_WAIT)
+ {
+@@ -133,6 +139,7 @@ RTDECL(int) RTSemMutexRequest(RTSEMMUTEX hMutexSem, R
+ } while (RTTimeSystemMilliTS() - StartTS < cMillies);
+ }
+
++ IPRT_FREEBSD_RESTORE_EFL_ONLY_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -149,6 +156,7 @@ RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX hMut
+ int rc;
+ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
+ AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ if (cMillies == RT_INDEFINITE_WAIT)
+ {
+@@ -186,6 +194,7 @@ RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX hMut
+ } while (RTTimeSystemMilliTS() - StartTS < cMillies);
+ }
+
++ IPRT_FREEBSD_RESTORE_EFL_ONLY_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -201,8 +210,11 @@ RTDECL(int) RTSemMutexRelease(RTSEMMUTEX hMutexSem)
+ PRTSEMMUTEXINTERNAL pThis = hMutexSem;
+ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
+ AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ sx_xunlock(&pThis->SxLock);
++
++ IPRT_FREEBSD_RESTORE_EFL_ONLY_AC();
+ return VINF_SUCCESS;
+ }
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_spinlock-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_spinlock-r0drv-freebsd.c
new file mode 100644
index 000000000000..4a86a2e38eb2
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_spinlock-r0drv-freebsd.c
@@ -0,0 +1,30 @@
+--- src/VBox/Runtime/r0drv/freebsd/spinlock-r0drv-freebsd.c.orig 2021-01-07 15:42:09 UTC
++++ src/VBox/Runtime/r0drv/freebsd/spinlock-r0drv-freebsd.c
+@@ -106,7 +106,9 @@ RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock, u
+ * Allocate.
+ */
+ AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)RTMemAllocZ(sizeof(*pThis));
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ if (!pThis)
+ return VERR_NO_MEMORY;
+
+@@ -140,7 +142,9 @@ RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
+ * Make the lock invalid and release the memory.
+ */
+ ASMAtomicIncU32(&pThis->u32Magic);
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ RTMemFree(pThis);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -166,6 +170,7 @@ RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock)
+ {
+ RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis);
+ pThis->fIntSaved = fIntSaved;
++ IPRT_FREEBSD_RESTORE_EFL_ONLY_AC_EX(fIntSaved);
+ return;
+ }
+ if (--c <= 0)
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_the-freebsd-kernel.h b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_the-freebsd-kernel.h
new file mode 100644
index 000000000000..c783814425f5
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_the-freebsd-kernel.h
@@ -0,0 +1,48 @@
+--- src/VBox/Runtime/r0drv/freebsd/the-freebsd-kernel.h.orig 2025-04-14 17:59:14 UTC
++++ src/VBox/Runtime/r0drv/freebsd/the-freebsd-kernel.h
+@@ -97,6 +97,7 @@
+ #include <sys/smp.h>
+ #include <sys/sleepqueue.h>
+ #include <sys/sx.h>
++#include <sys/vmmeter.h> /* vm_cnt */
+ #include <vm/vm.h>
+ #include <vm/pmap.h> /* for vtophys */
+ #include <vm/vm_map.h>
+@@ -104,10 +105,11 @@
+ #include <vm/vm_kern.h>
+ #include <vm/vm_param.h> /* KERN_SUCCESS ++ */
+ #include <vm/vm_page.h>
++#include <vm/vm_pager.h>
+ #include <vm/vm_phys.h> /* vm_phys_alloc_* */
+ #include <vm/vm_extern.h> /* kmem_alloc_attr */
+ #include <vm/vm_pageout.h> /* vm_contig_grow_cache */
+-#include <sys/vmmeter.h> /* cnt */
++#include <vm/vm_radix.h>
+ #include <sys/resourcevar.h>
+ #include <machine/cpu.h>
+
+@@ -165,6 +167,24 @@
+ */
+ #if 0 /** @todo Not available yet. */
+ # define USE_KMEM_ALLOC_PROT
++#endif
++
++/**
++ * Macros for preserving EFLAGS.AC (despair / paranoid)
++ */
++#if __FreeBSD_version >= 1200076 && defined(RT_ARCH_AMD64)
++# include <iprt/asm-amd64-x86.h>
++# include <iprt/x86.h>
++# define IPRT_FREEBSD_SAVE_EFL_AC() RTCCUINTREG const fSavedEfl = ASMGetFlags()
++# define IPRT_FREEBSD_RESTORE_EFL_AC() ASMSetFlags(fSavedEfl)
++# define IPRT_FREEBSD_RESTORE_EFL_ONLY_AC() ASMChangeFlags(~X86_EFL_AC, fSavedEfl & X86_EFL_AC)
++# define IPRT_FREEBSD_RESTORE_EFL_ONLY_AC_EX(f) ASMChangeFlags(~X86_EFL_AC, (f) & X86_EFL_AC)
++# define VBOX_WITH_EFLAGS_AC_SET_IN_VBOXDRV
++#else
++# define IPRT_FREEBSD_SAVE_EFL_AC() do { } while (0)
++# define IPRT_FREEBSD_RESTORE_EFL_AC() do { } while (0)
++# define IPRT_FREEBSD_RESTORE_EFL_ONLY_AC() do { } while (0)
++# define IPRT_FREEBSD_RESTORE_EFL_ONLY_AC_EX(f) do { } while (0)
+ #endif
+
+ #endif /* !IPRT_INCLUDED_SRC_r0drv_freebsd_the_freebsd_kernel_h */
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_thread-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_thread-r0drv-freebsd.c
new file mode 100644
index 000000000000..c1ba2d811cde
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_thread-r0drv-freebsd.c
@@ -0,0 +1,91 @@
+--- src/VBox/Runtime/r0drv/freebsd/thread-r0drv-freebsd.c.orig 2021-04-20 04:32:44 UTC
++++ src/VBox/Runtime/r0drv/freebsd/thread-r0drv-freebsd.c
+@@ -49,7 +49,6 @@ RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
+ static int rtR0ThreadFbsdSleepCommon(RTMSINTERVAL cMillies)
+ {
+ int rc;
+- int cTicks;
+
+ /*
+ * 0 ms sleep -> yield.
+@@ -60,30 +59,34 @@ static int rtR0ThreadFbsdSleepCommon(RTMSINTERVAL cMil
+ return VINF_SUCCESS;
+ }
+
++ IPRT_FREEBSD_SAVE_EFL_AC();
++
+ /*
+ * Translate milliseconds into ticks and go to sleep.
+ */
+ if (cMillies != RT_INDEFINITE_WAIT)
+ {
+- if (hz == 1000)
+- cTicks = cMillies;
+- else if (hz == 100)
+- cTicks = cMillies / 10;
+- else
+- {
+- int64_t cTicks64 = ((uint64_t)cMillies * hz) / 1000;
+- cTicks = (int)cTicks64;
+- if (cTicks != cTicks64)
+- cTicks = INT_MAX;
+- }
++ struct timeval tv;
++
++ tv.tv_sec = cMillies / 1000;
++ tv.tv_usec = cMillies * 1000;
++
++ rc = tsleep_sbt((void *)RTThreadSleep,
++ PZERO | PCATCH,
++ "iprtsl", /* max 6 chars */
++ tvtosbt(tv),
++ 0,
++ C_ABSOLUTE);
+ }
+ else
+- cTicks = 0; /* requires giant lock! */
+-
+- rc = tsleep((void *)RTThreadSleep,
+- PZERO | PCATCH,
+- "iprtsl", /* max 6 chars */
+- cTicks);
++ {
++ /* requires giant lock! */
++ rc = tsleep((void *)RTThreadSleep,
++ PZERO | PCATCH,
++ "iprts0", /* max 6 chars */
++ 0);
++ }
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ switch (rc)
+ {
+ case 0:
+@@ -114,11 +117,13 @@ RTDECL(int) RTThreadSleepNoLog(RTMSINTERVAL cMillies)
+
+ RTDECL(bool) RTThreadYield(void)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ #if __FreeBSD_version >= 900032
+ kern_yield(curthread->td_user_pri);
+ #else
+ uio_yield();
+ #endif
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return false; /** @todo figure this one ... */
+ }
+
+@@ -167,12 +172,14 @@ RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTST
+
+ RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC(); /* paranoia */
+ AssertPtr(pState);
+ Assert(pState->u32Reserved == 42);
+ pState->u32Reserved = 0;
+
+ RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
+ critical_exit();
++ IPRT_FREEBSD_RESTORE_EFL_ONLY_AC(); /* paranoia */
+ }
+
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_thread2-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_thread2-r0drv-freebsd.c
new file mode 100644
index 000000000000..c9cd05c42397
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_thread2-r0drv-freebsd.c
@@ -0,0 +1,35 @@
+--- src/VBox/Runtime/r0drv/freebsd/thread2-r0drv-freebsd.c.orig 2021-01-07 15:42:09 UTC
++++ src/VBox/Runtime/r0drv/freebsd/thread2-r0drv-freebsd.c
+@@ -94,6 +94,8 @@ DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT
+ return VERR_INVALID_PARAMETER;
+ }
+
++ IPRT_FREEBSD_SAVE_EFL_AC();
++
+ #if __FreeBSD_version < 700000
+ /* Do like they're doing in subr_ntoskrnl.c... */
+ mtx_lock_spin(&sched_lock);
+@@ -110,6 +112,7 @@ DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT
+ thread_unlock(curthread);
+ #endif
+
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -159,6 +162,7 @@ static void rtThreadNativeMain(void *pvThreadInt)
+
+ DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
+ int rc;
+ struct proc *pProc;
+
+@@ -174,6 +178,7 @@ DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThr
+ }
+ else
+ rc = RTErrConvertFromErrno(rc);
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return rc;
+ }
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_time-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_time-r0drv-freebsd.c
new file mode 100644
index 000000000000..399328e16faa
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_time-r0drv-freebsd.c
@@ -0,0 +1,43 @@
+--- src/VBox/Runtime/r0drv/freebsd/time-r0drv-freebsd.c.orig 2021-01-07 15:42:09 UTC
++++ src/VBox/Runtime/r0drv/freebsd/time-r0drv-freebsd.c
+@@ -64,16 +64,23 @@
+
+ RTDECL(uint64_t) RTTimeNanoTS(void)
+ {
+- struct timespec tsp;
+- nanouptime(&tsp);
+- return tsp.tv_sec * RT_NS_1SEC_64
+- + tsp.tv_nsec;
++ struct bintime bt;
++ uint64_t ns;
++ binuptime(&bt);
++ ns = RT_NS_1SEC_64 * bt.sec;
++ ns += (RT_NS_1SEC_64 * (uint32_t)(bt.frac >> 32)) >> 32;
++ return ns;
+ }
+
+
+ RTDECL(uint64_t) RTTimeMilliTS(void)
+ {
+- return RTTimeNanoTS() / RT_NS_1MS;
++ struct bintime bt;
++ uint64_t ms;
++ binuptime(&bt);
++ ms = RT_MS_1SEC_64 * bt.sec;
++ ms += (RT_MS_1SEC_64 * (uint32_t)(bt.frac >> 32)) >> 32;
++ return ms;
+ }
+
+
+@@ -91,8 +98,7 @@ RTDECL(uint64_t) RTTimeSystemMilliTS(void)
+
+ RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
+ {
+- struct timespec tsp;
+- nanotime(&tsp);
+- return RTTimeSpecSetTimespec(pTime, &tsp);
++ struct timespec ts;
++ nanotime(&ts);
++ return RTTimeSpecSetTimespec(pTime, &ts);
+ }
+-
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_timer-r0drv-freebsd.c b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_timer-r0drv-freebsd.c
new file mode 100644
index 000000000000..ee5b90f13c51
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r0drv_freebsd_timer-r0drv-freebsd.c
@@ -0,0 +1,68 @@
+--- src/VBox/Runtime/r0drv/freebsd/timer-r0drv-freebsd.c.orig 2021-01-07 15:42:09 UTC
++++ src/VBox/Runtime/r0drv/freebsd/timer-r0drv-freebsd.c
+@@ -116,6 +116,7 @@ static void rtTimerFreeBSDCallback(void *pvTimer);
+ RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, uint32_t fFlags, PFNRTTIMER pfnTimer, void *pvUser)
+ {
+ *ppTimer = NULL;
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ /*
+ * Validate flags.
+@@ -145,6 +146,7 @@ RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_
+ callout_init(&pTimer->Callout, CALLOUT_MPSAFE);
+
+ *ppTimer = pTimer;
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -165,6 +167,8 @@ DECLINLINE(bool) rtTimerIsValid(PRTTIMER pTimer)
+
+ RTDECL(int) RTTimerDestroy(PRTTIMER pTimer)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
++
+ /* It's ok to pass NULL pointer. */
+ if (pTimer == /*NIL_RTTIMER*/ NULL)
+ return VINF_SUCCESS;
+@@ -177,6 +181,8 @@ RTDECL(int) RTTimerDestroy(PRTTIMER pTimer)
+ pTimer->u32Magic++;
+ callout_stop(&pTimer->Callout);
+ RTMemFree(pTimer);
++
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+@@ -184,6 +190,7 @@ RTDECL(int) RTTimerDestroy(PRTTIMER pTimer)
+ RTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First)
+ {
+ struct timeval tv;
++ IPRT_FREEBSD_SAVE_EFL_AC();
+
+ if (!rtTimerIsValid(pTimer))
+ return VERR_INVALID_HANDLE;
+@@ -207,12 +214,15 @@ RTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64
+ tv.tv_usec = (u64First % 1000000000) / 1000;
+ callout_reset(&pTimer->Callout, tvtohz(&tv), rtTimerFreeBSDCallback, pTimer);
+
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
+
+ RTDECL(int) RTTimerStop(PRTTIMER pTimer)
+ {
++ IPRT_FREEBSD_SAVE_EFL_AC();
++
+ if (!rtTimerIsValid(pTimer))
+ return VERR_INVALID_HANDLE;
+ if (pTimer->fSuspended)
+@@ -224,6 +234,7 @@ RTDECL(int) RTTimerStop(PRTTIMER pTimer)
+ pTimer->fSuspended = true;
+ callout_stop(&pTimer->Callout);
+
++ IPRT_FREEBSD_RESTORE_EFL_AC();
+ return VINF_SUCCESS;
+ }
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r3_freebsd_systemmem-freebsd.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r3_freebsd_systemmem-freebsd.cpp
new file mode 100644
index 000000000000..87ae993446a3
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r3_freebsd_systemmem-freebsd.cpp
@@ -0,0 +1,39 @@
+--- src/VBox/Runtime/r3/freebsd/systemmem-freebsd.cpp.orig 2025-04-14 17:59:18 UTC
++++ src/VBox/Runtime/r3/freebsd/systemmem-freebsd.cpp
+@@ -75,7 +75,6 @@ RTDECL(int) RTSystemQueryAvailableRam(uint64_t *pcb)
+ u_int cPagesMemFree = 0;
+ u_int cPagesMemInactive = 0;
+ u_int cPagesMemCached = 0;
+- u_int cPagesMemUsed = 0;
+ int cbPage = 0;
+ size_t cbParameter;
+ int cProcessed = 0;
+@@ -83,25 +82,23 @@ RTDECL(int) RTSystemQueryAvailableRam(uint64_t *pcb)
+ cbParameter = sizeof(cPagesMemFree);
+ if (sysctlbyname("vm.stats.vm.v_free_count", &cPagesMemFree, &cbParameter, NULL, 0))
+ rc = RTErrConvertFromErrno(errno);
+- cbParameter = sizeof(cPagesMemUsed);
+- if ( RT_SUCCESS(rc)
+- && sysctlbyname("vm.stats.vm.v_active_count", &cPagesMemUsed, &cbParameter, NULL, 0))
+- rc = RTErrConvertFromErrno(errno);
+ cbParameter = sizeof(cPagesMemInactive);
+ if ( RT_SUCCESS(rc)
+ && sysctlbyname("vm.stats.vm.v_inactive_count", &cPagesMemInactive, &cbParameter, NULL, 0))
+ rc = RTErrConvertFromErrno(errno);
++#if __FreeBSD_version < 1200016
+ cbParameter = sizeof(cPagesMemCached);
+ if ( RT_SUCCESS(rc)
+ && sysctlbyname("vm.stats.vm.v_cache_count", &cPagesMemCached, &cbParameter, NULL, 0))
+ rc = RTErrConvertFromErrno(errno);
++#endif
+ cbParameter = sizeof(cbPage);
+ if ( RT_SUCCESS(rc)
+ && sysctlbyname("hw.pagesize", &cbPage, &cbParameter, NULL, 0))
+ rc = RTErrConvertFromErrno(errno);
+
+ if (RT_SUCCESS(rc))
+- *pcb = (cPagesMemFree + cPagesMemInactive + cPagesMemCached ) * cbPage;
++ *pcb = ((uint64_t)cPagesMemFree + cPagesMemInactive + cPagesMemCached) * cbPage;
+
+ return rc;
+ }
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r3_posix_process-creation-posix.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r3_posix_process-creation-posix.cpp
new file mode 100644
index 000000000000..83cabcb77b97
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_Runtime_r3_posix_process-creation-posix.cpp
@@ -0,0 +1,38 @@
+--- src/VBox/Runtime/r3/posix/process-creation-posix.cpp.orig 2022-01-13 18:58:24 UTC
++++ src/VBox/Runtime/r3/posix/process-creation-posix.cpp
+@@ -30,7 +30,7 @@
+ *********************************************************************************************************************************/
+ #define LOG_GROUP RTLOGGROUP_PROCESS
+ #include <iprt/cdefs.h>
+-#ifdef RT_OS_LINUX
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
+ # define IPRT_WITH_DYNAMIC_CRYPT_R
+ #endif
+ #if (defined(RT_OS_LINUX) || defined(RT_OS_OS2)) && !defined(_GNU_SOURCE)
+@@ -69,7 +69,7 @@
+ # include <shadow.h>
+ #endif
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_OS2)
++#if defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)
+ /* While Solaris has posix_spawn() of course we don't want to use it as
+ * we need to have the child in a different process contract, no matter
+ * whether it is started detached or not. */
+@@ -157,7 +157,7 @@
+ # define IPRT_LIBPAM_FILE_3 "libpam.1.dylib"
+ # define IPRT_LIBPAM_FILE_3_FIRST_VER 0
+ # define IPRT_LIBPAM_FILE_3_END_VER 0
+-# elif RT_OS_LINUX
++# elif RT_OS_LINUX || RT_OS_FREEBSD
+ # define IPRT_LIBPAM_FILE_1 "libpam.so.0"
+ # define IPRT_LIBPAM_FILE_1_FIRST_VER 0
+ # define IPRT_LIBPAM_FILE_1_END_VER 0
+@@ -572,7 +572,7 @@ static int rtCheckCredentials(const char *pszUser, con
+ if (pPw->pw_passwd && *pPw->pw_passwd)
+ # endif
+ {
+-# if defined(RT_OS_LINUX) || defined(RT_OS_OS2)
++# if defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)
+ # ifdef IPRT_WITH_DYNAMIC_CRYPT_R
+ size_t const cbCryptData = RT_MAX(sizeof(struct crypt_data) * 2, _256K);
+ # else
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VBox_VMM_VMMR3_PDMAsyncCompletionFileNormal.cpp b/emulators/virtualbox-ose-71/files/patch-src_VBox_VMM_VMMR3_PDMAsyncCompletionFileNormal.cpp
new file mode 100644
index 000000000000..b04b05811f86
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VBox_VMM_VMMR3_PDMAsyncCompletionFileNormal.cpp
@@ -0,0 +1,59 @@
+--- src/VBox/VMM/VMMR3/PDMAsyncCompletionFileNormal.cpp.orig 2021-04-19 21:33:04.000000000 -0700
++++ src/VBox/VMM/VMMR3/PDMAsyncCompletionFileNormal.cpp 2021-05-18 11:45:08.396136000 -0700
+@@ -27,6 +27,13 @@
+ #include <iprt/string.h>
+ #include <iprt/assert.h>
+ #include <VBox/log.h>
++/* TBR: we need a complicated crawl through the data structure to get the AIO system limits
++ to check when considering growing the number of active AIO requests.... */
++/* We need the PDMInternal *before* the UVM, or it isn't visible afterwards. (src/VBox/VMM/include/PDMInternal.h) */
++#include <PDMInternal.h>
++#include <VBox/vmm/uvm.h>
++#include <VBox/vmm/vm.h>
++/* TBR: end of extra includes. */
+
+ #include "PDMAsyncCompletionFileInternal.h"
+
+@@ -1120,8 +1127,40 @@
+ */
+ pdmacFileAioMgrNormalBalanceLoad(pAioMgr);
+ #else
+- /* Grow the I/O manager */
+- pAioMgr->enmState = PDMACEPFILEMGRSTATE_GROWING;
++ /* TBR: Check the global AIO system limit before growing.
++ This is the complicateds crawl through the data structure mentioned
++ near the start of this file.
++ There HAS to be a better way and better time to get this limit! */
++ PPDMASYNCCOMPLETIONEPCLASS pEpClass = NULL;
++ PCPDMASYNCCOMPLETIONEPCLASSOPS pEndpointOps = NULL;
++ PDMASYNCCOMPLETIONEPCLASSTYPE enmClassType;
++ PPDMASYNCCOMPLETIONEPCLASSFILE pEpClassFile = NULL;
++ PVM pVM = NULL;
++ PUVM pUVM = NULL;
++ unsigned int aio_system_reqests_max = RTFILEAIO_UNLIMITED_REQS;
++ pEpClass = pEndpoint->Core.pEpClass;
++ AssertMsg((NULL != pEpClass),("ep->class is NULL"));
++ pEndpointOps = pEpClass->pEndpointOps;
++ AssertMsg((NULL != pEndpointOps),("ep->class->ops is NULL"));
++ enmClassType = pEndpointOps->enmClassType;
++ AssertMsg((PDMASYNCCOMPLETIONEPCLASSTYPE_FILE == enmClassType),
++ ("ep->class->ops->type != PDMASYNCCOMPLETIONEPCLASSTYPE_FILE"));
++ pVM = pEpClass->pVM;
++ AssertMsg((NULL != pVM),("ep->class->VM is NULL"));
++ pUVM = pVM->pUVM;
++ AssertMsg((NULL != pUVM),("ep->class->VM->UVM is NULL"));
++ pEpClassFile = (PPDMASYNCCOMPLETIONEPCLASSFILE) (pUVM->pdm.s.apAsyncCompletionEndpointClass[enmClassType]);
++ AssertMsg((NULL != pEpClassFile),("ep->class->VM->UVM->pdn[globals] is NULL"));
++ aio_system_reqests_max = pEpClassFile->cReqsOutstandingMax;
++#if 0
++ /* A one time check during development to verify getting the right number. */
++ AssertMsg((256 != aio_system_reqests_max),
++ ("aio_system_reqests_max != 256 (val=%u)",aio_system_reqests_max));
++#endif
++ if (RT_UNLIKELY( aio_system_reqests_max == RTFILEAIO_UNLIMITED_REQS
++ || (pAioMgr->cRequestsActiveMax+PDMACEPFILEMGR_REQS_STEP) <= aio_system_reqests_max))
++ /* Grow the I/O manager */
++ pAioMgr->enmState = PDMACEPFILEMGRSTATE_GROWING;
+ #endif
+ }
+ }
diff --git a/emulators/virtualbox-ose-71/files/patch-src_VMM_Config.kmk b/emulators/virtualbox-ose-71/files/patch-src_VMM_Config.kmk
new file mode 100644
index 000000000000..1c44352c9409
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_VMM_Config.kmk
@@ -0,0 +1,11 @@
+--- src/VBox/VMM/Config.kmk.orig 2024-12-27 03:55:34.269311000 +0100
++++ src/VBox/VMM/Config.kmk 2024-12-27 03:42:41.858673000 +0100
+@@ -91,7 +91,7 @@
+ VMM_COMMON_DEFS += VBOX_WITH_NATIVE_NEM VBOX_WITH_NEM_R0
+ endif
+ endif
+-if1of ($(KBUILD_TARGET), freebsd linux solaris) # Hosts that implements SUPR0HCPhysToVirt.
++if1of ($(KBUILD_TARGET), linux solaris) # Hosts that implements SUPR0HCPhysToVirt.
+ VMM_COMMON_DEFS += VBOX_WITH_LINEAR_HOST_PHYS_MEM
+ endif
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_Makefile.kmk b/emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_Makefile.kmk
new file mode 100644
index 000000000000..c87ba535edb0
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_Makefile.kmk
@@ -0,0 +1,11 @@
+--- src/libs/xpcom18a4/Makefile.kmk.orig 2021-01-07 15:44:04 UTC
++++ src/libs/xpcom18a4/Makefile.kmk
+@@ -985,6 +985,8 @@ VBoxXPCOM_LIBS = \
+ $(VBox-xpcom-proxy_1_TARGET) \
+ $(VBox-xpcom-nspr_1_TARGET) \
+ $(VBoxXPCOMGlue_s_1_TARGET)
++VBoxXPCOM_LIBS.freebsd = \
++ pthread
+ VBoxXPCOM_LIBS.linux = \
+ pthread dl
+
diff --git a/emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_nsprpub_pr_src_pthreads_ptsynch.c b/emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_nsprpub_pr_src_pthreads_ptsynch.c
new file mode 100644
index 000000000000..4d556c7cf5a0
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_nsprpub_pr_src_pthreads_ptsynch.c
@@ -0,0 +1,13 @@
+--- src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptsynch.c.orig 2025-01-21 20:03:59.000000000 +0700
++++ src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptsynch.c 2025-01-23 01:00:59.324267000 +0700
+@@ -45,6 +45,10 @@
+ #include <string.h>
+ #include <pthread.h>
+ #include <sys/time.h>
++#ifdef FREEBSD
++#include <sys/param.h>
++#endif
++
+ #include <errno.h>
+
+ #include <iprt/asm.h>
diff --git a/emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_xpcom_io_nsLocalFileUnix.h b/emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_xpcom_io_nsLocalFileUnix.h
new file mode 100644
index 000000000000..13af9aa6bffa
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/patch-src_libs_xpcom18a4_xpcom_io_nsLocalFileUnix.h
@@ -0,0 +1,17 @@
+--- src/libs/xpcom18a4/xpcom/io/nsLocalFileUnix.h.orig 2020-05-13 19:46:34 UTC
++++ src/libs/xpcom18a4/xpcom/io/nsLocalFileUnix.h
+@@ -72,14 +72,6 @@
+ #define STATFS statfs
+ #endif
+
+-// so we can statfs on freebsd
+-#if defined(__FreeBSD__)
+- #define HAVE_SYS_STATFS_H
+- #define STATFS statfs
+- #include <sys/param.h>
+- #include <sys/mount.h>
+-#endif
+-
+ class NS_COM nsLocalFile : public nsILocalFile
+ {
+ public:
diff --git a/emulators/virtualbox-ose-71/files/pkg-message.in b/emulators/virtualbox-ose-71/files/pkg-message.in
new file mode 100644
index 000000000000..27c14e0a2e2a
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/pkg-message.in
@@ -0,0 +1,120 @@
+[
+{ type: install
+ message: <<EOM
+VirtualBox was installed.
+
+You need to load the vboxdrv kernel module via /boot/loader.conf:
+
+vboxdrv_load="YES"
+
+You also have to add all users to your vboxusers group in order to use vbox.
+
+% pw groupmod vboxusers -m jerry
+
+Reboot the machine to load the needed kernel modules.
+
+
+Bridging Support:
+=================
+
+For bridged networking please add the following line to your /etc/rc.conf:
+
+vboxnet_enable="YES"
+
+
+USB Support:
+============
+
+For USB support your user needs to be in the operator group and needs read
+and write permissions to the USB device.
+
+% pw groupmod operator -m jerry
+
+Add the following to /etc/devfs.rules (create if it doesn't exist):
+
+[system=10]
+add path 'usb/*' mode 0660 group operator
+
+To load these new rule add the following to /etc/rc.conf:
+
+devfs_system_ruleset="system"
+
+Then restart devfs to load the new rules:
+
+% /etc/rc.d/devfs restart
+
+
+Troubleshooting:
+================
+
+Running VirtualBox as non-root user may fail with a fatal error
+NS_ERROR_FACTORY_NOT_REGISTERED. In this case delete /tmp/.vbox-*-ipc file.
+
+If you experience "Network: write Failed: Cannot allocate memory" errors
+try to increase net.graph.maxdata in /boot/loader.conf
+
+If you are using AIO, then increase these limits (https://bugs.freebsd.org/168298):
+vfs.aio.max_buf_aio=8192
+vfs.aio.max_aio_queue_per_proc=65536
+vfs.aio.max_aio_per_proc=8192
+vfs.aio.max_aio_queue=65536
+To check if AIO is used use: kldstat -v | grep aio
+
+If you are experiencing VMs freezes with an error in VBox.log such as:
+"
+00:01:29.590192 AssertLogRel /usr/ports/emulators/virtualbox-ose/work/VirtualBox-6.1.44
+/src/VBox/VMM/VMMR3/PGMPhys.cpp(5148) int PGMR3PhysAllocateHandyPages(PVM): RT_SUCCESS(rc)
+00:01:29.590221 87/128: idPage=0x3d400 HCPhysGCPhys=000000027eaed000 rc=VERR_NO_MEMORY
+00:01:29.590247 Changing the VM state from 'RUNNING' to 'GURU_MEDITATION'
+00:01:29.590261 Console: Machine state changed to 'GuruMeditation'
+00:01:29.590695 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+00:01:29.590696 !!
+00:01:29.590697 !! VCPU0: Guru Meditation -8 (VERR_NO_MEMORY)
+"
+and see a lot of free RAM, then increase sysctl vm.max_user_wired
+(https://bugs.freebsd.org/252227).
+For dedicated VM servers, a good start is:
+("RAM in GB" - max(1, "RAM in GB" / 32)) * 1024*1024*1024 / PAGE_SIZE
+PAGE_SIZE on x86 is 4096.
+Examples with different RAM sizes in GB:
+ 16: ( 16-max(1, 16/32)*1024*1024*1024/4096 = 3932160 => 15GB
+ 32: ( 32-max(1, 32/32)*1024*1024*1024/4096 = 8126464 => 31GB
+ 48: ( 48-max(1, 48/32)*1024*1024*1024/4096 = 12189696 => 46.5GB
+ 64: ( 64-max(1, 64/32)*1024*1024*1024/4096 = 16252928 => 62GB
+128: (128-max(1,128/32)*1024*1024*1024/4096 = 32505856 => 124GB
+256: (256-max(1,256/32)*1024*1024*1024/4096 = 65011712 => 248GB
+
+When assigning IP addresses in host-only mode from ranges outside
+of VirtualBox's defaults, the respective ranges need to be listed
+in %%VBOX_ETC%%/networks.conf (https://bugs.freebsd.org/259399).
+
+Check the wiki page for known issues and troubleshooting:
+https://wiki.freebsd.org/VirtualBox
+
+Please report any problems to emulation@. Thanks!
+EOM
+}
+{ type: upgrade
+ maximum_version: 6.1.22
+ message: <<EOM
+The PULSEAUDIO option has been forcibly disabled since VirtualBox
+version 6.1.24 due to a bug in it preventing virtual machines
+configured to use it from starting.
+
+When upgrading from a previous version please reconfigure any virtual
+machines using the Pulseaudio host audio driver to use another
+supported one.
+EOM
+}
+{ type: upgrade
+ minimum_version: 6.1.26
+ maximum_version: 6.1.32_1
+ message: <<EOM
+To comply to hier(7) requirements, networks.conf's location changed
+to %%VBOX_ETC%%/networks.conf.
+
+In case /etc/vbox/networks.conf exists, it needs to be moved to
+%%VBOX_ETC%% and /etc/vbox should be deleted.
+EOM
+}
+]
diff --git a/emulators/virtualbox-ose-71/files/vboxheadless.in b/emulators/virtualbox-ose-71/files/vboxheadless.in
new file mode 100644
index 000000000000..5ddc5fc21d6c
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/vboxheadless.in
@@ -0,0 +1,140 @@
+#!/bin/sh
+
+# PROVIDE: vboxheadless
+# REQUIRE: LOGIN vboxnet
+# KEYWORD: shutdown
+#
+# Add the following line to /etc/rc.conf[.local] to enable vboxheadless
+#
+# vboxheadless_enable (bool): Set to "NO" by default.
+# Set it to "YES" to enable vboxheadless.
+# vboxheadless_machines (str): Space separated list of machines
+# vboxheadless_user (str): Default user account to run with.
+# (default: %%VBOXUSER%%)
+# vboxheadless_stop (str): Default stop cmd for VBoxManage controlvm.
+# (default: savestate)
+# vboxheadless_delay (int): Default startup/shutdown delay in seconds.
+# (default: 0)
+# vboxheadless_<machine>_name (str): Virtualbox machine name or UUID.
+# vboxheadless_<machine>_user (str): User account to run with.
+# vboxheadless_<machine>_flags (str): Additional flags for VBoxHeadless.
+# vboxheadless_<machine>_stop (str): Stop command for VBoxManage controlvm.
+# vboxheadless_<machine>_delay (int): Startup and shutdown delay in seconds.
+
+. /etc/rc.subr
+
+name="vboxheadless"
+rcvar=vboxheadless_enable
+rc_fast="YES"
+
+command="%%VBOXDIR%%/VBoxHeadless"
+pidbase="/var/run/${name}"
+
+start_cmd="${name}_start"
+stop_cmd="${name}_stop"
+status_cmd="${name}_status"
+
+vboxheadless_start()
+{
+ local machine mpidfile pid vmname vmuser vmflags vmdelay
+
+ echo "Starting Virtual Machines:"
+ for machine in ${vboxheadless_machines}; do
+ mpidfile="${pidbase}_${machine}.pid"
+ pid=$(check_pidfile $mpidfile $command)
+ eval vmname="\${vboxheadless_${machine}_name:-${machine}}"
+ eval vmuser="\${vboxheadless_${machine}_user:-${vboxheadless_user}}"
+ eval vmflags="\${vboxheadless_${machine}_flags:-}"
+ eval vmdelay="\${vboxheadless_${machine}_delay:-${vboxheadless_delay}}"
+
+ HOME=$(/usr/sbin/pw usershow -7 -n "${vmuser}" | /usr/bin/cut -d: -f6)
+
+ /usr/bin/printf "%25s " "${vmname}"
+
+ /usr/bin/su ${vmuser} -c "%%VBOXDIR%%/VBoxManage showvminfo '${vmname}' >/dev/null" 2>/dev/null
+
+ if [ $? != 0 ]; then
+ echo "Unknown machine"
+ continue
+ fi
+
+ if [ -n "${pid}" ]; then
+ echo "Already running? (pid=${pid})"
+ continue
+ fi
+
+ /bin/sleep ${vmdelay}
+ /usr/bin/install -o ${vmuser} -g %%VBOXGROUP%% -m 644 /dev/null ${mpidfile}
+ /usr/sbin/daemon -f -p ${mpidfile} -u ${vmuser} ${command} --startvm "${vmname}" ${vmflags}
+ echo "Started"
+ done
+}
+
+vboxheadless_stop()
+{
+ local machine mpidfile pid pids vmname vmuser vmstop vmdelay
+
+ echo "Saving states for Virtual Machines:"
+ for machine in ${vboxheadless_machines}; do
+ mpidfile="${pidbase}_${machine}.pid"
+ pid=$(check_pidfile $mpidfile $command)
+ eval vmname="\${vboxheadless_${machine}_name:-${machine}}"
+ eval vmuser="\${vboxheadless_${machine}_user:-${vboxheadless_user}}"
+ eval vmstop="\${vboxheadless_${machine}_stop:-${vboxheadless_stop}}"
+ eval vmdelay="\${vboxheadless_${machine}_delay:-${vboxheadless_delay}}"
+
+ /usr/bin/printf "%25s " "${vmname}"
+
+ if [ -n "${pid}" ]; then
+ pids="${pids} ${pid}"
+ /bin/sleep ${vmdelay}
+ /usr/bin/su ${vmuser} -c "%%VBOXDIR%%/VBoxManage controlvm '${vmname}' ${vmstop} >/dev/null &" 2>/dev/null
+ fi
+ done
+ if [ -n "${pids}" ]; then
+ wait_for_pids $pids >/dev/null
+ echo "Stopped"
+ else
+ echo "Not running?"
+ fi
+}
+
+vboxheadless_status()
+{
+ local machine mpidfile pid vmname vmuser
+
+ /usr/bin/printf "%25s %s\n" "Machine" "Status"
+ /usr/bin/printf "%25s %s\n" "-------------------------" "------------"
+
+ for machine in ${vboxheadless_machines}; do
+ mpidfile="${pidbase}_${machine}.pid"
+ pid=$(check_pidfile $mpidfile $command)
+ eval vmname="\${vboxheadless_${machine}_name:-${machine}}"
+ eval vmuser="\${vboxheadless_${machine}_user:-${vboxheadless_user}}"
+
+ /usr/bin/su ${vmuser} -c "%%VBOXDIR%%/VBoxManage showvminfo '${vmname}' >/dev/null" 2>/dev/null
+
+ if [ $? != 0 ]; then
+ /usr/bin/printf "%20s %s\n" "${vmname}" "Unknown Machine"
+ elif [ -n "${pid}" ]; then
+ /usr/bin/printf "%25s %s\n" "${vmname}" "Running"
+ else
+ /usr/bin/printf "%25s %s\n" "${vmname}" "Powered Off"
+ fi
+ done
+}
+
+load_rc_config $name
+
+: ${vboxheadless_enable="NO"}
+: ${vboxheadless_user="%%VBOXUSER%%"}
+: ${vboxheadless_stop="savestate"}
+: ${vboxheadless_delay="0"}
+
+cmd_arg="$1" ; shift
+
+if [ -n "$*" ]; then
+ vboxheadless_machines="$*"
+fi
+
+run_rc_command "${cmd_arg}"
diff --git a/emulators/virtualbox-ose-71/files/vboxinit.in b/emulators/virtualbox-ose-71/files/vboxinit.in
new file mode 100644
index 000000000000..13ec9614827d
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/vboxinit.in
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+# PROVIDE: vboxinit
+# REQUIRE: LOGIN vboxnet vboxwebsrv sshd
+# KEYWORD: shutdown
+#
+# Add the following line to /etc/rc.conf[.local] to enable vboxinit
+#
+# vboxinit_enable (bool): Set to "NO" by default.
+# Set it to "YES" to enable vboxinit.
+# stop and faststop are always enabled.
+# vboxinit_user (str): Default user account to run with.
+# (default: %%VBOXUSER%%)
+# vboxinit_home (str): Default home directory to run with.
+# (default: home of user ${vboxinit_user}
+# vboxinit_stop (str): Default stop cmd for VBoxManage controlvm.
+# (default: savestate)
+# vboxinit_start_delay (int): Default startup delay in seconds.
+# (default: 0)
+# vboxinit_stop_delay (int): Default shutdown delay in seconds.
+# (default: 0)
+#
+# Set the "Startup Mode" to "Automatic" for the virtual machine in
+# phpvirtualbox to automatically start the virtual machine during OS boot.
+#
+
+. /etc/rc.subr
+
+name="vboxinit"
+rcvar="${name}_enable"
+
+start_cmd="${name}_start"
+stop_cmd="${name}_stop"
+status_cmd="${name}_status"
+restart_cmd="${name}_restart"
+
+vboxinit_start()
+{
+ # Get a list of all machines with autorun enabled in phpvirtualbox
+ ${su_command} "${command} list vms | /usr/bin/tr -d '{}\"'" | while read VMNAME UUID; do
+ STARTUP=$(${su_command} "${command} getextradata ${UUID} 'pvbx/startupMode'" | /usr/bin/cut -d' ' -f2)
+ if [ "${STARTUP}" == "auto" ]; then
+ echo "${name}: starting machine ${VMNAME} ..."
+ ${su_command} "${command} startvm ${UUID} --type headless"
+ sleep "${vboxinit_start_delay}"
+ fi
+ done
+}
+
+vboxinit_stop()
+{
+ # Get all running machines
+ ${su_command} "${command} list runningvms | /usr/bin/tr -d '{}\"'" | while read VMNAME UUID; do
+ echo "${name}: stopping machine ${VMNAME} with action '${vboxinit_stop}' ..."
+ ${su_command} "${command} controlvm ${UUID} ${vboxinit_stop}"
+ sleep "${vboxinit_stop_delay}"
+ done
+}
+
+vboxinit_status()
+{
+ # List all running machines
+ ${su_command} "${command} list runningvms"
+}
+
+vboxinit_restart()
+{
+ vboxinit_stop
+ vboxinit_start
+}
+
+load_rc_config $name
+
+: ${vboxinit_enable="NO"}
+: ${vboxinit_user="%%VBOXUSER%%"}
+: ${vboxinit_home=$(/usr/sbin/pw usershow -7 -n "${vboxinit_user}" | /usr/bin/cut -d: -f6)}
+: ${vboxinit_stop="savestate"}
+: ${vboxinit_start_delay="0"}
+: ${vboxinit_stop_delay="0"}
+HOME=${vboxinit_home}
+USER=${vboxinit_user}
+export HOME USER
+
+command="%%VBOXDIR%%/VBoxManage"
+su_command="/usr/bin/su -m ${vboxinit_user} -c"
+
+if [ "x$1" = "xstop" ] || [ "x$1" = "xfaststop" ]; then
+ vboxinit_enable="YES"
+fi
+
+run_rc_command "$1"
diff --git a/emulators/virtualbox-ose-71/files/vboxwatchdog.in b/emulators/virtualbox-ose-71/files/vboxwatchdog.in
new file mode 100644
index 000000000000..c21bc03b3523
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/vboxwatchdog.in
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+# PROVIDE: vboxwatchdog
+# REQUIRE: LOGIN
+# KEYWORD: shutdown
+#
+# Add the following line to /etc/rc.conf[.local] to enable vboxwatchdog
+#
+# vboxwatchdog_enable (bool): Set to "NO" by default.
+# Set it to "YES" to enable vboxwatchdog.
+# vboxwatchdog_user (str): User account to run with.
+# vboxwatchdog_flags (str): Custom flags for VBoxWatchdog.
+
+. /etc/rc.subr
+
+name=vboxwatchdog
+rcvar=vboxwatchdog_enable
+
+command="%%VBOXDIR%%/VBoxBalloonCtrl"
+pidfile="/var/run/${name}.pid"
+
+start_cmd="${name}_start"
+
+vboxwatchdog_start()
+{
+ local pid
+
+ HOME=$(/usr/sbin/pw usershow -7 -n "${vboxwatchdog_user}" | /usr/bin/cut -d: -f6)
+ pid=$(check_pidfile $pidfile $command)
+
+ if [ -n "${pid}" ]; then
+ echo "${name} already running? (pid=${pid})."
+ return 1
+ fi
+
+ # prevent inheriting this setting to VBoxSVC
+ unset VBOX_RELEASE_LOG_DEST
+
+ echo -n "Starting ${name}"
+ /usr/bin/install -o ${vboxwatchdog_user} -g %%VBOXGROUP%% -m 644 /dev/null ${pidfile}
+ /usr/sbin/daemon -f -p ${pidfile} -u ${vboxwatchdog_user} ${command} ${vboxwatchdog_flags}
+ echo '.'
+}
+
+load_rc_config $name
+
+: ${vboxwatchdog_enable="NO"}
+: ${vboxwatchdog_user="%%VBOXUSER%%"}
+: ${vboxwatchdog_flags=""}
+
+run_rc_command "$1"
diff --git a/emulators/virtualbox-ose-71/files/vboxwebsrv.in b/emulators/virtualbox-ose-71/files/vboxwebsrv.in
new file mode 100644
index 000000000000..a7e1e38e3090
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/vboxwebsrv.in
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+# PROVIDE: vboxwebsrv
+# REQUIRE: LOGIN
+# KEYWORD: shutdown
+#
+# Add the following line to /etc/rc.conf[.local] to enable vboxwebsrv
+#
+# vboxwebsrv_enable (bool): Set to "NO" by default.
+# Set it to "YES" to enable vboxwebsrv.
+# vboxwebsrv_user (str): User account to run with.
+# vboxwebsrv_flags (str): Custom flags for vboxwebsrv.
+
+. /etc/rc.subr
+
+name=vboxwebsrv
+rcvar=vboxwebsrv_enable
+
+command="%%VBOXDIR%%/vboxwebsrv"
+pidfile="/var/run/${name}.pid"
+
+start_cmd="${name}_start"
+
+vboxwebsrv_start()
+{
+ local pid
+
+ HOME=$(/usr/sbin/pw usershow -7 -n "${vboxwebsrv_user}" | /usr/bin/cut -d: -f6)
+ pid=$(check_pidfile $pidfile $command)
+
+ if [ -n "${pid}" ]; then
+ echo "${name} already running? (pid=${pid})."
+ return 1
+ fi
+
+ echo -n "Starting ${name}"
+ /usr/bin/install -o ${vboxwebsrv_user} -g %%VBOXGROUP%% -m 644 /dev/null ${pidfile}
+ /usr/sbin/daemon -f -p ${pidfile} -u ${vboxwebsrv_user} ${command} ${vboxwebsrv_flags}
+ echo '.'
+}
+
+load_rc_config $name
+
+: ${vboxwebsrv_enable="NO"}
+: ${vboxwebsrv_user="%%VBOXWSUSER%%"}
+
+run_rc_command "$1"
diff --git a/emulators/virtualbox-ose-71/files/virtualbox.desktop b/emulators/virtualbox-ose-71/files/virtualbox.desktop
new file mode 100644
index 000000000000..b0d09e2128b7
--- /dev/null
+++ b/emulators/virtualbox-ose-71/files/virtualbox.desktop
@@ -0,0 +1,17 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Name=Oracle VM VirtualBox
+GenericName=Virtual Machine
+Type=Application
+Exec=VirtualBox
+TryExec=VirtualBox
+Icon=VBox
+Categories=Emulator;System;
+Comment=Run several virtual systems on a single host computer
+Comment[de]=Windows und andere Betriebssysteme unter FreeBSD ausführen
+Comment[it]=Esegui più macchine virtuali su un singolo computer
+Comment[ko]=가상 머신
+Comment[pl]=Uruchamianie wielu systemów wirtualnych na jednym komputerze gospodarza
+Comment[ru]=Запуск нескольких виртуальных машин на одном компьютере
+Comment[sv]=Kör flera virtuella system på en enda värddator