pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Import virtualbox-5.0.16 as wip/virtualbox.
Module Name: pkgsrc-wip
Committed By: Kamil Rytarowski <n54%gmx.com@localhost>
Pushed By: kamil
Date: Thu Jul 7 15:19:54 2016 +0200
Changeset: 89404835ab2074464dd1f874bef88fb6549b5559
Added Files:
virtualbox/DESCR
virtualbox/Makefile
virtualbox/PLIST
virtualbox/distinfo
virtualbox/patches/patch-Config.kmk
virtualbox/patches/patch-Makefile.kmk
virtualbox/patches/patch-configure
virtualbox/patches/patch-include_VBox_VBoxGuest.h
virtualbox/patches/patch-include_VBox_ostypes.h
virtualbox/patches/patch-include_VBox_param.h
virtualbox/patches/patch-include_VBox_usb.h
virtualbox/patches/patch-include_iprt_string.h
virtualbox/patches/patch-src_VBox_Additions_Makefile.kmk
virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuestLib_VBoxGuestR3Lib.cpp
virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuestLib_VBoxGuestR3LibLog.cpp
virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_Makefile.kmk
virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuest-netbsd.c
virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuest.cpp
virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuestInternal.h
virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_netbsd_Makefile
virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_netbsd_files__vboxguest
virtualbox/patches/patch-src_VBox_Additions_common_VBoxService_VBoxService.cpp
virtualbox/patches/patch-src_VBox_Additions_common_VBoxService_VBoxServiceVMInfo.cpp
virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_Makefile.kmk
virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_NetBSD__exports.py
virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_fakedri__drv.c
virtualbox/patches/patch-src_VBox_Additions_netbsd_Installer_pkg-descr
virtualbox/patches/patch-src_VBox_Additions_netbsd_Installer_vboxguest.sh
virtualbox/patches/patch-src_VBox_Additions_netbsd_Makefile
virtualbox/patches/patch-src_VBox_Additions_netbsd_Makefile.kmk
virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_Makefile
virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_Makefile.kmk
virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_files__vboxvideo__drm
virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_vboxvideo__drm.c
virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_Makefile.kmk
virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs.h
virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs__vfsops.c
virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs__vnops.c
virtualbox/patches/patch-src_VBox_Debugger_DBGPlugInDiggers.cpp
virtualbox/patches/patch-src_VBox_Debugger_DBGPlugIns.h
virtualbox/patches/patch-src_VBox_Devices_EFI_Firmware_AppPkg_Applications_Python_PyMod-2.7.1_Include_pyport.h
virtualbox/patches/patch-src_VBox_Devices_Makefile.kmk
virtualbox/patches/patch-src_VBox_Devices_Network_DrvNAT.cpp
virtualbox/patches/patch-src_VBox_Devices_Network_slirp_resolv__conf__parser.c
virtualbox/patches/patch-src_VBox_Devices_Network_slirp_udp.c
virtualbox/patches/patch-src_VBox_Devices_PC_DrvACPI.cpp
virtualbox/patches/patch-src_VBox_Devices_Serial_DrvHostSerial.cpp
virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostBase.cpp
virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostBase.h
virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostDVD.cpp
virtualbox/patches/patch-src_VBox_Devices_USB_netbsd_USBProxyDevice-netbsd.cpp
virtualbox/patches/patch-src_VBox_Devices_build_VBoxDD.cpp
virtualbox/patches/patch-src_VBox_Devices_build_VBoxDD.h
virtualbox/patches/patch-src_VBox_ExtPacks_BusMouseSample_Makefile.kmk
virtualbox/patches/patch-src_VBox_ExtPacks_Skeleton_Makefile.kmk
virtualbox/patches/patch-src_VBox_ExtPacks_VBoxDTrace_Makefile.kmk
virtualbox/patches/patch-src_VBox_ExtPacks_VBoxDTrace_VBoxDTraceWrapper.cpp
virtualbox/patches/patch-src_VBox_ExtPacks_VNC_Makefile.kmk
virtualbox/patches/patch-src_VBox_Frontends_VBoxAutostart_VBoxAutostart-posix.cpp
virtualbox/patches/patch-src_VBox_Frontends_VBoxBalloonCtrl_VBoxWatchdog.cpp
virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxInternalManage.cpp
virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxManageHelp.cpp
virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxManageModifyVM.cpp
virtualbox/patches/patch-src_VBox_Frontends_VBoxSDL_Makefile.kmk
virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_Makefile.kmk
virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_VBoxGLSupportInfo.cpp
virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_net_UIUpdateManager.cpp
virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_settings_machine_UIMachineSettingsAudio.cpp
virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_Makefile.kmk
virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_chromium.h
virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_cr__dll.h
virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_cr__timer.h
virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_spu__loader_glloader.py
virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_dll.c
virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_environment.c
virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_timer.c
virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_vboxhgcm.c
virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_vboxhgsmi.c
virtualbox/patches/patch-src_VBox_GuestHost_SharedClipboard_Makefile.kmk
virtualbox/patches/patch-src_VBox_HostDrivers_Makefile.kmk
virtualbox/patches/patch-src_VBox_HostDrivers_Support_Makefile.kmk
virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrv.cpp
virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvGip.cpp
virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvIDC.h
virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvInternal.h
virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvTracer.cpp
virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPR3HardenedMain.cpp
virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_Makefile
virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.c
virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.def
virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPLib-netbsd.cpp
virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPR0IdcClient-netbsd.c
virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_files__vboxdrv
virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_Makefile.kmk
virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_VBoxNetAdpInternal.h
virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_Makefile
virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_VBoxNetAdp-netbsd.c
virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_files__vboxnetadp
virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_Makefile.kmk
virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_VBoxNetFltInternal.h
virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_Makefile
virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_VBoxNetFlt-netbsd.c
virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_files__vboxnetflt
virtualbox/patches/patch-src_VBox_HostDrivers_netbsd_Makefile
virtualbox/patches/patch-src_VBox_HostDrivers_netbsd_Makefile.kmk
virtualbox/patches/patch-src_VBox_HostServices_Makefile.kmk
virtualbox/patches/patch-src_VBox_HostServices_SharedClipboard_Makefile.kmk
virtualbox/patches/patch-src_VBox_HostServices_SharedOpenGL_Makefile.kmk
virtualbox/patches/patch-src_VBox_HostServices_auth_Makefile.kmk
virtualbox/patches/patch-src_VBox_HostServices_auth_pam_VBoxAuthPAM.c
virtualbox/patches/patch-src_VBox_ImageMounter_VBoxFUSE_Makefile.kmk
virtualbox/patches/patch-src_VBox_ImageMounter_VBoxFUSE_VBoxFUSE.cpp
virtualbox/patches/patch-src_VBox_Installer_Makefile.kmk
virtualbox/patches/patch-src_VBox_Installer_darwin_VirtualBox_postflight
virtualbox/patches/patch-src_VBox_Installer_darwin_VirtualBox_preflight
virtualbox/patches/patch-src_VBox_Installer_linux_VBoxSysInfo.sh
virtualbox/patches/patch-src_VBox_Installer_linux_debian_control
virtualbox/patches/patch-src_VBox_Installer_linux_rpm_VirtualBox.tmpl.spec
virtualbox/patches/patch-src_VBox_Installer_netbsd_Makefile.kmk
virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg-comment
virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg-descr
virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg__plist
virtualbox/patches/patch-src_VBox_Installer_netbsd_postdeinstall.sh
virtualbox/patches/patch-src_VBox_Installer_netbsd_postinstall.sh
virtualbox/patches/patch-src_VBox_Installer_netbsd_virtualbox.desktop
virtualbox/patches/patch-src_VBox_Main_Makefile.kmk
virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPIGlue.c
virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPI__v2__2.h
virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPI__v3__0.h
virtualbox/patches/patch-src_VBox_Main_glue_tests_Makefile
virtualbox/patches/patch-src_VBox_Main_include_ConsoleImpl.h
virtualbox/patches/patch-src_VBox_Main_include_HostUSBDeviceImpl.h
virtualbox/patches/patch-src_VBox_Main_include_USBProxyService.h
virtualbox/patches/patch-src_VBox_Main_include_ovfreader.h
virtualbox/patches/patch-src_VBox_Main_src-client_ConsoleImpl.cpp
virtualbox/patches/patch-src_VBox_Main_src-client_ConsoleImpl2.cpp
virtualbox/patches/patch-src_VBox_Main_src-server_ApplianceImpl.cpp
virtualbox/patches/patch-src_VBox_Main_src-server_HostDnsService.cpp
virtualbox/patches/patch-src_VBox_Main_src-server_HostDnsService.h
virtualbox/patches/patch-src_VBox_Main_src-server_HostImpl.cpp
virtualbox/patches/patch-src_VBox_Main_src-server_HostNetworkInterfaceImpl.cpp
virtualbox/patches/patch-src_VBox_Main_src-server_MachineImpl.cpp
virtualbox/patches/patch-src_VBox_Main_src-server_generic_NetIf-generic.cpp
virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_HostHardwareNetBSD.cpp
virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_Makefile.kup
virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_NetIf-netbsd.cpp
virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_PerformanceNetBSD.cpp
virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_USBProxyServiceNetBSD.cpp
virtualbox/patches/patch-src_VBox_Main_testcase_tstCollector.cpp
virtualbox/patches/patch-src_VBox_Main_webservice_vboxweb.cpp
virtualbox/patches/patch-src_VBox_Main_xml_Settings.cpp
virtualbox/patches/patch-src_VBox_Main_xml_VirtualBox-settings.xsd
virtualbox/patches/patch-src_VBox_Makefile.kmk
virtualbox/patches/patch-src_VBox_NetworkServices_NAT_Makefile.kmk
virtualbox/patches/patch-src_VBox_NetworkServices_NAT_pxping.c
virtualbox/patches/patch-src_VBox_NetworkServices_NAT_pxudp.c
virtualbox/patches/patch-src_VBox_Runtime_Makefile.kmk
virtualbox/patches/patch-src_VBox_Runtime_VBox_log-vbox.cpp
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_alloc-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_assert-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_initterm-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_memobj-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_memuserkernel-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_mp-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_process-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semevent-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semeventmulti-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semfastmutex-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semmutex-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_sleepqueue-r0drv-netbsd.h
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_spinlock-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_the-netbsd-kernel.h
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_thread-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_thread2-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_time-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_timer-r0drv-netbsd.c
virtualbox/patches/patch-src_VBox_Runtime_r3_init.cpp
virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_fileaio-netbsd.cpp
virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_mp-netbsd.cpp
virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_rtProcInitExePath-netbsd.cpp
virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_systemmem-netbsd.cpp
virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fileaio-posix.cpp
virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fileio-posix.cpp
virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fs-posix.cpp
virtualbox/patches/patch-src_VBox_Runtime_r3_posix_path2-posix.cpp
virtualbox/patches/patch-src_VBox_Runtime_r3_posix_thread-posix.cpp
virtualbox/patches/patch-src_VBox_Runtime_r3_posix_thread2-posix.cpp
virtualbox/patches/patch-src_VBox_Storage_testcase_Makefile.kmk
virtualbox/patches/patch-src_VBox_VMM_VMMR0_GMMR0.cpp
virtualbox/patches/patch-src_VBox_VMM_VMMR0_VMMR0.cpp
virtualbox/patches/patch-src_VBox_VMM_VMMR3_PGMPhys.cpp
virtualbox/patches/patch-src_VBox_VMM_VMMR3_VM.cpp
virtualbox/patches/patch-src_VBox_VMM_VMMRC_VMMRCDeps.cpp
virtualbox/patches/patch-src_VBox_VMM_testcase_mkdsk.sh
virtualbox/patches/patch-src_VBox_VMM_testcase_tstX86-1.cpp
virtualbox/patches/patch-src_VBox_ValidationKit_Makefile.kmk
virtualbox/patches/patch-src_VBox_ValidationKit_testboxscript_testboxscript__real.py
virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_base.py
virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_vbox.py
virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_vboxtestvms.py
virtualbox/patches/patch-src_VBox_ValidationKit_testmanager_core_coreconsts.py
virtualbox/patches/patch-src_VBox_ValidationKit_tests_autostart_tdAutostart1.py
virtualbox/patches/patch-src_apps_Makefile.kmk
virtualbox/patches/patch-src_libs_libxml2-2.9.2_include_vboxconfig.h
virtualbox/patches/patch-src_recompiler_Makefile.kmk
virtualbox/patches/patch-src_recompiler_exec.c
virtualbox/patches/patch-tools_bin_gen-slickedit-workspace.sh
Log Message:
Import virtualbox-5.0.16 as wip/virtualbox.
VirtualBox is a family of powerful x86 virtualization products for
enterprise as well as home use. Not only is VirtualBox an extremely
feature rich, high performance product for enterprise customers, it
is also the only professional solution that is freely available as
Open Source Software under the terms of the GNU General Public License.
WWW: http://www.virtualbox.org/
To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=89404835ab2074464dd1f874bef88fb6549b5559
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
virtualbox/DESCR | 7 +
virtualbox/Makefile | 96 ++
virtualbox/PLIST | 0
virtualbox/distinfo | 209 ++++
virtualbox/patches/patch-Config.kmk | 110 ++
virtualbox/patches/patch-Makefile.kmk | 178 ++++
virtualbox/patches/patch-configure | 117 +++
virtualbox/patches/patch-include_VBox_VBoxGuest.h | 41 +
virtualbox/patches/patch-include_VBox_ostypes.h | 13 +
virtualbox/patches/patch-include_VBox_param.h | 18 +
virtualbox/patches/patch-include_VBox_usb.h | 18 +
virtualbox/patches/patch-include_iprt_string.h | 18 +
.../patches/patch-src_VBox_Additions_Makefile.kmk | 56 +
...dditions_common_VBoxGuestLib_VBoxGuestR3Lib.cpp | 44 +
...tions_common_VBoxGuestLib_VBoxGuestR3LibLog.cpp | 18 +
...rc_VBox_Additions_common_VBoxGuest_Makefile.kmk | 78 ++
...x_Additions_common_VBoxGuest_VBoxGuest-netbsd.c | 636 ++++++++++++
...c_VBox_Additions_common_VBoxGuest_VBoxGuest.cpp | 18 +
..._Additions_common_VBoxGuest_VBoxGuestInternal.h | 18 +
...VBox_Additions_common_VBoxGuest_netbsd_Makefile | 171 ++++
...itions_common_VBoxGuest_netbsd_files__vboxguest | 204 ++++
...ox_Additions_common_VBoxService_VBoxService.cpp | 18 +
...itions_common_VBoxService_VBoxServiceVMInfo.cpp | 65 ++
...src_VBox_Additions_common_crOpenGL_Makefile.kmk | 198 ++++
...ox_Additions_common_crOpenGL_NetBSD__exports.py | 16 +
...c_VBox_Additions_common_crOpenGL_fakedri__drv.c | 42 +
...h-src_VBox_Additions_netbsd_Installer_pkg-descr | 8 +
...rc_VBox_Additions_netbsd_Installer_vboxguest.sh | 140 +++
.../patch-src_VBox_Additions_netbsd_Makefile | 58 ++
.../patch-src_VBox_Additions_netbsd_Makefile.kmk | 196 ++++
.../patch-src_VBox_Additions_netbsd_drm_Makefile | 31 +
...atch-src_VBox_Additions_netbsd_drm_Makefile.kmk | 76 ++
...VBox_Additions_netbsd_drm_files__vboxvideo__drm | 30 +
...-src_VBox_Additions_netbsd_drm_vboxvideo__drm.c | 144 +++
...-src_VBox_Additions_netbsd_vboxvfs_Makefile.kmk | 68 ++
...tch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs.h | 97 ++
...VBox_Additions_netbsd_vboxvfs_vboxvfs__vfsops.c | 263 +++++
..._VBox_Additions_netbsd_vboxvfs_vboxvfs__vnops.c | 246 +++++
.../patch-src_VBox_Debugger_DBGPlugInDiggers.cpp | 17 +
.../patches/patch-src_VBox_Debugger_DBGPlugIns.h | 17 +
...pplications_Python_PyMod-2.7.1_Include_pyport.h | 23 +
.../patches/patch-src_VBox_Devices_Makefile.kmk | 69 ++
.../patch-src_VBox_Devices_Network_DrvNAT.cpp | 18 +
...ox_Devices_Network_slirp_resolv__conf__parser.c | 13 +
.../patch-src_VBox_Devices_Network_slirp_udp.c | 13 +
.../patches/patch-src_VBox_Devices_PC_DrvACPI.cpp | 24 +
...patch-src_VBox_Devices_Serial_DrvHostSerial.cpp | 135 +++
.../patch-src_VBox_Devices_Storage_DrvHostBase.cpp | 89 ++
.../patch-src_VBox_Devices_Storage_DrvHostBase.h | 31 +
.../patch-src_VBox_Devices_Storage_DrvHostDVD.cpp | 63 ++
...ox_Devices_USB_netbsd_USBProxyDevice-netbsd.cpp | 1066 ++++++++++++++++++++
.../patch-src_VBox_Devices_build_VBoxDD.cpp | 40 +
.../patches/patch-src_VBox_Devices_build_VBoxDD.h | 27 +
...h-src_VBox_ExtPacks_BusMouseSample_Makefile.kmk | 22 +
.../patch-src_VBox_ExtPacks_Skeleton_Makefile.kmk | 22 +
...patch-src_VBox_ExtPacks_VBoxDTrace_Makefile.kmk | 22 +
..._VBox_ExtPacks_VBoxDTrace_VBoxDTraceWrapper.cpp | 18 +
.../patch-src_VBox_ExtPacks_VNC_Makefile.kmk | 22 +
...Frontends_VBoxAutostart_VBoxAutostart-posix.cpp | 18 +
...VBox_Frontends_VBoxBalloonCtrl_VBoxWatchdog.cpp | 45 +
...Box_Frontends_VBoxManage_VBoxInternalManage.cpp | 70 ++
...rc_VBox_Frontends_VBoxManage_VBoxManageHelp.cpp | 50 +
...Box_Frontends_VBoxManage_VBoxManageModifyVM.cpp | 31 +
.../patch-src_VBox_Frontends_VBoxSDL_Makefile.kmk | 17 +
...atch-src_VBox_Frontends_VirtualBox_Makefile.kmk | 58 ++
..._Frontends_VirtualBox_src_VBoxGLSupportInfo.cpp | 18 +
...rontends_VirtualBox_src_net_UIUpdateManager.cpp | 18 +
...src_settings_machine_UIMachineSettingsAudio.cpp | 39 +
.../patch-src_VBox_GuestHost_OpenGL_Makefile.kmk | 54 +
...ch-src_VBox_GuestHost_OpenGL_include_chromium.h | 13 +
...tch-src_VBox_GuestHost_OpenGL_include_cr__dll.h | 13 +
...h-src_VBox_GuestHost_OpenGL_include_cr__timer.h | 13 +
...c_VBox_GuestHost_OpenGL_spu__loader_glloader.py | 32 +
.../patch-src_VBox_GuestHost_OpenGL_util_dll.c | 40 +
...ch-src_VBox_GuestHost_OpenGL_util_environment.c | 13 +
.../patch-src_VBox_GuestHost_OpenGL_util_timer.c | 13 +
...patch-src_VBox_GuestHost_OpenGL_util_vboxhgcm.c | 31 +
...atch-src_VBox_GuestHost_OpenGL_util_vboxhgsmi.c | 31 +
...src_VBox_GuestHost_SharedClipboard_Makefile.kmk | 9 +
.../patch-src_VBox_HostDrivers_Makefile.kmk | 31 +
...patch-src_VBox_HostDrivers_Support_Makefile.kmk | 69 ++
.../patch-src_VBox_HostDrivers_Support_SUPDrv.cpp | 36 +
...atch-src_VBox_HostDrivers_Support_SUPDrvGip.cpp | 18 +
.../patch-src_VBox_HostDrivers_Support_SUPDrvIDC.h | 19 +
...h-src_VBox_HostDrivers_Support_SUPDrvInternal.h | 18 +
...h-src_VBox_HostDrivers_Support_SUPDrvTracer.cpp | 18 +
..._VBox_HostDrivers_Support_SUPR3HardenedMain.cpp | 47 +
...ch-src_VBox_HostDrivers_Support_netbsd_Makefile | 189 ++++
...VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.c | 637 ++++++++++++
...ox_HostDrivers_Support_netbsd_SUPDrv-netbsd.def | 6 +
...ox_HostDrivers_Support_netbsd_SUPLib-netbsd.cpp | 190 ++++
...tDrivers_Support_netbsd_SUPR0IdcClient-netbsd.c | 60 ++
..._VBox_HostDrivers_Support_netbsd_files__vboxdrv | 218 ++++
...ch-src_VBox_HostDrivers_VBoxNetAdp_Makefile.kmk | 64 ++
...Box_HostDrivers_VBoxNetAdp_VBoxNetAdpInternal.h | 21 +
...src_VBox_HostDrivers_VBoxNetAdp_netbsd_Makefile | 40 +
...stDrivers_VBoxNetAdp_netbsd_VBoxNetAdp-netbsd.c | 331 ++++++
...HostDrivers_VBoxNetAdp_netbsd_files__vboxnetadp | 85 ++
...ch-src_VBox_HostDrivers_VBoxNetFlt_Makefile.kmk | 62 ++
...Box_HostDrivers_VBoxNetFlt_VBoxNetFltInternal.h | 40 +
...src_VBox_HostDrivers_VBoxNetFlt_netbsd_Makefile | 43 +
...stDrivers_VBoxNetFlt_netbsd_VBoxNetFlt-netbsd.c | 802 +++++++++++++++
...HostDrivers_VBoxNetFlt_netbsd_files__vboxnetflt | 90 ++
.../patch-src_VBox_HostDrivers_netbsd_Makefile | 81 ++
.../patch-src_VBox_HostDrivers_netbsd_Makefile.kmk | 30 +
.../patch-src_VBox_HostServices_Makefile.kmk | 24 +
..._VBox_HostServices_SharedClipboard_Makefile.kmk | 22 +
...src_VBox_HostServices_SharedOpenGL_Makefile.kmk | 26 +
.../patch-src_VBox_HostServices_auth_Makefile.kmk | 23 +
...ch-src_VBox_HostServices_auth_pam_VBoxAuthPAM.c | 13 +
...tch-src_VBox_ImageMounter_VBoxFUSE_Makefile.kmk | 13 +
...tch-src_VBox_ImageMounter_VBoxFUSE_VBoxFUSE.cpp | 27 +
.../patches/patch-src_VBox_Installer_Makefile.kmk | 19 +
...src_VBox_Installer_darwin_VirtualBox_postflight | 18 +
...-src_VBox_Installer_darwin_VirtualBox_preflight | 13 +
.../patch-src_VBox_Installer_linux_VBoxSysInfo.sh | 27 +
.../patch-src_VBox_Installer_linux_debian_control | 22 +
...c_VBox_Installer_linux_rpm_VirtualBox.tmpl.spec | 13 +
.../patch-src_VBox_Installer_netbsd_Makefile.kmk | 343 +++++++
.../patch-src_VBox_Installer_netbsd_pkg-comment | 6 +
.../patch-src_VBox_Installer_netbsd_pkg-descr | 8 +
.../patch-src_VBox_Installer_netbsd_pkg__plist | 103 ++
...atch-src_VBox_Installer_netbsd_postdeinstall.sh | 36 +
.../patch-src_VBox_Installer_netbsd_postinstall.sh | 80 ++
...ch-src_VBox_Installer_netbsd_virtualbox.desktop | 23 +
.../patches/patch-src_VBox_Main_Makefile.kmk | 47 +
.../patch-src_VBox_Main_cbinding_VBoxCAPIGlue.c | 28 +
.../patch-src_VBox_Main_cbinding_VBoxCAPI__v2__2.h | 14 +
.../patch-src_VBox_Main_cbinding_VBoxCAPI__v3__0.h | 14 +
.../patch-src_VBox_Main_glue_tests_Makefile | 13 +
.../patch-src_VBox_Main_include_ConsoleImpl.h | 22 +
...patch-src_VBox_Main_include_HostUSBDeviceImpl.h | 14 +
.../patch-src_VBox_Main_include_USBProxyService.h | 48 +
.../patch-src_VBox_Main_include_ovfreader.h | 19 +
.../patch-src_VBox_Main_src-client_ConsoleImpl.cpp | 54 +
...patch-src_VBox_Main_src-client_ConsoleImpl2.cpp | 60 ++
...atch-src_VBox_Main_src-server_ApplianceImpl.cpp | 25 +
...tch-src_VBox_Main_src-server_HostDnsService.cpp | 13 +
...patch-src_VBox_Main_src-server_HostDnsService.h | 31 +
.../patch-src_VBox_Main_src-server_HostImpl.cpp | 63 ++
...ox_Main_src-server_HostNetworkInterfaceImpl.cpp | 16 +
.../patch-src_VBox_Main_src-server_MachineImpl.cpp | 13 +
..._VBox_Main_src-server_generic_NetIf-generic.cpp | 22 +
...x_Main_src-server_netbsd_HostHardwareNetBSD.cpp | 389 +++++++
...ch-src_VBox_Main_src-server_netbsd_Makefile.kup | 6 +
...rc_VBox_Main_src-server_netbsd_NetIf-netbsd.cpp | 429 ++++++++
...ox_Main_src-server_netbsd_PerformanceNetBSD.cpp | 122 +++
...ain_src-server_netbsd_USBProxyServiceNetBSD.cpp | 359 +++++++
.../patch-src_VBox_Main_testcase_tstCollector.cpp | 19 +
.../patch-src_VBox_Main_webservice_vboxweb.cpp | 40 +
.../patches/patch-src_VBox_Main_xml_Settings.cpp | 26 +
...patch-src_VBox_Main_xml_VirtualBox-settings.xsd | 17 +
virtualbox/patches/patch-src_VBox_Makefile.kmk | 18 +
...patch-src_VBox_NetworkServices_NAT_Makefile.kmk | 12 +
.../patch-src_VBox_NetworkServices_NAT_pxping.c | 13 +
.../patch-src_VBox_NetworkServices_NAT_pxudp.c | 13 +
.../patches/patch-src_VBox_Runtime_Makefile.kmk | 245 +++++
.../patch-src_VBox_Runtime_VBox_log-vbox.cpp | 57 ++
..._VBox_Runtime_r0drv_netbsd_alloc-r0drv-netbsd.c | 184 ++++
...VBox_Runtime_r0drv_netbsd_assert-r0drv-netbsd.c | 74 ++
...ox_Runtime_r0drv_netbsd_initterm-r0drv-netbsd.c | 57 ++
...VBox_Runtime_r0drv_netbsd_memobj-r0drv-netbsd.c | 811 +++++++++++++++
...ntime_r0drv_netbsd_memuserkernel-r0drv-netbsd.c | 87 ++
...src_VBox_Runtime_r0drv_netbsd_mp-r0drv-netbsd.c | 273 +++++
...Box_Runtime_r0drv_netbsd_process-r0drv-netbsd.c | 55 +
...ox_Runtime_r0drv_netbsd_semevent-r0drv-netbsd.c | 260 +++++
...ntime_r0drv_netbsd_semeventmulti-r0drv-netbsd.c | 324 ++++++
...untime_r0drv_netbsd_semfastmutex-r0drv-netbsd.c | 119 +++
...ox_Runtime_r0drv_netbsd_semmutex-r0drv-netbsd.c | 223 ++++
..._Runtime_r0drv_netbsd_sleepqueue-r0drv-netbsd.h | 334 ++++++
...ox_Runtime_r0drv_netbsd_spinlock-r0drv-netbsd.c | 214 ++++
...c_VBox_Runtime_r0drv_netbsd_the-netbsd-kernel.h | 106 ++
...VBox_Runtime_r0drv_netbsd_thread-r0drv-netbsd.c | 186 ++++
...Box_Runtime_r0drv_netbsd_thread2-r0drv-netbsd.c | 139 +++
...c_VBox_Runtime_r0drv_netbsd_time-r0drv-netbsd.c | 78 ++
..._VBox_Runtime_r0drv_netbsd_timer-r0drv-netbsd.c | 290 ++++++
.../patches/patch-src_VBox_Runtime_r3_init.cpp | 18 +
...h-src_VBox_Runtime_r3_netbsd_fileaio-netbsd.cpp | 676 +++++++++++++
.../patch-src_VBox_Runtime_r3_netbsd_mp-netbsd.cpp | 205 ++++
..._Runtime_r3_netbsd_rtProcInitExePath-netbsd.cpp | 77 ++
...src_VBox_Runtime_r3_netbsd_systemmem-netbsd.cpp | 79 ++
...tch-src_VBox_Runtime_r3_posix_fileaio-posix.cpp | 59 ++
...atch-src_VBox_Runtime_r3_posix_fileio-posix.cpp | 45 +
.../patch-src_VBox_Runtime_r3_posix_fs-posix.cpp | 22 +
...patch-src_VBox_Runtime_r3_posix_path2-posix.cpp | 17 +
...atch-src_VBox_Runtime_r3_posix_thread-posix.cpp | 18 +
...tch-src_VBox_Runtime_r3_posix_thread2-posix.cpp | 27 +
.../patch-src_VBox_Storage_testcase_Makefile.kmk | 9 +
.../patches/patch-src_VBox_VMM_VMMR0_GMMR0.cpp | 18 +
.../patches/patch-src_VBox_VMM_VMMR0_VMMR0.cpp | 27 +
.../patches/patch-src_VBox_VMM_VMMR3_PGMPhys.cpp | 36 +
virtualbox/patches/patch-src_VBox_VMM_VMMR3_VM.cpp | 18 +
.../patches/patch-src_VBox_VMM_VMMRC_VMMRCDeps.cpp | 32 +
.../patches/patch-src_VBox_VMM_testcase_mkdsk.sh | 13 +
.../patch-src_VBox_VMM_testcase_tstX86-1.cpp | 23 +
.../patch-src_VBox_ValidationKit_Makefile.kmk | 45 +
...idationKit_testboxscript_testboxscript__real.py | 18 +
...patch-src_VBox_ValidationKit_testdriver_base.py | 17 +
...patch-src_VBox_ValidationKit_testdriver_vbox.py | 36 +
...rc_VBox_ValidationKit_testdriver_vboxtestvms.py | 55 +
...ox_ValidationKit_testmanager_core_coreconsts.py | 28 +
...x_ValidationKit_tests_autostart_tdAutostart1.py | 17 +
virtualbox/patches/patch-src_apps_Makefile.kmk | 17 +
...tch-src_libs_libxml2-2.9.2_include_vboxconfig.h | 18 +
.../patches/patch-src_recompiler_Makefile.kmk | 17 +
virtualbox/patches/patch-src_recompiler_exec.c | 35 +
.../patch-tools_bin_gen-slickedit-workspace.sh | 17 +
207 files changed, 18079 insertions(+)
diffs:
diff --git a/virtualbox/DESCR b/virtualbox/DESCR
new file mode 100644
index 0000000..d10019c
--- /dev/null
+++ b/virtualbox/DESCR
@@ -0,0 +1,7 @@
+VirtualBox is a family of powerful x86 virtualization products for
+enterprise as well as home use. Not only is VirtualBox an extremely
+feature rich, high performance product for enterprise customers, it
+is also the only professional solution that is freely available as
+Open Source Software under the terms of the GNU General Public License.
+
+WWW: http://www.virtualbox.org/
diff --git a/virtualbox/Makefile b/virtualbox/Makefile
new file mode 100644
index 0000000..b1e687e
--- /dev/null
+++ b/virtualbox/Makefile
@@ -0,0 +1,96 @@
+# $NetBSD$
+
+DISTNAME= virtualbox-ose-5.0.16
+PKGNAME= ${DISTNAME:C/-ose//}
+CATEGORIES= emulators
+MASTER_SITES= http://download.virtualbox.org/virtualbox/${PKGVERSION_NOREV}/ \
+ http://tmp.chruetertee.ch/ \
+ http://disasterarea.chruetertee.ch/ \
+ http://download.virtualbox.org/virtualbox/${VBOX_GUEST_VER}/:guestadditions
+DISTFILES= VirtualBox-${PKGVERSION_NOREV}${EXTRACT_SUFX} ${GADISTFILES}
+EXTRACT_ONLY= VirtualBox-${PKGVERSION_NOREV}${EXTRACT_SUFX}
+EXTRACT_SUFX= .tar.bz2
+
+MAINTAINER= pkgsrc-users%NetBSD.org@localhost
+COMMENT= General-purpose full virtualizer for x86 hardware
+LICENSE= gnu-gpl-v2
+
+DEPENDS+= cdrtools-[0-9]*:../../sysutils/cdrtools
+
+BUILD_DEPENDS+= yasm-[0-9]*:../../devel/yasm
+BUILD_DEPENDS+= kbuild-[0-9]*:../../wip/kbuild
+
+USE_TOOLS+= gtar pkg-config bison flex
+
+WRKSRC= ${WRKDIR}/VirtualBox-${PKGVERSION_NOREV}
+
+HAS_CONFIGURE= yes
+USE_LANGUAGES+= c c++
+
+SUBST_CLASSES+= paths
+SUBST_MESSAGE.paths+= Adjust paths for pkgsrc
+SUBST_STAGE.paths= pre-configure
+#SUBST_STAGE.paths= post-build
+SUBST_FILES.paths+= configure
+SUBST_SED.paths+= -e 's!^INCCRYPTO=.*!INCCRYPTO="-I${BUILDLINK_PREFIX.openssl}/include"!g'
+SUBST_SED.paths+= -e 's!^LIBCRYPTO=.*!LIBCRYPTO="${COMPILER_RPATH_FLAG}${BUILDLINK_PREFIX.openssl}/lib -L${BUILDLINK_PREFIX.openssl}/lib -lssl -lcrypto"!g'
+SUBST_SED.paths+= -e 's!^INCX11=.*!INCX11="-I${X11BASE}/include"!g'
+SUBST_SED.paths+= -e 's!^LIBX11=.*!LIBX11="${COMPILER_RPATH_FLAG}${X11BASE}/lib -L${X11BASE}/lib -lXext -lX11"!g'
+SUBST_SED.paths+= -e 's!^INCZ=.*!INCZ="-I${BUILDLINK_PREFIX.zlib}/include"!g'
+SUBST_SED.paths+= -e 's!^LIBZ=.*!LIBZ="${COMPILER_RPATH_FLAG}${BUILDLINK_PREFIX.zlib}/lib -L${BUILDLINK_PREFIX.zlib}/lib -lz"!g'
+SUBST_SED.paths+= -e 's!^INCCURL=.*!INCCURL="-I${BUILDLINK_PREFIX.curl}/include"!g'
+SUBST_SED.paths+= -e 's!^LIBCURL=.*!LIBCURL="${COMPILER_RPATH_FLAG}${BUILDLINK_PREFIX.curl}/lib -L${BUILDLINK_PREFIX.curl}/lib -lcurl"!g'
+SUBST_SED.paths+= -e 's!^INCPULSE=.*!INCPULSE="-I${BUILDLINK_PREFIX.pulseaudio}/include"!g'
+SUBST_SED.paths+= -e 's!^LIBPULSE=.*!LIBPULSE="${COMPILER_RPATH_FLAG}${BUILDLINK_PREFIX.pulseaudio}/lib -L${BUILDLINK_PREFIX.pulseaudio}/lib"!g'
+SUBST_SED.paths+= -e 's!^INCPNG=.*!INCPNG="-I${BUILDLINK_PREFIX.png}/include"!g'
+SUBST_SED.paths+= -e 's!^LIBPNG=.*!LIBPNG="${COMPILER_RPATH_FLAG}${BUILDLINK_PREFIX.png}/lib -L${BUILDLINK_PREFIX.png}/lib"!g'
+SUBST_SED.paths+= -e 's!^INCVPX=.*!INCVPX="-I${BUILDLINK_PREFIX.libvpx}/include"!g'
+SUBST_SED.paths+= -e 's!^LIBVPX=.*!LIBVPX="${COMPILER_RPATH_FLAG}${BUILDLINK_PREFIX.libvpx}/lib -L${BUILDLINK_PREFIX.libvpx}/lib -lvpx"!g'
+# These paths are used as a shell enumeration to check
+SUBST_SED.paths+= -e 's!^PYTHONDIR=.*!PYTHONDIR="${PREFIX}"!g'
+SUBST_SED.paths+= -e 's!^QT4DIR=.*!QT4DIR="${QTDIR}"!g'
+# Set proper path of Python libs under ${PREFIX}/lib..
+SUBST_SED.paths+= -e 's!lib/x86_64-linux-gnu lib/i386-linux-gnu lib64 lib/64 lib!lib!g'
+# Use pkgsrc provided Python version
+SUBST_SED.paths+= -e 's!SUPPYTHONLIBS=.*!SUPPYTHONLIBS="python${PYVERSSUFFIX}"!g'
+# Add needed rpath for testing execution of an application linked with libpython
+SUBST_SED.paths+= -e 's!PYTHONLIBRPATH=.*!PYTHONLIBRPATH="${COMPILER_RPATH_FLAG}${PREFIX}/lib"!g'
+
+VBLIBDIR= ${PREFIX}/lib/virtualbox
+
+KMK_CONFIG+= KBUILD_PATH=${WRKSRC}/kBuild
+# Multiple jobs tend to be broken
+KMK_FLAGS+= -j1
+
+pre-configure:
+ ${RUN} echo "VBOX_GCC_OPT=${CXXFLAGS}" >> ${WRKSRC}/LocalConfig.kmk
+ ${RUN} echo "VBOX_WITH_ORIGIN:=" >> ${WRKSRC}/LocalConfig.kmk
+ ${RUN} echo "VBOX_WITH_RUNPATH:=${VBLIBDIR}" >> ${WRKSRC}/LocalConfig.kmk
+ ${RUN} echo "VBOX_PATH_APP_PRIVATE_ARCH:=${VBLIBDIR}" >> ${WRKSRC}/LocalConfig.kmk
+ ${RUN} echo "VBOX_PATH_APP_PRIVATE:=${VBLIBDIR}" >> ${WRKSRC}/LocalConfig.kmk
+ ${RUN} echo "VBOX_WITH_TESTCASES=" >> ${WRKSRC}/LocalConfig.kmk
+ ${RUN} echo "VBOX_WITH_TESTSUITE:=" >> ${WRKSRC}/LocalConfig.kmk
+ ${RUN} echo "VBOX_JAVA_HOME:=${JAVA_HOME}" >> ${WRKSRC}/LocalConfig.kmk
+ ${RUN} echo "VBOX_USE_SYSTEM_XORG_HEADERS:=1" >> ${WRKSRC}/LocalConfig.kmk
+
+do-build:
+ ${RUN} cd ${WRKSRC} && . ./env.sh && ${KMK_CONFIG} kmk ${KMK_FLAGS}
+
+do-install:
+ ${RUN} cd ${WRKSRC} && . ./env.sh && kmk install
+
+.include "../../mk/java-vm.mk"
+.include "../../audio/pulseaudio/buildlink3.mk"
+.include "../../multimedia/libvpx/buildlink3.mk"
+.include "../../graphics/png/buildlink3.mk"
+.include "../../multimedia/libvpx/buildlink3.mk"
+.include "../../www/curl/buildlink3.mk"
+.include "../../graphics/png/buildlink3.mk"
+.include "../../textproc/libxslt/buildlink3.mk"
+.include "../../devel/SDL/buildlink3.mk"
+.include "../../devel/glib2/buildlink3.mk"
+.include "../../x11/libXext/buildlink3.mk"
+.include "../../x11/qt4-libs/buildlink3.mk"
+.include "../../lang/python/pyversion.mk"
+.include "../../lang/python/application.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/virtualbox/PLIST b/virtualbox/PLIST
new file mode 100644
index 0000000..e69de29
diff --git a/virtualbox/distinfo b/virtualbox/distinfo
new file mode 100644
index 0000000..1e1f206
--- /dev/null
+++ b/virtualbox/distinfo
@@ -0,0 +1,209 @@
+$NetBSD$
+
+SHA1 (VirtualBox-5.0.16.tar.bz2) = ca7b3fadda37b1b281f78ef2d573aceacab7d9fd
+RMD160 (VirtualBox-5.0.16.tar.bz2) = 6d7a5d6cae5367d26a015895c09294ff0282d062
+SHA512 (VirtualBox-5.0.16.tar.bz2) = 3da3a227360fb50d299e99770378f65e8cb99525377343fa8faff2360be66643d46f68323d6a8b8d4d26182082f171bb35ab2497167bf6df18827a5ea7742074
+Size (VirtualBox-5.0.16.tar.bz2) = 111062984 bytes
+SHA1 (patch-Config.kmk) = 136895de8ba926bad725f7f7cf084b25ffbf3152
+SHA1 (patch-Makefile.kmk) = fbb5d999abad202368df11756d91ed7e13c646ae
+SHA1 (patch-configure) = ac34debc8ad9900aaa22c4d00ca7641eb7091aa3
+SHA1 (patch-include_VBox_VBoxGuest.h) = 4f41910ca3abbc502bad31cb9f9b427566025765
+SHA1 (patch-include_VBox_ostypes.h) = fd452f95c79b2e5c98a048af21f6561c80adebc5
+SHA1 (patch-include_VBox_param.h) = 1efcacb3e7890344dc132fee85b945bf9baa9614
+SHA1 (patch-include_VBox_usb.h) = c16d333f6dee240f1d4147cc49c04451dfb776a7
+SHA1 (patch-include_iprt_string.h) = dd74a70d35be03f480bbb42db170cf7c5f583e4e
+SHA1 (patch-src_VBox_Additions_Makefile.kmk) = e47ebb5cbfb51d103f76e1316b18e835fb5d6b1d
+SHA1 (patch-src_VBox_Additions_common_VBoxGuestLib_VBoxGuestR3Lib.cpp) = 99138a3a7abd00e74c50f0fdc841ac7984e11a08
+SHA1 (patch-src_VBox_Additions_common_VBoxGuestLib_VBoxGuestR3LibLog.cpp) = e0b83d8785a8bfe000c6467d125d3b45c1517ff7
+SHA1 (patch-src_VBox_Additions_common_VBoxGuest_Makefile.kmk) = 8c2cbd6e7fca2b685608c3103361ad039158281d
+SHA1 (patch-src_VBox_Additions_common_VBoxGuest_VBoxGuest-netbsd.c) = 2f064ab71cc663c8af000f96e2f4d906e37c4b90
+SHA1 (patch-src_VBox_Additions_common_VBoxGuest_VBoxGuest.cpp) = 70e98134ae1a57a8fe62df831ab91e2e29fe8419
+SHA1 (patch-src_VBox_Additions_common_VBoxGuest_VBoxGuestInternal.h) = 230b0725aedfa38476e63c10c2c38ce2302ebae0
+SHA1 (patch-src_VBox_Additions_common_VBoxGuest_netbsd_Makefile) = 0bf4f2612ee76df864204e96ffbd5c5a0361438a
+SHA1 (patch-src_VBox_Additions_common_VBoxGuest_netbsd_files__vboxguest) = c620e3df9c61ab6fc6f5914f39945a5ab8a622b1
+SHA1 (patch-src_VBox_Additions_common_VBoxService_VBoxService.cpp) = d2f1a2e2f18dff2b03348949c40f9f2a4fd5c4c4
+SHA1 (patch-src_VBox_Additions_common_VBoxService_VBoxServiceVMInfo.cpp) = f243f7fa833c05fae684ed8df5bb826dd630c86a
+SHA1 (patch-src_VBox_Additions_common_crOpenGL_Makefile.kmk) = 2888abd438224f8de5cce02537d02173370f4fbd
+SHA1 (patch-src_VBox_Additions_common_crOpenGL_NetBSD__exports.py) = d410ce3fb1494664c0443def76b166a80a767d66
+SHA1 (patch-src_VBox_Additions_common_crOpenGL_fakedri__drv.c) = 9b164dfd0ddc77dfe62ad8e0ea3f8bb40091af93
+SHA1 (patch-src_VBox_Additions_netbsd_Installer_pkg-descr) = 656e1953f0b9c8eb09fe25fbb09af502b30efa9c
+SHA1 (patch-src_VBox_Additions_netbsd_Installer_vboxguest.sh) = 25295205110c7a68fc57104f688084b2fc56828c
+SHA1 (patch-src_VBox_Additions_netbsd_Makefile) = 98da08e34af9003a55a121d431a7116374c485cd
+SHA1 (patch-src_VBox_Additions_netbsd_Makefile.kmk) = 3a13ee0eac2bd8995d54da93a5d9e5d4d6fa1ec0
+SHA1 (patch-src_VBox_Additions_netbsd_drm_Makefile) = 8b557d6450a658b577b117c6b3b7ab6778768977
+SHA1 (patch-src_VBox_Additions_netbsd_drm_Makefile.kmk) = 0f59622dcc0de56a61becc3dbc158d307e0483ca
+SHA1 (patch-src_VBox_Additions_netbsd_drm_files__vboxvideo__drm) = fdd8b4c6ec76fc765496be62ed0aad6435e5aead
+SHA1 (patch-src_VBox_Additions_netbsd_drm_vboxvideo__drm.c) = 498d7f621af8d3719e79fd5fa2690bfdb2e0368f
+SHA1 (patch-src_VBox_Additions_netbsd_vboxvfs_Makefile.kmk) = 30187f5b31e824a54ec01767e3f79d2f17708854
+SHA1 (patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs.h) = 4d0fc6c06af40e66ec70b5bb459739e150eb6c04
+SHA1 (patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs__vfsops.c) = 7f1c95df11fa32e3c693fcb28fe8484c738174da
+SHA1 (patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs__vnops.c) = e94574f46776b704755603d3a87be0ef6dee0827
+SHA1 (patch-src_VBox_Debugger_DBGPlugInDiggers.cpp) = 3851f8bb02e1e00d504ca73542663ff78359bf01
+SHA1 (patch-src_VBox_Debugger_DBGPlugIns.h) = c98f48c70574f05d6afa33e5309610d74c0c32ec
+SHA1 (patch-src_VBox_Devices_EFI_Firmware_AppPkg_Applications_Python_PyMod-2.7.1_Include_pyport.h) = 626e4ad27a01ba949b42a6fdb2f6e0dcf7daa132
+SHA1 (patch-src_VBox_Devices_Makefile.kmk) = 67cb5e0bbad005e4ca71e8e74556ffae8939de61
+SHA1 (patch-src_VBox_Devices_Network_DrvNAT.cpp) = c24f0b47ee671833fcc9d8bb9a569cd1c6710d95
+SHA1 (patch-src_VBox_Devices_Network_slirp_resolv__conf__parser.c) = 03736443ea30ea6e4ae08003d8f5a512f71932d1
+SHA1 (patch-src_VBox_Devices_Network_slirp_udp.c) = 2e4e1030bcb66c5260d980216e40ed4e677c8914
+SHA1 (patch-src_VBox_Devices_PC_DrvACPI.cpp) = d3af18169132d43ecfd79ab4ff471c48d8ce6e17
+SHA1 (patch-src_VBox_Devices_Serial_DrvHostSerial.cpp) = 0d007ffe9ee83fa40b66970ec20f5d8cf42a26af
+SHA1 (patch-src_VBox_Devices_Storage_DrvHostBase.cpp) = aa5485a0fcd72f6188cca3339e17ca839e60ae1a
+SHA1 (patch-src_VBox_Devices_Storage_DrvHostBase.h) = 1f091530ee9f819c4c0152b6452fb91649b25b3c
+SHA1 (patch-src_VBox_Devices_Storage_DrvHostDVD.cpp) = 2412e4c3fb0cc2eafe9aca57fa03f9f133c6083d
+SHA1 (patch-src_VBox_Devices_USB_netbsd_USBProxyDevice-netbsd.cpp) = 4def83455dc98c31e444b7e3bfc904347f15f756
+SHA1 (patch-src_VBox_Devices_build_VBoxDD.cpp) = eafd6c00f34caf28e560466fe5793b915bbfbfec
+SHA1 (patch-src_VBox_Devices_build_VBoxDD.h) = c5a48d45145eacf0c28b1e1aaf56f0c43fba2db2
+SHA1 (patch-src_VBox_ExtPacks_BusMouseSample_Makefile.kmk) = 30258f2d52fd5d79a6678eb636366956273f2cea
+SHA1 (patch-src_VBox_ExtPacks_Skeleton_Makefile.kmk) = 619d98569376322460b4fc1176b6839224ebf0f8
+SHA1 (patch-src_VBox_ExtPacks_VBoxDTrace_Makefile.kmk) = 3c22df455dc5a573a0c6603fb6b368a6bae10005
+SHA1 (patch-src_VBox_ExtPacks_VBoxDTrace_VBoxDTraceWrapper.cpp) = f84f01b25fd870d247af1c07da91d137e43c9432
+SHA1 (patch-src_VBox_ExtPacks_VNC_Makefile.kmk) = bb1d503b158c67ee719813a60067098f48b0fc16
+SHA1 (patch-src_VBox_Frontends_VBoxAutostart_VBoxAutostart-posix.cpp) = a71304926b9ee6483db98a6820c412e240412f94
+SHA1 (patch-src_VBox_Frontends_VBoxBalloonCtrl_VBoxWatchdog.cpp) = f3cab833ad225707727b9c086e31eded736e21f6
+SHA1 (patch-src_VBox_Frontends_VBoxManage_VBoxInternalManage.cpp) = 1ed2323d1ba63ea529901fb6a89412f7398a2ca7
+SHA1 (patch-src_VBox_Frontends_VBoxManage_VBoxManageHelp.cpp) = f4887fa62c8f731c025cd2ae6a7f5d3fbc698adf
+SHA1 (patch-src_VBox_Frontends_VBoxManage_VBoxManageModifyVM.cpp) = 981e932def953e62666cb613def76d4fc1da4973
+SHA1 (patch-src_VBox_Frontends_VBoxSDL_Makefile.kmk) = 2b97c7a5f9c6966c4416be63f7f2b9248cf76cd8
+SHA1 (patch-src_VBox_Frontends_VirtualBox_Makefile.kmk) = 502cd14e6b912d27d18bb675fd1c0ed1d671bc10
+SHA1 (patch-src_VBox_Frontends_VirtualBox_src_VBoxGLSupportInfo.cpp) = f6d5e4197f48b87a92c856b293234da32074ab54
+SHA1 (patch-src_VBox_Frontends_VirtualBox_src_net_UIUpdateManager.cpp) = a8b72c225780fe1e95f97960817256c1c5239bec
+SHA1 (patch-src_VBox_Frontends_VirtualBox_src_settings_machine_UIMachineSettingsAudio.cpp) = 2b4d59f7b3913f0371e5be66628dc3d2a6a02242
+SHA1 (patch-src_VBox_GuestHost_OpenGL_Makefile.kmk) = ab26b3a7948475f9419d4523a62d29de6baa8833
+SHA1 (patch-src_VBox_GuestHost_OpenGL_include_chromium.h) = f165da53ecffecf1efe717e3910eb89c85aa691b
+SHA1 (patch-src_VBox_GuestHost_OpenGL_include_cr__dll.h) = 14afc936727aa02d40d01d50e50a527f3b628c54
+SHA1 (patch-src_VBox_GuestHost_OpenGL_include_cr__timer.h) = fbc3e84725b65cf7cfae6a1c8c021f006482d61b
+SHA1 (patch-src_VBox_GuestHost_OpenGL_spu__loader_glloader.py) = c0adfee444458753c0ffbe62e5045213a4d51b95
+SHA1 (patch-src_VBox_GuestHost_OpenGL_util_dll.c) = 105691414621862e115c3fa84892357fc74077ae
+SHA1 (patch-src_VBox_GuestHost_OpenGL_util_environment.c) = 90e646ceb1a9502a916bb99b33529894210a8e94
+SHA1 (patch-src_VBox_GuestHost_OpenGL_util_timer.c) = 59d4b1296d928254c38bb79fac89d2e34f6ff301
+SHA1 (patch-src_VBox_GuestHost_OpenGL_util_vboxhgcm.c) = a36f1b8cb73c6f24758822942291b46d548177f6
+SHA1 (patch-src_VBox_GuestHost_OpenGL_util_vboxhgsmi.c) = b81fa899ee99b2db490e3bac0b14d4115fc89e47
+SHA1 (patch-src_VBox_GuestHost_SharedClipboard_Makefile.kmk) = 4bb2ab80e8824d20e0358d1d374d8b0b30daa95c
+SHA1 (patch-src_VBox_HostDrivers_Makefile.kmk) = 0ac9a8767c9ce56e93cd614bcffe7c86da5fac1a
+SHA1 (patch-src_VBox_HostDrivers_Support_Makefile.kmk) = 0b9358eb11bf274c8ba5ffd6056ce76bab1ef6ea
+SHA1 (patch-src_VBox_HostDrivers_Support_SUPDrv.cpp) = 586aaa022f2a5a9147b0d4f1647230ac7ee89a6a
+SHA1 (patch-src_VBox_HostDrivers_Support_SUPDrvGip.cpp) = af044f4f74cd4879b05538c5d7fbb8dd97f1b678
+SHA1 (patch-src_VBox_HostDrivers_Support_SUPDrvIDC.h) = 340f0b02bd21ba463578d1560a3e3f494a874890
+SHA1 (patch-src_VBox_HostDrivers_Support_SUPDrvInternal.h) = e40bd87c79e140ef1d7a774679ff6cd22dc281b9
+SHA1 (patch-src_VBox_HostDrivers_Support_SUPDrvTracer.cpp) = 754583a84916aca5a8c378658d7eab7356ad7d00
+SHA1 (patch-src_VBox_HostDrivers_Support_SUPR3HardenedMain.cpp) = 688f9fab1f30330fa105f1a4913ffeb8776ba9e7
+SHA1 (patch-src_VBox_HostDrivers_Support_netbsd_Makefile) = 42a33228b7bded32fb9b543d1de0b9d2acb57f90
+SHA1 (patch-src_VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.c) = fbc5fd6f45657e3323f731f09a1da298dd06db7c
+SHA1 (patch-src_VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.def) = 85eb317c813e124b1b9556f9cdb5725ec6278f8f
+SHA1 (patch-src_VBox_HostDrivers_Support_netbsd_SUPLib-netbsd.cpp) = b6690a459513a372be5200381fcb34b6e5b220d9
+SHA1 (patch-src_VBox_HostDrivers_Support_netbsd_SUPR0IdcClient-netbsd.c) = dd51dbf5274d223424124fb29886d8737f02bce7
+SHA1 (patch-src_VBox_HostDrivers_Support_netbsd_files__vboxdrv) = 16bfd494b5f406cfb1824b62a6c568db1befc16f
+SHA1 (patch-src_VBox_HostDrivers_VBoxNetAdp_Makefile.kmk) = 5d2bf3d9bd06e1deaab8060c17aed30fd80411d0
+SHA1 (patch-src_VBox_HostDrivers_VBoxNetAdp_VBoxNetAdpInternal.h) = d738f197a2d3a736f56aff5005fed7756c543827
+SHA1 (patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_Makefile) = 5fa21e33796ca01d143abac5c6f6537a233676ab
+SHA1 (patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_VBoxNetAdp-netbsd.c) = 08de7421b2937c723a6d612e3a913a257eba2e72
+SHA1 (patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_files__vboxnetadp) = 11f5cb24de890b66e247c29ec0cb4a9773c06089
+SHA1 (patch-src_VBox_HostDrivers_VBoxNetFlt_Makefile.kmk) = c96d162a56023a0e3fd104ade8a5a86d1a3cd217
+SHA1 (patch-src_VBox_HostDrivers_VBoxNetFlt_VBoxNetFltInternal.h) = 1cd4b438d22169d39229625c2b9852290e93c42f
+SHA1 (patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_Makefile) = 96c5c1ffe7b16b349c0bc4c8da85d8f677867c62
+SHA1 (patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_VBoxNetFlt-netbsd.c) = 19f2c118a358b2de02be90a18d9280c686948bff
+SHA1 (patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_files__vboxnetflt) = 0777bc7009f6644e024089524606e67769615830
+SHA1 (patch-src_VBox_HostDrivers_netbsd_Makefile) = b949a73b17a516be0cbfe1cd9f486ad9c69abcd8
+SHA1 (patch-src_VBox_HostDrivers_netbsd_Makefile.kmk) = 0ebb3b51f15aa94cfc1cf502536dff7140f082d9
+SHA1 (patch-src_VBox_HostServices_Makefile.kmk) = 5c6cc9480c3ae255ff71cc4cb10a72309e1d244a
+SHA1 (patch-src_VBox_HostServices_SharedClipboard_Makefile.kmk) = a5d01d4beb8e359f9acee4cd1538b13afc1e5388
+SHA1 (patch-src_VBox_HostServices_SharedOpenGL_Makefile.kmk) = fac651b38e46be39f86f106fe432dbad562cf9af
+SHA1 (patch-src_VBox_HostServices_auth_Makefile.kmk) = 6cfd3e5a2873629e8721ae30b94e476ed8009e24
+SHA1 (patch-src_VBox_HostServices_auth_pam_VBoxAuthPAM.c) = b8015ac5a32d32cc6d50985cccb898449cbe99ec
+SHA1 (patch-src_VBox_ImageMounter_VBoxFUSE_Makefile.kmk) = a4d2970cf51a657ceb9373fae5238a9c29b94961
+SHA1 (patch-src_VBox_ImageMounter_VBoxFUSE_VBoxFUSE.cpp) = fe2f5e836eacb7304891f2955caddf7bc52ae988
+SHA1 (patch-src_VBox_Installer_Makefile.kmk) = 90beb8bf00c0207446af4d3db92ad745c8d1be72
+SHA1 (patch-src_VBox_Installer_darwin_VirtualBox_postflight) = d2251d079cc9e683a6d0aeb8b5a43bd64b19f3a3
+SHA1 (patch-src_VBox_Installer_darwin_VirtualBox_preflight) = b8918b156eafb5febce4be1c2f28f576b949a47f
+SHA1 (patch-src_VBox_Installer_linux_VBoxSysInfo.sh) = 67a71cb960c314bf9c02d5459f91fde20e9a68f2
+SHA1 (patch-src_VBox_Installer_linux_debian_control) = 2b75a4db1873ad1e5bd52bfa11448b218cb3bff5
+SHA1 (patch-src_VBox_Installer_linux_rpm_VirtualBox.tmpl.spec) = cf6e5b9f34cb0b708a04d0b552e2c46d6f05526e
+SHA1 (patch-src_VBox_Installer_netbsd_Makefile.kmk) = d6fd8928fda1884a30631196bc9000234c18fa9b
+SHA1 (patch-src_VBox_Installer_netbsd_pkg-comment) = 4b2ce009a24ab94c1f83c1f4bc6ed4537246d9a1
+SHA1 (patch-src_VBox_Installer_netbsd_pkg-descr) = b7c85ea5685ad7da628247d5926542b82863e748
+SHA1 (patch-src_VBox_Installer_netbsd_pkg__plist) = f8c784bb044bde2a3e78382f98c8479cb0b5054e
+SHA1 (patch-src_VBox_Installer_netbsd_postdeinstall.sh) = 97e6762b381fe2239adc6b52cd5352815405747a
+SHA1 (patch-src_VBox_Installer_netbsd_postinstall.sh) = ef1356ccf355d789733a6522435242e607e34058
+SHA1 (patch-src_VBox_Installer_netbsd_virtualbox.desktop) = f0973e025a4333750e741cbacf16275cc4d5982d
+SHA1 (patch-src_VBox_Main_Makefile.kmk) = 2f3cac33895b6e0cee14593bd0d85aa3c7e25234
+SHA1 (patch-src_VBox_Main_cbinding_VBoxCAPIGlue.c) = f2ab8096d65b200bad3171875706d3acd3e86ea4
+SHA1 (patch-src_VBox_Main_cbinding_VBoxCAPI__v2__2.h) = 0a66eb2fa8ebcb1dd8a720dd3dadbb03a8a8c5b7
+SHA1 (patch-src_VBox_Main_cbinding_VBoxCAPI__v3__0.h) = 0c49c14b973ea74bdb0bf6e3c124d87ba1eaeb20
+SHA1 (patch-src_VBox_Main_glue_tests_Makefile) = 19002fe2622195a6342eeec8cb180ced75ad7c0a
+SHA1 (patch-src_VBox_Main_include_ConsoleImpl.h) = 5bc4916830e8f7e2c47c5c98d9491312f9543f1d
+SHA1 (patch-src_VBox_Main_include_HostUSBDeviceImpl.h) = 6d4a8057ea6e52aefc605e23f0a770cc5adee9ae
+SHA1 (patch-src_VBox_Main_include_USBProxyService.h) = e06e4b5fb3f40cde49fb46c8b63d53883cde863e
+SHA1 (patch-src_VBox_Main_include_ovfreader.h) = f2e8caa5daf609f80040f14cc28baedc999b806a
+SHA1 (patch-src_VBox_Main_src-client_ConsoleImpl.cpp) = b3da50392a63f5f4313782751df7abfbaf33d2bf
+SHA1 (patch-src_VBox_Main_src-client_ConsoleImpl2.cpp) = ac8fcb71cdc19d76bb8c66c0c20310dabc308215
+SHA1 (patch-src_VBox_Main_src-server_ApplianceImpl.cpp) = 3e1d6959ab6f8422fdd898f376ec114ff9fefd11
+SHA1 (patch-src_VBox_Main_src-server_HostDnsService.cpp) = 493f34bc90ee49085cfddb7f44dd9ab31c95b774
+SHA1 (patch-src_VBox_Main_src-server_HostDnsService.h) = df468bf3ed607b0858a180954a29d45062e21fcd
+SHA1 (patch-src_VBox_Main_src-server_HostImpl.cpp) = 94ee908eec9fd15bb2e9d65db373351724363990
+SHA1 (patch-src_VBox_Main_src-server_HostNetworkInterfaceImpl.cpp) = 19cd7af464a0c71c4396210ce554076c30bb1cae
+SHA1 (patch-src_VBox_Main_src-server_MachineImpl.cpp) = ad6a19bfc0ae125aacd4cb31cbb98cc0e2347c79
+SHA1 (patch-src_VBox_Main_src-server_generic_NetIf-generic.cpp) = b6f3629d789d24e5fcae35d6730400e90829c81c
+SHA1 (patch-src_VBox_Main_src-server_netbsd_HostHardwareNetBSD.cpp) = fd74325565b81014924f8fb8307c322c3194e4b3
+SHA1 (patch-src_VBox_Main_src-server_netbsd_Makefile.kup) = d74d57c9bb23cd2ac869e8b4dd65979ea5d43752
+SHA1 (patch-src_VBox_Main_src-server_netbsd_NetIf-netbsd.cpp) = 5979bd5a04a7ad8463c43c51d5f1575f78121127
+SHA1 (patch-src_VBox_Main_src-server_netbsd_PerformanceNetBSD.cpp) = 9ed0245868e054892e0d939205ffa72f0f9ae562
+SHA1 (patch-src_VBox_Main_src-server_netbsd_USBProxyServiceNetBSD.cpp) = 2295ec43bd4256bb93d2e7bbde6fd1dae5cf7e0b
+SHA1 (patch-src_VBox_Main_testcase_tstCollector.cpp) = 6947b195a11e59936aa9cc0f4ba89aa303c15ab1
+SHA1 (patch-src_VBox_Main_webservice_vboxweb.cpp) = 3386319324815e539d734c769766ba621210ba32
+SHA1 (patch-src_VBox_Main_xml_Settings.cpp) = 94a74a59e3b3dbaa28e8c5683d7a75af8a9544bd
+SHA1 (patch-src_VBox_Main_xml_VirtualBox-settings.xsd) = e5cd29442dcc67cc9b8019a14903e8501c3042fa
+SHA1 (patch-src_VBox_Makefile.kmk) = c6c010cc8fa19c6445d4d03b630a8741ccc3d364
+SHA1 (patch-src_VBox_NetworkServices_NAT_Makefile.kmk) = cb489f3e32ea551faa59f1172500731ab2e74863
+SHA1 (patch-src_VBox_NetworkServices_NAT_pxping.c) = 7e7f3fd26ae5f787e5cb9299d24eea9c4a53529a
+SHA1 (patch-src_VBox_NetworkServices_NAT_pxudp.c) = 56dd97543fd9be4096d4b3aa1fd25075ec4ff7f3
+SHA1 (patch-src_VBox_Runtime_Makefile.kmk) = 103d89bf858e86a43da151095f83ca9a3a276a93
+SHA1 (patch-src_VBox_Runtime_VBox_log-vbox.cpp) = b833b5e038652518f3c0ad74c699bc0ab57f56d5
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_alloc-r0drv-netbsd.c) = 8d39beeb6c649a68794b17e0cec27fc6acb68fed
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_assert-r0drv-netbsd.c) = a333976118abdc7f6c143c95f648ab9aa51c885e
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_initterm-r0drv-netbsd.c) = 80a02c8837b25253f891ae8af1b6c8418cbd1852
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_memobj-r0drv-netbsd.c) = ffd98f71fb5ff12a5d054d8b2ed2a933fbc44b2c
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_memuserkernel-r0drv-netbsd.c) = 2822ca57f3b8a1b5df5a09137108a910fd9a10fb
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_mp-r0drv-netbsd.c) = 780b8e6780b134de01218d5d356862b105ed1934
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_process-r0drv-netbsd.c) = e76ad01b63d8a2435e02f6e64c0bdf3b9ba35031
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_semevent-r0drv-netbsd.c) = a3f4ad38aeba4d37af35382e704028e10695552c
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_semeventmulti-r0drv-netbsd.c) = 86f9df32d970e9f06717325439cdf4ea0652c799
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_semfastmutex-r0drv-netbsd.c) = 22d00b556b7f3839ebd95a336a589bc80938940a
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_semmutex-r0drv-netbsd.c) = b560eaf7a9f0b5fe5e1b22c9937520b11931f107
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_sleepqueue-r0drv-netbsd.h) = 3aab753113d2ee1af15bf58799d4bf608447bc77
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_spinlock-r0drv-netbsd.c) = 9bfc083274e80d0707bc335580e04acb84934ec6
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_the-netbsd-kernel.h) = b1e998b8e79471a313f16aa8a74342e6d2e4a61c
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_thread-r0drv-netbsd.c) = 0717c0b70e1f90e12d7489960cc9e7f6ac3638b1
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_thread2-r0drv-netbsd.c) = 911cecba018896d7626a1cb7ef60c00d8159d419
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_time-r0drv-netbsd.c) = c3e475887b1751943ac066187d5034f3c1ba9b72
+SHA1 (patch-src_VBox_Runtime_r0drv_netbsd_timer-r0drv-netbsd.c) = 9ff20109f3b7459544b0de405e305c0ee5a89ac0
+SHA1 (patch-src_VBox_Runtime_r3_init.cpp) = 1d80d2335a2fe24a17f954812073bca6f9a3f8e7
+SHA1 (patch-src_VBox_Runtime_r3_netbsd_fileaio-netbsd.cpp) = 4398c5ee439acbea4e7a1d3be1069345870f2143
+SHA1 (patch-src_VBox_Runtime_r3_netbsd_mp-netbsd.cpp) = c753459fc84c64aa560ca46d0eef78d575b3b91f
+SHA1 (patch-src_VBox_Runtime_r3_netbsd_rtProcInitExePath-netbsd.cpp) = 8395efc0496b3590403ae5af34840bc515189781
+SHA1 (patch-src_VBox_Runtime_r3_netbsd_systemmem-netbsd.cpp) = 8839c15e35275013952da1573f66d79c40dc78a4
+SHA1 (patch-src_VBox_Runtime_r3_posix_fileaio-posix.cpp) = 71651627904b5ff98a2b2771a09bcc99a2eb82ad
+SHA1 (patch-src_VBox_Runtime_r3_posix_fileio-posix.cpp) = 7a1938001c15ce6bf6f46777cde671ece9ba1e32
+SHA1 (patch-src_VBox_Runtime_r3_posix_fs-posix.cpp) = 38911cba4785635527aed70d0fb819821b3e6342
+SHA1 (patch-src_VBox_Runtime_r3_posix_path2-posix.cpp) = 512e64a1ae953748f589e95f95b3945935310514
+SHA1 (patch-src_VBox_Runtime_r3_posix_thread-posix.cpp) = c6e672e0a394cd013e71341689c680c4bff81d38
+SHA1 (patch-src_VBox_Runtime_r3_posix_thread2-posix.cpp) = c909a7e96477284102624502e3bbf790ec2b71a6
+SHA1 (patch-src_VBox_Storage_testcase_Makefile.kmk) = edafb43c93359d0b37fbe4bec839370f2d2db29e
+SHA1 (patch-src_VBox_VMM_VMMR0_GMMR0.cpp) = 08336e3aa159e2d2092cacbd16c2011963fe3908
+SHA1 (patch-src_VBox_VMM_VMMR0_VMMR0.cpp) = 57f17e39057edea79be1fa16a43f0624eaf2a15b
+SHA1 (patch-src_VBox_VMM_VMMR3_PGMPhys.cpp) = 4b934d9c2dfcffc38eb4b9e834d91328c284a50b
+SHA1 (patch-src_VBox_VMM_VMMR3_VM.cpp) = bf65afe2fe4012c332a3914eeaddde7a980c19b5
+SHA1 (patch-src_VBox_VMM_VMMRC_VMMRCDeps.cpp) = 4c6a6919633b07e1e6a9b93ec2c49dfec598f7cd
+SHA1 (patch-src_VBox_VMM_testcase_mkdsk.sh) = b45e17ad1ea5ab524fd4e36448b29b5700e20fec
+SHA1 (patch-src_VBox_VMM_testcase_tstX86-1.cpp) = bbdefc55c2ca664475417a127093995c6e618b79
+SHA1 (patch-src_VBox_ValidationKit_Makefile.kmk) = a9d0dbc43708423f088798dd4fdfc79e2d54c90a
+SHA1 (patch-src_VBox_ValidationKit_testboxscript_testboxscript__real.py) = 2091a7308e9168bbdd09c35820c4b7487be816f5
+SHA1 (patch-src_VBox_ValidationKit_testdriver_base.py) = 4af1913442af97e74227ae4a855149e6eb4a83f5
+SHA1 (patch-src_VBox_ValidationKit_testdriver_vbox.py) = b7c02df0233aaa946145c598fc5be0ee0c910589
+SHA1 (patch-src_VBox_ValidationKit_testdriver_vboxtestvms.py) = a9d41e33691622c9ee52fedbbac5e3261b0fe335
+SHA1 (patch-src_VBox_ValidationKit_testmanager_core_coreconsts.py) = 68eec44aa0d0b824593b77d26ca9d79f4e2a9c78
+SHA1 (patch-src_VBox_ValidationKit_tests_autostart_tdAutostart1.py) = 750ed6069a119efe97ebc082b74d6a1c8ee6950a
+SHA1 (patch-src_apps_Makefile.kmk) = 578f077b8961fab80d839c7024e3e89cec29c3e0
+SHA1 (patch-src_libs_libxml2-2.9.2_include_vboxconfig.h) = 461438f04dcf7f54051f897834f3fc6457ddfdf0
+SHA1 (patch-src_recompiler_Makefile.kmk) = 0f849ac56932b41882f056df3b59a5626fe8608b
+SHA1 (patch-src_recompiler_exec.c) = b8d61864eb2b6426607c850585b1ccd11446e905
+SHA1 (patch-tools_bin_gen-slickedit-workspace.sh) = 3db84478c9d4235319cccbe2c2d57c540f859738
diff --git a/virtualbox/patches/patch-Config.kmk b/virtualbox/patches/patch-Config.kmk
new file mode 100644
index 0000000..540f030
--- /dev/null
+++ b/virtualbox/patches/patch-Config.kmk
@@ -0,0 +1,110 @@
+$NetBSD$
+
+--- Config.kmk.orig 2016-03-04 19:22:54.000000000 +0000
++++ Config.kmk
+@@ -1908,7 +1908,7 @@ VBOX_CHECK_IMPORTS ?= $(PATH_OBJ)/VBoxCh
+ # GNU tar if present.
+ if1of ($(KBUILD_TARGET), linux os2 win)
+ VBOX_GTAR ?= tar
+-else if1of ($(KBUILD_TARGET), freebsd solaris)
++else if1of ($(KBUILD_TARGET), freebsd netbsd solaris)
+ VBOX_GTAR ?= gtar
+ endif
+
+@@ -3979,6 +3979,81 @@ TEMPLATE_VBOXR0DRV_CXXFLAGS.x86 =
+ TEMPLATE_VBOXR0DRV_CXXFLAGS.amd64 = $(TEMPLATE_VBOXR0DRV_CFLAGS.amd64) -fno-exceptions -fno-rtti
+ endif # Haiku
+
++ifeq ($(KBUILD_TARGET),netbsd)
++## The location of the NetBSD kernel source.
++VBOX_NETBSD_SRC ?= /usr/src/sys
++## The FreeBSD /usr/include.
++VBOX_NETBSD_SYS_INCS ?= /usr/include
++
++TEMPLATE_VBOXR0DRV_TOOL = $(VBOX_GCC_TOOL)
++TEMPLATE_VBOXR0DRV_LDTOOL = NETBSDKMODLD
++TEMPLATE_VBOXR0DRV_DEFS += _KERNEL KLD_MODULE
++TEMPLATE_VBOXR0DRV_INCS = \
++ $(VBOX_NETBSD_SRC) \
++ $(VBOX_NETBSD_SRC)/contrib/altq \
++ $(VBOX_NETBSD_SRC)/../include \
++ $(VBOX_NETBSD_SYS_INCS)
++# omitting: -Wcast-qual, -Wredundant-decls
++TEMPLATE_VBOXR0DRV_CFLAGS = \
++ $(VBOX_GCC_WARN) -Wpointer-arith -Winline $(VBOX_GCC_Wno-pointer-sign) $(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 \
++ $(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
++ -nostdinc -std=c99
++TEMPLATE_VBOXR0DRV_CFLAGS.x86 = -m32 -mno-align-long-strings -mpreferred-stack-boundary=2 -mno-mmx -mno-3dnow -mno-sse -mno-sse2
++TEMPLATE_VBOXR0DRV_CFLAGS.amd64 = -m64 --param inline-unit-growth=100 --param large-function-growth=1000 \
++ -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 -Wundef
++TEMPLATE_VBOXR0DRV_CXXFLAGS = -fno-exceptions -fno-rtti \
++ $(VBOX_GCC_WARN) -Wpointer-arith -Winline \
++ -O2 -fno-strict-aliasing -fno-common -finline-limit=8000 \
++ $(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
++ -nostdinc
++TEMPLATE_VBOXR0DRV_CXXFLAGS.x86 = $(TEMPLATE_VBOXR0DRV_CFLAGS.x86)
++TEMPLATE_VBOXR0DRV_CXXFLAGS.amd64 = $(TEMPLATE_VBOXR0DRV_CFLAGS.amd64)
++TEMPLATE_VBOXR0DRV_SYSSUFF = .kmod
++TEMPLATE_VBOXR0DRV_LDFLAGS = -d --warn-common
++TEMPLATE_VBOXR0DRV_LDFLAGS.x86 = -m elf_i386_fbsd
++TEMPLATE_VBOXR0DRV_LDFLAGS.amd64 = -m elf_x86_64_fbsd
++
++TOOL_NETBSDKMODLD = NetBSD kernel module linker.
++# See kBuild/tools/GCC3.kmk for docs.
++TOOL_NETBSDKMODLD_LINK_SYSMOD_OUTPUT_MAYBE = $(outbase).map
++TOOL_NETBSDKMODLD_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
++TOOL_NETBSDKMODLD_LINK_SYSMOD_DEPORD =
++ ifeq ($(KBUILD_TARGET_ARCH),amd64)
++TOOL_NETBSDKMODLD_LINK_SYSMOD_OUTPUT =
++define TOOL_NETBSDKMODLD_LINK_SYSMOD_CMDS
++# Link intermediate .kld (a relocatable object).
++ ld $(flags) -r -o $(out) $(objs) \
++ $(foreach p,$(libpath), -L$(p))\
++ $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
++# Strip non-exported symbols private and localize the exported ones.
++ awk -f $(VBOX_NETBSD_SRC)/conf/kmod_syms.awk $(out) $(if $(othersrc), $(othersrc),/dev/null) \
++ | xargs -J% objcopy % $(out)
++
++## Strip debug info (comment out if debugging or something).
++ objcopy --strip-debug $(out)
++endef
++ else # x86
++TOOL_NETBSDKMODLD_LINK_SYSMOD_OUTPUT = $(outbase).kld
++define TOOL_NETBSDKMODLD_LINK_SYSMOD_CMDS
++# Link intermediate .kld (a relocatable object).
++ ld $(flags) -r -o $(outbase).kld $(objs) \
++ $(foreach p,$(libpath), -L$(p))\
++ $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
++# Strip non-exported symbols private and localize the exported ones.
++ awk -f $(VBOX_NETBSD_SRC)/conf/kmod_syms.awk $(outbase).kld $(if $(othersrc), $(othersrc),/dev/null) \
++ | xargs -J% objcopy % $(outbase).kld
++
++# Link the final .ko (a shared object).
++ ld $(flags) -Bshareable -o $(out) $(outbase).kld
++endef
++ endif # x86
++
++endif # NetBSD
++
+ ifdef VBOX_WITH_VBOXDRV
+ ifndef TEMPLATE_VBOXR0DRV_TOOL
+ $(warning Warning: VBox Build: Target $(KBUILD_HOST) is not officially supported!)
+@@ -5710,7 +5785,7 @@ TEMPLATE_VBOXGUESTR3EXE_DEFS := $(fi
+ TEMPLATE_VBOXGUESTR3EXE_DEFS.linux := $(TEMPLATE_VBOXR3EXE_DEFS.linux) LOG_USE_C99 RT_WITHOUT_EXEC_ALLOC
+ ifeq ($(KBUILD_TARGET),linux) # As few libs as possible on linux.
+ TEMPLATE_VBOXGUESTR3EXE_LIBS = pthread rt m dl
+-else if1of ($(KBUILD_TARGET), darwin freebsd netbsd openbsd)
++else if1of ($(KBUILD_TARGET), darwin freebsd openbsd)
+ TEMPLATE_VBOXGUESTR3EXE_LIBS = $(TEMPLATE_VBOXR3EXE_LIBS) iconv
+ else ifeq ($(KBUILD_TARGET), solaris)
+ TEMPLATE_VBOXGUESTR3EXE_LIBS = $(TEMPLATE_VBOXR3EXE_LIBS) nsl
+@@ -6384,5 +6459,3 @@ st stat status:
+
+ quick:
+ $(MAKE) VBOX_QUICK=1
+-
+-
diff --git a/virtualbox/patches/patch-Makefile.kmk b/virtualbox/patches/patch-Makefile.kmk
new file mode 100644
index 0000000..f0df6b8
--- /dev/null
+++ b/virtualbox/patches/patch-Makefile.kmk
@@ -0,0 +1,178 @@
+$NetBSD$
+
+--- Makefile.kmk.orig 2016-03-04 19:22:54.000000000 +0000
++++ Makefile.kmk
+@@ -525,6 +525,7 @@ VBOX_CORE_DOXYFILE_INPUT_DIRS = \
+ src/VBox/HostDrivers/Support \
+ src/VBox/HostDrivers/Support/darwin \
+ src/VBox/HostDrivers/Support/freebsd \
++ src/VBox/HostDrivers/Support/netbsd \
+ src/VBox/HostDrivers/Support/linux \
+ src/VBox/HostDrivers/Support/os2 \
+ src/VBox/HostDrivers/Support/solaris \
+@@ -612,6 +613,7 @@ VBOX_CORE_DOXYFILE_INPUT_DIRS = \
+ src/VBox/Additions/common/VBoxControl \
+ src/VBox/Additions/common/VBoxGuest \
+ src/VBox/Additions/common/VBoxGuest/freebsd \
++ src/VBox/Additions/common/VBoxGuest/netbsd \
+ src/VBox/Additions/common/VBoxGuest/linux \
+ src/VBox/Additions/common/VBoxGuest/win \
+ src/VBox/Additions/common/VBoxGuestLib \
+@@ -628,6 +630,10 @@ VBOX_CORE_DOXYFILE_INPUT_DIRS = \
+ src/VBox/Additions/freebsd/Installer \
+ src/VBox/Additions/freebsd/drm \
+ src/VBox/Additions/freebsd/vboxvfs \
++ src/VBox/Additions/netbsd \
++ src/VBox/Additions/netbsd/Installer \
++ src/VBox/Additions/netbsd/drm \
++ src/VBox/Additions/netbsd/vboxvfs \
+ src/VBox/Additions/linux \
+ src/VBox/Additions/linux/drm \
+ src/VBox/Additions/linux/installer \
+@@ -913,7 +919,7 @@ VBOX_RSYNC_IN_FN = rsync -a -v --delete
+ --exclude=tinderclient.log \
+ --exclude=tools/FetchDir/ \
+ --exclude=webtools/ \
+- $(foreach os,darwin freebsd linux solaris os2 win,$(if-expr "$(1)" != "$(os)", \
++ $(foreach os,darwin freebsd netbsd linux solaris os2 win,$(if-expr "$(1)" != "$(os)", \
+ --exclude=tools/$(os).x86/ \
+ --exclude=tools/$(os).amd64/ \
+ --exclude=out/$(os).amd64/ \
+@@ -1163,6 +1169,8 @@ additions-packing:
+ + $(KMK) VBOX_ONLY_ADDITIONS=1 \
+ VBOX_WITH_ADDITIONS_ISO.freebsd.amd64= \
+ VBOX_WITH_ADDITIONS_ISO.freebsd.x86= \
++ VBOX_WITH_ADDITIONS_ISO.netbsd.amd64= \
++ VBOX_WITH_ADDITIONS_ISO.netbsd.x86= \
+ VBOX_WITH_ADDITIONS_ISO.linux.amd64= \
+ VBOX_WITH_ADDITIONS_ISO.linux.x86=1 \
+ VBOX_WITH_COMBINED_LINUX_GUEST_PACKAGE=1 \
+@@ -1202,6 +1210,8 @@ extpacks-fetch:
+ + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=x86 KBUILD_TARGET=darwin BUILD_TARGET_ARCH=x86 BUILD_TARGET=darwin VBOX_ONLY_EXTPACKS=1
+ # + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=amd64 KBUILD_TARGET=freebsd BUILD_TARGET_ARCH=amd64 BUILD_TARGET=freebsd VBOX_ONLY_EXTPACKS=1
+ # + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=x86 KBUILD_TARGET=freebsd BUILD_TARGET_ARCH=x86 BUILD_TARGET=freebsd VBOX_ONLY_EXTPACKS=1
++# + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=amd64 KBUILD_TARGET=netbsd BUILD_TARGET_ARCH=amd64 BUILD_TARGET=netbsd VBOX_ONLY_EXTPACKS=1
++# + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=x86 KBUILD_TARGET=netbsd BUILD_TARGET_ARCH=x86 BUILD_TARGET=netbsd VBOX_ONLY_EXTPACKS=1
+ + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=amd64 KBUILD_TARGET=linux BUILD_TARGET_ARCH=amd64 BUILD_TARGET=linux VBOX_ONLY_EXTPACKS=1
+ + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=x86 KBUILD_TARGET=linux BUILD_TARGET_ARCH=x86 BUILD_TARGET=linux VBOX_ONLY_EXTPACKS=1
+ # + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=x86 KBUILD_TARGET=os2 BUILD_TARGET_ARCH=x86 BUILD_TARGET=os2 VBOX_ONLY_EXTPACKS=1
+@@ -1218,7 +1228,9 @@ extpacks-build: \
+ extpacks-build-linux \
+ extpacks-build-darwin.amd64 \
+ extpacks-build-freebsd.amd64 \
+- extpacks-build-freebsd.x86
++ extpacks-build-freebsd.x86 \
++ extpacks-build-netbsd.amd64 \
++ extpacks-build-netbsd.x86
+
+ VBOX_EXTPACKS_BUILD.amd64 = VBOX_ONLY_EXTPACKS=1 \
+ KBUILD_TYPE=$(KBUILD_TYPE) BUILD_TYPE=$(KBUILD_TYPE) \
+@@ -1339,6 +1351,24 @@ extpacks-build-freebsd.x86: $(VBOX_EXTPA
+ # $(call VBOX_BLD_VM_MSG_END__,FreeBSD/x86 extension packs)
+ #endif
+
++extpacks-build-netbsd.amd64: $(VBOX_EXTPACKS_BUILD_WIN_HOST_FIRST)
++#ifeq ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH),netbsd.amd64)
++# + $(VBOX_KMK_TIME) $(KMK) $(VBOX_EXTPACKS_BUILD.amd64) all $(VBOX_EXTPACKS_HOST_BUILD_TWEAK)
++#else
++# $(call VBOX_BLD_VM_MSG_BEGIN,NetBSD/amd64 extension packs)
++# $(VBOX_KMK_TIME) ssh vbox@$(VBOX_BLD_VM_FBSD_AMD64_IP) " echo $@ && cd /mnt/tinderbox/$(VBOX_EXTPACKS_BUILD_SUBDIRNAME) && tools/env.sh --no-wine kmk $(VBOX_EXTPACKS_BUILD.amd64) all"
++# $(call VBOX_BLD_VM_MSG_END__,NetBSD/amd64 extension packs)
++#endif
++
++extpacks-build-netbsd.x86: $(VBOX_EXTPACKS_BUILD_WIN_HOST_FIRST)
++#ifeq ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH),netbsd.x86)
++# + $(VBOX_KMK_TIME) $(KMK) $(VBOX_EXTPACKS_BUILD.x86) all $(VBOX_EXTPACKS_HOST_BUILD_TWEAK)
++#else
++# $(call VBOX_BLD_VM_MSG_BEGIN,NetBSD/x86 extension packs)
++# $(VBOX_KMK_TIME) ssh vbox@$(VBOX_BLD_VM_FBSD_X86_IP) " echo $@ && cd /mnt/tinderbox/$(VBOX_EXTPACKS_BUILD_SUBDIRNAME) && tools/env.sh --no-wine kmk $(VBOX_EXTPACKS_BUILD.x86) all"
++# $(call VBOX_BLD_VM_MSG_END__,NetBSD/x86 extension packs)
++#endif
++
+ extpacks-build-darwin.amd64: $(VBOX_EXTPACKS_BUILD_WIN_HOST_FIRST)
+ ifeq ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH),darwin.amd64)
+ + $(VBOX_KMK_TIME) $(KMK) $(VBOX_EXTPACKS_BUILD.amd64) all $(VBOX_EXTPACKS_HOST_BUILD_TWEAK)
+@@ -1354,7 +1384,7 @@ extpacks-packing:
+ + $(KMK) VBOX_ONLY_EXTPACKS=1 \
+ VBOX_WITH_EXTPACK_OS_ARCHS="darwin.amd64 linux.amd64 linux.x86 solaris.amd64 win.amd64 win.x86" \
+ packing
+-# +++ freebsd.amd64 freebsd.x86 os2.x86 ^^^
++# +++ freebsd.amd64 freebsd.x86 netbsd.amd64 netbsd.x86 os2.x86 ^^^
+
+ .PHONY: \
+ extpacks-build-win.x86 \
+@@ -1366,6 +1396,8 @@ extpacks-packing:
+ extpacks-build-linux.x86 \
+ extpacks-build-freebsd.amd64 \
+ extpacks-build-freebsd.x86 \
++ extpacks-build-netbsd.amd64 \
++ extpacks-build-netbsd.x86 \
+ extpacks-build-darwin.amd64 \
+ extpacks-packing
+
+@@ -1382,6 +1414,8 @@ validationkit-fetch:
+ + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=x86 KBUILD_TARGET=darwin BUILD_TARGET_ARCH=x86 BUILD_TARGET=darwin VBOX_ONLY_VALIDATIONKIT=1
+ # + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=amd64 KBUILD_TARGET=freebsd BUILD_TARGET_ARCH=amd64 BUILD_TARGET=freebsd VBOX_ONLY_VALIDATIONKIT=1
+ # + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=x86 KBUILD_TARGET=freebsd BUILD_TARGET_ARCH=x86 BUILD_TARGET=freebsd VBOX_ONLY_VALIDATIONKIT=1
++# + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=amd64 KBUILD_TARGET=netbsd BUILD_TARGET_ARCH=amd64 BUILD_TARGET=netbsd VBOX_ONLY_VALIDATIONKIT=1
++# + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=x86 KBUILD_TARGET=netbsd BUILD_TARGET_ARCH=x86 BUILD_TARGET=netbsd VBOX_ONLY_VALIDATIONKIT=1
+ + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=amd64 KBUILD_TARGET=linux BUILD_TARGET_ARCH=amd64 BUILD_TARGET=linux VBOX_ONLY_VALIDATIONKIT=1
+ + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=x86 KBUILD_TARGET=linux BUILD_TARGET_ARCH=x86 BUILD_TARGET=linux VBOX_ONLY_VALIDATIONKIT=1
+ + $(KMK) -C tools fetch KBUILD_TARGET_ARCH=x86 KBUILD_TARGET=os2 BUILD_TARGET_ARCH=x86 BUILD_TARGET=os2 VBOX_ONLY_VALIDATIONKIT=1
+@@ -1401,6 +1435,8 @@ validationkit-build: \
+ validationkit-build-linux \
+ validationkit-build-freebsd.amd64 \
+ validationkit-build-freebsd.x86 \
++ validationkit-build-netbsd.amd64 \
++ validationkit-build-netbsd.x86 \
+ validationkit-build-darwin.amd64 \
+ validationkit-build-darwin.x86
+
+@@ -1564,6 +1600,24 @@ validationkit-build-freebsd.x86: $(VBO
+ # $(call VBOX_BLD_VM_MSG_END__,Freebsd/x86 Validation Kit)
+ #endif
+
++validationkit-build-netbsd.amd64: $(VBOX_VALIDATIONKIT_BUILD_WIN_HOST_FIRST)
++#ifeq ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH),netbsd.amd64)
++# + $(VBOX_KMK_TIME) $(KMK) $(VBOX_VALIDATIONKIT_BUILD.amd64) all $(VBOX_VALIDATIONKIT_HOST_BUILD_TWEAK)
++#else
++# $(call VBOX_BLD_VM_MSG_BEGIN,Netbsd/amd64 Validation Kit)
++# $(VBOX_KMK_TIME) ssh vbox@$(VBOX_BLD_VM_NBSD_AMD64_IP) " echo $@ && cd /mnt/tinderbox/$(VBOX_VALIDATIONKIT_BUILD_SUBDIRNAME) && tools/env.sh --no-wine kmk $(VBOX_VALIDATIONKIT_BUILD.amd64) all"
++# $(call VBOX_BLD_VM_MSG_END__,Netbsd/amd64 Validation Kit)
++#endif
++
++validationkit-build-netbsd.x86: $(VBOX_VALIDATIONKIT_BUILD_WIN_HOST_FIRST)
++#ifeq ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH),netbsd.x86)
++# + $(VBOX_KMK_TIME) $(KMK) $(VBOX_VALIDATIONKIT_BUILD.x86) all $(VBOX_VALIDATIONKIT_HOST_BUILD_TWEAK)
++#else
++# $(call VBOX_BLD_VM_MSG_BEGIN,Netbsd/x86 Validation Kit)
++# $(VBOX_KMK_TIME) ssh vbox@$(VBOX_BLD_VM_NBSD_X86_IP) " echo $@ && cd /mnt/tinderbox/$(VBOX_VALIDATIONKIT_BUILD_SUBDIRNAME) && tools/env.sh --no-wine kmk $(VBOX_VALIDATIONKIT_BUILD.x86) all"
++# $(call VBOX_BLD_VM_MSG_END__,Netbsd/x86 Validation Kit)
++#endif
++
+ validationkit-build-darwin.amd64: $(VBOX_VALIDATIONKIT_BUILD_WIN_HOST_FIRST)
+ ifeq ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH),darwin.amd64)
+ + $(VBOX_KMK_TIME) $(KMK) $(VBOX_VALIDATIONKIT_BUILD.amd64) all $(VBOX_VALIDATIONKIT_HOST_BUILD_TWEAK)
+@@ -1593,6 +1647,8 @@ validationkit-packing:
+ VBOX_WITH_VALIDATIONKIT_PACKING.darwin.x86=2 \
+ VBOX_WITH_VALIDATIONKIT_PACKING.freebsd.amd64= \
+ VBOX_WITH_VALIDATIONKIT_PACKING.freebsd.x86= \
++ VBOX_WITH_VALIDATIONKIT_PACKING.netbsd.amd64= \
++ VBOX_WITH_VALIDATIONKIT_PACKING.netbsd.x86= \
+ VBOX_WITH_VALIDATIONKIT_PACKING.linux.amd64=1 \
+ VBOX_WITH_VALIDATIONKIT_PACKING.linux.x86=1 \
+ VBOX_WITH_VALIDATIONKIT_PACKING.os2.x86=1 \
+@@ -1615,6 +1671,8 @@ validationkit-packing:
+ validationkit-build-linux.x86 \
+ validationkit-build-freebsd.amd64 \
+ validationkit-build-freebsd.x86 \
++ validationkit-build-netbsd.amd64 \
++ validationkit-build-netbsd.x86 \
+ validationkit-build-darwin.amd64 \
+ validationkit-build-darwin.x86 \
+ validationkit-packing
+@@ -1819,4 +1877,3 @@ sdk:
+
+ sdk-fetch:
+ + $(KMK) VBOX_ONLY_SDK=1 -C tools
+-
diff --git a/virtualbox/patches/patch-configure b/virtualbox/patches/patch-configure
new file mode 100644
index 0000000..451aff1
--- /dev/null
+++ b/virtualbox/patches/patch-configure
@@ -0,0 +1,117 @@
+$NetBSD$
+
+--- configure.orig 2016-03-04 19:22:54.000000000 +0000
++++ configure
+@@ -51,6 +51,8 @@ case "$OS" in
+ ;;
+ freebsd)
+ ;;
++ netbsd)
++ ;;
+ sunos)
+ OS='solaris'
+ ;;
+@@ -134,19 +136,12 @@ LIBVNCSERVER="-lvncserver"
+ INCDEVMAPPER=""
+ LIBDEVMAPPER="-ldevmapper"
+ CXX_FLAGS=""
+-if [ "$OS" = "freebsd" ]; then
+- INCCURL="-I/usr/local/include"
+- LIBCURL="-L/usr/local/lib -lcurl"
+- INCPULSE="-I/usr/local/include"
+- LIBPULSE="-L/usr/local/lib"
+- INCPNG="-I/usr/local/include"
+- LIBPNG="-L/usr/local/lib -lpng"
+-else
+- INCCURL=""
+- LIBCURL="-lcurl"
+- INCPNG=""
+- LIBPNG="-lpng"
+-fi
++INCCURL="-I/usr/local/include"
++LIBCURL="-L/usr/local/lib -lcurl"
++INCPULSE="-I/usr/local/include"
++LIBPULSE="-L/usr/local/lib"
++INCPNG="-I/usr/local/include"
++LIBPNG="-L/usr/local/lib -lpng"
+ INCVPX=""
+ LIBVPX="-lvpx"
+ PKGCONFIG="`which_wrapper pkg-config`"
+@@ -438,7 +433,7 @@ check_gcc()
+ -o \( $cc_maj -eq 5 -a $cc_min -gt 3 \) \
+ -o $cc_maj -gt 5 ]; then
+ log_failure "gcc version $cc_maj.$cc_min found, expected gcc 3.x with x>1 or gcc 4.x with 0<x<10 or gcc 5.3"
+- fail really
++# fail really
+ else
+ log_success "found version $cc_ver"
+ fi
+@@ -529,6 +524,7 @@ check_open_watcom()
+ "darwin") wc_bin="binosx";; # ??
+ "dos") wc_bin="binw";;
+ "freebsd") wc_bin="binfbsd";; # ??
++ "freebsd") wc_bin="binnbsd";; # ??
+ "linux") wc_bin="binl";;
+ "solaris") wc_bin="binsol";; # ??
+ "os2") wc_bin="binp";;
+@@ -914,7 +910,7 @@ EOF
+ [ -n "$INCZ" ] && I_INCZ=`prefix_I "$INCZ"`
+ if test_compile "$LIBZ $I_INCZ" zlib zlib; then
+ if test_execute; then
+- echo "if1of (\$(KBUILD_TARGET),darwin freebsd haiku linux)" >> $CNF
++ echo "if1of (\$(KBUILD_TARGET),darwin freebsd netbsd haiku linux)" >> $CNF
+ cnf_append " SDK_VBOX_ZLIB_LIBS" "`strip_l "$LIBZ"`"
+ cnf_append " SDK_VBOX_ZLIB_INCS" "$INCZ"
+ echo "endif" >> $CNF
+@@ -1932,20 +1928,16 @@ extern "C" int main(void)
+ }
+ EOF
+ found=
+-# For Solaris we use libpython2.4 for compatibility with Solaris 10 and passing IPS pkg audit
+- if [ "$OS" != "solaris" ]; then
+- SUPPYTHONLIBS="python2.7 python2.6 python2.5 python2.4 python2.3"
+- else
+- SUPPYTHONLIBS="python2.4"
+- fi
++SUPPYTHONLIBS="python2.7 python2.6 python2.5 python2.4 python2.3"
++PYTHONLIBRPATH=""
+ for p in $PYTHONDIR; do
+ for d in $SUPPYTHONLIBS; do
+ for b in lib/x86_64-linux-gnu lib/i386-linux-gnu lib64 lib/64 lib; do
+ 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 $PYTHONLIBRPATH" >> $LOG
++ $CXX -O -Wall -o $ODIR.tmp_out $ODIR.tmp_src.cc -I$p/include/$d $p/$b/lib$d.so $PYTHONLIBRPATH >> $LOG 2>&1
+ if [ $? -eq 0 ]; then
+ found=1
+ break
+@@ -2287,7 +2279,7 @@ EOF
+ [ $OSE -eq 0 ] && echo " --disable-extpack don't build the extpack"
+ [ $WITH_DOCS -eq 1 ] && echo " --disable-docs don't build the documentation"
+ [ $WITH_LIBVPX -eq 1 ] && echo " --disable-libvpx don't use libvpx for video capturing"
+-[ "$OS" = "linux" -o "$OS" = "freebsd" ] && echo " --enable-vde enable VDE networking"
++[ "$OS" = "linux" -o "$OS" = "freebsd" -o "$OS" = "netbsd" ] && echo " --enable-vde enable VDE networking"
+ cat << EOF
+ --disable-udptunnel disable UDP tunnel networking
+ --disable-devmapper disable device mapper library access
+@@ -2744,7 +2736,7 @@ if [ $ONLY_ADDITIONS -eq 0 ]; then
+ [ $WITH_JAVA -eq 1 ] && check_java
+
+ # PulseAudio
+- if [ "$OS" = "linux" -o "$OS" = "freebsd" ]; then
++ if [ "$OS" = "linux" -o "$OS" = "freebsd" -o "$OS" = "netbsd" ]; then
+ if [ $WITH_PULSE -eq 1 ]; then
+ check_pulse
+ elif [ $WITH_PULSE -eq 0 ]; then
+@@ -2803,7 +2795,7 @@ if [ $ONLY_ADDITIONS -eq 0 -a $WITH_UDPT
+ fi
+
+ # VDE
+-if [ $ONLY_ADDITIONS -eq 0 -a "$OS" = "linux" -o "$OS" = "freebsd" ]; then
++if [ $ONLY_ADDITIONS -eq 0 -a "$OS" = "linux" -o "$OS" = "freebsd" -o "$OS" = "netbsd" ]; then
+ if [ $WITH_VDE -eq 1 ]; then
+ cnf_append "VBOX_WITH_VDE" "1"
+ fi
diff --git a/virtualbox/patches/patch-include_VBox_VBoxGuest.h b/virtualbox/patches/patch-include_VBox_VBoxGuest.h
new file mode 100644
index 0000000..80104bc
--- /dev/null
+++ b/virtualbox/patches/patch-include_VBox_VBoxGuest.h
@@ -0,0 +1,41 @@
+$NetBSD$
+
+--- include/VBox/VBoxGuest.h.orig 2016-03-04 19:22:56.000000000 +0000
++++ include/VBox/VBoxGuest.h
+@@ -204,6 +204,13 @@ typedef const VBGLBIGREQ *PCVBGLBIGREQ;
+ # define VBOXGUEST_IOCTL_CODE_FAST_(Function) _IO( 'V', (Function))
+ # define VBOXGUEST_IOCTL_STRIP_SIZE(Code) IOCBASECMD(Code)
+
++#elif defined(RT_OS_NETBSD) /** @todo r=bird: Please do it like SUPDRVIOC to keep it as similar as possible. */
++# include <sys/ioccom.h>
++
++# define VBOXGUEST_IOCTL_CODE_(Function, Size) _IOWR('V', (Function), VBGLBIGREQ)
++# define VBOXGUEST_IOCTL_CODE_FAST_(Function) _IO( 'V', (Function))
++# define VBOXGUEST_IOCTL_STRIP_SIZE(Code) IOCBASECMD(Code)
++
+ #else /* BSD Like */
+ /* Automatic buffering, size limited to 4KB on *BSD and 8KB on Darwin - commands the limit, 4KB. */
+ # include <sys/ioccom.h>
+@@ -534,7 +541,7 @@ typedef VBOXGUESTOS2IDCCONNECT *PVBOXGUE
+
+ #endif /* RT_OS_OS2 */
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+
+ /* Private IOCtls between user space and the kernel video driver. DRM private
+ * IOCtls always have the type 'd' and a number between 0x40 and 0x99 (0x9F?) */
+@@ -554,7 +561,7 @@ typedef VBOXGUESTOS2IDCCONNECT *PVBOXGUE
+ # define DRM_IOCTL_VBOX_ENABLE_HGSMI VBOX_DRM_IOCTL(ENABLE_HGSMI)
+ # define VBOXVIDEO_IOCTL_ENABLE_HGSMI _IO('d', DRM_IOCTL_VBOX_ENABLE_HGSMI)
+
+-#endif /* RT_OS_LINUX || RT_OS_SOLARIS || RT_OS_FREEBSD */
++#endif /* RT_OS_LINUX || RT_OS_SOLARIS || RT_OS_FREEBSD || RT_OS_FREEBSD */
+
+ #endif /* !defined(IN_RC) && !defined(IN_RING0_AGNOSTIC) && !defined(IPRT_NO_CRT) */
+
+@@ -562,4 +569,3 @@ typedef VBOXGUESTOS2IDCCONNECT *PVBOXGUE
+
+ /** @} */
+ #endif
+-
diff --git a/virtualbox/patches/patch-include_VBox_ostypes.h b/virtualbox/patches/patch-include_VBox_ostypes.h
new file mode 100644
index 0000000..fd20b34
--- /dev/null
+++ b/virtualbox/patches/patch-include_VBox_ostypes.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- include/VBox/ostypes.h.orig 2016-03-04 19:22:57.000000000 +0000
++++ include/VBox/ostypes.h
+@@ -157,6 +157,8 @@ typedef enum VBOXOSFAMILY
+ VBOXOSFAMILY_Solaris64 = 8,
+ VBOXOSFAMILY_MacOSX32 = 9,
+ VBOXOSFAMILY_MacOSX64 = 10,
++ VBOXOSFAMILY_NetBSD32 = 11,
++ VBOXOSFAMILY_NetBSD64 = 12,
+ /** The usual 32-bit hack. */
+ VBOXOSFAMILY_32BIT_HACK = 0x7fffffff
+ } VBOXOSFAMILY;
diff --git a/virtualbox/patches/patch-include_VBox_param.h b/virtualbox/patches/patch-include_VBox_param.h
new file mode 100644
index 0000000..b59ef5e
--- /dev/null
+++ b/virtualbox/patches/patch-include_VBox_param.h
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- include/VBox/param.h.orig 2016-03-04 19:22:57.000000000 +0000
++++ include/VBox/param.h
+@@ -45,7 +45,7 @@
+ * @remarks This must match GMMR0Init; currently we only support page fusion on
+ * all 64-bit hosts except Mac OS X */
+ #if ( HC_ARCH_BITS == 64 /* ASM-NOINC */ \
+- && (defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS)) ) /* ASM-NOINC */ \
++ && (defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(RT_OS_NETBSD)) ) /* ASM-NOINC */ \
+ || defined(DOXYGEN_RUNNING) /* ASM-NOINC */
+ # define VBOX_WITH_PAGE_SHARING /* ASM-NOINC */
+ #endif /* ASM-NOINC */
+@@ -172,4 +172,3 @@
+ /** @} */
+
+ #endif
+-
diff --git a/virtualbox/patches/patch-include_VBox_usb.h b/virtualbox/patches/patch-include_VBox_usb.h
new file mode 100644
index 0000000..5e48325
--- /dev/null
+++ b/virtualbox/patches/patch-include_VBox_usb.h
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- include/VBox/usb.h.orig 2016-03-04 19:22:58.000000000 +0000
++++ include/VBox/usb.h
+@@ -124,7 +124,7 @@ typedef struct USBDEVICE
+ uint8_t bBus;
+ /** The port number. */
+ uint8_t bPort;
+-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /** Device number. */
+ uint8_t bDevNum;
+ #endif
+@@ -260,4 +260,3 @@ typedef USBCONFIGDESC *PUSBCONFIGDESC;
+ RT_C_DECLS_END
+
+ #endif
+-
diff --git a/virtualbox/patches/patch-include_iprt_string.h b/virtualbox/patches/patch-include_iprt_string.h
new file mode 100644
index 0000000..efc4af3
--- /dev/null
+++ b/virtualbox/patches/patch-include_iprt_string.h
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- include/iprt/string.h.orig 2016-03-04 19:23:01.000000000 +0000
++++ include/iprt/string.h
+@@ -113,7 +113,7 @@ char *strpbrk(const char *pszStr, const
+ RT_C_DECLS_END
+ #endif
+
+-#if !defined(RT_OS_LINUX) || !defined(_GNU_SOURCE)
++#if (!defined(RT_OS_LINUX) || !defined(_GNU_SOURCE)) && !defined(RT_OS_NETBSD)
+ RT_C_DECLS_BEGIN
+ void *memrchr(const char *pv, int ch, size_t cb);
+ RT_C_DECLS_END
+@@ -3018,4 +3018,3 @@ RTDECL(uint32_t) RTStrHash1ExNV(size_
+ RT_C_DECLS_END
+
+ #endif
+-
diff --git a/virtualbox/patches/patch-src_VBox_Additions_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Additions_Makefile.kmk
new file mode 100644
index 0000000..8b3b671
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_Makefile.kmk
@@ -0,0 +1,56 @@
+$NetBSD$
+
+--- src/VBox/Additions/Makefile.kmk.orig 2016-03-04 19:23:02.000000000 +0000
++++ src/VBox/Additions/Makefile.kmk
+@@ -55,6 +55,9 @@ ifndef VBOX_ONLY_VALIDATIONKIT
+ ifeq ($(KBUILD_TARGET),freebsd)
+ include $(PATH_SUB_CURRENT)/freebsd/Makefile.kmk
+ endif
++ ifeq ($(KBUILD_TARGET),netbsd)
++ include $(PATH_SUB_CURRENT)/netbsd/Makefile.kmk
++ endif
+ ifeq ($(KBUILD_TARGET),linux)
+ include $(PATH_SUB_CURRENT)/linux/Makefile.kmk
+ endif
+@@ -199,6 +202,18 @@ ifdef VBOX_WITH_ADDITIONS_ISO.freebsd.x8
+ VBoxFreeBSDAdditions-x86.tbz=$(VBOX_PATH_ADDITIONS.freebsd.x86)/VBoxFreeBSDAdditions.tbz
+ endif
+
++# NetBSD
++ifdef VBOX_WITH_ADDITIONS_ISO.netbsd.amd64
++ VBOX_PATH_ADDITIONS.netbsd.amd64 = $(PATH_OUT_BASE)/netbsd.amd64/$(KBUILD_TYPE)/bin/additions
++ GUESTADDITIONS_FILESPEC.netbsd.amd64 = \
++ VBoxNetBSDAdditions-amd64.tbz=$(VBOX_PATH_ADDITIONS.netbsd.amd64)/VBoxNetBSDAdditions.tbz
++endif
++ifdef VBOX_WITH_ADDITIONS_ISO.netbsd.x86
++ VBOX_PATH_ADDITIONS.netbsd.x86 = $(PATH_OUT_BASE)/netbsd.x86/$(KBUILD_TYPE)/bin/additions
++ GUESTADDITIONS_FILESPEC.netbsd.x86 = \
++ VBoxNetBSDAdditions-x86.tbz=$(VBOX_PATH_ADDITIONS.netbsd.x86)/VBoxNetBSDAdditions.tbz
++endif
++
+ # GNU/Linux
+ ifdef VBOX_WITH_ADDITIONS_ISO.linux.amd64
+ VBOX_PATH_ADDITIONS.linux.amd64 = $(PATH_OUT_BASE)/linux.amd64/$(KBUILD_TYPE)/bin/additions
+@@ -312,6 +327,8 @@ $(VBOX_PATH_ADDITIONS_ISO)/VBoxGuestAddi
+ $(GUESTADDITIONS_FILESPEC.linux.amd64) \
+ $(GUESTADDITIONS_FILESPEC.freebsd.x86) \
+ $(GUESTADDITIONS_FILESPEC.freebsd.amd64) \
++ $(GUESTADDITIONS_FILESPEC.netbsd.x86) \
++ $(GUESTADDITIONS_FILESPEC.netbsd.amd64) \
+ $(GUESTADDITIONS_FILESPEC.haiku.x86) \
+ $(GUESTADDITIONS_FILESPEC.darwin.x86) \
+ $(GUESTADDITIONS_FILESPEC.darwin.amd64) \
+@@ -335,6 +352,8 @@ $(VBOX_PATH_ADDITIONS_ISO)/VBoxGuestAddi
+ $(GUESTADDITIONS_FILESPEC.linux.amd64) \
+ $(GUESTADDITIONS_FILESPEC.freebsd.x86) \
+ $(GUESTADDITIONS_FILESPEC.freebsd.amd64) \
++ $(GUESTADDITIONS_FILESPEC.netbsd.x86) \
++ $(GUESTADDITIONS_FILESPEC.netbsd.amd64) \
+ $(GUESTADDITIONS_FILESPEC.haiku.x86) \
+ $(GUESTADDITIONS_FILESPEC.darwin.x86) \
+ $(GUESTADDITIONS_FILESPEC.darwin.amd64)
+@@ -349,4 +368,3 @@ $(VBOX_PATH_ADDITIONS_ISO)/VBoxGuestAddi
+ additions-iso: $(VBOX_PATH_ADDITIONS_ISO)/VBoxGuestAdditions.zip
+
+ endif
+-
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuestLib_VBoxGuestR3Lib.cpp b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuestLib_VBoxGuestR3Lib.cpp
new file mode 100644
index 0000000..2c0062c
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuestLib_VBoxGuestR3Lib.cpp
@@ -0,0 +1,44 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp.orig 2016-03-04 19:23:10.000000000 +0000
++++ src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp
+@@ -38,6 +38,7 @@
+
+ #elif defined(RT_OS_DARWIN) \
+ || defined(RT_OS_FREEBSD) \
++ || defined(RT_OS_NETBSD) \
+ || defined(RT_OS_HAIKU) \
+ || defined(RT_OS_LINUX) \
+ || defined(RT_OS_SOLARIS)
+@@ -252,7 +253,7 @@ static int vbglR3Init(const char *pszDev
+
+ #else
+
+- /* The default implementation. (linux, solaris, freebsd, haiku) */
++ /* The default implementation. (linux, solaris, freebsd, netbsd, haiku) */
+ RTFILE File;
+ int rc = RTFileOpen(&File, pszDeviceName, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
+ if (RT_FAILURE(rc))
+@@ -394,7 +395,7 @@ int vbglR3DoIOCtl(unsigned iFunction, vo
+ return RTErrConvertFromOS2(rc);
+
+ #else
+-# if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++# if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ VBGLBIGREQ Hdr;
+ Hdr.u32Magic = VBGLBIGREQ_MAGIC;
+ Hdr.cbData = cbData;
+@@ -413,7 +414,7 @@ int vbglR3DoIOCtl(unsigned iFunction, vo
+ NOREF(cbData);
+ # endif
+
+-# if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_DARWIN) || defined(RT_OS_LINUX)
++# if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_NETBSD)
+ # ifdef VBOX_VBGLR3_XSERVER
+ int rc = xf86ioctl((int)g_File, iFunction, pvData);
+ # else
+@@ -444,4 +445,3 @@ int vbglR3DoIOCtl(unsigned iFunction, vo
+
+ #endif
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuestLib_VBoxGuestR3LibLog.cpp b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuestLib_VBoxGuestR3LibLog.cpp
new file mode 100644
index 0000000..583aad0
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuestLib_VBoxGuestR3LibLog.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibLog.cpp.orig 2016-03-04 19:23:10.000000000 +0000
++++ src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibLog.cpp
+@@ -66,7 +66,7 @@ VBGLR3DECL(int) VbglR3WriteLog(const cha
+ RTMemFree(pvTmp);
+ return rc;
+
+-#elif 0 /** @todo Several OSes could take this route (solaris and freebsd for instance). */
++#elif 0 /** @todo Several OSes could take this route (solaris, freebsd and netbsd for instance). */
+ /*
+ * Handle the entire request in one go.
+ */
+@@ -88,4 +88,3 @@ VBGLR3DECL(int) VbglR3WriteLog(const cha
+ return rc;
+ #endif
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_Makefile.kmk
new file mode 100644
index 0000000..6b4dd70
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_Makefile.kmk
@@ -0,0 +1,78 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/VBoxGuest/Makefile.kmk.orig 2016-03-04 19:23:09.000000000 +0000
++++ src/VBox/Additions/common/VBoxGuest/Makefile.kmk
+@@ -19,13 +19,14 @@ SUB_DEPTH = ../../../../..
+ include $(KBUILD_PATH)/subheader.kmk
+
+
+-if1of ($(KBUILD_TARGET), darwin freebsd haiku $(if $(defined VBOX_WITH_ADDITION_DRIVERS),linux,) os2 solaris win)
++if1of ($(KBUILD_TARGET), darwin freebsd netbsd haiku $(if $(defined VBOX_WITH_ADDITION_DRIVERS),linux,) os2 solaris win)
+ #
+ # VBoxGuest - The Guest Additions Driver.
+ #
+ SYSMODS += VBoxGuest
+ VBoxGuest_TEMPLATE = VBOXGUESTR0
+ VBoxGuest_NAME.freebsd = vboxguest
++ VBoxGuest_NAME.netbsd = vboxguest
+ VBoxGuest_NAME.haiku = vboxguest
+ VBoxGuest_NAME.linux = vboxguest
+ VBoxGuest_NAME.solaris = vboxguest
+@@ -54,10 +55,12 @@ if1of ($(KBUILD_TARGET), darwin freebsd
+ VBoxGuest_DEPS.linux += $(VBOX_SVN_REV_HEADER)
+ VBoxGuest_DEPS.haiku += $(VBOX_SVN_REV_HEADER)
+ VBoxGuest_DEPS.freebsd += $(VBOX_SVN_REV_HEADER)
++ VBoxGuest_DEPS.netbsd += $(VBOX_SVN_REV_HEADER)
+ VBoxGuest_DEPS.darwin += $(VBOX_SVN_REV_HEADER)
+ VBoxGuest_DEFS = VBGL_VBOXGUEST VBOX_WITH_HGCM
+ VBoxGuest_INCS = .
+ VBoxGuest_INCS.freebsd = $(VBoxGuest_0_OUTDIR) $(PATH_STAGE)/gen-sys-hdrs
++ VBoxGuest_INCS.netbsd = $(VBoxGuest_0_OUTDIR) $(PATH_STAGE)/gen-sys-hdrs
+ VBoxGuest_INCS.linux = ../../../Runtime/r0drv/linux
+ ifeq ($(KBUILD_HOST),solaris)
+ VBoxGuest_LDFLAGS.solaris += -N misc/ctf
+@@ -80,7 +83,7 @@ if1of ($(KBUILD_TARGET), darwin freebsd
+ VBoxGuest.cpp_SDKS = $(VBOX_WINDDK_GST_WLH)
+ endif
+ endif # win
+- ifn1of ($(KBUILD_TARGET), linux freebsd solaris haiku)
++ ifn1of ($(KBUILD_TARGET), linux freebsd netbsd solaris haiku)
+ VBoxGuest_SOURCES = VBoxGuest-$(KBUILD_TARGET).cpp
+ else
+ VBoxGuest_SOURCES = VBoxGuest-$(KBUILD_TARGET).c
+@@ -99,6 +102,10 @@ if1of ($(KBUILD_TARGET), darwin freebsd
+ $(PATH_STAGE)/gen-sys-hdrs/pci_if.h \
+ $(PATH_STAGE)/gen-sys-hdrs/bus_if.h \
+ $(PATH_STAGE)/gen-sys-hdrs/device_if.h
++ VBoxGuest_ORDERDEPS.netbsd = \
++ $(PATH_STAGE)/gen-sys-hdrs/pci_if.h \
++ $(PATH_STAGE)/gen-sys-hdrs/bus_if.h \
++ $(PATH_STAGE)/gen-sys-hdrs/device_if.h
+ ifeq ($(KBUILD_TARGET),haiku)
+ # Haiku drivers cannot export symbols for other drivers, but modules can.
+ # Therefore vboxguest is a module containing the ring-0 guest lib, and vboxdev/vboxsf
+@@ -244,6 +251,19 @@ ifeq ($(KBUILD_TARGET),freebsd)
+
+ endif # FreeBSD
+
++ifeq ($(KBUILD_TARGET),netbsd)
++ #
++ # Install the source files and script(s).
++ #
++ include $(PATH_SUB_CURRENT)/netbsd/files_vboxguest
++ # sources and stuff.
++ INSTALLS += vboxguest-src
++ vboxguest-src_INST = $(INST_ADDITIONS)src/vboxguest/
++ vboxguest-src_MODE = a+r,u+w
++ vboxguest-src_SOURCES = $(subst ",,$(FILES_VBOXGUEST_NOBIN))
++
++endif # FreeBSD
++
+ ifeq ($(KBUILD_TARGET),win)
+ #
+ # VBoxGuestInst - The installer.
+@@ -254,4 +274,3 @@ VBoxGuestInst_SOURCES = win/VBoxGuestIns
+ endif
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuest-netbsd.c b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuest-netbsd.c
new file mode 100644
index 0000000..37c99c8
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuest-netbsd.c
@@ -0,0 +1,636 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/VBoxGuest/VBoxGuest-netbsd.c.orig 2016-07-07 07:08:46.294122795 +0000
++++ src/VBox/Additions/common/VBoxGuest/VBoxGuest-netbsd.c
+@@ -0,0 +1,631 @@
++/* VBoxGuest-netbsd.c $ */
++/** @file
++ * VirtualBox Guest Additions Driver for NetBSD.
++ */
++
++/*
++ * Copyright (C) 2007-2015 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.
++ */
++
++/** @todo r=bird: This must merge with SUPDrv-netbsd.c before long. The two
++ * source files should only differ on prefixes and the extra bits wrt to the
++ * pci device. I.e. it should be diffable so that fixes to one can easily be
++ * applied to the other. */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include <sys/param.h>
++#undef PVM
++#include <sys/types.h>
++#include <sys/module.h>
++#include <sys/systm.h>
++#include <sys/errno.h>
++#include <sys/kernel.h>
++#include <sys/fcntl.h>
++#include <sys/conf.h>
++#include <sys/uio.h>
++#include <sys/bus.h>
++#include <sys/poll.h>
++#include <sys/selinfo.h>
++#include <sys/queue.h>
++#include <sys/lock.h>
++#include <sys/lockmgr.h>
++#include <sys/malloc.h>
++#include <sys/file.h>
++#include <sys/rman.h>
++#include <machine/bus.h>
++#include <machine/resource.h>
++#include <dev/pci/pcivar.h>
++#include <dev/pci/pcireg.h>
++
++#include "VBoxGuestInternal.h"
++#include <VBox/version.h>
++#include <VBox/log.h>
++#include <iprt/assert.h>
++#include <iprt/initterm.h>
++#include <iprt/process.h>
++#include <iprt/mem.h>
++#include <iprt/asm.h>
++
++
++/*********************************************************************************************************************************
++* Defined Constants And Macros *
++*********************************************************************************************************************************/
++/** The module name. */
++#define DEVICE_NAME "vboxguest"
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++struct VBoxGuestDeviceState
++{
++ /** Resource ID of the I/O port */
++ int iIOPortResId;
++ /** Pointer to the I/O port resource. */
++ struct resource *pIOPortRes;
++ /** Start address of the IO Port. */
++ uint16_t uIOPortBase;
++ /** Resource ID of the MMIO area */
++ int iVMMDevMemResId;
++ /** Pointer to the MMIO resource. */
++ struct resource *pVMMDevMemRes;
++ /** Handle of the MMIO resource. */
++ bus_space_handle_t VMMDevMemHandle;
++ /** Size of the memory area. */
++ bus_size_t VMMDevMemSize;
++ /** Mapping of the register space */
++ void *pMMIOBase;
++ /** IRQ number */
++ int iIrqResId;
++ /** IRQ resource handle. */
++ struct resource *pIrqRes;
++ /** Pointer to the IRQ handler. */
++ void *pfnIrqHandler;
++ /** VMMDev version */
++ uint32_t u32Version;
++};
++
++
++/*********************************************************************************************************************************
++* Internal Functions *
++*********************************************************************************************************************************/
++/*
++ * Character device file handlers.
++ */
++static d_fdopen_t vgdrvNetBSDOpen;
++static d_close_t vgdrvNetBSDClose;
++static d_ioctl_t vgdrvNetBSDIOCtl;
++static d_write_t vgdrvNetBSDWrite;
++static d_read_t vgdrvNetBSDRead;
++static d_poll_t vgdrvNetBSDPoll;
++
++/*
++ * IRQ related functions.
++ */
++static void vgdrvNetBSDRemoveIRQ(device_t pDevice, void *pvState);
++static int vgdrvNetBSDAddIRQ(device_t pDevice, void *pvState);
++static int vgdrvNetBSDISR(void *pvState);
++
++
++/*********************************************************************************************************************************
++* Global Variables *
++*********************************************************************************************************************************/
++static MALLOC_DEFINE(M_VBOXGUEST, "vboxguest", "VirtualBox Guest Device Driver");
++
++#ifndef D_NEEDMINOR
++# define D_NEEDMINOR 0
++#endif
++
++/*
++ * The /dev/vboxguest character device entry points.
++ */
++static struct cdevsw g_vgdrvNetBSDChrDevSW =
++{
++ .d_version = D_VERSION,
++ .d_flags = D_TRACKCLOSE | D_NEEDMINOR,
++ .d_fdopen = vgdrvNetBSDOpen,
++ .d_close = vgdrvNetBSDClose,
++ .d_ioctl = vgdrvNetBSDIOCtl,
++ .d_read = vgdrvNetBSDRead,
++ .d_write = vgdrvNetBSDWrite,
++ .d_poll = vgdrvNetBSDPoll,
++ .d_name = "vboxguest"
++};
++
++/** Device extention & session data association structure. */
++static VBOXGUESTDEVEXT g_DevExt;
++
++/** List of cloned device. Managed by the kernel. */
++static struct clonedevs *g_pvgdrvNetBSDClones;
++/** The dev_clone event handler tag. */
++static eventhandler_tag g_vgdrvNetBSDEHTag;
++/** Reference counter */
++static volatile uint32_t cUsers;
++/** selinfo structure used for polling. */
++static struct selinfo g_SelInfo;
++
++/**
++ * DEVFS event handler.
++ */
++static void vgdrvNetBSDClone(void *pvArg, struct ucred *pCred, char *pszName, int cchName, struct cdev **ppDev)
++{
++ int iUnit;
++ int rc;
++
++ Log(("vgdrvNetBSDClone: 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(("vgdrvNetBSDClone: iUnit=%d >= 256 - rejected\n", iUnit));
++ return;
++ }
++
++ Log(("vgdrvNetBSDClone: pszName=%s iUnit=%d\n", pszName, iUnit));
++
++ rc = clone_create(&g_pvgdrvNetBSDClones, &g_vgdrvNetBSDChrDevSW, &iUnit, ppDev, 0);
++ Log(("vgdrvNetBSDClone: clone_create -> %d; iUnit=%d\n", rc, iUnit));
++ if (rc)
++ {
++ *ppDev = make_dev(&g_vgdrvNetBSDChrDevSW,
++ iUnit,
++ UID_ROOT,
++ GID_WHEEL,
++ 0664,
++ "vboxguest%d", iUnit);
++ if (*ppDev)
++ {
++ dev_ref(*ppDev);
++ (*ppDev)->si_flags |= SI_CHEAPCLONE;
++ Log(("vgdrvNetBSDClone: 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(("vgdrvNetBSDClone: make_dev iUnit=%d failed\n", iUnit));
++ }
++ else
++ Log(("vgdrvNetBSDClone: Existing *ppDev=%p iUnit=%d si_drv1=%p si_drv2=%p\n",
++ *ppDev, iUnit, (*ppDev)->si_drv1, (*ppDev)->si_drv2));
++}
++
++/**
++ * File open handler
++ *
++ */
++static int vgdrvNetBSDOpen(struct cdev *pDev, int fOpen, struct thread *pTd)
++{
++ int rc;
++ PVBOXGUESTSESSION pSession;
++
++ LogFlow(("vgdrvNetBSDOpen:\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.
++ */
++ rc = VGDrvCommonCreateUserSession(&g_DevExt, &pSession);
++ if (RT_SUCCESS(rc))
++ {
++ if (ASMAtomicCmpXchgPtr(&pDev->si_drv1, pSession, (void *)0x42))
++ {
++ Log(("vgdrvNetBSDOpen: success - g_DevExt=%p pSession=%p rc=%d pid=%d\n", &g_DevExt, pSession, rc, (int)RTProcSelf()));
++ ASMAtomicIncU32(&cUsers);
++ return 0;
++ }
++
++ VGDrvCommonCloseSession(&g_DevExt, pSession);
++ }
++
++ LogRel(("vgdrvNetBSDOpen: failed. rc=%d\n", rc));
++ return RTErrConvertToErrno(rc);
++}
++
++/**
++ * File close handler
++ *
++ */
++static int vgdrvNetBSDClose(struct cdev *pDev, int fFile, int DevType, struct thread *pTd)
++{
++ PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pDev->si_drv1;
++ Log(("vgdrvNetBSDClose: fFile=%#x pSession=%p\n", fFile, pSession));
++
++ /*
++ * Close the session if it's still hanging on to the device...
++ */
++ if (VALID_PTR(pSession))
++ {
++ VGDrvCommonCloseSession(&g_DevExt, pSession);
++ if (!ASMAtomicCmpXchgPtr(&pDev->si_drv1, NULL, pSession))
++ Log(("vgdrvNetBSDClose: 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(("vgdrvNetBSDClose: si_drv1=%p!\n", pSession));
++ return 0;
++}
++
++/**
++ * IOCTL handler
++ *
++ */
++static int vgdrvNetBSDIOCtl(struct cdev *pDev, u_long ulCmd, caddr_t pvData, int fFile, struct thread *pTd)
++{
++ LogFlow(("vgdrvNetBSDIOCtl\n"));
++
++ int rc = 0;
++
++ /*
++ * Validate the input.
++ */
++ PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pDev->si_drv1;
++ if (RT_UNLIKELY(!VALID_PTR(pSession)))
++ return EINVAL;
++
++ /*
++ * Validate the request wrapper.
++ */
++ if (IOCPARM_LEN(ulCmd) != sizeof(VBGLBIGREQ))
++ {
++ Log(("vgdrvNetBSDIOCtl: bad request %lu size=%lu expected=%d\n", ulCmd, IOCPARM_LEN(ulCmd), sizeof(VBGLBIGREQ)));
++ return ENOTTY;
++ }
++
++ PVBGLBIGREQ ReqWrap = (PVBGLBIGREQ)pvData;
++ if (ReqWrap->u32Magic != VBGLBIGREQ_MAGIC)
++ {
++ Log(("vgdrvNetBSDIOCtl: bad magic %#x; pArg=%p Cmd=%lu.\n", ReqWrap->u32Magic, pvData, ulCmd));
++ return EINVAL;
++ }
++ if (RT_UNLIKELY( ReqWrap->cbData == 0
++ || ReqWrap->cbData > _1M*16))
++ {
++ printf("vgdrvNetBSDIOCtl: bad size %#x; pArg=%p Cmd=%lu.\n", ReqWrap->cbData, pvData, ulCmd);
++ return EINVAL;
++ }
++
++ /*
++ * Read the request.
++ */
++ void *pvBuf = RTMemTmpAlloc(ReqWrap->cbData);
++ if (RT_UNLIKELY(!pvBuf))
++ {
++ Log(("vgdrvNetBSDIOCtl: RTMemTmpAlloc failed to alloc %d bytes.\n", ReqWrap->cbData));
++ return ENOMEM;
++ }
++
++ rc = copyin((void *)(uintptr_t)ReqWrap->pvDataR3, pvBuf, ReqWrap->cbData);
++ if (RT_UNLIKELY(rc))
++ {
++ RTMemTmpFree(pvBuf);
++ Log(("vgdrvNetBSDIOCtl: copyin failed; pvBuf=%p pArg=%p Cmd=%lu. rc=%d\n", pvBuf, pvData, ulCmd, rc));
++ return EFAULT;
++ }
++ if (RT_UNLIKELY( ReqWrap->cbData != 0
++ && !VALID_PTR(pvBuf)))
++ {
++ RTMemTmpFree(pvBuf);
++ Log(("vgdrvNetBSDIOCtl: pvBuf invalid pointer %p\n", pvBuf));
++ return EINVAL;
++ }
++ Log(("vgdrvNetBSDIOCtl: pSession=%p pid=%d.\n", pSession, (int)RTProcSelf()));
++
++ /*
++ * Process the IOCtl.
++ */
++ size_t cbDataReturned;
++ rc = VGDrvCommonIoCtl(ulCmd, &g_DevExt, pSession, pvBuf, ReqWrap->cbData, &cbDataReturned);
++ if (RT_SUCCESS(rc))
++ {
++ rc = 0;
++ if (RT_UNLIKELY(cbDataReturned > ReqWrap->cbData))
++ {
++ Log(("vgdrvNetBSDIOCtl: too much output data %d expected %d\n", cbDataReturned, ReqWrap->cbData));
++ cbDataReturned = ReqWrap->cbData;
++ }
++ if (cbDataReturned > 0)
++ {
++ rc = copyout(pvBuf, (void *)(uintptr_t)ReqWrap->pvDataR3, cbDataReturned);
++ if (RT_UNLIKELY(rc))
++ {
++ Log(("vgdrvNetBSDIOCtl: copyout failed; pvBuf=%p pArg=%p Cmd=%lu. rc=%d\n", pvBuf, pvData, ulCmd, rc));
++ rc = EFAULT;
++ }
++ }
++ }
++ else
++ {
++ Log(("vgdrvNetBSDIOCtl: VGDrvCommonIoCtl failed. rc=%d\n", rc));
++ rc = EFAULT;
++ }
++ RTMemTmpFree(pvBuf);
++ return rc;
++}
++
++static int vgdrvNetBSDPoll(struct cdev *pDev, int fEvents, struct thread *td)
++{
++ int fEventsProcessed;
++
++ LogFlow(("vgdrvNetBSDPoll: fEvents=%d\n", fEvents));
++
++ PVBOXGUESTSESSION pSession = (PVBOXGUESTSESSION)pDev->si_drv1;
++ if (RT_UNLIKELY(!VALID_PTR(pSession))) {
++ Log(("vgdrvNetBSDPoll: no state data for %s\n", devtoname(pDev)));
++ return (fEvents & (POLLHUP|POLLIN|POLLRDNORM|POLLOUT|POLLWRNORM));
++ }
++
++ uint32_t u32CurSeq = ASMAtomicUoReadU32(&g_DevExt.u32MousePosChangedSeq);
++ if (pSession->u32MousePosChangedSeq != u32CurSeq)
++ {
++ fEventsProcessed = fEvents & (POLLIN | POLLRDNORM);
++ pSession->u32MousePosChangedSeq = u32CurSeq;
++ }
++ else
++ {
++ fEventsProcessed = 0;
++
++ selrecord(td, &g_SelInfo);
++ }
++
++ return fEventsProcessed;
++}
++
++static int vgdrvNetBSDWrite(struct cdev *pDev, struct uio *pUio, int fIo)
++{
++ return 0;
++}
++
++static int vgdrvNetBSDRead(struct cdev *pDev, struct uio *pUio, int fIo)
++{
++ return 0;
++}
++
++static int vgdrvNetBSDDetach(device_t pDevice)
++{
++ struct VBoxGuestDeviceState *pState = device_get_softc(pDevice);
++
++ if (cUsers > 0)
++ return EBUSY;
++
++ /*
++ * Reverse what we did in vgdrvNetBSDAttach.
++ */
++ if (g_vgdrvNetBSDEHTag != NULL)
++ EVENTHANDLER_DEREGISTER(dev_clone, g_vgdrvNetBSDEHTag);
++
++ clone_cleanup(&g_pvgdrvNetBSDClones);
++
++ vgdrvNetBSDRemoveIRQ(pDevice, pState);
++
++ if (pState->pVMMDevMemRes)
++ bus_release_resource(pDevice, SYS_RES_MEMORY, pState->iVMMDevMemResId, pState->pVMMDevMemRes);
++ if (pState->pIOPortRes)
++ bus_release_resource(pDevice, SYS_RES_IOPORT, pState->iIOPortResId, pState->pIOPortRes);
++
++ VGDrvCommonDeleteDevExt(&g_DevExt);
++
++ RTR0Term();
++
++ return 0;
++}
++
++/**
++ * Interrupt service routine.
++ *
++ * @returns Whether the interrupt was from VMMDev.
++ * @param pvState Opaque pointer to the device state.
++ */
++static int vgdrvNetBSDISR(void *pvState)
++{
++ LogFlow(("vgdrvNetBSDISR: pvState=%p\n", pvState));
++
++ bool fOurIRQ = VGDrvCommonISR(&g_DevExt);
++
++ return fOurIRQ ? 0 : 1;
++}
++
++void VGDrvNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt)
++{
++ LogFlow(("VGDrvNativeISRMousePollEvent:\n"));
++
++ /*
++ * Wake up poll waiters.
++ */
++ selwakeup(&g_SelInfo);
++}
++
++/**
++ * Sets IRQ for VMMDev.
++ *
++ * @returns NetBSD error code.
++ * @param pDevice Pointer to the device info structure.
++ * @param pvState Pointer to the state info structure.
++ */
++static int vgdrvNetBSDAddIRQ(device_t pDevice, void *pvState)
++{
++ int iResId = 0;
++ int rc = 0;
++ struct VBoxGuestDeviceState *pState = (struct VBoxGuestDeviceState *)pvState;
++
++ pState->pIrqRes = bus_alloc_resource_any(pDevice, SYS_RES_IRQ, &iResId, RF_SHAREABLE | RF_ACTIVE);
++
++ rc = bus_setup_intr(pDevice, pState->pIrqRes, INTR_TYPE_BIO, (driver_intr_t *)vgdrvNetBSDISR, pState, &pState->pfnIrqHandler);
++
++ if (rc)
++ {
++ pState->pfnIrqHandler = NULL;
++ return VERR_DEV_IO_ERROR;
++ }
++
++ pState->iIrqResId = iResId;
++
++ return VINF_SUCCESS;
++}
++
++/**
++ * Removes IRQ for VMMDev.
++ *
++ * @param pDevice Pointer to the device info structure.
++ * @param pvState Opaque pointer to the state info structure.
++ */
++static void vgdrvNetBSDRemoveIRQ(device_t pDevice, void *pvState)
++{
++ struct VBoxGuestDeviceState *pState = (struct VBoxGuestDeviceState *)pvState;
++
++ if (pState->pIrqRes)
++ {
++ bus_teardown_intr(pDevice, pState->pIrqRes, pState->pfnIrqHandler);
++ bus_release_resource(pDevice, SYS_RES_IRQ, 0, pState->pIrqRes);
++ }
++}
++
++static int vgdrvNetBSDAttach(device_t pDevice)
++{
++ int rc;
++ int iResId;
++ struct VBoxGuestDeviceState *pState;
++
++ cUsers = 0;
++
++ /*
++ * Initialize IPRT R0 driver, which internally calls OS-specific r0 init.
++ */
++ rc = RTR0Init(0);
++ if (RT_FAILURE(rc))
++ {
++ LogFunc(("RTR0Init failed.\n"));
++ return ENXIO;
++ }
++
++ pState = device_get_softc(pDevice);
++
++ /*
++ * Allocate I/O port resource.
++ */
++ iResId = PCIR_BAR(0);
++ pState->pIOPortRes = bus_alloc_resource_any(pDevice, SYS_RES_IOPORT, &iResId, RF_ACTIVE);
++ pState->uIOPortBase = rman_get_start(pState->pIOPortRes);
++ pState->iIOPortResId = iResId;
++ if (pState->uIOPortBase)
++ {
++ /*
++ * Map the MMIO region.
++ */
++ iResId = PCIR_BAR(1);
++ pState->pVMMDevMemRes = bus_alloc_resource_any(pDevice, SYS_RES_MEMORY, &iResId, RF_ACTIVE);
++ pState->VMMDevMemHandle = rman_get_bushandle(pState->pVMMDevMemRes);
++ pState->VMMDevMemSize = rman_get_size(pState->pVMMDevMemRes);
++
++ pState->pMMIOBase = rman_get_virtual(pState->pVMMDevMemRes);
++ pState->iVMMDevMemResId = iResId;
++ if (pState->pMMIOBase)
++ {
++ /*
++ * Call the common device extension initializer.
++ */
++ rc = VGDrvCommonInitDevExt(&g_DevExt, pState->uIOPortBase,
++ pState->pMMIOBase, pState->VMMDevMemSize,
++#if ARCH_BITS == 64
++ VBOXOSTYPE_NetBSD_x64,
++#else
++ VBOXOSTYPE_NetBSD,
++#endif
++ VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
++ if (RT_SUCCESS(rc))
++ {
++ /*
++ * Add IRQ of VMMDev.
++ */
++ rc = vgdrvNetBSDAddIRQ(pDevice, pState);
++ if (RT_SUCCESS(rc))
++ {
++ /*
++ * Configure device cloning.
++ */
++ clone_setup(&g_pvgdrvNetBSDClones);
++ g_vgdrvNetBSDEHTag = EVENTHANDLER_REGISTER(dev_clone, vgdrvNetBSDClone, 0, 1000);
++ if (g_vgdrvNetBSDEHTag)
++ {
++ printf(DEVICE_NAME ": loaded successfully\n");
++ return 0;
++ }
++
++ printf(DEVICE_NAME ": EVENTHANDLER_REGISTER(dev_clone,,,) failed\n");
++ clone_cleanup(&g_pvgdrvNetBSDClones);
++ vgdrvNetBSDRemoveIRQ(pDevice, pState);
++ }
++ else
++ printf((DEVICE_NAME ": VGDrvCommonInitDevExt failed.\n"));
++ VGDrvCommonDeleteDevExt(&g_DevExt);
++ }
++ else
++ printf((DEVICE_NAME ": vgdrvNetBSDAddIRQ failed.\n"));
++ }
++ else
++ printf((DEVICE_NAME ": MMIO region setup failed.\n"));
++ }
++ else
++ printf((DEVICE_NAME ": IOport setup failed.\n"));
++
++ RTR0Term();
++ return ENXIO;
++}
++
++static int vgdrvNetBSDProbe(device_t pDevice)
++{
++ if ((pci_get_vendor(pDevice) == VMMDEV_VENDORID) && (pci_get_device(pDevice) == VMMDEV_DEVICEID))
++ return 0;
++
++ return ENXIO;
++}
++
++static device_method_t vgdrvNetBSDMethods[] =
++{
++ /* Device interface. */
++ DEVMETHOD(device_probe, vgdrvNetBSDProbe),
++ DEVMETHOD(device_attach, vgdrvNetBSDAttach),
++ DEVMETHOD(device_detach, vgdrvNetBSDDetach),
++ {0,0}
++};
++
++static driver_t vgdrvNetBSDDriver =
++{
++ DEVICE_NAME,
++ vgdrvNetBSDMethods,
++ sizeof(struct VBoxGuestDeviceState),
++};
++
++static devclass_t vgdrvNetBSDClass;
++
++DRIVER_MODULE(vboxguest, pci, vgdrvNetBSDDriver, vgdrvNetBSDClass, 0, 0);
++MODULE_VERSION(vboxguest, 1);
++
++/* Common code that depend on g_DevExt. */
++#include "VBoxGuestIDC-unix.c.h"
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuest.cpp b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuest.cpp
new file mode 100644
index 0000000..3c2072c
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuest.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp.orig 2016-03-04 19:23:09.000000000 +0000
++++ src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp
+@@ -68,7 +68,7 @@
+ # include <iprt/thread.h>
+ #endif
+ #include "version-generated.h"
+-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include "revision-generated.h"
+ #endif
+ #ifdef RT_OS_WINDOWS
+@@ -3745,4 +3745,3 @@ bool VGDrvCommonISR(PVBOXGUESTDEVEXT pDe
+ NOREF(rc);
+ return fOurIrq;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuestInternal.h b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuestInternal.h
new file mode 100644
index 0000000..ff9c988
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_VBoxGuestInternal.h
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/VBoxGuest/VBoxGuestInternal.h.orig 2016-03-04 19:23:10.000000000 +0000
++++ src/VBox/Additions/common/VBoxGuest/VBoxGuestInternal.h
+@@ -249,7 +249,7 @@ typedef struct VBOXGUESTSESSION
+ {
+ /** The list node. */
+ RTLISTNODE ListNode;
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS) || defined(RT_OS_NETBSD)
+ /** Pointer to the next session with the same hash. */
+ PVBOXGUESTSESSION pNextHash;
+ #endif
+@@ -348,4 +348,3 @@ int VGDrvNtIOCtl_DpcLatencyChecker(void)
+ RT_C_DECLS_END
+
+ #endif
+-
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_netbsd_Makefile b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_netbsd_Makefile
new file mode 100644
index 0000000..e7be1f7
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_netbsd_Makefile
@@ -0,0 +1,171 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/VBoxGuest/netbsd/Makefile.orig 2016-07-06 20:08:38.705500122 +0000
++++ src/VBox/Additions/common/VBoxGuest/netbsd/Makefile
+@@ -0,0 +1,166 @@
++# Makefile $
++## @file
++# VirtualBox Guest Additions Module Makefile.
++#
++
++#
++# Copyright (C) 2006-2015 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.
++#
++KMOD = vboxguest
++
++CFLAGS += -DRT_OS_NETBSD -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
++
++.if (${MACHINE_ARCH} == "i386")
++ CFLAGS += -DRT_ARCH_X86
++.elif (${MACHINE_ARCH} == "amd64")
++ CFLAGS += -DRT_ARCH_AMD64
++.endif
++
++SRCS = \
++ VBoxGuest.c \
++ VBoxGuest-netbsd.c \
++ GenericRequest.c \
++ HGCMInternal.c \
++ Init.c \
++ PhysHeap.c \
++ SysHlp.c \
++ VMMDev.c
++
++# Include needed interface headers so they are created during build
++SRCS += \
++ device_if.h \
++ bus_if.h \
++ pci_if.h \
++
++.PATH: ${.CURDIR}/alloc
++SRCS += \
++ heapsimple.c
++
++.PATH: ${.CURDIR}/common/err
++SRCS += \
++ RTErrConvertFromErrno.c \
++ RTErrConvertToErrno.c
++
++.PATH: ${.CURDIR}/common/log
++SRCS += \
++ log.c \
++ logellipsis.c \
++ logrel.c \
++ logrelellipsis.c \
++ logcom.c \
++ logformat.c
++
++.PATH: ${.CURDIR}/common/misc
++SRCS += \
++ RTAssertMsg1Weak.c \
++ RTAssertMsg2.c \
++ RTAssertMsg2Add.c \
++ RTAssertMsg2AddWeak.c \
++ RTAssertMsg2AddWeakV.c \
++ RTAssertMsg2Weak.c \
++ RTAssertMsg2WeakV.c \
++ assert.c \
++ handletable.c \
++ handletablectx.c \
++ once.c \
++ thread.c
++
++.PATH: ${.CURDIR}/common/string
++SRCS += \
++ RTStrCopy.c \
++ RTStrCopyEx.c \
++ RTStrCopyP.c \
++ strformat.c \
++ strformatrt.c \
++ strformattype.c \
++ strprintf.c \
++ strtonum.c \
++ memchr.c
++
++.PATH: ${.CURDIR}/common/rand
++SRCS += \
++ rand.c \
++ randadv.c \
++ randparkmiller.c
++
++.PATH: ${.CURDIR}/common/path
++SRCS += \
++ RTPathStripFilename.c
++
++.PATH: ${.CURDIR}/common/checksum
++SRCS += \
++ crc32.c \
++ ipv4.c
++
++.PATH: ${.CURDIR}/common/table
++SRCS += \
++ avlpv.c
++
++.PATH: ${.CURDIR}/common/time
++SRCS += \
++ time.c
++
++.PATH: ${.CURDIR}/generic
++SRCS += \
++ uuid-generic.c \
++ RTAssertShouldPanic-generic.c \
++ RTLogWriteDebugger-generic.c \
++ RTLogWriteStdOut-stub-generic.c \
++ RTLogWriteStdErr-stub-generic.c \
++ RTRandAdvCreateSystemFaster-generic.c \
++ RTRandAdvCreateSystemTruer-generic.c \
++ RTSemEventWait-2-ex-generic.c \
++ RTSemEventWaitNoResume-2-ex-generic.c \
++ RTSemEventMultiWait-2-ex-generic.c \
++ RTSemEventMultiWaitNoResume-2-ex-generic.c \
++ RTTimerCreate-generic.c \
++ timer-generic.c \
++ errvars-generic.c \
++ mppresent-generic.c
++
++.PATH: ${.CURDIR}/r0drv
++SRCS += \
++ alloc-r0drv.c \
++ initterm-r0drv.c \
++ memobj-r0drv.c \
++ powernotification-r0drv.c
++
++.PATH: ${.CURDIR}/r0drv/netbsd
++SRCS += \
++ assert-r0drv-netbsd.c \
++ alloc-r0drv-netbsd.c \
++ initterm-r0drv-netbsd.c \
++ memobj-r0drv-netbsd.c \
++ memuserkernel-r0drv-netbsd.c \
++ mp-r0drv-netbsd.c \
++ process-r0drv-netbsd.c \
++ semevent-r0drv-netbsd.c \
++ semeventmulti-r0drv-netbsd.c \
++ semfastmutex-r0drv-netbsd.c \
++ semmutex-r0drv-netbsd.c \
++ spinlock-r0drv-netbsd.c \
++ thread-r0drv-netbsd.c \
++ thread2-r0drv-netbsd.c \
++ time-r0drv-netbsd.c \
++ timer-r0drv-netbsd.c
++
++.PATH: ${.CURDIR}/r0drv/generic
++SRCS += \
++ semspinmutex-r0drv-generic.c \
++ mpnotification-r0drv-generic.c \
++ RTMpIsCpuWorkPending-r0drv-generic.c
++
++.PATH: ${.CURDIR}/VBox
++SRCS += \
++ log-vbox.c \
++ logbackdoor.c
++
++.include <bsd.kmod.mk>
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_netbsd_files__vboxguest b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_netbsd_files__vboxguest
new file mode 100644
index 0000000..93b1fb6
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxGuest_netbsd_files__vboxguest
@@ -0,0 +1,204 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/VBoxGuest/netbsd/files_vboxguest.orig 2016-07-07 07:08:46.332361686 +0000
++++ src/VBox/Additions/common/VBoxGuest/netbsd/files_vboxguest
+@@ -0,0 +1,199 @@
++#!/bin/sh
++# files_vboxguest $
++## @file
++# Shared file between Makefile.kmk and export_modules
++#
++
++#
++# Copyright (C) 2007-2015 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.
++#
++
++FILES_VBOXGUEST_NOBIN=" \
++ ${PATH_ROOT}/include/iprt/alloca.h=>include/iprt/alloca.h \
++ ${PATH_ROOT}/include/iprt/alloc.h=>include/iprt/alloc.h \
++ ${PATH_ROOT}/include/iprt/asm.h=>include/iprt/asm.h \
++ ${PATH_ROOT}/include/iprt/asm-amd64-x86.h=>include/iprt/asm-amd64-x86.h \
++ ${PATH_ROOT}/include/iprt/asm-math.h=>include/iprt/asm-math.h \
++ ${PATH_ROOT}/include/iprt/assert.h=>include/iprt/assert.h \
++ ${PATH_ROOT}/include/iprt/avl.h=>include/iprt/avl.h \
++ ${PATH_ROOT}/include/iprt/cdefs.h=>include/iprt/cdefs.h \
++ ${PATH_ROOT}/include/iprt/cpuset.h=>include/iprt/cpuset.h \
++ ${PATH_ROOT}/include/iprt/ctype.h=>include/iprt/ctype.h \
++ ${PATH_ROOT}/include/iprt/err.h=>include/iprt/err.h \
++ ${PATH_ROOT}/include/iprt/errno.h=>include/iprt/errno.h \
++ ${PATH_ROOT}/include/iprt/heap.h=>include/iprt/heap.h \
++ ${PATH_ROOT}/include/iprt/handletable.h=>include/iprt/handletable.h \
++ ${PATH_ROOT}/include/iprt/initterm.h=>include/iprt/initterm.h \
++ ${PATH_ROOT}/include/iprt/latin1.h=>include/iprt/latin1.h \
++ ${PATH_ROOT}/include/iprt/list.h=>include/iprt/list.h \
++ ${PATH_ROOT}/include/iprt/lockvalidator.h=>include/iprt/lockvalidator.h \
++ ${PATH_ROOT}/include/iprt/log.h=>include/iprt/log.h \
++ ${PATH_ROOT}/include/iprt/mangling.h=>include/iprt/mangling.h \
++ ${PATH_ROOT}/include/iprt/mem.h=>include/iprt/mem.h \
++ ${PATH_ROOT}/include/iprt/memobj.h=>include/iprt/memobj.h \
++ ${PATH_ROOT}/include/iprt/mp.h=>include/iprt/mp.h \
++ ${PATH_ROOT}/include/iprt/param.h=>include/iprt/param.h \
++ ${PATH_ROOT}/include/iprt/power.h=>include/iprt/power.h \
++ ${PATH_ROOT}/include/iprt/process.h=>include/iprt/process.h \
++ ${PATH_ROOT}/include/iprt/semaphore.h=>include/iprt/semaphore.h \
++ ${PATH_ROOT}/include/iprt/spinlock.h=>include/iprt/spinlock.h \
++ ${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/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 \
++ ${PATH_ROOT}/include/iprt/types.h=>include/iprt/types.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 \
++ ${PATH_ROOT}/include/iprt/net.h=>include/iprt/net.h \
++ ${PATH_ROOT}/include/iprt/rand.h=>include/iprt/rand.h \
++ ${PATH_ROOT}/include/iprt/path.h=>include/iprt/path.h \
++ ${PATH_ROOT}/include/iprt/once.h=>include/iprt/once.h \
++ ${PATH_ROOT}/include/iprt/critsect.h=>include/iprt/critsect.h \
++ ${PATH_ROOT}/include/iprt/x86.h=>include/iprt/x86.h \
++ ${PATH_ROOT}/include/iprt/nocrt/limits.h=>include/iprt/nocrt/limits.h \
++ ${PATH_ROOT}/include/VBox/cdefs.h=>include/VBox/cdefs.h \
++ ${PATH_ROOT}/include/VBox/err.h=>include/VBox/err.h \
++ ${PATH_ROOT}/include/VBox/log.h=>include/VBox/log.h \
++ ${PATH_ROOT}/include/VBox/param.h=>include/VBox/param.h \
++ ${PATH_ROOT}/include/VBox/types.h=>include/VBox/types.h \
++ ${PATH_ROOT}/include/VBox/ostypes.h=>include/VBox/ostypes.h \
++ ${PATH_ROOT}/include/VBox/VMMDev.h=>include/VBox/VMMDev.h \
++ ${PATH_ROOT}/include/VBox/VMMDev2.h=>include/VBox/VMMDev2.h \
++ ${PATH_ROOT}/include/VBox/VBoxGuest.h=>include/VBox/VBoxGuest.h \
++ ${PATH_ROOT}/include/VBox/VBoxGuest2.h=>include/VBox/VBoxGuest2.h \
++ ${PATH_ROOT}/include/VBox/VBoxGuestLib.h=>include/VBox/VBoxGuestLib.h \
++ ${PATH_ROOT}/include/VBox/VBoxGuestMangling.h=>include/VBox/VBoxGuestMangling.h \
++ ${PATH_ROOT}/include/VBox/version.h=>include/VBox/version.h \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp=>VBoxGuest.c \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuest/VBoxGuest-netbsd.c=>VBoxGuest-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuest/VBoxGuestIDC-unix.c.h=>VBoxGuestIDC-unix.c.h \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuest/VBoxGuestInternal.h=>VBoxGuestInternal.h \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuest/netbsd/Makefile=>Makefile \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuestLib/GenericRequest.cpp=>GenericRequest.c \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuestLib/HGCMInternal.cpp=>HGCMInternal.c \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuestLib/Init.cpp=>Init.c \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuestLib/PhysHeap.cpp=>PhysHeap.c \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuestLib/SysHlp.h=>SysHlp.h \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuestLib/SysHlp.cpp=>SysHlp.c \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuestLib/VBGLInternal.h=>VBGLInternal.h \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestLog.h=>VBoxGuestLog.h \
++ ${PATH_ROOT}/src/VBox/Additions/common/VBoxGuestLib/VMMDev.cpp=>VMMDev.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/alloc/heapsimple.cpp=>alloc/heapsimple.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/err/RTErrConvertFromErrno.cpp=>common/err/RTErrConvertFromErrno.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/err/RTErrConvertToErrno.cpp=>common/err/RTErrConvertToErrno.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/log.cpp=>common/log/log.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/logellipsis.cpp=>common/log/logellipsis.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/logrel.cpp=>common/log/logrel.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/logrelellipsis.cpp=>common/log/logrelellipsis.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/logcom.cpp=>common/log/logcom.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/logformat.cpp=>common/log/logformat.c \
++ ${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/once.cpp=>common/misc/once.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 \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2Add.cpp=>common/misc/RTAssertMsg2Add.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2AddWeak.cpp=>common/misc/RTAssertMsg2AddWeak.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2AddWeakV.cpp=>common/misc/RTAssertMsg2AddWeakV.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2Weak.cpp=>common/misc/RTAssertMsg2Weak.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2WeakV.cpp=>common/misc/RTAssertMsg2WeakV.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/assert.cpp=>common/misc/assert.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/RTStrCopy.cpp=>common/string/RTStrCopy.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/RTStrCopyEx.cpp=>common/string/RTStrCopyEx.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/RTStrCopyP.cpp=>common/string/RTStrCopyP.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/strformat.cpp=>common/string/strformat.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/strformatrt.cpp=>common/string/strformatrt.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/strformattype.cpp=>common/string/strformattype.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/strprintf.cpp=>common/string/strprintf.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/rand/rand.cpp=>common/rand/rand.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/rand/randadv.cpp=>common/rand/randadv.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/rand/randparkmiller.cpp=>common/rand/randparkmiller.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/path/RTPathStripFilename.cpp=>common/path/RTPathStripFilename.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/checksum/crc32.cpp=>common/checksum/crc32.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/checksum/ipv4.cpp=>common/checksum/ipv4.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avlpv.cpp=>common/table/avlpv.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_Base.cpp.h=>common/table/avl_Base.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_Get.cpp.h=>common/table/avl_Get.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_GetBestFit.cpp.h=>common/table/avl_GetBestFit.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_RemoveBestFit.cpp.h=>common/table/avl_RemoveBestFit.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_DoWithAll.cpp.h=>common/table/avl_DoWithAll.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_Destroy.cpp.h=>common/table/avl_Destroy.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/time/time.cpp=>common/time/time.c \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/assert.h=>include/internal/assert.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/initterm.h=>include/internal/initterm.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/iprt.h=>include/internal/iprt.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/lockvalidator.h=>include/internal/lockvalidator.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/magics.h=>include/internal/magics.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/memobj.h=>include/internal/memobj.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/string.h=>include/internal/string.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/thread.h=>include/internal/thread.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/time.h=>include/internal/time.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/rand.h=>include/internal/rand.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/sched.h=>include/internal/sched.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/process.h=>include/internal/process.h \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTAssertShouldPanic-generic.cpp=>generic/RTAssertShouldPanic-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTLogWriteStdErr-stub-generic.cpp=>generic/RTLogWriteStdErr-stub-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTLogWriteStdOut-stub-generic.cpp=>generic/RTLogWriteStdOut-stub-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTLogWriteDebugger-generic.cpp=>generic/RTLogWriteDebugger-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTRandAdvCreateSystemFaster-generic.cpp=>generic/RTRandAdvCreateSystemFaster-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTRandAdvCreateSystemTruer-generic.cpp=>generic/RTRandAdvCreateSystemTruer-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/uuid-generic.cpp=>generic/uuid-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTSemEventWait-2-ex-generic.cpp=>generic/RTSemEventWait-2-ex-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTSemEventWaitNoResume-2-ex-generic.cpp=>generic/RTSemEventWaitNoResume-2-ex-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTSemEventMultiWait-2-ex-generic.cpp=>generic/RTSemEventMultiWait-2-ex-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp=>generic/RTSemEventMultiWaitNoResume-2-ex-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTTimerCreate-generic.cpp=>generic/RTTimerCreate-generic.c \
++ ${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-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 \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/mp-r0drv.h=>r0drv/mp-r0drv.h \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/power-r0drv.h=>r0drv/power-r0drv.h \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/powernotification-r0drv.c=>r0drv/powernotification-r0drv.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/assert-r0drv-netbsd.c=>r0drv/netbsd/assert-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/alloc-r0drv-netbsd.c=>r0drv/netbsd/alloc-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/initterm-r0drv-netbsd.c=>r0drv/netbsd/initterm-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c=>r0drv/netbsd/memobj-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/memuserkernel-r0drv-netbsd.c=>r0drv/netbsd/memuserkernel-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/mp-r0drv-netbsd.c=>r0drv/netbsd/mp-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/process-r0drv-netbsd.c=>r0drv/netbsd/process-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/semevent-r0drv-netbsd.c=>r0drv/netbsd/semevent-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/semeventmulti-r0drv-netbsd.c=>r0drv/netbsd/semeventmulti-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/semfastmutex-r0drv-netbsd.c=>r0drv/netbsd/semfastmutex-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/semmutex-r0drv-netbsd.c=>r0drv/netbsd/semmutex-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/spinlock-r0drv-netbsd.c=>r0drv/netbsd/spinlock-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/the-netbsd-kernel.h=>r0drv/netbsd/the-netbsd-kernel.h \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/thread-r0drv-netbsd.c=>r0drv/netbsd/thread-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/thread2-r0drv-netbsd.c=>r0drv/netbsd/thread2-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/time-r0drv-netbsd.c=>r0drv/netbsd/time-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/sleepqueue-r0drv-netbsd.h=>r0drv/netbsd/sleepqueue-r0drv-netbsd.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/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 \
++ ${PATH_ROOT}/src/VBox/Runtime/VBox/logbackdoor.cpp=>VBox/logbackdoor.c \
++ ${PATH_OUT}/version-generated.h=>version-generated.h \
++ ${PATH_OUT}/product-generated.h=>product-generated.h \
++ ${PATH_OUT}/revision-generated.h=>revision-generated.h \
++"
++
++FILES_VBOXGUEST_BIN=" \
++"
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_VBoxService_VBoxService.cpp b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxService_VBoxService.cpp
new file mode 100644
index 0000000..bc74dc1
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxService_VBoxService.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/VBoxService/VBoxService.cpp.orig 2016-03-04 19:23:11.000000000 +0000
++++ src/VBox/Additions/common/VBoxService/VBoxService.cpp
+@@ -62,7 +62,7 @@
+ # define pthread_sigmask sigprocmask
+ # endif
+ #endif
+-#ifdef RT_OS_FREEBSD
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <pthread.h>
+ #endif
+
+@@ -1259,4 +1259,3 @@ int main(int argc, char **argv)
+
+ return rcExit;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_VBoxService_VBoxServiceVMInfo.cpp b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxService_VBoxServiceVMInfo.cpp
new file mode 100644
index 0000000..1d9048c
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_VBoxService_VBoxServiceVMInfo.cpp
@@ -0,0 +1,65 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp.orig 2016-03-04 19:23:11.000000000 +0000
++++ src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
+@@ -71,7 +71,7 @@
+ # include <net/if.h>
+ # include <pwd.h> /* getpwuid */
+ # include <unistd.h>
+-# if !defined(RT_OS_OS2) && !defined(RT_OS_FREEBSD) && !defined(RT_OS_HAIKU)
++# if !defined(RT_OS_OS2) && !defined(RT_OS_FREEBSD) && !defined(RT_OS_HAIKU)
+ # include <utmpx.h> /* @todo FreeBSD 9 should have this. */
+ # endif
+ # ifdef RT_OS_OS2
+@@ -81,7 +81,7 @@
+ # include <sys/sockio.h>
+ # include <net/if_arp.h>
+ # endif
+-# if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++# if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <ifaddrs.h> /* getifaddrs, freeifaddrs */
+ # include <net/if_dl.h> /* LLADDR */
+ # include <netdb.h> /* getnameinfo */
+@@ -568,6 +568,10 @@ static int vgsvcVMInfoWriteUsers(void)
+ * block below (?). */
+ rc = VERR_NOT_IMPLEMENTED;
+
++#elif defined(RT_OS_NETBSD)
++ /** @todo NetBSD: */
++ rc = VERR_NOT_IMPLEMENTED;
++
+ #elif defined(RT_OS_HAIKU)
+ /** @todo Haiku: Port logged on user info retrieval. */
+ rc = VERR_NOT_IMPLEMENTED;
+@@ -874,7 +878,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_FREEBSD && !RT_OS_HAIKU && !RT_OS_OS2 && !RT_OS_NETBSD */
+
+ Assert(RT_FAILURE(rc) || cUsersInList == 0 || (pszUserList && *pszUserList));
+
+@@ -1090,7 +1094,7 @@ static int vgsvcVMInfoWriteNetwork(void)
+ /** @todo Haiku: implement network info. retreival */
+ return VERR_NOT_IMPLEMENTED;
+
+-#elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ struct ifaddrs *pIfHead = NULL;
+
+ /* Get all available interfaces */
+@@ -1162,7 +1166,7 @@ static int vgsvcVMInfoWriteNetwork(void)
+ /* Free allocated resources. */
+ freeifaddrs(pIfHead);
+
+-#else /* !RT_OS_WINDOWS && !RT_OS_FREEBSD */
++#else /* !RT_OS_WINDOWS && !RT_OS_FREEBSD && !RT_OS_NETBSD */
+ /*
+ * Use SIOCGIFCONF to get a list of interface/protocol configurations.
+ *
+@@ -1685,4 +1689,3 @@ VBOXSERVICE g_VMInfo =
+ vbsvcVMInfoStop,
+ vbsvcVMInfoTerm
+ };
+-
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_Makefile.kmk
new file mode 100644
index 0000000..95691ba
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_Makefile.kmk
@@ -0,0 +1,198 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/crOpenGL/Makefile.kmk.orig 2016-03-04 19:23:12.000000000 +0000
++++ src/VBox/Additions/common/crOpenGL/Makefile.kmk
+@@ -24,7 +24,7 @@ include $(KBUILD_PATH)/subheader.kmk
+ BLDDIRS += \
+ $(VBOX_PATH_CROGL_GENFILES)/
+
+-if1of ($(KBUILD_TARGET), win linux solaris freebsd)
++if1of ($(KBUILD_TARGET), win linux solaris freebsd netbsd)
+ DLLS += \
+ VBoxOGL \
+ VBoxOGLarrayspu \
+@@ -44,7 +44,7 @@ ifdef VBOX_WITH_WDDM
+ DLLS.win.amd64 += $(VBOX_OGL_X86_GUEST_DLLS)
+ endif
+
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ #VBoxOGL_DRI = 1
+ ifn1of ($(KBUILD_TARGET),solaris) # No DRI on Solaris yet
+ VBoxOGL_FAKEDRI = 1
+@@ -53,7 +53,7 @@ if1of ($(KBUILD_TARGET), linux solaris f
+ # Only Solaris right now needs C stubs because I can't figure out how to
+ # generate the GOT based relocation ASM yet.
+ ifdef VBoxOGL_FAKEDRI
+- if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH),solaris.x86 solaris.amd64 linux.x86 linux.amd64 freebsd.x86 freebsd.amd64)
++ if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH),solaris.x86 solaris.amd64 linux.x86 linux.amd64 freebsd.x86 freebsd.amd64 netbsd.x86 netbsd.amd64)
+ VBOX_OGL_GLX_USE_CSTUBS = 1
+ endif
+ endif
+@@ -65,7 +65,7 @@ endif
+ #
+ VBoxOGL_TEMPLATE = VBOXCROGLR3GUESTDLL
+ VBoxOGL_INCS = .
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGL_INCS += \
+ $(VBOX_PATH_X11_ROOT)/libXdamage-1.1 \
+ $(VBOX_PATH_X11_ROOT)/libXcomposite-0.4.0 \
+@@ -120,7 +120,7 @@ VBoxOGL_SOURCES += \
+ $(VBOX_PATH_CROGL_GENFILES)/NULLfuncs.c \
+ $(VBOX_PATH_CROGL_GENFILES)/tsfuncs.c
+
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGL_SOURCES += \
+ glx.c \
+ xfont.c
+@@ -138,6 +138,8 @@ if1of ($(KBUILD_TARGET), linux solaris f
+ $(VBOX_PATH_CROGL_GENFILES)/solaris_exports_dri.asm
+ VBoxOGL_SOURCES.freebsd += \
+ $(VBOX_PATH_CROGL_GENFILES)/freebsd_exports_dri.asm
++ VBoxOGL_SOURCES.netbsd += \
++ $(VBOX_PATH_CROGL_GENFILES)/netbsd_exports_dri.asm
+ else ifdef VBoxOGL_FAKEDRI
+ VBoxOGL_SOURCES += \
+ fakedri_drv.c
+@@ -151,6 +153,9 @@ if1of ($(KBUILD_TARGET), linux solaris f
+ VBoxOGL_SOURCES.freebsd += \
+ $(VBOX_PATH_CROGL_GENFILES)/freebsd_glxapi_exports.asm \
+ $(VBOX_PATH_CROGL_GENFILES)/freebsd_exports_dri.asm
++ VBoxOGL_SOURCES.netbsd += \
++ $(VBOX_PATH_CROGL_GENFILES)/netbsd_glxapi_exports.asm \
++ $(VBOX_PATH_CROGL_GENFILES)/netbsd_exports_dri.asm
+ else
+ VBoxOGL_SOURCES.solaris += \
+ $(VBOX_PATH_CROGL_GENFILES)/solaris_exports.c
+@@ -158,6 +163,8 @@ if1of ($(KBUILD_TARGET), linux solaris f
+ $(VBOX_PATH_CROGL_GENFILES)/linux_exports.c
+ VBoxOGL_SOURCES.freebsd += \
+ $(VBOX_PATH_CROGL_GENFILES)/freebsd_exports.c
++ VBoxOGL_SOURCES.netbsd += \
++ $(VBOX_PATH_CROGL_GENFILES)/netbsd_exports.c
+ endif
+ else
+ VBoxOGL_SOURCES.linux += \
+@@ -166,6 +173,8 @@ if1of ($(KBUILD_TARGET), linux solaris f
+ $(VBOX_PATH_CROGL_GENFILES)/solaris_exports.c
+ VBoxOGL_SOURCES.freebsd += \
+ $(VBOX_PATH_CROGL_GENFILES)/freebsd_exports.c
++ VBoxOGL_SOURCES.netbsd += \
++ $(VBOX_PATH_CROGL_GENFILES)/netbsd_exports.c
+ endif
+ endif
+
+@@ -211,14 +220,14 @@ VBoxOGL_LIBS.win += \
+ $(PATH_STAGE_LIB)/additions/VBoxDispMpLogger$(VBOX_SUFF_LIB) \
+ $(PATH_STAGE_LIB)/additions/VBoxCrHgsmi$(VBOX_SUFF_LIB)
+
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGL_LIBS += \
+ $(PATH_STAGE_LIB)/libXcomposite.so \
+ $(PATH_STAGE_LIB)/libXdamage.so \
+ $(PATH_STAGE_LIB)/libXfixes.so \
+ $(PATH_STAGE_LIB)/libXext.so
+ ifdef VBoxOGL_FAKEDRI
+- ifeq ($(KBUILD_TARGET), freebsd)
++ ifeq ($(KBUILD_TARGET), freebsd netbsd)
+ VBoxOGL_LIBS += \
+ elf
+ else
+@@ -305,7 +314,7 @@ $(VBOX_PATH_CROGL_GENFILES)/cropengl-x86
+ endif #ifdef VBOX_WITH_WDDM
+
+
+-else if1of ($(KBUILD_TARGET), freebsd linux solaris)
++else if1of ($(KBUILD_TARGET), freebsd netbsd linux solaris)
+ # FreeBSD, Linux, Solaris
+ $(VBOX_PATH_CROGL_GENFILES)/getprocaddress.c: $(PATH_SUB_CURRENT)/getprocaddress.py $(VBOX_CROGL_API_FILES) | $$(dir $$@)
+ $(call MSG_GENERATE,python,$@,$<)
+@@ -328,6 +337,14 @@ $(VBOX_PATH_CROGL_GENFILES)/freebsd_expo
+ $(call MSG_GENERATE,python,$@,$<)
+ $(QUIET)$(call VBOX_CROGL_PYTHON_ENV,$(VBOX_PATH_CROGL_PYTHON_INCLUDE),$@) $(VBOX_BLD_PYTHON) $< $(VBOX_PATH_CROGL_GLAPI)
+
++ else ifeq ($(KBUILD_TARGET),netbsd)
++$(VBOX_PATH_CROGL_GENFILES)/netbsd_exports.c: \
++ $(PATH_SUB_CURRENT)/NetBSD_exports.py \
++ $(VBOX_CROGL_API_FILES) $(PATH_SUB_CURRENT)/entrypoints.py \
++ | $$(dir $$@)
++ $(call MSG_GENERATE,python,$@,$<)
++ $(QUIET)$(call VBOX_CROGL_PYTHON_ENV,$(VBOX_PATH_CROGL_PYTHON_INCLUDE),$@) $(VBOX_BLD_PYTHON) $< $(VBOX_PATH_CROGL_GLAPI)
++
+ else
+ $(VBOX_PATH_CROGL_GENFILES)/linux_exports.asm: \
+ $(PATH_SUB_CURRENT)/Linux_i386_exports.py \
+@@ -366,6 +383,14 @@ $(VBOX_PATH_CROGL_GENFILES)/freebsd_expo
+ $(call MSG_GENERATE,python,$@,$<)
+ $(QUIET)$(call VBOX_CROGL_PYTHON_ENV,$(VBOX_PATH_CROGL_PYTHON_INCLUDE),$@) $(VBOX_BLD_PYTHON) $< $(VBOX_PATH_CROGL_GLAPI)
+
++ else ifeq ($(KBUILD_TARGET),netbsd)
++$(VBOX_PATH_CROGL_GENFILES)/netbsd_exports_dri.asm: \
++ $(PATH_SUB_CURRENT)/NetBSD_i386_exports_dri.py \
++ $(VBOX_CROGL_API_FILES) $(PATH_SUB_CURRENT)/entrypoints.py \
++ | $$(dir $$@)
++ $(call MSG_GENERATE,python,$@,$<)
++ $(QUIET)$(call VBOX_CROGL_PYTHON_ENV,$(VBOX_PATH_CROGL_PYTHON_INCLUDE),$@) $(VBOX_BLD_PYTHON) $< $(VBOX_PATH_CROGL_GLAPI)
++
+ else
+ $(VBOX_PATH_CROGL_GENFILES)/linux_exports_dri.asm: \
+ $(PATH_SUB_CURRENT)/Linux_i386_exports_dri.py \
+@@ -420,6 +445,14 @@ $(VBOX_PATH_CROGL_GENFILES)/freebsd_expo
+ | $$(dir $$@)
+ $(call MSG_GENERATE,python,$@,$<)
+ $(QUIET)$(call VBOX_CROGL_PYTHON_ENV,$(VBOX_PATH_CROGL_PYTHON_INCLUDE),$@) $(VBOX_BLD_PYTHON) $< $(VBOX_PATH_CROGL_GLAPI)
++
++ else ifeq ($(KBUILD_TARGET),netbsd)
++$(VBOX_PATH_CROGL_GENFILES)/netbsd_exports.c: \
++ $(PATH_SUB_CURRENT)/NetBSD_exports.py \
++ $(VBOX_CROGL_API_FILES) $(PATH_SUB_CURRENT)/entrypoints.py \
++ | $$(dir $$@)
++ $(call MSG_GENERATE,python,$@,$<)
++ $(QUIET)$(call VBOX_CROGL_PYTHON_ENV,$(VBOX_PATH_CROGL_PYTHON_INCLUDE),$@) $(VBOX_BLD_PYTHON) $< $(VBOX_PATH_CROGL_GLAPI)
+ else
+ $(VBOX_PATH_CROGL_GENFILES)/linux_exports.c: \
+ $(PATH_SUB_CURRENT)/Linux_exports.py \
+@@ -439,7 +472,7 @@ endif
+ VBoxOGLarrayspu_TEMPLATE = VBOXCROGLR3GUESTDLL
+ VBoxOGLarrayspu_INCS = \
+ array
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd metbsd)
+ VBoxOGLarrayspu_INCS += \
+ $(VBOX_MESA_INCS)
+ endif
+@@ -487,7 +520,7 @@ endif
+ VBoxOGLpassthroughspu_TEMPLATE = VBOXCROGLR3GUESTDLL
+ VBoxOGLpassthroughspu_INCS = \
+ passthrough
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGLpassthroughspu_INCS += \
+ $(VBOX_MESA_INCS)
+ endif
+@@ -536,7 +569,7 @@ VBoxOGLpackspu_TEMPLATE = VBOXCROGL
+ VBoxOGLpackspu_DEFS = TRACKS_STATE=1 PACKS=1
+ VBoxOGLpackspu_INCS = \
+ pack
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGLpackspu_INCS += \
+ $(VBOX_MESA_INCS)
+ endif
+@@ -642,7 +675,7 @@ $(VBOX_PATH_CROGL_GENFILES)/packspu_prot
+ VBoxOGLfeedbackspu_TEMPLATE = VBOXCROGLR3GUESTDLL
+ VBoxOGLfeedbackspu_INCS = \
+ feedback
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGLfeedbackspu_INCS += \
+ $(VBOX_MESA_INCS)
+ endif
+@@ -704,4 +737,3 @@ $(VBOX_PATH_CROGL_GENFILES)/feedbackspu_
+ $(QUIET)$(call VBOX_CROGL_PYTHON_ENV,$(VBOX_PATH_CROGL_PYTHON_INCLUDE),$@) $(VBOX_BLD_PYTHON) $< $(VBOX_PATH_CROGL_GLAPI) $(<D)
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_NetBSD__exports.py b/virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_NetBSD__exports.py
new file mode 100644
index 0000000..e9db8af
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_NetBSD__exports.py
@@ -0,0 +1,16 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/crOpenGL/NetBSD_exports.py.orig 2016-07-06 19:36:20.413032855 +0000
++++ src/VBox/Additions/common/crOpenGL/NetBSD_exports.py
+@@ -0,0 +1,11 @@
++# Copyright (c) 2001, Stanford University
++# All rights reserved.
++#
++# See the file LICENSE.txt for information on redistributing this software.
++
++import entrypoints
++
++hacks = []
++
++entrypoints.GenerateEntrypoints(hacks)
++
diff --git a/virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_fakedri__drv.c b/virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_fakedri__drv.c
new file mode 100644
index 0000000..1fcfc3d
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_common_crOpenGL_fakedri__drv.c
@@ -0,0 +1,42 @@
+$NetBSD$
+
+--- src/VBox/Additions/common/crOpenGL/fakedri_drv.c.orig 2016-03-04 19:23:12.000000000 +0000
++++ src/VBox/Additions/common/crOpenGL/fakedri_drv.c
+@@ -30,7 +30,7 @@
+ #include <elf.h>
+ #include <unistd.h>
+
+-#if defined(RT_OS_FREEBSD)
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ #include <sys/param.h>
+ #include <fcntl.h>
+ #include <gelf.h>
+@@ -62,6 +62,9 @@ typedef enum {
+ # ifdef RT_OS_FREEBSD
+ # define DRI_DEFAULT_DRIVER_DIR "/usr/local/lib/dri"
+ # define DRI_XORG_DRV_DIR "/usr/local/lib/xorg/modules/drivers/"
++# elif defined(RT_OS_NETBSD)
++# define DRI_DEFAULT_DRIVER_DIR "/usr/X11R7/lib/modules/dri"
++# define DRI_XORG_DRV_DIR "/usr/X11R7/lib/modules/drivers/"
+ # else
+ # define DRI_DEFAULT_DRIVER_DIR "/usr/lib64/dri:/usr/lib/dri:/usr/lib/x86_64-linux-gnu/dri:/usr/lib/xorg/modules/dri"
+ # define DRI_XORG_DRV_DIR "/usr/lib/xorg/modules/drivers/"
+@@ -70,6 +73,9 @@ typedef enum {
+ # ifdef RT_OS_FREEBSD
+ # define DRI_DEFAULT_DRIVER_DIR "/usr/local/lib/dri"
+ # define DRI_XORG_DRV_DIR "/usr/local/lib/xorg/modules/drivers/"
++# elif defined(RT_OS_NETBSD)
++# define DRI_DEFAULT_DRIVER_DIR "/usr/X11R7/lib/modules/dri"
++# define DRI_XORG_DRV_DIR "/usr/X11R7/lib/modules/drivers/"
+ # else
+ # define DRI_DEFAULT_DRIVER_DIR "/usr/lib/dri:/usr/lib/i386-linux-gnu/dri:/usr/lib/xorg/modules/dri"
+ # define DRI_XORG_DRV_DIR "/usr/lib/xorg/modules/drivers/"
+@@ -228,7 +234,7 @@ vboxApplyPatch(const char* psFuncName, v
+
+ #define FAKEDRI_JMP64_PATCH_SIZE 13
+
+-#if defined(RT_OS_FREEBSD)
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /* Provide basic dladdr1 flags */
+ enum {
+ RTLD_DL_SYMENT = 1
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_Installer_pkg-descr b/virtualbox/patches/patch-src_VBox_Additions_netbsd_Installer_pkg-descr
new file mode 100644
index 0000000..df78364
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_Installer_pkg-descr
@@ -0,0 +1,8 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/Installer/pkg-descr.orig 2016-07-07 07:08:46.360554883 +0000
++++ src/VBox/Additions/netbsd/Installer/pkg-descr
+@@ -0,0 +1,3 @@
++VirtualBox guest additions for the NETBSD operating system
++
++WWW: http://www.virtualbox.org
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_Installer_vboxguest.sh b/virtualbox/patches/patch-src_VBox_Additions_netbsd_Installer_vboxguest.sh
new file mode 100644
index 0000000..17d3307
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_Installer_vboxguest.sh
@@ -0,0 +1,140 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/Installer/vboxguest.sh.orig 2016-07-07 07:08:46.369610770 +0000
++++ src/VBox/Additions/netbsd/Installer/vboxguest.sh
+@@ -0,0 +1,135 @@
++#!/bin/bash
++#
++# VirtualBox Guest Additions kernel module control script for NetBSD.
++#
++# Copyright (C) 2008-2010 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.
++#
++
++VBOXGUESTFILE=""
++SILENTUNLOAD=""
++
++abort()
++{
++ echo 1>&2 "$1"
++ exit 1
++}
++
++info()
++{
++ echo 1>&2 "$1"
++}
++
++get_module_path()
++{
++ moduledir="/stand/$(uname -m)/$(uname -r)/modules/";
++ modulepath=$moduledir/vboxguest/vboxguest.kmod
++ if test -f "$modulepath"; then
++ VBOXGUESTFILE="$modulepath"
++ else
++ VBOXGUESTFILE=""
++ fi
++}
++
++check_if_installed()
++{
++ if test "$VBOXGUESTFILE" -a -f "$VBOXGUESTFILE"; then
++ return 0
++ fi
++ abort "VirtualBox kernel module (vboxguest) not installed."
++}
++
++module_loaded()
++{
++ loadentry=`kldstat | grep vboxguest`
++ if test -z "$loadentry"; then
++ return 1
++ fi
++ return 0
++}
++
++check_root()
++{
++ if test `id -u` -ne 0; then
++ abort "This program must be run with administrator privileges. Aborting"
++ fi
++}
++
++start()
++{
++ if module_loaded; then
++ info "vboxguest already loaded..."
++ else
++ /sbin/kldload vboxguest.ko
++ if ! module_loaded; then
++ abort "Failed to load vboxguest."
++ elif test -c "/dev/vboxguest"; then
++ info "Loaded vboxguest."
++ else
++ stop
++ abort "Aborting due to attach failure."
++ fi
++ fi
++}
++
++stop()
++{
++ if module_loaded; then
++ /sbin/kldunload vboxguest.ko
++ info "Unloaded vboxguest."
++ elif test -z "$SILENTUNLOAD"; then
++ info "vboxguest not loaded."
++ fi
++}
++
++restart()
++{
++ stop
++ sync
++ start
++ return 0
++}
++
++status()
++{
++ if module_loaded; then
++ info "vboxguest running."
++ else
++ info "vboxguest stopped."
++ fi
++}
++
++check_root
++get_module_path
++check_if_installed
++
++if test "$2" = "silentunload"; then
++ SILENTUNLOAD="$2"
++fi
++
++case "$1" in
++start)
++ start
++ ;;
++stop)
++ stop
++ ;;
++restart)
++ restart
++ ;;
++status)
++ status
++ ;;
++*)
++ echo "Usage: $0 {start|stop|restart|status}"
++ exit 1
++esac
++
++exit
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_Makefile b/virtualbox/patches/patch-src_VBox_Additions_netbsd_Makefile
new file mode 100644
index 0000000..680bbd9
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_Makefile
@@ -0,0 +1,58 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/Makefile.orig 2016-07-07 07:08:46.378102526 +0000
++++ src/VBox/Additions/netbsd/Makefile
+@@ -0,0 +1,53 @@
++#
++# Makefile for the VirtualBox NetBSD Guest Drivers.
++#
++
++#
++#
++# Copyright (C) 2009-2010 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.
++#
++
++KBUILD_VERBOSE =
++
++all:
++ @echo "*** Building 'vboxguest' module ***"
++ @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxguest
++ @if [ -f vboxguest/vboxguest.ko ]; then \
++ cp vboxguest/vboxguest.ko .; \
++ fi
++ @echo
++ @if [ -d vboxvfs ]; then \
++ echo "*** Building 'vboxvfs' module ***"; \
++ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxvfs; \
++ if [ -f vboxvfs/vboxvfs.ko ]; then \
++ cp vboxvfs/vboxvfs.ko .; \
++ fi; \
++ fi
++
++
++install:
++ @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxguest install
++ @if [ -d vboxvfs ]; then \
++ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxvfs install; \
++ fi
++
++clean:
++ @$(MAKE) -C vboxguest clean
++ @if [ -d vboxvfs ]; then \
++ $(MAKE) -C vboxvfs clean; \
++ fi
++ rm -f vboxguest.*o vboxvfs.*o
++
++load:
++ @/sbin/kldunload vboxvfs || true
++ @/sbin/kldunload vboxguest || true
++ @/sbin/kldload ./vboxguest.ko
++ @if [ -f vboxvfs.ko ]; then /sbin/kldload ./vboxvfs.ko; fi
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Additions_netbsd_Makefile.kmk
new file mode 100644
index 0000000..0f9b42f
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_Makefile.kmk
@@ -0,0 +1,196 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/Makefile.kmk.orig 2016-07-07 07:08:46.386807464 +0000
++++ src/VBox/Additions/netbsd/Makefile.kmk
+@@ -0,0 +1,191 @@
++# Makefile.kmk $
++## @file
++# Sub-Makefile for the NetBSD guest additions base directory.
++#
++
++#
++# Copyright (C) 2008-2015 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.
++#
++
++SUB_DEPTH = ../../../..
++include $(KBUILD_PATH)/subheader.kmk
++
++ifneq ($(KBUILD_HOST),netbsd)
++$(error "The NetBSD guest additions installer can only be built on NetBSD!")
++endif
++
++# Include sub-makefiles.
++#include $(PATH_SUB_CURRENT)/vboxvfs/Makefile.kmk
++include $(PATH_SUB_CURRENT)/drm/Makefile.kmk
++
++#
++# Globals
++#
++VBOX_FBSD_ADD_INS_OUT_DIR := $(PATH_TARGET)/Additions/Installer/netbsd
++BLDDIRS += \
++ $(VBOX_FBSD_ADD_INS_OUT_DIR) \
++ $(VBOX_FBSD_ADD_INS_OUT_DIR)/module
++VBOX_PATH_NETBSD_ADDITION_INSTALLER := $(PATH_SUB_CURRENT)/Installer
++VBOX_PATH_X11_ADDITION_INSTALLER := $(PATH_ROOT)/src/VBox/Additions/x11/Installer
++
++
++#
++# Targets
++#
++ifndef VBOX_OSE
++ BLDDIRS += $(VBOX_FBSD_ADD_INS_OUT_DIR) $(VBOX_FBSD_ADD_INS_OUT_DIR)/module
++ PACKING += $(PATH_STAGE_BIN)/additions/VBoxNetBSDAdditions.tbz
++ OTHER_CLEAN += $(PACKING)
++endif
++
++
++#
++# Files to install
++#
++VBOX_FBSD_ADD_STRIP_BIN = \
++ VBoxService \
++ VBoxClient \
++ VBoxControl \
++ vboxmouse_drv_70.so \
++ vboxmouse_drv_71.so \
++ vboxmouse_drv_14.so \
++ vboxmouse_drv_15.so \
++ vboxmouse_drv_16.so \
++ vboxmouse_drv_17.so \
++ vboxvideo_drv_70.so \
++ vboxvideo_drv_71.so \
++ vboxvideo_drv_13.so \
++ vboxvideo_drv_14.so \
++ vboxvideo_drv_15.so \
++ vboxvideo_drv_16.so \
++ vboxvideo_drv_17.so \
++ VBoxOGLarrayspu.so \
++ VBoxOGLcrutil.so \
++ VBoxOGLerrorspu.so \
++ VBoxOGLfeedbackspu.so \
++ VBoxOGLpackspu.so \
++ VBoxOGLpassthroughspu.so \
++ VBoxOGL.so
++
++VBOX_FBSD_ADD_MODULES = \
++ vboxguest \
++ vboxvideo_drm
++
++#
++# All the bin files that go into the archives.
++#
++VBOX_FBSD_ADD_DBG_SYM_FILES := $(addsuffix .dbgsym,$(VBOX_FBSD_ADD_STRIP_BIN))
++VBOX_FBSD_ADD_INS_FILES := $(addprefix $(VBOX_FBSD_ADD_INS_OUT_DIR)/,$(VBOX_FBSD_ADD_STRIP_BIN) $(VBOX_FBSD_ADD_STRIP_OBJ) $(VBOX_FBSD_ADD_DBG_SYM_FILES))
++VBOX_FBSD_ADD_INS_MODULES := $(addprefix $(VBOX_FBSD_ADD_INS_OUT_DIR)/module/,$(VBOX_FBSD_ADD_MODULES))
++
++# Cleanup of the the installer directory files
++OTHER_CLEAN += $(VBOX_FBSD_ADD_INS_FILES)) $(VBOX_FBSD_ADD_INS_MODULES)
++
++# pattern rule for copying the debug info from the VBOX_FBSD_ADD_STRIP_BIN files to the installation directory
++$(addprefix $(VBOX_FBSD_ADD_INS_OUT_DIR)/,$(VBOX_FBSD_ADD_DBG_SYM_FILES)): \
++ $(VBOX_FBSD_ADD_INS_OUT_DIR)/%.dbgsym : $(PATH_STAGE_BIN)/additions/% | $$(dir $$@)
++ $(call MSG_TOOL,copydbg,$<,$@)
++ $(QUIET)objcopy --only-keep-debug $< $@
++
++# pattern rule for stripping and copying the VBOX_FBSD_ADD_STRIP_BIN files to the installation directory
++$(addprefix $(VBOX_FBSD_ADD_INS_OUT_DIR)/,$(VBOX_FBSD_ADD_STRIP_BIN)): \
++ $(VBOX_FBSD_ADD_INS_OUT_DIR)/% : $(PATH_STAGE_BIN)/additions/% \
++ $(VBOX_FBSD_ADD_INS_OUT_DIR)/%.dbgsym \
++ | $$(dir $$@)
++ $(call MSG_INST_FILE,$<,$@)
++ $(QUIET)$(INSTALL) -m 0755 $(if $(VBOX_DO_STRIP),-s,) $< $@
++ $(QUIET)objcopy --add-gnu-debuglink=$(addsuffix .dbgsym,$@) $@
++
++# pattern rule for stripping and copying the VBOX_FBSD_ADD_STRIP_OBJ files to the installation directory
++$(addprefix $(VBOX_FBSD_ADD_INS_OUT_DIR)/,$(VBOX_FBSD_ADD_STRIP_OBJ)): \
++ $(VBOX_FBSD_ADD_INS_OUT_DIR)/% : $(PATH_STAGE_BIN)/additions/% | $$(dir $$@)
++ $(call MSG_INST_FILE,$<,$@)
++ifeq ($(VBOX_DO_STRIP),)
++ $(QUIET)$(INSTALL) -m 0644 $< $@
++else # strip to temp file because of umask.
++ $(QUIET)objcopy --strip-unneeded -R .comment $< $@.tmp
++ $(QUIET)$(INSTALL) -m 0644 $@.tmp $@
++ $(QUIET)$(RM) -f -- $@.tmp
++endif
++
++# pattern rule for copying the VBOX_FBSD_ADD_MODULES files to the installation directory
++$(VBOX_FBSD_ADD_INS_MODULES): \
++ $(VBOX_FBSD_ADD_INS_OUT_DIR)/module/% : $(PATH_STAGE_BIN)/additions/src/% | $(VBOX_FBSD_ADD_INS_OUT_DIR)/module/
++ $(call MSG_INST_FILE,$<,$@)
++# Remove target directories first, otherwise the behaviour of cp will not be
++# what we want if it already exists. See the cp manual page for more details.
++ $(QUIET)$(RM) -Rf $@
++ $(QUIET)cp -af $< $(VBOX_FBSD_ADD_INS_OUT_DIR)/module
++
++
++INSTALLS += $(if $(VBOX_OSE),, fbsd_add_inst-nobin)
++fbsd_add_inst-nobin_INST = obj/Additions/Installer/netbsd
++fbsd_add_inst-nobin_MODE = a+r,u+w
++fbsd_add_inst-nobin_SOURCES = \
++ ../x11/Installer/98vboxadd-xclient \
++ ../x11/Installer/vboxclient.desktop \
++ ../x11/Installer/vboxvideo.ids \
++ ../x11/Installer/x11config.pl \
++ ../x11/Installer/x11config15.pl
++
++
++INSTALLS += GuestDrivers-src
++GuestDrivers-src_INST = bin/additions/src/
++GuestDrivers-src_MODE = a+r,u+w
++GuestDrivers-src_SOURCES = Makefile
++
++# this file needs editing before it can be included in the generic installer.
++$(VBOX_FBSD_ADD_INS_OUT_DIR)/install.sh: \
++ $(VBOX_PATH_NETBSD_ADDITION_INSTALLER)/install.sh | $$(dir $$@)
++ $(QUIET)$(SED) \
++ -e "s;_VERSION_;$(VBOX_VERSION_STRING);g" \
++ -e "s;_BUILD_;$(shell date);g" \
++ -e "s;_OSE_;$(VBOX_OSE);g" \
++ -e "s;_BUILDTYPE_;$(KBUILD_TYPE);g" \
++ -e "s;_ARCH_;$(KBUILD_TARGET_ARCH);g" \
++ --output $(VBOX_FBSD_ADD_INS_OUT_DIR)/install_.sh \
++ $<
++ $(QUIET)$(INSTALL) -m 0755 $(VBOX_FBSD_ADD_INS_OUT_DIR)/install_.sh $@
++ $(QUIET)$(RM) $(VBOX_FBSD_ADD_INS_OUT_DIR)/install_.sh
++OTHERS_CLEAN += $(VBOX_FBSD_ADD_INS_OUT_DIR)/install.sh
++
++
++include $(FILE_KBUILD_SUB_FOOTER)
++
++
++#
++# Build the NetBSD Guest Additions installer package.
++#
++# Note that $(PATH_SUB_CURRENT) was changed by subfooter.kmk above and
++# any references should be made via variables assigned a know value via := .
++#
++# We need to depend on all source files for the additions and shared
++# folders kernel modules.
++## @todo Replace the wildcard stuff by the correct file lists now that
++# we've got everything included.
++#
++$(PATH_STAGE_BIN)/additions/VBoxNetBSDAdditions.tbz: \
++ $$(fbsd_add_inst-nobin_2_STAGE_TARGETS) \
++ $$(fbsd_add_inst-bin_2_STAGE_TARGETS) \
++ $(VBOX_FBSD_ADD_INS_FILES) \
++ $(VBOX_FBSD_ADD_INS_MODULES) \
++ $(VBOX_FBSD_ADD_INS_OUT_DIR)/install.sh \
++ $(wildcard $(PATH_STAGE_BIN)/additions/src/*) \
++ $(wildcard $(PATH_STAGE_BIN)/additions/src/*/*) \
++ $(wildcard $(PATH_STAGE_BIN)/additions/src/*/*/*) \
++ $(wildcard $(PATH_STAGE_BIN)/additions/src/*/*/*/*) \
++ $(VBOX_VERSION_STAMP) $(VBOX_SVN_REV_HEADER)
++ pkg_create \
++ -I $(VBOX_PATH_NETBSD_ADDITION_INSTALLER)/install.sh \
++ -c $(VBOX_PATH_NETBSD_ADDITION_INSTALLER)/pkg-comment \
++ -d $(VBOX_PATH_NETBSD_ADDITION_INSTALLER)/pkg-descr \
++ -f $(VBOX_PATH_NETBSD_ADDITION_INSTALLER)/pkg-plist \
++ $@
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_Makefile b/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_Makefile
new file mode 100644
index 0000000..7ae7275
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_Makefile
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/drm/Makefile.orig 2016-07-07 07:08:46.395472943 +0000
++++ src/VBox/Additions/netbsd/drm/Makefile
+@@ -0,0 +1,26 @@
++# Makefile $
++## @file
++# Makefile for the VirtualBox NetBSD Host Driver.
++#
++
++#
++#
++# Copyright (C) 2006-2010 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.
++#
++
++KMOD = vboxvideo
++
++SRCS = \
++ vboxvideo_drm.c
++
++SRCS += device_if.h bus_if.h pci_if.h opt_drm.h
++
++.include <bsd.kmod.mk>
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_Makefile.kmk
new file mode 100644
index 0000000..4583542
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_Makefile.kmk
@@ -0,0 +1,76 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/drm/Makefile.kmk.orig 2016-07-07 07:08:46.404285508 +0000
++++ src/VBox/Additions/netbsd/drm/Makefile.kmk
+@@ -0,0 +1,71 @@
++# Makefile.kmk $
++## @file
++# Sub-Makefile for the vboxvideo DRM module (NetBSD kernel OpenGL module).
++#
++
++#
++# Copyright (C) 2009-2015 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.
++#
++
++
++SUB_DEPTH = ../../../../..
++include $(KBUILD_PATH)/subheader.kmk
++
++INSTALLS += vboxvideo-mod
++
++ifdef VBOX_WITH_ADDITION_DRIVERS
++ SYSMODS += vboxvideo_drm
++endif
++ifneq ($(KBUILD_HOST),netbsd)
++$(error "The NetBSD guest additions can only be built on NetBSD!")
++endif
++
++#
++# Populate FILES_VBOXVIDEO_DRM_NOBIN
++#
++include $(PATH_SUB_CURRENT)/files_vboxvideo_drm
++
++# vboxvideo source
++vboxvideo-mod_INST = $(INST_ADDITIONS)src/vboxvideo_drm/
++vboxvideo-mod_MODE = a+r,u+w
++vboxvideo-mod_SOURCES = $(subst ",,$(FILES_VBOXVIDEO_DRM_NOBIN))
++
++#
++# vboxvideo - The Video DRM (Direct Rendering Module) kernel module
++#
++# Note! Syntax checking only.
++#
++vboxvideo_drm_TEMPLATE = VBOXGUESTR0
++vboxvideo_drm_NAME = vboxvideo
++vboxvideo_drm_DEFS = VBOX_WITH_HGCM VBOX_SVN_REV=$(VBOX_SVN_REV)
++vboxvideo_drm_DEPS += $(VBOX_SVN_REV_KMK)
++vboxvideo_drm_INCS.netbsd = \
++ $(vboxvideo_drm_0_OUTDIR) \
++ $(PATH_STAGE)/gen-sys-hdrs
++vboxvideo_drm_SOURCES = vboxvideo_drm.c
++vboxvideo_drm_LIBS = \
++ $(VBOX_LIB_VBGL_R0) \
++ $(VBOX_LIB_IPRT_GUEST_R0)
++vboxvideo_drm_ORDERDEPS.netbsd = \
++ $(PATH_STAGE)/gen-sys-hdrs/pci_if.h \
++ $(PATH_STAGE)/gen-sys-hdrs/bus_if.h \
++ $(PATH_STAGE)/gen-sys-hdrs/device_if.h \
++ $(vboxvideo_drm_0_OUTDIR)/opt_drm.h
++vboxvideo_drm_CLEAN.netbsd = $(vboxvideo_drm_DEPS)
++
++#
++# Header for DRM not included by us.
++#
++$$(vboxvideo_drm_0_OUTDIR)/opt_drm.h:
++ $(QUIET)$(MKDIR) -p $(vboxvideo_drm_0_OUTDIR)
++ $(QUIET)touch $(vboxvideo_drm_0_OUTDIR)/opt_drm.h
++
++include $(FILE_KBUILD_SUB_FOOTER)
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_files__vboxvideo__drm b/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_files__vboxvideo__drm
new file mode 100644
index 0000000..26e63e2
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_files__vboxvideo__drm
@@ -0,0 +1,30 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/drm/files_vboxvideo_drm.orig 2016-07-07 07:08:46.413493808 +0000
++++ src/VBox/Additions/netbsd/drm/files_vboxvideo_drm
+@@ -0,0 +1,25 @@
++#!/bin/sh
++# files_vboxvideo_drm $
++## @file
++# Shared file between Makefile.kmk and export_modules
++#
++
++#
++# Copyright (C) 2007-2010 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.
++#
++
++FILES_VBOXVIDEO_DRM_NOBIN=" \
++ ${PATH_ROOT}/src/VBox/Additions/netbsd/drm/vboxvideo_drm.c=>vboxvideo_drm.c \
++ ${PATH_ROOT}/src/VBox/Additions/netbsd/drm/Makefile=>Makefile \
++"
++
++FILES_VBOXVIDEO_DRM_BIN=" \
++"
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_vboxvideo__drm.c b/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_vboxvideo__drm.c
new file mode 100644
index 0000000..f701732
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_drm_vboxvideo__drm.c
@@ -0,0 +1,144 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/drm/vboxvideo_drm.c.orig 2016-07-07 07:08:46.422526448 +0000
++++ src/VBox/Additions/netbsd/drm/vboxvideo_drm.c
+@@ -0,0 +1,139 @@
++/* vboxvideo_drm.c $ */
++/** @file
++ * VirtualBox Guest Additions - vboxvideo DRM module.
++ * NetBSD kernel OpenGL module.
++ */
++
++/*
++ * Copyright (C) 2006-2010 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.
++ * --------------------------------------------------------------------
++ *
++ * This code is based on:
++ *
++ * tdfx_drv.c -- tdfx driver -*- linux-c -*-
++ * Created: Thu Oct 7 10:38:32 1999 by faith%precisioninsight.com@localhost
++ *
++ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
++ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
++ * All Rights Reserved.
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a
++ * copy of this software and associated documentation files (the "Software"),
++ * to deal in the Software without restriction, including without limitation
++ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
++ * and/or sell copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice (including the next
++ * paragraph) shall be included in all copies or substantial portions of the
++ * Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
++ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
++ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
++ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
++ * DEALINGS IN THE SOFTWARE.
++ *
++ * Authors:
++ * Rickard E. (Rik) Faith <faith%valinux.com@localhost>
++ * Daryll Strauss <daryll%valinux.com@localhost>
++ * Gareth Hughes <gareth%valinux.com@localhost>
++ *
++ */
++
++#include <sys/cdefs.h>
++
++#include "dev/drm/drmP.h"
++#include "dev/drm/drm_pciids.h"
++
++#define DRIVER_AUTHOR "Oracle Corporation"
++#define DRIVER_NAME "vboxvideo"
++#define DRIVER_DESC "VirtualBox DRM"
++#define DRIVER_DATE "20090317"
++#define DRIVER_MAJOR 1
++#define DRIVER_MINOR 0
++#define DRIVER_PATCHLEVEL 0
++
++/** @todo Take PCI IDs from VBox/param.h; VBOX_VESA_VENDORID,
++ * VBOX_VESA_DEVICEID. */
++#define vboxvideo_PCI_IDS { 0x80ee, 0xbeef, 0, "VirtualBox Video" }, \
++ { 0, 0, 0, NULL }
++
++static drm_pci_id_list_t vboxvideo_pciidlist[] = {
++ vboxvideo_PCI_IDS
++};
++
++static void vboxvideo_configure(struct drm_device *dev)
++{
++ dev->driver->buf_priv_size = 1; /* No dev_priv */
++
++ dev->driver->max_ioctl = 0;
++
++ dev->driver->name = DRIVER_NAME;
++ dev->driver->desc = DRIVER_DESC;
++ dev->driver->date = DRIVER_DATE;
++ dev->driver->major = DRIVER_MAJOR;
++ dev->driver->minor = DRIVER_MINOR;
++ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
++}
++
++static int
++vboxvideo_probe(device_t kdev)
++{
++ return drm_probe(kdev, vboxvideo_pciidlist);
++}
++
++static int
++vboxvideo_attach(device_t kdev)
++{
++ struct drm_device *dev = device_get_softc(kdev);
++
++ dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
++ M_WAITOK | M_ZERO);
++
++ vboxvideo_configure(dev);
++
++ return drm_attach(kdev, vboxvideo_pciidlist);
++}
++
++static int
++vboxvideo_detach(device_t kdev)
++{
++ struct drm_device *dev = device_get_softc(kdev);
++ int ret;
++
++ ret = drm_detach(kdev);
++
++ free(dev->driver, DRM_MEM_DRIVER);
++
++ return ret;
++}
++
++static device_method_t vboxvideo_methods[] = {
++ /* Device interface */
++ DEVMETHOD(device_probe, vboxvideo_probe),
++ DEVMETHOD(device_attach, vboxvideo_attach),
++ DEVMETHOD(device_detach, vboxvideo_detach),
++
++ { 0, 0 }
++};
++
++static driver_t vboxvideo_driver = {
++ "drm",
++ vboxvideo_methods,
++ sizeof(struct drm_device)
++};
++
++extern devclass_t drm_devclass;
++DRIVER_MODULE(vboxvideo, vgapci, vboxvideo_driver, drm_devclass, 0, 0);
++MODULE_DEPEND(vboxvideo, drm, 1, 1, 1);
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_Makefile.kmk
new file mode 100644
index 0000000..6678eb2
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_Makefile.kmk
@@ -0,0 +1,68 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/vboxvfs/Makefile.kmk.orig 2016-07-07 07:08:46.431560014 +0000
++++ src/VBox/Additions/netbsd/vboxvfs/Makefile.kmk
+@@ -0,0 +1,63 @@
++# Id: Makefile.kmk $
++## @file
++# Sub-Makefile for the NetBSD Shared folder kernel module.
++#
++
++#
++# Copyright (C) 2007-2015 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.
++#
++
++SUB_DEPTH = ../../../../..
++include $(KBUILD_PATH)/subheader.kmk
++
++ifneq ($(KBUILD_HOST),netbsd)
++$(error "The NetBSD guest additions can only be built on NetBSD!")
++endif
++
++#
++# vboxvfs - The Shared Folder Driver
++#
++SYSMODS.netbsd += vboxvfs
++vboxvfs_TEMPLATE = VBOXGUESTR0
++vboxvfs_DEFS = VBOX_WITH_HGCM
++vboxvfs_INCS = \
++ . \
++ $(vboxvfs_0_OUTDIR)
++vboxvfs_SOURCES = \
++ vboxvfs_vfsops.c \
++ vboxvfs_vnops.c
++vboxvfs_LIBS = \
++ $(VBOX_LIB_VBGL_R0) \
++ $(VBOX_LIB_IPRT_GUEST_R0)
++vboxvfs_DEPS = \
++ $$(vboxvfs_0_OUTDIR)/vnode_if.h \
++ $$(vboxvfs_0_OUTDIR)/vnode_if_newproto.h \
++ $$(vboxvfs_0_OUTDIR)/vnode_if_typedef.h
++vboxvfs_CLEAN += $(vboxvfs_DEPS)
++
++VBOX_AWK := /usr/bin/awk
++
++$$(vboxvfs_0_OUTDIR)/vnode_if.h: $(VBOX_NETBSD_SRC)/kern/vnode_if.src
++ $(call MSG_TOOL,awk,VBoxGuest,$<,$@)
++ $(QUIET)$(VBOX_AWK) -f $(VBOX_NETBSD_SRC)/tools/vnode_if.awk $(VBOX_NETBSD_SRC)/kern/vnode_if.src -h
++ $(QUIET)$(MV) $(vboxvfs_0_OUTDIR)/vnode_if.h $(vboxvfs_0_OUTDIR)/vnode_if.h
++
++$$(vboxvfs_0_OUTDIR)/vnode_if_newproto.h: $(VBOX_NETBSD_SRC)/kern/vnode_if.src
++ $(call MSG_TOOL,awk,VBoxGuest,$<,$@)
++ $(QUIET)$(VBOX_AWK) -f $(VBOX_NETBSD_SRC)/tools/vnode_if.awk $(VBOX_NETBSD_SRC)/kern/vnode_if.src -p
++ $(QUIET)$(MV) $(vboxvfs_0_OUTDIR)/vnode_if_newproto.h $(vboxvfs_0_OUTDIR)/vnode_if_newproto.h
++
++$$(vboxvfs_0_OUTDIR)/vnode_if_typedef.h: $(VBOX_NETBSD_SRC)/kern/vnode_if.src
++ $(call MSG_TOOL,awk,VBoxGuest,$<,$@)
++ $(QUIET)$(VBOX_AWK) -f $(VBOX_NETBSD_SRC)/tools/vnode_if.awk $(VBOX_NETBSD_SRC)/kern/vnode_if.src -q
++ $(QUIET)$(MV) $(vboxvfs_0_OUTDIR)/vnode_if_typedef.h $(vboxvfs_0_OUTDIR)/vnode_if_typedef.h
++
++include $(FILE_KBUILD_SUB_FOOTER)
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs.h b/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs.h
new file mode 100644
index 0000000..c0b1f67
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs.h
@@ -0,0 +1,97 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/vboxvfs/vboxvfs.h.orig 2016-07-06 19:39:01.675495646 +0000
++++ src/VBox/Additions/netbsd/vboxvfs/vboxvfs.h
+@@ -0,0 +1,92 @@
++/* vboxvfs.h $ */
++/** @file
++ * Description.
++ */
++
++/*
++ * Copyright (C) 2010 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.
++ */
++
++#ifndef ___VBOXVFS_H___
++#define ___VBOXVFS_H___
++
++#define VBOXVFS_VFSNAME "vboxvfs"
++#define VBOXVFS_VERSION 1
++
++#define MAX_HOST_NAME 256
++#define MAX_NLS_NAME 32
++
++struct vboxvfs_mount_info {
++ char name[MAX_HOST_NAME];
++ char nls_name[MAX_NLS_NAME];
++ int uid;
++ int gid;
++ int ttl;
++};
++
++#ifdef _KERNEL
++
++#include <VBox/VBoxGuestLibSharedFolders.h>
++#include <sys/mount.h>
++#include <sys/vnode.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;
++};
++
++/* structs - stolen from the linux shared module code */
++struct sf_glob_info {
++ VBGLSFMAP map;
++/* struct nls_table *nls;*/
++ int ttl;
++ int uid;
++ int gid;
++ struct vnode *vnode_root;
++};
++
++struct sf_inode_info {
++ SHFLSTRING *path;
++ int force_restat;
++};
++
++#if 0
++struct sf_dir_info {
++ struct list_head info_list;
++};
++#endif
++
++struct sf_dir_buf {
++ size_t nb_entries;
++ size_t free_bytes;
++ size_t used_bytes;
++ void *buf;
++#if 0
++ struct list_head head;
++#endif
++};
++
++struct sf_reg_info {
++ SHFLHANDLE handle;
++};
++
++#endif /* KERNEL */
++
++#endif /* !___VBOXVFS_H___ */
++
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs__vfsops.c b/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs__vfsops.c
new file mode 100644
index 0000000..8f9c9b7
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs__vfsops.c
@@ -0,0 +1,263 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/vboxvfs/vboxvfs_vfsops.c.orig 2016-07-06 19:39:01.675500224 +0000
++++ src/VBox/Additions/netbsd/vboxvfs/vboxvfs_vfsops.c
+@@ -0,0 +1,258 @@
++/* vboxvfs_vfsops.c $ */
++/** @file
++ * Description.
++ */
++
++/*
++ * Copyright (C) 2008-2010 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.
++ */
++
++#include "vboxvfs.h"
++#include <sys/param.h>
++#include <sys/systm.h>
++#include <sys/proc.h>
++#include <sys/bio.h>
++#include <sys/buf.h>
++#include <sys/kernel.h>
++#include <sys/sysctl.h>
++#include <sys/vnode.h>
++#include <sys/mount.h>
++#include <sys/stat.h>
++#include <sys/malloc.h>
++#include <sys/module.h>
++
++#include <iprt/mem.h>
++
++#define VFSMP2SFGLOBINFO(mp) ((struct sf_glob_info *)mp->mnt_data)
++
++static int vboxvfs_version = VBOXVFS_VERSION;
++
++SYSCTL_NODE(_vfs, OID_AUTO, vboxvfs, CTLFLAG_RW, 0, "VirtualBox shared filesystem");
++SYSCTL_INT(_vfs_vboxvfs, OID_AUTO, version, CTLFLAG_RD, &vboxvfs_version, 0, "");
++
++/* global connection to the host service. */
++static VBGLSFCLIENT g_vboxSFClient;
++
++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;
++
++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,
++};
++
++
++VFS_SET(vboxvfs_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)
++{
++ struct vboxvfs_mount_info args;
++ int rc = 0;
++
++ printf("%s: Enter\n", __FUNCTION__);
++
++ rc = copyin(data, &args, sizeof(struct vboxvfs_mount_info));
++ if (rc)
++ return rc;
++
++ ma = mount_argf(ma, "uid", "%d", args.uid);
++ ma = mount_argf(ma, "gid", "%d", args.gid);
++ ma = mount_arg(ma, "from", args.name, -1);
++
++ rc = kernel_mount(ma, flags);
++
++ printf("%s: Leave rc=%d\n", __FUNCTION__, rc);
++
++ return rc;
++}
++
++static const char *vboxvfs_opts[] = {
++ "uid", "gid", "from", "fstype", "fspath", "errmsg", NULL
++};
++
++static int vboxvfs_mount(struct mount *mp, struct thread *td)
++{
++ 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__);
++
++ if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS))
++ return EOPNOTSUPP;
++
++ if (vfs_filteropt(mp->mnt_optnew, vboxvfs_opts))
++ {
++ vfs_mount_error(mp, "%s", "Invalid option");
++ return EINVAL;
++ }
++
++ rc = vfs_getopt(mp->mnt_optnew, "from", (void **)&pszShare, &cbShare);
++ if (rc || pszShare[cbShare-1] != '\0' || cbShare > 0xfffe)
++ return EINVAL;
++
++ rc = vfs_getopt(mp->mnt_optnew, "gid", (void **)&gid, &cbOption);
++ if ((rc != ENOENT) && (rc || cbOption != sizeof(gid)))
++ return EINVAL;
++
++ rc = vfs_getopt(mp->mnt_optnew, "uid", (void **)&uid, &cbOption);
++ if ((rc != ENOENT) && (rc || cbOption != sizeof(uid)))
++ return EINVAL;
++
++ pShFlGlobalInfo = RTMemAllocZ(sizeof(struct sf_glob_info));
++ if (!pShFlGlobalInfo)
++ return ENOMEM;
++
++ cbShFlShareName = offsetof (SHFLSTRING, String.utf8) + cbShare + 1;
++ pShFlShareName = RTMemAllocZ(cbShFlShareName);
++ if (!pShFlShareName)
++ return VERR_NO_MEMORY;
++
++ pShFlShareName->u16Length = cbShare;
++ pShFlShareName->u16Size = cbShare + 1;
++ memcpy (pShFlShareName->String.utf8, pszShare, cbShare + 1);
++
++ rc = VbglR0SfMapFolder (&g_vboxSFClient, pShFlShareName, &pShFlGlobalInfo->map);
++ RTMemFree(pShFlShareName);
++
++ if (RT_FAILURE (rc))
++ {
++ RTMemFree(pShFlGlobalInfo);
++ printf("VbglR0SfMapFolder failed rc=%d\n", rc);
++ return EPROTO;
++ }
++
++ pShFlGlobalInfo->uid = uid;
++ pShFlGlobalInfo->gid = gid;
++
++ mp->mnt_data = pShFlGlobalInfo;
++
++ /* @todo root vnode. */
++
++ vfs_getnewfsid(mp);
++ vfs_mountedfrom(mp, pszShare);
++
++ printf("%s: Leave rc=0\n", __FUNCTION__);
++
++ return 0;
++}
++
++static int vboxvfs_unmount(struct mount *mp, int mntflags, struct thread *td)
++{
++ struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp);
++ int rc;
++ int flags = 0;
++
++ rc = VbglR0SfUnmapFolder(&g_vboxSFClient, &pShFlGlobalInfo->map);
++ if (RT_FAILURE(rc))
++ printf("Failed to unmap shared folder\n");
++
++ if (mntflags & MNT_FORCE)
++ flags |= FORCECLOSE;
++
++ /* There is 1 extra root vnode reference (vnode_root). */
++ rc = vflush(mp, 1, flags, td);
++ if (rc)
++ return rc;
++
++
++ RTMemFree(pShFlGlobalInfo);
++ mp->mnt_data = NULL;
++
++ return 0;
++}
++
++static int vboxvfs_root(struct mount *mp, int flags, struct vnode **vpp, struct thread *td)
++{
++ int rc = 0;
++ struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp);
++ struct vnode *vp;
++
++ printf("%s: Enter\n", __FUNCTION__);
++
++ vp = pShFlGlobalInfo->vnode_root;
++ VREF(vp);
++
++ vn_lock(vp, flags | LK_RETRY, td);
++ *vpp = vp;
++
++ printf("%s: Leave\n", __FUNCTION__);
++
++ return rc;
++}
++
++static int vboxvfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg, struct thread *td)
++{
++ return EOPNOTSUPP;
++}
++
++int vboxvfs_init(struct vfsconf *vfsp)
++{
++ int rc;
++
++ /* Initialize the R0 guest library. */
++ rc = VbglR0SfInit();
++ if (RT_FAILURE(rc))
++ return ENXIO;
++
++ /* 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;
++ }
++
++ rc = VbglR0SfSetUtf8(&g_vboxSFClient);
++ if (RT_FAILURE (rc))
++ {
++ printf("VbglR0SfSetUtf8 failed, rc=%d\n", rc);
++ VbglR0SfDisconnect(&g_vboxSFClient);
++ VbglR0SfTerm();
++ return EPROTO;
++ }
++
++ printf("Successfully loaded shared folder module\n");
++
++ return 0;
++}
++
++int vboxvfs_uninit(struct vfsconf *vfsp)
++{
++ VbglR0SfDisconnect(&g_vboxSFClient);
++ VbglR0SfTerm();
++
++ return 0;
++}
++
++int vboxvfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
++{
++ return 0;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs__vnops.c b/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs__vnops.c
new file mode 100644
index 0000000..977ca9f
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Additions_netbsd_vboxvfs_vboxvfs__vnops.c
@@ -0,0 +1,246 @@
+$NetBSD$
+
+--- src/VBox/Additions/netbsd/vboxvfs/vboxvfs_vnops.c.orig 2016-07-06 19:39:01.675503997 +0000
++++ src/VBox/Additions/netbsd/vboxvfs/vboxvfs_vnops.c
+@@ -0,0 +1,241 @@
++/* vboxvfs_vnops.c $ */
++/** @file
++ * Description.
++ */
++
++/*
++ * Copyright (C) 2008-2010 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.
++ */
++
++#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/bio.h>
++#include <sys/buf.h>
++#include <sys/fcntl.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 <vm/vm.h>
++#include <vm/vm_extern.h>
++
++/*
++ * 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;
++
++struct vop_vector vboxvfs_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,
++};
++
++static int vboxvfs_access(struct vop_access_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_open(struct vop_open_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_close(struct vop_close_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_getattr(struct vop_getattr_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_setattr(struct vop_setattr_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_read(struct vop_read_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_write(struct vop_write_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_create(struct vop_create_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_remove(struct vop_remove_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_rename(struct vop_rename_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_link(struct vop_link_args *ap)
++{
++ return EOPNOTSUPP;
++}
++
++static int vboxvfs_symlink(struct vop_symlink_args *ap)
++{
++ return EOPNOTSUPP;
++}
++
++static int vboxvfs_mknod(struct vop_mknod_args *ap)
++{
++ return EOPNOTSUPP;
++}
++
++static int vboxvfs_mkdir(struct vop_mkdir_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_rmdir(struct vop_rmdir_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_readdir(struct vop_readdir_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_fsync(struct vop_fsync_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_print (struct vop_print_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_pathconf (struct vop_pathconf_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_strategy (struct vop_strategy_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_ioctl(struct vop_ioctl_args *ap)
++{
++ return ENOTTY;
++}
++
++static int vboxvfs_getextattr(struct vop_getextattr_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_advlock(struct vop_advlock_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_lookup(struct vop_lookup_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_inactive(struct vop_inactive_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_reclaim(struct vop_reclaim_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_getpages(struct vop_getpages_args *ap)
++{
++ return 0;
++}
++
++static int vboxvfs_putpages(struct vop_putpages_args *ap)
++{
++ return 0;
++}
++
diff --git a/virtualbox/patches/patch-src_VBox_Debugger_DBGPlugInDiggers.cpp b/virtualbox/patches/patch-src_VBox_Debugger_DBGPlugInDiggers.cpp
new file mode 100644
index 0000000..abf73f1
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Debugger_DBGPlugInDiggers.cpp
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/VBox/Debugger/DBGPlugInDiggers.cpp.orig 2016-03-04 19:25:46.000000000 +0000
++++ src/VBox/Debugger/DBGPlugInDiggers.cpp
+@@ -33,6 +33,7 @@ DECLEXPORT(int) DbgPlugInEntry(DBGFPLUGI
+ {
+ &g_DBGDiggerDarwin,
+ //&g_DBGDiggerFreeBSD,
++ //&g_DBGDiggerNetBSD,
+ &g_DBGDiggerLinux,
+ &g_DBGDiggerOS2,
+ &g_DBGDiggerSolaris,
+@@ -74,4 +75,3 @@ DECLEXPORT(int) DbgPlugInEntry(DBGFPLUGI
+ return VERR_NOT_SUPPORTED;
+ }
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Debugger_DBGPlugIns.h b/virtualbox/patches/patch-src_VBox_Debugger_DBGPlugIns.h
new file mode 100644
index 0000000..790957a
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Debugger_DBGPlugIns.h
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/VBox/Debugger/DBGPlugIns.h.orig 2016-03-04 19:25:46.000000000 +0000
++++ src/VBox/Debugger/DBGPlugIns.h
+@@ -26,6 +26,7 @@
+ RT_C_DECLS_BEGIN
+
+ //extern const DBGFOSREG g_DBGDiggerFreeBSD;
++//extern const DBGFOSREG g_DBGDiggerNetBSD;
+ extern const DBGFOSREG g_DBGDiggerDarwin;
+ extern const DBGFOSREG g_DBGDiggerLinux;
+ extern const DBGFOSREG g_DBGDiggerOS2;
+@@ -35,4 +36,3 @@ extern const DBGFOSREG g_DBGDiggerWinNt;
+ RT_C_DECLS_END
+
+ #endif
+-
diff --git a/virtualbox/patches/patch-src_VBox_Devices_EFI_Firmware_AppPkg_Applications_Python_PyMod-2.7.1_Include_pyport.h b/virtualbox/patches/patch-src_VBox_Devices_EFI_Firmware_AppPkg_Applications_Python_PyMod-2.7.1_Include_pyport.h
new file mode 100644
index 0000000..7f97048
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_EFI_Firmware_AppPkg_Applications_Python_PyMod-2.7.1_Include_pyport.h
@@ -0,0 +1,23 @@
+$NetBSD$
+
+--- src/VBox/Devices/EFI/Firmware/AppPkg/Applications/Python/PyMod-2.7.1/Include/pyport.h.orig 2016-03-04 19:25:48.000000000 +0000
++++ src/VBox/Devices/EFI/Firmware/AppPkg/Applications/Python/PyMod-2.7.1/Include/pyport.h
+@@ -455,7 +455,7 @@ extern "C" {
+ * This isn't reliable. See Py_OVERFLOWED comments.
+ * X is evaluated more than once.
+ */
+-#if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
++#if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64)) || defined(__NetBSD__)
+ #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
+ #else
+ #define _Py_SET_EDOM_FOR_NAN(X) ;
+@@ -671,6 +671,9 @@ extern int fdatasync(int);
+ #endif
+ #endif
+
++#ifdef __NetBSD__
++# define _PY_PORT_CTYPE_UTF8_ISSUE
++#endif
+
+ #if defined(__APPLE__)
+ # define _PY_PORT_CTYPE_UTF8_ISSUE
diff --git a/virtualbox/patches/patch-src_VBox_Devices_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Devices_Makefile.kmk
new file mode 100644
index 0000000..7de2d5b
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_Makefile.kmk
@@ -0,0 +1,69 @@
+$NetBSD$
+
+--- src/VBox/Devices/Makefile.kmk.orig 2016-03-04 19:27:54.000000000 +0000
++++ src/VBox/Devices/Makefile.kmk
+@@ -185,7 +185,7 @@ if !defined(VBOX_ONLY_EXTPACKS)
+ ifn1of ($(KBUILD_TARGET), os2)
+ VBoxDD_SOURCES += Storage/DrvHostDVD.cpp
+ endif
+- ifn1of ($(KBUILD_TARGET), darwin freebsd os2 solaris)
++ ifn1of ($(KBUILD_TARGET), darwin freebsd os2 solaris netbsd)
+ VBoxDD_SOURCES += Storage/DrvHostFloppy.cpp
+ endif
+
+@@ -350,6 +350,11 @@ if !defined(VBOX_ONLY_EXTPACKS)
+ USB/USBProxyDevice.cpp \
+ USB/freebsd/USBProxyDevice-freebsd.cpp
+
++ VBoxDD_DEFS.netbsd += VUSB_HAVE_USBPROXY_DEVICE
++ VBoxDD_SOURCES.netbsd+= \
++ USB/USBProxyDevice.cpp \
++ USB/netbsd/USBProxyDevice-netbsd.cpp
++
+ ifdef VBOX_WITH_SCSI
+ VBoxDD_SOURCES += \
+ Storage/UsbMsd.cpp
+@@ -575,6 +580,17 @@ if !defined(VBOX_ONLY_EXTPACKS)
+ endif
+ endif
+
++ ifeq ($(KBUILD_TARGET),netbsd)
++ VBoxDD_SOURCES += \
++ Audio/DrvHostOSSAudio.cpp
++ ifdef VBOX_WITH_PULSE
++ VBoxDD_DEFS += VBOX_WITH_PULSE
++ VBoxDD_SOURCES += \
++ Audio/DrvHostPulseAudio.cpp \
++ Audio/pulse_stubs.c
++ endif
++ endif
++
+ ifeq ($(KBUILD_TARGET),solaris)
+ ifdef VBOX_WITH_SOLARIS_OSS
+ VBoxDD_SOURCES += Audio/DrvHostOSSAudio.cpp
+@@ -701,6 +717,11 @@ if !defined(VBOX_ONLY_EXTPACKS)
+ VBoxDD_SOURCES.freebsd += Network/DrvTAP.cpp
+ endif # freebsd
+
++ ifeq ($(KBUILD_TARGET),netbsd)
++ VBoxDD_SOURCES += Serial/DrvHostSerial.cpp
++ VBoxDD_SOURCES.netbsd += Network/DrvTAP.cpp
++ endif # netbsd
++
+ VBoxDD_SOURCES.linux += \
+ Network/DrvTAP.cpp \
+ Parallel/DrvHostParallel.cpp \
+@@ -1414,7 +1435,7 @@ if defined(VBOX_WITH_VMSVGA3D) && !defin
+ Graphics/shaderlib/libWineStub/debug.c
+ VBoxSVGA3D_LIBS = $(LIB_RUNTIME)
+ VBoxSVGA3D_LIBS.win += $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/Opengl32.lib
+- if1of ($(KBUILD_TARGET), solaris linux freebsd)
++ if1of ($(KBUILD_TARGET), solaris linux freebsd netbsd)
+ VBoxSVGA3D_LIBS += GL
+ endif
+ VBoxSVGA3D_LDFLAGS.darwin += \
+@@ -1453,4 +1474,3 @@ if defined(VBOX_WITH_VMSVGA3D) && !defin
+ endif # defined(VBOX_WITH_VMSVGA3D) && !defined(VBOX_ONLY_EXTPACKS)
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_Devices_Network_DrvNAT.cpp b/virtualbox/patches/patch-src_VBox_Devices_Network_DrvNAT.cpp
new file mode 100644
index 0000000..5845ef8
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_Network_DrvNAT.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Devices/Network/DrvNAT.cpp.orig 2016-03-04 19:27:54.000000000 +0000
++++ src/VBox/Devices/Network/DrvNAT.cpp
+@@ -51,7 +51,7 @@ extern "C" {
+ # include <poll.h>
+ # include <errno.h>
+ #endif
+-#ifdef RT_OS_FREEBSD
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <netinet/in.h>
+ #endif
+ #include <iprt/semaphore.h>
+@@ -1752,4 +1752,3 @@ const PDMDRVREG g_DrvNAT =
+ /* u32EndVersion */
+ PDM_DRVREG_VERSION
+ };
+-
diff --git a/virtualbox/patches/patch-src_VBox_Devices_Network_slirp_resolv__conf__parser.c b/virtualbox/patches/patch-src_VBox_Devices_Network_slirp_resolv__conf__parser.c
new file mode 100644
index 0000000..b453b24
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_Network_slirp_resolv__conf__parser.c
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/Devices/Network/slirp/resolv_conf_parser.c.orig 2016-03-04 19:27:59.000000000 +0000
++++ src/VBox/Devices/Network/slirp/resolv_conf_parser.c
+@@ -22,7 +22,7 @@
+ #include <iprt/stream.h>
+ #include <iprt/thread.h>
+
+-#ifdef RT_OS_FREEBSD
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <sys/socket.h>
+ #endif
+
diff --git a/virtualbox/patches/patch-src_VBox_Devices_Network_slirp_udp.c b/virtualbox/patches/patch-src_VBox_Devices_Network_slirp_udp.c
new file mode 100644
index 0000000..c2e058e
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_Network_slirp_udp.c
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/Devices/Network/slirp/udp.c.orig 2016-03-04 19:28:00.000000000 +0000
++++ src/VBox/Devices/Network/slirp/udp.c
+@@ -327,7 +327,7 @@ udp_input(PNATState pData, register stru
+ const char * const dfoptname = #_Optname;
+ #if defined(IP_MTU_DISCOVER)
+ USE_DF_OPTION(IP_MTU_DISCOVER);
+-#elif defined(IP_DONTFRAG) /* Solaris 11+, FreeBSD */
++#elif defined(IP_DONTFRAG) /* Solaris 11+, FreeBSD, NetBSD */
+ USE_DF_OPTION(IP_DONTFRAG);
+ #elif defined(IP_DONTFRAGMENT) /* Windows */
+ USE_DF_OPTION(IP_DONTFRAGMENT);
diff --git a/virtualbox/patches/patch-src_VBox_Devices_PC_DrvACPI.cpp b/virtualbox/patches/patch-src_VBox_Devices_PC_DrvACPI.cpp
new file mode 100644
index 0000000..5ca33d6
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_PC_DrvACPI.cpp
@@ -0,0 +1,24 @@
+$NetBSD$
+
+--- src/VBox/Devices/PC/DrvACPI.cpp.orig 2016-03-04 19:28:01.000000000 +0000
++++ src/VBox/Devices/PC/DrvACPI.cpp
+@@ -45,7 +45,7 @@
+ # include <IOKit/ps/IOPSKeys.h>
+ #endif
+
+-#ifdef RT_OS_FREEBSD
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <sys/ioctl.h>
+ # include <dev/acpica/acpiio.h>
+ # include <sys/types.h>
+@@ -221,6 +221,10 @@ static DECLCALLBACK(int) drvACPIQueryPow
+ AssertMsg(errno == ENOENT, ("rc=%d (%s)\n", rc, strerror(errno)));
+ *pPowerSource = PDM_ACPI_POWER_SOURCE_OUTLET;
+ }
++
++#elif defined(RT_OS_NETBSD)
++ // TODO
++ *pPowerSource = PDM_ACPI_POWER_SOURCE_OUTLET;
+ #else /* !RT_OS_FREEBSD either - what could this be? */
+ *pPowerSource = PDM_ACPI_POWER_SOURCE_OUTLET;
+
diff --git a/virtualbox/patches/patch-src_VBox_Devices_Serial_DrvHostSerial.cpp b/virtualbox/patches/patch-src_VBox_Devices_Serial_DrvHostSerial.cpp
new file mode 100644
index 0000000..78cc37c
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_Serial_DrvHostSerial.cpp
@@ -0,0 +1,135 @@
+$NetBSD$
+
+--- src/VBox/Devices/Serial/DrvHostSerial.cpp.orig 2016-03-04 19:28:24.000000000 +0000
++++ src/VBox/Devices/Serial/DrvHostSerial.cpp
+@@ -33,7 +33,7 @@
+ #include <iprt/semaphore.h>
+ #include <iprt/uuid.h>
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <errno.h>
+ # ifdef RT_OS_SOLARIS
+ # include <sys/termios.h>
+@@ -101,7 +101,7 @@ typedef struct DRVHOSTSERIAL
+ /** the device path */
+ char *pszDevicePath;
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /** the device handle */
+ RTFILE hDeviceFile;
+ # ifdef RT_OS_DARWIN
+@@ -194,7 +194,7 @@ static DECLCALLBACK(int) drvHostSerialWr
+ static DECLCALLBACK(int) drvHostSerialSetParameters(PPDMICHARCONNECTOR pInterface, unsigned Bps, char chParity, unsigned cDataBits, unsigned cStopBits)
+ {
+ PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ struct termios *termiosSetup;
+ int baud_rate;
+ #elif defined(RT_OS_WINDOWS)
+@@ -482,7 +482,7 @@ static DECLCALLBACK(int) drvHostSerialSe
+ {
+ /* copy the send queue so we get a linear buffer with the maximal size. */
+ uint8_t ch = pThis->u8SendByte;
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+
+ size_t cbWritten;
+ rc = RTFileWrite(pThis->hDeviceFile, &ch, 1, &cbWritten);
+@@ -679,7 +679,7 @@ static DECLCALLBACK(int) drvHostSerialRe
+ }
+ cbRemaining = cbRead;
+
+-#elif defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+
+ size_t cbRead;
+ struct pollfd aFDs[2];
+@@ -865,7 +865,7 @@ static DECLCALLBACK(int) drvHostSerialRe
+ static DECLCALLBACK(int) drvHostSerialWakeupRecvThread(PPDMDRVINS pDrvIns, PPDMTHREAD /*pThread*/)
+ {
+ PDRVHOSTSERIAL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTSERIAL);
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ size_t cbIgnored;
+ return RTPipeWrite(pThis->hWakeupPipeW, "", 1, &cbIgnored);
+
+@@ -878,7 +878,7 @@ static DECLCALLBACK(int) drvHostSerialWa
+ #endif
+ }
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /* -=-=-=-=- Monitor thread -=-=-=-=- */
+
+ /**
+@@ -998,7 +998,7 @@ static DECLCALLBACK(int) drvHostSerialSe
+ {
+ PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ int modemStateSet = 0;
+ int modemStateClear = 0;
+
+@@ -1046,7 +1046,7 @@ static DECLCALLBACK(int) drvHostSerialSe
+ {
+ PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ if (fBreak)
+ ioctl(RTFileToNative(pThis->hDeviceFile), TIOCSBRK);
+ else
+@@ -1085,7 +1085,7 @@ static DECLCALLBACK(void) drvHostSerialD
+ pThis->SendSem = NIL_RTSEMEVENT;
+ }
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+
+ int rc = RTPipeClose(pThis->hWakeupPipeW); AssertRC(rc);
+ pThis->hWakeupPipeW = NIL_RTPIPE;
+@@ -1138,7 +1138,7 @@ static DECLCALLBACK(int) drvHostSerialCo
+ /*
+ * Init basic data members and interfaces.
+ */
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ pThis->hDeviceFile = NIL_RTFILE;
+ # ifdef RT_OS_DARWIN
+ pThis->hDeviceFileR = NIL_RTFILE;
+@@ -1233,7 +1233,7 @@ static DECLCALLBACK(int) drvHostSerialCo
+ {
+ case VERR_ACCESS_DENIED:
+ return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ N_("Cannot open host device '%s' for read/write access. Check the permissions "
+ "of that device ('/bin/ls -l %s'): Most probably you need to be member "
+ "of the device group. Make sure that you logout/login after changing "
+@@ -1251,7 +1251,7 @@ static DECLCALLBACK(int) drvHostSerialCo
+ }
+
+ /* Set to non blocking I/O */
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+
+ fcntl(RTFileToNative(pThis->hDeviceFile), F_SETFL, O_NONBLOCK);
+ # ifdef RT_OS_DARWIN
+@@ -1296,7 +1296,7 @@ static DECLCALLBACK(int) drvHostSerialCo
+ if (RT_FAILURE(rc))
+ return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create send thread"), pDrvIns->iInstance);
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /* Linux & darwin needs a separate thread which monitors the status lines. */
+ # ifndef RT_OS_LINUX
+ ioctl(RTFileToNative(pThis->hDeviceFile), TIOCMGET, &pThis->fStatusLines);
+@@ -1368,4 +1368,3 @@ const PDMDRVREG g_DrvHostSerial =
+ /* u32EndVersion */
+ PDM_DRVREG_VERSION
+ };
+-
diff --git a/virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostBase.cpp b/virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostBase.cpp
new file mode 100644
index 0000000..4bc3fe1
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostBase.cpp
@@ -0,0 +1,89 @@
+$NetBSD$
+
+--- src/VBox/Devices/Storage/DrvHostBase.cpp.orig 2016-03-04 19:28:24.000000000 +0000
++++ src/VBox/Devices/Storage/DrvHostBase.cpp
+@@ -96,7 +96,7 @@ NTSTATUS __stdcall NtQueryVolumeInformat
+ /*IN*/ ULONG Length,
+ /*IN*/ FS_INFORMATION_CLASS FileSystemInformationClass );
+
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <sys/cdefs.h>
+ # include <sys/param.h>
+ # include <errno.h>
+@@ -147,14 +147,14 @@ static DECLCALLBACK(int) drvHostBaseRead
+ if ( pThis->fMediaPresent
+ && pThis->ppScsiTaskDI
+ && pThis->cbBlock)
+-#elif RT_OS_FREEBSD
++#elif RT_OS_FREEBSD || defined(RT_OS_NETBSD)
+ if ( pThis->fMediaPresent
+ && pThis->cbBlock)
+ #else
+ if (pThis->fMediaPresent)
+ #endif
+ {
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /*
+ * Issue a READ(12) request.
+ */
+@@ -226,7 +226,7 @@ static DECLCALLBACK(int) drvHostBaseWrit
+ {
+ if (pThis->fMediaPresent)
+ {
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /** @todo write support... */
+ rc = VERR_WRITE_PROTECT;
+
+@@ -264,7 +264,7 @@ static DECLCALLBACK(int) drvHostBaseFlus
+
+ if (pThis->fMediaPresent)
+ {
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ rc = VINF_SUCCESS;
+ /** @todo scsi device buffer flush... */
+ #else
+@@ -991,7 +991,7 @@ static int drvHostBaseOpen(PDRVHOSTBASE
+ IOObjectRelease(DVDServices);
+ return rc;
+
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ RTFILE hFileDevice;
+ int rc = RTFileOpen(&hFileDevice, pThis->pszDeviceOpen, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
+ if (RT_FAILURE(rc))
+@@ -1176,7 +1176,7 @@ static int drvHostBaseReopen(PDRVHOSTBAS
+ */
+ static DECLCALLBACK(int) drvHostBaseGetMediaSize(PDRVHOSTBASE pThis, uint64_t *pcb)
+ {
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /*
+ * Try a READ_CAPACITY command...
+ */
+@@ -1254,7 +1254,7 @@ static DECLCALLBACK(int) drvHostBaseGetM
+ }
+
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /**
+ * Execute a SCSI command.
+ *
+@@ -1365,7 +1365,7 @@ DECLCALLBACK(int) DRVHostBaseScsiCmd(PDR
+
+ (*ppScsiTaskI)->Release(ppScsiTaskI);
+
+-# elif defined(RT_OS_FREEBSD)
++# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ int rc = VINF_SUCCESS;
+ int rcBSD = 0;
+ union ccb DeviceCCB;
+@@ -2265,4 +2265,3 @@ int DRVHostBaseInitFinish(PDRVHOSTBASE p
+ return src;
+ return rc;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostBase.h b/virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostBase.h
new file mode 100644
index 0000000..69c13c4
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostBase.h
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- src/VBox/Devices/Storage/DrvHostBase.h.orig 2016-03-04 19:28:24.000000000 +0000
++++ src/VBox/Devices/Storage/DrvHostBase.h
+@@ -147,6 +147,17 @@ typedef struct DRVHOSTBASE
+ lun_id_t ScsiLunID;
+ #endif
+
++#ifdef RT_OS_NETBSD
++ /** The block size. Set when querying the media size. */
++ uint32_t cbBlock;
++ /** SCSI bus number. */
++ path_id_t ScsiBus;
++ /** target ID of the passthrough device. */
++ target_id_t ScsiTargetID;
++ /** LUN of the passthrough device. */
++ lun_id_t ScsiLunID;
++#endif
++
+ /**
+ * Performs the locking / unlocking of the device.
+ *
+@@ -185,7 +196,7 @@ int DRVHostBaseInitFinish(PDRVHOSTBASE p
+ int DRVHostBaseMediaPresent(PDRVHOSTBASE pThis);
+ void DRVHostBaseMediaNotPresent(PDRVHOSTBASE pThis);
+ DECLCALLBACK(void) DRVHostBaseDestruct(PPDMDRVINS pDrvIns);
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ DECLCALLBACK(int) DRVHostBaseScsiCmd(PDRVHOSTBASE pThis, const uint8_t *pbCmd, size_t cbCmd, PDMBLOCKTXDIR enmTxDir,
+ void *pvBuf, uint32_t *pcbBuf, uint8_t *pbSense, size_t cbSense, uint32_t cTimeoutMillies);
+ #endif
diff --git a/virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostDVD.cpp b/virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostDVD.cpp
new file mode 100644
index 0000000..5c605a3
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_Storage_DrvHostDVD.cpp
@@ -0,0 +1,63 @@
+$NetBSD$
+
+--- src/VBox/Devices/Storage/DrvHostDVD.cpp.orig 2016-03-04 19:28:24.000000000 +0000
++++ src/VBox/Devices/Storage/DrvHostDVD.cpp
+@@ -86,7 +86,7 @@
+ # undef _interlockedbittestandreset64
+ # undef USE_MEDIA_POLLING
+
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <sys/cdefs.h>
+ # include <sys/param.h>
+ # include <stdio.h>
+@@ -144,7 +144,7 @@ static DECLCALLBACK(int) drvHostDvdUnmou
+ /*
+ * Eject the disc.
+ */
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ uint8_t abCmd[16] =
+ {
+ SCSI_START_STOP_UNIT, 0, 0, 0, 2 /*eject+stop*/, 0,
+@@ -234,7 +234,7 @@ static DECLCALLBACK(int) drvHostDvdUnmou
+ */
+ static DECLCALLBACK(int) drvHostDvdDoLock(PDRVHOSTBASE pThis, bool fLock)
+ {
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ uint8_t abCmd[16] =
+ {
+ SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL, 0, 0, 0, fLock, 0,
+@@ -322,7 +322,7 @@ static DECLCALLBACK(int) drvHostDvdPoll(
+ /*
+ * Poll for media change.
+ */
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ #ifdef RT_OS_DARWIN
+ AssertReturn(pThis->ppScsiTaskDI, VERR_INTERNAL_ERROR);
+ #endif
+@@ -392,7 +392,7 @@ static DECLCALLBACK(int) drvHostDvdPoll(
+ /*
+ * Poll for media change.
+ */
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /* taken care of above. */
+ #elif defined(RT_OS_LINUX)
+ bool fMediaChanged = ioctl(RTFileToNative(pThis->hFileDevice), CDROM_MEDIA_CHANGED, CDSL_CURRENT) == 1;
+@@ -422,7 +422,7 @@ static DECLCALLBACK(int) drvHostDvdSendC
+ int rc;
+ LogFlow(("%s: cmd[0]=%#04x txdir=%d pcbBuf=%d timeout=%d\n", __FUNCTION__, pbCmd[0], enmTxDir, *pcbBuf, cTimeoutMillies));
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /*
+ * Pass the request on to the internal scsi command interface.
+ * The command seems to be 12 bytes long, the docs a bit copy&pasty on the command length point...
+@@ -878,4 +878,3 @@ const PDMDRVREG g_DrvHostDVD =
+ /* u32EndVersion */
+ PDM_DRVREG_VERSION
+ };
+-
diff --git a/virtualbox/patches/patch-src_VBox_Devices_USB_netbsd_USBProxyDevice-netbsd.cpp b/virtualbox/patches/patch-src_VBox_Devices_USB_netbsd_USBProxyDevice-netbsd.cpp
new file mode 100644
index 0000000..f00988d
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_USB_netbsd_USBProxyDevice-netbsd.cpp
@@ -0,0 +1,1066 @@
+$NetBSD$
+
+--- src/VBox/Devices/USB/netbsd/USBProxyDevice-netbsd.cpp.orig 2016-07-07 07:08:46.468615794 +0000
++++ src/VBox/Devices/USB/netbsd/USBProxyDevice-netbsd.cpp
+@@ -0,0 +1,1061 @@
++/* USBProxyDevice-netbsd.cpp $ */
++/** @file
++ * USB device proxy - the NetBSD backend.
++ */
++
++/*
++ * Includes contributions from Hans Petter Selasky
++ *
++ * Copyright (C) 2006-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#define LOG_GROUP LOG_GROUP_DRV_USBPROXY
++#ifdef VBOX
++# include <iprt/stdint.h>
++#endif
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <sys/ioctl.h>
++#include <sys/poll.h>
++#include <stdint.h>
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++#include <limits.h>
++#include <unistd.h>
++#include <fcntl.h>
++#include <errno.h>
++#include <dev/usb/usb.h>
++#include <dev/usb/usbdi.h>
++#include <dev/usb/usb_ioctl.h>
++
++#include <VBox/vmm/pdm.h>
++#include <VBox/err.h>
++#include <VBox/log.h>
++#include <VBox/vusb.h>
++#include <iprt/assert.h>
++#include <iprt/stream.h>
++#include <iprt/alloc.h>
++#include <iprt/thread.h>
++#include <iprt/time.h>
++#include <iprt/asm.h>
++#include <iprt/string.h>
++#include <iprt/file.h>
++#include <iprt/pipe.h>
++#include "../USBProxyDevice.h"
++
++/** Maximum endpoints supported. */
++#define USBFBSD_MAXENDPOINTS 127
++#define USBFBSD_MAXFRAMES 56
++
++/** This really needs to be defined in vusb.h! */
++#ifndef VUSB_DIR_TO_DEV
++# define VUSB_DIR_TO_DEV 0x00
++#endif
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++typedef struct USBENDPOINTFBSD
++{
++ /** Flag whether it is opened. */
++ bool fOpen;
++ /** Flag whether it is cancelling. */
++ bool fCancelling;
++ /** Buffer pointers. */
++ void *apvData[USBFBSD_MAXFRAMES];
++ /** Buffer lengths. */
++ uint32_t acbData[USBFBSD_MAXFRAMES];
++ /** Initial buffer length. */
++ uint32_t cbData0;
++ /** Pointer to the URB. */
++ PVUSBURB pUrb;
++ /** Copy of endpoint number. */
++ unsigned iEpNum;
++ /** Maximum transfer length. */
++ unsigned cMaxIo;
++ /** Maximum frame count. */
++ unsigned cMaxFrames;
++} USBENDPOINTFBSD, *PUSBENDPOINTFBSD;
++
++/**
++ * Data for the NetBSD usb proxy backend.
++ */
++typedef struct USBPROXYDEVFBSD
++{
++ /** The open file. */
++ RTFILE hFile;
++ /** Flag whether an URB is cancelling. */
++ bool fCancelling;
++ /** Flag whether initialised or not */
++ bool fInit;
++ /** Pipe handle for waking up - writing end. */
++ RTPIPE hPipeWakeupW;
++ /** Pipe handle for waking up - reading end. */
++ RTPIPE hPipeWakeupR;
++ /** Software endpoint structures */
++ USBENDPOINTFBSD aSwEndpoint[USBFBSD_MAXENDPOINTS];
++ /** Kernel endpoint structures */
++ struct usb_fs_endpoint aHwEndpoint[USBFBSD_MAXENDPOINTS];
++} USBPROXYDEVFBSD, *PUSBPROXYDEVFBSD;
++
++
++/*********************************************************************************************************************************
++* Internal Functions *
++*********************************************************************************************************************************/
++static int usbProxyNetBSDEndpointClose(PUSBPROXYDEV pProxyDev, int Endpoint);
++
++/**
++ * Wrapper for the ioctl call.
++ *
++ * This wrapper will repeat the call if we get an EINTR or EAGAIN. It can also
++ * handle ENODEV (detached device) errors.
++ *
++ * @returns whatever ioctl returns.
++ * @param pProxyDev The proxy device.
++ * @param iCmd The ioctl command / function.
++ * @param pvArg The ioctl argument / data.
++ * @param fHandleNoDev Whether to handle ENXIO.
++ * @internal
++ */
++static int usbProxyNetBSDDoIoCtl(PUSBPROXYDEV pProxyDev, unsigned long iCmd,
++ void *pvArg, bool fHandleNoDev)
++{
++ int rc = VINF_SUCCESS;
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++
++ LogFlow(("usbProxyNetBSDDoIoCtl: iCmd=%#x\n", iCmd));
++
++ do
++ {
++ rc = ioctl(RTFileToNative(pDevFBSD->hFile), iCmd, pvArg);
++ if (rc >= 0)
++ return VINF_SUCCESS;
++ } while (errno == EINTR);
++
++ if (errno == ENXIO && fHandleNoDev)
++ {
++ Log(("usbProxyNetBSDDoIoCtl: ENXIO -> unplugged. pProxyDev=%s\n",
++ pProxyDev->pUsbIns->pszName));
++ errno = ENODEV;
++ }
++ else if (errno != EAGAIN)
++ {
++ LogFlow(("usbProxyNetBSDDoIoCtl: Returned %d. pProxyDev=%s\n",
++ errno, pProxyDev->pUsbIns->pszName));
++ }
++ return RTErrConvertFromErrno(errno);
++}
++
++/**
++ * Init USB subsystem.
++ */
++static int usbProxyNetBSDFsInit(PUSBPROXYDEV pProxyDev)
++{
++ struct usb_fs_init UsbFsInit;
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ int rc;
++
++ LogFlow(("usbProxyNetBSDFsInit: pProxyDev=%p\n", (void *)pProxyDev));
++
++ /* Sanity check */
++ AssertPtrReturn(pDevFBSD, VERR_INVALID_PARAMETER);
++
++ if (pDevFBSD->fInit == true)
++ return VINF_SUCCESS;
++
++ /* Zero default */
++ memset(&UsbFsInit, 0, sizeof(UsbFsInit));
++
++ UsbFsInit.pEndpoints = pDevFBSD->aHwEndpoint;
++ UsbFsInit.ep_index_max = USBFBSD_MAXENDPOINTS;
++
++ /* Init USB subsystem */
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_FS_INIT, &UsbFsInit, false);
++ if (RT_SUCCESS(rc))
++ pDevFBSD->fInit = true;
++
++ return rc;
++}
++
++/**
++ * Uninit USB subsystem.
++ */
++static int usbProxyNetBSDFsUnInit(PUSBPROXYDEV pProxyDev)
++{
++ struct usb_fs_uninit UsbFsUninit;
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ int rc;
++
++ LogFlow(("usbProxyNetBSDFsUnInit: ProxyDev=%p\n", (void *)pProxyDev));
++
++ /* Sanity check */
++ AssertPtrReturn(pDevFBSD, VERR_INVALID_PARAMETER);
++
++ if (pDevFBSD->fInit != true)
++ return VINF_SUCCESS;
++
++ /* Close any open endpoints. */
++ for (unsigned n = 0; n != USBFBSD_MAXENDPOINTS; n++)
++ usbProxyNetBSDEndpointClose(pProxyDev, n);
++
++ /* Zero default */
++ memset(&UsbFsUninit, 0, sizeof(UsbFsUninit));
++
++ /* Uninit USB subsystem */
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_FS_UNINIT, &UsbFsUninit, false);
++ if (RT_SUCCESS(rc))
++ pDevFBSD->fInit = false;
++
++ return rc;
++}
++
++/**
++ * Setup a USB request packet.
++ */
++static void usbProxyNetBSDSetupReq(struct usb_device_request *pSetupData,
++ uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue,
++ uint16_t wIndex, uint16_t wLength)
++{
++ LogFlow(("usbProxyNetBSDSetupReq: pSetupData=%p bmRequestType=%x "
++ "bRequest=%x wValue=%x wIndex=%x wLength=%x\n", (void *)pSetupData,
++ bmRequestType, bRequest, wValue, wIndex, wLength));
++
++ pSetupData->bmRequestType = bmRequestType;
++ pSetupData->bRequest = bRequest;
++
++ /* Handle endianess here. Currently no swapping is needed. */
++ pSetupData->wValue[0] = wValue & 0xff;
++ pSetupData->wValue[1] = (wValue >> 8) & 0xff;
++ pSetupData->wIndex[0] = wIndex & 0xff;
++ pSetupData->wIndex[1] = (wIndex >> 8) & 0xff;
++ pSetupData->wLength[0] = wLength & 0xff;
++ pSetupData->wLength[1] = (wLength >> 8) & 0xff;
++}
++
++static int usbProxyNetBSDEndpointOpen(PUSBPROXYDEV pProxyDev, int Endpoint, bool fIsoc, int index)
++{
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ PUSBENDPOINTFBSD pEndpointFBSD = NULL; /* shut up gcc */
++ struct usb_fs_endpoint *pXferEndpoint;
++ struct usb_fs_open UsbFsOpen;
++ int rc;
++
++ LogFlow(("usbProxyNetBSDEndpointOpen: pProxyDev=%p Endpoint=%d\n",
++ (void *)pProxyDev, Endpoint));
++
++ for (; index < USBFBSD_MAXENDPOINTS; index++)
++ {
++ pEndpointFBSD = &pDevFBSD->aSwEndpoint[index];
++ if (pEndpointFBSD->fCancelling)
++ continue;
++ if ( pEndpointFBSD->fOpen
++ && !pEndpointFBSD->pUrb
++ && (int)pEndpointFBSD->iEpNum == Endpoint)
++ return index;
++ }
++
++ if (index == USBFBSD_MAXENDPOINTS)
++ {
++ for (index = 0; index != USBFBSD_MAXENDPOINTS; index++)
++ {
++ pEndpointFBSD = &pDevFBSD->aSwEndpoint[index];
++ if (pEndpointFBSD->fCancelling)
++ continue;
++ if (!pEndpointFBSD->fOpen)
++ break;
++ }
++ if (index == USBFBSD_MAXENDPOINTS)
++ return -1;
++ }
++ /* set ppBuffer and pLength */
++
++ pXferEndpoint = &pDevFBSD->aHwEndpoint[index];
++ pXferEndpoint->ppBuffer = &pEndpointFBSD->apvData[0];
++ pXferEndpoint->pLength = &pEndpointFBSD->acbData[0];
++
++ LogFlow(("usbProxyNetBSDEndpointOpen: ep_index=%d ep_num=%d\n",
++ index, Endpoint));
++
++ memset(&UsbFsOpen, 0, sizeof(UsbFsOpen));
++
++ UsbFsOpen.ep_index = index;
++ UsbFsOpen.ep_no = Endpoint;
++ UsbFsOpen.max_bufsize = 256 * 1024;
++ /* Hardcoded assumption about the URBs we get. */
++
++ UsbFsOpen.max_frames = fIsoc ? USBFBSD_MAXFRAMES : 2;
++
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_FS_OPEN, &UsbFsOpen, true);
++ if (RT_FAILURE(rc))
++ {
++ if (rc == VERR_RESOURCE_BUSY)
++ LogFlow(("usbProxyNetBSDEndpointOpen: EBUSY\n"));
++
++ return -1;
++ }
++ pEndpointFBSD->fOpen = true;
++ pEndpointFBSD->pUrb = NULL;
++ pEndpointFBSD->iEpNum = Endpoint;
++ pEndpointFBSD->cMaxIo = UsbFsOpen.max_bufsize;
++ pEndpointFBSD->cMaxFrames = UsbFsOpen.max_frames;
++
++ return index;
++}
++
++/**
++ * Close an endpoint.
++ *
++ * @returns VBox status code.
++ */
++static int usbProxyNetBSDEndpointClose(PUSBPROXYDEV pProxyDev, int Endpoint)
++{
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ PUSBENDPOINTFBSD pEndpointFBSD = &pDevFBSD->aSwEndpoint[Endpoint];
++ struct usb_fs_close UsbFsClose;
++ int rc = VINF_SUCCESS;
++
++ LogFlow(("usbProxyNetBSDEndpointClose: pProxyDev=%p Endpoint=%d\n",
++ (void *)pProxyDev, Endpoint));
++
++ /* check for cancelling */
++ if (pEndpointFBSD->pUrb != NULL)
++ {
++ pEndpointFBSD->fCancelling = true;
++ pDevFBSD->fCancelling = true;
++ }
++
++ /* check for opened */
++ if (pEndpointFBSD->fOpen)
++ {
++ pEndpointFBSD->fOpen = false;
++
++ /* Zero default */
++ memset(&UsbFsClose, 0, sizeof(UsbFsClose));
++
++ /* Set endpoint index */
++ UsbFsClose.ep_index = Endpoint;
++
++ /* Close endpoint */
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_FS_CLOSE, &UsbFsClose, true);
++ }
++ return rc;
++}
++
++/**
++ * Opens the device file.
++ *
++ * @returns VBox status code.
++ * @param pProxyDev The device instance.
++ * @param pszAddress If we are using usbfs, this is the path to the
++ * device. If we are using sysfs, this is a string of
++ * the form "sysfs:<sysfs path>//device:<device node>".
++ * In the second case, the two paths are guaranteed
++ * not to contain the substring "//".
++ * @param pvBackend Backend specific pointer, unused for the linux backend.
++ */
++static DECLCALLBACK(int) usbProxyNetBSDOpen(PUSBPROXYDEV pProxyDev, const char *pszAddress,
++ void *pvBackend)
++{
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ int rc;
++
++ LogFlow(("usbProxyNetBSDOpen: pProxyDev=%p pszAddress=%s\n", pProxyDev, pszAddress));
++
++ NOREF(pvBackend);
++
++ /*
++ * Try open the device node.
++ */
++ RTFILE hFile;
++ rc = RTFileOpen(&hFile, pszAddress, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
++ if (RT_SUCCESS(rc))
++ {
++ /*
++ * Initialize the NetBSD backend data.
++ */
++ pDevFBSD->hFile = hFile;
++ rc = usbProxyNetBSDFsInit(pProxyDev);
++ if (RT_SUCCESS(rc))
++ {
++ /*
++ * Create wakeup pipe.
++ */
++ rc = RTPipeCreate(&pDevFBSD->hPipeWakeupR, &pDevFBSD->hPipeWakeupW, 0);
++ if (RT_SUCCESS(rc))
++ {
++ LogFlow(("usbProxyNetBSDOpen(%p, %s): returns successfully hFile=%RTfile iActiveCfg=%d\n",
++ pProxyDev, pszAddress, pDevFBSD->hFile, pProxyDev->iActiveCfg));
++
++ return VINF_SUCCESS;
++ }
++ }
++
++ RTFileClose(hFile);
++ }
++ else if (rc == VERR_ACCESS_DENIED)
++ rc = VERR_VUSB_USBFS_PERMISSION;
++
++ Log(("usbProxyNetBSDOpen(%p, %s) failed, rc=%d!\n",
++ pProxyDev, pszAddress, rc));
++
++ return rc;
++}
++
++
++/**
++ * Claims all the interfaces and figures out the
++ * current configuration.
++ *
++ * @returns VINF_SUCCESS.
++ * @param pProxyDev The proxy device.
++ */
++static DECLCALLBACK(int) usbProxyNetBSDInit(PUSBPROXYDEV pProxyDev)
++{
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ int rc;
++
++ LogFlow(("usbProxyNetBSDInit: pProxyDev=%s\n",
++ pProxyDev->pUsbIns->pszName));
++
++ /* Retrieve current active configuration. */
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_GET_CONFIG,
++ &pProxyDev->iActiveCfg, true);
++ if (RT_FAILURE(rc) || pProxyDev->iActiveCfg == 255)
++ {
++ pProxyDev->cIgnoreSetConfigs = 0;
++ pProxyDev->iActiveCfg = -1;
++ }
++ else
++ {
++ pProxyDev->cIgnoreSetConfigs = 1;
++ pProxyDev->iActiveCfg++;
++ }
++
++ Log(("usbProxyNetBSDInit: iActiveCfg=%d\n", pProxyDev->iActiveCfg));
++
++ return rc;
++}
++
++/**
++ * Closes the proxy device.
++ */
++static DECLCALLBACK(void) usbProxyNetBSDClose(PUSBPROXYDEV pProxyDev)
++{
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++
++ LogFlow(("usbProxyNetBSDClose: pProxyDev=%s\n", pProxyDev->pUsbIns->pszName));
++
++ /* sanity check */
++ AssertPtrReturnVoid(pDevFBSD);
++
++ usbProxyNetBSDFsUnInit(pProxyDev);
++
++ RTPipeClose(pDevFBSD->hPipeWakeupR);
++ RTPipeClose(pDevFBSD->hPipeWakeupW);
++
++ RTFileClose(pDevFBSD->hFile);
++ pDevFBSD->hFile = NIL_RTFILE;
++
++ LogFlow(("usbProxyNetBSDClose: returns\n"));
++}
++
++/**
++ * Reset a device.
++ *
++ * @returns VBox status code.
++ * @param pDev The device to reset.
++ */
++static DECLCALLBACK(int) usbProxyNetBSDReset(PUSBPROXYDEV pProxyDev, bool fResetOnNetBSD)
++{
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ int iParm;
++ int rc = VINF_SUCCESS;
++
++ LogFlow(("usbProxyNetBSDReset: pProxyDev=%s\n",
++ pProxyDev->pUsbIns->pszName));
++
++ if (!fResetOnNetBSD)
++ goto done;
++
++ /* We need to release kernel ressources first. */
++ rc = usbProxyNetBSDFsUnInit(pProxyDev);
++ if (RT_FAILURE(rc))
++ goto done;
++
++ /* Resetting is only possible as super-user, ignore any failures: */
++ iParm = 0;
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_DEVICEENUMERATE, &iParm, true);
++ if (RT_FAILURE(rc))
++ {
++ /* Set the config instead of bus reset */
++ iParm = 255;
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_SET_CONFIG, &iParm, true);
++ if (RT_SUCCESS(rc))
++ {
++ iParm = 0;
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_SET_CONFIG, &iParm, true);
++ }
++ }
++ usleep(10000); /* nice it! */
++
++ /* Allocate kernel ressources again. */
++ rc = usbProxyNetBSDFsInit(pProxyDev);
++ if (RT_FAILURE(rc))
++ goto done;
++
++ /* Retrieve current active configuration. */
++ rc = usbProxyNetBSDInit(pProxyDev);
++
++done:
++ pProxyDev->cIgnoreSetConfigs = 2;
++
++ return rc;
++}
++
++/**
++ * SET_CONFIGURATION.
++ *
++ * The caller makes sure that it's not called first time after open or reset
++ * with the active interface.
++ *
++ * @returns success indicator.
++ * @param pProxyDev The device instance data.
++ * @param iCfg The configuration to set.
++ */
++static DECLCALLBACK(int) usbProxyNetBSDSetConfig(PUSBPROXYDEV pProxyDev, int iCfg)
++{
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ int iCfgIndex;
++ int rc;
++
++ LogFlow(("usbProxyNetBSDSetConfig: pProxyDev=%s cfg=%x\n",
++ pProxyDev->pUsbIns->pszName, iCfg));
++
++ /* We need to release kernel ressources first. */
++ rc = usbProxyNetBSDFsUnInit(pProxyDev);
++ if (RT_FAILURE(rc))
++ {
++ LogFlow(("usbProxyNetBSDSetInterface: Freeing kernel resources "
++ "failed failed rc=%d\n", rc));
++ return rc;
++ }
++
++ if (iCfg == 0)
++ {
++ /* Unconfigure */
++ iCfgIndex = 255;
++ }
++ else
++ {
++ /* Get the configuration index matching the value. */
++ for (iCfgIndex = 0; iCfgIndex < pProxyDev->DevDesc.bNumConfigurations; iCfgIndex++)
++ {
++ if (pProxyDev->paCfgDescs[iCfgIndex].Core.bConfigurationValue == iCfg)
++ break;
++ }
++
++ if (iCfgIndex == pProxyDev->DevDesc.bNumConfigurations)
++ {
++ LogFlow(("usbProxyNetBSDSetConfig: configuration "
++ "%d not found\n", iCfg));
++ return VERR_NOT_FOUND;
++ }
++ }
++
++ /* Set the config */
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_SET_CONFIG, &iCfgIndex, true);
++ if (RT_FAILURE(rc))
++ return rc;
++
++ /* Allocate kernel ressources again. */
++ return usbProxyNetBSDFsInit(pProxyDev);
++}
++
++/**
++ * Claims an interface.
++ * @returns success indicator.
++ */
++static DECLCALLBACK(int) usbProxyNetBSDClaimInterface(PUSBPROXYDEV pProxyDev, int iIf)
++{
++ int rc;
++
++ LogFlow(("usbProxyNetBSDClaimInterface: pProxyDev=%s "
++ "ifnum=%x\n", pProxyDev->pUsbIns->pszName, iIf));
++
++ /*
++ * Try to detach kernel driver on this interface, ignore any
++ * failures
++ */
++ usbProxyNetBSDDoIoCtl(pProxyDev, USB_IFACE_DRIVER_DETACH, &iIf, true);
++
++ /* Try to claim interface */
++ return usbProxyNetBSDDoIoCtl(pProxyDev, USB_CLAIM_INTERFACE, &iIf, true);
++}
++
++/**
++ * Releases an interface.
++ * @returns success indicator.
++ */
++static DECLCALLBACK(int) usbProxyNetBSDReleaseInterface(PUSBPROXYDEV pProxyDev, int iIf)
++{
++ int rc;
++
++ LogFlow(("usbProxyNetBSDReleaseInterface: pProxyDev=%s "
++ "ifnum=%x\n", pProxyDev->pUsbIns->pszName, iIf));
++
++ return usbProxyNetBSDDoIoCtl(pProxyDev, USB_RELEASE_INTERFACE, &iIf, true);
++}
++
++/**
++ * SET_INTERFACE.
++ *
++ * @returns success indicator.
++ */
++static DECLCALLBACK(int) usbProxyNetBSDSetInterface(PUSBPROXYDEV pProxyDev, int iIf, int iAlt)
++{
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ struct usb_alt_interface UsbIntAlt;
++ int rc;
++
++ LogFlow(("usbProxyNetBSDSetInterface: pProxyDev=%p iIf=%x iAlt=%x\n",
++ pProxyDev, iIf, iAlt));
++
++ /* We need to release kernel ressources first. */
++ rc = usbProxyNetBSDFsUnInit(pProxyDev);
++ if (RT_FAILURE(rc))
++ {
++ LogFlow(("usbProxyNetBSDSetInterface: Freeing kernel resources "
++ "failed failed rc=%d\n", rc));
++ return rc;
++ }
++ memset(&UsbIntAlt, 0, sizeof(UsbIntAlt));
++ UsbIntAlt.uai_interface_index = iIf;
++ UsbIntAlt.uai_alt_index = iAlt;
++
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_SET_ALTINTERFACE, &UsbIntAlt, true);
++ if (RT_FAILURE(rc))
++ {
++ LogFlow(("usbProxyNetBSDSetInterface: Setting interface %d %d "
++ "failed rc=%d\n", iIf, iAlt, rc));
++ return rc;
++ }
++
++ return usbProxyNetBSDFsInit(pProxyDev);
++}
++
++/**
++ * Clears the halted endpoint 'ep_num'.
++ */
++static DECLCALLBACK(int) usbProxyNetBSDClearHaltedEp(PUSBPROXYDEV pProxyDev, unsigned int ep_num)
++{
++ LogFlow(("usbProxyNetBSDClearHaltedEp: pProxyDev=%s ep_num=%u\n",
++ pProxyDev->pUsbIns->pszName, ep_num));
++
++ /*
++ * Clearing the zero control pipe doesn't make sense.
++ * Just ignore it.
++ */
++ if ((ep_num & 0xF) == 0)
++ return VINF_SUCCESS;
++
++ struct usb_ctl_request Req;
++ memset(&Req, 0, sizeof(Req));
++ usbProxyNetBSDSetupReq(&Req.ucr_request,
++ VUSB_DIR_TO_DEV | VUSB_TO_ENDPOINT,
++ VUSB_REQ_CLEAR_FEATURE, 0, ep_num, 0);
++
++ int rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_DO_REQUEST, &Req, true);
++
++ LogFlow(("usbProxyNetBSDClearHaltedEp: rc=%Rrc\n", rc));
++ return rc;
++}
++
++/**
++ * @copydoc USBPROXYBACK::pfnUrbQueue
++ */
++static DECLCALLBACK(int) usbProxyNetBSDUrbQueue(PUSBPROXYDEV pProxyDev, PVUSBURB pUrb)
++{
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ PUSBENDPOINTFBSD pEndpointFBSD;
++ struct usb_fs_endpoint *pXferEndpoint;
++ struct usb_fs_start UsbFsStart;
++ unsigned cFrames;
++ uint8_t *pbData;
++ int index;
++ int ep_num;
++ int rc;
++
++ LogFlow(("usbProxyNetBSDUrbQueue: pUrb=%p EndPt=%u Dir=%u\n",
++ pUrb, (unsigned)pUrb->EndPt, (unsigned)pUrb->enmDir));
++
++ ep_num = pUrb->EndPt;
++ if ((pUrb->enmType != VUSBXFERTYPE_MSG) && (pUrb->enmDir == VUSBDIRECTION_IN)) {
++ /* set IN-direction bit */
++ ep_num |= 0x80;
++ }
++
++ index = 0;
++
++retry:
++
++ index = usbProxyNetBSDEndpointOpen(pProxyDev, ep_num,
++ (pUrb->enmType == VUSBXFERTYPE_ISOC),
++ index);
++
++ if (index < 0)
++ return VERR_INVALID_PARAMETER;
++
++ pEndpointFBSD = &pDevFBSD->aSwEndpoint[index];
++ pXferEndpoint = &pDevFBSD->aHwEndpoint[index];
++
++ pbData = pUrb->abData;
++
++ switch (pUrb->enmType)
++ {
++ case VUSBXFERTYPE_MSG:
++ {
++ pEndpointFBSD->apvData[0] = pbData;
++ pEndpointFBSD->acbData[0] = 8;
++
++ /* check wLength */
++ if (pbData[6] || pbData[7])
++ {
++ pEndpointFBSD->apvData[1] = pbData + 8;
++ pEndpointFBSD->acbData[1] = pbData[6] | (pbData[7] << 8);
++ cFrames = 2;
++ }
++ else
++ {
++ pEndpointFBSD->apvData[1] = NULL;
++ pEndpointFBSD->acbData[1] = 0;
++ cFrames = 1;
++ }
++
++ LogFlow(("usbProxyNetBSDUrbQueue: pUrb->cbData=%u, 0x%02x, "
++ "0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
++ pUrb->cbData, pbData[0], pbData[1], pbData[2], pbData[3],
++ pbData[4], pbData[5], pbData[6], pbData[7]));
++
++ pXferEndpoint->timeout = USB_FS_TIMEOUT_NONE;
++ pXferEndpoint->flags = USB_FS_FLAG_MULTI_SHORT_OK;
++ break;
++ }
++ case VUSBXFERTYPE_ISOC:
++ {
++ unsigned i;
++
++ for (i = 0; i < pUrb->cIsocPkts; i++)
++ {
++ if (i >= pEndpointFBSD->cMaxFrames)
++ break;
++ pEndpointFBSD->apvData[i] = pbData + pUrb->aIsocPkts[i].off;
++ pEndpointFBSD->acbData[i] = pUrb->aIsocPkts[i].cb;
++ }
++ /* Timeout handling will be done during reap. */
++ pXferEndpoint->timeout = USB_FS_TIMEOUT_NONE;
++ pXferEndpoint->flags = USB_FS_FLAG_MULTI_SHORT_OK;
++ cFrames = i;
++ break;
++ }
++ default:
++ {
++ pEndpointFBSD->apvData[0] = pbData;
++ pEndpointFBSD->cbData0 = pUrb->cbData;
++
++ /* XXX maybe we have to loop */
++ if (pUrb->cbData > pEndpointFBSD->cMaxIo)
++ pEndpointFBSD->acbData[0] = pEndpointFBSD->cMaxIo;
++ else
++ pEndpointFBSD->acbData[0] = pUrb->cbData;
++
++ /* Timeout handling will be done during reap. */
++ pXferEndpoint->timeout = USB_FS_TIMEOUT_NONE;
++ pXferEndpoint->flags = pUrb->fShortNotOk ? 0 : USB_FS_FLAG_MULTI_SHORT_OK;
++ cFrames = 1;
++ break;
++ }
++ }
++
++ /* store number of frames */
++ pXferEndpoint->nFrames = cFrames;
++
++ /* zero-default */
++ memset(&UsbFsStart, 0, sizeof(UsbFsStart));
++
++ /* Start the transfer */
++ UsbFsStart.ep_index = index;
++
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_FS_START, &UsbFsStart, true);
++
++ LogFlow(("usbProxyNetBSDUrbQueue: USB_FS_START returned rc=%d "
++ "len[0]=%u len[1]=%u cbData=%u index=%u ep_num=%u\n", rc,
++ (unsigned)pEndpointFBSD->acbData[0],
++ (unsigned)pEndpointFBSD->acbData[1],
++ (unsigned)pUrb->cbData,
++ (unsigned)index, (unsigned)ep_num));
++
++ if (RT_FAILURE(rc))
++ {
++ if (rc == VERR_RESOURCE_BUSY)
++ {
++ index++;
++ goto retry;
++ }
++ return rc;
++ }
++ pUrb->Dev.pvPrivate = (void *)(long)(index + 1);
++ pEndpointFBSD->pUrb = pUrb;
++
++ return rc;
++}
++
++/**
++ * Reap URBs in-flight on a device.
++ *
++ * @returns Pointer to a completed URB.
++ * @returns NULL if no URB was completed.
++ * @param pProxyDev The device.
++ * @param cMillies Number of milliseconds to wait. Use 0 to not wait at all.
++ */
++static DECLCALLBACK(PVUSBURB) usbProxyNetBSDUrbReap(PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies)
++{
++ struct usb_fs_endpoint *pXferEndpoint;
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ PUSBENDPOINTFBSD pEndpointFBSD;
++ PVUSBURB pUrb;
++ struct usb_fs_complete UsbFsComplete;
++ struct pollfd pfd[2];
++ int rc;
++
++ LogFlow(("usbProxyNetBSDUrbReap: pProxyDev=%p, cMillies=%u\n",
++ pProxyDev, cMillies));
++
++repeat:
++
++ pUrb = NULL;
++
++ /* check for cancelled transfers */
++ if (pDevFBSD->fCancelling)
++ {
++ for (unsigned n = 0; n < USBFBSD_MAXENDPOINTS; n++)
++ {
++ pEndpointFBSD = &pDevFBSD->aSwEndpoint[n];
++ if (pEndpointFBSD->fCancelling)
++ {
++ pEndpointFBSD->fCancelling = false;
++ pUrb = pEndpointFBSD->pUrb;
++ pEndpointFBSD->pUrb = NULL;
++
++ if (pUrb != NULL)
++ break;
++ }
++ }
++
++ if (pUrb != NULL)
++ {
++ pUrb->enmStatus = VUSBSTATUS_INVALID;
++ pUrb->Dev.pvPrivate = NULL;
++
++ switch (pUrb->enmType)
++ {
++ case VUSBXFERTYPE_MSG:
++ pUrb->cbData = 0;
++ break;
++ case VUSBXFERTYPE_ISOC:
++ pUrb->cbData = 0;
++ for (int n = 0; n < (int)pUrb->cIsocPkts; n++)
++ pUrb->aIsocPkts[n].cb = 0;
++ break;
++ default:
++ pUrb->cbData = 0;
++ break;
++ }
++ return pUrb;
++ }
++ pDevFBSD->fCancelling = false;
++ }
++ /* Zero default */
++
++ memset(&UsbFsComplete, 0, sizeof(UsbFsComplete));
++
++ /* Check if any endpoints are complete */
++ rc = usbProxyNetBSDDoIoCtl(pProxyDev, USB_FS_COMPLETE, &UsbFsComplete, true);
++ if (RT_SUCCESS(rc))
++ {
++ pXferEndpoint = &pDevFBSD->aHwEndpoint[UsbFsComplete.ep_index];
++ pEndpointFBSD = &pDevFBSD->aSwEndpoint[UsbFsComplete.ep_index];
++
++ LogFlow(("usbProxyNetBSDUrbReap: Reaped "
++ "URB %#p\n", pEndpointFBSD->pUrb));
++
++ if (pXferEndpoint->status == USB_ERR_CANCELLED)
++ goto repeat;
++
++ pUrb = pEndpointFBSD->pUrb;
++ pEndpointFBSD->pUrb = NULL;
++ if (pUrb == NULL)
++ goto repeat;
++
++ switch (pXferEndpoint->status)
++ {
++ case USB_ERR_NORMAL_COMPLETION:
++ pUrb->enmStatus = VUSBSTATUS_OK;
++ break;
++ case USB_ERR_STALLED:
++ pUrb->enmStatus = VUSBSTATUS_STALL;
++ break;
++ default:
++ pUrb->enmStatus = VUSBSTATUS_INVALID;
++ break;
++ }
++
++ pUrb->Dev.pvPrivate = NULL;
++
++ switch (pUrb->enmType)
++ {
++ case VUSBXFERTYPE_MSG:
++ pUrb->cbData = pEndpointFBSD->acbData[0] + pEndpointFBSD->acbData[1];
++ break;
++ case VUSBXFERTYPE_ISOC:
++ {
++ int n;
++
++ if (pUrb->enmDir == VUSBDIRECTION_OUT)
++ break;
++ pUrb->cbData = 0;
++ for (n = 0; n < (int)pUrb->cIsocPkts; n++)
++ {
++ if (n >= (int)pEndpointFBSD->cMaxFrames)
++ break;
++ pUrb->cbData += pEndpointFBSD->acbData[n];
++ pUrb->aIsocPkts[n].cb = pEndpointFBSD->acbData[n];
++ }
++ for (; n < (int)pUrb->cIsocPkts; n++)
++ pUrb->aIsocPkts[n].cb = 0;
++
++ break;
++ }
++ default:
++ pUrb->cbData = pEndpointFBSD->acbData[0];
++ break;
++ }
++
++ LogFlow(("usbProxyNetBSDUrbReap: Status=%d epindex=%u "
++ "len[0]=%d len[1]=%d\n",
++ (int)pXferEndpoint->status,
++ (unsigned)UsbFsComplete.ep_index,
++ (unsigned)pEndpointFBSD->acbData[0],
++ (unsigned)pEndpointFBSD->acbData[1]));
++
++ }
++ else if (cMillies != 0 && rc == VERR_RESOURCE_BUSY)
++ {
++ for (;;)
++ {
++ pfd[0].fd = RTFileToNative(pDevFBSD->hFile);
++ pfd[0].events = POLLIN | POLLRDNORM;
++ pfd[0].revents = 0;
++
++ pfd[1].fd = RTPipeToNative(pDevFBSD->hPipeWakeupR);
++ pfd[1].events = POLLIN | POLLRDNORM;
++ pfd[1].revents = 0;
++
++ rc = poll(pfd, 2, (cMillies == RT_INDEFINITE_WAIT) ? INFTIM : cMillies);
++ if (rc > 0)
++ {
++ if (pfd[1].revents & POLLIN)
++ {
++ /* Got woken up, drain pipe. */
++ uint8_t bRead;
++ size_t cbIgnored = 0;
++ RTPipeRead(pDevFBSD->hPipeWakeupR, &bRead, 1, &cbIgnored);
++ /* Make sure we return from this function */
++ cMillies = 0;
++ }
++ break;
++ }
++ if (rc == 0)
++ return NULL;
++ if (errno != EAGAIN)
++ return NULL;
++ }
++ goto repeat;
++ }
++ return pUrb;
++}
++
++/**
++ * Cancels the URB.
++ * The URB requires reaping, so we don't change its state.
++ */
++static DECLCALLBACK(int) usbProxyNetBSDUrbCancel(PUSBPROXYDEV pProxyDev, PVUSBURB pUrb)
++{
++ int index;
++
++ index = (int)(long)pUrb->Dev.pvPrivate - 1;
++
++ if (index < 0 || index >= USBFBSD_MAXENDPOINTS)
++ return VINF_SUCCESS; /* invalid index, pretend success. */
++
++ LogFlow(("usbProxyNetBSDUrbCancel: epindex=%u\n", (unsigned)index));
++ return usbProxyNetBSDEndpointClose(pProxyDev, index);
++}
++
++static DECLCALLBACK(int) usbProxyNetBSDWakeup(PUSBPROXYDEV pProxyDev)
++{
++ PUSBPROXYDEVFBSD pDevFBSD = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVFBSD);
++ size_t cbIgnored;
++
++ LogFlowFunc(("pProxyDev=%p\n", pProxyDev));
++
++ return RTPipeWrite(pDevFBSD->hPipeWakeupW, "", 1, &cbIgnored);
++}
++
++/**
++ * The NetBSD USB Proxy Backend.
++ */
++extern const USBPROXYBACK g_USBProxyDeviceHost =
++{
++ /* pszName */
++ "host",
++ /* cbBackend */
++ sizeof(USBPROXYDEVFBSD),
++ usbProxyNetBSDOpen,
++ usbProxyNetBSDInit,
++ usbProxyNetBSDClose,
++ usbProxyNetBSDReset,
++ usbProxyNetBSDSetConfig,
++ usbProxyNetBSDClaimInterface,
++ usbProxyNetBSDReleaseInterface,
++ usbProxyNetBSDSetInterface,
++ usbProxyNetBSDClearHaltedEp,
++ usbProxyNetBSDUrbQueue,
++ usbProxyNetBSDUrbCancel,
++ usbProxyNetBSDUrbReap,
++ usbProxyNetBSDWakeup,
++ 0
++};
++
++/*
++ * Local Variables:
++ * mode: c
++ * c-file-style: "bsd"
++ * c-basic-offset: 4
++ * tab-width: 4
++ * indent-tabs-mode: s
++ * End:
++ */
diff --git a/virtualbox/patches/patch-src_VBox_Devices_build_VBoxDD.cpp b/virtualbox/patches/patch-src_VBox_Devices_build_VBoxDD.cpp
new file mode 100644
index 0000000..ebec3dc
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_build_VBoxDD.cpp
@@ -0,0 +1,40 @@
+$NetBSD$
+
+--- src/VBox/Devices/build/VBoxDD.cpp.orig 2016-03-04 19:28:26.000000000 +0000
++++ src/VBox/Devices/build/VBoxDD.cpp
+@@ -222,7 +222,7 @@ extern "C" DECLEXPORT(int) VBoxDriversRe
+ rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvVD);
+ if (RT_FAILURE(rc))
+ return rc;
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostDVD);
+ if (RT_FAILURE(rc))
+ return rc;
+@@ -241,7 +241,7 @@ extern "C" DECLEXPORT(int) VBoxDriversRe
+ rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvNAT);
+ if (RT_FAILURE(rc))
+ return rc;
+-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostInterface);
+ if (RT_FAILURE(rc))
+ return rc;
+@@ -296,7 +296,7 @@ extern "C" DECLEXPORT(int) VBoxDriversRe
+ if (RT_FAILURE(rc))
+ return rc;
+ #endif /* RT_OS_LINUX */
+-#if defined(RT_OS_FREEBSD)
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostOSSAudio);
+ if (RT_FAILURE(rc))
+ return rc;
+@@ -344,7 +344,7 @@ extern "C" DECLEXPORT(int) VBoxDriversRe
+ if (RT_FAILURE(rc))
+ return rc;
+ #endif
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_WINDOWS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostSerial);
+ if (RT_FAILURE(rc))
+ return rc;
diff --git a/virtualbox/patches/patch-src_VBox_Devices_build_VBoxDD.h b/virtualbox/patches/patch-src_VBox_Devices_build_VBoxDD.h
new file mode 100644
index 0000000..e507ede
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Devices_build_VBoxDD.h
@@ -0,0 +1,27 @@
+$NetBSD$
+
+--- src/VBox/Devices/build/VBoxDD.h.orig 2016-03-04 19:28:26.000000000 +0000
++++ src/VBox/Devices/build/VBoxDD.h
+@@ -97,7 +97,7 @@ extern const PDMDRVREG g_DrvMediaISO;
+ extern const PDMDRVREG g_DrvRawImage;
+ extern const PDMDRVREG g_DrvISCSI;
+ extern const PDMDRVREG g_DrvISCSITransportTcp;
+-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ extern const PDMDRVREG g_DrvHostInterface;
+ #endif
+ #ifdef VBOX_WITH_UDPTUNNEL
+@@ -130,7 +130,7 @@ extern const PDMDRVREG g_DrvHostCoreAudi
+ extern const PDMDRVREG g_DrvHostOSSAudio;
+ extern const PDMDRVREG g_DrvHostSolAudio;
+ #endif
+-#if defined(RT_OS_FREEBSD)
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ extern const PDMDRVREG g_DrvHostOSSAudio;
+ #endif
+ extern const PDMDRVREG g_DrvACPI;
+@@ -182,4 +182,3 @@ int acpiCleanupSsdt(PPDMDEVINS pDevIns,
+ RT_C_DECLS_END
+
+ #endif
+-
diff --git a/virtualbox/patches/patch-src_VBox_ExtPacks_BusMouseSample_Makefile.kmk b/virtualbox/patches/patch-src_VBox_ExtPacks_BusMouseSample_Makefile.kmk
new file mode 100644
index 0000000..693c8ef
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ExtPacks_BusMouseSample_Makefile.kmk
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/VBox/ExtPacks/BusMouseSample/Makefile.kmk.orig 2016-03-04 19:28:27.000000000 +0000
++++ src/VBox/ExtPacks/BusMouseSample/Makefile.kmk
+@@ -133,6 +133,12 @@ endif
+ if1of (freebsd.x86, $(VBOX_WITH_EXTPACK_OS_ARCHS))
+ VBOX_BUSMOUSE_FILES += $(call VBOX_BUSMOUSE_FILES_MACRO,freebsd.x86,bin,so)
+ endif
++if1of (netbsd.amd64, $(VBOX_WITH_EXTPACK_OS_ARCHS))
++ VBOX_BUSMOUSE_FILES += $(call VBOX_BUSMOUSE_FILES_MACRO,netbsd.amd64,bin,so)
++endif
++if1of (netbsd.x86, $(VBOX_WITH_EXTPACK_OS_ARCHS))
++ VBOX_BUSMOUSE_FILES += $(call VBOX_BUSMOUSE_FILES_MACRO,netbsd.x86,bin,so)
++endif
+ if1of (linux.amd64, $(VBOX_WITH_EXTPACK_OS_ARCHS))
+ VBOX_BUSMOUSE_FILES += $(call VBOX_BUSMOUSE_FILES_MACRO,linux.amd64,bin,so)
+ endif
+@@ -184,4 +190,3 @@ $(VBOX_PATH_PACKAGES)/$(VBOX_BUSMOUSE_MA
+ BLDDIRS += $(VBOX_PATH_PACKAGES)/
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_ExtPacks_Skeleton_Makefile.kmk b/virtualbox/patches/patch-src_VBox_ExtPacks_Skeleton_Makefile.kmk
new file mode 100644
index 0000000..86f70b2
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ExtPacks_Skeleton_Makefile.kmk
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/VBox/ExtPacks/Skeleton/Makefile.kmk.orig 2016-03-04 19:28:27.000000000 +0000
++++ src/VBox/ExtPacks/Skeleton/Makefile.kmk
+@@ -108,6 +108,12 @@ endif
+ if1of (freebsd.x86, $(VBOX_WITH_EXTPACK_OS_ARCHS))
+ VBOX_SKELETON_FILES += $(call VBOX_SKELETON_FILES_MACRO,freebsd.x86,bin,so)
+ endif
++if1of (netbsd.amd64, $(VBOX_WITH_EXTPACK_OS_ARCHS))
++ VBOX_SKELETON_FILES += $(call VBOX_SKELETON_FILES_MACRO,netbsd.amd64,bin,so)
++endif
++if1of (netbsd.x86, $(VBOX_WITH_EXTPACK_OS_ARCHS))
++ VBOX_SKELETON_FILES += $(call VBOX_SKELETON_FILES_MACRO,netbsd.x86,bin,so)
++endif
+ if1of (linux.amd64, $(VBOX_WITH_EXTPACK_OS_ARCHS))
+ VBOX_SKELETON_FILES += $(call VBOX_SKELETON_FILES_MACRO,linux.amd64,bin,so)
+ endif
+@@ -159,4 +165,3 @@ $(VBOX_PATH_PACKAGES)/$(VBOX_SKELETON_MA
+ BLDDIRS += $(VBOX_PATH_PACKAGES)/
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_ExtPacks_VBoxDTrace_Makefile.kmk b/virtualbox/patches/patch-src_VBox_ExtPacks_VBoxDTrace_Makefile.kmk
new file mode 100644
index 0000000..c71c1bf
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ExtPacks_VBoxDTrace_Makefile.kmk
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/VBox/ExtPacks/VBoxDTrace/Makefile.kmk.orig 2016-03-04 19:28:27.000000000 +0000
++++ src/VBox/ExtPacks/VBoxDTrace/Makefile.kmk
+@@ -292,6 +292,12 @@ if defined(VBOX_WITH_EXTPACK_VBOXDTRACE)
+ if1of (freebsd.x86, $(VBOX_WITH_EXTPACK_OS_ARCHS))
+ VBOX_VBOXDTRACE_FILES += $(call VBOX_VBOXDTRACE_FILES_MACRO,freebsd.x86,bin,so)
+ endif
++ if1of (netbsd.amd64, $(VBOX_WITH_EXTPACK_OS_ARCHS))
++ VBOX_VBOXDTRACE_FILES += $(call VBOX_VBOXDTRACE_FILES_MACRO,netbsd.amd64,bin,so)
++ endif
++ if1of (netbsd.x86, $(VBOX_WITH_EXTPACK_OS_ARCHS))
++ VBOX_VBOXDTRACE_FILES += $(call VBOX_VBOXDTRACE_FILES_MACRO,netbsd.x86,bin,so)
++ endif
+ if1of (linux.amd64, $(VBOX_WITH_EXTPACK_OS_ARCHS))
+ VBOX_VBOXDTRACE_FILES += $(call VBOX_VBOXDTRACE_FILES_MACRO,linux.amd64,bin,so)
+ endif
+@@ -346,4 +352,3 @@ endif # VBOX_WITH_EXTPACK_VBOXDTRACE
+
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_ExtPacks_VBoxDTrace_VBoxDTraceWrapper.cpp b/virtualbox/patches/patch-src_VBox_ExtPacks_VBoxDTrace_VBoxDTraceWrapper.cpp
new file mode 100644
index 0000000..36cadc5
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ExtPacks_VBoxDTrace_VBoxDTraceWrapper.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/ExtPacks/VBoxDTrace/VBoxDTraceWrapper.cpp.orig 2016-03-04 19:28:27.000000000 +0000
++++ src/VBox/ExtPacks/VBoxDTrace/VBoxDTraceWrapper.cpp
+@@ -68,7 +68,7 @@ int main(int argc, char **argv)
+ char szDTraceCmd[RTPATH_MAX];
+ szDTraceCmd[0] = '\0';
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_NETBSD)
+ /*
+ * 1. Try native first on platforms where it's applicable.
+ */
+@@ -199,4 +199,3 @@ int main(int argc, char **argv)
+ }
+ return rcExit;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_ExtPacks_VNC_Makefile.kmk b/virtualbox/patches/patch-src_VBox_ExtPacks_VNC_Makefile.kmk
new file mode 100644
index 0000000..1d4a5f0
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ExtPacks_VNC_Makefile.kmk
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/VBox/ExtPacks/VNC/Makefile.kmk.orig 2016-03-04 19:28:58.000000000 +0000
++++ src/VBox/ExtPacks/VNC/Makefile.kmk
+@@ -110,6 +110,12 @@ endif
+ if1of (freebsd.x86, $(VBOX_WITH_EXTPACK_OS_ARCHS))
+ VBOX_VNC_FILES += $(call VBOX_VNC_FILES_MACRO,freebsd.x86,bin,so)
+ endif
++if1of (netbsd.amd64, $(VBOX_WITH_EXTPACK_OS_ARCHS))
++ VBOX_VNC_FILES += $(call VBOX_VNC_FILES_MACRO,netbsd.amd64,bin,so)
++endif
++if1of (netbsd.x86, $(VBOX_WITH_EXTPACK_OS_ARCHS))
++ VBOX_VNC_FILES += $(call VBOX_VNC_FILES_MACRO,netbsd.x86,bin,so)
++endif
+ if1of (linux.amd64, $(VBOX_WITH_EXTPACK_OS_ARCHS))
+ VBOX_VNC_FILES += $(call VBOX_VNC_FILES_MACRO,linux.amd64,bin,so)
+ endif
+@@ -161,4 +167,3 @@ $(VBOX_PATH_PACKAGES)/$(VBOX_VNC_MANGLED
+ BLDDIRS += $(VBOX_PATH_PACKAGES)/
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_Frontends_VBoxAutostart_VBoxAutostart-posix.cpp b/virtualbox/patches/patch-src_VBox_Frontends_VBoxAutostart_VBoxAutostart-posix.cpp
new file mode 100644
index 0000000..eb4f93b
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Frontends_VBoxAutostart_VBoxAutostart-posix.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Frontends/VBoxAutostart/VBoxAutostart-posix.cpp.orig 2016-03-04 19:28:58.000000000 +0000
++++ src/VBox/Frontends/VBoxAutostart/VBoxAutostart-posix.cpp
+@@ -61,7 +61,7 @@
+
+ using namespace com;
+
+-#if defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_DARWIN)
++#if defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_DARWIN) || defined(RT_OS_NETBSD)
+ # define VBOXAUTOSTART_DAEMONIZE
+ #endif
+
+@@ -564,4 +564,3 @@ int main(int argc, char *argv[])
+ autostartShutdown();
+ return rcExit;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Frontends_VBoxBalloonCtrl_VBoxWatchdog.cpp b/virtualbox/patches/patch-src_VBox_Frontends_VBoxBalloonCtrl_VBoxWatchdog.cpp
new file mode 100644
index 0000000..f9aa88b
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Frontends_VBoxBalloonCtrl_VBoxWatchdog.cpp
@@ -0,0 +1,45 @@
+$NetBSD$
+
+--- src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdog.cpp.orig 2016-03-04 19:28:59.000000000 +0000
++++ src/VBox/Frontends/VBoxBalloonCtrl/VBoxWatchdog.cpp
+@@ -112,7 +112,7 @@ enum GETOPTDEF_WATCHDOG
+ * Command line arguments.
+ */
+ static const RTGETOPTDEF g_aOptions[] = {
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ { "--background", 'b', RTGETOPT_REQ_NOTHING },
+ #endif
+ /** For displayHelp(). */
+@@ -854,7 +854,7 @@ static void displayHelp(const char *pszI
+ pcszDescr = "Print this help message and exit.";
+ break;
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ case 'b':
+ pcszDescr = "Run in background (daemon mode).";
+ break;
+@@ -992,7 +992,7 @@ int main(int argc, char *argv[])
+ g_fVerbose = true;
+ break;
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ case 'b':
+ g_fDaemonize = true;
+ break;
+@@ -1072,7 +1072,7 @@ int main(int argc, char *argv[])
+ if (RT_FAILURE(rc))
+ return RTMsgErrorExit(RTEXITCODE_FAILURE, "failed to open release log (%s, %Rrc)", szError, rc);
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ if (g_fDaemonize)
+ {
+ /* prepare release logging */
+@@ -1160,4 +1160,3 @@ int main(int argc, char *argv[])
+ return RTEXITCODE_SUCCESS;
+ #endif /* VBOX_ONLY_DOCS */
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxInternalManage.cpp b/virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxInternalManage.cpp
new file mode 100644
index 0000000..186e239
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxInternalManage.cpp
@@ -0,0 +1,70 @@
+$NetBSD$
+
+--- src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp.orig 2016-03-04 19:28:59.000000000 +0000
++++ src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
+@@ -51,7 +51,7 @@
+ # include <windows.h>
+ # include <winioctl.h>
+ #elif defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) \
+- || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++ || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <errno.h>
+ # include <sys/ioctl.h>
+ # include <sys/types.h>
+@@ -73,9 +73,9 @@
+ # include <sys/dkio.h>
+ # include <sys/vtoc.h>
+ #endif /* RT_OS_SOLARIS */
+-#ifdef RT_OS_FREEBSD
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <sys/disk.h>
+-#endif /* RT_OS_FREEBSD */
++#endif /* RT_OS_FREEBSD || RT_OS_NETBSD */
+
+ using namespace com;
+
+@@ -1192,12 +1192,12 @@ static RTEXITCODE CmdCreateRawVMDK(int a
+ i++;
+ pszPartitions = argv[i];
+ }
+-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_WINDOWS)
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_WINDOWS) || defined(RT_OS_NETBSD)
+ else if (strcmp(argv[i], "-relative") == 0)
+ {
+ fRelative = true;
+ }
+-#endif /* RT_OS_LINUX || RT_OS_FREEBSD */
++#endif /* RT_OS_LINUX || RT_OS_FREEBSD || RT_OS_NETBSD */
+ else
+ return errorSyntax(USAGE_CREATERAWVMDK, "Invalid parameter '%s'", argv[i]);
+ }
+@@ -1437,7 +1437,7 @@ static RTEXITCODE CmdCreateRawVMDK(int a
+ RTMsgError("Failed to get file informtation for raw disk '%s': %Rrc",
+ rawdisk.c_str(), vrc);
+ }
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ struct stat DevStat;
+ if (!fstat(RTFileToNative(hRawFile), &DevStat))
+ {
+@@ -1657,13 +1657,13 @@ static RTEXITCODE CmdCreateRawVMDK(int a
+
+ if (fRelative)
+ {
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /* Refer to the correct partition and use offset 0. */
+ char *psz;
+ RTStrAPrintf(&psz,
+ #if defined(RT_OS_LINUX)
+ "%s%u",
+-#elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ "%ss%u",
+ #endif
+ rawdisk.c_str(),
+@@ -2562,4 +2562,3 @@ RTEXITCODE handleInternalCommands(Handle
+ /* default: */
+ return errorSyntax(USAGE_ALL, "Invalid command '%s'", a->argv[0]);
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxManageHelp.cpp b/virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxManageHelp.cpp
new file mode 100644
index 0000000..4a0e0ce
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxManageHelp.cpp
@@ -0,0 +1,50 @@
+$NetBSD$
+
+--- src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp.orig 2016-03-04 19:28:59.000000000 +0000
++++ src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
+@@ -570,6 +570,11 @@ void printUsage(USAGECATEGORY fCategory,
+ #else
+ bool fFreeBSD = false;
+ #endif
++#ifdef RT_OS_NETBSD
++ bool fNetBSD = true;
++#else
++ bool fNetBSD = false;
++#endif
+ #ifdef RT_OS_DARWIN
+ bool fDarwin = true;
+ #else
+@@ -588,6 +593,7 @@ void printUsage(USAGECATEGORY fCategory,
+ fWin = true;
+ fSolaris = true;
+ fFreeBSD = true;
++ fNetBSD = true;
+ fDarwin = true;
+ fVBoxSDL = true;
+ fCategory = USAGE_ALL;
+@@ -824,6 +830,20 @@ void printUsage(USAGECATEGORY fCategory,
+ RTStrmPrintf(pStrm, "|pulse");
+ #endif
+ }
++ if (fNetBSD)
++ {
++ /* Get the line break sorted when dumping all option variants. */
++ if (fDumpOpts)
++ {
++ RTStrmPrintf(pStrm, "|\n"
++ " oss");
++ }
++ else
++ RTStrmPrintf(pStrm, "|oss");
++#ifdef VBOX_WITH_PULSE
++ RTStrmPrintf(pStrm, "|pulse");
++#endif
++ }
+ if (fDarwin)
+ {
+ RTStrmPrintf(pStrm, "|coreaudio");
+@@ -1523,4 +1543,3 @@ RTEXITCODE errorArgument(const char *psz
+ va_end(args);
+ return RTEXITCODE_SYNTAX;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxManageModifyVM.cpp b/virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxManageModifyVM.cpp
new file mode 100644
index 0000000..10037d3
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Frontends_VBoxManage_VBoxManageModifyVM.cpp
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp.orig 2016-03-04 19:29:00.000000000 +0000
++++ src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp
+@@ -2247,7 +2247,7 @@ RTEXITCODE handleModifyVM(HandlerArg *a)
+ CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
+ }
+ #endif /* !RT_OS_SOLARIS */
+-#ifdef RT_OS_FREEBSD
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ else if (!RTStrICmp(ValueUnion.psz, "oss"))
+ {
+ CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
+@@ -2260,7 +2260,7 @@ RTEXITCODE handleModifyVM(HandlerArg *a)
+ CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
+ }
+ # endif
+-#endif /* !RT_OS_FREEBSD */
++#endif /* !RT_OS_FREEBSD && !RT_OS_NETBSD */
+ #ifdef RT_OS_DARWIN
+ else if (!RTStrICmp(ValueUnion.psz, "coreaudio"))
+ {
+@@ -2269,7 +2269,7 @@ RTEXITCODE handleModifyVM(HandlerArg *a)
+ }
+
+ #endif /* !RT_OS_DARWIN */
+-# if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(VBOX_WITH_SOLARIS_OSS)
++# if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(VBOX_WITH_SOLARIS_OSS) || defined(RT_OS_NETBSD)
+ else if (!RTStrICmp(ValueUnion.psz, "oss"))
+ {
+ CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
diff --git a/virtualbox/patches/patch-src_VBox_Frontends_VBoxSDL_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Frontends_VBoxSDL_Makefile.kmk
new file mode 100644
index 0000000..cd2d263
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Frontends_VBoxSDL_Makefile.kmk
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/VBox/Frontends/VBoxSDL/Makefile.kmk.orig 2016-03-04 19:29:00.000000000 +0000
++++ src/VBox/Frontends/VBoxSDL/Makefile.kmk
+@@ -59,6 +59,7 @@ else
+ endif
+ endif
+ VBoxSDL_DEFS.freebsd = VBOXSDL_WITH_X11
++VBoxSDL_DEFS.netbsd = VBOXSDL_WITH_X11
+ VBoxSDL_DEFS.linux = _GNU_SOURCE VBOXSDL_WITH_X11
+ VBoxSDL_DEFS.solaris = VBOXSDL_WITH_X11
+ ifdef VBOX_OPENGL
+@@ -157,4 +158,3 @@ tstSDL_CXXFLAGS.linux = -O -Wall -Wno-no
+
+ endif # !VBOX_WITH_HARDENING || "$(KBUILD_TARGET)" != "darwin"
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_Makefile.kmk
new file mode 100644
index 0000000..79c4543
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_Makefile.kmk
@@ -0,0 +1,58 @@
+$NetBSD$
+
+--- src/VBox/Frontends/VirtualBox/Makefile.kmk.orig 2016-03-04 19:29:00.000000000 +0000
++++ src/VBox/Frontends/VirtualBox/Makefile.kmk
+@@ -104,6 +104,7 @@ VirtualBox_DEFS.debug = VBOX_CHECK_S
+ VirtualBox_DEFS.linux = VBOX_WITH_MASKED_SEAMLESS VBOX_WITH_TRANSLUCENT_SEAMLESS
+ VirtualBox_DEFS.solaris = VBOX_WITH_MASKED_SEAMLESS VBOX_WITH_TRANSLUCENT_SEAMLESS
+ VirtualBox_DEFS.freebsd = VBOX_WITH_MASKED_SEAMLESS VBOX_WITH_TRANSLUCENT_SEAMLESS
++VirtualBox_DEFS.netbsd = VBOX_WITH_MASKED_SEAMLESS VBOX_WITH_TRANSLUCENT_SEAMLESS
+ VirtualBox_DEFS.darwin = VBOX_WITH_TRANSLUCENT_SEAMLESS # VBOX_WITH_MASKED_SEAMLESS
+ VirtualBox_DEFS.win = VBOX_WITH_MASKED_SEAMLESS # VBOX_WITH_TRANSLUCENT_SEAMLESS
+ VirtualBox_DEFS.win += UNICODE QT_DLL
+@@ -118,6 +119,7 @@ VirtualBox_DEFS += \
+ $(if $(VBOX_WITH_SOLARIS_OSS),VBOX_WITH_SOLARIS_OSS) \
+ $(if $(VBOX_WITH_E1000),VBOX_WITH_E1000) \
+ $(if $(VBOX_WITH_NETFLT)$(eq $(KBUILD_TARGET),freebsd),VBOX_WITH_NETFLT) \
++ $(if $(VBOX_WITH_NETFLT)$(eq $(KBUILD_TARGET),netbsd),VBOX_WITH_NETFLT) \
+ $(if $(VBOX_WITH_VDE),VBOX_WITH_VDE) \
+ $(if $(VBOX_WITH_UDPTUNNEL),VBOX_WITH_UDPTUNNEL) \
+ $(if $(VBOX_WITH_EXTPACK),VBOX_WITH_EXTPACK) \
+@@ -219,6 +221,7 @@ endif
+ VirtualBox_LIBS.linux += Xinerama
+ VirtualBox_LIBS.solaris += Xinerama
+ VirtualBox_LIBS.freebsd += Xinerama
++VirtualBox_LIBS.netbsd += Xinerama
+
+ ifneq ($(KBUILD_TARGET),win)
+ VirtualBox_CXXFLAGS += -Wno-switch
+@@ -260,6 +263,7 @@ if defined(VBOX_WITH_VIDEOHWACCEL) || de
+ VirtualBox_LIBS.solaris += GL
+ VirtualBox_LIBS.linux += GL
+ VirtualBox_LIBS.freebsd += GL
++ VirtualBox_LIBS.netbsd += GL
+ VirtualBox_LDFLAGS.darwin += -framework OpenGL
+ endif
+ ifdef VBOX_WITH_CROGL
+@@ -988,6 +992,7 @@ endif
+ VirtualBoxPch_SOURCES.darwin = $(NO_SUCH_VARIABLE)
+ VirtualBoxPch_SOURCES.solaris = $(NO_SUCH_VARIABLE)
+ VirtualBoxPch_SOURCES.freebsd = $(NO_SUCH_VARIABLE)
++ VirtualBoxPch_SOURCES.netbsd = $(NO_SUCH_VARIABLE)
+ VirtualBoxPch_SOURCES.linux = $(NO_SUCH_VARIABLE)
+ VirtualBoxPch_SOURCES.win = $(NO_SUCH_VARIABLE)
+ VirtualBoxPch_QT_MODULES = $(VirtualBox_QT_MODULES) # "bug" - not inherited.
+@@ -1118,7 +1123,7 @@ endif # darwin
+ # App for testing GL support
+ #
+ if defined(VBOX_WITH_VIDEOHWACCEL)
+- if1of ($(KBUILD_TARGET), win linux freebsd)
++ if1of ($(KBUILD_TARGET), win linux freebsd netbsd)
+ LIBRARIES += VBoxOGL2D
+ VBoxOGL2D_TEMPLATE = $(if $(VBOX_WITH_VIDEOHWACCEL),$(if $(VBOX_WITH_HARDENING),VBOXQT4GUI,VBOXQT4GUIEXE),VBOXMAINEXE)
+ VBoxOGL2D_DEFS = QT_NO_DEBUG QT_THREAD_SUPPORT QT_SHARED HAVE_CONFIG_H VBOX_WITH_VIDEOHWACCEL VBOX_GUI_USE_QGL
+@@ -1253,4 +1258,3 @@ nls/VirtualBox_en.ts: \
+ $(QUIET)$(SED) -n -i -e \
+ '/<context>/,/<\/context>/!p;/<context>/h;/<name>/H;/<message numerus="yes">/,/<\/message>/H;/<\/context>/{H;x;/<message/p}' \
+ $@
+-
diff --git a/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_VBoxGLSupportInfo.cpp b/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_VBoxGLSupportInfo.cpp
new file mode 100644
index 0000000..39b11da
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_VBoxGLSupportInfo.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Frontends/VirtualBox/src/VBoxGLSupportInfo.cpp.orig 2016-03-04 19:29:07.000000000 +0000
++++ src/VBox/Frontends/VirtualBox/src/VBoxGLSupportInfo.cpp
+@@ -605,7 +605,7 @@ bool VBoxVHWAInfo::isVHWASupported() con
+ /* static */
+ bool VBoxVHWAInfo::checkVHWASupport()
+ {
+-#if defined(RT_OS_WINDOWS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_WINDOWS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ static char pszVBoxPath[RTPATH_MAX];
+ const char *papszArgs[] = { NULL, "-test", "2D", NULL};
+ int rc;
+@@ -702,4 +702,3 @@ const class QGLContext * VBoxGLTmpContex
+ }
+ return NULL;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_net_UIUpdateManager.cpp b/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_net_UIUpdateManager.cpp
new file mode 100644
index 0000000..588b104
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_net_UIUpdateManager.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Frontends/VirtualBox/src/net/UIUpdateManager.cpp.orig 2016-03-04 19:29:10.000000000 +0000
++++ src/VBox/Frontends/VirtualBox/src/net/UIUpdateManager.cpp
+@@ -249,6 +249,8 @@ private:
+ strPlatform = "os2";
+ #elif defined (Q_OS_FREEBSD)
+ strPlatform = "freebsd";
++#elif defined (Q_OS_NETBSD)
++ strPlatform = "netbsd";
+ #elif defined (Q_OS_SOLARIS)
+ strPlatform = "solaris";
+ #else
+@@ -514,4 +516,3 @@ void UIUpdateManager::sltHandleUpdateFin
+ }
+
+ #include "UIUpdateManager.moc"
+-
diff --git a/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_settings_machine_UIMachineSettingsAudio.cpp b/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_settings_machine_UIMachineSettingsAudio.cpp
new file mode 100644
index 0000000..c44cf92
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Frontends_VirtualBox_src_settings_machine_UIMachineSettingsAudio.cpp
@@ -0,0 +1,39 @@
+$NetBSD$
+
+--- src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.cpp.orig 2016-03-04 19:29:15.000000000 +0000
++++ src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.cpp
+@@ -159,12 +159,12 @@ void UIMachineSettingsAudio::retranslate
+ # endif /* VBOX_WITH_SOLARIS_OSS */
+ #endif /* Q_OS_SOLARIS */
+
+-#if defined Q_OS_LINUX || defined Q_OS_FREEBSD
++#if defined Q_OS_LINUX || defined Q_OS_FREEBSD || defined(RT_OS_NETBSD)
+ m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_OSS));
+ # ifdef VBOX_WITH_PULSE
+ m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_Pulse));
+ # endif /* VBOX_WITH_PULSE */
+-#endif /* Q_OS_LINUX | Q_OS_FREEBSD */
++#endif /* Q_OS_LINUX | Q_OS_FREEBSD || RT_OS_NETBSD */
+
+ #ifdef Q_OS_LINUX
+ # ifdef VBOX_WITH_ALSA
+@@ -227,12 +227,12 @@ void UIMachineSettingsAudio::prepareComb
+ # endif /* VBOX_WITH_SOLARIS_OSS */
+ #endif /* Q_OS_SOLARIS */
+
+-#if defined Q_OS_LINUX || defined Q_OS_FREEBSD
++#if defined Q_OS_LINUX || defined Q_OS_FREEBSD || defined(RT_OS_NETBSD)
+ m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_OSS);
+ # ifdef VBOX_WITH_PULSE
+ m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_Pulse);
+ # endif /* VBOX_WITH_PULSE */
+-#endif /* Q_OS_LINUX | Q_OS_FREEBSD */
++#endif /* Q_OS_LINUX | Q_OS_FREEBSD | RT_OS_NETBSD */
+
+ #ifdef Q_OS_LINUX
+ # ifdef VBOX_WITH_ALSA
+@@ -253,4 +253,3 @@ void UIMachineSettingsAudio::prepareComb
+ m_pComboAudioController->insertItem(++iIndex, "", KAudioControllerType_AC97);
+ m_pComboAudioController->insertItem(++iIndex, "", KAudioControllerType_SB16);
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_Makefile.kmk b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_Makefile.kmk
new file mode 100644
index 0000000..510089e
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_Makefile.kmk
@@ -0,0 +1,54 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/OpenGL/Makefile.kmk.orig 2016-03-04 19:29:19.000000000 +0000
++++ src/VBox/GuestHost/OpenGL/Makefile.kmk
+@@ -52,7 +52,7 @@ if defined(VBOX_SIGNING_MODE) && defined
+ endif
+ VBoxOGLcrutil_SDKS.win = ReorderCompilerIncs $(VBOX_WINPSDK) $(VBOX_WINDDK)
+ VBoxOGLcrutil_INTERMEDIATES = $(VBOX_PATH_CROGL_GENFILES)/cr_opcodes.h
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGLcrutil_INCS += \
+ $(VBOX_MESA_INCS)
+ endif
+@@ -197,7 +197,7 @@ endif
+ VBoxOGLcrpacker_TEMPLATE = VBOXCROGLR3GUESTLIB
+ VBoxOGLcrpacker_INCS = \
+ packer
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGLcrpacker_INCS += \
+ $(VBOX_MESA_INCS)
+ endif
+@@ -348,7 +348,7 @@ $(VBOX_PATH_CROGL_GENFILES)/%_swap.c: $(
+ VBoxOGLspuload_TEMPLATE = VBOXCROGLR3GUESTLIB
+ VBoxOGLspuload_INTERMEDIATES = \
+ $(VBOX_PATH_CROGL_GENFILES)/spu_dispatch_table.h
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGLspuload_INCS += \
+ $(VBOX_MESA_INCS)
+ endif
+@@ -421,7 +421,7 @@ $(VBOX_PATH_CROGL_GENFILES)/spu_dispatch
+ VBoxOGLcrstate_TEMPLATE = VBOXCROGLR3GUESTLIB
+ VBoxOGLcrstate_INCS = \
+ state_tracker
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGLcrstate_INCS += \
+ $(VBOX_MESA_INCS)
+ endif
+@@ -619,7 +619,7 @@ if defined(VBOX_SIGNING_MODE) && defined
+ endif
+ VBoxOGLerrorspu_INTERMEDIATES = \
+ $(VBOX_PATH_CROGL_GENFILES)/spu_dispatch_table.h
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ VBoxOGLerrorspu_INCS += \
+ $(VBOX_MESA_INCS)
+ endif
+@@ -676,4 +676,3 @@ $(VBOX_PATH_CROGL_GENFILES)/errorspu.c:
+ $(call MSG_GENERATE,python,$@,$<)
+ $(QUIET)$(call VBOX_CROGL_PYTHON_ENV,$(VBOX_PATH_CROGL_PYTHON_INCLUDE),$@) $(VBOX_BLD_PYTHON) $< $(VBOX_PATH_CROGL_GLAPI)
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_chromium.h b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_chromium.h
new file mode 100644
index 0000000..b158a9a
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_chromium.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/OpenGL/include/chromium.h.orig 2016-03-04 19:29:19.000000000 +0000
++++ src/VBox/GuestHost/OpenGL/include/chromium.h
+@@ -67,7 +67,7 @@
+
+ #ifdef DARWIN
+ # include <stddef.h>
+-#elif !defined(FreeBSD)
++#elif !defined(FreeBSD) && !defined(__NetBSD__)
+ # include <malloc.h> /* to get ptrdiff_t used below */
+ #endif
+
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_cr__dll.h b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_cr__dll.h
new file mode 100644
index 0000000..e6baf6b
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_cr__dll.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/OpenGL/include/cr_dll.h.orig 2016-03-04 19:29:19.000000000 +0000
++++ src/VBox/GuestHost/OpenGL/include/cr_dll.h
+@@ -22,7 +22,7 @@ typedef struct {
+ char *name;
+ #if defined(WINDOWS)
+ HINSTANCE hinstLib;
+-#elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
++#elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1) || defined(__NetBSD__)
+ void *hinstLib;
+ #elif defined(DARWIN)
+ void *hinstLib; /* void to avoid including the headers */
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_cr__timer.h b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_cr__timer.h
new file mode 100644
index 0000000..413500f
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_include_cr__timer.h
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/OpenGL/include/cr_timer.h.orig 2016-03-04 19:29:19.000000000 +0000
++++ src/VBox/GuestHost/OpenGL/include/cr_timer.h
+@@ -35,7 +35,7 @@ typedef struct Timer
+ #elif defined(WINDOWS)
+ LARGE_INTEGER performance_counter, performance_frequency;
+ double one_over_frequency;
+-#elif defined( Linux ) || defined( FreeBSD ) || defined(DARWIN) || defined(AIX) || defined (SunOS) || defined(OSF1)
++#elif defined( Linux ) || defined( FreeBSD ) || defined(DARWIN) || defined(AIX) || defined (SunOS) || defined(OSF1) || defined(__NetBSD__)
+ struct timeval timeofday;
+ #endif
+ } CRTimer;
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_spu__loader_glloader.py b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_spu__loader_glloader.py
new file mode 100644
index 0000000..f512609
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_spu__loader_glloader.py
@@ -0,0 +1,32 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/OpenGL/spu_loader/glloader.py.orig 2016-03-04 19:29:21.000000000 +0000
++++ src/VBox/GuestHost/OpenGL/spu_loader/glloader.py
+@@ -34,10 +34,12 @@ print """
+ # define SYSTEM_AGL "AGL"
+ # endif
+ #include <string.h> /* VBOX */
+-#elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
++#elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSDOB) || defined(AIX) || defined(SunOS) || defined(OSF1) || defined(__NetBSD__)
+ #include <string.h>
+ #if defined(AIX)
+ #define SYSTEM_GL "libGL.o"
++#elif defined(__NetBSD__)
++#define SYSTEM_GL "libGL.so.2"
+ #else
+ #define SYSTEM_GL "libGL.so.1"
+ #endif
+@@ -150,7 +152,7 @@ __findSystemLib( const char *provided_sy
+ }*/
+ #endif
+ }
+-#if !defined(__linux__) && !defined(SunOS) && !defined(__FreeBSD__)
++#if !defined(__linux__) && !defined(SunOS) && !defined(__FreeBSD__) && !defined(__NetBSD__)
+ crStrcat( system_path, "/" );
+ #endif
+ #if !defined(CR_NO_GL_SYSTEM_PATH)
+@@ -601,4 +603,3 @@ int crLoadOSMesa( OSMesaContext (**creat
+ #endif
+
+ """
+-
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_dll.c b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_dll.c
new file mode 100644
index 0000000..557f3b3
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_dll.c
@@ -0,0 +1,40 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/OpenGL/util/dll.c.orig 2016-03-04 19:29:23.000000000 +0000
++++ src/VBox/GuestHost/OpenGL/util/dll.c
+@@ -14,7 +14,7 @@
+ #include <string.h>
+ #endif
+
+-#if defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(DARWIN) || defined(SunOS) || defined(OSF1)
++#if defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(DARWIN) || defined(SunOS) || defined(OSF1) || defined(__NetBSD__)
+ #include <dlfcn.h>
+ #endif
+
+@@ -269,7 +269,7 @@ CRDLL *crDLLOpen( const char *dllname, i
+ dll_err = "Unknown DLL type";
+ break;
+ };
+-#elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
++#elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1) || defined(__NetBSD__)
+ if (resolveGlobal)
+ dll->hinstLib = dlopen( dllname, RTLD_LAZY | RTLD_GLOBAL );
+ else
+@@ -322,7 +322,7 @@ CRDLLFunc crDLLGetNoError( CRDLL *dll, c
+
+ return (CRDLLFunc) NSAddressOfSymbol( nssym );
+
+-#elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
++#elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1) || defined(__NetBSD__)
+ return (CRDLLFunc) dlsym( dll->hinstLib, symname );
+ #else
+ #error CR DLL ARCHITETECTURE
+@@ -366,7 +366,7 @@ void crDLLClose( CRDLL *dll )
+ NSUnLinkModule( (NSModule) dll->hinstLib, 0L );
+ break;
+ }
+-#elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
++#elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1) || defined(__NetBSD__)
+ /*
+ * Unloading Nvidia's libGL will crash VirtualBox later during shutdown.
+ * Therefore we will skip unloading it. It will be unloaded later anway
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_environment.c b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_environment.c
new file mode 100644
index 0000000..c5e19da
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_environment.c
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/OpenGL/util/environment.c.orig 2016-03-04 19:29:23.000000000 +0000
++++ src/VBox/GuestHost/OpenGL/util/environment.c
+@@ -12,7 +12,7 @@
+
+ void crSetenv( const char *var, const char *value )
+ {
+-#if defined(LINUX) || defined(FREEBSD) || defined(DARWIN)
++#if defined(LINUX) || defined(FREEBSD) || defined(DARWIN) || defined(__NetBSD__)
+ setenv( var, value, 1 /* replace */ );
+ #else
+ unsigned long len;
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_timer.c b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_timer.c
new file mode 100644
index 0000000..329c602
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_timer.c
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/OpenGL/util/timer.c.orig 2016-03-04 19:29:23.000000000 +0000
++++ src/VBox/GuestHost/OpenGL/util/timer.c
+@@ -35,7 +35,7 @@ static double crTimerGetTime( CRTimer *t
+ #elif defined( WINDOWS )
+ QueryPerformanceCounter( &t->performance_counter );
+ return ((double) t->performance_counter.QuadPart)*t->one_over_frequency;
+-#elif defined( Linux ) || defined( FreeBSD ) || defined(DARWIN) || defined(AIX) || defined(SunOS) || defined(OSF1)
++#elif defined( Linux ) || defined( FreeBSD ) || defined(DARWIN) || defined(AIX) || defined(SunOS) || defined(OSF1) || defined(__NetBSD__)
+ gettimeofday( &t->timeofday, NULL );
+ return t->timeofday.tv_sec + t->timeofday.tv_usec / 1000000.0;
+ #else
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_vboxhgcm.c b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_vboxhgcm.c
new file mode 100644
index 0000000..62472c0
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_vboxhgcm.c
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/OpenGL/util/vboxhgcm.c.orig 2016-03-04 19:29:23.000000000 +0000
++++ src/VBox/GuestHost/OpenGL/util/vboxhgcm.c
+@@ -623,7 +623,7 @@ static int crVBoxHGCMCall(CRConnection *
+ }
+ # else
+ int rc;
+-# if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++# if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ VBGLBIGREQ Hdr;
+ Hdr.u32Magic = VBGLBIGREQ_MAGIC;
+ Hdr.cbData = cbData;
+@@ -1405,7 +1405,7 @@ static int crVBoxHGCMDoConnect( CRConnec
+ &info, sizeof (info),
+ &cbReturned,
+ NULL))
+-#elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ VBGLBIGREQ Hdr;
+ Hdr.u32Magic = VBGLBIGREQ_MAGIC;
+ Hdr.cbData = sizeof(info);
+@@ -1567,7 +1567,7 @@ static void crVBoxHGCMDoDisconnect( CRCo
+ {
+ crDebug("Disconnect failed with %x\n", GetLastError());
+ }
+-# elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++# elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ VBGLBIGREQ Hdr;
+ Hdr.u32Magic = VBGLBIGREQ_MAGIC;
+ Hdr.cbData = sizeof(info);
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_vboxhgsmi.c b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_vboxhgsmi.c
new file mode 100644
index 0000000..2416f28
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_OpenGL_util_vboxhgsmi.c
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/OpenGL/util/vboxhgsmi.c.orig 2016-03-04 19:29:23.000000000 +0000
++++ src/VBox/GuestHost/OpenGL/util/vboxhgsmi.c
+@@ -255,7 +255,7 @@ static int crVBoxHGCMCall(void *pvData,
+ return VERR_NOT_SUPPORTED;
+ # else
+ int rc;
+-# if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++# if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ VBGLBIGREQ Hdr;
+ Hdr.u32Magic = VBGLBIGREQ_MAGIC;
+ Hdr.cbData = cbData;
+@@ -1258,7 +1258,7 @@ static int crVBoxHGSMIDoConnect( CRConne
+ &info, sizeof (info),
+ &cbReturned,
+ NULL))
+-#elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ VBGLBIGREQ Hdr;
+ Hdr.u32Magic = VBGLBIGREQ_MAGIC;
+ Hdr.cbData = sizeof(info);
+@@ -1370,7 +1370,7 @@ static void crVBoxHGSMIDoDisconnect( CRC
+ {
+ crDebug("Disconnect failed with %x\n", GetLastError());
+ }
+-# elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++# elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ VBGLBIGREQ Hdr;
+ Hdr.u32Magic = VBGLBIGREQ_MAGIC;
+ Hdr.cbData = sizeof(info);
diff --git a/virtualbox/patches/patch-src_VBox_GuestHost_SharedClipboard_Makefile.kmk b/virtualbox/patches/patch-src_VBox_GuestHost_SharedClipboard_Makefile.kmk
new file mode 100644
index 0000000..bac735e
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_GuestHost_SharedClipboard_Makefile.kmk
@@ -0,0 +1,9 @@
+$NetBSD$
+
+--- src/VBox/GuestHost/SharedClipboard/Makefile.kmk.orig 2016-03-04 19:29:23.000000000 +0000
++++ src/VBox/GuestHost/SharedClipboard/Makefile.kmk
+@@ -53,4 +53,3 @@ $$(tstClipboardX11Smoke_0_OUTDIR)/tstCli
+ endif
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Makefile.kmk b/virtualbox/patches/patch-src_VBox_HostDrivers_Makefile.kmk
new file mode 100644
index 0000000..3cea366
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Makefile.kmk
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Makefile.kmk.orig 2016-03-04 19:29:23.000000000 +0000
++++ src/VBox/HostDrivers/Makefile.kmk
+@@ -30,18 +30,18 @@ if !defined(VBOX_ONLY_DOCS) \
+ ifdef VBOX_WITH_USB
+ include $(PATH_SUB_CURRENT)/VBoxUSB/Makefile.kmk
+ endif
+- if1of ($(KBUILD_TARGET), darwin solaris win linux freebsd)
++ if1of ($(KBUILD_TARGET), darwin solaris win linux freebsd netbsd)
+ ifdef VBOX_WITH_NETFLT
+ include $(PATH_SUB_CURRENT)/VBoxNetFlt/Makefile.kmk
+ endif
+ endif
+- if1of ($(KBUILD_TARGET), darwin solaris win linux freebsd)
++ if1of ($(KBUILD_TARGET), darwin solaris win linux freebsd netbsd)
+ ifdef VBOX_WITH_NETADP
+ include $(PATH_SUB_CURRENT)/VBoxNetAdp/Makefile.kmk
+ else
+ endif
+ endif
+- if1of ($(KBUILD_TARGET), darwin freebsd linux)
++ if1of ($(KBUILD_TARGET), darwin freebsd linux netbsd)
+ include $(PATH_SUB_CURRENT)/$(KBUILD_TARGET)/Makefile.kmk
+ endif
+
+@@ -55,4 +55,3 @@ endif # !defined(VBOX_ONLY_DOCS) && !def
+
+ # Let kBuild generate the rules.
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_Makefile.kmk b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_Makefile.kmk
new file mode 100644
index 0000000..565c640
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_Makefile.kmk
@@ -0,0 +1,69 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/Makefile.kmk.orig 2016-03-04 19:29:24.000000000 +0000
++++ src/VBox/HostDrivers/Support/Makefile.kmk
+@@ -58,6 +58,7 @@ if !defined(VBOX_ONLY_DOCS) \
+ endif
+ INSTALLS.linux += vboxdrv-mod
+ INSTALLS.freebsd += vboxdrv-mod
++ INSTALLS.netbsd += vboxdrv-mod
+
+ #
+ # Include sub-makefile(s).
+@@ -73,6 +74,9 @@ if !defined(VBOX_ONLY_DOCS) \
+ ifeq ($(KBUILD_TARGET),freebsd)
+ include $(PATH_SUB_CURRENT)/freebsd/files_vboxdrv
+ endif
++ ifeq ($(KBUILD_TARGET),netbsd)
++ include $(PATH_SUB_CURRENT)/netbsd/files_vboxdrv
++ endif
+ endif # !VBOX_ONLY_DOCS && !VBOX_ONLY_EXTPACKS && !VBOX_ONLY_VALIDATIONKIT
+
+ #
+@@ -533,12 +537,13 @@ endif # os2
+ #
+ # New VBoxDrv target. TODO: Convert all the above to use this!
+ #
+-if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
++if1of ($(KBUILD_TARGET), darwin freebsd netbsd linux solaris win)
+ ifdef VBOX_WITH_VBOXDRV
+ SYSMODS += VBoxDrv
+ endif
+ VBoxDrv_TEMPLATE = VBOXR0DRV
+ VBoxDrv_NAME.freebsd = vboxdrv
++ VBoxDrv_NAME.netbsd = vboxdrv
+ VBoxDrv_NAME.linux = vboxdrv
+ VBoxDrv_NAME.solaris = vboxdrv
+ ifdef VBOX_SIGNING_MODE
+@@ -637,7 +642,7 @@ if1of ($(KBUILD_TARGET), darwin freebsd
+ SUPDrv-dtrace.cpp
+ SUPDrv-dtrace.cpp_DEFS.darwin += VBOX_PATH_MACOSX_DTRACE_H=\"$(VBOX_PATH_MACOSX_SDK)/usr/include/sys/dtrace.h\"
+ endif
+- ifn1of ($(KBUILD_TARGET), linux freebsd)
++ ifn1of ($(KBUILD_TARGET), linux freebsd netbsd)
+ VBoxDrv_SOURCES += \
+ SUPDrvTracerA.asm
+ endif
+@@ -687,7 +692,7 @@ if1of ($(KBUILD_TARGET), darwin solaris)
+ endif
+
+
+-if1of ($(KBUILD_TARGET), linux freebsd)
++if1of ($(KBUILD_TARGET), linux freebsd netbsd)
+ #
+ # Targets for installing the linux sources.
+ #
+@@ -717,7 +722,7 @@ if1of ($(KBUILD_TARGET), linux freebsd)
+ --output $@ $<
+ %$(QUIET2)$(APPEND) -t '$(PATH_TARGET)/vboxdrv-mod-1.dep' \
+ 'Support/$(KBUILD_TARGET)/Makefile_VBOX_HARDENED=$(VBOX_WITH_HARDENING)'
+-endif # linux freebsd
++endif # linux freebsd netbsd
+
+
+ ifeq ($(KBUILD_TARGET), win)
+@@ -752,4 +757,3 @@ endif # win
+
+ endif # !VBOX_ONLY_DOCS && !VBOX_ONLY_EXTPACKS && !VBOX_ONLY_VALIDATIONKIT
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrv.cpp b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrv.cpp
new file mode 100644
index 0000000..b189e1b
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrv.cpp
@@ -0,0 +1,36 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/SUPDrv.cpp.orig 2016-03-04 19:29:24.000000000 +0000
++++ src/VBox/HostDrivers/Support/SUPDrv.cpp
+@@ -54,7 +54,7 @@
+ #include <iprt/crc.h>
+ #include <iprt/string.h>
+ #include <iprt/timer.h>
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <iprt/rand.h>
+ # include <iprt/path.h>
+ #endif
+@@ -456,7 +456,7 @@ static SUPFUNC g_aFunctions[] =
+ /* SED: END */
+ };
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /**
+ * Drag in the rest of IRPT since we share it with the
+ * rest of the kernel modules on darwin.
+@@ -469,7 +469,7 @@ PFNRT g_apfnVBoxDrvIPRTDeps[] =
+ (PFNRT)RTPathStripFilename,
+ NULL
+ };
+-#endif /* RT_OS_DARWIN || RT_OS_SOLARIS || RT_OS_SOLARIS */
++#endif /* RT_OS_DARWIN || RT_OS_SOLARIS || RT_OS_SOLARIS || RT_OS_NETBSD */
+
+
+ /**
+@@ -5719,4 +5719,3 @@ static int supdrvIOCtl_ResumeSuspendedKb
+ return VERR_NOT_IMPLEMENTED;
+ #endif
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvGip.cpp b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvGip.cpp
new file mode 100644
index 0000000..d928235
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvGip.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/SUPDrvGip.cpp.orig 2016-03-04 19:29:24.000000000 +0000
++++ src/VBox/HostDrivers/Support/SUPDrvGip.cpp
+@@ -51,7 +51,7 @@
+ #include <iprt/crc.h>
+ #include <iprt/string.h>
+ #include <iprt/timer.h>
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <iprt/rand.h>
+ # include <iprt/path.h>
+ #endif
+@@ -4894,4 +4894,3 @@ int VBOXCALL supdrvIOCtl_GipSetFlags(PSU
+ #endif
+ return rc;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvIDC.h b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvIDC.h
new file mode 100644
index 0000000..0360e0a
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvIDC.h
@@ -0,0 +1,19 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/SUPDrvIDC.h.orig 2016-03-04 19:29:24.000000000 +0000
++++ src/VBox/HostDrivers/Support/SUPDrvIDC.h
+@@ -233,6 +233,9 @@ extern DECLIMPORT(int) VBOXCALL SUPDrvDa
+ #elif defined(RT_OS_FREEBSD)
+ extern int VBOXCALL SUPDrvFreeBSDIDC(uint32_t iReq, PSUPDRVIDCREQHDR pReq);
+
++#elif defined(RT_OS_NETBSD)
++extern int VBOXCALL SUPDrvNetBSDIDC(uint32_t iReq, PSUPDRVIDCREQHDR pReq);
++
+ #elif defined(RT_OS_LINUX)
+ extern int VBOXCALL SUPDrvLinuxIDC(uint32_t iReq, PSUPDRVIDCREQHDR pReq);
+
+@@ -272,4 +275,3 @@ typedef DECLCALLBACK(int) FNSUPDRVIDCENT
+ #pragma pack() /* paranoia */
+
+ #endif
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvInternal.h b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvInternal.h
new file mode 100644
index 0000000..0681c2a
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvInternal.h
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/SUPDrvInternal.h.orig 2016-03-04 19:29:24.000000000 +0000
++++ src/VBox/HostDrivers/Support/SUPDrvInternal.h
+@@ -115,7 +115,7 @@
+
+ #elif defined(RT_OS_OS2)
+
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # define memset libkern_memset /** @todo these are just hacks to get it compiling, check out later. */
+ # define memcmp libkern_memcmp
+ # define strchr libkern_strchr
+@@ -995,4 +995,3 @@ const SUPDRVTRACERREG * VBOXCALL supdrvD
+ RT_C_DECLS_END
+
+ #endif
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvTracer.cpp b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvTracer.cpp
new file mode 100644
index 0000000..e62fa87
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPDrvTracer.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/SUPDrvTracer.cpp.orig 2016-03-04 19:29:24.000000000 +0000
++++ src/VBox/HostDrivers/Support/SUPDrvTracer.cpp
+@@ -1466,7 +1466,7 @@ SUPR0DECL(int) SUPR0TracerDeregisterImpl
+ * rebuilding of the kernel module from scratch at install time, we have to
+ * deploy some ugly gcc inline assembly here.
+ */
+-#if defined(__GNUC__) && (defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX))
++#if defined(__GNUC__) && (defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_NETBSD))
+ __asm__("\
+ .section .text \n\
+ \n\
+@@ -2468,4 +2468,3 @@ void VBOXCALL supdrvTracerTerm(PSUPDRVDE
+ pDevExt->mtxTracer = NIL_RTSEMFASTMUTEX;
+ LOG_TRACER(("supdrvTracerTerm: Done\n"));
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPR3HardenedMain.cpp b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPR3HardenedMain.cpp
new file mode 100644
index 0000000..208c1c6
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_SUPR3HardenedMain.cpp
@@ -0,0 +1,47 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp.orig 2016-03-04 19:29:24.000000000 +0000
++++ src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
+@@ -63,7 +63,7 @@
+ # ifndef CAP_TO_MASK
+ # define CAP_TO_MASK(cap) RT_BIT(cap)
+ # endif
+-# elif defined(RT_OS_FREEBSD)
++# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <sys/param.h>
+ # include <sys/sysctl.h>
+ # elif defined(RT_OS_SOLARIS)
+@@ -859,7 +859,7 @@ static void supR3HardenedGetFullExePath(
+ *
+ * Darwin, OS/2 and Windows all have proper APIs for getting the program file name.
+ */
+-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS) || defined(RT_OS_NETBSD)
+ # ifdef RT_OS_LINUX
+ int cchLink = readlink("/proc/self/exe", &g_szSupLibHardenedExePath[0], sizeof(g_szSupLibHardenedExePath) - 1);
+
+@@ -881,6 +881,19 @@ static void supR3HardenedGetFullExePath(
+ g_szSupLibHardenedExePath[sizeof(g_szSupLibHardenedExePath) - 1] = '\0';
+ int cchLink = suplibHardenedStrLen(g_szSupLibHardenedExePath); /* paranoid? can't we use cbPath? */
+
++# else /* RT_OS_NETBSD */
++ int aiName[4];
++ aiName[0] = CTL_KERN;
++ aiName[1] = KERN_PROC_ARGS;
++ aiName[2] = getpid();
++ aiName[3] = KERN_PROC_PATHNAME;
++
++ size_t cbPath = sizeof(g_szSupLibHardenedExePath);
++ if (sysctl(aiName, RT_ELEMENTS(aiName), g_szSupLibHardenedExePath, &cbPath, NULL, 0) < 0)
++ supR3HardenedFatal("supR3HardenedExecDir: sysctl failed\n");
++ g_szSupLibHardenedExePath[sizeof(g_szSupLibHardenedExePath) - 1] = '\0';
++ int cchLink = suplibHardenedStrLen(g_szSupLibHardenedExePath); /* paranoid? can't we use cbPath? */
++
+ # endif
+ if (cchLink < 0 || cchLink == sizeof(g_szSupLibHardenedExePath) - 1)
+ supR3HardenedFatal("supR3HardenedExecDir: couldn't read \"%s\", errno=%d cchLink=%d\n",
+@@ -2025,4 +2038,3 @@ DECLHIDDEN(int) SUPR3HardenedMain(const
+ g_enmSupR3HardenedMainState = SUPR3HARDENEDMAINSTATE_CALLED_TRUSTED_MAIN;
+ return pfnTrustedMain(argc, argv, envp);
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_Makefile b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_Makefile
new file mode 100644
index 0000000..a07a528
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_Makefile
@@ -0,0 +1,189 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/netbsd/Makefile.orig 2016-07-07 07:08:46.477818725 +0000
++++ src/VBox/HostDrivers/Support/netbsd/Makefile
+@@ -0,0 +1,184 @@
++# Makefile $
++## @file
++# Makefile for the VirtualBox NetBSD Host Driver.
++#
++
++#
++# Copyright (C) 2006-2015 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.
++#
++
++KMOD = vboxdrv
++
++CFLAGS += -DRT_OS_NETBSD -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
++
++.if (${MACHINE_ARCH} == "i386")
++ CFLAGS += -DRT_ARCH_X86
++.elif (${MACHINE_ARCH} == "amd64")
++ CFLAGS += -DRT_ARCH_AMD64
++.endif
++
++SRCS = \
++ SUPDrv.c \
++ SUPDrvGip.c \
++ SUPDrvSem.c \
++ SUPDrvTracer.c \
++ SUPLibAll.c \
++
++# Include needed interface headers so they are created during build
++SRCS += \
++ device_if.h \
++ bus_if.h
++
++.PATH: ${.CURDIR}/netbsd
++SRCS += \
++ SUPDrv-netbsd.c
++
++.PATH: ${.CURDIR}/alloc
++SRCS += \
++ heapsimple.c \
++ alloc.c
++
++.PATH: ${.CURDIR}/common/err
++SRCS += \
++ RTErrConvertFromErrno.c \
++ RTErrConvertToErrno.c
++
++.PATH: ${.CURDIR}/common/log
++SRCS += \
++ log.c \
++ logellipsis.c \
++ logrel.c \
++ logrelellipsis.c \
++ logcom.c \
++ logformat.c
++
++.PATH: ${.CURDIR}/common/misc
++SRCS += \
++ RTAssertMsg1Weak.c \
++ RTAssertMsg2.c \
++ RTAssertMsg2Add.c \
++ RTAssertMsg2AddWeak.c \
++ RTAssertMsg2AddWeakV.c \
++ RTAssertMsg2Weak.c \
++ RTAssertMsg2WeakV.c \
++ assert.c \
++ handletable.c \
++ handletablectx.c \
++ once.c \
++ term.c \
++ thread.c
++
++.PATH: ${.CURDIR}/common/string
++SRCS += \
++ RTStrNCmp.c \
++ RTStrNLen.c \
++ RTStrCopy.c \
++ RTStrCopyEx.c \
++ RTStrCopyP.c \
++ strformat.c \
++ strformatrt.c \
++ strformattype.c \
++ strprintf.c \
++ strtonum.c \
++ memchr.c \
++ stringalloc.c
++
++.PATH: ${.CURDIR}/common/rand
++SRCS += \
++ rand.c \
++ randadv.c \
++ randparkmiller.c
++
++.PATH: ${.CURDIR}/common/path
++SRCS += \
++ RTPathStripFilename.c
++
++.PATH: ${.CURDIR}/common/checksum
++SRCS += \
++ crc32.c \
++ ipv4.c \
++ ipv6.c
++
++.PATH: ${.CURDIR}/common/table
++SRCS += \
++ avlpv.c
++
++.PATH: ${.CURDIR}/common/time
++SRCS += \
++ time.c
++
++.PATH: ${.CURDIR}/generic
++SRCS += \
++ uuid-generic.c \
++ RTAssertShouldPanic-generic.c \
++ RTLogWriteDebugger-generic.c \
++ RTLogWriteStdOut-stub-generic.c \
++ RTLogWriteStdErr-stub-generic.c \
++ RTLogWriteUser-generic.c \
++ RTMpGetArraySize-generic.c \
++ RTMpOnPair-generic.c \
++ RTRandAdvCreateSystemFaster-generic.c \
++ RTRandAdvCreateSystemTruer-generic.c \
++ RTSemEventWait-2-ex-generic.c \
++ RTSemEventWaitNoResume-2-ex-generic.c \
++ RTSemEventMultiWait-2-ex-generic.c \
++ RTSemEventMultiWaitNoResume-2-ex-generic.c \
++ RTTimerCreate-generic.c \
++ errvars-generic.c \
++ mppresent-generic.c \
++ timer-generic.c
++
++.PATH: ${.CURDIR}/r0drv
++SRCS += \
++ alloc-r0drv.c \
++ initterm-r0drv.c \
++ memobj-r0drv.c \
++ powernotification-r0drv.c
++
++.PATH: ${.CURDIR}/r0drv/netbsd
++SRCS += \
++ assert-r0drv-netbsd.c \
++ alloc-r0drv-netbsd.c \
++ initterm-r0drv-netbsd.c \
++ memobj-r0drv-netbsd.c \
++ memuserkernel-r0drv-netbsd.c \
++ mp-r0drv-netbsd.c \
++ process-r0drv-netbsd.c \
++ semevent-r0drv-netbsd.c \
++ semeventmulti-r0drv-netbsd.c \
++ semfastmutex-r0drv-netbsd.c \
++ semmutex-r0drv-netbsd.c \
++ spinlock-r0drv-netbsd.c \
++ thread-r0drv-netbsd.c \
++ thread2-r0drv-netbsd.c \
++ time-r0drv-netbsd.c
++
++.PATH: ${.CURDIR}/r0drv/generic
++SRCS += \
++ semspinmutex-r0drv-generic.c \
++ mpnotification-r0drv-generic.c \
++ threadctxhooks-r0drv-generic.c \
++ RTMpIsCpuWorkPending-r0drv-generic.c
++
++.PATH: ${.CURDIR}/VBox
++SRCS += \
++ log-vbox.c
++
++.include <bsd.kmod.mk>
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.c b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.c
new file mode 100644
index 0000000..669f713
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.c
@@ -0,0 +1,637 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/netbsd/SUPDrv-netbsd.c.orig 2016-07-07 07:08:46.487236799 +0000
++++ src/VBox/HostDrivers/Support/netbsd/SUPDrv-netbsd.c
+@@ -0,0 +1,632 @@
++/* SUPDrv-netbsd.c $ */
++/** @file
++ * VBoxDrv - The VirtualBox Support Driver - NetBSD specifics.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#define LOG_GROUP LOG_GROUP_SUP_DRV
++/* Deal with conflicts first. */
++#include <sys/param.h>
++#undef PVM
++#include <sys/types.h>
++#include <sys/module.h>
++#include <sys/systm.h>
++#include <sys/errno.h>
++#include <sys/kernel.h>
++#include <sys/fcntl.h>
++#include <sys/conf.h>
++#include <sys/uio.h>
++
++#include "../SUPDrvInternal.h"
++#include <VBox/version.h>
++#include <iprt/initterm.h>
++#include <iprt/string.h>
++#include <iprt/spinlock.h>
++#include <iprt/process.h>
++#include <iprt/assert.h>
++#include <iprt/uuid.h>
++#include <VBox/log.h>
++#include <iprt/alloc.h>
++#include <iprt/err.h>
++#include <iprt/asm.h>
++
++#ifdef VBOX_WITH_HARDENING
++# define VBOXDRV_PERM 0600
++#else
++# define VBOXDRV_PERM 0666
++#endif
++
++
++/*********************************************************************************************************************************
++* Internal Functions *
++*********************************************************************************************************************************/
++static int VBoxDrvNetBSDModuleEvent(struct module *pMod, int enmEventType, void *pvArg);
++static int VBoxDrvNetBSDLoad(void);
++static int VBoxDrvNetBSDUnload(void);
++
++static d_open_t VBoxDrvNetBSDOpenUsr;
++static d_open_t VBoxDrvNetBSDOpenSys;
++static void vboxdrvNetBSDDtr(void *pvData);
++static d_ioctl_t VBoxDrvNetBSDIOCtl;
++static int VBoxDrvNetBSDIOCtlSlow(PSUPDRVSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd);
++
++
++/*********************************************************************************************************************************
++* Global Variables *
++*********************************************************************************************************************************/
++/**
++ * Module info structure used by the kernel.
++ */
++static moduledata_t g_VBoxDrvNetBSDModule =
++{
++ "vboxdrv",
++ VBoxDrvNetBSDModuleEvent,
++ NULL
++};
++
++/** Declare the module as a pseudo device. */
++DECLARE_MODULE(vboxdrv, g_VBoxDrvNetBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY);
++MODULE_VERSION(vboxdrv, 1);
++
++/**
++ * The /dev/vboxdrv character device entry points.
++ */
++static struct cdevsw g_VBoxDrvNetBSDChrDevSwSys =
++{
++ .d_version = D_VERSION,
++ .d_open = VBoxDrvNetBSDOpenSys,
++ .d_ioctl = VBoxDrvNetBSDIOCtl,
++ .d_name = "vboxdrv"
++};
++/** The /dev/vboxdrv character device. */
++static struct cdev *g_pVBoxDrvNetBSDChrDevSys;
++
++/**
++ * The /dev/vboxdrvu character device entry points.
++ */
++static struct cdevsw g_VBoxDrvNetBSDChrDevSwUsr =
++{
++ .d_version = D_VERSION,
++ .d_open = VBoxDrvNetBSDOpenUsr,
++ .d_ioctl = VBoxDrvNetBSDIOCtl,
++ .d_name = "vboxdrvu"
++};
++/** The /dev/vboxdrvu character device. */
++static struct cdev *g_pVBoxDrvNetBSDChrDevUsr;
++
++/** Reference counter. */
++static volatile uint32_t g_cUsers;
++
++/** The device extention. */
++static SUPDRVDEVEXT g_VBoxDrvNetBSDDevExt;
++
++/**
++ * Module event handler.
++ *
++ * @param pMod The module structure.
++ * @param enmEventType The event type (modeventtype_t).
++ * @param pvArg Module argument. NULL.
++ *
++ * @return 0 on success, errno.h status code on failure.
++ */
++static int VBoxDrvNetBSDModuleEvent(struct module *pMod, int enmEventType, void *pvArg)
++{
++ int rc;
++ switch (enmEventType)
++ {
++ case MOD_LOAD:
++ rc = VBoxDrvNetBSDLoad();
++ break;
++
++ case MOD_UNLOAD:
++ mtx_unlock(&Giant);
++ rc = VBoxDrvNetBSDUnload();
++ mtx_lock(&Giant);
++ break;
++
++ case MOD_SHUTDOWN:
++ case MOD_QUIESCE:
++ default:
++ return EOPNOTSUPP;
++ }
++
++ if (RT_SUCCESS(rc))
++ return 0;
++ return RTErrConvertToErrno(rc);
++}
++
++
++static int VBoxDrvNetBSDLoad(void)
++{
++ g_cUsers = 0;
++
++ /*
++ * Initialize the runtime.
++ */
++ int rc = RTR0Init(0);
++ if (RT_SUCCESS(rc))
++ {
++ Log(("VBoxDrvNetBSDLoad:\n"));
++
++ /*
++ * Initialize the device extension.
++ */
++ rc = supdrvInitDevExt(&g_VBoxDrvNetBSDDevExt, sizeof(SUPDRVSESSION));
++ if (RT_SUCCESS(rc))
++ {
++ /*
++ * Configure character devices. Add symbolic links for compatibility.
++ */
++ g_pVBoxDrvNetBSDChrDevSys = make_dev(&g_VBoxDrvNetBSDChrDevSwSys, 0, UID_ROOT, GID_WHEEL, VBOXDRV_PERM, "vboxdrv");
++ g_pVBoxDrvNetBSDChrDevUsr = make_dev(&g_VBoxDrvNetBSDChrDevSwUsr, 1, UID_ROOT, GID_WHEEL, 0666, "vboxdrvu");
++ return VINF_SUCCESS;
++ }
++
++ printf("vboxdrv: supdrvInitDevExt failed, rc=%d\n", rc);
++ RTR0Term();
++ }
++ else
++ printf("vboxdrv: RTR0Init failed, rc=%d\n", rc);
++ return rc;
++}
++
++static int VBoxDrvNetBSDUnload(void)
++{
++ Log(("VBoxDrvNetBSDUnload:\n"));
++
++ if (g_cUsers > 0)
++ return VERR_RESOURCE_BUSY;
++
++ /*
++ * Reserve what we did in VBoxDrvNetBSDInit.
++ */
++ destroy_dev(g_pVBoxDrvNetBSDChrDevUsr);
++ destroy_dev(g_pVBoxDrvNetBSDChrDevSys);
++
++ supdrvDeleteDevExt(&g_VBoxDrvNetBSDDevExt);
++
++ RTR0TermForced();
++
++ memset(&g_VBoxDrvNetBSDDevExt, 0, sizeof(g_VBoxDrvNetBSDDevExt));
++ return VINF_SUCCESS;
++}
++
++
++/**
++ *
++ * @returns 0 on success, errno on failure.
++ * EBUSY if the device is used by someone else.
++ * @param pDev The device node.
++ * @param fOpen The open flags.
++ * @param iDevType Some device type thing we don't use.
++ * @param pTd The thread.
++ * @param fUnrestricted Set if opening /dev/vboxdrv, clear if /dev/vboxdrvu.
++ */
++static int vboxdrvNetBSDOpenCommon(struct cdev *pDev, int fOpen, int iDevType, struct thread *pTd, bool fUnrestricted)
++{
++ PSUPDRVSESSION pSession;
++ int rc;
++
++ /*
++ * Let's be a bit picky about the flags...
++ */
++ if (fOpen != (FREAD | FWRITE /*=O_RDWR*/))
++ {
++ Log(("VBoxDrvNetBSDOpen: fOpen=%#x expected %#x\n", fOpen, O_RDWR));
++ return EINVAL;
++ }
++
++ /*
++ * Create a new session.
++ */
++ rc = supdrvCreateSession(&g_VBoxDrvNetBSDDevExt, true /* fUser */, fUnrestricted, &pSession);
++ if (RT_SUCCESS(rc))
++ {
++ /** @todo get (r)uid and (r)gid.
++ pSession->Uid = stuff;
++ pSession->Gid = stuff; */
++ rc = devfs_set_cdevpriv(pSession, vboxdrvNetBSDDtr); Assert(rc == 0);
++ Log(("VBoxDrvNetBSDOpen: pSession=%p\n", pSession));
++ ASMAtomicIncU32(&g_cUsers);
++ return 0;
++ }
++
++ return RTErrConvertToErrno(rc);
++}
++
++
++/** For vboxdrv. */
++static int VBoxDrvNetBSDOpenSys(struct cdev *pDev, int fOpen, int iDevType, struct thread *pTd)
++{
++ return vboxdrvNetBSDOpenCommon(pDev, fOpen, iDevType, pTd, true);
++}
++
++
++/** For vboxdrvu. */
++static int VBoxDrvNetBSDOpenUsr(struct cdev *pDev, int fOpen, int iDevType, struct thread *pTd)
++{
++ return vboxdrvNetBSDOpenCommon(pDev, fOpen, iDevType, pTd, false);
++}
++
++
++/**
++ * Close a file device previously opened by VBoxDrvNetBSDOpen.
++ *
++ * @returns 0 on success.
++ * @param pvData The session being closed.
++ */
++static void vboxdrvNetBSDDtr(void *pvData)
++{
++ PSUPDRVSESSION pSession = pvData;
++ Log(("vboxdrvNetBSDDtr: pSession=%p\n", pSession));
++
++ /*
++ * Close the session.
++ */
++ supdrvSessionRelease(pSession);
++ ASMAtomicDecU32(&g_cUsers);
++}
++
++
++/**
++ * I/O control request.
++ *
++ * @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 VBoxDrvNetBSDIOCtl(struct cdev *pDev, u_long ulCmd, caddr_t pvData, int fFile, struct thread *pTd)
++{
++ PSUPDRVSESSION pSession;
++ devfs_get_cdevpriv((void **)&pSession);
++
++ /*
++ * Deal with the fast ioctl path first.
++ */
++ if ( ( ulCmd == SUP_IOCTL_FAST_DO_RAW_RUN
++ || ulCmd == SUP_IOCTL_FAST_DO_HM_RUN
++ || ulCmd == SUP_IOCTL_FAST_DO_NOP)
++ && pSession->fUnrestricted == true)
++ return supdrvIOCtlFast(ulCmd, *(uint32_t *)pvData, &g_VBoxDrvNetBSDDevExt, pSession);
++
++ return VBoxDrvNetBSDIOCtlSlow(pSession, ulCmd, pvData, pTd);
++}
++
++
++/**
++ * Deal with the 'slow' I/O control requests.
++ *
++ * @returns 0 on success, appropriate errno on failure.
++ * @param pSession The session.
++ * @param ulCmd The command.
++ * @param pvData The request data.
++ * @param pTd The calling thread.
++ */
++static int VBoxDrvNetBSDIOCtlSlow(PSUPDRVSESSION pSession, u_long ulCmd, caddr_t pvData, struct thread *pTd)
++{
++ PSUPREQHDR pHdr;
++ uint32_t cbReq = IOCPARM_LEN(ulCmd);
++ void *pvUser = NULL;
++
++ /*
++ * Buffered request?
++ */
++ if ((IOC_DIRMASK & ulCmd) == IOC_INOUT)
++ {
++ pHdr = (PSUPREQHDR)pvData;
++ if (RT_UNLIKELY(cbReq < sizeof(*pHdr)))
++ {
++ OSDBGPRINT(("VBoxDrvNetBSDIOCtlSlow: cbReq=%#x < %#x; ulCmd=%#lx\n", cbReq, (int)sizeof(*pHdr), ulCmd));
++ return EINVAL;
++ }
++ if (RT_UNLIKELY((pHdr->fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
++ {
++ OSDBGPRINT(("VBoxDrvNetBSDIOCtlSlow: bad magic fFlags=%#x; ulCmd=%#lx\n", pHdr->fFlags, ulCmd));
++ return EINVAL;
++ }
++ if (RT_UNLIKELY( RT_MAX(pHdr->cbIn, pHdr->cbOut) != cbReq
++ || pHdr->cbIn < sizeof(*pHdr)
++ || pHdr->cbOut < sizeof(*pHdr)))
++ {
++ OSDBGPRINT(("VBoxDrvNetBSDIOCtlSlow: max(%#x,%#x) != %#x; ulCmd=%#lx\n", pHdr->cbIn, pHdr->cbOut, cbReq, ulCmd));
++ return EINVAL;
++ }
++ }
++ /*
++ * Big unbuffered request?
++ */
++ else if ((IOC_DIRMASK & ulCmd) == IOC_VOID && !cbReq)
++ {
++ /*
++ * Read the header, validate it and figure out how much that needs to be buffered.
++ */
++ SUPREQHDR Hdr;
++ pvUser = *(void **)pvData;
++ int rc = copyin(pvUser, &Hdr, sizeof(Hdr));
++ if (RT_UNLIKELY(rc))
++ {
++ OSDBGPRINT(("VBoxDrvNetBSDIOCtlSlow: copyin(%p,Hdr,) -> %#x; ulCmd=%#lx\n", pvUser, rc, ulCmd));
++ return rc;
++ }
++ if (RT_UNLIKELY((Hdr.fFlags & SUPREQHDR_FLAGS_MAGIC_MASK) != SUPREQHDR_FLAGS_MAGIC))
++ {
++ OSDBGPRINT(("VBoxDrvNetBSDIOCtlSlow: bad magic fFlags=%#x; ulCmd=%#lx\n", Hdr.fFlags, ulCmd));
++ return EINVAL;
++ }
++ cbReq = RT_MAX(Hdr.cbIn, Hdr.cbOut);
++ if (RT_UNLIKELY( Hdr.cbIn < sizeof(Hdr)
++ || Hdr.cbOut < sizeof(Hdr)
++ || cbReq > _1M*16))
++ {
++ OSDBGPRINT(("VBoxDrvNetBSDIOCtlSlow: max(%#x,%#x); ulCmd=%#lx\n", Hdr.cbIn, Hdr.cbOut, ulCmd));
++ return EINVAL;
++ }
++
++ /*
++ * Allocate buffer and copy in the data.
++ */
++ pHdr = (PSUPREQHDR)RTMemTmpAlloc(cbReq);
++ if (RT_UNLIKELY(!pHdr))
++ {
++ OSDBGPRINT(("VBoxDrvNetBSDIOCtlSlow: failed to allocate buffer of %d bytes; ulCmd=%#lx\n", cbReq, ulCmd));
++ return ENOMEM;
++ }
++ rc = copyin(pvUser, pHdr, Hdr.cbIn);
++ if (RT_UNLIKELY(rc))
++ {
++ OSDBGPRINT(("VBoxDrvNetBSDIOCtlSlow: copyin(%p,%p,%#x) -> %#x; ulCmd=%#lx\n",
++ pvUser, pHdr, Hdr.cbIn, rc, ulCmd));
++ RTMemTmpFree(pHdr);
++ return rc;
++ }
++ if (Hdr.cbIn < cbReq)
++ RT_BZERO((uint8_t *)pHdr + Hdr.cbIn, cbReq - Hdr.cbIn);
++ }
++ else
++ {
++ Log(("VBoxDrvNetBSDIOCtlSlow: huh? cbReq=%#x ulCmd=%#lx\n", cbReq, ulCmd));
++ return EINVAL;
++ }
++
++ /*
++ * Process the IOCtl.
++ */
++ int rc = supdrvIOCtl(ulCmd, &g_VBoxDrvNetBSDDevExt, pSession, pHdr, cbReq);
++ if (RT_LIKELY(!rc))
++ {
++ /*
++ * If unbuffered, copy back the result before returning.
++ */
++ if (pvUser)
++ {
++ uint32_t cbOut = pHdr->cbOut;
++ if (cbOut > cbReq)
++ {
++ OSDBGPRINT(("VBoxDrvNetBSDIOCtlSlow: too much output! %#x > %#x; uCmd=%#lx!\n", cbOut, cbReq, ulCmd));
++ cbOut = cbReq;
++ }
++ rc = copyout(pHdr, pvUser, cbOut);
++ if (RT_UNLIKELY(rc))
++ OSDBGPRINT(("VBoxDrvNetBSDIOCtlSlow: copyout(%p,%p,%#x) -> %d; uCmd=%#lx!\n", pHdr, pvUser, cbOut, rc, ulCmd));
++
++ Log(("VBoxDrvNetBSDIOCtlSlow: returns %d / %d ulCmd=%lx\n", 0, pHdr->rc, ulCmd));
++
++ /* cleanup */
++ RTMemTmpFree(pHdr);
++ }
++ }
++ else
++ {
++ /*
++ * The request failed, just clean up.
++ */
++ if (pvUser)
++ RTMemTmpFree(pHdr);
++
++ Log(("VBoxDrvNetBSDIOCtlSlow: ulCmd=%lx pData=%p failed, rc=%d\n", ulCmd, pvData, rc));
++ rc = EINVAL;
++ }
++
++ return rc;
++}
++
++
++/**
++ * The SUPDRV IDC entry point.
++ *
++ * @returns VBox status code, see supdrvIDC.
++ * @param uReq The request code.
++ * @param pReq The request.
++ */
++int VBOXCALL SUPDrvNetBSDIDC(uint32_t uReq, PSUPDRVIDCREQHDR pReq)
++{
++ PSUPDRVSESSION pSession;
++
++ /*
++ * Some quick validations.
++ */
++ if (RT_UNLIKELY(!VALID_PTR(pReq)))
++ return VERR_INVALID_POINTER;
++
++ pSession = pReq->pSession;
++ if (pSession)
++ {
++ if (RT_UNLIKELY(!VALID_PTR(pReq->pSession)))
++ return VERR_INVALID_PARAMETER;
++ if (RT_UNLIKELY(pSession->pDevExt != &g_VBoxDrvNetBSDDevExt))
++ return VERR_INVALID_PARAMETER;
++ }
++ else if (RT_UNLIKELY(uReq != SUPDRV_IDC_REQ_CONNECT))
++ return VERR_INVALID_PARAMETER;
++
++ /*
++ * Do the job.
++ */
++ return supdrvIDC(uReq, &g_VBoxDrvNetBSDDevExt, pSession, pReq);
++}
++
++
++void VBOXCALL supdrvOSCleanupSession(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession)
++{
++ NOREF(pDevExt);
++ NOREF(pSession);
++}
++
++
++void VBOXCALL supdrvOSSessionHashTabInserted(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser)
++{
++ NOREF(pDevExt); NOREF(pSession); NOREF(pvUser);
++}
++
++
++void VBOXCALL supdrvOSSessionHashTabRemoved(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, void *pvUser)
++{
++ NOREF(pDevExt); NOREF(pSession); NOREF(pvUser);
++}
++
++
++void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
++{
++ NOREF(pObj);
++ NOREF(pSession);
++}
++
++
++bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
++{
++ NOREF(pObj);
++ NOREF(pSession);
++ NOREF(pszObjName);
++ NOREF(prc);
++ return false;
++}
++
++
++bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
++{
++ return false;
++}
++
++
++bool VBOXCALL supdrvOSAreCpusOfflinedOnSuspend(void)
++{
++ /** @todo verify this. */
++ return false;
++}
++
++
++bool VBOXCALL supdrvOSAreTscDeltasInSync(void)
++{
++ return false;
++}
++
++
++int VBOXCALL supdrvOSLdrOpen(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const char *pszFilename)
++{
++ NOREF(pDevExt); NOREF(pImage); NOREF(pszFilename);
++ return VERR_NOT_SUPPORTED;
++}
++
++
++void VBOXCALL supdrvOSLdrNotifyOpened(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
++{
++ NOREF(pDevExt); NOREF(pImage);
++}
++
++
++int VBOXCALL supdrvOSLdrValidatePointer(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, void *pv, const uint8_t *pbImageBits)
++{
++ NOREF(pDevExt); NOREF(pImage); NOREF(pv); NOREF(pbImageBits);
++ return VERR_NOT_SUPPORTED;
++}
++
++
++int VBOXCALL supdrvOSLdrLoad(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage, const uint8_t *pbImageBits, PSUPLDRLOAD pReq)
++{
++ NOREF(pDevExt); NOREF(pImage); NOREF(pbImageBits); NOREF(pReq);
++ return VERR_NOT_SUPPORTED;
++}
++
++
++void VBOXCALL supdrvOSLdrUnload(PSUPDRVDEVEXT pDevExt, PSUPDRVLDRIMAGE pImage)
++{
++ NOREF(pDevExt); NOREF(pImage);
++}
++
++
++#ifdef SUPDRV_WITH_MSR_PROBER
++
++int VBOXCALL supdrvOSMsrProberRead(uint32_t uMsr, RTCPUID idCpu, uint64_t *puValue)
++{
++ NOREF(uMsr); NOREF(idCpu); NOREF(puValue);
++ return VERR_NOT_SUPPORTED;
++}
++
++
++int VBOXCALL supdrvOSMsrProberWrite(uint32_t uMsr, RTCPUID idCpu, uint64_t uValue)
++{
++ NOREF(uMsr); NOREF(idCpu); NOREF(uValue);
++ return VERR_NOT_SUPPORTED;
++}
++
++
++int VBOXCALL supdrvOSMsrProberModify(RTCPUID idCpu, PSUPMSRPROBER pReq)
++{
++ NOREF(idCpu); NOREF(pReq);
++ return VERR_NOT_SUPPORTED;
++}
++
++#endif /* SUPDRV_WITH_MSR_PROBER */
++
++
++SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...)
++{
++ va_list va;
++ char szMsg[256];
++ int cch;
++
++ va_start(va, pszFormat);
++ cch = RTStrPrintfV(szMsg, sizeof(szMsg), pszFormat, va);
++ va_end(va);
++
++ printf("%s", szMsg);
++
++ return cch;
++}
++
++
++SUPR0DECL(uint32_t) SUPR0GetKernelFeatures(void)
++{
++ return 0;
++}
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.def b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.def
new file mode 100644
index 0000000..346e5c8
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPDrv-netbsd.def
@@ -0,0 +1,6 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/netbsd/SUPDrv-netbsd.def.orig 2016-07-07 07:08:46.496688121 +0000
++++ src/VBox/HostDrivers/Support/netbsd/SUPDrv-netbsd.def
+@@ -0,0 +1 @@
++SUPDrvNetBSDIDC
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPLib-netbsd.cpp b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPLib-netbsd.cpp
new file mode 100644
index 0000000..985b7a4
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPLib-netbsd.cpp
@@ -0,0 +1,190 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/netbsd/SUPLib-netbsd.cpp.orig 2016-07-07 07:08:46.506033890 +0000
++++ src/VBox/HostDrivers/Support/netbsd/SUPLib-netbsd.cpp
+@@ -0,0 +1,185 @@
++/* SUPLib-netbsd.cpp $ */
++/** @file
++ * VirtualBox Support Library - NetBSD specific parts.
++ */
++
++/*
++ * Copyright (C) 2006-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#define LOG_GROUP LOG_GROUP_SUP
++#ifdef IN_SUP_HARDENED_R3
++# undef DEBUG /* Warning: disables RT_STRICT */
++# define LOG_DISABLED
++# define RTLOG_REL_DISABLED
++# include <iprt/log.h>
++#endif
++
++#include <VBox/types.h>
++#include <VBox/sup.h>
++#include <VBox/param.h>
++#include <VBox/err.h>
++#include <VBox/log.h>
++#include <iprt/path.h>
++#include <iprt/assert.h>
++#include <iprt/mem.h>
++#include <iprt/err.h>
++#include <iprt/string.h>
++#include "../SUPLibInternal.h"
++#include "../SUPDrvIOC.h"
++
++#include <sys/fcntl.h>
++#include <sys/ioctl.h>
++#include <errno.h>
++#include <unistd.h>
++#include <stdlib.h>
++#include <stdio.h>
++
++
++/*********************************************************************************************************************************
++* Defined Constants And Macros *
++*********************************************************************************************************************************/
++/** System device name. */
++#define DEVICE_NAME_SYS "/dev/vboxdrv"
++/** User device name. */
++#define DEVICE_NAME_USR "/dev/vboxdrvu"
++
++
++
++int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted, SUPINITOP *penmWhat, PRTERRINFO pErrInfo)
++{
++ /*
++ * Nothing to do if pre-inited.
++ */
++ if (fPreInited)
++ return VINF_SUCCESS;
++
++ /*
++ * Try open the BSD device.
++ */
++ int hDevice = open(fUnrestricted ? DEVICE_NAME_SYS : DEVICE_NAME_USR, O_RDWR, 0);
++ if (hDevice < 0)
++ {
++ int rc;
++ switch (errno)
++ {
++ case ENODEV: rc = VERR_VM_DRIVER_LOAD_ERROR; break;
++ case EPERM:
++ case EACCES: rc = VERR_VM_DRIVER_NOT_ACCESSIBLE; break;
++ case ENOENT: rc = VERR_VM_DRIVER_NOT_INSTALLED; break;
++ default: rc = VERR_VM_DRIVER_OPEN_ERROR; break;
++ }
++ LogRel(("Failed to open \"%s\", errno=%d, rc=%Rrc\n", fUnrestricted ? DEVICE_NAME_SYS : DEVICE_NAME_USR, errno, rc));
++ return rc;
++ }
++
++ /*
++ * Mark the file handle close on exec.
++ */
++ if (fcntl(hDevice, F_SETFD, FD_CLOEXEC) != 0)
++ {
++#ifdef IN_SUP_HARDENED_R3
++ int rc = VERR_INTERNAL_ERROR;
++#else
++ int err = errno;
++ int rc = RTErrConvertFromErrno(err);
++ LogRel(("suplibOSInit: setting FD_CLOEXEC failed, errno=%d (%Rrc)\n", err, rc));
++#endif
++ close(hDevice);
++ return rc;
++ }
++
++ /*
++ * We're done.
++ */
++ pThis->hDevice = hDevice;
++ pThis->fUnrestricted = fUnrestricted;
++ return VINF_SUCCESS;
++}
++
++
++#ifndef IN_SUP_HARDENED_R3
++
++int suplibOsTerm(PSUPLIBDATA pThis)
++{
++ /*
++ * Check if we're inited at all.
++ */
++ if (pThis->hDevice != (intptr_t)NIL_RTFILE)
++ {
++ if (close(pThis->hDevice))
++ AssertFailed();
++ pThis->hDevice = (intptr_t)NIL_RTFILE;
++ }
++ return VINF_SUCCESS;
++}
++
++
++int suplibOsInstall(void)
++{
++ return VERR_NOT_IMPLEMENTED;
++}
++
++
++int suplibOsUninstall(void)
++{
++ return VERR_NOT_IMPLEMENTED;
++}
++
++
++int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
++{
++ if (RT_LIKELY(ioctl(pThis->hDevice, uFunction, pvReq) >= 0))
++ return VINF_SUCCESS;
++ return RTErrConvertFromErrno(errno);
++}
++
++
++int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu)
++{
++ int rc = ioctl(pThis->hDevice, uFunction, idCpu);
++ if (rc == -1)
++ rc = errno;
++ return rc;
++}
++
++
++int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
++{
++ NOREF(pThis);
++ *ppvPages = RTMemPageAllocZ(cPages << PAGE_SHIFT);
++ if (*ppvPages)
++ return VINF_SUCCESS;
++ return RTErrConvertFromErrno(errno);
++}
++
++
++int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t cPages)
++{
++ NOREF(pThis);
++ RTMemPageFree(pvPages, cPages * PAGE_SIZE);
++ return VINF_SUCCESS;
++}
++
++#endif /* !IN_SUP_HARDENED_R3 */
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPR0IdcClient-netbsd.c b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPR0IdcClient-netbsd.c
new file mode 100644
index 0000000..c4634a5
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_SUPR0IdcClient-netbsd.c
@@ -0,0 +1,60 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/netbsd/SUPR0IdcClient-netbsd.c.orig 2016-07-07 07:08:46.515663297 +0000
++++ src/VBox/HostDrivers/Support/netbsd/SUPR0IdcClient-netbsd.c
+@@ -0,0 +1,55 @@
++/* SUPR0IdcClient-netbsd.c $ */
++/** @file
++ * VirtualBox Support Driver - IDC Client Lib, NetBSD Specific Code.
++ */
++
++/*
++ * Copyright (C) 2008-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "../SUPR0IdcClientInternal.h"
++#include <VBox/err.h>
++
++
++int VBOXCALL supR0IdcNativeOpen(PSUPDRVIDCHANDLE pHandle, PSUPDRVIDCREQCONNECT pReq)
++{
++ return supR0IdcNativeCall(pHandle, SUPDRV_IDC_REQ_CONNECT, &pReq->Hdr);
++}
++
++
++int VBOXCALL supR0IdcNativeClose(PSUPDRVIDCHANDLE pHandle, PSUPDRVIDCREQHDR pReq)
++{
++ return supR0IdcNativeCall(pHandle, SUPDRV_IDC_REQ_DISCONNECT, pReq);
++}
++
++
++int VBOXCALL supR0IdcNativeCall(PSUPDRVIDCHANDLE pHandle, uint32_t iReq, PSUPDRVIDCREQHDR pReq)
++{
++ int rc = SUPDrvNetBSDIDC(iReq, pReq);
++ if (RT_SUCCESS(rc))
++ rc = pReq->rc;
++
++ NOREF(pHandle);
++ return rc;
++}
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_files__vboxdrv b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_files__vboxdrv
new file mode 100644
index 0000000..8384c93
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_Support_netbsd_files__vboxdrv
@@ -0,0 +1,218 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/Support/netbsd/files_vboxdrv.orig 2016-07-07 07:08:46.524933547 +0000
++++ src/VBox/HostDrivers/Support/netbsd/files_vboxdrv
+@@ -0,0 +1,213 @@
++#!/bin/sh
++# files_vboxdrv $
++## @file
++# Shared file between Makefile.kmk and export_modules
++#
++
++#
++# Copyright (C) 2007-2015 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.
++#
++
++FILES_VBOXDRV_NOBIN=" \
++ ${PATH_ROOT}/include/iprt/alloc.h=>include/iprt/alloc.h \
++ ${PATH_ROOT}/include/iprt/alloca.h=>include/iprt/alloca.h \
++ ${PATH_ROOT}/include/iprt/asm.h=>include/iprt/asm.h \
++ ${PATH_ROOT}/include/iprt/asm-amd64-x86.h=>include/iprt/asm-amd64-x86.h \
++ ${PATH_ROOT}/include/iprt/asm-math.h=>include/iprt/asm-math.h \
++ ${PATH_ROOT}/include/iprt/assert.h=>include/iprt/assert.h \
++ ${PATH_ROOT}/include/iprt/avl.h=>include/iprt/avl.h \
++ ${PATH_ROOT}/include/iprt/cdefs.h=>include/iprt/cdefs.h \
++ ${PATH_ROOT}/include/iprt/cpuset.h=>include/iprt/cpuset.h \
++ ${PATH_ROOT}/include/iprt/crc.h=>include/iprt/crc.h \
++ ${PATH_ROOT}/include/iprt/ctype.h=>include/iprt/ctype.h \
++ ${PATH_ROOT}/include/iprt/err.h=>include/iprt/err.h \
++ ${PATH_ROOT}/include/iprt/errno.h=>include/iprt/errno.h \
++ ${PATH_ROOT}/include/iprt/heap.h=>include/iprt/heap.h \
++ ${PATH_ROOT}/include/iprt/handletable.h=>include/iprt/handletable.h \
++ ${PATH_ROOT}/include/iprt/initterm.h=>include/iprt/initterm.h \
++ ${PATH_ROOT}/include/iprt/latin1.h=>include/iprt/latin1.h \
++ ${PATH_ROOT}/include/iprt/list.h=>include/iprt/list.h \
++ ${PATH_ROOT}/include/iprt/log.h=>include/iprt/log.h \
++ ${PATH_ROOT}/include/iprt/mangling.h=>include/iprt/mangling.h \
++ ${PATH_ROOT}/include/iprt/mem.h=>include/iprt/mem.h \
++ ${PATH_ROOT}/include/iprt/memobj.h=>include/iprt/memobj.h \
++ ${PATH_ROOT}/include/iprt/mp.h=>include/iprt/mp.h \
++ ${PATH_ROOT}/include/iprt/net.h=>include/iprt/net.h \
++ ${PATH_ROOT}/include/iprt/param.h=>include/iprt/param.h \
++ ${PATH_ROOT}/include/iprt/power.h=>include/iprt/power.h \
++ ${PATH_ROOT}/include/iprt/process.h=>include/iprt/process.h \
++ ${PATH_ROOT}/include/iprt/semaphore.h=>include/iprt/semaphore.h \
++ ${PATH_ROOT}/include/iprt/spinlock.h=>include/iprt/spinlock.h \
++ ${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/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 \
++ ${PATH_ROOT}/include/iprt/types.h=>include/iprt/types.h \
++ ${PATH_ROOT}/include/iprt/uint128.h=>include/iprt/uint128.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 \
++ ${PATH_ROOT}/include/iprt/net.h=>include/iprt/net.h \
++ ${PATH_ROOT}/include/iprt/rand.h=>include/iprt/rand.h \
++ ${PATH_ROOT}/include/iprt/path.h=>include/iprt/path.h \
++ ${PATH_ROOT}/include/iprt/once.h=>include/iprt/once.h \
++ ${PATH_ROOT}/include/iprt/critsect.h=>include/iprt/critsect.h \
++ ${PATH_ROOT}/include/iprt/x86.h=>include/iprt/x86.h \
++ ${PATH_ROOT}/include/iprt/lockvalidator.h=>include/iprt/lockvalidator.h \
++ ${PATH_ROOT}/include/iprt/nocrt/limits.h=>include/iprt/nocrt/limits.h \
++ ${PATH_ROOT}/include/VBox/cdefs.h=>include/VBox/cdefs.h \
++ ${PATH_ROOT}/include/VBox/err.h=>include/VBox/err.h \
++ ${PATH_ROOT}/include/VBox/log.h=>include/VBox/log.h \
++ ${PATH_ROOT}/include/VBox/param.h=>include/VBox/param.h \
++ ${PATH_ROOT}/include/VBox/sup.h=>include/VBox/sup.h \
++ ${PATH_ROOT}/include/VBox/types.h=>include/VBox/types.h \
++ ${PATH_ROOT}/include/VBox/version.h=>include/VBox/version.h \
++ ${PATH_ROOT}/include/VBox/SUPDrvMangling.h=>include/VBox/SUPDrvMangling.h \
++ ${PATH_ROOT}/include/VBox/VBoxTpG.h=>include/VBox/VBoxTpG.h \
++ ${PATH_ROOT}/include/VBox/vmm/hm_vmx.h=>include/VBox/vmm/hm_vmx.h \
++ ${PATH_ROOT}/include/VBox/vmm/hm_svm.h=>include/VBox/vmm/hm_svm.h \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/netbsd/SUPDrv-netbsd.c=>netbsd/SUPDrv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPDrv.cpp=>SUPDrv.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPDrvGip.cpp=>SUPDrvGip.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPDrvSem.cpp=>SUPDrvSem.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPDrvTracer.cpp=>SUPDrvTracer.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPDrvIDC.h=>SUPDrvIDC.h \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPDrvIOC.h=>SUPDrvIOC.h \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPDrvInternal.h=>SUPDrvInternal.h \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPLibAll.cpp=>SUPLibAll.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/alloc/heapsimple.cpp=>alloc/heapsimple.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/alloc/alloc.cpp=>alloc/alloc.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/err/RTErrConvertFromErrno.cpp=>common/err/RTErrConvertFromErrno.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/err/RTErrConvertToErrno.cpp=>common/err/RTErrConvertToErrno.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/log.cpp=>common/log/log.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/logellipsis.cpp=>common/log/logellipsis.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/logrel.cpp=>common/log/logrel.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/logrelellipsis.cpp=>common/log/logrelellipsis.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/logcom.cpp=>common/log/logcom.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/log/logformat.cpp=>common/log/logformat.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 \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2Add.cpp=>common/misc/RTAssertMsg2Add.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2AddWeak.cpp=>common/misc/RTAssertMsg2AddWeak.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2AddWeakV.cpp=>common/misc/RTAssertMsg2AddWeakV.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2Weak.cpp=>common/misc/RTAssertMsg2Weak.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/RTAssertMsg2WeakV.cpp=>common/misc/RTAssertMsg2WeakV.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/misc/assert.cpp=>common/misc/assert.c \
++ ${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/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/string/RTStrCopyP.cpp=>common/string/RTStrCopyP.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/RTStrCopy.cpp=>common/string/RTStrCopy.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/RTStrCopyEx.cpp=>common/string/RTStrCopyEx.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/RTStrNCmp.cpp=>common/string/RTStrNCmp.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/RTStrNLen.cpp=>common/string/RTStrNLen.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/strformat.cpp=>common/string/strformat.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/strformatrt.cpp=>common/string/strformatrt.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/strformattype.cpp=>common/string/strformattype.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/string/strprintf.cpp=>common/string/strprintf.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/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 \
++ ${PATH_ROOT}/src/VBox/Runtime/common/rand/randparkmiller.cpp=>common/rand/randparkmiller.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/path/RTPathStripFilename.cpp=>common/path/RTPathStripFilename.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/checksum/crc32.cpp=>common/checksum/crc32.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/checksum/ipv4.cpp=>common/checksum/ipv4.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/checksum/ipv6.cpp=>common/checksum/ipv6.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avlpv.cpp=>common/table/avlpv.c \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_Base.cpp.h=>common/table/avl_Base.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_Get.cpp.h=>common/table/avl_Get.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_GetBestFit.cpp.h=>common/table/avl_GetBestFit.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_RemoveBestFit.cpp.h=>common/table/avl_RemoveBestFit.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_DoWithAll.cpp.h=>common/table/avl_DoWithAll.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/table/avl_Destroy.cpp.h=>common/table/avl_Destroy.cpp.h \
++ ${PATH_ROOT}/src/VBox/Runtime/common/time/time.cpp=>common/time/time.c \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/assert.h=>include/internal/assert.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/initterm.h=>include/internal/initterm.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/iprt.h=>include/internal/iprt.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/lockvalidator.h=>include/internal/lockvalidator.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/magics.h=>include/internal/magics.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/memobj.h=>include/internal/memobj.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/string.h=>include/internal/string.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/thread.h=>include/internal/thread.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/rand.h=>include/internal/rand.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/sched.h=>include/internal/sched.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/process.h=>include/internal/process.h \
++ ${PATH_ROOT}/src/VBox/Runtime/include/internal/time.h=>include/internal/time.h \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTAssertShouldPanic-generic.cpp=>generic/RTAssertShouldPanic-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTLogWriteStdErr-stub-generic.cpp=>generic/RTLogWriteStdErr-stub-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTLogWriteStdOut-stub-generic.cpp=>generic/RTLogWriteStdOut-stub-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTLogWriteUser-generic.cpp=>generic/RTLogWriteUser-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTLogWriteDebugger-generic.cpp=>generic/RTLogWriteDebugger-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTRandAdvCreateSystemFaster-generic.cpp=>generic/RTRandAdvCreateSystemFaster-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTRandAdvCreateSystemTruer-generic.cpp=>generic/RTRandAdvCreateSystemTruer-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTSemEventWait-2-ex-generic.cpp=>generic/RTSemEventWait-2-ex-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTSemEventWaitNoResume-2-ex-generic.cpp=>generic/RTSemEventWaitNoResume-2-ex-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTSemEventMultiWait-2-ex-generic.cpp=>generic/RTSemEventMultiWait-2-ex-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp=>generic/RTSemEventMultiWaitNoResume-2-ex-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTTimerCreate-generic.cpp=>generic/RTTimerCreate-generic.c \
++ ${PATH_ROOT}/src/VBox/Runtime/generic/RTMpGetArraySize-generic.cpp=>generic/RTMpGetArraySize-generic.c \
++ ${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/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 \
++ ${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 \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/mp-r0drv.h=>r0drv/mp-r0drv.h \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/power-r0drv.h=>r0drv/power-r0drv.h \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/powernotification-r0drv.c=>r0drv/powernotification-r0drv.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/assert-r0drv-netbsd.c=>r0drv/netbsd/assert-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/alloc-r0drv-netbsd.c=>r0drv/netbsd/alloc-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/initterm-r0drv-netbsd.c=>r0drv/netbsd/initterm-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c=>r0drv/netbsd/memobj-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/memuserkernel-r0drv-netbsd.c=>r0drv/netbsd/memuserkernel-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/mp-r0drv-netbsd.c=>r0drv/netbsd/mp-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/process-r0drv-netbsd.c=>r0drv/netbsd/process-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/semevent-r0drv-netbsd.c=>r0drv/netbsd/semevent-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/semeventmulti-r0drv-netbsd.c=>r0drv/netbsd/semeventmulti-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/semfastmutex-r0drv-netbsd.c=>r0drv/netbsd/semfastmutex-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/semmutex-r0drv-netbsd.c=>r0drv/netbsd/semmutex-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/spinlock-r0drv-netbsd.c=>r0drv/netbsd/spinlock-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/the-netbsd-kernel.h=>r0drv/netbsd/the-netbsd-kernel.h \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/thread-r0drv-netbsd.c=>r0drv/netbsd/thread-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/thread2-r0drv-netbsd.c=>r0drv/netbsd/thread2-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/time-r0drv-netbsd.c=>r0drv/netbsd/time-r0drv-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/sleepqueue-r0drv-netbsd.h=>r0drv/netbsd/sleepqueue-r0drv-netbsd.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 \
++ ${PATH_OUT}/version-generated.h=>version-generated.h \
++ ${PATH_OUT}/product-generated.h=>product-generated.h \
++"
++
++FILES_VBOXDRV_BIN=" \
++"
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_Makefile.kmk b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_Makefile.kmk
new file mode 100644
index 0000000..2c8eb72
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_Makefile.kmk
@@ -0,0 +1,64 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/VBoxNetAdp/Makefile.kmk.orig 2016-03-04 19:29:26.000000000 +0000
++++ src/VBox/HostDrivers/VBoxNetAdp/Makefile.kmk
+@@ -18,7 +18,7 @@
+ SUB_DEPTH = ../../../..
+ include $(KBUILD_PATH)/subheader.kmk
+
+-if1of ($(KBUILD_TARGET), solaris darwin linux freebsd)
++if1of ($(KBUILD_TARGET), solaris darwin linux freebsd netbsd)
+ #
+ # VBoxNetAdp - Virtual Network Adapter
+ # Note! On Solaris the name has to be <= 8 chars long.
+@@ -31,6 +31,7 @@ if1of ($(KBUILD_TARGET), solaris darwin
+ VBoxNetAdp_NAME.solaris = vboxnet
+ VBoxNetAdp_NAME.linux = vboxnetadp
+ VBoxNetAdp_NAME.freebsd = vboxnetadp
++ VBoxNetAdp_NAME.netbsd = vboxnetadp
+ VBoxNetAdp_DEPS.solaris += $(VBOX_SVN_REV_KMK)
+ VBoxNetAdp_DEFS = IN_RT_R0 VBOX_SVN_REV=$(VBOX_SVN_REV) IN_SUP_STATIC
+ VBoxNetAdp_DEFS.linux = KBUILD_MODNAME=KBUILD_STR\(vboxnetadp\) KBUILD_BASENAME=KBUILD_STR\(vboxnetadp\) MODULE
+@@ -51,6 +52,9 @@ if1of ($(KBUILD_TARGET), solaris darwin
+ VBoxNetAdp_SOURCES.freebsd = \
+ freebsd/VBoxNetAdp-freebsd.c \
+ VBoxNetAdp.c
++ VBoxNetAdp_SOURCES.netbsd = \
++ freebsd/VBoxNetAdp-netbsd.c \
++ VBoxNetAdp.c
+ VBoxNetAdp_SOURCES =
+ #VBoxNetAdp_SOURCES = \
+ # VBoxNetAdp.c
+@@ -211,5 +215,31 @@ $$(VBoxNetAdp-src_0_OUTDIR)/Makefile: \
+
+ endif # freebsd
+
+-include $(FILE_KBUILD_SUB_FOOTER)
++ifeq ($(KBUILD_TARGET),netbsd)
++ #
++ # Install source files for compilation on NetBSD.
++ # files_vboxnetadp defines VBOX_VBOXNETADP_SOURCES.
++ #
++ INSTALLS += VBoxNetAdp-src
++ include $(PATH_SUB_CURRENT)/netbsd/files_vboxnetadp
++ VBoxNetAdp-src_INST = bin/src/vboxnetadp/
++ VBoxNetAdp-src_SOURCES = \
++ $(subst $(DQUOTE),,$(VBOX_VBOXNETADP_SOURCES)) \
++ $(VBoxNetAdp-src_0_OUTDIR)/Makefile
++ VBoxNetAdp-src_CLEAN = \
++ $(VBoxNetAdp-src_0_OUTDIR)/Makefile \
+
++$$(VBoxNetAdp-src_0_OUTDIR)/Makefile: \
++ $(PATH_SUB_CURRENT)/netbsd/Makefile \
++ $$(if $$(eq $$(VBoxNetAdp/netbsd/Makefile_VBOX_HARDENED),$$(VBOX_WITH_HARDENING)),,FORCE) \
++ | $$(dir $$@)
++ $(QUIET)$(RM) -f -- $@
++ ifndef VBOX_WITH_HARDENING
++ $(QUIET)$(SED) -e "s;-DVBOX_WITH_HARDENING;;g" --output $@ $<
++ else
++ $(QUIET)$(CP) -f $< $@
++ endif
++
++endif # netbsd
++
++include $(FILE_KBUILD_SUB_FOOTER)
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_VBoxNetAdpInternal.h b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_VBoxNetAdpInternal.h
new file mode 100644
index 0000000..78ddcfc
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_VBoxNetAdpInternal.h
@@ -0,0 +1,21 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h.orig 2016-03-04 19:29:26.000000000 +0000
++++ src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h
+@@ -113,6 +113,11 @@ struct VBoxNetAdapter
+ * @{ */
+ struct ifnet *ifp;
+ /** @} */
++# elif defined(RT_OS_NETBSD)
++ /** @name NetBSD instance data.
++ * @{ */
++ struct ifnet *ifp;
++ /** @} */
+ # else
+ # error PORTME
+ # endif
+@@ -178,4 +183,3 @@ DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOX
+ RT_C_DECLS_END
+
+ #endif
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_Makefile b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_Makefile
new file mode 100644
index 0000000..0f9b087
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_Makefile
@@ -0,0 +1,40 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/VBoxNetAdp/netbsd/Makefile.orig 2016-07-07 07:08:46.534055230 +0000
++++ src/VBox/HostDrivers/VBoxNetAdp/netbsd/Makefile
+@@ -0,0 +1,35 @@
++# Makefile $
++## @file
++# Makefile for the VirtualBox NetBSD Host Driver.
++#
++
++#
++#
++# Copyright (C) 2006-2015 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.
++#
++
++KMOD = vboxnetadp
++
++CFLAGS += -DRT_OS_NETBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -Iinclude -I. -Ir0drv -w -DVBOX_WITH_HARDENING -DVIMAGE
++
++.if (${MACHINE_ARCH} == "i386")
++ CFLAGS += -DRT_ARCH_X86
++.elif (${MACHINE_ARCH} == "amd64")
++ CFLAGS += -DRT_ARCH_AMD64
++.endif
++
++SRCS = \
++ VBoxNetAdp-netbsd.c \
++ VBoxNetAdp.c
++
++SRCS += device_if.h bus_if.h
++
++.include <bsd.kmod.mk>
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_VBoxNetAdp-netbsd.c b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_VBoxNetAdp-netbsd.c
new file mode 100644
index 0000000..f3ccfe5
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_VBoxNetAdp-netbsd.c
@@ -0,0 +1,331 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/VBoxNetAdp/netbsd/VBoxNetAdp-netbsd.c.orig 2016-07-07 07:08:46.543692306 +0000
++++ src/VBox/HostDrivers/VBoxNetAdp/netbsd/VBoxNetAdp-netbsd.c
+@@ -0,0 +1,326 @@
++/* VBoxNetAdp-netbsd.c $ */
++/** @file
++ * VBoxNetAdp - Virtual Network Adapter Driver (Host), NetBSD Specific Code.
++ */
++
++/*-
++ * Copyright (c) 2009 Fredrik Lindberg <fli%shapeshifter.se@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include <sys/param.h>
++#undef PVM
++#include <sys/types.h>
++#include <sys/module.h>
++#include <sys/systm.h>
++#include <sys/errno.h>
++#include <sys/kernel.h>
++#include <sys/fcntl.h>
++#include <sys/conf.h>
++#include <sys/uio.h>
++#include <sys/socket.h>
++#include <sys/sockio.h>
++
++#include <net/if.h>
++#include <net/if_var.h>
++#include <net/route.h>
++#include <net/if_dl.h>
++#include <net/if_media.h>
++#include <net/if_types.h>
++#include <net/ethernet.h>
++#include <net/bpf.h>
++
++#define LOG_GROUP LOG_GROUP_NET_ADP_DRV
++#include <VBox/version.h>
++#include <VBox/err.h>
++#include <VBox/log.h>
++#include <iprt/initterm.h>
++#include <iprt/string.h>
++#include <iprt/spinlock.h>
++#include <iprt/process.h>
++#include <iprt/assert.h>
++#include <iprt/uuid.h>
++#include <iprt/alloc.h>
++#include <iprt/err.h>
++
++#define VBOXNETADP_OS_SPECFIC 1
++#include "../VBoxNetAdpInternal.h"
++
++# include <sys/jail.h>
++# include <net/vnet.h>
++
++# define VBOXCURVNET_SET(arg) CURVNET_SET_QUIET(arg)
++# define VBOXCURVNET_SET_FROM_UCRED() VBOXCURVNET_SET(CRED_TO_VNET(curthread->td_ucred))
++# define VBOXCURVNET_RESTORE() CURVNET_RESTORE()
++
++static int VBoxNetAdpNetBSDCtrlioctl(struct cdev *, u_long, caddr_t, int flags,
++ struct thread *);
++static struct cdevsw vboxnetadp_cdevsw =
++{
++ .d_version = D_VERSION,
++ .d_ioctl = VBoxNetAdpNetBSDCtrlioctl,
++ .d_read = (d_read_t *)nullop,
++ .d_write = (d_write_t *)nullop,
++ .d_name = VBOXNETADP_CTL_DEV_NAME,
++};
++
++static struct cdev *VBoxNetAdpNetBSDcdev;
++
++static int VBoxNetAdpNetBSDModuleEvent(struct module *, int, void *);
++static moduledata_t g_VBoxNetAdpNetBSDModule = {
++ "vboxnetadp",
++ VBoxNetAdpNetBSDModuleEvent,
++ NULL
++};
++
++/** Declare the module as a pseudo device. */
++DECLARE_MODULE(vboxnetadp, g_VBoxNetAdpNetBSDModule, SI_SUB_PSEUDO, SI_ORDER_ANY);
++MODULE_VERSION(vboxnetadp, 1);
++MODULE_DEPEND(vboxnetadp, vboxdrv, 1, 1, 1);
++MODULE_DEPEND(vboxnetadp, vboxnetflt, 1, 1, 1);
++
++/**
++ * Module event handler
++ */
++static int
++VBoxNetAdpNetBSDModuleEvent(struct module *pMod, int enmEventType, void *pvArg)
++{
++ int rc = 0;
++
++ Log(("VBoxNetAdpNetBSDModuleEvent\n"));
++
++ switch (enmEventType)
++ {
++ case MOD_LOAD:
++ rc = RTR0Init(0);
++ if (RT_FAILURE(rc))
++ {
++ Log(("RTR0Init failed %d\n", rc));
++ return RTErrConvertToErrno(rc);
++ }
++ rc = vboxNetAdpInit();
++ if (RT_FAILURE(rc))
++ {
++ RTR0Term();
++ Log(("vboxNetAdpInit failed %d\n", rc));
++ return RTErrConvertToErrno(rc);
++ }
++ /* Create dev node */
++ VBoxNetAdpNetBSDcdev = make_dev(&vboxnetadp_cdevsw, 0,
++ UID_ROOT, GID_WHEEL, 0600, VBOXNETADP_CTL_DEV_NAME);
++
++ break;
++
++ case MOD_UNLOAD:
++ vboxNetAdpShutdown();
++ destroy_dev(VBoxNetAdpNetBSDcdev);
++ RTR0Term();
++ break;
++ case MOD_SHUTDOWN:
++ case MOD_QUIESCE:
++ default:
++ return EOPNOTSUPP;
++ }
++
++ if (RT_SUCCESS(rc))
++ return 0;
++ return RTErrConvertToErrno(rc);
++}
++
++/**
++ * Device I/O Control entry point.
++ */
++static int
++VBoxNetAdpNetBSDCtrlioctl(struct cdev *dev, u_long iCmd, caddr_t data, int flags, struct thread *td)
++{
++ PVBOXNETADP pAdp;
++ PVBOXNETADPREQ pReq = (PVBOXNETADPREQ)data;
++ struct ifnet *ifp;
++ int rc;
++
++ switch (iCmd)
++ {
++ case VBOXNETADP_CTL_ADD:
++ if ( !(iCmd & IOC_INOUT) /* paranoia*/
++ || IOCPARM_LEN(iCmd) < sizeof(*pReq))
++ return EINVAL;
++
++ rc = vboxNetAdpCreate(&pAdp,
++ pReq->szName[0] && RTStrEnd(pReq->szName, RT_MIN(IOCPARM_LEN(iCmd), sizeof(pReq->szName))) ?
++ pReq->szName : NULL);
++ if (RT_FAILURE(rc))
++ return EINVAL;
++
++ strncpy(pReq->szName, pAdp->szName, sizeof(pReq->szName) - 1);
++ pReq->szName[sizeof(pReq->szName) - 1] = '\0';
++ break;
++
++ case VBOXNETADP_CTL_REMOVE:
++ if (!RTStrEnd(pReq->szName, RT_MIN(sizeof(pReq->szName), IOCPARM_LEN(iCmd))))
++ return EINVAL;
++
++ pAdp = vboxNetAdpFindByName(pReq->szName);
++ if (!pAdp)
++ return EINVAL;
++
++ rc = vboxNetAdpDestroy(pAdp);
++ if (RT_FAILURE(rc))
++ return EINVAL;
++
++ break;
++
++ default:
++ return EINVAL;
++ }
++ return 0;
++}
++
++/**
++ * Initialize device, just set the running flag.
++ */
++static void VBoxNetAdpNetBSDNetinit(void *priv)
++{
++ PVBOXNETADP pThis = priv;
++ struct ifnet *ifp = pThis->u.s.ifp;
++
++ ifp->if_drv_flags |= IFF_DRV_RUNNING;
++}
++
++/**
++ * Transmit packets.
++ * netflt has already done everything for us so we just hand the
++ * packets to BPF and increment the packet stats.
++ */
++static void VBoxNetAdpNetBSDNetstart(struct ifnet *ifp)
++{
++ PVBOXNETADP pThis = ifp->if_softc;
++ struct mbuf *m;
++
++ if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != IFF_DRV_RUNNING)
++ return;
++
++ ifp->if_drv_flags |= IFF_DRV_OACTIVE;
++ while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
++ {
++ ifp->if_opackets++;
++ IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
++ BPF_MTAP(ifp, m);
++ m_freem(m);
++ }
++ ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
++}
++
++/**
++ * Interface ioctl handling
++ */
++static int VBoxNetAdpNetBSDNetioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
++{
++ int error = 0;
++
++ switch (cmd)
++ {
++ case SIOCSIFFLAGS:
++ if (ifp->if_flags & IFF_UP)
++ {
++ if (!(ifp->if_drv_flags & IFF_DRV_RUNNING))
++ ifp->if_init(ifp->if_softc);
++ }
++ else
++ {
++ if (ifp->if_drv_flags & IFF_DRV_RUNNING)
++ ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
++ }
++ break;
++ case SIOCGIFMEDIA:
++ {
++ struct ifmediareq *ifmr;
++ int count;
++
++ ifmr = (struct ifmediareq *)data;
++ count = ifmr->ifm_count;
++ ifmr->ifm_count = 1;
++ ifmr->ifm_status = IFM_AVALID;
++ ifmr->ifm_active = IFM_ETHER;
++ ifmr->ifm_status |= IFM_ACTIVE;
++ ifmr->ifm_current = ifmr->ifm_active;
++ if (count >= 1)
++ {
++ int media = IFM_ETHER;
++ error = copyout(&media, ifmr->ifm_ulist, sizeof(int));
++ }
++ break;
++ }
++ default:
++ return ether_ioctl(ifp, cmd, data);
++ }
++ return error;
++}
++
++int vboxNetAdpOsInit(PVBOXNETADP pThis)
++{
++ pThis->u.s.ifp = NULL;
++ return VINF_SUCCESS;;
++}
++
++int vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac)
++{
++ struct ifnet *ifp;
++
++ VBOXCURVNET_SET_FROM_UCRED();
++ ifp = if_alloc(IFT_ETHER);
++ if (ifp == NULL)
++ return VERR_NO_MEMORY;
++
++ if_initname(ifp, VBOXNETADP_NAME, pThis->iUnit);
++ ifp->if_softc = pThis;
++ ifp->if_mtu = ETHERMTU;
++ ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
++ ifp->if_ioctl = VBoxNetAdpNetBSDNetioctl;
++ ifp->if_start = VBoxNetAdpNetBSDNetstart;
++ ifp->if_init = VBoxNetAdpNetBSDNetinit;
++ IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
++ ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
++ IFQ_SET_READY(&ifp->if_snd);
++ ether_ifattach(ifp, (void *)pMac);
++ ifp->if_baudrate = 0;
++
++ strncpy(pThis->szName, ifp->if_xname, VBOXNETADP_MAX_NAME_LEN);
++ pThis->u.s.ifp = ifp;
++ VBOXCURVNET_RESTORE();
++ return 0;
++}
++
++void vboxNetAdpOsDestroy(PVBOXNETADP pThis)
++{
++ struct ifnet *ifp;
++
++ ifp = pThis->u.s.ifp;
++ VBOXCURVNET_SET(ifp->if_vnet);
++ ether_ifdetach(ifp);
++ if_free(ifp);
++ VBOXCURVNET_RESTORE();
++}
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_files__vboxnetadp b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_files__vboxnetadp
new file mode 100644
index 0000000..48ef684
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetAdp_netbsd_files__vboxnetadp
@@ -0,0 +1,85 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/VBoxNetAdp/netbsd/files_vboxnetadp.orig 2016-07-07 07:08:46.553240648 +0000
++++ src/VBox/HostDrivers/VBoxNetAdp/netbsd/files_vboxnetadp
+@@ -0,0 +1,80 @@
++#!/bin/sh
++# files_vboxnetadp $
++## @file
++# Shared file between Makefile.kmk and export_modules
++#
++
++#
++# Copyright (C) 2007-2015 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.
++#
++
++
++VBOX_VBOXNETADP_SOURCES=" \
++ ${PATH_ROOT}/include/iprt/alloc.h=>include/iprt/alloc.h \
++ ${PATH_ROOT}/include/iprt/alloca.h=>include/iprt/alloca.h \
++ ${PATH_ROOT}/include/iprt/asm.h=>include/iprt/asm.h \
++ ${PATH_ROOT}/include/iprt/asm-amd64-x86.h=>include/iprt/asm-amd64-x86.h \
++ ${PATH_ROOT}/include/iprt/asm-math.h=>include/iprt/asm-math.h \
++ ${PATH_ROOT}/include/iprt/assert.h=>include/iprt/assert.h \
++ ${PATH_ROOT}/include/iprt/avl.h=>include/iprt/avl.h \
++ ${PATH_ROOT}/include/iprt/cdefs.h=>include/iprt/cdefs.h \
++ ${PATH_ROOT}/include/iprt/cpuset.h=>include/iprt/cpuset.h \
++ ${PATH_ROOT}/include/iprt/ctype.h=>include/iprt/ctype.h \
++ ${PATH_ROOT}/include/iprt/err.h=>include/iprt/err.h \
++ ${PATH_ROOT}/include/iprt/heap.h=>include/iprt/heap.h \
++ ${PATH_ROOT}/include/iprt/initterm.h=>include/iprt/initterm.h \
++ ${PATH_ROOT}/include/iprt/latin1.h=>include/iprt/latin1.h \
++ ${PATH_ROOT}/include/iprt/log.h=>include/iprt/log.h \
++ ${PATH_ROOT}/include/iprt/mangling.h=>include/iprt/mangling.h \
++ ${PATH_ROOT}/include/iprt/mem.h=>include/iprt/mem.h \
++ ${PATH_ROOT}/include/iprt/memobj.h=>include/iprt/memobj.h \
++ ${PATH_ROOT}/include/iprt/mp.h=>include/iprt/mp.h \
++ ${PATH_ROOT}/include/iprt/param.h=>include/iprt/param.h \
++ ${PATH_ROOT}/include/iprt/power.h=>include/iprt/power.h \
++ ${PATH_ROOT}/include/iprt/process.h=>include/iprt/process.h \
++ ${PATH_ROOT}/include/iprt/semaphore.h=>include/iprt/semaphore.h \
++ ${PATH_ROOT}/include/iprt/spinlock.h=>include/iprt/spinlock.h \
++ ${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/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 \
++ ${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/nocrt/limits.h=>include/iprt/nocrt/limits.h \
++ ${PATH_ROOT}/include/VBox/cdefs.h=>include/VBox/cdefs.h \
++ ${PATH_ROOT}/include/VBox/err.h=>include/VBox/err.h \
++ ${PATH_ROOT}/include/VBox/log.h=>include/VBox/log.h \
++ ${PATH_ROOT}/include/VBox/intnet.h=>include/VBox/intnet.h \
++ ${PATH_ROOT}/include/VBox/vmm/stam.h=>include/VBox/vmm/stam.h \
++ ${PATH_ROOT}/include/VBox/sup.h=>include/VBox/sup.h \
++ ${PATH_ROOT}/include/VBox/types.h=>include/VBox/types.h \
++ ${PATH_ROOT}/include/VBox/version.h=>include/VBox/version.h \
++ ${PATH_ROOT}/include/VBox/SUPDrvMangling.h=>include/VBox/SUPDrvMangling.h \
++ ${PATH_ROOT}/src/VBox/HostDrivers/VBoxNetAdp/netbsd/VBoxNetAdp-netbsd.c=>VBoxNetAdp-netbsd.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdp.c=>VBoxNetAdp.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h=>VBoxNetAdpInternal.h \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/the-netbsd-kernel.h=>r0drv/netbsd/the-netbsd-kernel.h \
++ ${PATH_OUT}/version-generated.h=>version-generated.h \
++ ${PATH_OUT}/product-generated.h=>product-generated.h \
++"
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_Makefile.kmk b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_Makefile.kmk
new file mode 100644
index 0000000..b01b809
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_Makefile.kmk
@@ -0,0 +1,62 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/VBoxNetFlt/Makefile.kmk.orig 2016-03-04 19:29:26.000000000 +0000
++++ src/VBox/HostDrivers/VBoxNetFlt/Makefile.kmk
+@@ -450,7 +450,7 @@ $(PATH_TARGET)/VBoxNetAdpCat.dir/VBoxNet
+
+ endif #ifeq ($(KBUILD_TARGET), win)
+
+-else if1of ($(KBUILD_TARGET), linux solaris freebsd) ## @todo merge this with the mixed case stuff.
++else if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd) ## @todo merge this with the mixed case stuff.
+ #
+ # vboxnetflt(.ko/.o/) - The lower case driver.
+ # Note! On Solaris the name has to be <= 8 chars long.
+@@ -479,6 +479,7 @@ else if1of ($(KBUILD_TARGET), linux sola
+ vboxnetflt_SOURCES.linux = linux/VBoxNetFlt-linux.c
+ vboxnetflt_SOURCES.solaris = solaris/VBoxNetFlt-solaris.c
+ vboxnetflt_SOURCES.freebsd = freebsd/VBoxNetFlt-freebsd.c
++ vboxnetflt_SOURCES.netbsd = netbsd/VBoxNetFlt-netbsd.c
+ vboxnetflt_SOURCES = VBoxNetFlt.c
+ solaris/VBoxNetFlt-solaris.c_DEFS = VBOX_SVN_REV=$(VBOX_SVN_REV)
+
+@@ -570,5 +571,39 @@ $(PATH_OUT)/opt_netgraph.h:
+ endif
+ endif # freebsd
+
+-include $(FILE_KBUILD_SUB_FOOTER)
++## @todo Properly generate opt_netgraph.h
++ifeq ($(KBUILD_TARGET),netbsd)
++ vboxnetflt_DEPS.netbsd += $(PATH_OUT)/opt_netgraph.h
++$(PATH_OUT)/opt_netgraph.h:
++ echo > $(PATH_OUT)/opt_netgraph.h
++
++ #
++ # Install source files for compilation on NetBSD.
++ # files_vboxnetflt defines VBOX_VBOXNETFLT_SOURCES.
++ #
++ include $(PATH_SUB_CURRENT)/netbsd/files_vboxnetflt
++ INSTALLS += VBoxNetFlt-src
++ VBoxNetFlt-src_INST = bin/src/vboxnetflt/
++ VBoxNetFlt-src_SOURCES = \
++ $(subst $(DQUOTE),,$(VBOX_VBOXNETFLT_SOURCES)) \
++ $(VBoxNetFlt-src_0_OUTDIR)/Makefile
++ VBoxNetFlt-src_CLEAN = \
++ $(VBoxNetFlt-src_0_OUTDIR)/Makefile \
+
++ $$(VBoxNetFlt-src_0_OUTDIR)/Makefile: \
++ $(PATH_SUB_CURRENT)/netbsd/Makefile \
++ $$(if $$(eq $$(VBoxNetFlt/netbsd/Makefile_VBOX_HARDENED),$$(VBOX_WITH_HARDENING)),,FORCE) \
++ | $$(dir $$@)
++ $(QUIET)$(RM) -f -- $@
++ $(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 # netbsd
++
++include $(FILE_KBUILD_SUB_FOOTER)
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_VBoxNetFltInternal.h b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_VBoxNetFltInternal.h
new file mode 100644
index 0000000..2e55e6f
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_VBoxNetFltInternal.h
@@ -0,0 +1,40 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h.orig 2016-03-04 19:29:26.000000000 +0000
++++ src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
+@@ -244,6 +244,30 @@ typedef struct VBOXNETFLTINS
+ /** The MAC address of the interface. */
+ RTMAC MacAddr;
+ /** @} */
++# elif defined(RT_OS_NETBSD)
++ /** @name NetBSD instance data.
++ * @{ */
++ /** Interface handle */
++ struct ifnet *ifp;
++ /** Netgraph node handle */
++ node_p node;
++ /** Input hook */
++ hook_p input;
++ /** Output hook */
++ hook_p output;
++ /** Original interface flags */
++ unsigned int flags;
++ /** Input queue */
++ struct ifqueue inq;
++ /** Output queue */
++ struct ifqueue outq;
++ /** Input task */
++ struct task tskin;
++ /** Output task */
++ struct task tskout;
++ /** The MAC address of the interface. */
++ RTMAC MacAddr;
++ /** @} */
+ # elif defined(RT_OS_WINDOWS)
+ /** @name Windows instance data.
+ * @{ */
+@@ -475,4 +499,3 @@ DECLHIDDEN(int) vboxNetFltOsPreInitInsta
+ RT_C_DECLS_END
+
+ #endif
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_Makefile b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_Makefile
new file mode 100644
index 0000000..ee187e5
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_Makefile
@@ -0,0 +1,43 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/VBoxNetFlt/netbsd/Makefile.orig 2016-07-07 07:08:46.562307341 +0000
++++ src/VBox/HostDrivers/VBoxNetFlt/netbsd/Makefile
+@@ -0,0 +1,38 @@
++# Makefile $
++## @file
++# Makefile for the VirtualBox NetBSD Host Driver.
++#
++
++#
++#
++# Copyright (C) 2006-2015 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.
++#
++
++KMOD = vboxnetflt
++
++CFLAGS += -DRT_OS_NETBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -Iinclude -I. -Ir0drv -w -DVBOX_WITH_HARDENING -DVIMAGE
++
++.if (${MACHINE_ARCH} == "i386")
++ CFLAGS += -DRT_ARCH_X86
++.elif (${MACHINE_ARCH} == "amd64")
++ CFLAGS += -DRT_ARCH_AMD64
++.endif
++
++SRCS = \
++ VBoxNetFlt-netbsd.c \
++ VBoxNetFlt.c \
++ SUPR0IdcClient-netbsd.c \
++ SUPR0IdcClient.c \
++ SUPR0IdcClientComponent.c
++
++SRCS += device_if.h bus_if.h opt_netgraph.h
++
++.include <bsd.kmod.mk>
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_VBoxNetFlt-netbsd.c b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_VBoxNetFlt-netbsd.c
new file mode 100644
index 0000000..390e545
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_VBoxNetFlt-netbsd.c
@@ -0,0 +1,802 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/VBoxNetFlt/netbsd/VBoxNetFlt-netbsd.c.orig 2016-07-07 07:08:46.572066003 +0000
++++ src/VBox/HostDrivers/VBoxNetFlt/netbsd/VBoxNetFlt-netbsd.c
+@@ -0,0 +1,797 @@
++/* VBoxNetFlt-netbsd.c $ */
++/** @file
++ * VBoxNetFlt - Network Filter Driver (Host), NetBSD Specific Code.
++ */
++
++/*
++ * Copyright (c) 2009 Fredrik Lindberg <fli%shapeshifter.se@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include <sys/param.h>
++#undef PVM
++#include <sys/types.h>
++#include <sys/module.h>
++#include <sys/systm.h>
++#include <sys/errno.h>
++#include <sys/kernel.h>
++#include <sys/fcntl.h>
++#include <sys/conf.h>
++#include <sys/socket.h>
++#include <sys/sockio.h>
++#include <sys/syscallsubr.h>
++#include <sys/queue.h>
++#include <sys/taskqueue.h>
++
++#include <net/if.h>
++#include <net/if_var.h>
++#include <net/if_dl.h>
++#include <net/if_types.h>
++#include <net/ethernet.h>
++
++#include <netgraph/ng_message.h>
++#include <netgraph/netgraph.h>
++#include <netgraph/ng_parse.h>
++
++#define LOG_GROUP LOG_GROUP_NET_FLT_DRV
++#include <VBox/version.h>
++#include <VBox/err.h>
++#include <VBox/log.h>
++#include <VBox/intnetinline.h>
++#include <iprt/initterm.h>
++#include <iprt/string.h>
++#include <iprt/spinlock.h>
++#include <iprt/process.h>
++#include <iprt/assert.h>
++#include <iprt/uuid.h>
++#include <iprt/alloc.h>
++#include <iprt/err.h>
++
++#define VBOXNETFLT_OS_SPECFIC 1
++#include "../VBoxNetFltInternal.h"
++
++static int vboxnetflt_modevent(struct module *, int, void *);
++static ng_constructor_t ng_vboxnetflt_constructor;
++static ng_rcvmsg_t ng_vboxnetflt_rcvmsg;
++static ng_shutdown_t ng_vboxnetflt_shutdown;
++static ng_newhook_t ng_vboxnetflt_newhook;
++static ng_rcvdata_t ng_vboxnetflt_rcvdata;
++static ng_disconnect_t ng_vboxnetflt_disconnect;
++static int ng_vboxnetflt_mod_event(module_t mod, int event, void *data);
++
++/** Netgraph node type */
++#define NG_VBOXNETFLT_NODE_TYPE "vboxnetflt"
++/** Netgraph message cookie */
++#define NGM_VBOXNETFLT_COOKIE 0x56424f58
++
++/** Input netgraph hook name */
++#define NG_VBOXNETFLT_HOOK_IN "input"
++/** Output netgraph hook name */
++#define NG_VBOXNETFLT_HOOK_OUT "output"
++
++/** mbuf tag identifier */
++#define MTAG_VBOX 0x56424f58
++/** mbuf packet tag */
++#define PACKET_TAG_VBOX 128
++
++# include <sys/jail.h>
++# include <net/vnet.h>
++
++# define VBOXCURVNET_SET(arg) CURVNET_SET_QUIET(arg)
++# define VBOXCURVNET_SET_FROM_UCRED() VBOXCURVNET_SET(CRED_TO_VNET(curthread->td_ucred))
++# define VBOXCURVNET_RESTORE() CURVNET_RESTORE()
++
++/*
++ * Netgraph command list, we don't support any
++ * additional commands.
++ */
++static const struct ng_cmdlist ng_vboxnetflt_cmdlist[] =
++{
++ { 0 }
++};
++
++/*
++ * Netgraph type definition
++ */
++static struct ng_type ng_vboxnetflt_typestruct =
++{
++ .version = NG_ABI_VERSION,
++ .name = NG_VBOXNETFLT_NODE_TYPE,
++ .mod_event = vboxnetflt_modevent,
++ .constructor= ng_vboxnetflt_constructor,
++ .rcvmsg = ng_vboxnetflt_rcvmsg,
++ .shutdown = ng_vboxnetflt_shutdown,
++ .newhook = ng_vboxnetflt_newhook,
++ .rcvdata = ng_vboxnetflt_rcvdata,
++ .disconnect = ng_vboxnetflt_disconnect,
++ .cmdlist = ng_vboxnetflt_cmdlist,
++};
++NETGRAPH_INIT(vboxnetflt, &ng_vboxnetflt_typestruct);
++
++/*
++ * Use vboxnetflt because the kernel module is named vboxnetflt and vboxnetadp
++ * depends on this when loading dependencies.
++ * NETGRAP_INIT will prefix the given name with ng_ so MODULE_DEPEND needs the
++ * prefixed name.
++ */
++MODULE_VERSION(vboxnetflt, 1);
++MODULE_DEPEND(ng_vboxnetflt, vboxdrv, 1, 1, 1);
++
++/**
++ * The (common) global data.
++ */
++static VBOXNETFLTGLOBALS g_VBoxNetFltGlobals;
++
++/**
++ * Module event handler, called from netgraph subsystem.
++ */
++static int vboxnetflt_modevent(struct module *pMod, int enmEventType, void *pvArg)
++{
++ int rc;
++
++ Log(("VBoxNetFltNetBSDModuleEvent\n"));
++
++ switch (enmEventType)
++ {
++ case MOD_LOAD:
++ rc = RTR0Init(0);
++ if (RT_FAILURE(rc))
++ {
++ printf("RTR0Init failed %d\n", rc);
++ return RTErrConvertToErrno(rc);
++ }
++
++ memset(&g_VBoxNetFltGlobals, 0, sizeof(VBOXNETFLTGLOBALS));
++ rc = vboxNetFltInitGlobalsAndIdc(&g_VBoxNetFltGlobals);
++ if (RT_FAILURE(rc))
++ {
++ 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:
++ rc = vboxNetFltTryDeleteIdcAndGlobals(&g_VBoxNetFltGlobals);
++ memset(&g_VBoxNetFltGlobals, 0, sizeof(VBOXNETFLTGLOBALS));
++ RTR0Term();
++ break;
++
++ case MOD_SHUTDOWN:
++ case MOD_QUIESCE:
++ default:
++ return EOPNOTSUPP;
++ }
++
++ if (RT_SUCCESS(rc))
++ return 0;
++ return RTErrConvertToErrno(rc);
++}
++
++/*
++ * Convert from mbufs to vbox scatter-gather data structure
++ */
++static void vboxNetFltNetBSDMBufToSG(PVBOXNETFLTINS pThis, struct mbuf *m, PINTNETSG pSG,
++ unsigned int cSegs, unsigned int segOffset)
++{
++ static uint8_t const s_abZero[128] = {0};
++ unsigned int i;
++ struct mbuf *m0;
++
++ IntNetSgInitTempSegs(pSG, m_length(m, NULL), cSegs, 0 /*cSegsUsed*/);
++
++ for (m0 = m, i = segOffset; m0; m0 = m0->m_next)
++ {
++ if (m0->m_len == 0)
++ continue;
++
++ pSG->aSegs[i].cb = m0->m_len;
++ pSG->aSegs[i].pv = mtod(m0, uint8_t *);
++ pSG->aSegs[i].Phys = NIL_RTHCPHYS;
++ i++;
++ }
++
++#ifdef PADD_RUNT_FRAMES_FROM_HOST
++ if (pSG->cbTotal < 60)
++ {
++ pSG->aSegs[i].Phys = NIL_RTHCPHYS;
++ pSG->aSegs[i].pv = (void *)&s_abZero[0];
++ pSG->aSegs[i].cb = 60 - pSG->cbTotal;
++ pSG->cbTotal = 60;
++ i++;
++ }
++#endif
++
++ pSG->cSegsUsed = i;
++}
++
++/*
++ * Convert to mbufs from vbox scatter-gather data structure
++ */
++static struct mbuf * vboxNetFltNetBSDSGMBufFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG)
++{
++ struct mbuf *m;
++ int error;
++ unsigned int i;
++
++ if (pSG->cbTotal == 0)
++ return (NULL);
++
++ m = m_getcl(M_WAITOK, MT_DATA, M_PKTHDR);
++ if (m == NULL)
++ return (NULL);
++
++ m->m_pkthdr.len = m->m_len = 0;
++ m->m_pkthdr.rcvif = NULL;
++
++ for (i = 0; i < pSG->cSegsUsed; i++)
++ {
++ error = m_append(m, pSG->aSegs[i].cb, pSG->aSegs[i].pv);
++ if (error == 0)
++ {
++ m_freem(m);
++ return (NULL);
++ }
++ }
++ return (m);
++}
++
++
++static int ng_vboxnetflt_constructor(node_p node)
++{
++ /* Nothing to do */
++ return (EINVAL);
++}
++
++/*
++ * Setup netgraph hooks
++ */
++static int ng_vboxnetflt_newhook(node_p node, hook_p hook, const char *name)
++{
++ PVBOXNETFLTINS pThis = NG_NODE_PRIVATE(node);
++
++ if (strcmp(name, NG_VBOXNETFLT_HOOK_IN) == 0)
++ {
++ NG_HOOK_SET_TO_INBOUND(hook);
++ pThis->u.s.input = hook;
++ }
++ else if (strcmp(name, NG_VBOXNETFLT_HOOK_OUT) == 0)
++ {
++ pThis->u.s.output = hook;
++ }
++ else
++ return (EINVAL);
++
++ NG_HOOK_HI_STACK(hook);
++ return (0);
++}
++
++/**
++ * Netgraph message processing for node specific messages.
++ * We don't accept any special messages so this is not used.
++ */
++static int ng_vboxnetflt_rcvmsg(node_p node, item_p item, hook_p lasthook)
++{
++ PVBOXNETFLTINS pThis = NG_NODE_PRIVATE(node);
++ struct ng_mesg *msg;
++ int error = 0;
++
++ NGI_GET_MSG(item, msg);
++ if (msg->header.typecookie != NGM_VBOXNETFLT_COOKIE)
++ return (EINVAL);
++
++ switch (msg->header.cmd)
++ {
++ default:
++ error = EINVAL;
++ }
++ return (error);
++}
++
++/**
++ * Handle data on netgraph hooks.
++ * Frames processing is deferred to a taskqueue because this might
++ * be called with non-sleepable locks held and code paths inside
++ * the virtual switch might sleep.
++ */
++static int ng_vboxnetflt_rcvdata(hook_p hook, item_p item)
++{
++ const node_p node = NG_HOOK_NODE(hook);
++ PVBOXNETFLTINS pThis = NG_NODE_PRIVATE(node);
++ struct ifnet *ifp = pThis->u.s.ifp;
++ struct mbuf *m;
++ struct m_tag *mtag;
++ bool fActive;
++
++ VBOXCURVNET_SET(ifp->if_vnet);
++ fActive = vboxNetFltTryRetainBusyActive(pThis);
++
++ NGI_GET_M(item, m);
++ NG_FREE_ITEM(item);
++
++ /* Locate tag to see if processing should be skipped for this frame */
++ mtag = m_tag_locate(m, MTAG_VBOX, PACKET_TAG_VBOX, NULL);
++ if (mtag != NULL)
++ {
++ m_tag_unlink(m, mtag);
++ m_tag_free(mtag);
++ }
++
++ /*
++ * Handle incoming hook. This is connected to the
++ * input path of the interface, thus handling incoming frames.
++ */
++ if (pThis->u.s.input == hook)
++ {
++ if (mtag != NULL || !fActive)
++ {
++ ether_demux(ifp, m);
++ if (fActive)
++ vboxNetFltRelease(pThis, true /*fBusy*/);
++ VBOXCURVNET_RESTORE();
++ return (0);
++ }
++ mtx_lock_spin(&pThis->u.s.inq.ifq_mtx);
++ _IF_ENQUEUE(&pThis->u.s.inq, m);
++ mtx_unlock_spin(&pThis->u.s.inq.ifq_mtx);
++ taskqueue_enqueue_fast(taskqueue_fast, &pThis->u.s.tskin);
++ }
++ /*
++ * Handle mbufs on the outgoing hook, frames going to the interface
++ */
++ else if (pThis->u.s.output == hook)
++ {
++ if (mtag != NULL || !fActive)
++ {
++ int rc = ether_output_frame(ifp, m);
++ if (fActive)
++ vboxNetFltRelease(pThis, true /*fBusy*/);
++ VBOXCURVNET_RESTORE();
++ return rc;
++ }
++ mtx_lock_spin(&pThis->u.s.outq.ifq_mtx);
++ _IF_ENQUEUE(&pThis->u.s.outq, m);
++ mtx_unlock_spin(&pThis->u.s.outq.ifq_mtx);
++ taskqueue_enqueue_fast(taskqueue_fast, &pThis->u.s.tskout);
++ }
++ else
++ {
++ m_freem(m);
++ }
++
++ if (fActive)
++ vboxNetFltRelease(pThis, true /*fBusy*/);
++ VBOXCURVNET_RESTORE();
++ return (0);
++}
++
++static int ng_vboxnetflt_shutdown(node_p node)
++{
++ PVBOXNETFLTINS pThis = NG_NODE_PRIVATE(node);
++ bool fActive;
++
++ /* Prevent node shutdown if we're active */
++ if (pThis->enmTrunkState == INTNETTRUNKIFSTATE_ACTIVE)
++ return (EBUSY);
++ NG_NODE_UNREF(node);
++ return (0);
++}
++
++static int ng_vboxnetflt_disconnect(hook_p hook)
++{
++ return (0);
++}
++
++/**
++ * Input processing task, handles incoming frames
++ */
++static void vboxNetFltNetBSDinput(void *arg, int pending)
++{
++ PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)arg;
++ struct mbuf *m, *m0;
++ struct ifnet *ifp = pThis->u.s.ifp;
++ unsigned int cSegs = 0;
++ bool fDropIt = false, fActive;
++ PINTNETSG pSG;
++
++ VBOXCURVNET_SET(ifp->if_vnet);
++ vboxNetFltRetain(pThis, true /* fBusy */);
++ for (;;)
++ {
++ mtx_lock_spin(&pThis->u.s.inq.ifq_mtx);
++ _IF_DEQUEUE(&pThis->u.s.inq, m);
++ mtx_unlock_spin(&pThis->u.s.inq.ifq_mtx);
++ if (m == NULL)
++ break;
++
++ for (m0 = m; m0 != NULL; m0 = m0->m_next)
++ if (m0->m_len > 0)
++ cSegs++;
++
++#ifdef PADD_RUNT_FRAMES_FROM_HOST
++ if (m_length(m, NULL) < 60)
++ cSegs++;
++#endif
++
++ /* Create a copy and deliver to the virtual switch */
++ pSG = RTMemTmpAlloc(RT_OFFSETOF(INTNETSG, aSegs[cSegs]));
++ vboxNetFltNetBSDMBufToSG(pThis, m, pSG, cSegs, 0);
++ fDropIt = pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, NULL /* pvIf */, pSG, INTNETTRUNKDIR_WIRE);
++ RTMemTmpFree(pSG);
++ if (fDropIt)
++ m_freem(m);
++ else
++ ether_demux(ifp, m);
++ }
++ vboxNetFltRelease(pThis, true /* fBusy */);
++ VBOXCURVNET_RESTORE();
++}
++
++/**
++ * Output processing task, handles outgoing frames
++ */
++static void vboxNetFltNetBSDoutput(void *arg, int pending)
++{
++ PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)arg;
++ struct mbuf *m, *m0;
++ struct ifnet *ifp = pThis->u.s.ifp;
++ unsigned int cSegs = 0;
++ bool fDropIt = false, fActive;
++ PINTNETSG pSG;
++
++ VBOXCURVNET_SET(ifp->if_vnet);
++ vboxNetFltRetain(pThis, true /* fBusy */);
++ for (;;)
++ {
++ mtx_lock_spin(&pThis->u.s.outq.ifq_mtx);
++ _IF_DEQUEUE(&pThis->u.s.outq, m);
++ mtx_unlock_spin(&pThis->u.s.outq.ifq_mtx);
++ if (m == NULL)
++ break;
++
++ for (m0 = m; m0 != NULL; m0 = m0->m_next)
++ if (m0->m_len > 0)
++ cSegs++;
++
++#ifdef PADD_RUNT_FRAMES_FROM_HOST
++ if (m_length(m, NULL) < 60)
++ cSegs++;
++#endif
++ /* Create a copy and deliver to the virtual switch */
++ pSG = RTMemTmpAlloc(RT_OFFSETOF(INTNETSG, aSegs[cSegs]));
++ vboxNetFltNetBSDMBufToSG(pThis, m, pSG, cSegs, 0);
++ fDropIt = pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, NULL /* pvIf */, pSG, INTNETTRUNKDIR_HOST);
++ RTMemTmpFree(pSG);
++
++ if (fDropIt)
++ m_freem(m);
++ else
++ ether_output_frame(ifp, m);
++ }
++ vboxNetFltRelease(pThis, true /* fBusy */);
++ VBOXCURVNET_RESTORE();
++}
++
++/**
++ * Called to deliver a frame to either the host, the wire or both.
++ */
++int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *pvIfData, PINTNETSG pSG, uint32_t fDst)
++{
++ NOREF(pvIfData);
++
++ void (*input_f)(struct ifnet *, struct mbuf *);
++ struct ifnet *ifp;
++ struct mbuf *m;
++ struct m_tag *mtag;
++ bool fActive;
++ int error;
++
++ ifp = ASMAtomicUoReadPtrT(&pThis->u.s.ifp, struct ifnet *);
++ VBOXCURVNET_SET(ifp->if_vnet);
++
++ if (fDst & INTNETTRUNKDIR_WIRE)
++ {
++ m = vboxNetFltNetBSDSGMBufFromSG(pThis, pSG);
++ if (m == NULL)
++ return VERR_NO_MEMORY;
++ m = m_pullup(m, ETHER_HDR_LEN);
++ if (m == NULL)
++ return VERR_NO_MEMORY;
++
++ m->m_flags |= M_PKTHDR;
++ ether_output_frame(ifp, m);
++ }
++
++ if (fDst & INTNETTRUNKDIR_HOST)
++ {
++ m = vboxNetFltNetBSDSGMBufFromSG(pThis, pSG);
++ if (m == NULL)
++ return VERR_NO_MEMORY;
++ m = m_pullup(m, ETHER_HDR_LEN);
++ if (m == NULL)
++ 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
++ * can skip re-delivery of the packet to the guest during
++ * input hook processing.
++ */
++ mtag = m_tag_alloc(MTAG_VBOX, PACKET_TAG_VBOX, 0, M_NOWAIT);
++ if (mtag == NULL)
++ {
++ m_freem(m);
++ return VERR_NO_MEMORY;
++ }
++
++ m_tag_init(m);
++ m_tag_prepend(m, mtag);
++ m->m_flags |= M_PKTHDR;
++ m->m_pkthdr.rcvif = ifp;
++ ifp->if_input(ifp, m);
++ }
++ VBOXCURVNET_RESTORE();
++ return VINF_SUCCESS;
++}
++
++static bool vboxNetFltNetBsdIsPromiscuous(PVBOXNETFLTINS pThis)
++{
++ /** @todo This isn't taking into account that we put the interface in
++ * promiscuous mode. */
++ return (pThis->u.s.flags & IFF_PROMISC) ? true : false;
++}
++
++int vboxNetFltOsInitInstance(PVBOXNETFLTINS pThis, void *pvContext)
++{
++ char nam[NG_NODESIZ];
++ struct ifnet *ifp;
++ node_p node;
++
++ VBOXCURVNET_SET_FROM_UCRED();
++ NOREF(pvContext);
++ ifp = ifunit(pThis->szName);
++ if (ifp == NULL)
++ 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)
++ return VERR_INTERNAL_ERROR;
++
++ RTSpinlockAcquire(pThis->hSpinlock);
++
++ ASMAtomicUoWritePtr(&pThis->u.s.ifp, ifp);
++ pThis->u.s.node = node;
++ bcopy(IF_LLADDR(ifp), &pThis->u.s.MacAddr, ETHER_ADDR_LEN);
++ ASMAtomicUoWriteBool(&pThis->fDisconnectedFromHost, false);
++
++ /* Initialize deferred input queue */
++ bzero(&pThis->u.s.inq, sizeof(struct ifqueue));
++ mtx_init(&pThis->u.s.inq.ifq_mtx, "vboxnetflt inq", NULL, MTX_SPIN);
++ TASK_INIT(&pThis->u.s.tskin, 0, vboxNetFltNetBSDinput, pThis);
++
++ /* Initialize deferred output queue */
++ bzero(&pThis->u.s.outq, sizeof(struct ifqueue));
++ mtx_init(&pThis->u.s.outq.ifq_mtx, "vboxnetflt outq", NULL, MTX_SPIN);
++ TASK_INIT(&pThis->u.s.tskout, 0, vboxNetFltNetBSDoutput, pThis);
++
++ RTSpinlockRelease(pThis->hSpinlock);
++
++ NG_NODE_SET_PRIVATE(node, pThis);
++
++ /* Attempt to name it vboxnetflt_<ifname> */
++ snprintf(nam, NG_NODESIZ, "vboxnetflt_%s", pThis->szName);
++ ng_name_node(node, nam);
++
++ /* Report MAC address, promiscuous mode and GSO capabilities. */
++ /** @todo keep these reports up to date, either by polling for changes or
++ * intercept some control flow if possible. */
++ if (vboxNetFltTryRetainBusyNotDisconnected(pThis))
++ {
++ Assert(pThis->pSwitchPort);
++ pThis->pSwitchPort->pfnReportMacAddress(pThis->pSwitchPort, &pThis->u.s.MacAddr);
++ pThis->pSwitchPort->pfnReportPromiscuousMode(pThis->pSwitchPort, vboxNetFltNetBsdIsPromiscuous(pThis));
++ pThis->pSwitchPort->pfnReportGsoCapabilities(pThis->pSwitchPort, 0, INTNETTRUNKDIR_WIRE | INTNETTRUNKDIR_HOST);
++ pThis->pSwitchPort->pfnReportNoPreemptDsts(pThis->pSwitchPort, 0 /* none */);
++ vboxNetFltRelease(pThis, true /*fBusy*/);
++ }
++ VBOXCURVNET_RESTORE();
++
++ return VINF_SUCCESS;
++}
++
++bool vboxNetFltOsMaybeRediscovered(PVBOXNETFLTINS pThis)
++{
++ struct ifnet *ifp, *ifp0;
++
++ ifp = ASMAtomicUoReadPtrT(&pThis->u.s.ifp, struct ifnet *);
++ VBOXCURVNET_SET(ifp->if_vnet);
++ /*
++ * Attempt to check if the interface is still there and re-initialize if
++ * something has changed.
++ */
++ ifp0 = ifunit(pThis->szName);
++ if (ifp != ifp0)
++ {
++ ASMAtomicUoWriteBool(&pThis->fDisconnectedFromHost, true);
++ ng_rmnode_self(pThis->u.s.node);
++ pThis->u.s.node = NULL;
++ }
++ VBOXCURVNET_RESTORE();
++
++ if (ifp0 != NULL)
++ {
++ vboxNetFltOsDeleteInstance(pThis);
++ vboxNetFltOsInitInstance(pThis, NULL);
++ }
++
++ return !ASMAtomicUoReadBool(&pThis->fDisconnectedFromHost);
++}
++
++void vboxNetFltOsDeleteInstance(PVBOXNETFLTINS pThis)
++{
++
++ taskqueue_drain(taskqueue_fast, &pThis->u.s.tskin);
++ taskqueue_drain(taskqueue_fast, &pThis->u.s.tskout);
++
++ mtx_destroy(&pThis->u.s.inq.ifq_mtx);
++ mtx_destroy(&pThis->u.s.outq.ifq_mtx);
++
++ VBOXCURVNET_SET_FROM_UCRED();
++ if (pThis->u.s.node != NULL)
++ ng_rmnode_self(pThis->u.s.node);
++ VBOXCURVNET_RESTORE();
++ pThis->u.s.node = NULL;
++}
++
++int vboxNetFltOsPreInitInstance(PVBOXNETFLTINS pThis)
++{
++
++ pThis->u.s.ifp = NULL;
++ pThis->u.s.flags = 0;
++ pThis->u.s.node = NULL;
++ return VINF_SUCCESS;
++}
++
++void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, bool fActive)
++{
++ struct ifnet *ifp;
++ struct ifreq ifreq;
++ int error;
++ node_p node;
++ struct ng_mesg *msg;
++ struct ngm_connect *con;
++ struct ngm_rmhook *rm;
++ char path[NG_PATHSIZ];
++
++ Log(("%s: fActive:%d\n", __func__, fActive));
++
++ ifp = ASMAtomicUoReadPtrT(&pThis->u.s.ifp, struct ifnet *);
++ VBOXCURVNET_SET(ifp->if_vnet);
++ node = ASMAtomicUoReadPtrT(&pThis->u.s.node, node_p);
++
++ memset(&ifreq, 0, sizeof(struct ifreq));
++ /* Activate interface */
++ if (fActive)
++ {
++ pThis->u.s.flags = ifp->if_flags;
++ ifpromisc(ifp, 1);
++
++ /* ng_ether nodes are named after the interface name */
++ snprintf(path, sizeof(path), "%s:", ifp->if_xname);
++
++ /*
++ * Send a netgraph connect message to the ng_ether node
++ * assigned to the bridged interface. Connecting
++ * the hooks 'lower' (ng_ether) to out 'input'.
++ */
++ NG_MKMESSAGE(msg, NGM_GENERIC_COOKIE, NGM_CONNECT,
++ sizeof(struct ngm_connect), M_NOWAIT);
++ if (msg == NULL)
++ return;
++ con = (struct ngm_connect *)msg->data;
++ snprintf(con->path, NG_PATHSIZ, "vboxnetflt_%s:", ifp->if_xname);
++ strlcpy(con->ourhook, "lower", NG_HOOKSIZ);
++ strlcpy(con->peerhook, "input", NG_HOOKSIZ);
++ NG_SEND_MSG_PATH(error, node, msg, path, 0);
++
++ /*
++ * Do the same for the hooks 'upper' (ng_ether) and our
++ * 'output' hook.
++ */
++ NG_MKMESSAGE(msg, NGM_GENERIC_COOKIE, NGM_CONNECT,
++ sizeof(struct ngm_connect), M_NOWAIT);
++ if (msg == NULL)
++ return;
++ con = (struct ngm_connect *)msg->data;
++ snprintf(con->path, NG_PATHSIZ, "vboxnetflt_%s:",
++ ifp->if_xname);
++ strlcpy(con->ourhook, "upper", sizeof(con->ourhook));
++ strlcpy(con->peerhook, "output", sizeof(con->peerhook));
++ NG_SEND_MSG_PATH(error, node, msg, path, 0);
++ }
++ else
++ {
++ /* De-activate interface */
++ pThis->u.s.flags = 0;
++ ifpromisc(ifp, 0);
++
++ /* Disconnect msgs are addressed to ourself */
++ snprintf(path, sizeof(path), "vboxnetflt_%s:", ifp->if_xname);
++
++ /*
++ * Send a netgraph message to disconnect our 'input' hook
++ */
++ NG_MKMESSAGE(msg, NGM_GENERIC_COOKIE, NGM_RMHOOK,
++ sizeof(struct ngm_rmhook), M_NOWAIT);
++ if (msg == NULL)
++ return;
++ rm = (struct ngm_rmhook *)msg->data;
++ strlcpy(rm->ourhook, "input", NG_HOOKSIZ);
++ NG_SEND_MSG_PATH(error, node, msg, path, 0);
++
++ /*
++ * Send a netgraph message to disconnect our 'output' hook
++ */
++ NG_MKMESSAGE(msg, NGM_GENERIC_COOKIE, NGM_RMHOOK,
++ sizeof(struct ngm_rmhook), M_NOWAIT);
++ if (msg == NULL)
++ return;
++ rm = (struct ngm_rmhook *)msg->data;
++ strlcpy(rm->ourhook, "output", NG_HOOKSIZ);
++ NG_SEND_MSG_PATH(error, node, msg, path, 0);
++ }
++ VBOXCURVNET_RESTORE();
++}
++
++int vboxNetFltOsDisconnectIt(PVBOXNETFLTINS pThis)
++{
++ return VINF_SUCCESS;
++}
++
++int vboxNetFltOsConnectIt(PVBOXNETFLTINS pThis)
++{
++ return VINF_SUCCESS;
++}
++
++void vboxNetFltPortOsNotifyMacAddress(PVBOXNETFLTINS pThis, void *pvIfData, PCRTMAC pMac)
++{
++ NOREF(pThis); NOREF(pvIfData); NOREF(pMac);
++}
++
++int vboxNetFltPortOsConnectInterface(PVBOXNETFLTINS pThis, void *pvIf, void **ppvIfData)
++{
++ /* Nothing to do */
++ NOREF(pThis); NOREF(pvIf); NOREF(ppvIfData);
++ return VINF_SUCCESS;
++}
++
++int vboxNetFltPortOsDisconnectInterface(PVBOXNETFLTINS pThis, void *pvIfData)
++{
++ /* Nothing to do */
++ NOREF(pThis); NOREF(pvIfData);
++ return VINF_SUCCESS;
++}
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_files__vboxnetflt b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_files__vboxnetflt
new file mode 100644
index 0000000..1e03d1f
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_VBoxNetFlt_netbsd_files__vboxnetflt
@@ -0,0 +1,90 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/VBoxNetFlt/netbsd/files_vboxnetflt.orig 2016-07-07 07:08:46.581760114 +0000
++++ src/VBox/HostDrivers/VBoxNetFlt/netbsd/files_vboxnetflt
+@@ -0,0 +1,85 @@
++#!/bin/sh
++# files_vboxnetflt $
++## @file
++# Shared file between Makefile.kmk and export_modules
++#
++
++#
++# Copyright (C) 2007-2015 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.
++#
++
++VBOX_VBOXNETFLT_SOURCES=" \
++ ${PATH_ROOT}/include/iprt/alloc.h=>include/iprt/alloc.h \
++ ${PATH_ROOT}/include/iprt/alloca.h=>include/iprt/alloca.h \
++ ${PATH_ROOT}/include/iprt/asm.h=>include/iprt/asm.h \
++ ${PATH_ROOT}/include/iprt/asm-amd64-x86.h=>include/iprt/asm-amd64-x86.h \
++ ${PATH_ROOT}/include/iprt/asm-math.h=>include/iprt/asm-math.h \
++ ${PATH_ROOT}/include/iprt/assert.h=>include/iprt/assert.h \
++ ${PATH_ROOT}/include/iprt/avl.h=>include/iprt/avl.h \
++ ${PATH_ROOT}/include/iprt/cdefs.h=>include/iprt/cdefs.h \
++ ${PATH_ROOT}/include/iprt/cpuset.h=>include/iprt/cpuset.h \
++ ${PATH_ROOT}/include/iprt/ctype.h=>include/iprt/ctype.h \
++ ${PATH_ROOT}/include/iprt/err.h=>include/iprt/err.h \
++ ${PATH_ROOT}/include/iprt/heap.h=>include/iprt/heap.h \
++ ${PATH_ROOT}/include/iprt/initterm.h=>include/iprt/initterm.h \
++ ${PATH_ROOT}/include/iprt/latin1.h=>include/iprt/latin1.h \
++ ${PATH_ROOT}/include/iprt/log.h=>include/iprt/log.h \
++ ${PATH_ROOT}/include/iprt/mangling.h=>include/iprt/mangling.h \
++ ${PATH_ROOT}/include/iprt/mem.h=>include/iprt/mem.h \
++ ${PATH_ROOT}/include/iprt/memobj.h=>include/iprt/memobj.h \
++ ${PATH_ROOT}/include/iprt/mp.h=>include/iprt/mp.h \
++ ${PATH_ROOT}/include/iprt/param.h=>include/iprt/param.h \
++ ${PATH_ROOT}/include/iprt/power.h=>include/iprt/power.h \
++ ${PATH_ROOT}/include/iprt/process.h=>include/iprt/process.h \
++ ${PATH_ROOT}/include/iprt/semaphore.h=>include/iprt/semaphore.h \
++ ${PATH_ROOT}/include/iprt/spinlock.h=>include/iprt/spinlock.h \
++ ${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/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 \
++ ${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/nocrt/limits.h=>include/iprt/nocrt/limits.h \
++ ${PATH_ROOT}/include/VBox/cdefs.h=>include/VBox/cdefs.h \
++ ${PATH_ROOT}/include/VBox/err.h=>include/VBox/err.h \
++ ${PATH_ROOT}/include/VBox/log.h=>include/VBox/log.h \
++ ${PATH_ROOT}/include/VBox/intnet.h=>include/VBox/intnet.h \
++ ${PATH_ROOT}/include/VBox/intnetinline.h=>include/VBox/intnetinline.h \
++ ${PATH_ROOT}/include/VBox/vmm/stam.h=>include/VBox/vmm/stam.h \
++ ${PATH_ROOT}/include/VBox/sup.h=>include/VBox/sup.h \
++ ${PATH_ROOT}/include/VBox/types.h=>include/VBox/types.h \
++ ${PATH_ROOT}/include/VBox/version.h=>include/VBox/version.h \
++ ${PATH_ROOT}/include/VBox/SUPDrvMangling.h=>include/VBox/SUPDrvMangling.h \
++ ${PATH_ROOT}/src/VBox/HostDrivers/VBoxNetFlt/netbsd/VBoxNetFlt-netbsd.c=>VBoxNetFlt-netbsd.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFlt.c=>VBoxNetFlt.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h=>VBoxNetFltInternal.h \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPDrvIDC.h=>SUPDrvIDC.h \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPR0IdcClient.c=>SUPR0IdcClient.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPR0IdcClientComponent.c=>SUPR0IdcClientComponent.c \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/SUPR0IdcClientInternal.h=>SUPR0IdcClientInternal.h \
++ ${PATH_ROOT}/src/VBox/HostDrivers/Support/netbsd/SUPR0IdcClient-netbsd.c=>SUPR0IdcClient-netbsd.c \
++ ${PATH_ROOT}/src/VBox/Runtime/r0drv/netbsd/the-netbsd-kernel.h=>r0drv/netbsd/the-netbsd-kernel.h \
++ ${PATH_OUT}/version-generated.h=>version-generated.h \
++ ${PATH_OUT}/product-generated.h=>product-generated.h \
++"
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_netbsd_Makefile b/virtualbox/patches/patch-src_VBox_HostDrivers_netbsd_Makefile
new file mode 100644
index 0000000..113544e
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_netbsd_Makefile
@@ -0,0 +1,81 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/netbsd/Makefile.orig 2016-07-07 07:08:46.590334369 +0000
++++ src/VBox/HostDrivers/netbsd/Makefile
+@@ -0,0 +1,76 @@
++#
++# Makefile for the VirtualBox NetBSD Host Drivers.
++#
++
++#
++#
++# Copyright (C) 2008-2015 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.
++#
++
++KBUILD_VERBOSE =
++
++all:
++ @echo "*** Building 'vboxdrv' module ***"
++ @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxdrv
++ @cp vboxdrv/vboxdrv.kmod .
++ @echo
++ @if [ -d vboxnetflt ]; then \
++ if [ -f vboxdrv/Module.symvers ]; then \
++ cp vboxdrv/Module.symvers vboxnetflt; \
++ fi; \
++ echo "*** Building 'vboxnetflt' module ***"; \
++ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetflt; \
++ cp vboxnetflt/vboxnetflt.kmod .; \
++ echo; \
++ fi
++ @if [ -d vboxnetadp ]; then \
++ if [ -f vboxdrv/Module.symvers ]; then \
++ cp vboxdrv/Module.symvers vboxnetadp; \
++ fi; \
++ echo "*** Building 'vboxnetadp' module ***"; \
++ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetadp; \
++ cp vboxnetadp/vboxnetadp.kmod .; \
++ echo; \
++ fi
++
++
++install:
++ @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxdrv install
++ @if [ -d vboxnetflt ]; then \
++ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetflt install; \
++ fi
++ @if [ -d vboxnetadp ]; then \
++ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxnetadp install; \
++ fi
++
++clean:
++ @$(MAKE) -C vboxdrv clean
++ @if [ -d vboxnetflt ]; then \
++ $(MAKE) -C vboxnetflt clean; \
++ fi
++ @if [ -d vboxnetadp ]; then \
++ $(MAKE) -C vboxnetadp clean; \
++ fi
++ rm -f vboxdrv.kmod vboxnetflt.kmod vboxnetadp.kmod
++
++load:
++ @for module in vboxnetadp vboxnetflt vboxdrv; do \
++ if modstat -n "$$module" >/dev/null; then \
++ echo "Removing previously installed $$module module"; \
++ /sbin/modunload $$module; \
++ fi; \
++ done
++ @for module in vboxdrv vboxnetflt vboxnetadp; do \
++ if test -f $$module.kmod; then \
++ echo "Installing $$module module"; \
++ /sbin/modload ./$$module.kmod; \
++ fi; \
++ done
diff --git a/virtualbox/patches/patch-src_VBox_HostDrivers_netbsd_Makefile.kmk b/virtualbox/patches/patch-src_VBox_HostDrivers_netbsd_Makefile.kmk
new file mode 100644
index 0000000..272b7e3
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostDrivers_netbsd_Makefile.kmk
@@ -0,0 +1,30 @@
+$NetBSD$
+
+--- src/VBox/HostDrivers/netbsd/Makefile.kmk.orig 2016-07-07 07:08:46.599051025 +0000
++++ src/VBox/HostDrivers/netbsd/Makefile.kmk
+@@ -0,0 +1,25 @@
++# Makefile.kmk $
++## @file
++# Sub-makefile for the NetBSD host driver helper scripts.
++#
++
++#
++# Copyright (C) 2006-2015 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.
++#
++
++SUB_DEPTH = ../../../..
++include $(KBUILD_PATH)/subheader.kmk
++
++INSTALLS += HostDrivers-scripts
++HostDrivers-scripts_INST = bin/src/
++HostDrivers-scripts_SOURCES = Makefile
++
++include $(FILE_KBUILD_SUB_FOOTER)
diff --git a/virtualbox/patches/patch-src_VBox_HostServices_Makefile.kmk b/virtualbox/patches/patch-src_VBox_HostServices_Makefile.kmk
new file mode 100644
index 0000000..dea16fb
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostServices_Makefile.kmk
@@ -0,0 +1,24 @@
+$NetBSD$
+
+--- src/VBox/HostServices/Makefile.kmk.orig 2016-03-04 19:29:29.000000000 +0000
++++ src/VBox/HostServices/Makefile.kmk
+@@ -23,12 +23,12 @@ include $(PATH_SUB_CURRENT)/auth/Makefil
+ ifdef VBOX_WITH_SHARED_FOLDERS
+ include $(PATH_SUB_CURRENT)/SharedFolders/Makefile.kmk
+ endif
+-if1of ($(KBUILD_TARGET), win linux solaris darwin freebsd)
++if1of ($(KBUILD_TARGET), win linux solaris darwin freebsd netbsd)
+ ifdef VBOX_WITH_CROGL
+ include $(PATH_SUB_CURRENT)/SharedOpenGL/Makefile.kmk
+ endif
+ endif
+-if1of ($(KBUILD_TARGET), win linux solaris darwin freebsd)
++if1of ($(KBUILD_TARGET), win linux solaris darwin freebsd netbsd)
+ ifdef VBOX_WITH_SHARED_CLIPBOARD
+ include $(PATH_SUB_CURRENT)/SharedClipboard/Makefile.kmk
+ endif
+@@ -48,4 +48,3 @@ endif
+ include $(PATH_SUB_CURRENT)/testcase/Makefile.kmk
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostServices_SharedClipboard_Makefile.kmk b/virtualbox/patches/patch-src_VBox_HostServices_SharedClipboard_Makefile.kmk
new file mode 100644
index 0000000..b1aa7c5
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostServices_SharedClipboard_Makefile.kmk
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/VBox/HostServices/SharedClipboard/Makefile.kmk.orig 2016-03-04 19:29:29.000000000 +0000
++++ src/VBox/HostServices/SharedClipboard/Makefile.kmk
+@@ -39,7 +39,7 @@ VBoxSharedClipboard_SOURCES.darwin = \
+ darwin.cpp \
+ $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/clipboard-helper.cpp \
+ darwin-pasteboard.cpp
+-if1of ($(KBUILD_TARGET), linux solaris freebsd) ## @todo X11
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd) ## @todo X11
+ ifndef VBOX_HEADLESS
+ VBoxSharedClipboard_SOURCES += \
+ $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/clipboard-helper.cpp \
+@@ -55,7 +55,7 @@ VBoxSharedClipboard_LIBS = \
+ $(LIB_VMM) \
+ $(LIB_RUNTIME) \
+ $(LIB_REM)
+-if1of ($(KBUILD_TARGET), linux solaris freebsd)
++if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
+ ifndef VBOX_HEADLESS
+ VBoxSharedClipboard_LIBPATH = \
+ $(VBOX_LIBPATH_X11)
diff --git a/virtualbox/patches/patch-src_VBox_HostServices_SharedOpenGL_Makefile.kmk b/virtualbox/patches/patch-src_VBox_HostServices_SharedOpenGL_Makefile.kmk
new file mode 100644
index 0000000..0fa8c7d
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostServices_SharedOpenGL_Makefile.kmk
@@ -0,0 +1,26 @@
+$NetBSD$
+
+--- src/VBox/HostServices/SharedOpenGL/Makefile.kmk.orig 2016-03-04 19:29:29.000000000 +0000
++++ src/VBox/HostServices/SharedOpenGL/Makefile.kmk
+@@ -376,6 +376,7 @@ VBoxOGLrenderspu_SOURCES.win = \
+ VBoxOGLrenderspu_SOURCES.linux = render/renderspu_glx.c
+ VBoxOGLrenderspu_SOURCES.solaris = render/renderspu_glx.c
+ VBoxOGLrenderspu_SOURCES.freebsd = render/renderspu_glx.c
++VBoxOGLrenderspu_SOURCES.netbsd = render/renderspu_glx.c
+ VBoxOGLrenderspu_OBJCFLAGS.darwin = -Wno-shadow
+ VBoxOGLrenderspu_SOURCES.darwin = \
+ OpenGLTest/OpenGLTestDarwin.cpp \
+@@ -438,7 +439,7 @@ if ( defined(VBOX_WITH_QTGUI) \
+ VBoxTestOGL_QT_MODULES += Core Gui OpenGL
+ VBoxTestOGL_LDFLAGS.darwin += -framework OpenGL
+ VBoxTestOGL_LIBS.win += $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/Opengl32.lib
+- if1of ($(KBUILD_TARGET), solaris linux freebsd)
++ if1of ($(KBUILD_TARGET), solaris linux freebsd netbsd)
+ # must come after VBoxOGL2D, therefore don't set the arch-specific LIBS variable here!
+ VBoxTestOGL_LIBS += GL
+ endif
+@@ -448,4 +449,3 @@ if ( defined(VBOX_WITH_QTGUI) \
+ endif
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostServices_auth_Makefile.kmk b/virtualbox/patches/patch-src_VBox_HostServices_auth_Makefile.kmk
new file mode 100644
index 0000000..dd63cd9
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostServices_auth_Makefile.kmk
@@ -0,0 +1,23 @@
+$NetBSD$
+
+--- src/VBox/HostServices/auth/Makefile.kmk.orig 2016-03-04 19:29:32.000000000 +0000
++++ src/VBox/HostServices/auth/Makefile.kmk
+@@ -28,11 +28,13 @@ VBoxAuth_TEMPLATE = VBOXR3
+ VBoxAuth_SOURCES.linux = pam/VBoxAuthPAM.c
+ VBoxAuth_SOURCES.solaris = pam/VBoxAuthPAM.c
+ VBoxAuth_SOURCES.freebsd = pam/VBoxAuthPAM.c
++VBoxAuth_SOURCES.netbsd = pam/VBoxAuthPAM.c
+ VBoxAuth_SOURCES.win = winlogon/winlogon.cpp winlogon/VBoxAuth.rc
+ VBoxAuth_SOURCES.darwin = directoryservice/directoryservice.cpp
+ VBoxAuth_LIBS.linux = $(LIB_RUNTIME) dl
+ VBoxAuth_LIBS.solaris = $(LIB_RUNTIME) dl
+ VBoxAuth_LIBS.freebsd = $(LIB_RUNTIME)
++VBoxAuth_LIBS.netbsd = $(LIB_RUNTIME)
+ VBoxAuth_LIBS.darwin = $(LIB_RUNTIME)
+ VBoxAuth_LDFLAGS.darwin = -framework DirectoryService
+
+@@ -62,4 +64,3 @@ VBoxAuth-sdkhdr_SOURCES = $(PATH_ROOT)/i
+
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_HostServices_auth_pam_VBoxAuthPAM.c b/virtualbox/patches/patch-src_VBox_HostServices_auth_pam_VBoxAuthPAM.c
new file mode 100644
index 0000000..1deb567
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_HostServices_auth_pam_VBoxAuthPAM.c
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/HostServices/auth/pam/VBoxAuthPAM.c.orig 2016-03-04 19:29:32.000000000 +0000
++++ src/VBox/HostServices/auth/pam/VBoxAuthPAM.c
+@@ -74,7 +74,7 @@
+ #include <stdlib.h>
+ #include <stdarg.h>
+ #include <string.h>
+-#ifndef RT_OS_FREEBSD
++#if !defined(RT_OS_FREEBSD) && !defied(RT_OS_NETBSD)
+ # include <malloc.h>
+ #endif
+
diff --git a/virtualbox/patches/patch-src_VBox_ImageMounter_VBoxFUSE_Makefile.kmk b/virtualbox/patches/patch-src_VBox_ImageMounter_VBoxFUSE_Makefile.kmk
new file mode 100644
index 0000000..eee00aa
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ImageMounter_VBoxFUSE_Makefile.kmk
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/ImageMounter/VBoxFUSE/Makefile.kmk.orig 2016-03-04 19:29:32.000000000 +0000
++++ src/VBox/ImageMounter/VBoxFUSE/Makefile.kmk
+@@ -51,7 +51,7 @@ VBoxFUSE_LIBS = \
+ VBoxFUSE_LIBS.darwin = fuse
+ VBoxFUSE_LIBS.linux = fuse
+ VBoxFUSE_LIBS.freebsd = fuse
++VBoxFUSE_LIBS.netbsd = fuse
+ VBoxFUSE_LIBPATHS.darwin = /usr/local/lib
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_ImageMounter_VBoxFUSE_VBoxFUSE.cpp b/virtualbox/patches/patch-src_VBox_ImageMounter_VBoxFUSE_VBoxFUSE.cpp
new file mode 100644
index 0000000..bcdf98a
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ImageMounter_VBoxFUSE_VBoxFUSE.cpp
@@ -0,0 +1,27 @@
+$NetBSD$
+
+--- src/VBox/ImageMounter/VBoxFUSE/VBoxFUSE.cpp.orig 2016-03-04 19:29:32.000000000 +0000
++++ src/VBox/ImageMounter/VBoxFUSE/VBoxFUSE.cpp
+@@ -22,7 +22,7 @@
+ #define LOG_GROUP LOG_GROUP_DEFAULT /** @todo log group */
+ #include <iprt/types.h>
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(RT_OS_NETBSD)
+ # include <sys/param.h>
+ # undef PVM /* Blasted old BSD mess still hanging around darwin. */
+ #endif
+@@ -1013,7 +1013,7 @@ static int vboxfuseOp_open(const char *p
+ return -EINVAL;
+ if ((pInfo->flags & O_ACCMODE) == O_ACCMODE)
+ return -EINVAL;
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ if (pInfo->flags & ( O_APPEND | O_ASYNC | O_DIRECT /* | O_LARGEFILE ? */
+ | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK
+ /* | O_SYNC ? */))
+@@ -1473,4 +1473,3 @@ int main(int argc, char **argv)
+ RTPrintf("VBoxFUSE: fuse_main -> %d\n", rc);
+ return rc;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Installer_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Installer_Makefile.kmk
new file mode 100644
index 0000000..67938ab
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_Makefile.kmk
@@ -0,0 +1,19 @@
+$NetBSD$
+
+--- src/VBox/Installer/Makefile.kmk.orig 2016-03-04 19:29:32.000000000 +0000
++++ src/VBox/Installer/Makefile.kmk
+@@ -44,6 +44,9 @@ ifndef VBOX_ONLY_SDK
+ if "$(KBUILD_TARGET)" == "freebsd" && "$(KBUILD_HOST)" == "freebsd"
+ include $(PATH_SUB_CURRENT)/freebsd/Makefile.kmk
+ endif
++ if "$(KBUILD_TARGET)" == "netbsd" && "$(KBUILD_HOST)" == "netbsd"
++ include $(PATH_SUB_CURRENT)/netbsd/Makefile.kmk
++ endif
+ endif
+
+ include $(PATH_SUB_CURRENT)/common/Makefile.kmk
+@@ -68,4 +71,3 @@ endif
+
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_Installer_darwin_VirtualBox_postflight b/virtualbox/patches/patch-src_VBox_Installer_darwin_VirtualBox_postflight
new file mode 100644
index 0000000..f7359f6
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_darwin_VirtualBox_postflight
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Installer/darwin/VirtualBox/postflight.orig 2016-03-04 19:29:32.000000000 +0000
++++ src/VBox/Installer/darwin/VirtualBox/postflight
+@@ -69,7 +69,7 @@ if [[ -e "${LSREGISTER}" && "x" != "x${U
+ fi
+
+ # Check environment.
+-if [ "${INSTALLER_TEMP}x" == "x" ]; then
++if [ "${INSTALLER_TEMP}x" = "x" ]; then
+ echo "Required environment variable INSTALLER_TEMP is missing. Aborting installation."
+ exit 1;
+ fi
+@@ -96,4 +96,3 @@ for bin in ${SET_UID_BINARIES}; do
+ done
+
+ exit 0;
+-
diff --git a/virtualbox/patches/patch-src_VBox_Installer_darwin_VirtualBox_preflight b/virtualbox/patches/patch-src_VBox_Installer_darwin_VirtualBox_preflight
new file mode 100644
index 0000000..97daad1
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_darwin_VirtualBox_preflight
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/Installer/darwin/VirtualBox/preflight.orig 2016-03-04 19:29:32.000000000 +0000
++++ src/VBox/Installer/darwin/VirtualBox/preflight
+@@ -15,7 +15,7 @@
+ set -e
+
+ # Check environment.
+-if [ "${INSTALLER_TEMP}x" == "x" ]; then
++if [ "${INSTALLER_TEMP}x" = "x" ]; then
+ echo "Required environment variable INSTALLER_TEMP is missing. Aborting installation."
+ exit 1;
+ fi
diff --git a/virtualbox/patches/patch-src_VBox_Installer_linux_VBoxSysInfo.sh b/virtualbox/patches/patch-src_VBox_Installer_linux_VBoxSysInfo.sh
new file mode 100644
index 0000000..e94b19e
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_linux_VBoxSysInfo.sh
@@ -0,0 +1,27 @@
+$NetBSD$
+
+--- src/VBox/Installer/linux/VBoxSysInfo.sh.orig 2016-03-04 19:29:33.000000000 +0000
++++ src/VBox/Installer/linux/VBoxSysInfo.sh
+@@ -109,6 +109,12 @@ get_freebsd_info () {
+ echo "Kernel: $kernel"
+ }
+
++# Print information about a NetBSD system. FIXME.
++get_netbsd_info () {
++ kernel=`uname -v`
++ echo "Kernel: $kernel"
++}
++
+ system=`uname -s`
+ case "$system" in
+ Linux|linux)
+@@ -123,6 +129,9 @@ Darwin)
+ FreeBSD)
+ get_freebsd_info
+ ;;
++NetBSD)
++ get_netbsd_info
++ ;;
+ *)
+ echo "System unknown"
+ exit 1
diff --git a/virtualbox/patches/patch-src_VBox_Installer_linux_debian_control b/virtualbox/patches/patch-src_VBox_Installer_linux_debian_control
new file mode 100644
index 0000000..b0ca6a1
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_linux_debian_control
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/VBox/Installer/linux/debian/control.orig 2016-03-04 19:29:33.000000000 +0000
++++ src/VBox/Installer/linux/debian/control
+@@ -26,7 +26,7 @@ Conflicts: virtualbox, virtualbox-ose, v
+ Description: Oracle VM VirtualBox
+ VirtualBox is a powerful PC virtualization solution allowing you to run a
+ wide range of PC operating systems on your Linux system. This includes
+- Windows, Linux, FreeBSD, DOS, OpenBSD and others. VirtualBox comes with a broad
++ Windows, Linux, FreeBSD, NetBSD, DOS, OpenBSD and others. VirtualBox comes with a broad
+ feature set and excellent performance, making it the premier virtualization
+ software solution on the market.
+ XB-Python-Version: ${python:Versions}
+@@ -40,7 +40,7 @@ Conflicts: virtualbox-dbg, virtualbox-os
+ Description: Oracle VM VirtualBox debugging symbols
+ VirtualBox is a powerful PC virtualization solution allowing you to run a
+ wide range of PC operating systems on your Linux system. This includes
+- Windows, Linux, FreeBSD, DOS, OpenBSD and others. VirtualBox comes with a broad
++ Windows, Linux, FreeBSD, NetBSD, DOS, OpenBSD and others. VirtualBox comes with a broad
+ feature set and excellent performance, making it the premier virtualization
+ software solution on the market.
+ .
diff --git a/virtualbox/patches/patch-src_VBox_Installer_linux_rpm_VirtualBox.tmpl.spec b/virtualbox/patches/patch-src_VBox_Installer_linux_rpm_VirtualBox.tmpl.spec
new file mode 100644
index 0000000..697c1e3
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_linux_rpm_VirtualBox.tmpl.spec
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/Installer/linux/rpm/VirtualBox.tmpl.spec.orig 2016-03-04 19:29:33.000000000 +0000
++++ src/VBox/Installer/linux/rpm/VirtualBox.tmpl.spec
+@@ -40,7 +40,7 @@ Requires: %INITSCRIPTS% %LIBASOUND% net
+ %description
+ VirtualBox is a powerful PC virtualization solution allowing
+ you to run a wide range of PC operating systems on your Linux
+-system. This includes Windows, Linux, FreeBSD, DOS, OpenBSD
++system. This includes Windows, Linux, FreeBSD, NetBSD, DOS, OpenBSD
+ and others. VirtualBox comes with a broad feature set and
+ excellent performance, making it the premier virtualization
+ software solution on the market.
diff --git a/virtualbox/patches/patch-src_VBox_Installer_netbsd_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Installer_netbsd_Makefile.kmk
new file mode 100644
index 0000000..f422eae
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_netbsd_Makefile.kmk
@@ -0,0 +1,343 @@
+$NetBSD$
+
+--- src/VBox/Installer/netbsd/Makefile.kmk.orig 2016-07-07 07:08:46.625776932 +0000
++++ src/VBox/Installer/netbsd/Makefile.kmk
+@@ -0,0 +1,338 @@
++# Makefile.kmk $
++## @file
++# Makefile for the NetBSD installer.
++#
++
++#
++# Copyright (C) 2006-2015 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.
++#
++
++SUB_DEPTH = ../../../..
++include $(KBUILD_PATH)/subheader.kmk
++
++ifneq ($(KBUILD_HOST),netbsd)
++ $(error "The NetBSD installer can only be built on NetBSD!")
++endif
++
++#
++# Globals and targets.
++#
++VBOX_PATH_FBSD_INST_SRC := $(PATH_SUB_CURRENT)
++VBOX_FBSD_INST_OUT_DIR := $(PATH_TARGET)/Installer/netbsd
++VBOX_FBSD_INST_STAGE_DIR := $(PATH_TARGET)/Installer/netbsd/install
++VBOX_FBSD_DBG_PATH := usr/lib/debug/opt/VirtualBox
++VBOX_FBSD_PACKAGE_NAME = VirtualBox-$(VBOX_VERSION_STRING)-r$(VBOX_SVN_REV).tbz
++VBOX_FBSD_INST_LIB_DIR := $(VBOX_FBSD_INST_STAGE_DIR)/lib
++VBOX_FBSD_INST_BIN_DIR := $(VBOX_FBSD_INST_STAGE_DIR)/bin
++VBOX_FBSD_INST_LIBVBOX_DIR := $(VBOX_FBSD_INST_LIB_DIR)/virtualbox
++VBOX_FBSD_INST_SHARE_DIR := $(VBOX_FBSD_INST_STAGE_DIR)/share
++VBOX_FBSD_INST_SHAREAPP_DIR := $(VBOX_FBSD_INST_SHARE_DIR)/applications
++VBOX_FBSD_INST_SHAREICON_DIR := $(VBOX_FBSD_INST_SHARE_DIR)/pixmaps
++VBOX_FBSD_INST_SHAREVBOX_DIR := $(VBOX_FBSD_INST_SHARE_DIR)/virtualbox
++
++# Unset this to speed up things during makefile hacking.
++VBOX_FBSD_INST_DEP_ON_MAKEFILE := $(MAKEFILE_CURRENT)
++
++BLDDIRS += $(VBOX_FBSD_INST_OUT_DIR) $(VBOX_FBSD_INST_STAGE_DIR)
++PACKING += $(PATH_STAGE_BIN)/$(VBOX_FBSD_PACKAGE_NAME)
++
++OTHER_CLEAN += \
++ $(addprefix $(VBOX_FBSD_INST_STAGE_DIR)/,\
++ pkg_plist \
++ LICENSE) \
++ $(wildcard $(VBOX_FBSD_INST_OUT_DIR)/VirtualBox-*)
++
++#
++# NetBSD installs.
++#
++INSTALLS += netbsd-misc
++netbsd-misc_INST = bin/
++netbsd-misc_MODE = a+r,u+w
++netbsd-misc_SOURCES = \
++ $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/images/$(if $(VBOX_OSE),OSE,NonOSE)/VirtualBox_32px.png=>VBox.png \
++ $(if $(VBOX_OSE),,$(VBOX_BRAND_LICENSE_TXT)=>LICENSE) \
++ $(if $(VBOX_WITH_QTGUI),$(netbsd-misc_0_OUTDIR)/virtualbox.desktop,)
++netbsd-misc_CLEAN = $(netbsd-misc_0_OUTDIR)/virtualbox.desktop
++
++$$(PATH_netbsd-misc)/virtualbox.desktop: $(PATH_SUB_CURRENT)/virtualbox.desktop $(VBOX_VERSION_STAMP) | $$(dir $$@)
++ $(call MSG_GENERATE,,$@,$<)
++ifdef VBOX_PATH_PACKAGE_DOCS
++ $(QUIET)$(SED) -e "s+\$$VBOX_DOC_PATH+$(VBOX_PATH_PACKAGE_DOCS)+" --output $@ $<
++else
++ $(QUIET)$(SED) -e "s+\$$VBOX_DOC_PATH+/opt/VirtualBox+" --output $@ $<
++endif
++
++
++
++#
++# The files residing in bin/ that we'll ship.
++#
++
++# Strip these binaries
++VBOX_FBSD_STRIP_BIN = \
++ VBoxDD.so \
++ VBoxDD2.so \
++ VBoxREM.so \
++ VBoxDDU.so \
++ VBoxVMM.so \
++ $(if $(eq $(KBUILD_TARGET_ARCH),x86),VBoxREM32.so,) \
++ $(if $(eq $(KBUILD_TARGET_ARCH),x86),VBoxREM64.so,) \
++ VBoxRT.so \
++ $(if $(VBOX_WITH_VBOXSDL),VBoxSDL $(if $(VBOX_WITH_HARDENING),VBoxSDL.so),) \
++ $(if $(VBOX_WITH_SHARED_CLIPBOARD), VBoxSharedClipboard.so,) \
++ $(if $(VBOX_WITH_SHARED_FOLDERS), VBoxSharedFolders.so,) \
++ $(if $(VBOX_WITH_GUEST_PROPS),VBoxGuestPropSvc.so,) \
++ $(if $(VBOX_WITH_GUEST_CONTROL),VBoxGuestControlSvc.so,) \
++ VBoxHostChannel.so \
++ $(if $(VBOX_WITH_MAIN), \
++ VBoxManage \
++ VBoxNetDHCP $(if $(VBOX_WITH_HARDENING),VBoxNetDHCP.so,) \
++ VBoxNetAdpCtl \
++ VBoxSVC \
++ VBoxXPCOM.so \
++ VBoxXPCOMC.so \
++ VBoxXPCOMIPCD \
++ components/VBoxXPCOMIPCC.so \
++ components/VBoxSVCM.so \
++ components/VBoxC.so,) \
++ $(if $(VBOX_WITH_CROGL),\
++ VBoxOGLhostcrutil.so \
++ VBoxOGLhosterrorspu.so \
++ VBoxOGLrenderspu.so \
++ VBoxTestOGL \
++ VBoxSharedCrOpenGL.so,) \
++ $(if $(VBOX_WITH_PYTHON),VBoxPython.so,) \
++ $(if $(VBOX_WITH_DTRACE),VBoxDTrace,)
++
++# Do not remove relocation information of these binaries
++VBOX_FBSD_STRIP_OBJ = \
++ VBoxDD2RC.rc \
++ VBoxDD2R0.r0 \
++ VBoxDDRC.rc \
++ VBoxDDR0.r0 \
++ VMMRC.rc \
++ VMMR0.r0
++
++# Do not strip anything of these files
++VBOX_FBSD_NO_STRIP = \
++ $(if $(VBOX_OSE),,LICENSE) \
++ $(if $(VBOX_WITH_MAIN), \
++ components/VBoxXPCOMBase.xpt \
++ components/VirtualBox_XPCOM.xpt) \
++ vboxdrv.tar.gz
++
++# EFI firmware
++ifdef VBOX_WITH_EFIFW_PACKING
++ VBOX_FBSD_NO_STRIP += \
++ VBoxEFI32.fd \
++ VBoxEFI64.fd
++endif
++
++# Symlinks residing in bin/
++VBOX_FBSD_SYMLINKS = \
++ $(if $(VBOX_WITH_MAIN), \
++ VBoxManage \
++ VBoxSVC) \
++ $(if $(VBOX_WITH_VBOXSDL),VBoxSDL,) \
++ $(if $(VBOX_WITH_DTRACE),VBoxDTrace,)
++
++# Qt4 GUI
++ifdef VBOX_WITH_QTGUI
++ include $(PATH_ROOT)/src/VBox/Frontends/VirtualBox/nls/ApprovedLanguages.kmk
++ VBOX_FBSD_STRIP_BIN += \
++ VBoxKeyboard.so \
++ VirtualBox \
++ $(if $(VBOX_WITH_HARDENING),VirtualBox.so) \
++ $(if $(VBOX_WITH_DEBUGGER_GUI),VBoxDbg.so DbgPlugInDiggers.so,)
++ VBOX_FBSD_SYMLINKS += \
++ VirtualBox
++ VBOX_FBSD_NO_STRIP += \
++ $(VBOX_LICENSE_FILES) \
++ $(if $(VBOX_WITH_QT4_SUN),$(notdir $(wildcard $(PATH_STAGE_BIN)/lib*VBox*)),) \
++ $(if $(VBOX_WITH_QT4_SUN),accessible/libqtaccessiblewidgets.so,) \
++ $(foreach f,$(VBOX_APPROVED_GUI_LANGUAGES),nls/VirtualBox_$(f).qm nls/qt_$(f).qm)
++ VBOX_FBSD_DESKTOP_FILE = \
++ virtualbox.desktop
++ VBOX_FBSD_ICON_FILE = \
++ VBox.png
++endif
++
++# Guest Additions
++ifdef VBOX_WITH_ADDITIONS_PACKING
++ VBOX_FBSD_NO_STRIP += \
++ additions/VBoxGuestAdditions.iso
++endif
++
++# Documentation
++ifdef VBOX_WITH_DOCS_PACKING
++ VBOX_FBSD_NO_STRIP += \
++ VirtualBox.chm UserManual.pdf \
++ $(foreach f,$(VBOX_MANUAL_ADD_LANGUAGES),VirtualBox_$(f).chm UserManual_$(f).pdf)
++ VBOX_FBSD_STRIP_BIN += \
++ $(if $(VBOX_WITH_KCHMVIEWER),kchmviewer,)
++endif
++
++# VRDP
++ifdef VBOX_WITH_VRDP
++ VBOX_FBSD_STRIP_BIN += \
++ VBoxVRDP.so \
++ VBoxAuth.so
++ VBOX_FBSD_NO_STRIP += \
++ rdesktop-vrdp.tar.gz
++ ifdef VBOX_WITH_VRDP_RDESKTOP
++# VBOX_FBSD_NO_STRIP += \
++# rdesktop-vrdp-keymaps
++ VBOX_FBSD_STRIP_BIN += \
++ rdesktop-vrdp
++ endif
++endif
++
++# Headless
++ifdef VBOX_WITH_HEADLESS
++ VBOX_FBSD_STRIP_BIN += \
++ VBoxHeadless \
++ $(if $(VBOX_WITH_HARDENING),VBoxHeadless.so)
++ VBOX_FBSD_SYMLINKS += \
++ VBoxHeadless
++endif
++
++# Webservices
++ifdef VBOX_WITH_WEBSERVICES
++ VBOX_FBSD_STRIP_BIN += \
++ vboxwebsrv \
++ webtest
++ VBOX_FBSD_SYMLINKS += \
++ vboxwebsrv
++endif
++
++# DTrace library, testcase and scripts (as the rest of this file, this makes bold
++# ASSUMPTIONS about VBPX_INST_XXX variable values).
++ifdef VBOX_WITH_DTRACE
++ VBOX_FBSD_NO_STRIP += \
++ $(addprefix dtrace/lib/$(KBUILD_TARGET_ARCH)/,$(VBOXINST_DTRACE_LIB_ARCH_FILES)) \
++ $(addprefix dtrace/testcase/$(KBUILD_TARGET_ARCH)/,$(VBOXINST_DTRACE_TESTCASE_ARCH_FILES)) \
++ $(addprefix dtrace/scripts/,$(VBOXINST_DTRACE_SCRIPTS_FILES))
++endif
++
++#
++# All the bin files that goes into the archives.
++#
++VBOX_FBSD_ARCH_FILES := $(VBOX_FBSD_STRIP_BIN) $(VBOX_FBSD_STRIP_OBJ) $(VBOX_FBSD_NO_STRIP)
++
++# Cleanup of the files we copy/symlink from bin.
++OTHER_CLEAN += $(addprefix $(VBOX_FBSD_INST_LIBVBOX_DIR)/,$(VBOX_FBSD_ARCH_FILES))
++
++#
++# The module source archive
++#
++$(PATH_STAGE_BIN)/vboxdrv.tar.gz: \
++ src
++ $(call MSG_TOOL, export_modules,,$@)
++ $(QUIET)$(PATH_STAGE_BIN)/export_modules $@
++
++#
++# The generic installer.
++## @todo r=aeichner: Create pkg_plist dynamically based on the available features
++#
++$(PATH_STAGE_BIN)/$(VBOX_FBSD_PACKAGE_NAME): \
++ $(VBOX_VERSION_STAMP) \
++ $(VBOX_FBSD_INST_OUT_DIR)/pkg_plist \
++ $(addprefix $(VBOX_FBSD_INST_LIBVBOX_DIR)/,$(VBOX_FBSD_ARCH_FILES)) \
++ $(addprefix $(VBOX_FBSD_INST_BIN_DIR)/,$(VBOX_FBSD_SYMLINKS)) \
++ $(if $(VBOX_OSE),,$(VBOX_BRAND_LICENSE_TXT)) \
++ $(if $(VBOX_WITH_QTGUI),$(addprefix $(VBOX_FBSD_INST_SHAREAPP_DIR)/,$(VBOX_FBSD_DESKTOP_FILE)),) \
++ $(if $(VBOX_WITH_QTGUI),$(addprefix $(VBOX_FBSD_INST_SHAREICON_DIR)/,$(VBOX_FBSD_ICON_FILE)),) \
++ $(VBOX_PATH_FBSD_INST_SRC)/postinstall.sh \
++ $(VBOX_PATH_FBSD_INST_SRC)/postdeinstall.sh
++ $(call MSG_TOOL,pkg_create,,$@)
++ $(QUIET)$(RM) -f $@
++ $(QUIET)pkg_create \
++ -I $(VBOX_PATH_FBSD_INST_SRC)/postinstall.sh \
++ -K $(VBOX_PATH_FBSD_INST_SRC)/postdeinstall.sh \
++ -c $(VBOX_PATH_FBSD_INST_SRC)/pkg-comment \
++ -d $(VBOX_PATH_FBSD_INST_SRC)/pkg-descr \
++ -f $(VBOX_FBSD_INST_OUT_DIR)/pkg_plist \
++ -p /usr/local \
++ -s $(VBOX_FBSD_INST_STAGE_DIR) \
++ $@
++ $(QUIET)$(RM) -Rf $(VBOX_FBSD_INST_STAGE_DIR)
++
++$(addprefix $(VBOX_FBSD_INST_LIBVBOX_DIR)/,$(VBOX_FBSD_STRIP_BIN)): \
++ $(VBOX_FBSD_INST_LIBVBOX_DIR)/% : $(PATH_STAGE_BIN)/%
++ $(call MSG_INST_FILE,$<,$@)
++ $(QUIET)$(INSTALL) -d $(dir $@)
++ $(QUIET)$(INSTALL) -m 0755 $(if $(VBOX_DO_STRIP),-s,) $< $@
++
++# pattern rule for striping and copying the VBOX_FBSD_STRIP_OBJ files to install/lib/virtualbox
++$(addprefix $(VBOX_FBSD_INST_LIBVBOX_DIR)/,$(VBOX_FBSD_STRIP_OBJ)): \
++ $(VBOX_FBSD_INST_LIBVBOX_DIR)/% : $(PATH_STAGE_BIN)/%
++ $(call MSG_INST_FILE,$<,$@)
++ $(QUIET)$(INSTALL) -d $(dir $@)
++ifeq ($(VBOX_DO_STRIP),)
++ $(QUIET)$(INSTALL) -m 0644 $< $@
++else # strip to temp file because of umask.
++ $(QUIET)objcopy --strip-unneeded -R .comment $< $@.tmp
++ $(QUIET)$(INSTALL) -m 0644 $@.tmp $@
++ $(QUIET)$(RM) -f -- $@.tmp
++endif
++
++# pattern rule for linking the VBOX_FBSD_NO_STRIP into lib/virtualbox/
++$(addprefix $(VBOX_FBSD_INST_LIBVBOX_DIR)/,$(VBOX_FBSD_NO_STRIP)): \
++ $(VBOX_FBSD_INST_LIBVBOX_DIR)/% : $(PATH_STAGE_BIN)/%
++ $(call MSG_INST_FILE,$<,$@)
++ $(QUIET)$(INSTALL) -d $(dir $@)
++ $(QUIET)$(RM) -f $@
++ $(QUIET)$(INSTALL) -m 0644 $< $@
++
++# pattern rule for symlinking the VBOX_FBSD_SYMLINKS into bin/
++$(addprefix $(VBOX_FBSD_INST_BIN_DIR)/,$(VBOX_FBSD_SYMLINKS)): \
++ $(VBOX_FBSD_INST_BIN_DIR)/% : $(PATH_STAGE_BIN)/%
++ $(call MSG_INST_SYM,$<,$@)
++ $(QUIET)$(INSTALL) -d $(dir $@)
++ $(QUIET)$(RM) -f $@
++ $(QUIET)$(LN_SYMLINK) ../lib/virtualbox/$(notdir $@) $@
++
++# pattern rule for copying the VBOX_FBSD_DESKTOP_FILE into share/applications/
++$(addprefix $(VBOX_FBSD_INST_SHAREAPP_DIR)/,$(VBOX_FBSD_DESKTOP_FILE)): \
++ $(VBOX_FBSD_INST_SHAREAPP_DIR)/% : $(PATH_STAGE_BIN)/%
++ $(call MSG_INST_FILE,$<,$@)
++ $(QUIET)$(INSTALL) -d $(dir $@)
++ $(QUIET)$(RM) -f $@
++ $(QUIET)$(INSTALL) -m 0644 $< $@
++
++# pattern rule for copying the VBOX_FBSD_ICON_FILE into share/pixmaps/
++$(addprefix $(VBOX_FBSD_INST_SHAREICON_DIR)/,$(VBOX_FBSD_ICON_FILE)): \
++ $(VBOX_FBSD_INST_SHAREICON_DIR)/% : $(PATH_STAGE_BIN)/%
++ $(call MSG_INST_FILE,$<,$@)
++ $(QUIET)$(INSTALL) -d $(dir $@)
++ $(QUIET)$(RM) -f $@
++ $(QUIET)$(INSTALL) -m 0644 $< $@
++
++# Create pkg_plist
++$(VBOX_FBSD_INST_OUT_DIR)/pkg_plist: \
++ $(VBOX_PATH_FBSD_INST_SRC)/pkg_plist
++ $(call MSG_INST_FILE,$<,$@)
++ $(QUIET)$(INSTALL) -d $(dir $@)
++ $(QUIET)$(SED) \
++ -e "s;_VBOX_REM_32BIT_MODULE_;$(if $(eq $(KBUILD_TARGET_ARCH),x86),VBoxREM32.so,);g" \
++ -e "s;_VBOX_REM_64BIT_MODULE_;$(if $(eq $(KBUILD_TARGET_ARCH),x86),VBoxREM64.so,);g" \
++ --output $@ \
++ $<
++ifdef VBOX_WITH_DTRACE
++ $(QUIET)$(APPEND) -n "$@" "@mode 644" \
++ $(addprefix lib/virtualbox/dtrace/lib/$(KBUILD_TARGET_ARCH)/,$(VBOXINST_DTRACE_LIB_ARCH_FILES)) \
++ $(addprefix lib/virtualbox/dtrace/testcase/$(KBUILD_TARGET_ARCH)/,$(VBOXINST_DTRACE_TESTCASE_ARCH_FILES)) \
++ $(addprefix lib/virtualbox/dtrace/scripts/,$(VBOXINST_DTRACE_SCRIPTS_FILES)) \
++ "@mode 755" \
++ "bin/VBoxDTrace"
++endif
++
++include $(FILE_KBUILD_SUB_FOOTER)
diff --git a/virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg-comment b/virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg-comment
new file mode 100644
index 0000000..f994e82
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg-comment
@@ -0,0 +1,6 @@
+$NetBSD$
+
+--- src/VBox/Installer/netbsd/pkg-comment.orig 2016-07-06 20:01:35.493671141 +0000
++++ src/VBox/Installer/netbsd/pkg-comment
+@@ -0,0 +1 @@
++VirtualBox x86 virtualization package
diff --git a/virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg-descr b/virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg-descr
new file mode 100644
index 0000000..cd5a879
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg-descr
@@ -0,0 +1,8 @@
+$NetBSD$
+
+--- src/VBox/Installer/netbsd/pkg-descr.orig 2016-07-07 07:08:46.642993647 +0000
++++ src/VBox/Installer/netbsd/pkg-descr
+@@ -0,0 +1,3 @@
++VirtualBox for the NetBSD operating system
++
++WWW: http://www.virtualbox.org
diff --git a/virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg__plist b/virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg__plist
new file mode 100644
index 0000000..23cbbc4
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_netbsd_pkg__plist
@@ -0,0 +1,103 @@
+$NetBSD$
+
+--- src/VBox/Installer/netbsd/pkg_plist.orig 2016-07-06 20:01:35.495294415 +0000
++++ src/VBox/Installer/netbsd/pkg_plist
+@@ -0,0 +1,98 @@
++@owner root
++@group wheel
++@mode 755
++lib/virtualbox/VBoxDbg.so
++lib/virtualbox/DbgPlugInDiggers.so
++lib/virtualbox/VBoxDD.so
++lib/virtualbox/VBoxDD2.so
++lib/virtualbox/VBoxDDU.so
++lib/virtualbox/VBoxGuestPropSvc.so
++lib/virtualbox/VBoxGuestControlSvc.so
++lib/virtualbox/VBoxHostChannel.so
++lib/virtualbox/VBoxHeadless.so
++lib/virtualbox/VBoxKeyboard.so
++lib/virtualbox/VBoxManage
++lib/virtualbox/VBoxNetDHCP.so
++lib/virtualbox/VBoxPython.so
++lib/virtualbox/VBoxREM.so
++lib/virtualbox/VBoxRT.so
++lib/virtualbox/VBoxSDL.so
++lib/virtualbox/VBoxSharedFolders.so
++lib/virtualbox/VBoxSVC
++lib/virtualbox/VBoxVMM.so
++lib/virtualbox/VBoxVRDP.so
++lib/virtualbox/VBoxXPCOM.so
++lib/virtualbox/VBoxXPCOMC.so
++lib/virtualbox/VBoxXPCOMIPCD
++lib/virtualbox/VirtualBox.so
++lib/virtualbox/VBoxOGLhostcrutil.so
++lib/virtualbox/VBoxOGLhosterrorspu.so
++lib/virtualbox/VBoxOGLrenderspu.so
++lib/virtualbox/vboxwebsrv
++lib/virtualbox/webtest
++lib/virtualbox/rdesktop-vrdp
++lib/virtualbox/VBoxTestOGL
++_VBOX_REM_32BIT_MODULE_
++_VBOX_REM_64BIT_MODULE_
++@mode 4755
++lib/virtualbox/VBoxSDL
++lib/virtualbox/VirtualBox
++lib/virtualbox/VBoxNetDHCP
++lib/virtualbox/VBoxNetAdpCtl
++lib/virtualbox/VBoxHeadless
++@mode 755
++lib/virtualbox/components/VBoxC.so
++lib/virtualbox/components/VBoxSVCM.so
++lib/virtualbox/components/VBoxXPCOMIPCC.so
++@mode 644
++lib/virtualbox/components/VBoxXPCOMBase.xpt
++lib/virtualbox/components/VirtualBox_XPCOM.xpt
++@mode 755
++bin/VirtualBox
++bin/VBoxManage
++bin/VBoxSVC
++bin/VBoxHeadless
++bin/VBoxSDL
++bin/vboxwebsrv
++@mode 644
++lib/virtualbox/VBoxDDRC.rc
++lib/virtualbox/VBoxDD2RC.rc
++lib/virtualbox/VBoxDDR0.r0
++lib/virtualbox/VBoxDD2R0.r0
++lib/virtualbox/VMMRC.rc
++lib/virtualbox/VMMR0.r0
++lib/virtualbox/License-7.html
++lib/virtualbox/vboxdrv.tar.gz
++lib/virtualbox/nls/qt_de.qm
++lib/virtualbox/nls/VirtualBox_de.qm
++lib/virtualbox/nls/qt_fr.qm
++lib/virtualbox/nls/VirtualBox_fr.qm
++lib/virtualbox/nls/qt_it.qm
++lib/virtualbox/nls/VirtualBox_it.qm
++lib/virtualbox/nls/qt_ro.qm
++lib/virtualbox/nls/VirtualBox_ro.qm
++lib/virtualbox/nls/qt_zh_CN.qm
++lib/virtualbox/nls/VirtualBox_zh_CN.qm
++lib/virtualbox/nls/qt_ja.qm
++lib/virtualbox/nls/VirtualBox_ja.qm
++lib/virtualbox/nls/qt_es.qm
++lib/virtualbox/nls/VirtualBox_es.qm
++lib/virtualbox/nls/qt_ru.qm
++lib/virtualbox/nls/VirtualBox_ru.qm
++lib/virtualbox/nls/qt_pl.qm
++lib/virtualbox/nls/VirtualBox_pl.qm
++lib/virtualbox/nls/qt_pt_BR.qm
++lib/virtualbox/nls/VirtualBox_pt_BR.qm
++lib/virtualbox/nls/qt_ko.qm
++lib/virtualbox/nls/VirtualBox_ko.qm
++lib/virtualbox/nls/qt_sv.qm
++lib/virtualbox/nls/VirtualBox_sv.qm
++lib/virtualbox/nls/qt_fi.qm
++lib/virtualbox/nls/VirtualBox_fi.qm
++lib/virtualbox/nls/qt_hu.qm
++lib/virtualbox/nls/VirtualBox_hu.qm
++lib/virtualbox/nls/qt_cs.qm
++lib/virtualbox/nls/VirtualBox_cs.qm
++share/applications/virtualbox.desktop
++share/pixmaps/VBox.png
++
diff --git a/virtualbox/patches/patch-src_VBox_Installer_netbsd_postdeinstall.sh b/virtualbox/patches/patch-src_VBox_Installer_netbsd_postdeinstall.sh
new file mode 100644
index 0000000..73a1a9d
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_netbsd_postdeinstall.sh
@@ -0,0 +1,36 @@
+$NetBSD$
+
+--- src/VBox/Installer/netbsd/postdeinstall.sh.orig 2016-07-07 07:08:46.660385240 +0000
++++ src/VBox/Installer/netbsd/postdeinstall.sh
+@@ -0,0 +1,31 @@
++#!/bin/sh
++## @file
++#
++# VirtualBox postdeinstall script for NetBSD.
++#
++
++#
++# Copyright (C) 2007-2015 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.
++#
++
++echo "Removing kernel modules, please wait..."
++
++kldunload vboxnetadp
++kldunload vboxnetflt
++kldunload vboxdrv
++rm /boot/kernel/vboxnetflt.ko
++rm /boot/kernel/vboxnetadp.ko
++rm /boot/kernel/vboxdrv.ko
++kldxref -R /boot
++
++echo "Kernel modules successfully removed."
++
++exit 0
diff --git a/virtualbox/patches/patch-src_VBox_Installer_netbsd_postinstall.sh b/virtualbox/patches/patch-src_VBox_Installer_netbsd_postinstall.sh
new file mode 100644
index 0000000..33874f0
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_netbsd_postinstall.sh
@@ -0,0 +1,80 @@
+$NetBSD$
+
+--- src/VBox/Installer/netbsd/postinstall.sh.orig 2016-07-07 07:08:46.669159987 +0000
++++ src/VBox/Installer/netbsd/postinstall.sh
+@@ -0,0 +1,75 @@
++#!/bin/sh
++## @file
++#
++# VirtualBox postinstall script for NetBSD.
++#
++
++#
++# Copyright (C) 2007-2015 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_TMP="/tmp"
++PATH_TMP_MODS="$PATH_TMP/vbox_mods"
++PATH_INST="/usr/local/lib/virtualbox"
++PATH_KERN_SRC="/usr/src/sys"
++FILE_VBOXDRV="$PATH_INST/vboxdrv.tar.gz"
++
++
++if [ ! -f $PATH_KERN_SRC/Makefile ]; then
++ echo "Kernel sources are not installed. Please install them and reinstall VirtualBox"
++ exit 1
++fi
++
++echo "Compiling kernel modules, please wait..."
++
++# Create temporary directory
++mkdir -p $PATH_TMP_MODS
++
++# Unpack archive
++tar -C $PATH_TMP_MODS -xf $FILE_VBOXDRV
++
++# Compile
++cd $PATH_TMP_MODS
++make
++
++# Check if we succeeded
++if [ $? != 0 ]; then
++ echo "Compiling kernel modules failed."
++ cd ..
++ rm -rf $PATH_TMP_MODS
++ exit 1
++fi
++
++# Copy the modules to /boot/kernel
++echo "Installing kernel modules to /boot/kernel, please wait..."
++cp $PATH_TMP_MODS/vboxdrv.ko /boot/kernel
++cp $PATH_TMP_MODS/vboxnetflt.ko /boot/kernel
++cp $PATH_TMP_MODS/vboxnetadp.ko /boot/kernel
++kldxref -R /boot
++
++# Load them now, unloading old modules
++make load
++
++if [ $? != 0 ]; then
++ echo "Loading kernel modules failed"
++ cd ..
++ rm -rf $PATH_TMP_MODS
++ exit 1
++fi
++
++echo "Kernel modules successfully installed."
++echo "To load them on every boot put them into /boot/loader.conf"
++
++# Cleanup
++cd ..
++rm -rf $PATH_TMP_MODS
++
++exit 0
diff --git a/virtualbox/patches/patch-src_VBox_Installer_netbsd_virtualbox.desktop b/virtualbox/patches/patch-src_VBox_Installer_netbsd_virtualbox.desktop
new file mode 100644
index 0000000..d8f2b5b
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Installer_netbsd_virtualbox.desktop
@@ -0,0 +1,23 @@
+$NetBSD$
+
+--- src/VBox/Installer/netbsd/virtualbox.desktop.orig 2016-07-07 07:08:46.678057739 +0000
++++ src/VBox/Installer/netbsd/virtualbox.desktop
+@@ -0,0 +1,18 @@
++
++[Desktop Entry]
++Encoding=UTF-8
++Version=1.0
++Name=Oracle VM VirtualBox
++GenericName=Virtual Machine
++Type=Application
++Exec=VirtualBox
++TryExec=VirtualBox
++DocPath=file://$VBOX_DOC_PATH/UserManual.pdf
++Icon=VBox
++Categories=Emulator;System;
++Comment=Run several virtual systems on a single host computer
++Comment[de]=Windows und andere Betriebssysteme unter NetBSD ausführen
++Comment[it]=Esegui più macchine virtuali su un singolo computer
++Comment[pl]=Uruchamianie wielu systemów wirtualnych na jednym komputerze gospodarza
++Comment[sv]=Kör flera virtuella system på en enda värddator
++Comment[ko]=가상 머신
diff --git a/virtualbox/patches/patch-src_VBox_Main_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Main_Makefile.kmk
new file mode 100644
index 0000000..d874daa
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_Makefile.kmk
@@ -0,0 +1,47 @@
+$NetBSD$
+
+--- src/VBox/Main/Makefile.kmk.orig 2016-03-04 19:29:35.000000000 +0000
++++ src/VBox/Main/Makefile.kmk
+@@ -444,6 +444,10 @@ VBoxSVC_SOURCES.freebsd = \
+ src-server/freebsd/HostHardwareFreeBSD.cpp \
+ src-server/HostDnsServiceResolvConf.cpp
+
++VBoxSVC_SOURCES.netbsd = \
++ src-server/netbsd/HostHardwareNetBSD.cpp \
++ src-server/HostDnsServiceResolvConf.cpp
++
+
+ ifdef VBOX_WITH_USB
+ ifdef VBOX_WITH_SYSFS_BY_DEFAULT
+@@ -460,6 +464,7 @@ ifdef VBOX_WITH_USB
+ VBoxSVC_SOURCES.solaris += src-server/solaris/USBProxyServiceSolaris.cpp
+ VBoxSVC_SOURCES.win += src-server/win/USBProxyServiceWindows.cpp
+ VBoxSVC_SOURCES.freebsd += src-server/freebsd/USBProxyServiceFreeBSD.cpp
++ VBoxSVC_SOURCES.netbsd += src-server/netbsd/USBProxyServiceNetBSD.cpp
+ endif
+
+ ifdef VBOX_WITH_NETFLT
+@@ -487,6 +492,7 @@ ifdef VBOX_WITH_RESOURCE_USAGE_API
+ src-server/Performance.cpp
+ VBoxSVC_SOURCES.darwin += src-server/darwin/PerformanceDarwin.cpp
+ VBoxSVC_SOURCES.freebsd += src-server/freebsd/PerformanceFreeBSD.cpp
++ VBoxSVC_SOURCES.netbsd += src-server/netbsd/PerformanceNetBSD.cpp
+ VBoxSVC_SOURCES.linux += src-server/linux/PerformanceLinux.cpp
+ VBoxSVC_SOURCES.os2 += src-server/os2/PerformanceOs2.cpp
+ VBoxSVC_SOURCES.solaris += src-server/solaris/PerformanceSolaris.cpp
+@@ -503,8 +509,9 @@ ifdef VBOX_WITH_HOSTNETIF_API
+ VBoxSVC_SOURCES.darwin += src-server/darwin/NetIf-darwin.cpp
+ VBoxSVC_SOURCES.solaris += src-server/solaris/NetIf-solaris.cpp
+ VBoxSVC_SOURCES.freebsd += src-server/freebsd/NetIf-freebsd.cpp
++ VBoxSVC_SOURCES.netbsd += src-server/netbsd/NetIf-netbsd.cpp
+ VBoxSVC_DEFS += VBOX_WITH_HOSTNETIF_API
+- if1of ($(KBUILD_TARGET), linux darwin solaris freebsd)
++ if1of ($(KBUILD_TARGET), linux darwin solaris freebsd netbsd)
+ VBoxSVC_SOURCES += src-server/generic/NetIf-generic.cpp
+ endif
+ endif
+@@ -1273,4 +1280,3 @@ testapiwrappers:: \
+ updatenls::
+ $(VBOX_LUPDATE) $(VBoxSVC_SOURCES) $(VBoxSVC_VBOX_HEADERS) -ts $(VBoxSVC_VBOX_TRANSLATIONS)
+ $(VBOX_LUPDATE) $(VBoxC_SOURCES) $(VBoxC_VBOX_HEADERS) -ts $(VBoxC_VBOX_TRANSLATIONS)
+-
diff --git a/virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPIGlue.c b/virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPIGlue.c
new file mode 100644
index 0000000..95fbf04
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPIGlue.c
@@ -0,0 +1,28 @@
+$NetBSD$
+
+--- src/VBox/Main/cbinding/VBoxCAPIGlue.c.orig 2016-03-04 19:29:35.000000000 +0000
++++ src/VBox/Main/cbinding/VBoxCAPIGlue.c
+@@ -50,7 +50,7 @@
+ /*********************************************************************************************************************************
+ * Defined Constants And Macros *
+ *********************************************************************************************************************************/
+-#if defined(__linux__) || defined(__linux_gnu__) || defined(__sun__) || defined(__FreeBSD__)
++#if defined(__linux__) || defined(__linux_gnu__) || defined(__sun__) || defined(__FreeBSD__) || defined(__NetBSD__)
+ # define DYNLIB_NAME "VBoxXPCOMC.so"
+ #elif defined(__APPLE__)
+ # define DYNLIB_NAME "VBoxXPCOMC.dylib"
+@@ -280,6 +280,9 @@ int VBoxCGlueInit(void)
+ #elif defined(__FreeBSD__)
+ if (tryLoadLibrary("/usr/local/lib/virtualbox", 1) == 0)
+ return 0;
++#elif defined(__NetBSD__)
++ if (tryLoadLibrary("/usr/local/lib/virtualbox", 1) == 0)
++ return 0;
+ #elif defined(__OS2__)
+ if (tryLoadLibrary("C:/Apps/VirtualBox", 1) == 0)
+ return 0;
+@@ -336,4 +339,3 @@ void VBoxCGlueTerm(void)
+ g_pfnGetFunctions = NULL;
+ memset(g_szVBoxErrMsg, 0, sizeof(g_szVBoxErrMsg));
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPI__v2__2.h b/virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPI__v2__2.h
new file mode 100644
index 0000000..41c1e37
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPI__v2__2.h
@@ -0,0 +1,14 @@
+$NetBSD$
+
+--- src/VBox/Main/cbinding/VBoxCAPI_v2_2.h.orig 2016-03-04 19:29:35.000000000 +0000
++++ src/VBox/Main/cbinding/VBoxCAPI_v2_2.h
+@@ -921,7 +921,8 @@ enum CIMOSType
+ CIMOSType_CIMOS_Linux_2_6_x = 99,
+ CIMOSType_CIMOS_Linux_2_6_x_64 = 100,
+ CIMOSType_CIMOS_Linux_64 = 101,
+- CIMOSType_CIMOS_Other_64 = 102
++ CIMOSType_CIMOS_Other_64 = 102,
++ CIMOSType_CIMOS_NetBSD_64 = 103,
+ };
+ /* End of enum CIMOSType Declaration */
+
diff --git a/virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPI__v3__0.h b/virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPI__v3__0.h
new file mode 100644
index 0000000..9c4ee6e
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_cbinding_VBoxCAPI__v3__0.h
@@ -0,0 +1,14 @@
+$NetBSD$
+
+--- src/VBox/Main/cbinding/VBoxCAPI_v3_0.h.orig 2016-03-04 19:29:35.000000000 +0000
++++ src/VBox/Main/cbinding/VBoxCAPI_v3_0.h
+@@ -1371,7 +1371,8 @@ enum CIMOSType
+ CIMOSType_CIMOS_Linux_2_6_x = 99,
+ CIMOSType_CIMOS_Linux_2_6_x_64 = 100,
+ CIMOSType_CIMOS_Linux_64 = 101,
+- CIMOSType_CIMOS_Other_64 = 102
++ CIMOSType_CIMOS_Other_64 = 102,
++ CIMOSType_CIMOS_NetBSD_64 = 78,
+ };
+ /* End of enum CIMOSType Declaration */
+
diff --git a/virtualbox/patches/patch-src_VBox_Main_glue_tests_Makefile b/virtualbox/patches/patch-src_VBox_Main_glue_tests_Makefile
new file mode 100644
index 0000000..54b7003
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_glue_tests_Makefile
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/Main/glue/tests/Makefile.orig 2016-03-04 19:29:36.000000000 +0000
++++ src/VBox/Main/glue/tests/Makefile
+@@ -17,7 +17,7 @@
+ # User serviceable parts: adjust the following lines appropriately
+ #
+
+-# The host OS: linux, solaris, win, darwin, freebsd
++# The host OS: linux, solaris, win, darwin, freebsd, netbsd
+ HOSTOS=linux
+ # Absolute (!) path to the VirtualBox install directory
+ VBOX_BIN = /opt/VirtualBox
diff --git a/virtualbox/patches/patch-src_VBox_Main_include_ConsoleImpl.h b/virtualbox/patches/patch-src_VBox_Main_include_ConsoleImpl.h
new file mode 100644
index 0000000..1239e91
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_include_ConsoleImpl.h
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/VBox/Main/include/ConsoleImpl.h.orig 2016-03-04 19:29:36.000000000 +0000
++++ src/VBox/Main/include/ConsoleImpl.h
+@@ -579,7 +579,7 @@ private:
+ HRESULT i_powerDown(IProgress *aProgress = NULL);
+
+ /* Note: FreeBSD needs this whether netflt is used or not. */
+-#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
++#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD))
+ HRESULT i_attachToTapInterface(INetworkAdapter *networkAdapter);
+ HRESULT i_detachFromTapInterface(INetworkAdapter *networkAdapter);
+ #endif
+@@ -946,7 +946,7 @@ private:
+ } *mpIfSecKeyHlp;
+
+ /* Note: FreeBSD needs this whether netflt is used or not. */
+-#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
++#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD))
+ Utf8Str maTAPDeviceName[8];
+ RTFILE maTapFD[8];
+ #endif
diff --git a/virtualbox/patches/patch-src_VBox_Main_include_HostUSBDeviceImpl.h b/virtualbox/patches/patch-src_VBox_Main_include_HostUSBDeviceImpl.h
new file mode 100644
index 0000000..fd4b5e9
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_include_HostUSBDeviceImpl.h
@@ -0,0 +1,14 @@
+$NetBSD$
+
+--- src/VBox/Main/include/HostUSBDeviceImpl.h.orig 2016-03-04 19:29:37.000000000 +0000
++++ src/VBox/Main/include/HostUSBDeviceImpl.h
+@@ -323,6 +323,9 @@ private:
+ #ifdef RT_OS_FreeBSD
+ friend class USBProxyServiceFreeBSD;
+ #endif
++#ifdef RT_OS_NETBSD
++ friend class USBProxyServiceNetBSD;
++#endif
+ };
+
+ #endif // ____H_HOSTUSBDEVICEIMPL
diff --git a/virtualbox/patches/patch-src_VBox_Main_include_USBProxyService.h b/virtualbox/patches/patch-src_VBox_Main_include_USBProxyService.h
new file mode 100644
index 0000000..f971889
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_include_USBProxyService.h
@@ -0,0 +1,48 @@
+$NetBSD$
+
+--- src/VBox/Main/include/USBProxyService.h.orig 2016-03-04 19:29:37.000000000 +0000
++++ src/VBox/Main/include/USBProxyService.h
+@@ -347,7 +347,7 @@ private:
+ };
+ # endif /* RT_OS_WINDOWS */
+
+-# ifdef RT_OS_FREEBSD
++# ifdef defined(RT_OS_FREEBSD)
+ /**
+ * The FreeBSD hosted USB Proxy Service.
+ */
+@@ -376,5 +376,34 @@ private:
+ };
+ # endif /* RT_OS_FREEBSD */
+
++# ifdef defined(RT_OS_NETBSD)
++/**
++ * The NetBSD hosted USB Proxy Service.
++ */
++class USBProxyServiceNetBSD : public USBProxyService
++{
++public:
++ USBProxyServiceNetBSD(Host *aHost);
++ HRESULT init(void);
++ ~USBProxyServiceNetBSD();
++
++ virtual int captureDevice(HostUSBDevice *aDevice);
++ virtual int releaseDevice(HostUSBDevice *aDevice);
++
++protected:
++ int initUsbfs(void);
++ int initSysfs(void);
++ virtual int wait(RTMSINTERVAL aMillies);
++ virtual int interruptWait(void);
++ virtual PUSBDEVICE getDevices(void);
++ int addDeviceToChain(PUSBDEVICE pDev, PUSBDEVICE *ppFirst, PUSBDEVICE **pppNext, int rc);
++ virtual void deviceAdded(ComObjPtr<HostUSBDevice> &aDevice, SessionMachinesList &llOpenedMachines, PUSBDEVICE aUSBDevice);
++ virtual bool updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters, SessionMachine **aIgnoreMachine);
++
++private:
++ RTSEMEVENT mNotifyEventSem;
++};
++# endif /* RT_OS_NETBSD */
++
+ #endif /* !____H_USBPROXYSERVICE */
+ /* vi: set tabstop=4 shiftwidth=4 expandtab: */
diff --git a/virtualbox/patches/patch-src_VBox_Main_include_ovfreader.h b/virtualbox/patches/patch-src_VBox_Main_include_ovfreader.h
new file mode 100644
index 0000000..3d39375
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_include_ovfreader.h
@@ -0,0 +1,19 @@
+$NetBSD$
+
+--- src/VBox/Main/include/ovfreader.h.orig 2016-03-04 19:29:37.000000000 +0000
++++ src/VBox/Main/include/ovfreader.h
+@@ -174,7 +174,8 @@ enum CIMOSType_T
+ CIMOSType_CIMOS_CentOS_64 = 107,
+ CIMOSType_CIMOS_OracleEnterpriseLinux = 108,
+ CIMOSType_CIMOS_OracleEnterpriseLinux_64 = 109,
+- CIMOSType_CIMOS_eComStation = 110
++ CIMOSType_CIMOS_eComStation = 110,
++ CIMOSType_CIMOS_NetBSD_64 = 78,
+ // no new types added with CIM 2.26.0
+ };
+
+@@ -655,4 +656,3 @@ private:
+ } // end namespace ovf
+
+ #endif // !____H_OVFREADER
+-
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-client_ConsoleImpl.cpp b/virtualbox/patches/patch-src_VBox_Main_src-client_ConsoleImpl.cpp
new file mode 100644
index 0000000..2879188
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-client_ConsoleImpl.cpp
@@ -0,0 +1,54 @@
+$NetBSD$
+
+--- src/VBox/Main/src-client/ConsoleImpl.cpp.orig 2016-03-04 19:29:38.000000000 +0000
++++ src/VBox/Main/src-client/ConsoleImpl.cpp
+@@ -29,7 +29,7 @@
+ # include <stdio.h>
+ # include <stdlib.h>
+ # include <string.h>
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <errno.h>
+ # include <sys/ioctl.h>
+ # include <sys/poll.h>
+@@ -8771,7 +8771,7 @@ Console::i_usbDetachCallback(Console *th
+ #endif /* VBOX_WITH_USB */
+
+ /* Note: FreeBSD needs this whether netflt is used or not. */
+-#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
++#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD))
+ /**
+ * Helper function to handle host interface device creation and attachment.
+ *
+@@ -8885,7 +8885,7 @@ HRESULT Console::i_attachToTapInterface(
+ }
+ }
+
+-# elif defined(RT_OS_FREEBSD)
++# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /*
+ * Set/obtain the tap interface.
+ */
+@@ -9003,7 +9003,7 @@ HRESULT Console::i_detachFromTapInterfac
+ LogFlowThisFunc(("returning %d\n", rc));
+ return rc;
+ }
+-#endif /* (RT_OS_LINUX || RT_OS_FREEBSD) && !VBOX_WITH_NETFLT */
++#endif /* (RT_OS_LINUX || RT_OS_FREEBSD || RT_OS_NETBSD) && !VBOX_WITH_NETFLT */
+
+ /**
+ * Called at power down to terminate host interface networking.
+@@ -9047,11 +9047,11 @@ HRESULT Console::i_powerDownHostInterfac
+ pNetworkAdapter->COMGETTER(AttachmentType)(&attachment);
+ if (attachment == NetworkAttachmentType_Bridged)
+ {
+-#if ((defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT))
++#if ((defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)) && !defined(VBOX_WITH_NETFLT))
+ HRESULT rc2 = i_detachFromTapInterface(pNetworkAdapter);
+ if (FAILED(rc2) && SUCCEEDED(rc))
+ rc = rc2;
+-#endif /* (RT_OS_LINUX || RT_OS_FREEBSD) && !VBOX_WITH_NETFLT */
++#endif /* (RT_OS_LINUX || RT_OS_FREEBSD || RT_OS_NETBSD) && !VBOX_WITH_NETFLT */
+ }
+ }
+
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-client_ConsoleImpl2.cpp b/virtualbox/patches/patch-src_VBox_Main_src-client_ConsoleImpl2.cpp
new file mode 100644
index 0000000..86a4b27
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-client_ConsoleImpl2.cpp
@@ -0,0 +1,60 @@
+$NetBSD$
+
+--- src/VBox/Main/src-client/ConsoleImpl2.cpp.orig 2016-03-04 19:29:38.000000000 +0000
++++ src/VBox/Main/src-client/ConsoleImpl2.cpp
+@@ -97,7 +97,7 @@
+ # include <linux/types.h>
+ # include <linux/if.h>
+ # include <linux/wireless.h>
+-# elif defined(RT_OS_FREEBSD)
++# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <unistd.h>
+ # include <sys/types.h>
+ # include <sys/ioctl.h>
+@@ -2689,7 +2689,7 @@ int Console::i_configConstructorInner(PU
+ break;
+ }
+ #endif
+-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS) || defined(RT_OS_NETBSD)
+ case AudioDriverType_OSS:
+ {
+ InsertConfigString(pLunL1, "Driver", "OSSAudio");
+@@ -4638,7 +4638,7 @@ int Console::i_configNetwork(const char
+
+ case NetworkAttachmentType_Bridged:
+ {
+-#if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT)
++#if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)) && !defined(VBOX_WITH_NETFLT)
+ hrc = i_attachToTapInterface(aNetworkAdapter);
+ if (FAILED(hrc))
+ {
+@@ -4833,8 +4833,8 @@ int Console::i_configNetwork(const char
+ const char *pszTrunk = szTrunkName;
+ /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
+
+-# elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
+-# if defined(RT_OS_FREEBSD)
++# elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
++# if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /*
+ * If we bridge to a tap interface open it the `old' direct way.
+ * This works and performs better than bridging a physical
+@@ -4944,7 +4944,7 @@ int Console::i_configNetwork(const char
+ }
+ else
+ Log(("Failed to open wireless socket\n"));
+-# elif defined(RT_OS_FREEBSD)
++# elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ int iSock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (iSock >= 0)
+ {
+@@ -5062,7 +5062,7 @@ int Console::i_configNetwork(const char
+ /* NOTHING TO DO HERE */
+ #elif defined(RT_OS_LINUX)
+ /// @todo aleksey: is there anything to be done here?
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /** @todo FreeBSD: Check out this later (HIF networking). */
+ #else
+ # error "Port me"
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_ApplianceImpl.cpp b/virtualbox/patches/patch-src_VBox_Main_src-server_ApplianceImpl.cpp
new file mode 100644
index 0000000..4f0a92c
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_ApplianceImpl.cpp
@@ -0,0 +1,25 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/ApplianceImpl.cpp.orig 2016-03-04 19:29:39.000000000 +0000
++++ src/VBox/Main/src-server/ApplianceImpl.cpp
+@@ -138,6 +138,7 @@ g_osTypes[] =
+ { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2008, VBOXOSTYPE_Win2k8 },
+ { ovf::CIMOSType_CIMOS_MicrosoftWindowsServer2008_64, VBOXOSTYPE_Win2k8_x64 },
+ { ovf::CIMOSType_CIMOS_FreeBSD_64, VBOXOSTYPE_FreeBSD_x64 },
++ { ovf::CIMOSType_CIMOS_NetBSD_64, VBOXOSTYPE_NetBSD_x64 },
+ { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS },
+ { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS_x64 }, // there is no CIM 64-bit type for this
+ { ovf::CIMOSType_CIMOS_MACOS, VBOXOSTYPE_MacOS106 },
+@@ -263,6 +264,7 @@ static const osTypePattern g_osTypesPatt
+ {"OpenSolaris", VBOXOSTYPE_OpenSolaris_x64},
+ {"Solaris", VBOXOSTYPE_OpenSolaris_x64},
+ {"FreeBSD", VBOXOSTYPE_FreeBSD_x64},
++ {"NetBSD", VBOXOSTYPE_NetBSD_x64},
+ };
+
+ /**
+@@ -1695,4 +1697,3 @@ const settings::MachineConfigFile* Virtu
+ {
+ return m->pConfig;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_HostDnsService.cpp b/virtualbox/patches/patch-src_VBox_Main_src-server_HostDnsService.cpp
new file mode 100644
index 0000000..f266977
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_HostDnsService.cpp
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/HostDnsService.cpp.orig 2016-03-04 19:29:40.000000000 +0000
++++ src/VBox/Main/src-server/HostDnsService.cpp
+@@ -152,6 +152,8 @@ const HostDnsMonitor *HostDnsMonitor::ge
+ g_monitor = new HostDnsServiceSolaris();
+ # elif defined(RT_OS_FREEBSD)
+ g_monitor = new HostDnsServiceFreebsd();
++# elif defined(RT_OS_NETBSD)
++ g_monitor = new HostDnsServiceNetbsd();
+ # elif defined(RT_OS_OS2)
+ g_monitor = new HostDnsServiceOs2();
+ # else
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_HostDnsService.h b/virtualbox/patches/patch-src_VBox_Main_src-server_HostDnsService.h
new file mode 100644
index 0000000..82b9a2a
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_HostDnsService.h
@@ -0,0 +1,31 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/HostDnsService.h.orig 2016-03-04 19:29:40.000000000 +0000
++++ src/VBox/Main/src-server/HostDnsService.h
+@@ -154,7 +154,7 @@ class HostDnsServiceWin : public HostDns
+ Data *m;
+ };
+ # endif
+-# if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD)
++# if defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ class HostDnsServiceResolvConf: public HostDnsMonitor
+ {
+ public:
+@@ -215,6 +215,17 @@ class HostDnsServiceFreebsd: public Host
+ }
+ };
+
++# elif defined(RT_OS_NETBSD)
++class HostDnsServiceNetbsd: public HostDnsServiceResolvConf
++{
++ public:
++ HostDnsServiceNetbsd(){}
++ ~HostDnsServiceNetbsd(){}
++ virtual HRESULT init(VirtualBox *virtualbox) {
++ return HostDnsServiceResolvConf::init(virtualbox, "/etc/resolv.conf");
++ }
++};
++
+ # elif defined(RT_OS_OS2)
+ class HostDnsServiceOs2 : public HostDnsServiceResolvConf
+ {
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_HostImpl.cpp b/virtualbox/patches/patch-src_VBox_Main_src-server_HostImpl.cpp
new file mode 100644
index 0000000..f5a3d31
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_HostImpl.cpp
@@ -0,0 +1,63 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/HostImpl.cpp.orig 2016-03-04 19:29:40.000000000 +0000
++++ src/VBox/Main/src-server/HostImpl.cpp
+@@ -41,11 +41,11 @@
+ #include "MediumImpl.h"
+ #include "HostPower.h"
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <HostHardwareLinux.h>
+ #endif
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <set>
+ #endif
+
+@@ -212,7 +212,7 @@ struct Host::Data
+ bool fDVDDrivesListBuilt,
+ fFloppyDrivesListBuilt;
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /** Object with information about host drives */
+ VBoxMainDriveInfo hostDrives;
+ #endif
+@@ -288,6 +288,8 @@ HRESULT Host::init(VirtualBox *aParent)
+ m->pUSBProxyService = new USBProxyServiceWindows(this);
+ # elif defined(RT_OS_FREEBSD)
+ m->pUSBProxyService = new USBProxyServiceFreeBSD(this);
++# elif defined(RT_OS_NETBSD)
++ m->pUSBProxyService = new USBProxyServiceNetBSD(this);
+ # else
+ m->pUSBProxyService = new USBProxyService(this);
+ # endif
+@@ -419,7 +421,7 @@ HRESULT Host::init(VirtualBox *aParent)
+ m->f3DAccelerationSupported = false;
+ #endif
+
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /* Extract the list of configured host-only interfaces */
+ std::set<Utf8Str> aConfiguredNames;
+ SafeArray<BSTR> aGlobalExtraDataKeys;
+@@ -453,7 +455,7 @@ HRESULT Host::init(VirtualBox *aParent)
+ LogRel(("failed to create %s, error (0x%x)\n", it->c_str(), r));
+ }
+
+-#endif /* defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) */
++#endif /* defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD) */
+
+ /* Confirm a successful initialization */
+ autoInitSpan.setSucceeded();
+@@ -2074,7 +2076,7 @@ HRESULT Host::i_buildDVDDrivesList(Media
+ i_getDVDInfoFromDevTree(list);
+ }
+
+-#elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ if (RT_SUCCESS(m->hostDrives.updateDVDs()))
+ for (DriveInfoList::const_iterator it = m->hostDrives.DVDBegin();
+ SUCCEEDED(rc) && it != m->hostDrives.DVDEnd(); ++it)
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_HostNetworkInterfaceImpl.cpp b/virtualbox/patches/patch-src_VBox_Main_src-server_HostNetworkInterfaceImpl.cpp
new file mode 100644
index 0000000..0ad8657
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_HostNetworkInterfaceImpl.cpp
@@ -0,0 +1,16 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp.orig 2016-03-04 19:29:40.000000000 +0000
++++ src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp
+@@ -27,9 +27,9 @@
+
+ #include <iprt/cpp/utils.h>
+
+-#ifdef RT_OS_FREEBSD
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <netinet/in.h> /* INADDR_NONE */
+-#endif /* RT_OS_FREEBSD */
++#endif /* RT_OS_FREEBSD || RT_OS_NETBSD */
+
+ #include "VirtualBoxImpl.h"
+
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_MachineImpl.cpp b/virtualbox/patches/patch-src_VBox_Main_src-server_MachineImpl.cpp
new file mode 100644
index 0000000..a344b9d
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_MachineImpl.cpp
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/MachineImpl.cpp.orig 2016-03-04 19:29:40.000000000 +0000
++++ src/VBox/Main/src-server/MachineImpl.cpp
+@@ -2021,7 +2021,7 @@ HRESULT Machine::getMemoryBalloonSize(UL
+ HRESULT Machine::setMemoryBalloonSize(ULONG aMemoryBalloonSize)
+ {
+ /* This must match GMMR0Init; currently we only support memory ballooning on all 64-bit hosts except Mac OS X */
+-#if HC_ARCH_BITS == 64 && (defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD))
++#if HC_ARCH_BITS == 64 && (defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD))
+ /* check limits */
+ if (aMemoryBalloonSize >= VMMDEV_MAX_MEMORY_BALLOON(mHWData->mMemorySize))
+ return setError(E_INVALIDARG,
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_generic_NetIf-generic.cpp b/virtualbox/patches/patch-src_VBox_Main_src-server_generic_NetIf-generic.cpp
new file mode 100644
index 0000000..0cf276d
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_generic_NetIf-generic.cpp
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/generic/NetIf-generic.cpp.orig 2016-03-04 19:29:41.000000000 +0000
++++ src/VBox/Main/src-server/generic/NetIf-generic.cpp
+@@ -184,7 +184,7 @@ int NetIfCreateHostOnlyNetworkInterface(
+ IProgress **aProgress,
+ const char *pcszName)
+ {
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /* create a progress object */
+ ComObjPtr<Progress> progress;
+ progress.createObject();
+@@ -311,7 +311,7 @@ int NetIfCreateHostOnlyNetworkInterface(
+ int NetIfRemoveHostOnlyNetworkInterface(VirtualBox *pVirtualBox, IN_GUID aId,
+ IProgress **aProgress)
+ {
+-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /* create a progress object */
+ ComObjPtr<Progress> progress;
+ progress.createObject();
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_HostHardwareNetBSD.cpp b/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_HostHardwareNetBSD.cpp
new file mode 100644
index 0000000..081d414
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_HostHardwareNetBSD.cpp
@@ -0,0 +1,389 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/netbsd/HostHardwareNetBSD.cpp.orig 2016-07-06 20:08:39.045579684 +0000
++++ src/VBox/Main/src-server/netbsd/HostHardwareNetBSD.cpp
+@@ -0,0 +1,384 @@
++/* HostHardwareNetBSD.cpp $ */
++/** @file
++ * Classes for handling hardware detection under NetBSD.
++ */
++
++/*
++ * Copyright (C) 2008-2013 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.
++ */
++
++#define LOG_GROUP LOG_GROUP_MAIN
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++
++#include <HostHardwareLinux.h>
++
++#include <VBox/log.h>
++
++#include <iprt/dir.h>
++#include <iprt/env.h>
++#include <iprt/file.h>
++#include <iprt/mem.h>
++#include <iprt/param.h>
++#include <iprt/path.h>
++#include <iprt/string.h>
++
++#ifdef RT_OS_NETBSD
++# include <sys/param.h>
++# include <sys/types.h>
++# include <sys/stat.h>
++# include <unistd.h>
++# include <stdio.h>
++# include <sys/ioctl.h>
++# include <fcntl.h>
++# include <cam/cam.h>
++# include <cam/cam_ccb.h>
++# include <cam/scsi/scsi_pass.h>
++#endif /* RT_OS_NETBSD */
++#include <vector>
++
++
++/*********************************************************************************************************************************
++* Typedefs and Defines *
++*********************************************************************************************************************************/
++
++static int getDriveInfoFromEnv(const char *pcszVar, DriveInfoList *pList,
++ bool isDVD, bool *pfSuccess);
++static int getDVDInfoFromCAM(DriveInfoList *pList, bool *pfSuccess);
++
++/** Find the length of a string, ignoring trailing non-ascii or control
++ * characters */
++static size_t strLenStripped(const char *pcsz)
++{
++ size_t cch = 0;
++ for (size_t i = 0; pcsz[i] != '\0'; ++i)
++ if (pcsz[i] > 32 && pcsz[i] < 127)
++ cch = i;
++ return cch + 1;
++}
++
++static void strLenRemoveTrailingWhiteSpace(char *psz, size_t cchStr)
++{
++ while ( (cchStr > 0)
++ && (psz[cchStr -1] == ' '))
++ psz[--cchStr] = '\0';
++}
++
++/**
++ * Initialise the device description for a DVD drive based on
++ * vendor and model name strings.
++ * @param pcszVendor the vendor ID string
++ * @param pcszModel the product ID string
++ * @param pszDesc where to store the description string (optional)
++ * @param cchDesc the size of the buffer in @pszDesc
++ */
++/* static */
++void dvdCreateDeviceString(const char *pcszVendor, const char *pcszModel,
++ char *pszDesc, size_t cchDesc)
++{
++ AssertPtrReturnVoid(pcszVendor);
++ AssertPtrReturnVoid(pcszModel);
++ AssertPtrNullReturnVoid(pszDesc);
++ AssertReturnVoid(!pszDesc || cchDesc > 0);
++ size_t cchVendor = strLenStripped(pcszVendor);
++ size_t cchModel = strLenStripped(pcszModel);
++
++ /* Construct the description string as "Vendor Product" */
++ if (pszDesc)
++ {
++ if (cchVendor > 0)
++ RTStrPrintf(pszDesc, cchDesc, "%.*s %s", cchVendor, pcszVendor,
++ cchModel > 0 ? pcszModel : "(unknown drive model)");
++ else
++ RTStrPrintf(pszDesc, cchDesc, "%s", pcszModel);
++ }
++}
++
++
++int VBoxMainDriveInfo::updateDVDs ()
++{
++ LogFlowThisFunc(("entered\n"));
++ int rc = VINF_SUCCESS;
++ bool fSuccess = false; /* Have we succeeded in finding anything yet? */
++
++ try
++ {
++ mDVDList.clear ();
++ /* Always allow the user to override our auto-detection using an
++ * environment variable. */
++ if (RT_SUCCESS(rc) && !fSuccess)
++ rc = getDriveInfoFromEnv("VBOX_CDROM", &mDVDList, true /* isDVD */,
++ &fSuccess);
++ if (RT_SUCCESS(rc) && !fSuccess)
++ rc = getDVDInfoFromCAM(&mDVDList, &fSuccess);
++ }
++ catch(std::bad_alloc &e)
++ {
++ rc = VERR_NO_MEMORY;
++ }
++ LogFlowThisFunc(("rc=%Rrc\n", rc));
++ return rc;
++}
++
++int VBoxMainDriveInfo::updateFloppies ()
++{
++ LogFlowThisFunc(("entered\n"));
++ int rc = VINF_SUCCESS;
++ bool fSuccess = false; /* Have we succeeded in finding anything yet? */
++
++ try
++ {
++ mFloppyList.clear ();
++ /* Always allow the user to override our auto-detection using an
++ * environment variable. */
++ if (RT_SUCCESS(rc) && !fSuccess)
++ rc = getDriveInfoFromEnv("VBOX_FLOPPY", &mFloppyList, false /* isDVD */,
++ &fSuccess);
++ }
++ catch(std::bad_alloc &e)
++ {
++ rc = VERR_NO_MEMORY;
++ }
++ LogFlowThisFunc(("rc=%Rrc\n", rc));
++ return rc;
++}
++
++/**
++ * Search for available CD/DVD drives using the CAM layer.
++ *
++ * @returns iprt status code
++ * @param pList the list to append the drives found to
++ * @param pfSuccess this will be set to true if we found at least one drive
++ * and to false otherwise. Optional.
++ */
++static int getDVDInfoFromCAM(DriveInfoList *pList, bool *pfSuccess)
++{
++ int rc = VINF_SUCCESS;
++ RTFILE FileXpt;
++
++ rc = RTFileOpen(&FileXpt, "/dev/xpt0", RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
++ if (RT_SUCCESS(rc))
++ {
++ union ccb DeviceCCB;
++ struct dev_match_pattern DeviceMatchPattern;
++ struct dev_match_result *paMatches = NULL;
++
++ RT_ZERO(DeviceCCB);
++ RT_ZERO(DeviceMatchPattern);
++
++ /* We want to get all devices. */
++ DeviceCCB.ccb_h.func_code = XPT_DEV_MATCH;
++ DeviceCCB.ccb_h.path_id = CAM_XPT_PATH_ID;
++ DeviceCCB.ccb_h.target_id = CAM_TARGET_WILDCARD;
++ DeviceCCB.ccb_h.target_lun = CAM_LUN_WILDCARD;
++
++ /* Setup the pattern */
++ DeviceMatchPattern.type = DEV_MATCH_DEVICE;
++ DeviceMatchPattern.pattern.device_pattern.path_id = CAM_XPT_PATH_ID;
++ DeviceMatchPattern.pattern.device_pattern.target_id = CAM_TARGET_WILDCARD;
++ DeviceMatchPattern.pattern.device_pattern.target_lun = CAM_LUN_WILDCARD;
++ DeviceMatchPattern.pattern.device_pattern.flags = DEV_MATCH_INQUIRY;
++
++#if __NetBSD_version >= 900000
++# define INQ_PAT data.inq_pat
++#else
++ #define INQ_PAT inq_pat
++#endif
++ DeviceMatchPattern.pattern.device_pattern.INQ_PAT.type = T_CDROM;
++ DeviceMatchPattern.pattern.device_pattern.INQ_PAT.media_type = SIP_MEDIA_REMOVABLE | SIP_MEDIA_FIXED;
++ DeviceMatchPattern.pattern.device_pattern.INQ_PAT.vendor[0] = '*'; /* Matches anything */
++ DeviceMatchPattern.pattern.device_pattern.INQ_PAT.product[0] = '*'; /* Matches anything */
++ DeviceMatchPattern.pattern.device_pattern.INQ_PAT.revision[0] = '*'; /* Matches anything */
++#undef INQ_PAT
++ DeviceCCB.cdm.num_patterns = 1;
++ DeviceCCB.cdm.pattern_buf_len = sizeof(struct dev_match_result);
++ DeviceCCB.cdm.patterns = &DeviceMatchPattern;
++
++ /*
++ * Allocate the buffer holding the matches.
++ * We will allocate for 10 results and call
++ * CAM multiple times if we have more results.
++ */
++ paMatches = (struct dev_match_result *)RTMemAllocZ(10 * sizeof(struct dev_match_result));
++ if (paMatches)
++ {
++ DeviceCCB.cdm.num_matches = 0;
++ DeviceCCB.cdm.match_buf_len = 10 * sizeof(struct dev_match_result);
++ DeviceCCB.cdm.matches = paMatches;
++
++ do
++ {
++ rc = RTFileIoCtl(FileXpt, CAMIOCOMMAND, &DeviceCCB, sizeof(union ccb), NULL);
++ if (RT_FAILURE(rc))
++ {
++ Log(("Error while querying available CD/DVD devices rc=%Rrc\n", rc));
++ break;
++ }
++
++ for (unsigned i = 0; i < DeviceCCB.cdm.num_matches; i++)
++ {
++ if (paMatches[i].type == DEV_MATCH_DEVICE)
++ {
++ /* We have the drive now but need the appropriate device node */
++ struct device_match_result *pDevResult = &paMatches[i].result.device_result;
++ union ccb PeriphCCB;
++ struct dev_match_pattern PeriphMatchPattern;
++ struct dev_match_result aPeriphMatches[2];
++ struct periph_match_result *pPeriphResult = NULL;
++ unsigned iPeriphMatch = 0;
++
++ RT_ZERO(PeriphCCB);
++ RT_ZERO(PeriphMatchPattern);
++ RT_ZERO(aPeriphMatches);
++
++ /* This time we only want the specific nodes for the device. */
++ PeriphCCB.ccb_h.func_code = XPT_DEV_MATCH;
++ PeriphCCB.ccb_h.path_id = paMatches[i].result.device_result.path_id;
++ PeriphCCB.ccb_h.target_id = paMatches[i].result.device_result.target_id;
++ PeriphCCB.ccb_h.target_lun = paMatches[i].result.device_result.target_lun;
++
++ /* Setup the pattern */
++ PeriphMatchPattern.type = DEV_MATCH_PERIPH;
++ PeriphMatchPattern.pattern.periph_pattern.path_id = paMatches[i].result.device_result.path_id;
++ PeriphMatchPattern.pattern.periph_pattern.target_id = paMatches[i].result.device_result.target_id;
++ PeriphMatchPattern.pattern.periph_pattern.target_lun = paMatches[i].result.device_result.target_lun;
++ PeriphMatchPattern.pattern.periph_pattern.flags = PERIPH_MATCH_PATH | PERIPH_MATCH_TARGET |
++ PERIPH_MATCH_LUN;
++ PeriphCCB.cdm.num_patterns = 1;
++ PeriphCCB.cdm.pattern_buf_len = sizeof(struct dev_match_result);
++ PeriphCCB.cdm.patterns = &PeriphMatchPattern;
++ PeriphCCB.cdm.num_matches = 0;
++ PeriphCCB.cdm.match_buf_len = sizeof(aPeriphMatches);
++ PeriphCCB.cdm.matches = aPeriphMatches;
++
++ do
++ {
++ rc = RTFileIoCtl(FileXpt, CAMIOCOMMAND, &PeriphCCB, sizeof(union ccb), NULL);
++ if (RT_FAILURE(rc))
++ {
++ Log(("Error while querying available periph devices rc=%Rrc\n", rc));
++ break;
++ }
++
++ for (iPeriphMatch = 0; iPeriphMatch < PeriphCCB.cdm.num_matches; iPeriphMatch++)
++ {
++ if ( (aPeriphMatches[iPeriphMatch].type == DEV_MATCH_PERIPH)
++ && (!strcmp(aPeriphMatches[iPeriphMatch].result.periph_result.periph_name, "cd")))
++ {
++ pPeriphResult = &aPeriphMatches[iPeriphMatch].result.periph_result;
++ break; /* We found the periph device */
++ }
++ }
++
++ if (iPeriphMatch < PeriphCCB.cdm.num_matches)
++ break;
++
++ } while ( (DeviceCCB.ccb_h.status == CAM_REQ_CMP)
++ && (DeviceCCB.cdm.status == CAM_DEV_MATCH_MORE));
++
++ if (pPeriphResult)
++ {
++ char szPath[RTPATH_MAX];
++ char szDesc[256];
++
++ RTStrPrintf(szPath, sizeof(szPath), "/dev/%s%d",
++ pPeriphResult->periph_name, pPeriphResult->unit_number);
++
++ /* Remove trailing white space. */
++ strLenRemoveTrailingWhiteSpace(pDevResult->inq_data.vendor,
++ sizeof(pDevResult->inq_data.vendor));
++ strLenRemoveTrailingWhiteSpace(pDevResult->inq_data.product,
++ sizeof(pDevResult->inq_data.product));
++
++ dvdCreateDeviceString(pDevResult->inq_data.vendor,
++ pDevResult->inq_data.product,
++ szDesc, sizeof(szDesc));
++
++ pList->push_back(DriveInfo(szPath, "", szDesc));
++ if (pfSuccess)
++ *pfSuccess = true;
++ }
++ }
++ }
++ } while ( (DeviceCCB.ccb_h.status == CAM_REQ_CMP)
++ && (DeviceCCB.cdm.status == CAM_DEV_MATCH_MORE));
++
++ RTMemFree(paMatches);
++ }
++ else
++ rc = VERR_NO_MEMORY;
++
++ RTFileClose(FileXpt);
++ }
++
++ return rc;
++}
++
++/**
++ * Extract the names of drives from an environment variable and add them to a
++ * list if they are valid.
++ * @returns iprt status code
++ * @param pcszVar the name of the environment variable. The variable
++ * value should be a list of device node names, separated
++ * by ':' characters.
++ * @param pList the list to append the drives found to
++ * @param isDVD are we looking for DVD drives or for floppies?
++ * @param pfSuccess this will be set to true if we found at least one drive
++ * and to false otherwise. Optional.
++ */
++static int getDriveInfoFromEnv(const char *pcszVar, DriveInfoList *pList,
++ bool isDVD, bool *pfSuccess)
++{
++ AssertPtrReturn(pcszVar, VERR_INVALID_POINTER);
++ AssertPtrReturn(pList, VERR_INVALID_POINTER);
++ AssertPtrNullReturn(pfSuccess, VERR_INVALID_POINTER);
++ LogFlowFunc(("pcszVar=%s, pList=%p, isDVD=%d, pfSuccess=%p\n", pcszVar,
++ pList, isDVD, pfSuccess));
++ int rc = VINF_SUCCESS;
++ bool success = false;
++ char *pszFreeMe = RTEnvDupEx(RTENV_DEFAULT, pcszVar);
++
++ try
++ {
++ const char *pcszCurrent = pszFreeMe;
++ while (pcszCurrent && *pcszCurrent != '\0')
++ {
++ const char *pcszNext = strchr(pcszCurrent, ':');
++ char szPath[RTPATH_MAX], szReal[RTPATH_MAX];
++ char szDesc[256], szUdi[256];
++ if (pcszNext)
++ RTStrPrintf(szPath, sizeof(szPath), "%.*s",
++ pcszNext - pcszCurrent - 1, pcszCurrent);
++ else
++ RTStrPrintf(szPath, sizeof(szPath), "%s", pcszCurrent);
++ if (RT_SUCCESS(RTPathReal(szPath, szReal, sizeof(szReal))))
++ {
++ szUdi[0] = '\0'; /** @todo r=bird: missing a call to devValidateDevice() here and szUdi wasn't
++ * initialized because of that. Need proper fixing. */
++ pList->push_back(DriveInfo(szReal, szUdi, szDesc));
++ success = true;
++ }
++ pcszCurrent = pcszNext ? pcszNext + 1 : NULL;
++ }
++ if (pfSuccess != NULL)
++ *pfSuccess = success;
++ }
++ catch(std::bad_alloc &e)
++ {
++ rc = VERR_NO_MEMORY;
++ }
++ RTStrFree(pszFreeMe);
++ LogFlowFunc(("rc=%Rrc, success=%d\n", rc, success));
++ return rc;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_Makefile.kup b/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_Makefile.kup
new file mode 100644
index 0000000..34cfa7a
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_Makefile.kup
@@ -0,0 +1,6 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/netbsd/Makefile.kup.orig 2016-07-06 19:26:53.627141891 +0000
++++ src/VBox/Main/src-server/netbsd/Makefile.kup
+@@ -0,0 +1 @@
++#
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_NetIf-netbsd.cpp b/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_NetIf-netbsd.cpp
new file mode 100644
index 0000000..b7ce315
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_NetIf-netbsd.cpp
@@ -0,0 +1,429 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/netbsd/NetIf-netbsd.cpp.orig 2016-07-06 20:08:39.061471350 +0000
++++ src/VBox/Main/src-server/netbsd/NetIf-netbsd.cpp
+@@ -0,0 +1,424 @@
++/* NetIf-netbsd.cpp $ */
++/** @file
++ * Main - NetIfList, NetBSD implementation.
++ */
++
++/*
++ * Copyright (C) 2008-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.
++ */
++
++/*
++ * Original (C) 2009 Fredrik Lindberg <fli%shapeshifter.se@localhost>. Contributed
++ * to VirtualBox under the MIT license by the author.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#define LOG_GROUP LOG_GROUP_MAIN
++#include <sys/types.h>
++
++#include <sys/sysctl.h>
++#include <sys/socket.h>
++#include <sys/sockio.h>
++#include <net/if.h>
++#include <net/if_types.h>
++
++#include <net/route.h>
++/*
++ * route.h includes net/radix.h which for some reason defines Free as a wrapper
++ * around free. This collides with Free defined in xpcom/include/nsIMemory.h
++ * Undefine it and hope for the best
++ */
++#undef Free
++
++#include <net/if_dl.h>
++#include <netinet/in.h>
++
++#include <stdlib.h>
++#include <stdio.h>
++#include <unistd.h>
++#include <errno.h>
++
++#include <list>
++
++#include "HostNetworkInterfaceImpl.h"
++#include "netif.h"
++#include "Logging.h"
++
++#define ROUNDUP(a) \
++ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
++#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
++
++void extractAddresses(int iAddrMask, caddr_t cp, caddr_t cplim, struct sockaddr **pAddresses)
++{
++ struct sockaddr *sa;
++
++ for (int i = 0; i < RTAX_MAX && cp < cplim; i++) {
++ if (!(iAddrMask & (1 << i)))
++ continue;
++
++ sa = (struct sockaddr *)cp;
++
++ pAddresses[i] = sa;
++
++ ADVANCE(cp, sa);
++ }
++}
++
++static int getDefaultIfaceIndex(unsigned short *pu16Index, int family)
++{
++ size_t cbNeeded;
++ char *pBuf, *pNext;
++ int aiMib[6];
++ struct sockaddr *addresses[RTAX_MAX];
++ aiMib[0] = CTL_NET;
++ aiMib[1] = PF_ROUTE;
++ aiMib[2] = 0;
++ aiMib[3] = family; /* address family */
++ aiMib[4] = NET_RT_DUMP;
++ aiMib[5] = 0;
++
++ if (sysctl(aiMib, 6, NULL, &cbNeeded, NULL, 0) < 0)
++ {
++ Log(("getDefaultIfaceIndex: Failed to get estimate for list size (errno=%d).\n", errno));
++ return RTErrConvertFromErrno(errno);
++ }
++ if ((pBuf = (char*)malloc(cbNeeded)) == NULL)
++ return VERR_NO_MEMORY;
++ if (sysctl(aiMib, 6, pBuf, &cbNeeded, NULL, 0) < 0)
++ {
++ free(pBuf);
++ Log(("getDefaultIfaceIndex: Failed to retrieve interface table (errno=%d).\n", errno));
++ return RTErrConvertFromErrno(errno);
++ }
++
++ char *pEnd = pBuf + cbNeeded;
++ struct rt_msghdr *pRtMsg;
++ for (pNext = pBuf; pNext < pEnd; pNext += pRtMsg->rtm_msglen)
++ {
++ pRtMsg = (struct rt_msghdr *)pNext;
++
++ if (pRtMsg->rtm_type != RTM_GET)
++ {
++ Log(("getDefaultIfaceIndex: Got message %u while expecting %u.\n",
++ pRtMsg->rtm_type, RTM_GET));
++ //rc = VERR_INTERNAL_ERROR;
++ continue;
++ }
++ if ((char*)(pRtMsg + 1) < pEnd)
++ {
++ /* Extract addresses from the message. */
++ extractAddresses(pRtMsg->rtm_addrs, (char *)(pRtMsg + 1),
++ pRtMsg->rtm_msglen + (char *)pRtMsg, addresses);
++ if ((pRtMsg->rtm_addrs & RTA_DST))
++ {
++ if (addresses[RTAX_DST]->sa_family != AF_INET)
++ continue;
++ struct sockaddr_in *addr = (struct sockaddr_in *)addresses[RTAX_DST];
++ struct sockaddr_in *mask = (struct sockaddr_in *)addresses[RTAX_NETMASK];
++ if ((addr->sin_addr.s_addr == INADDR_ANY) &&
++ mask &&
++ (ntohl(mask->sin_addr.s_addr) == 0L ||
++ mask->sin_len == 0))
++ {
++ *pu16Index = pRtMsg->rtm_index;
++ free(pBuf);
++ return VINF_SUCCESS;
++ }
++ }
++ }
++ }
++ free(pBuf);
++ return VERR_INTERNAL_ERROR;
++
++}
++
++void extractAddressesToNetInfo(int iAddrMask, caddr_t cp, caddr_t cplim, PNETIFINFO pInfo)
++{
++ struct sockaddr *addresses[RTAX_MAX];
++
++ extractAddresses(iAddrMask, cp, cplim, addresses);
++ switch (addresses[RTAX_IFA]->sa_family)
++ {
++ case AF_INET:
++ if (!pInfo->IPAddress.u)
++ {
++ pInfo->IPAddress.u = ((struct sockaddr_in *)addresses[RTAX_IFA])->sin_addr.s_addr;
++ pInfo->IPNetMask.u = ((struct sockaddr_in *)addresses[RTAX_NETMASK])->sin_addr.s_addr;
++ }
++ break;
++ case AF_INET6:
++ if (!pInfo->IPv6Address.s.Lo && !pInfo->IPv6Address.s.Hi)
++ {
++ memcpy(pInfo->IPv6Address.au8,
++ ((struct sockaddr_in6 *)addresses[RTAX_IFA])->sin6_addr.__u6_addr.__u6_addr8,
++ sizeof(pInfo->IPv6Address));
++ memcpy(pInfo->IPv6NetMask.au8,
++ ((struct sockaddr_in6 *)addresses[RTAX_NETMASK])->sin6_addr.__u6_addr.__u6_addr8,
++ sizeof(pInfo->IPv6NetMask));
++ }
++ break;
++ default:
++ Log(("NetIfList: Unsupported address family: %u\n", addresses[RTAX_IFA]->sa_family));
++ break;
++ }
++}
++
++
++int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list)
++{
++ int rc = VINF_SUCCESS;
++ size_t cbNeeded;
++ char *pBuf, *pNext;
++ int aiMib[6];
++ unsigned short u16DefaultIface = 0; /* shut up gcc. */
++ bool fDefaultIfaceExistent = true;
++
++ /* Get the index of the interface associated with default route. */
++ rc = getDefaultIfaceIndex(&u16DefaultIface, PF_INET);
++ if (RT_FAILURE(rc))
++ {
++ fDefaultIfaceExistent = false;
++ rc = VINF_SUCCESS;
++ }
++
++ aiMib[0] = CTL_NET;
++ aiMib[1] = PF_ROUTE;
++ aiMib[2] = 0;
++ aiMib[3] = 0; /* address family */
++ aiMib[4] = NET_RT_IFLIST;
++ aiMib[5] = 0;
++
++ if (sysctl(aiMib, 6, NULL, &cbNeeded, NULL, 0) < 0)
++ {
++ Log(("NetIfList: Failed to get estimate for list size (errno=%d).\n", errno));
++ return RTErrConvertFromErrno(errno);
++ }
++ if ((pBuf = (char*)malloc(cbNeeded)) == NULL)
++ return VERR_NO_MEMORY;
++ if (sysctl(aiMib, 6, pBuf, &cbNeeded, NULL, 0) < 0)
++ {
++ free(pBuf);
++ Log(("NetIfList: Failed to retrieve interface table (errno=%d).\n", errno));
++ return RTErrConvertFromErrno(errno);
++ }
++
++ int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
++ if (sock < 0)
++ {
++ free(pBuf);
++ Log(("NetIfList: socket() -> %d\n", errno));
++ return RTErrConvertFromErrno(errno);
++ }
++
++ char *pEnd = pBuf + cbNeeded;
++ for (pNext = pBuf; pNext < pEnd;)
++ {
++ struct if_msghdr *pIfMsg = (struct if_msghdr *)pNext;
++
++ if (pIfMsg->ifm_type != RTM_IFINFO)
++ {
++ Log(("NetIfList: Got message %u while expecting %u.\n",
++ pIfMsg->ifm_type, RTM_IFINFO));
++ rc = VERR_INTERNAL_ERROR;
++ break;
++ }
++ struct sockaddr_dl *pSdl = (struct sockaddr_dl *)(pIfMsg + 1);
++
++ size_t cbNameLen = pSdl->sdl_nlen + 1;
++ PNETIFINFO pNew = (PNETIFINFO)RTMemAllocZ(RT_OFFSETOF(NETIFINFO, szName[cbNameLen]));
++ if (!pNew)
++ {
++ rc = VERR_NO_MEMORY;
++ break;
++ }
++ memcpy(pNew->MACAddress.au8, LLADDR(pSdl), sizeof(pNew->MACAddress.au8));
++ pNew->enmMediumType = NETIF_T_ETHERNET;
++ Assert(sizeof(pNew->szShortName) >= cbNameLen);
++ strlcpy(pNew->szShortName, pSdl->sdl_data, cbNameLen);
++ strlcpy(pNew->szName, pSdl->sdl_data, cbNameLen);
++ /* Generate UUID from name and MAC address. */
++ RTUUID uuid;
++ RTUuidClear(&uuid);
++ memcpy(&uuid, pNew->szShortName, RT_MIN(cbNameLen, sizeof(uuid)));
++ uuid.Gen.u8ClockSeqHiAndReserved = (uuid.Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80;
++ uuid.Gen.u16TimeHiAndVersion = (uuid.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
++ memcpy(uuid.Gen.au8Node, pNew->MACAddress.au8, sizeof(uuid.Gen.au8Node));
++ pNew->Uuid = uuid;
++
++ pNext += pIfMsg->ifm_msglen;
++ while (pNext < pEnd)
++ {
++ struct ifa_msghdr *pIfAddrMsg = (struct ifa_msghdr *)pNext;
++
++ if (pIfAddrMsg->ifam_type != RTM_NEWADDR)
++ break;
++ extractAddressesToNetInfo(pIfAddrMsg->ifam_addrs,
++ (char *)(pIfAddrMsg + 1),
++ pIfAddrMsg->ifam_msglen + (char *)pIfAddrMsg,
++ pNew);
++ pNext += pIfAddrMsg->ifam_msglen;
++ }
++
++ if (pSdl->sdl_type == IFT_ETHER || pSdl->sdl_type == IFT_L2VLAN)
++ {
++ struct ifreq IfReq;
++ RTStrCopy(IfReq.ifr_name, sizeof(IfReq.ifr_name), pNew->szShortName);
++ if (ioctl(sock, SIOCGIFFLAGS, &IfReq) < 0)
++ {
++ Log(("NetIfList: ioctl(SIOCGIFFLAGS) -> %d\n", errno));
++ pNew->enmStatus = NETIF_S_UNKNOWN;
++ }
++ else
++ pNew->enmStatus = (IfReq.ifr_flags & IFF_UP) ? NETIF_S_UP : NETIF_S_DOWN;
++
++ HostNetworkInterfaceType_T enmType;
++ if (strncmp(pNew->szName, RT_STR_TUPLE("vboxnet")))
++ enmType = HostNetworkInterfaceType_Bridged;
++ else
++ enmType = HostNetworkInterfaceType_HostOnly;
++
++ ComObjPtr<HostNetworkInterface> IfObj;
++ IfObj.createObject();
++ if (SUCCEEDED(IfObj->init(Bstr(pNew->szName), enmType, pNew)))
++ {
++ /* Make sure the default interface gets to the beginning. */
++ if ( fDefaultIfaceExistent
++ && pIfMsg->ifm_index == u16DefaultIface)
++ list.push_front(IfObj);
++ else
++ list.push_back(IfObj);
++ }
++ }
++ RTMemFree(pNew);
++ }
++
++ close(sock);
++ free(pBuf);
++ return rc;
++
++
++}
++
++int NetIfGetConfigByName(PNETIFINFO pInfo)
++{
++ int rc = VINF_SUCCESS;
++ size_t cbNeeded;
++ char *pBuf, *pNext;
++ int aiMib[6];
++
++ aiMib[0] = CTL_NET;
++ aiMib[1] = PF_ROUTE;
++ aiMib[2] = 0;
++ aiMib[3] = 0; /* address family */
++ aiMib[4] = NET_RT_IFLIST;
++ aiMib[5] = 0;
++
++ if (sysctl(aiMib, 6, NULL, &cbNeeded, NULL, 0) < 0)
++ {
++ Log(("NetIfList: Failed to get estimate for list size (errno=%d).\n", errno));
++ return RTErrConvertFromErrno(errno);
++ }
++ if ((pBuf = (char*)malloc(cbNeeded)) == NULL)
++ return VERR_NO_MEMORY;
++ if (sysctl(aiMib, 6, pBuf, &cbNeeded, NULL, 0) < 0)
++ {
++ free(pBuf);
++ Log(("NetIfList: Failed to retrieve interface table (errno=%d).\n", errno));
++ return RTErrConvertFromErrno(errno);
++ }
++
++ int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
++ if (sock < 0)
++ {
++ free(pBuf);
++ Log(("NetIfList: socket() -> %d\n", errno));
++ return RTErrConvertFromErrno(errno);
++ }
++
++ char *pEnd = pBuf + cbNeeded;
++ for (pNext = pBuf; pNext < pEnd;)
++ {
++ struct if_msghdr *pIfMsg = (struct if_msghdr *)pNext;
++
++ if (pIfMsg->ifm_type != RTM_IFINFO)
++ {
++ Log(("NetIfList: Got message %u while expecting %u.\n",
++ pIfMsg->ifm_type, RTM_IFINFO));
++ rc = VERR_INTERNAL_ERROR;
++ break;
++ }
++ struct sockaddr_dl *pSdl = (struct sockaddr_dl *)(pIfMsg + 1);
++
++ bool fSkip = !!strcmp(pInfo->szShortName, pSdl->sdl_data);
++
++ pNext += pIfMsg->ifm_msglen;
++ while (pNext < pEnd)
++ {
++ struct ifa_msghdr *pIfAddrMsg = (struct ifa_msghdr *)pNext;
++
++ if (pIfAddrMsg->ifam_type != RTM_NEWADDR)
++ break;
++ if (!fSkip)
++ extractAddressesToNetInfo(pIfAddrMsg->ifam_addrs,
++ (char *)(pIfAddrMsg + 1),
++ pIfAddrMsg->ifam_msglen + (char *)pIfAddrMsg,
++ pInfo);
++ pNext += pIfAddrMsg->ifam_msglen;
++ }
++
++ if (!fSkip && (pSdl->sdl_type == IFT_ETHER || pSdl->sdl_type == IFT_L2VLAN))
++ {
++ size_t cbNameLen = pSdl->sdl_nlen + 1;
++ memcpy(pInfo->MACAddress.au8, LLADDR(pSdl), sizeof(pInfo->MACAddress.au8));
++ pInfo->enmMediumType = NETIF_T_ETHERNET;
++ /* Generate UUID from name and MAC address. */
++ RTUUID uuid;
++ RTUuidClear(&uuid);
++ memcpy(&uuid, pInfo->szShortName, RT_MIN(cbNameLen, sizeof(uuid)));
++ uuid.Gen.u8ClockSeqHiAndReserved = (uuid.Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80;
++ uuid.Gen.u16TimeHiAndVersion = (uuid.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
++ memcpy(uuid.Gen.au8Node, pInfo->MACAddress.au8, sizeof(uuid.Gen.au8Node));
++ pInfo->Uuid = uuid;
++
++ struct ifreq IfReq;
++ RTStrCopy(IfReq.ifr_name, sizeof(IfReq.ifr_name), pInfo->szShortName);
++ if (ioctl(sock, SIOCGIFFLAGS, &IfReq) < 0)
++ {
++ Log(("NetIfList: ioctl(SIOCGIFFLAGS) -> %d\n", errno));
++ pInfo->enmStatus = NETIF_S_UNKNOWN;
++ }
++ else
++ pInfo->enmStatus = (IfReq.ifr_flags & IFF_UP) ? NETIF_S_UP : NETIF_S_DOWN;
++
++ return VINF_SUCCESS;
++ }
++ }
++ close(sock);
++ free(pBuf);
++ return rc;
++}
++
++/**
++ * Retrieve the physical link speed in megabits per second. If the interface is
++ * not up or otherwise unavailable the zero speed is returned.
++ *
++ * @returns VBox status code.
++ *
++ * @param pcszIfName Interface name.
++ * @param puMbits Where to store the link speed.
++ */
++int NetIfGetLinkSpeed(const char * /*pcszIfName*/, uint32_t * /*puMbits*/)
++{
++ return VERR_NOT_IMPLEMENTED;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_PerformanceNetBSD.cpp b/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_PerformanceNetBSD.cpp
new file mode 100644
index 0000000..1b5993a
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_PerformanceNetBSD.cpp
@@ -0,0 +1,122 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/netbsd/PerformanceNetBSD.cpp.orig 2016-07-06 20:08:39.069695369 +0000
++++ src/VBox/Main/src-server/netbsd/PerformanceNetBSD.cpp
+@@ -0,0 +1,117 @@
++/* PerformanceNetBSD.cpp $ */
++/** @file
++ * VirtualBox Performance Collector, NetBSD Specialization.
++ */
++
++/*
++ * Copyright (C) 2008-2013 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.
++ */
++
++#include <sys/types.h>
++#include <sys/sysctl.h>
++#include "Performance.h"
++
++namespace pm {
++
++class CollectorNetBSD : public CollectorHAL
++{
++public:
++ virtual int getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle);
++ virtual int getHostCpuMHz(ULONG *mhz);
++ virtual int getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available);
++ virtual int getProcessCpuLoad(RTPROCESS process, ULONG *user, ULONG *kernel);
++ virtual int getProcessMemoryUsage(RTPROCESS process, ULONG *used);
++};
++
++
++CollectorHAL *createHAL()
++{
++ return new CollectorNetBSD();
++}
++
++int CollectorNetBSD::getHostCpuLoad(ULONG *user, ULONG *kernel, ULONG *idle)
++{
++ return VERR_NOT_IMPLEMENTED;
++}
++
++int CollectorNetBSD::getHostCpuMHz(ULONG *mhz)
++{
++ int CpuMHz = 0;
++ size_t cbParameter = sizeof(CpuMHz);
++
++ /** @todo: Howto support more than one CPU? */
++ if (sysctlbyname("dev.cpu.0.freq", &CpuMHz, &cbParameter, NULL, 0))
++ return VERR_NOT_SUPPORTED;
++
++ *mhz = CpuMHz;
++
++ return VINF_SUCCESS;
++}
++
++int CollectorNetBSD::getHostMemoryUsage(ULONG *total, ULONG *used, ULONG *available)
++{
++ int rc = VINF_SUCCESS;
++ u_long cbMemPhys = 0;
++ u_int cPagesMemFree = 0;
++ u_int cPagesMemInactive = 0;
++ u_int cPagesMemCached = 0;
++ u_int cPagesMemUsed = 0;
++ int cbPage = 0;
++ size_t cbParameter = sizeof(cbMemPhys);
++ int cProcessed = 0;
++
++ if (!sysctlbyname("hw.physmem", &cbMemPhys, &cbParameter, NULL, 0))
++ cProcessed++;
++
++ cbParameter = sizeof(cPagesMemFree);
++ if (!sysctlbyname("vm.stats.vm.v_free_count", &cPagesMemFree, &cbParameter, NULL, 0))
++ cProcessed++;
++ cbParameter = sizeof(cPagesMemUsed);
++ if (!sysctlbyname("vm.stats.vm.v_active_count", &cPagesMemUsed, &cbParameter, NULL, 0))
++ cProcessed++;
++ cbParameter = sizeof(cPagesMemInactive);
++ if (!sysctlbyname("vm.stats.vm.v_inactive_count", &cPagesMemInactive, &cbParameter, NULL, 0))
++ cProcessed++;
++ cbParameter = sizeof(cPagesMemCached);
++ if (!sysctlbyname("vm.stats.vm.v_cache_count", &cPagesMemCached, &cbParameter, NULL, 0))
++ cProcessed++;
++ cbParameter = sizeof(cbPage);
++ if (!sysctlbyname("hw.pagesize", &cbPage, &cbParameter, NULL, 0))
++ cProcessed++;
++
++ if (cProcessed == 6)
++ {
++ *total = cbMemPhys / _1K;
++ *used = cPagesMemUsed * (cbPage / _1K);
++ *available = (cPagesMemFree + cPagesMemInactive + cPagesMemCached ) * (cbPage / _1K);
++ }
++ else
++ rc = VERR_NOT_SUPPORTED;
++
++ return rc;
++}
++
++int CollectorNetBSD::getProcessCpuLoad(RTPROCESS process, ULONG *user, ULONG *kernel)
++{
++ return VERR_NOT_IMPLEMENTED;
++}
++
++int CollectorNetBSD::getProcessMemoryUsage(RTPROCESS process, ULONG *used)
++{
++ return VERR_NOT_IMPLEMENTED;
++}
++
++int getDiskListByFs(const char *name, DiskList& list)
++{
++ return VERR_NOT_IMPLEMENTED;
++}
++
++} /* namespace pm */
diff --git a/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_USBProxyServiceNetBSD.cpp b/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_USBProxyServiceNetBSD.cpp
new file mode 100644
index 0000000..e4ed058
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_src-server_netbsd_USBProxyServiceNetBSD.cpp
@@ -0,0 +1,359 @@
+$NetBSD$
+
+--- src/VBox/Main/src-server/netbsd/USBProxyServiceNetBSD.cpp.orig 2016-07-06 20:08:39.078040350 +0000
++++ src/VBox/Main/src-server/netbsd/USBProxyServiceNetBSD.cpp
+@@ -0,0 +1,354 @@
++/* USBProxyServiceNetBSD.cpp $ */
++/** @file
++ * VirtualBox USB Proxy Service, NetBSD Specialization.
++ */
++
++/*
++ * Copyright (C) 2005-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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "USBProxyService.h"
++#include "Logging.h"
++
++#include <VBox/usb.h>
++#include <VBox/usblib.h>
++#include <VBox/err.h>
++
++#include <iprt/string.h>
++#include <iprt/alloc.h>
++#include <iprt/assert.h>
++#include <iprt/file.h>
++#include <iprt/err.h>
++#include <iprt/mem.h>
++#include <iprt/param.h>
++#include <iprt/path.h>
++#include <iprt/semaphore.h>
++
++#include <stdlib.h>
++#include <string.h>
++#include <stdio.h>
++#include <errno.h>
++#include <unistd.h>
++#include <fcntl.h>
++#include <sys/poll.h>
++#include <dev/usb/usb.h>
++#include <dev/usb/usb_ioctl.h>
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++
++
++/*********************************************************************************************************************************
++* Global Variables *
++*********************************************************************************************************************************/
++
++/**
++ * Initialize data members.
++ */
++USBProxyServiceNetBSD::USBProxyServiceNetBSD(Host *aHost)
++ : USBProxyService(aHost)
++{
++ LogFlowThisFunc(("aHost=%p\n", aHost));
++}
++
++
++/**
++ * Initializes the object (called right after construction).
++ *
++ * @returns S_OK on success and non-fatal failures, some COM error otherwise.
++ */
++HRESULT USBProxyServiceNetBSD::init(void)
++{
++ /*
++ * Create semaphore.
++ */
++ int rc = RTSemEventCreate(&mNotifyEventSem);
++ if (RT_FAILURE(rc))
++ {
++ mLastError = rc;
++ return E_FAIL;
++ }
++
++ /*
++ * Start the poller thread.
++ */
++ start();
++ return S_OK;
++}
++
++
++/**
++ * Stop all service threads and free the device chain.
++ */
++USBProxyServiceNetBSD::~USBProxyServiceNetBSD()
++{
++ LogFlowThisFunc(("\n"));
++
++ /*
++ * Stop the service.
++ */
++ if (isActive())
++ stop();
++
++ RTSemEventDestroy(mNotifyEventSem);
++ mNotifyEventSem = NULL;
++}
++
++
++int USBProxyServiceNetBSD::captureDevice(HostUSBDevice *aDevice)
++{
++ AssertReturn(aDevice, VERR_GENERAL_FAILURE);
++ AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE);
++
++ AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS);
++ LogFlowThisFunc(("aDevice=%s\n", aDevice->i_getName().c_str()));
++
++ /*
++ * Don't think we need to do anything when the device is held... fake it.
++ */
++ Assert(aDevice->i_getUnistate() == kHostUSBDeviceState_Capturing);
++ devLock.release();
++ interruptWait();
++
++ return VINF_SUCCESS;
++}
++
++
++int USBProxyServiceNetBSD::releaseDevice(HostUSBDevice *aDevice)
++{
++ AssertReturn(aDevice, VERR_GENERAL_FAILURE);
++ AssertReturn(!aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE);
++
++ AutoReadLock devLock(aDevice COMMA_LOCKVAL_SRC_POS);
++ LogFlowThisFunc(("aDevice=%s\n", aDevice->i_getName().c_str()));
++
++ /*
++ * We're not really holding it atm., just fake it.
++ */
++ Assert(aDevice->i_getUnistate() == kHostUSBDeviceState_ReleasingToHost);
++ devLock.release();
++ interruptWait();
++
++ return VINF_SUCCESS;
++}
++
++
++bool USBProxyServiceNetBSD::updateDeviceState(HostUSBDevice *aDevice, PUSBDEVICE aUSBDevice, bool *aRunFilters,
++ SessionMachine **aIgnoreMachine)
++{
++ AssertReturn(aDevice, false);
++ AssertReturn(!aDevice->isWriteLockOnCurrentThread(), false);
++
++ return updateDeviceStateFake(aDevice, aUSBDevice, aRunFilters, aIgnoreMachine);
++}
++
++
++/**
++ * A device was added
++ *
++ * See USBProxyService::deviceAdded for details.
++ */
++void USBProxyServiceNetBSD::deviceAdded(ComObjPtr<HostUSBDevice> &aDevice, SessionMachinesList &llOpenedMachines,
++ PUSBDEVICE aUSBDevice)
++{
++ USBProxyService::deviceAdded(aDevice, llOpenedMachines, aUSBDevice);
++}
++
++int USBProxyServiceNetBSD::wait(RTMSINTERVAL aMillies)
++{
++ return RTSemEventWait(mNotifyEventSem, aMillies < 1000 ? 1000 : 5000);
++}
++
++
++int USBProxyServiceNetBSD::interruptWait(void)
++{
++ return RTSemEventSignal(mNotifyEventSem);
++}
++
++
++/**
++ * Dumps a USBDEVICE structure to the log using LogLevel 3.
++ * @param pDev The structure to log.
++ * @todo This is really common code.
++ */
++DECLINLINE(void) usbLogDevice(PUSBDEVICE pDev)
++{
++ NOREF(pDev);
++
++ Log3(("USB device:\n"));
++ Log3(("Product: %s (%x)\n", pDev->pszProduct, pDev->idProduct));
++ Log3(("Manufacturer: %s (Vendor ID %x)\n", pDev->pszManufacturer, pDev->idVendor));
++ Log3(("Serial number: %s (%llx)\n", pDev->pszSerialNumber, pDev->u64SerialHash));
++ Log3(("Device revision: %d\n", pDev->bcdDevice));
++ Log3(("Device class: %x\n", pDev->bDeviceClass));
++ Log3(("Device subclass: %x\n", pDev->bDeviceSubClass));
++ Log3(("Device protocol: %x\n", pDev->bDeviceProtocol));
++ Log3(("USB version number: %d\n", pDev->bcdUSB));
++ Log3(("Device speed: %s\n",
++ pDev->enmSpeed == USBDEVICESPEED_UNKNOWN ? "unknown"
++ : pDev->enmSpeed == USBDEVICESPEED_LOW ? "1.5 MBit/s"
++ : pDev->enmSpeed == USBDEVICESPEED_FULL ? "12 MBit/s"
++ : pDev->enmSpeed == USBDEVICESPEED_HIGH ? "480 MBit/s"
++ : pDev->enmSpeed == USBDEVICESPEED_VARIABLE ? "variable"
++ : "invalid"));
++ Log3(("Number of configurations: %d\n", pDev->bNumConfigurations));
++ Log3(("Bus number: %d\n", pDev->bBus));
++ Log3(("Port number: %d\n", pDev->bPort));
++ Log3(("Device number: %d\n", pDev->bDevNum));
++ Log3(("Device state: %s\n",
++ pDev->enmState == USBDEVICESTATE_UNSUPPORTED ? "unsupported"
++ : pDev->enmState == USBDEVICESTATE_USED_BY_HOST ? "in use by host"
++ : pDev->enmState == USBDEVICESTATE_USED_BY_HOST_CAPTURABLE ? "in use by host, possibly capturable"
++ : pDev->enmState == USBDEVICESTATE_UNUSED ? "not in use"
++ : pDev->enmState == USBDEVICESTATE_HELD_BY_PROXY ? "held by proxy"
++ : pDev->enmState == USBDEVICESTATE_USED_BY_GUEST ? "used by guest"
++ : "invalid"));
++ Log3(("OS device address: %s\n", pDev->pszAddress));
++}
++
++PUSBDEVICE USBProxyServiceNetBSD::getDevices(void)
++{
++ PUSBDEVICE pDevices = NULL;
++ int FileUsb = 0;
++ int iBus = 0;
++ int iAddr = 1;
++ int rc = VINF_SUCCESS;
++ char *pszDevicePath = NULL;
++ uint32_t PlugTime = 0;
++
++ for (;;)
++ {
++ rc = RTStrAPrintf(&pszDevicePath, "/dev/%s%d.%d", USB_GENERIC_NAME, iBus, iAddr);
++ if (RT_FAILURE(rc))
++ {
++ mLastError = rc;
++ break;
++ }
++
++ LogFlowFunc((": Opening %s\n", pszDevicePath));
++
++ FileUsb = open(pszDevicePath, O_RDONLY);
++ if (FileUsb < 0)
++ {
++ if ( (errno != ENOENT)
++ && (errno != EACCES))
++ mLastError = RTErrConvertFromErrno(errno);
++
++ RTStrFree(pszDevicePath);
++
++ if ((errno == ENOENT) && (iAddr > 1))
++ {
++ iAddr = 1;
++ iBus++;
++ continue;
++ }
++ else if (errno == EACCES)
++ {
++ /* Skip devices without the right permission. */
++ iAddr++;
++ continue;
++ }
++ else
++ break;
++ }
++
++ LogFlowFunc((": %s opened successfully\n", pszDevicePath));
++
++ struct usb_device_info UsbDevInfo;
++ RT_ZERO(UsbDevInfo);
++
++ rc = ioctl(FileUsb, USB_GET_DEVICEINFO, &UsbDevInfo);
++ if (rc < 0)
++ {
++ LogFlowFunc((": Error querying device info rc=%Rrc\n", RTErrConvertFromErrno(errno)));
++ mLastError = RTErrConvertFromErrno(errno);
++ close(FileUsb);
++ RTStrFree(pszDevicePath);
++ break;
++ }
++
++ /* Filter out hubs */
++ if (UsbDevInfo.udi_class != 0x09)
++ {
++ PUSBDEVICE pDevice = (PUSBDEVICE)RTMemAllocZ(sizeof(USBDEVICE));
++ if (!pDevice)
++ {
++ mLastError = VERR_NO_MEMORY;
++ close(FileUsb);
++ RTStrFree(pszDevicePath);
++ break;
++ }
++
++ pDevice->enmState = USBDEVICESTATE_UNUSED;
++ pDevice->bBus = UsbDevInfo.udi_bus;
++ pDevice->bDeviceClass = UsbDevInfo.udi_class;
++ pDevice->bDeviceSubClass = UsbDevInfo.udi_subclass;
++ pDevice->bDeviceProtocol = UsbDevInfo.udi_protocol;
++ pDevice->bNumConfigurations = UsbDevInfo.udi_config_no;
++ pDevice->idVendor = UsbDevInfo.udi_vendorNo;
++ pDevice->idProduct = UsbDevInfo.udi_productNo;
++ pDevice->bDevNum = UsbDevInfo.udi_index;
++
++ switch (UsbDevInfo.udi_speed)
++ {
++ case USB_SPEED_LOW:
++ pDevice->enmSpeed = USBDEVICESPEED_LOW;
++ break;
++ case USB_SPEED_FULL:
++ pDevice->enmSpeed = USBDEVICESPEED_FULL;
++ break;
++ case USB_SPEED_HIGH:
++ pDevice->enmSpeed = USBDEVICESPEED_HIGH;
++ break;
++ case USB_SPEED_SUPER:
++ case USB_SPEED_VARIABLE:
++ default:
++ pDevice->enmSpeed = USBDEVICESPEED_UNKNOWN;
++ }
++
++ if (UsbDevInfo.udi_vendor[0] != '\0')
++ pDevice->pszManufacturer = RTStrDupN(UsbDevInfo.udi_vendor, sizeof(UsbDevInfo.udi_vendor));
++
++ if (UsbDevInfo.udi_product[0] != '\0')
++ pDevice->pszProduct = RTStrDupN(UsbDevInfo.udi_product, sizeof(UsbDevInfo.udi_product));
++
++ if (UsbDevInfo.udi_serial[0] != '\0')
++ {
++ pDevice->pszSerialNumber = RTStrDupN(UsbDevInfo.udi_serial, sizeof(UsbDevInfo.udi_serial));
++ pDevice->u64SerialHash = USBLibHashSerial(pDevice->pszSerialNumber);
++ }
++ rc = ioctl(FileUsb, USB_GET_PLUGTIME, &PlugTime);
++ if (rc == 0)
++ pDevice->u64SerialHash += PlugTime;
++
++ pDevice->pszAddress = RTStrDup(pszDevicePath);
++ pDevice->enmState = USBDEVICESTATE_USED_BY_HOST_CAPTURABLE;
++
++ usbLogDevice(pDevice);
++
++ pDevice->pNext = pDevices;
++ if (pDevices)
++ pDevices->pPrev = pDevice;
++ pDevices = pDevice;
++ }
++ close(FileUsb);
++ RTStrFree(pszDevicePath);
++ iAddr++;
++ }
++
++ return pDevices;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Main_testcase_tstCollector.cpp b/virtualbox/patches/patch-src_VBox_Main_testcase_tstCollector.cpp
new file mode 100644
index 0000000..fa822d0
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_testcase_tstCollector.cpp
@@ -0,0 +1,19 @@
+$NetBSD$
+
+--- src/VBox/Main/testcase/tstCollector.cpp.orig 2016-03-04 19:29:42.000000000 +0000
++++ src/VBox/Main/testcase/tstCollector.cpp
+@@ -23,6 +23,9 @@
+ #ifdef RT_OS_FREEBSD
+ # include "../src-server/freebsd/PerformanceFreeBSD.cpp"
+ #endif
++#ifdef RT_OS_NETBSD
++# include "../src-server/netbsd/PerformanceNetBSD.cpp"
++#endif
+ #ifdef RT_OS_LINUX
+ # include "../src-server/linux/PerformanceLinux.cpp"
+ #endif
+@@ -577,4 +580,3 @@ int main(int argc, char *argv[])
+
+ return rc;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Main_webservice_vboxweb.cpp b/virtualbox/patches/patch-src_VBox_Main_webservice_vboxweb.cpp
new file mode 100644
index 0000000..e6f51c2
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_webservice_vboxweb.cpp
@@ -0,0 +1,40 @@
+$NetBSD$
+
+--- src/VBox/Main/webservice/vboxweb.cpp.orig 2016-03-04 19:29:42.000000000 +0000
++++ src/VBox/Main/webservice/vboxweb.cpp
+@@ -189,7 +189,7 @@ static ThreadsMap g_mapThr
+ static const RTGETOPTDEF g_aOptions[]
+ = {
+ { "--help", 'h', RTGETOPT_REQ_NOTHING }, /* for DisplayHelp() */
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ { "--background", 'b', RTGETOPT_REQ_NOTHING },
+ #endif
+ { "--host", 'H', RTGETOPT_REQ_STRING },
+@@ -236,7 +236,7 @@ static void DisplayHelp()
+ pcszDescr = "Print this help message and exit.";
+ break;
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ case 'b':
+ pcszDescr = "Run in background (daemon mode).";
+ break;
+@@ -1161,7 +1161,7 @@ int main(int argc, char *argv[])
+ g_fVerbose = true;
+ break;
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ case 'b':
+ g_fDaemonize = true;
+ break;
+@@ -1187,7 +1187,7 @@ int main(int argc, char *argv[])
+ if (RT_FAILURE(rc))
+ return RTMsgErrorExit(RTEXITCODE_FAILURE, "failed to open release log (%s, %Rrc)", szError, rc);
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined (RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ if (g_fDaemonize)
+ {
+ /* prepare release logging */
diff --git a/virtualbox/patches/patch-src_VBox_Main_xml_Settings.cpp b/virtualbox/patches/patch-src_VBox_Main_xml_Settings.cpp
new file mode 100644
index 0000000..11c7fb2
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_xml_Settings.cpp
@@ -0,0 +1,26 @@
+$NetBSD$
+
+--- src/VBox/Main/xml/Settings.cpp.orig 2016-03-04 19:29:43.000000000 +0000
++++ src/VBox/Main/xml/Settings.cpp
+@@ -5496,10 +5496,10 @@ bool MachineConfigFile::isAudioDriverAll
+ case AudioDriverType_Pulse:
+ # endif
+ #endif /* RT_OS_LINUX */
+-#if defined (RT_OS_LINUX) || defined (RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
++#if defined (RT_OS_LINUX) || defined (RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS) || defined (RT_OS_NETBSD)
+ case AudioDriverType_OSS:
+ #endif
+-#ifdef RT_OS_FREEBSD
++#if defined (RT_OS_FREEBSD) || defined (RT_OS_NETBSD)
+ # ifdef VBOX_WITH_PULSE
+ case AudioDriverType_Pulse:
+ # endif
+@@ -5561,7 +5561,7 @@ AudioDriverType_T MachineConfigFile::get
+ return AudioDriverType_CoreAudio;
+ #elif defined(RT_OS_OS2)
+ return AudioDriverType_MMPM;
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_FREEBSD)
+ return AudioDriverType_OSS;
+ #else
+ return AudioDriverType_Null;
diff --git a/virtualbox/patches/patch-src_VBox_Main_xml_VirtualBox-settings.xsd b/virtualbox/patches/patch-src_VBox_Main_xml_VirtualBox-settings.xsd
new file mode 100644
index 0000000..dca729a
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Main_xml_VirtualBox-settings.xsd
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/VBox/Main/xml/VirtualBox-settings.xsd.orig 2016-03-04 19:29:43.000000000 +0000
++++ src/VBox/Main/xml/VirtualBox-settings.xsd
+@@ -743,9 +743,9 @@
+ <xsd:restriction base="xsd:token">
+ <xsd:enumeration value="null"/> <!-- deprecated -->
+ <xsd:enumeration value="Null"/> <!-- all platforms -->
+- <xsd:enumeration value="OSS"/> <!-- Linux, Solaris, FreeBSD -->
+- <xsd:enumeration value="ALSA"/> <!-- Linux, FreeBSD -->
+- <xsd:enumeration value="Pulse"/> <!-- Linux -->
++ <xsd:enumeration value="OSS"/> <!-- Linux, Solaris, FreeBSD, NetBSD -->
++ <xsd:enumeration value="ALSA"/> <!-- Linux, FreeBSD, NetBSD -->
++ <xsd:enumeration value="Pulse"/> <!-- Linux, NetBSD -->
+ <xsd:enumeration value="CoreAudio"/> <!-- Mac OS X -->
+ <xsd:enumeration value="MMPM"/> <!-- OS/2 -->
+ <xsd:enumeration value="SolAudio"/> <!-- Solaris -->
diff --git a/virtualbox/patches/patch-src_VBox_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Makefile.kmk
new file mode 100644
index 0000000..ae2d2c6
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Makefile.kmk
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Makefile.kmk.orig 2016-03-04 19:29:43.000000000 +0000
++++ src/VBox/Makefile.kmk
+@@ -22,7 +22,7 @@ include $(KBUILD_PATH)/subheader.kmk
+ ifdef VBOX_ONLY_ADDITIONS
+ include $(PATH_SUB_CURRENT)/Runtime/Makefile.kmk
+ if defined(VBOX_WITH_CROGL) || defined(VBOX_WITH_HGSMI)
+- if1of ($(KBUILD_TARGET),win linux solaris freebsd haiku)
++ if1of ($(KBUILD_TARGET),win linux solaris freebsd haiku netbsd)
+ include $(PATH_SUB_CURRENT)/GuestHost/Makefile.kmk
+ endif
+ endif
+@@ -106,4 +106,3 @@ endif # !VBOX_ONLY_ADDITIONS && !VBOX_ON
+
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_NetworkServices_NAT_Makefile.kmk b/virtualbox/patches/patch-src_VBox_NetworkServices_NAT_Makefile.kmk
new file mode 100644
index 0000000..4851c0e
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_NetworkServices_NAT_Makefile.kmk
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- src/VBox/NetworkServices/NAT/Makefile.kmk.orig 2016-03-04 19:29:43.000000000 +0000
++++ src/VBox/NetworkServices/NAT/Makefile.kmk
+@@ -119,6 +119,7 @@ endif
+
+ VBoxNetLwipNAT_SOURCES.darwin += rtmon_bsd.c
+ VBoxNetLwipNAT_SOURCES.freebsd += rtmon_bsd.c
++VBoxNetLwipNAT_SOURCES.netbsd += rtmon_bsd.c
+ VBoxNetLwipNAT_SOURCES.linux += rtmon_linux.c
+ VBoxNetLwipNAT_SOURCES.solaris += rtmon_bsd.c
+ VBoxNetLwipNAT_SOURCES.win += rtmon_win.c
diff --git a/virtualbox/patches/patch-src_VBox_NetworkServices_NAT_pxping.c b/virtualbox/patches/patch-src_VBox_NetworkServices_NAT_pxping.c
new file mode 100644
index 0000000..0d09494
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_NetworkServices_NAT_pxping.c
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/NetworkServices/NAT/pxping.c.orig 2016-03-04 19:29:43.000000000 +0000
++++ src/VBox/NetworkServices/NAT/pxping.c
+@@ -560,7 +560,7 @@ pxping_recv4(void *arg, struct pbuf *p)
+ #if defined(RT_OS_LINUX)
+ USE_DF_OPTION(IP_MTU_DISCOVER);
+ df = df ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
+-#elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ USE_DF_OPTION(IP_DONTFRAG);
+ #elif defined(RT_OS_WINDOWS)
+ USE_DF_OPTION(IP_DONTFRAGMENT);
diff --git a/virtualbox/patches/patch-src_VBox_NetworkServices_NAT_pxudp.c b/virtualbox/patches/patch-src_VBox_NetworkServices_NAT_pxudp.c
new file mode 100644
index 0000000..9496a3a
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_NetworkServices_NAT_pxudp.c
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/NetworkServices/NAT/pxudp.c.orig 2016-03-04 19:29:43.000000000 +0000
++++ src/VBox/NetworkServices/NAT/pxudp.c
+@@ -603,7 +603,7 @@ pxudp_pcb_forward_outbound(struct pxudp
+ const char * const dfoptname = #_Optname;
+ #if defined(IP_MTU_DISCOVER) /* Linux */
+ USE_DF_OPTION(IP_MTU_DISCOVER);
+-#elif defined(IP_DONTFRAG) /* Solaris 11+, FreeBSD */
++#elif defined(IP_DONTFRAG) /* Solaris 11+, FreeBSD, NetBSD */
+ USE_DF_OPTION(IP_DONTFRAG);
+ #elif defined(IP_DONTFRAGMENT) /* Windows */
+ USE_DF_OPTION(IP_DONTFRAGMENT);
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Runtime_Makefile.kmk
new file mode 100644
index 0000000..1ef49c9
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_Makefile.kmk
@@ -0,0 +1,245 @@
+$NetBSD$
+
+--- src/VBox/Runtime/Makefile.kmk.orig 2016-03-04 19:29:47.000000000 +0000
++++ src/VBox/Runtime/Makefile.kmk
+@@ -1094,6 +1094,81 @@ RuntimeR3_SOURCES.freebsd = \
+ RuntimeR3_SOURCES.freebsd.x86 += common/string/memrchr.asm
+ RuntimeR3_SOURCES.freebsd.amd64 += common/string/memrchr.asm
+
++## @todo Make BSD sched, implement RTMP*.
++RuntimeR3_SOURCES.netbsd = \
++ generic/cdrom-generic.cpp \
++ generic/RTCrStoreCreateSnapshotById-generic.cpp \
++ generic/RTDirQueryInfo-generic.cpp \
++ generic/RTDirSetTimes-generic.cpp \
++ generic/RTFileMove-generic.cpp \
++ generic/RTLogWriteDebugger-generic.cpp \
++ generic/RTPathAbs-generic.cpp \
++ generic/RTPathGetCurrentOnDrive-generic.cpp \
++ generic/RTSemEventMultiWait-2-ex-generic.cpp \
++ generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp \
++ generic/RTSystemQueryDmiString-generic.cpp \
++ generic/RTSystemShutdown-generic.cpp \
++ generic/RTThreadGetAffinity-stub-generic.cpp \
++ generic/RTThreadSetAffinity-stub-generic.cpp \
++ generic/RTThreadSetAffinityToCpu-generic.cpp \
++ generic/RTTimeLocalNow-generic.cpp \
++ generic/RTTimerCreate-generic.cpp \
++ generic/RTUuidCreate-generic.cpp \
++ generic/mppresent-generic.cpp \
++ generic/sched-generic.cpp \
++ generic/utf16locale-generic.cpp \
++ generic/uuid-generic.cpp \
++ generic/RTMpCpuId-generic.cpp \
++ generic/RTMpGetCoreCount-generic.cpp \
++ generic/RTMpGetOnlineCoreCount-generic.cpp \
++ generic/RTProcDaemonize-generic.cpp \
++ generic/RTProcIsRunningByName-generic.cpp \
++ generic/RTThreadGetNativeState-generic.cpp \
++ r3/netbsd/mp-netbsd.cpp \
++ r3/netbsd/systemmem-netbsd.cpp \
++ r3/netbsd/rtProcInitExePath-netbsd.cpp \
++ r3/generic/allocex-r3-generic.cpp \
++ r3/posix/RTFileQueryFsSizes-posix.cpp \
++ r3/posix/RTHandleGetStandard-posix.cpp \
++ r3/posix/RTMemProtect-posix.cpp \
++ r3/posix/RTPathUserHome-posix.cpp \
++ r3/posix/RTSystemQueryOSInfo-posix.cpp \
++ r3/posix/RTTimeNow-posix.cpp \
++ r3/posix/RTTimeSet-posix.cpp \
++ r3/posix/dir-posix.cpp \
++ r3/posix/env-posix.cpp \
++ r3/posix/errvars-posix.cpp \
++ r3/posix/fileio-posix.cpp \
++ r3/posix/fileio2-posix.cpp \
++ r3/posix/filelock-posix.cpp \
++ r3/posix/fs-posix.cpp \
++ r3/posix/fs2-posix.cpp \
++ r3/posix/fs3-posix.cpp \
++ r3/posix/ldrNative-posix.cpp \
++ r3/posix/rtmempage-exec-mmap-heap-posix.cpp \
++ r3/posix/path-posix.cpp \
++ r3/posix/path2-posix.cpp \
++ r3/posix/pathhost-posix.cpp \
++ r3/posix/RTPathUserDocuments-posix.cpp \
++ r3/posix/pipe-posix.cpp \
++ r3/posix/process-posix.cpp \
++ r3/posix/process-creation-posix.cpp \
++ r3/posix/rand-posix.cpp \
++ r3/posix/semevent-posix.cpp \
++ r3/posix/semeventmulti-posix.cpp \
++ r3/posix/semmutex-posix.cpp \
++ r3/posix/semrw-posix.cpp \
++ r3/posix/symlink-posix.cpp \
++ r3/posix/thread-posix.cpp \
++ r3/posix/thread2-posix.cpp \
++ r3/posix/time-posix.cpp \
++ r3/posix/timelocal-posix.cpp \
++ r3/posix/timer-posix.cpp \
++ r3/posix/tls-posix.cpp \
++ r3/posix/utf8-posix.cpp
++RuntimeR3_SOURCES.netbsd.x86 += common/string/memrchr.asm
++RuntimeR3_SOURCES.netbsd.amd64 += common/string/memrchr.asm
++
+ RuntimeR3_SOURCES.solaris = \
+ generic/cdrom-generic.cpp \
+ generic/RTCrStoreCreateSnapshotById-generic.cpp \
+@@ -1386,6 +1461,8 @@ VBoxRT_SOURCES.darwin += \
+ r3/posix/fileaio-posix.cpp
+ VBoxRT_SOURCES.freebsd += \
+ r3/freebsd/fileaio-freebsd.cpp
++VBoxRT_SOURCES.netbsd += \
++ r3/netbsd/fileaio-netbsd.cpp
+ VBoxRT_INCS := $(RuntimeR3_INCS)
+ VBoxRT_INCS.$(KBUILD_TARGET) := $(RuntimeR3_INCS.$(KBUILD_TARGET))
+ VBoxRT_INCS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH) := $(RuntimeR3_INCS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
+@@ -1424,6 +1501,8 @@ VBoxRT_LIBS.darwin = \
+ VBoxRT_LIBS.freebsd = \
+ iconv \
+ rt
++VBoxRT_LIBS.netbsd = \
++ rt
+ VBoxRT_LIBS.haiku = \
+ iconv
+ VBoxRT_LIBS.solaris = \
+@@ -1569,6 +1648,8 @@ VBoxRT-x86_LIBS.darwin = \
+ VBoxRT-x86_LIBS.freebsd = \
+ iconv \
+ rt
++VBoxRT-x86_LIBS.netbsd = \
++ rt
+ VBoxRT-x86_LIBS.haiku = \
+ iconv
+ VBoxRT-x86_LIBS.solaris = \
+@@ -1749,7 +1830,7 @@ RuntimeR0_SOURCES := \
+ \
+ $(RuntimeNoCrt_SOURCES)
+
+-if1of ($(KBUILD_TARGET), darwin solaris freebsd)
++if1of ($(KBUILD_TARGET), darwin solaris freebsd netbsd)
+ RuntimeR0_SOURCES += \
+ common/math/gcc/adddi3.c \
+ common/math/gcc/anddi3.c \
+@@ -1838,6 +1919,8 @@ RuntimeR0Drv_DEFS.linux = MODULE KBUILD_
+ RuntimeR0Drv_INCS := $(PATH_SUB_CURRENT) include
+ RuntimeR0Drv_INCS.freebsd = \
+ $(PATH_STAGE)/gen-sys-hdrs
++RuntimeR0Drv_INCS.netbsd = \
++ $(PATH_STAGE)/gen-sys-hdrs
+ RuntimeR0Drv_INCS.linux = \
+ r0drv/linux
+ RuntimeR0Drv_INCS.solaris = \
+@@ -2257,6 +2340,41 @@ RuntimeR0Drv_SOURCES.freebsd = \
+ r0drv/memobj-r0drv.cpp \
+ r0drv/powernotification-r0drv.c
+
++RuntimeR0Drv_SOURCES.netbsd = \
++ common/misc/thread.cpp \
++ common/string/memchr.asm \
++ common/string/memmove.asm \
++ common/string/strpbrk.cpp \
++ common/string/memcmp.asm \
++ common/string/strchr.asm \
++ generic/RTAssertShouldPanic-generic.cpp \
++ generic/RTLogWriteDebugger-generic.cpp \
++ generic/RTLogWriteStdOut-stub-generic.cpp \
++ generic/RTMpOnPair-generic.cpp \
++ generic/RTTimerCreate-generic.cpp \
++ generic/mppresent-generic.cpp \
++ r0drv/generic/RTMpIsCpuWorkPending-r0drv-generic.cpp \
++ r0drv/generic/mpnotification-r0drv-generic.cpp \
++ r0drv/generic/threadctxhooks-r0drv-generic.cpp \
++ r0drv/netbsd/alloc-r0drv-netbsd.c \
++ r0drv/netbsd/assert-r0drv-netbsd.c \
++ r0drv/netbsd/initterm-r0drv-netbsd.c \
++ r0drv/netbsd/memobj-r0drv-netbsd.c \
++ r0drv/netbsd/memuserkernel-r0drv-netbsd.c \
++ r0drv/netbsd/process-r0drv-netbsd.c \
++ r0drv/netbsd/semevent-r0drv-netbsd.c \
++ r0drv/netbsd/semeventmulti-r0drv-netbsd.c \
++ r0drv/netbsd/semfastmutex-r0drv-netbsd.c \
++ r0drv/netbsd/semmutex-r0drv-netbsd.c \
++ r0drv/netbsd/spinlock-r0drv-netbsd.c \
++ r0drv/netbsd/thread-r0drv-netbsd.c \
++ r0drv/netbsd/thread2-r0drv-netbsd.c \
++ r0drv/netbsd/time-r0drv-netbsd.c \
++ r0drv/netbsd/mp-r0drv-netbsd.c \
++ generic/timer-generic.cpp \
++ r0drv/memobj-r0drv.cpp \
++ r0drv/powernotification-r0drv.c
++
+ RuntimeR0Drv_SOURCES.solaris = \
+ common/misc/thread.cpp \
+ common/string/memchr.asm \
+@@ -2330,6 +2448,10 @@ RuntimeR0Drv_ORDERDEPS.freebsd = \
+ $(PATH_STAGE)/gen-sys-hdrs/bus_if.h \
+ $(PATH_STAGE)/gen-sys-hdrs/device_if.h
+
++RuntimeR0Drv_ORDERDEPS.netbsd = \
++ $(PATH_STAGE)/gen-sys-hdrs/bus_if.h \
++ $(PATH_STAGE)/gen-sys-hdrs/device_if.h
++
+
+ #
+ # RuntimeGuestR0 - Guest driver runtime.
+@@ -2429,7 +2551,7 @@ ifdef VBOX_WITH_RAW_MODE
+ RuntimeRC_SOURCES += os2/sys0.asm
+ endif
+
+- if1of ($(KBUILD_TARGET), darwin solaris freebsd)
++ if1of ($(KBUILD_TARGET), darwin solaris freebsd netbsd)
+ RuntimeRC_SOURCES += \
+ common/math/gcc/adddi3.c \
+ common/math/gcc/anddi3.c \
+@@ -2644,6 +2766,46 @@ $$(FreeBSDGeneratedKernelHeaders_0_OUTDI
+ $(QUIET)$(RM) $(@D)/pci_if.m
+ endif # FreeBSD
+
++if "$(KBUILD_TARGET)" == "netbsd"
++#
++# NetBSDGeneratedKernelHeaders - Generate some kernel interface headers.
++#
++# These are used by:
++# - The RTMp* API in IPRT.
++# - VBoxGuest
++#
++# Note! We cannot give a output path to the awk program, it will always
++# generate the header next to the source. So, we'll have to temporarily copy
++# the source file to the destination directory to work.
++#
++VBOX_AWK := /usr/bin/awk
++INSTALLS += NetBSDGeneratedKernelHeaders
++NetBSDGeneratedKernelHeaders_INST = gen-sys-hdrs/
++NetBSDGeneratedKernelHeaders_SOURCES = \
++ $(NetBSDGeneratedKernelHeaders_0_OUTDIR)/bus_if.h \
++ $(NetBSDGeneratedKernelHeaders_0_OUTDIR)/device_if.h \
++ $(NetBSDGeneratedKernelHeaders_0_OUTDIR)/pci_if.h
++NetBSDGeneratedKernelHeaders_CLEAN = $(NetBSDGeneratedKernelHeaders_SOURCES)
++
++$$(NetBSDGeneratedKernelHeaders_0_OUTDIR)/bus_if.h: $(VBOX_NETBSD_SRC)/kern/bus_if.m | $$(dir $$@)
++ $(call MSG_TOOL,awk,NetBSDGeneratedKernelHeaders,$<,$@)
++ $(QUIET)$(CP) -f $< $(@D)/bus_if.m
++ $(QUIET)$(VBOX_AWK) -f $(VBOX_NETBSD_SRC)/tools/makeobjops.awk $(@D)/bus_if.m -h -p
++ $(QUIET)$(RM) $(@D)/bus_if.m
++
++$$(NetBSDGeneratedKernelHeaders_0_OUTDIR)/device_if.h: $(VBOX_NETBSD_SRC)/kern/device_if.m | $$(dir $$@)
++ $(call MSG_TOOL,awk,NetBSDGeneratedKernelHeaders,$<,$@)
++ $(QUIET)$(CP) -f $< $(@D)/device_if.m
++ $(QUIET)$(VBOX_AWK) -f $(VBOX_NETBSD_SRC)/tools/makeobjops.awk $(@D)/device_if.m -h -p
++ $(QUIET)$(RM) $(@D)/device_if.m
++
++$$(NetBSDGeneratedKernelHeaders_0_OUTDIR)/pci_if.h: $(VBOX_NETBSD_SRC)/dev/pci/pci_if.m | $$(dir $$@)
++ $(call MSG_TOOL,awk,NetBSDGeneratedKernelHeaders,$<,$@)
++ $(QUIET)$(CP) -f $< $(@D)/pci_if.m
++ $(QUIET)$(VBOX_AWK) -f $(VBOX_NETBSD_SRC)/tools/makeobjops.awk $(@D)/pci_if.m -h -p
++ $(QUIET)$(RM) $(@D)/pci_if.m
++endif # NetBSD
++
+
+ #
+ # Aliases for .cpp.h files so we can more easily do syntax checking from the editor.
+@@ -2924,4 +3086,3 @@ taf-template.o taf-template.obj: taf-cor
+ tsp-template.o tsp-template.obj: tsp-core.o tsp-asn1-decoder.o tsp-sanity.o tsp-init.o
+ x509-template.o x509-template.obj: x509-core.o x509-asn1-decoder.o x509-sanity.o x509-init.o
+ pkcs7-template.o pkcs7-template.obj: pkcs7-core.o pkcs7-asn1-decoder.o pkcs7-sanity.o pkcs7-init.o
+-
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_VBox_log-vbox.cpp b/virtualbox/patches/patch-src_VBox_Runtime_VBox_log-vbox.cpp
new file mode 100644
index 0000000..6264893
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_VBox_log-vbox.cpp
@@ -0,0 +1,57 @@
+$NetBSD$
+
+--- src/VBox/Runtime/VBox/log-vbox.cpp.orig 2016-03-04 19:29:47.000000000 +0000
++++ src/VBox/Runtime/VBox/log-vbox.cpp
+@@ -137,6 +137,11 @@
+ # include <sys/user.h>
+ # include <stdlib.h>
+ # include <unistd.h>
++# elif defined(RT_OS_NETBSD)
++# include <sys/param.h>
++# include <sys/sysctl.h>
++# include <stdlib.h>
++# include <unistd.h>
+ # elif defined(RT_OS_HAIKU)
+ # include <OS.h>
+ # elif defined(RT_OS_SOLARIS)
+@@ -422,6 +427,40 @@ RTDECL(PRTLOGGER) RTLogDefaultInit(void)
+ }
+ }
+
++# elif defined(RT_OS_NETBSD)
++ /* Retrieve the required length first */
++ int aiName[4];
++ aiName[0] = CTL_KERN;
++ aiName[1] = KERN_PROC_ARGS;
++ aiName[2] = getpid();
++ aiName[3] = KERN_PROC_ARGV;
++ size_t cchArgs = 0;
++ int rcBSD = sysctl(aiName, RT_ELEMENTS(aiName), NULL, &cchArgs, NULL, 0);
++ if (cchArgs > 0)
++ {
++ char *pszArgFileBuf = (char *)RTMemAllocZ(cchArgs + 1 /* Safety */);
++ if (pszArgFileBuf)
++ {
++ /* Retrieve the argument list */
++ rcBSD = sysctl(aiName, RT_ELEMENTS(aiName), pszArgFileBuf, &cchArgs, NULL, 0);
++ if (!rcBSD)
++ {
++ unsigned iArg = 0;
++ size_t off = 0;
++ while (off < cchArgs)
++ {
++ size_t cchArg = strlen(&pszArgFileBuf[off]);
++ RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%u]: %s\n", iArg, &pszArgFileBuf[off]);
++
++ /* advance */
++ off += cchArg + 1;
++ iArg++;
++ }
++ }
++ RTMemFree(pszArgFileBuf);
++ }
++ }
++
+ # elif defined(RT_OS_OS2) || defined(RT_OS_DARWIN)
+ /* commandline? */
+ # else
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_alloc-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_alloc-r0drv-netbsd.c
new file mode 100644
index 0000000..a7725fa
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_alloc-r0drv-netbsd.c
@@ -0,0 +1,184 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/alloc-r0drv-netbsd.c.orig 2016-07-07 07:08:46.872622650 +0000
++++ src/VBox/Runtime/r0drv/netbsd/alloc-r0drv-netbsd.c
+@@ -0,0 +1,179 @@
++/* alloc-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Memory Allocation, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++#include "internal/iprt.h"
++#include <iprt/mem.h>
++
++#include <iprt/assert.h>
++#include <iprt/err.h>
++#include <iprt/param.h>
++
++#include "r0drv/alloc-r0drv.h"
++
++
++/*********************************************************************************************************************************
++* Global Variables *
++*********************************************************************************************************************************/
++/* These two statements will define two globals and add initializers
++ and destructors that will be called at load/unload time (I think). */
++MALLOC_DEFINE(M_IPRTHEAP, "iprtheap", "IPRT - heap");
++MALLOC_DEFINE(M_IPRTCONT, "iprtcont", "IPRT - contiguous");
++
++
++DECLHIDDEN(int) rtR0MemAllocEx(size_t cb, uint32_t fFlags, PRTMEMHDR *ppHdr)
++{
++ size_t cbAllocated = cb;
++ PRTMEMHDR pHdr = NULL;
++
++#ifdef RT_ARCH_AMD64
++ /*
++ * Things are a bit more complicated on AMD64 for executable memory
++ * because we need to be in the ~2GB..~0 range for code.
++ */
++ if (fFlags & RTMEMHDR_FLAG_EXEC)
++ {
++ if (fFlags & RTMEMHDR_FLAG_ANY_CTX)
++ return VERR_NOT_SUPPORTED;
++
++# ifdef USE_KMEM_ALLOC_PROT
++ pHdr = (PRTMEMHDR)kmem_alloc_prot(kernel_map, cb + sizeof(*pHdr),
++ VM_PROT_ALL, VM_PROT_ALL, KERNBASE);
++# else
++ vm_object_t pVmObject = NULL;
++ vm_offset_t Addr = KERNBASE;
++ cbAllocated = RT_ALIGN_Z(cb + sizeof(*pHdr), PAGE_SIZE);
++
++ pVmObject = vm_object_allocate(OBJT_DEFAULT, cbAllocated >> PAGE_SHIFT);
++ if (!pVmObject)
++ return VERR_NO_EXEC_MEMORY;
++
++ /* Addr contains a start address vm_map_find will start searching for suitable space at. */
++ int rc = vm_map_find(kernel_map, pVmObject, 0, &Addr,
++ cbAllocated, 0, VMFS_ANY_SPACE, VM_PROT_ALL, VM_PROT_ALL, 0);
++ if (rc == KERN_SUCCESS)
++ {
++ rc = vm_map_wire(kernel_map, Addr, Addr + cbAllocated,
++ VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
++ if (rc == KERN_SUCCESS)
++ {
++ pHdr = (PRTMEMHDR)Addr;
++
++ if (fFlags & RTMEMHDR_FLAG_ZEROED)
++ bzero(pHdr, cbAllocated);
++ }
++ else
++ vm_map_remove(kernel_map,
++ Addr,
++ Addr + cbAllocated);
++ }
++ else
++ vm_object_deallocate(pVmObject);
++# endif
++ }
++ else
++#endif
++ {
++ pHdr = (PRTMEMHDR)malloc(cb + sizeof(RTMEMHDR), M_IPRTHEAP,
++ fFlags & RTMEMHDR_FLAG_ZEROED ? M_NOWAIT | M_ZERO : M_NOWAIT);
++ }
++
++ if (RT_UNLIKELY(!pHdr))
++ return VERR_NO_MEMORY;
++
++ pHdr->u32Magic = RTMEMHDR_MAGIC;
++ pHdr->fFlags = fFlags;
++ pHdr->cb = cbAllocated;
++ pHdr->cbReq = cb;
++
++ *ppHdr = pHdr;
++ return VINF_SUCCESS;
++}
++
++
++DECLHIDDEN(void) rtR0MemFree(PRTMEMHDR pHdr)
++{
++ pHdr->u32Magic += 1;
++
++#ifdef RT_ARCH_AMD64
++ if (pHdr->fFlags & RTMEMHDR_FLAG_EXEC)
++# ifdef USE_KMEM_ALLOC_PROT
++ kmem_free(kernel_map, (vm_offset_t)pHdr, pHdr->cb);
++# else
++ vm_map_remove(kernel_map, (vm_offset_t)pHdr, ((vm_offset_t)pHdr) + pHdr->cb);
++# endif
++ else
++#endif
++ free(pHdr, M_IPRTHEAP);
++}
++
++
++RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
++{
++ void *pv;
++
++ /*
++ * Validate input.
++ */
++ AssertPtr(pPhys);
++ Assert(cb > 0);
++
++ /*
++ * This API works in pages, so no need to do any size aligning.
++ */
++ pv = contigmalloc(cb, /* size */
++ M_IPRTCONT, /* type */
++ M_NOWAIT | M_ZERO, /* flags */
++ 0, /* lowest physical address*/
++ _4G-1, /* highest physical address */
++ PAGE_SIZE, /* alignment. */
++ 0); /* boundary */
++ if (pv)
++ {
++ Assert(!((uintptr_t)pv & PAGE_OFFSET_MASK));
++ *pPhys = vtophys(pv);
++ Assert(!(*pPhys & PAGE_OFFSET_MASK));
++ }
++ return pv;
++}
++
++
++RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
++{
++ if (pv)
++ {
++ AssertMsg(!((uintptr_t)pv & PAGE_OFFSET_MASK), ("pv=%p\n", pv));
++ contigfree(pv, cb, M_IPRTCONT);
++ }
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_assert-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_assert-r0drv-netbsd.c
new file mode 100644
index 0000000..7ad2a12
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_assert-r0drv-netbsd.c
@@ -0,0 +1,74 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/assert-r0drv-netbsd.c.orig 2016-07-07 07:08:46.881887133 +0000
++++ src/VBox/Runtime/r0drv/netbsd/assert-r0drv-netbsd.c
+@@ -0,0 +1,69 @@
++/* assert-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Assertion Workers, Ring-0 Drivers, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++
++#include <iprt/assert.h>
++#include <iprt/log.h>
++#include <iprt/string.h>
++#include <iprt/stdarg.h>
++
++#include "internal/assert.h"
++
++
++DECLHIDDEN(void) rtR0AssertNativeMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
++{
++ printf("\r\n!!Assertion Failed!!\r\n"
++ "Expression: %s\r\n"
++ "Location : %s(%d) %s\r\n",
++ pszExpr, pszFile, uLine, pszFunction);
++}
++
++
++DECLHIDDEN(void) rtR0AssertNativeMsg2V(bool fInitial, const char *pszFormat, va_list va)
++{
++ char szMsg[256];
++
++ RTStrPrintfV(szMsg, sizeof(szMsg) - 1, pszFormat, va);
++ szMsg[sizeof(szMsg) - 1] = '\0';
++ printf("%s", szMsg);
++
++ NOREF(fInitial);
++}
++
++
++RTR0DECL(void) RTR0AssertPanicSystem(void)
++{
++ /** @todo implement RTR0AssertPanicSystem. */
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_initterm-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_initterm-r0drv-netbsd.c
new file mode 100644
index 0000000..7a2eddb
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_initterm-r0drv-netbsd.c
@@ -0,0 +1,57 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/initterm-r0drv-netbsd.c.orig 2016-07-07 07:08:46.891248736 +0000
++++ src/VBox/Runtime/r0drv/netbsd/initterm-r0drv-netbsd.c
+@@ -0,0 +1,52 @@
++/* initterm-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Initialization & Termination, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++
++#include <iprt/err.h>
++
++#include "internal/initterm.h"
++
++
++DECLHIDDEN(int) rtR0InitNative(void)
++{
++ /* nothing to do */
++ return VINF_SUCCESS;
++}
++
++
++DECLHIDDEN(void) rtR0TermNative(void)
++{
++ /* nothing to undo */
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_memobj-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_memobj-r0drv-netbsd.c
new file mode 100644
index 0000000..e8606f3
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_memobj-r0drv-netbsd.c
@@ -0,0 +1,811 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c.orig 2016-07-07 07:08:46.900749311 +0000
++++ src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c
+@@ -0,0 +1,806 @@
++/* memobj-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Ring-0 Memory Objects, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ * Copyright (c) 2011 Andriy Gapon <avg%FreeBSD.org@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++
++#include <iprt/memobj.h>
++#include <iprt/mem.h>
++#include <iprt/err.h>
++#include <iprt/assert.h>
++#include <iprt/log.h>
++#include <iprt/param.h>
++#include <iprt/process.h>
++#include "internal/memobj.h"
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++/**
++ * The NetBSD version of the memory object structure.
++ */
++typedef struct RTR0MEMOBJNETBSD
++{
++ /** The core structure. */
++ RTR0MEMOBJINTERNAL Core;
++ /** The VM object associated with the allocation. */
++ vm_object_t pObject;
++} RTR0MEMOBJNETBSD, *PRTR0MEMOBJNETBSD;
++
++
++MALLOC_DEFINE(M_IPRTMOBJ, "iprtmobj", "IPRT - R0MemObj");
++
++
++/**
++ * Gets the virtual memory map the specified object is mapped into.
++ *
++ * @returns VM map handle on success, NULL if no map.
++ * @param pMem The memory object.
++ */
++static vm_map_t rtR0MemObjNetBSDGetMap(PRTR0MEMOBJINTERNAL pMem)
++{
++ switch (pMem->enmType)
++ {
++ case RTR0MEMOBJTYPE_PAGE:
++ case RTR0MEMOBJTYPE_LOW:
++ case RTR0MEMOBJTYPE_CONT:
++ return kernel_map;
++
++ case RTR0MEMOBJTYPE_PHYS:
++ case RTR0MEMOBJTYPE_PHYS_NC:
++ return NULL; /* pretend these have no mapping atm. */
++
++ case RTR0MEMOBJTYPE_LOCK:
++ return pMem->u.Lock.R0Process == NIL_RTR0PROCESS
++ ? kernel_map
++ : &((struct proc *)pMem->u.Lock.R0Process)->p_vmspace->vm_map;
++
++ case RTR0MEMOBJTYPE_RES_VIRT:
++ return pMem->u.ResVirt.R0Process == NIL_RTR0PROCESS
++ ? kernel_map
++ : &((struct proc *)pMem->u.ResVirt.R0Process)->p_vmspace->vm_map;
++
++ case RTR0MEMOBJTYPE_MAPPING:
++ return pMem->u.Mapping.R0Process == NIL_RTR0PROCESS
++ ? kernel_map
++ : &((struct proc *)pMem->u.Mapping.R0Process)->p_vmspace->vm_map;
++
++ default:
++ return NULL;
++ }
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
++{
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)pMem;
++ int rc;
++
++ switch (pMemNetBSD->Core.enmType)
++ {
++ case RTR0MEMOBJTYPE_PAGE:
++ case RTR0MEMOBJTYPE_LOW:
++ case RTR0MEMOBJTYPE_CONT:
++ rc = vm_map_remove(kernel_map,
++ (vm_offset_t)pMemNetBSD->Core.pv,
++ (vm_offset_t)pMemNetBSD->Core.pv + pMemNetBSD->Core.cb);
++ AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
++ break;
++
++ case RTR0MEMOBJTYPE_LOCK:
++ {
++ vm_map_t pMap = kernel_map;
++
++ if (pMemNetBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
++ pMap = &((struct proc *)pMemNetBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map;
++
++ rc = vm_map_unwire(pMap,
++ (vm_offset_t)pMemNetBSD->Core.pv,
++ (vm_offset_t)pMemNetBSD->Core.pv + pMemNetBSD->Core.cb,
++ VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
++ AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
++ break;
++ }
++
++ case RTR0MEMOBJTYPE_RES_VIRT:
++ {
++ vm_map_t pMap = kernel_map;
++ if (pMemNetBSD->Core.u.ResVirt.R0Process != NIL_RTR0PROCESS)
++ pMap = &((struct proc *)pMemNetBSD->Core.u.ResVirt.R0Process)->p_vmspace->vm_map;
++ rc = vm_map_remove(pMap,
++ (vm_offset_t)pMemNetBSD->Core.pv,
++ (vm_offset_t)pMemNetBSD->Core.pv + pMemNetBSD->Core.cb);
++ AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
++ break;
++ }
++
++ case RTR0MEMOBJTYPE_MAPPING:
++ {
++ vm_map_t pMap = kernel_map;
++
++ if (pMemNetBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS)
++ pMap = &((struct proc *)pMemNetBSD->Core.u.Mapping.R0Process)->p_vmspace->vm_map;
++ rc = vm_map_remove(pMap,
++ (vm_offset_t)pMemNetBSD->Core.pv,
++ (vm_offset_t)pMemNetBSD->Core.pv + pMemNetBSD->Core.cb);
++ AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
++ break;
++ }
++
++ case RTR0MEMOBJTYPE_PHYS:
++ case RTR0MEMOBJTYPE_PHYS_NC:
++ {
++ VM_OBJECT_WLOCK(pMemNetBSD->pObject);
++ vm_page_t pPage = vm_page_find_least(pMemNetBSD->pObject, 0);
++ vm_page_lock_queues();
++
++ for (vm_page_t pPage = vm_page_find_least(pMemNetBSD->pObject, 0);
++ pPage != NULL;
++ pPage = vm_page_next(pPage))
++ {
++ vm_page_unwire(pPage, 0);
++ }
++ VM_OBJECT_WUNLOCK(pMemNetBSD->pObject);
++ vm_object_deallocate(pMemNetBSD->pObject);
++ break;
++ }
++
++ default:
++ AssertMsgFailed(("enmType=%d\n", pMemNetBSD->Core.enmType));
++ return VERR_INTERNAL_ERROR;
++ }
++
++ return VINF_SUCCESS;
++}
++
++
++static vm_page_t rtR0MemObjNetBSDContigPhysAllocHelper(vm_object_t pObject, vm_pindex_t iPIndex,
++ u_long cPages, vm_paddr_t VmPhysAddrHigh,
++ u_long uAlignment, bool fWire)
++{
++ vm_page_t pPages;
++ int cTries = 0;
++
++ int fFlags = VM_ALLOC_INTERRUPT | VM_ALLOC_NOBUSY;
++ if (fWire)
++ fFlags |= VM_ALLOC_WIRED;
++
++ while (cTries <= 1)
++ {
++ VM_OBJECT_WLOCK(pObject);
++ pPages = vm_page_alloc_contig(pObject, iPIndex, fFlags, cPages, 0,
++ VmPhysAddrHigh, uAlignment, 0, VM_MEMATTR_DEFAULT);
++ VM_OBJECT_WUNLOCK(pObject);
++ if (pPages)
++ break;
++ vm_pageout_grow_cache(cTries, 0, VmPhysAddrHigh);
++ cTries++;
++ }
++
++ return pPages;
++}
++
++static int rtR0MemObjNetBSDPhysAllocHelper(vm_object_t pObject, u_long cPages,
++ vm_paddr_t VmPhysAddrHigh, u_long uAlignment,
++ bool fContiguous, bool fWire, int rcNoMem)
++{
++ if (fContiguous)
++ {
++ if (rtR0MemObjNetBSDContigPhysAllocHelper(pObject, 0, cPages, VmPhysAddrHigh,
++ uAlignment, fWire) != NULL)
++ return VINF_SUCCESS;
++ return rcNoMem;
++ }
++
++ for (vm_pindex_t iPage = 0; iPage < cPages; iPage++)
++ {
++ vm_page_t pPage = rtR0MemObjNetBSDContigPhysAllocHelper(pObject, iPage, 1, VmPhysAddrHigh,
++ uAlignment, fWire);
++ if (!pPage)
++ {
++ /* Free all allocated pages */
++ VM_OBJECT_WLOCK(pObject);
++ while (iPage-- > 0)
++ {
++ pPage = vm_page_lookup(pObject, iPage);
++ if (fWire)
++ vm_page_unwire(pPage, 0);
++ vm_page_free(pPage);
++ }
++ VM_OBJECT_WUNLOCK(pObject);
++ return rcNoMem;
++ }
++ }
++ return VINF_SUCCESS;
++}
++
++static int rtR0MemObjNetBSDAllocHelper(PRTR0MEMOBJNETBSD pMemNetBSD, bool fExecutable,
++ vm_paddr_t VmPhysAddrHigh, bool fContiguous, int rcNoMem)
++{
++ vm_offset_t MapAddress = vm_map_min(kernel_map);
++ size_t cPages = atop(pMemNetBSD->Core.cb);
++ int rc;
++
++ pMemNetBSD->pObject = vm_object_allocate(OBJT_PHYS, cPages);
++
++ /* No additional object reference for auto-deallocation upon unmapping. */
++ rc = vm_map_find(kernel_map, pMemNetBSD->pObject, 0,
++ &MapAddress, pMemNetBSD->Core.cb, 0, VMFS_ANY_SPACE,
++ fExecutable ? VM_PROT_ALL : VM_PROT_RW, VM_PROT_ALL, 0);
++
++ if (rc == KERN_SUCCESS)
++ {
++ rc = rtR0MemObjNetBSDPhysAllocHelper(pMemNetBSD->pObject, cPages,
++ VmPhysAddrHigh, PAGE_SIZE, fContiguous,
++ false, rcNoMem);
++ if (RT_SUCCESS(rc))
++ {
++ vm_map_wire(kernel_map, MapAddress, MapAddress + pMemNetBSD->Core.cb,
++ VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
++
++ /* Store start address */
++ pMemNetBSD->Core.pv = (void *)MapAddress;
++ return VINF_SUCCESS;
++ }
++
++ vm_map_remove(kernel_map, MapAddress, MapAddress + pMemNetBSD->Core.cb);
++ }
++ else
++ {
++ rc = rcNoMem; /** @todo fix translation (borrow from darwin) */
++ vm_object_deallocate(pMemNetBSD->pObject);
++ }
++
++ rtR0MemObjDelete(&pMemNetBSD->Core);
++ return rc;
++}
++DECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
++{
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD),
++ RTR0MEMOBJTYPE_PAGE, NULL, cb);
++ if (!pMemNetBSD)
++ return VERR_NO_MEMORY;
++
++ int rc = rtR0MemObjNetBSDAllocHelper(pMemNetBSD, fExecutable, ~(vm_paddr_t)0, false, VERR_NO_MEMORY);
++ if (RT_FAILURE(rc))
++ {
++ rtR0MemObjDelete(&pMemNetBSD->Core);
++ return rc;
++ }
++
++ *ppMem = &pMemNetBSD->Core;
++ return rc;
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
++{
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD),
++ RTR0MEMOBJTYPE_LOW, NULL, cb);
++ if (!pMemNetBSD)
++ return VERR_NO_MEMORY;
++
++ int rc = rtR0MemObjNetBSDAllocHelper(pMemNetBSD, fExecutable, _4G - 1, false, VERR_NO_LOW_MEMORY);
++ if (RT_FAILURE(rc))
++ {
++ rtR0MemObjDelete(&pMemNetBSD->Core);
++ return rc;
++ }
++
++ *ppMem = &pMemNetBSD->Core;
++ return rc;
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
++{
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD),
++ RTR0MEMOBJTYPE_CONT, NULL, cb);
++ if (!pMemNetBSD)
++ return VERR_NO_MEMORY;
++
++ int rc = rtR0MemObjNetBSDAllocHelper(pMemNetBSD, fExecutable, _4G - 1, true, VERR_NO_CONT_MEMORY);
++ if (RT_FAILURE(rc))
++ {
++ rtR0MemObjDelete(&pMemNetBSD->Core);
++ return rc;
++ }
++
++ pMemNetBSD->Core.u.Cont.Phys = vtophys(pMemNetBSD->Core.pv);
++ *ppMem = &pMemNetBSD->Core;
++ return rc;
++}
++
++
++static int rtR0MemObjNetBSDAllocPhysPages(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJTYPE enmType,
++ size_t cb,
++ RTHCPHYS PhysHighest, size_t uAlignment,
++ bool fContiguous, int rcNoMem)
++{
++ uint32_t cPages = atop(cb);
++ vm_paddr_t VmPhysAddrHigh;
++
++ /* create the object. */
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD),
++ enmType, NULL, cb);
++ if (!pMemNetBSD)
++ return VERR_NO_MEMORY;
++
++ pMemNetBSD->pObject = vm_object_allocate(OBJT_PHYS, atop(cb));
++
++ if (PhysHighest != NIL_RTHCPHYS)
++ VmPhysAddrHigh = PhysHighest;
++ else
++ VmPhysAddrHigh = ~(vm_paddr_t)0;
++
++ int rc = rtR0MemObjNetBSDPhysAllocHelper(pMemNetBSD->pObject, cPages, VmPhysAddrHigh,
++ uAlignment, fContiguous, true, rcNoMem);
++ if (RT_SUCCESS(rc))
++ {
++ if (fContiguous)
++ {
++ Assert(enmType == RTR0MEMOBJTYPE_PHYS);
++ VM_OBJECT_WLOCK(pMemNetBSD->pObject);
++ pMemNetBSD->Core.u.Phys.PhysBase = VM_PAGE_TO_PHYS(vm_page_find_least(pMemNetBSD->pObject, 0));
++ VM_OBJECT_WUNLOCK(pMemNetBSD->pObject);
++ pMemNetBSD->Core.u.Phys.fAllocated = true;
++ }
++
++ *ppMem = &pMemNetBSD->Core;
++ }
++ else
++ {
++ vm_object_deallocate(pMemNetBSD->pObject);
++ rtR0MemObjDelete(&pMemNetBSD->Core);
++ }
++
++ return rc;
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment)
++{
++ return rtR0MemObjNetBSDAllocPhysPages(ppMem, RTR0MEMOBJTYPE_PHYS, cb, PhysHighest, uAlignment, true, VERR_NO_MEMORY);
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
++{
++ return rtR0MemObjNetBSDAllocPhysPages(ppMem, RTR0MEMOBJTYPE_PHYS_NC, cb, PhysHighest, PAGE_SIZE, false, VERR_NO_PHYS_MEMORY);
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy)
++{
++ AssertReturn(uCachePolicy == RTMEM_CACHE_POLICY_DONT_CARE, VERR_NOT_SUPPORTED);
++
++ /* create the object. */
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD), RTR0MEMOBJTYPE_PHYS, NULL, cb);
++ if (!pMemNetBSD)
++ return VERR_NO_MEMORY;
++
++ /* there is no allocation here, it needs to be mapped somewhere first. */
++ pMemNetBSD->Core.u.Phys.fAllocated = false;
++ pMemNetBSD->Core.u.Phys.PhysBase = Phys;
++ pMemNetBSD->Core.u.Phys.uCachePolicy = uCachePolicy;
++ *ppMem = &pMemNetBSD->Core;
++ return VINF_SUCCESS;
++}
++
++
++/**
++ * Worker locking the memory in either kernel or user maps.
++ */
++static int rtR0MemObjNativeLockInMap(PPRTR0MEMOBJINTERNAL ppMem, vm_map_t pVmMap,
++ vm_offset_t AddrStart, size_t cb, uint32_t fAccess,
++ RTR0PROCESS R0Process, int fFlags)
++{
++ int rc;
++ NOREF(fAccess);
++
++ /* create the object. */
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD), RTR0MEMOBJTYPE_LOCK, (void *)AddrStart, cb);
++ if (!pMemNetBSD)
++ 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 (rc == KERN_SUCCESS)
++ {
++ pMemNetBSD->Core.u.Lock.R0Process = R0Process;
++ *ppMem = &pMemNetBSD->Core;
++ return VINF_SUCCESS;
++ }
++ rtR0MemObjDelete(&pMemNetBSD->Core);
++ return VERR_NO_MEMORY;/** @todo fix mach -> vbox error conversion for freebsd. */
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process)
++{
++ return rtR0MemObjNativeLockInMap(ppMem,
++ &((struct proc *)R0Process)->p_vmspace->vm_map,
++ (vm_offset_t)R3Ptr,
++ cb,
++ fAccess,
++ R0Process,
++ VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess)
++{
++ return rtR0MemObjNativeLockInMap(ppMem,
++ kernel_map,
++ (vm_offset_t)pv,
++ cb,
++ fAccess,
++ NIL_RTR0PROCESS,
++ VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
++}
++
++
++/**
++ * Worker for the two virtual address space reservers.
++ *
++ * We're leaning on the examples provided by mmap and vm_mmap in vm_mmap.c here.
++ */
++static int rtR0MemObjNativeReserveInMap(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process, vm_map_t pMap)
++{
++ int rc;
++
++ /*
++ * The pvFixed address range must be within the VM space when specified.
++ */
++ if ( pvFixed != (void *)-1
++ && ( (vm_offset_t)pvFixed < vm_map_min(pMap)
++ || (vm_offset_t)pvFixed + cb > vm_map_max(pMap)))
++ return VERR_INVALID_PARAMETER;
++
++ /*
++ * Check that the specified alignment is supported.
++ */
++ if (uAlignment > PAGE_SIZE)
++ return VERR_NOT_SUPPORTED;
++
++ /*
++ * Create the object.
++ */
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD), RTR0MEMOBJTYPE_RES_VIRT, NULL, cb);
++ if (!pMemNetBSD)
++ return VERR_NO_MEMORY;
++
++ vm_offset_t MapAddress = pvFixed != (void *)-1
++ ? (vm_offset_t)pvFixed
++ : vm_map_min(pMap);
++ if (pvFixed != (void *)-1)
++ vm_map_remove(pMap,
++ MapAddress,
++ MapAddress + cb);
++
++ rc = vm_map_find(pMap, /* map */
++ NULL, /* object */
++ 0, /* offset */
++ &MapAddress, /* addr (IN/OUT) */
++ cb, /* length */
++ 0, /* max addr */
++ pvFixed == (void *)-1 ? VMFS_ANY_SPACE : VMFS_NO_SPACE,
++ /* find_space */
++ VM_PROT_NONE, /* protection */
++ VM_PROT_ALL, /* max(_prot) ?? */
++ 0); /* cow (copy-on-write) */
++ if (rc == KERN_SUCCESS)
++ {
++ if (R0Process != NIL_RTR0PROCESS)
++ {
++ rc = vm_map_inherit(pMap,
++ MapAddress,
++ MapAddress + cb,
++ VM_INHERIT_SHARE);
++ AssertMsg(rc == KERN_SUCCESS, ("%#x\n", rc));
++ }
++ pMemNetBSD->Core.pv = (void *)MapAddress;
++ pMemNetBSD->Core.u.ResVirt.R0Process = R0Process;
++ *ppMem = &pMemNetBSD->Core;
++ return VINF_SUCCESS;
++ }
++
++ rc = VERR_NO_MEMORY; /** @todo fix translation (borrow from darwin) */
++ rtR0MemObjDelete(&pMemNetBSD->Core);
++ return rc;
++
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
++{
++ return rtR0MemObjNativeReserveInMap(ppMem, pvFixed, cb, uAlignment, NIL_RTR0PROCESS, kernel_map);
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
++{
++ return rtR0MemObjNativeReserveInMap(ppMem, (void *)R3PtrFixed, cb, uAlignment, R0Process,
++ &((struct proc *)R0Process)->p_vmspace->vm_map);
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
++ unsigned fProt, size_t offSub, size_t cbSub)
++{
++// AssertMsgReturn(!offSub && !cbSub, ("%#x %#x\n", offSub, cbSub), VERR_NOT_SUPPORTED);
++ AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED);
++
++ /*
++ * Check that the specified alignment is supported.
++ */
++ if (uAlignment > PAGE_SIZE)
++ return VERR_NOT_SUPPORTED;
++
++ int rc;
++ PRTR0MEMOBJNETBSD pMemToMapNetBSD = (PRTR0MEMOBJNETBSD)pMemToMap;
++
++ /* calc protection */
++ vm_prot_t ProtectionFlags = 0;
++ if ((fProt & RTMEM_PROT_NONE) == RTMEM_PROT_NONE)
++ ProtectionFlags = VM_PROT_NONE;
++ if ((fProt & RTMEM_PROT_READ) == RTMEM_PROT_READ)
++ ProtectionFlags |= VM_PROT_READ;
++ if ((fProt & RTMEM_PROT_WRITE) == RTMEM_PROT_WRITE)
++ ProtectionFlags |= VM_PROT_WRITE;
++ if ((fProt & RTMEM_PROT_EXEC) == RTMEM_PROT_EXEC)
++ ProtectionFlags |= VM_PROT_EXECUTE;
++
++ vm_offset_t Addr = vm_map_min(kernel_map);
++ if (cbSub == 0)
++ cbSub = pMemToMap->cb - offSub;
++
++ vm_object_reference(pMemToMapNetBSD->pObject);
++ rc = vm_map_find(kernel_map, /* Map to insert the object in */
++ pMemToMapNetBSD->pObject, /* Object to map */
++ offSub, /* Start offset in the object */
++ &Addr, /* Start address IN/OUT */
++ cbSub, /* Size of the mapping */
++ 0, /* Upper bound of mapping */
++ VMFS_ANY_SPACE, /* Whether a suitable address should be searched for first */
++ ProtectionFlags, /* protection flags */
++ VM_PROT_ALL, /* Maximum protection flags */
++ 0); /* copy-on-write and similar flags */
++
++ if (rc == KERN_SUCCESS)
++ {
++ rc = vm_map_wire(kernel_map, Addr, Addr + cbSub, VM_MAP_WIRE_SYSTEM|VM_MAP_WIRE_NOHOLES);
++ AssertMsg(rc == KERN_SUCCESS, ("%#x\n", rc));
++
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(RTR0MEMOBJNETBSD),
++ RTR0MEMOBJTYPE_MAPPING,
++ (void *)Addr,
++ cbSub);
++ if (pMemNetBSD)
++ {
++ Assert((vm_offset_t)pMemNetBSD->Core.pv == Addr);
++ pMemNetBSD->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;
++ *ppMem = &pMemNetBSD->Core;
++ return VINF_SUCCESS;
++ }
++ rc = vm_map_remove(kernel_map, Addr, Addr + cbSub);
++ AssertMsg(rc == KERN_SUCCESS, ("Deleting mapping failed\n"));
++ }
++ else
++ vm_object_deallocate(pMemToMapNetBSD->pObject);
++
++ return VERR_NO_MEMORY;
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
++ unsigned fProt, RTR0PROCESS R0Process)
++{
++ /*
++ * Check for unsupported stuff.
++ */
++ AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
++ if (uAlignment > PAGE_SIZE)
++ return VERR_NOT_SUPPORTED;
++
++ int rc;
++ PRTR0MEMOBJNETBSD pMemToMapNetBSD = (PRTR0MEMOBJNETBSD)pMemToMap;
++ struct proc *pProc = (struct proc *)R0Process;
++ struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
++
++ /* calc protection */
++ vm_prot_t ProtectionFlags = 0;
++ if ((fProt & RTMEM_PROT_NONE) == RTMEM_PROT_NONE)
++ ProtectionFlags = VM_PROT_NONE;
++ if ((fProt & RTMEM_PROT_READ) == RTMEM_PROT_READ)
++ ProtectionFlags |= VM_PROT_READ;
++ if ((fProt & RTMEM_PROT_WRITE) == RTMEM_PROT_WRITE)
++ ProtectionFlags |= VM_PROT_WRITE;
++ if ((fProt & RTMEM_PROT_EXEC) == RTMEM_PROT_EXEC)
++ ProtectionFlags |= VM_PROT_EXECUTE;
++
++ /* calc mapping address */
++ vm_offset_t AddrR3;
++ if (R3PtrFixed == (RTR3PTR)-1)
++ {
++ /** @todo: is this needed?. */
++ PROC_LOCK(pProc);
++ AddrR3 = round_page((vm_offset_t)pProc->p_vmspace->vm_daddr + lim_max(pProc, RLIMIT_DATA));
++ PROC_UNLOCK(pProc);
++ }
++ else
++ AddrR3 = (vm_offset_t)R3PtrFixed;
++
++ /* Insert the pObject in the map. */
++ vm_object_reference(pMemToMapNetBSD->pObject);
++ rc = vm_map_find(pProcMap, /* Map to insert the object in */
++ pMemToMapNetBSD->pObject, /* Object to map */
++ 0, /* Start offset in the object */
++ &AddrR3, /* Start address IN/OUT */
++ pMemToMap->cb, /* Size of the mapping */
++ 0, /* Upper bound of the mapping */
++ R3PtrFixed == (RTR3PTR)-1 ? VMFS_ANY_SPACE : VMFS_NO_SPACE,
++ /* Whether a suitable address should be searched for first */
++ ProtectionFlags, /* protection flags */
++ VM_PROT_ALL, /* Maximum protection flags */
++ 0); /* copy-on-write and similar flags */
++
++ if (rc == KERN_SUCCESS)
++ {
++ rc = vm_map_wire(pProcMap, AddrR3, AddrR3 + pMemToMap->cb, 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);
++ AssertMsg(rc == KERN_SUCCESS, ("%#x\n", rc));
++
++ /*
++ * Create a mapping object for it.
++ */
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(RTR0MEMOBJNETBSD),
++ RTR0MEMOBJTYPE_MAPPING,
++ (void *)AddrR3,
++ pMemToMap->cb);
++ if (pMemNetBSD)
++ {
++ Assert((vm_offset_t)pMemNetBSD->Core.pv == AddrR3);
++ pMemNetBSD->Core.u.Mapping.R0Process = R0Process;
++ *ppMem = &pMemNetBSD->Core;
++ return VINF_SUCCESS;
++ }
++
++ rc = vm_map_remove(pProcMap, AddrR3, AddrR3 + pMemToMap->cb);
++ AssertMsg(rc == KERN_SUCCESS, ("Deleting mapping failed\n"));
++ }
++ else
++ vm_object_deallocate(pMemToMapNetBSD->pObject);
++
++ return VERR_NO_MEMORY;
++}
++
++
++DECLHIDDEN(int) rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
++{
++ vm_prot_t ProtectionFlags = 0;
++ vm_offset_t AddrStart = (uintptr_t)pMem->pv + offSub;
++ vm_offset_t AddrEnd = AddrStart + cbSub;
++ vm_map_t pVmMap = rtR0MemObjNetBSDGetMap(pMem);
++
++ if (!pVmMap)
++ return VERR_NOT_SUPPORTED;
++
++ if ((fProt & RTMEM_PROT_NONE) == RTMEM_PROT_NONE)
++ ProtectionFlags = VM_PROT_NONE;
++ if ((fProt & RTMEM_PROT_READ) == RTMEM_PROT_READ)
++ ProtectionFlags |= VM_PROT_READ;
++ if ((fProt & RTMEM_PROT_WRITE) == RTMEM_PROT_WRITE)
++ ProtectionFlags |= VM_PROT_WRITE;
++ if ((fProt & RTMEM_PROT_EXEC) == RTMEM_PROT_EXEC)
++ ProtectionFlags |= VM_PROT_EXECUTE;
++
++ int krc = vm_map_protect(pVmMap, AddrStart, AddrEnd, ProtectionFlags, FALSE);
++ if (krc == KERN_SUCCESS)
++ return VINF_SUCCESS;
++
++ return VERR_NOT_SUPPORTED;
++}
++
++
++DECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage)
++{
++ PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)pMem;
++
++ switch (pMemNetBSD->Core.enmType)
++ {
++ case RTR0MEMOBJTYPE_LOCK:
++ {
++ if ( pMemNetBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS
++ && pMemNetBSD->Core.u.Lock.R0Process != (RTR0PROCESS)curproc)
++ {
++ /* later */
++ return NIL_RTHCPHYS;
++ }
++
++ vm_offset_t pb = (vm_offset_t)pMemNetBSD->Core.pv + ptoa(iPage);
++
++ struct proc *pProc = (struct proc *)pMemNetBSD->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);
++ }
++
++ case RTR0MEMOBJTYPE_MAPPING:
++ {
++ vm_offset_t pb = (vm_offset_t)pMemNetBSD->Core.pv + ptoa(iPage);
++
++ if (pMemNetBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS)
++ {
++ struct proc *pProc = (struct proc *)pMemNetBSD->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);
++ }
++ return vtophys(pb);
++ }
++
++ case RTR0MEMOBJTYPE_PAGE:
++ case RTR0MEMOBJTYPE_LOW:
++ case RTR0MEMOBJTYPE_PHYS_NC:
++ {
++ RTHCPHYS addr;
++ VM_OBJECT_WLOCK(pMemNetBSD->pObject);
++ addr = VM_PAGE_TO_PHYS(vm_page_lookup(pMemNetBSD->pObject, iPage));
++ VM_OBJECT_WUNLOCK(pMemNetBSD->pObject);
++ return addr;
++ }
++
++ case RTR0MEMOBJTYPE_PHYS:
++ return pMemNetBSD->Core.u.Cont.Phys + ptoa(iPage);
++
++ case RTR0MEMOBJTYPE_CONT:
++ return pMemNetBSD->Core.u.Phys.PhysBase + ptoa(iPage);
++
++ case RTR0MEMOBJTYPE_RES_VIRT:
++ default:
++ return NIL_RTHCPHYS;
++ }
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_memuserkernel-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_memuserkernel-r0drv-netbsd.c
new file mode 100644
index 0000000..eed294e
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_memuserkernel-r0drv-netbsd.c
@@ -0,0 +1,87 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/memuserkernel-r0drv-netbsd.c.orig 2016-07-07 07:08:46.910526349 +0000
++++ src/VBox/Runtime/r0drv/netbsd/memuserkernel-r0drv-netbsd.c
+@@ -0,0 +1,82 @@
++/* memuserkernel-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - User & Kernel Memory, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (C) 2009-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++
++#include <iprt/mem.h>
++#include <iprt/err.h>
++
++
++RTR0DECL(int) RTR0MemUserCopyFrom(void *pvDst, RTR3PTR R3PtrSrc, size_t cb)
++{
++ int rc = copyin((const void *)R3PtrSrc, pvDst, cb);
++ if (RT_LIKELY(rc == 0))
++ return VINF_SUCCESS;
++ return VERR_ACCESS_DENIED;
++}
++
++
++RTR0DECL(int) RTR0MemUserCopyTo(RTR3PTR R3PtrDst, void const *pvSrc, size_t cb)
++{
++ int rc = copyout(pvSrc, (void *)R3PtrDst, cb);
++ if (RT_LIKELY(rc == 0))
++ return VINF_SUCCESS;
++ return VERR_ACCESS_DENIED;
++}
++
++
++RTR0DECL(bool) RTR0MemUserIsValidAddr(RTR3PTR R3Ptr)
++{
++ return R3Ptr < VM_MAXUSER_ADDRESS;
++}
++
++
++RTR0DECL(bool) RTR0MemKernelIsValidAddr(void *pv)
++{
++ return (uintptr_t)pv >= VM_MAXUSER_ADDRESS;
++}
++
++
++RTR0DECL(bool) RTR0MemAreKrnlAndUsrDifferent(void)
++{
++ return true;
++}
++
++
++RTR0DECL(int) RTR0MemKernelCopyFrom(void *pvDst, void const *pvSrc, size_t cb)
++{
++ return VERR_NOT_SUPPORTED;
++}
++
++
++RTR0DECL(int) RTR0MemKernelCopyTo(void *pvDst, void const *pvSrc, size_t cb)
++{
++ return VERR_NOT_SUPPORTED;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_mp-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_mp-r0drv-netbsd.c
new file mode 100644
index 0000000..0bd732f
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_mp-r0drv-netbsd.c
@@ -0,0 +1,273 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/mp-r0drv-netbsd.c.orig 2016-07-07 07:08:46.919669571 +0000
++++ src/VBox/Runtime/r0drv/netbsd/mp-r0drv-netbsd.c
+@@ -0,0 +1,268 @@
++/* mp-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Multiprocessor, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (C) 2008-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++
++#include <iprt/mp.h>
++#include <iprt/err.h>
++#include <iprt/asm.h>
++#include <iprt/cpuset.h>
++#include "r0drv/mp-r0drv.h"
++
++
++RTDECL(RTCPUID) RTMpCpuId(void)
++{
++ return curcpu;
++}
++
++
++RTDECL(int) RTMpCurSetIndex(void)
++{
++ return curcpu;
++}
++
++
++RTDECL(int) RTMpCurSetIndexAndId(PRTCPUID pidCpu)
++{
++ return *pidCpu = curcpu;
++}
++
++
++RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
++{
++ return idCpu < RTCPUSET_MAX_CPUS && idCpu <= mp_maxid ? (int)idCpu : -1;
++}
++
++
++RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
++{
++ return (unsigned)iCpu <= mp_maxid ? (RTCPUID)iCpu : NIL_RTCPUID;
++}
++
++
++RTDECL(RTCPUID) RTMpGetMaxCpuId(void)
++{
++ return mp_maxid;
++}
++
++
++RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
++{
++ return idCpu <= mp_maxid;
++}
++
++
++RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
++{
++ RTCPUID idCpu;
++
++ RTCpuSetEmpty(pSet);
++ idCpu = RTMpGetMaxCpuId();
++ do
++ {
++ if (RTMpIsCpuPossible(idCpu))
++ RTCpuSetAdd(pSet, idCpu);
++ } while (idCpu-- > 0);
++ return pSet;
++}
++
++
++RTDECL(RTCPUID) RTMpGetCount(void)
++{
++ return mp_maxid + 1;
++}
++
++
++RTDECL(RTCPUID) RTMpGetCoreCount(void)
++{
++ return mp_maxid + 1;
++}
++
++RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
++{
++ return idCpu <= mp_maxid
++ && !CPU_ABSENT(idCpu);
++}
++
++
++RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
++{
++ RTCPUID idCpu;
++
++ RTCpuSetEmpty(pSet);
++ idCpu = RTMpGetMaxCpuId();
++ do
++ {
++ if (RTMpIsCpuOnline(idCpu))
++ RTCpuSetAdd(pSet, idCpu);
++ } while (idCpu-- > 0);
++
++ return pSet;
++}
++
++
++RTDECL(RTCPUID) RTMpGetOnlineCount(void)
++{
++ return mp_ncpus;
++}
++
++
++/**
++ * Wrapper between the native NetBSD per-cpu callback and PFNRTWORKER
++ * for the RTMpOnAll API.
++ *
++ * @param pvArg Pointer to the RTMPARGS package.
++ */
++static void rtmpOnAllNetBSDWrapper(void *pvArg)
++{
++ PRTMPARGS pArgs = (PRTMPARGS)pvArg;
++ pArgs->pfnWorker(curcpu, pArgs->pvUser1, pArgs->pvUser2);
++}
++
++
++RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
++{
++ RTMPARGS Args;
++ Args.pfnWorker = pfnWorker;
++ Args.pvUser1 = pvUser1;
++ Args.pvUser2 = pvUser2;
++ Args.idCpu = NIL_RTCPUID;
++ Args.cHits = 0;
++ smp_rendezvous(NULL, rtmpOnAllNetBSDWrapper, smp_no_rendevous_barrier, &Args);
++ return VINF_SUCCESS;
++}
++
++
++/**
++ * Wrapper between the native NetBSD per-cpu callback and PFNRTWORKER
++ * for the RTMpOnOthers API.
++ *
++ * @param pvArg Pointer to the RTMPARGS package.
++ */
++static void rtmpOnOthersNetBSDWrapper(void *pvArg)
++{
++ PRTMPARGS pArgs = (PRTMPARGS)pvArg;
++ RTCPUID idCpu = curcpu;
++ if (pArgs->idCpu != idCpu)
++ pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
++}
++
++
++RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
++{
++ /* Will panic if no rendezvousing cpus, so check up front. */
++ if (RTMpGetOnlineCount() > 1)
++ {
++ cpuset_t Mask;
++ RTMPARGS Args;
++
++ Args.pfnWorker = pfnWorker;
++ Args.pvUser1 = pvUser1;
++ Args.pvUser2 = pvUser2;
++ Args.idCpu = RTMpCpuId();
++ Args.cHits = 0;
++ Mask = all_cpus;
++ CPU_CLR(curcpu, &Mask);
++ smp_rendezvous_cpus(Mask, NULL, rtmpOnOthersNetBSDWrapper, smp_no_rendevous_barrier, &Args);
++ }
++ return VINF_SUCCESS;
++}
++
++
++/**
++ * Wrapper between the native NetBSD per-cpu callback and PFNRTWORKER
++ * for the RTMpOnSpecific API.
++ *
++ * @param pvArg Pointer to the RTMPARGS package.
++ */
++static void rtmpOnSpecificNetBSDWrapper(void *pvArg)
++{
++ PRTMPARGS pArgs = (PRTMPARGS)pvArg;
++ RTCPUID idCpu = curcpu;
++ if (pArgs->idCpu == idCpu)
++ {
++ pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
++ ASMAtomicIncU32(&pArgs->cHits);
++ }
++}
++
++
++RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
++{
++ cpuset_t Mask;
++ RTMPARGS Args;
++
++ /* Will panic if no rendezvousing cpus, so make sure the cpu is online. */
++ if (!RTMpIsCpuOnline(idCpu))
++ return VERR_CPU_NOT_FOUND;
++
++ Args.pfnWorker = pfnWorker;
++ Args.pvUser1 = pvUser1;
++ Args.pvUser2 = pvUser2;
++ Args.idCpu = idCpu;
++ Args.cHits = 0;
++
++ CPU_SETOF(idCpu, &Mask);
++ smp_rendezvous_cpus(Mask, NULL, rtmpOnSpecificNetBSDWrapper, smp_no_rendevous_barrier, &Args);
++
++ return Args.cHits == 1
++ ? VINF_SUCCESS
++ : VERR_CPU_NOT_FOUND;
++}
++
++
++/**
++ * Dummy callback for RTMpPokeCpu.
++ * @param pvArg Ignored
++ */
++static void rtmpNetBSDPokeCallback(void *pvArg)
++{
++ NOREF(pvArg);
++}
++
++
++RTDECL(int) RTMpPokeCpu(RTCPUID idCpu)
++{
++ cpuset_t Mask;
++
++ /* Will panic if no rendezvousing cpus, so make sure the cpu is online. */
++ if (!RTMpIsCpuOnline(idCpu))
++ return VERR_CPU_NOT_FOUND;
++
++ CPU_SETOF(idCpu, &Mask);
++ smp_rendezvous_cpus(Mask, NULL, rtmpNetBSDPokeCallback, smp_no_rendevous_barrier, NULL);
++
++ return VINF_SUCCESS;
++}
++
++RTDECL(bool) RTMpOnAllIsConcurrentSafe(void)
++{
++ return true;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_process-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_process-r0drv-netbsd.c
new file mode 100644
index 0000000..3101597
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_process-r0drv-netbsd.c
@@ -0,0 +1,55 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/process-r0drv-netbsd.c.orig 2016-07-07 07:08:46.928969370 +0000
++++ src/VBox/Runtime/r0drv/netbsd/process-r0drv-netbsd.c
+@@ -0,0 +1,50 @@
++/* process-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Process Management, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++
++#include <iprt/process.h>
++
++
++RTDECL(RTPROCESS) RTProcSelf(void)
++{
++ struct proc *pSelf = curproc;
++ return pSelf->p_pid;
++}
++
++
++RTR0DECL(RTR0PROCESS) RTR0ProcHandleSelf(void)
++{
++ return (RTR0PROCESS)curproc;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semevent-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semevent-r0drv-netbsd.c
new file mode 100644
index 0000000..bef1feb
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semevent-r0drv-netbsd.c
@@ -0,0 +1,260 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/semevent-r0drv-netbsd.c.orig 2016-07-07 07:08:46.938368327 +0000
++++ src/VBox/Runtime/r0drv/netbsd/semevent-r0drv-netbsd.c
+@@ -0,0 +1,255 @@
++/* semevent-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Single Release Event Semaphores, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#define RTSEMEVENT_WITHOUT_REMAPPING
++#include "the-netbsd-kernel.h"
++#include "internal/iprt.h"
++#include <iprt/semaphore.h>
++
++#include <iprt/asm.h>
++#include <iprt/assert.h>
++#include <iprt/err.h>
++#include <iprt/lockvalidator.h>
++#include <iprt/mem.h>
++
++#include "sleepqueue-r0drv-netbsd.h"
++#include "internal/magics.h"
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++/**
++ * NetBSD event semaphore.
++ */
++typedef struct RTSEMEVENTINTERNAL
++{
++ /** Magic value (RTSEMEVENT_MAGIC). */
++ uint32_t volatile u32Magic;
++ /** The object status - !0 when signaled and 0 when reset. */
++ uint32_t volatile fState;
++ /** Reference counter. */
++ uint32_t volatile cRefs;
++} RTSEMEVENTINTERNAL, *PRTSEMEVENTINTERNAL;
++
++
++RTDECL(int) RTSemEventCreate(PRTSEMEVENT phEventSem)
++{
++ return RTSemEventCreateEx(phEventSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, NULL);
++}
++
++
++RTDECL(int) RTSemEventCreateEx(PRTSEMEVENT phEventSem, uint32_t fFlags, RTLOCKVALCLASS hClass, const char *pszNameFmt, ...)
++{
++ AssertCompile(sizeof(RTSEMEVENTINTERNAL) > sizeof(void *));
++ AssertReturn(!(fFlags & ~(RTSEMEVENT_FLAGS_NO_LOCK_VAL | RTSEMEVENT_FLAGS_BOOTSTRAP_HACK)), VERR_INVALID_PARAMETER);
++ Assert(!(fFlags & RTSEMEVENT_FLAGS_BOOTSTRAP_HACK) || (fFlags & RTSEMEVENT_FLAGS_NO_LOCK_VAL));
++ AssertPtrReturn(phEventSem, VERR_INVALID_POINTER);
++
++ PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)RTMemAllocZ(sizeof(*pThis));
++ if (!pThis)
++ return VERR_NO_MEMORY;
++
++ pThis->u32Magic = RTSEMEVENT_MAGIC;
++ pThis->cRefs = 1;
++ pThis->fState = 0;
++
++ *phEventSem = pThis;
++ return VINF_SUCCESS;
++}
++
++
++/**
++ * Retains a reference to the event semaphore.
++ *
++ * @param pThis The event semaphore.
++ */
++DECLINLINE(void) rtR0SemEventBsdRetain(PRTSEMEVENTINTERNAL pThis)
++{
++ uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
++ Assert(cRefs < 100000); NOREF(cRefs);
++}
++
++
++/**
++ * Releases a reference to the event semaphore.
++ *
++ * @param pThis The event semaphore.
++ */
++DECLINLINE(void) rtR0SemEventBsdRelease(PRTSEMEVENTINTERNAL pThis)
++{
++ if (RT_UNLIKELY(ASMAtomicDecU32(&pThis->cRefs) == 0))
++ RTMemFree(pThis);
++}
++
++
++RTDECL(int) RTSemEventDestroy(RTSEMEVENT hEventSem)
++{
++ /*
++ * Validate input.
++ */
++ PRTSEMEVENTINTERNAL pThis = hEventSem;
++ if (pThis == NIL_RTSEMEVENT)
++ return VINF_SUCCESS;
++ AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
++ Assert(pThis->cRefs > 0);
++
++ /*
++ * Invalidate it and signal the object just in case.
++ */
++ ASMAtomicWriteU32(&pThis->u32Magic, ~RTSEMEVENT_MAGIC);
++ ASMAtomicWriteU32(&pThis->fState, 0);
++ rtR0SemBsdBroadcast(pThis);
++ rtR0SemEventBsdRelease(pThis);
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTSemEventSignal(RTSEMEVENT hEventSem)
++{
++ /*
++ * Validate input.
++ */
++ PRTSEMEVENTINTERNAL pThis = (PRTSEMEVENTINTERNAL)hEventSem;
++ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
++ AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
++ rtR0SemEventBsdRetain(pThis);
++
++ /*
++ * Signal the event object.
++ */
++ ASMAtomicWriteU32(&pThis->fState, 1);
++ rtR0SemBsdSignal(pThis);
++ rtR0SemEventBsdRelease(pThis);
++ return VINF_SUCCESS;
++}
++
++/**
++ * Worker for RTSemEventWaitEx and RTSemEventWaitExDebug.
++ *
++ * @returns VBox status code.
++ * @param pThis The event semaphore.
++ * @param fFlags See RTSemEventWaitEx.
++ * @param uTimeout See RTSemEventWaitEx.
++ * @param pSrcPos The source code position of the wait.
++ */
++static int rtR0SemEventWait(PRTSEMEVENTINTERNAL pThis, uint32_t fFlags, uint64_t uTimeout,
++ PCRTLOCKVALSRCPOS pSrcPos)
++{
++ int rc;
++
++ /*
++ * Validate the input.
++ */
++ 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);
++ rtR0SemEventBsdRetain(pThis);
++
++ /*
++ * Try grab the event without setting up the wait.
++ */
++ if (ASMAtomicCmpXchgU32(&pThis->fState, 0, 1))
++ rc = VINF_SUCCESS;
++ else
++ {
++ /*
++ * We have to wait.
++ */
++ RTR0SEMBSDSLEEP Wait;
++ rc = rtR0SemBsdWaitInit(&Wait, fFlags, uTimeout, pThis);
++ if (RT_SUCCESS(rc))
++ {
++ for (;;)
++ {
++ /* The destruction test. */
++ if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENT_MAGIC))
++ rc = VERR_SEM_DESTROYED;
++ else
++ {
++ rtR0SemBsdWaitPrepare(&Wait);
++
++ /* Check the exit conditions. */
++ if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENT_MAGIC))
++ rc = VERR_SEM_DESTROYED;
++ else if (ASMAtomicCmpXchgU32(&pThis->fState, 0, 1))
++ rc = VINF_SUCCESS;
++ else if (rtR0SemBsdWaitHasTimedOut(&Wait))
++ rc = VERR_TIMEOUT;
++ else if (rtR0SemBsdWaitWasInterrupted(&Wait))
++ rc = VERR_INTERRUPTED;
++ else
++ {
++ /* Do the wait and then recheck the conditions. */
++ rtR0SemBsdWaitDoIt(&Wait);
++ continue;
++ }
++ }
++ break;
++ }
++
++ rtR0SemBsdWaitDelete(&Wait);
++ }
++ }
++
++ rtR0SemEventBsdRelease(pThis);
++ return rc;
++}
++
++
++RTDECL(int) RTSemEventWaitEx(RTSEMEVENT hEventSem, uint32_t fFlags, uint64_t uTimeout)
++{
++#ifndef RTSEMEVENT_STRICT
++ return rtR0SemEventWait(hEventSem, fFlags, uTimeout, NULL);
++#else
++ RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API();
++ return rtR0SemEventWait(hEventSem, fFlags, uTimeout, &SrcPos);
++#endif
++}
++RT_EXPORT_SYMBOL(RTSemEventWaitEx);
++
++
++RTDECL(int) RTSemEventWaitExDebug(RTSEMEVENT hEventSem, uint32_t fFlags, uint64_t uTimeout,
++ RTHCUINTPTR uId, RT_SRC_POS_DECL)
++{
++ RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API();
++ return rtR0SemEventWait(hEventSem, fFlags, uTimeout, &SrcPos);
++}
++RT_EXPORT_SYMBOL(RTSemEventWaitExDebug);
++
++
++RTDECL(uint32_t) RTSemEventGetResolution(void)
++{
++ return 1000000000 / hz;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semeventmulti-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semeventmulti-r0drv-netbsd.c
new file mode 100644
index 0000000..3b19381
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semeventmulti-r0drv-netbsd.c
@@ -0,0 +1,324 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/semeventmulti-r0drv-netbsd.c.orig 2016-07-07 07:08:46.948049864 +0000
++++ src/VBox/Runtime/r0drv/netbsd/semeventmulti-r0drv-netbsd.c
+@@ -0,0 +1,319 @@
++/* semeventmulti-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Multiple Release Event Semaphores, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#define RTSEMEVENTMULTI_WITHOUT_REMAPPING
++#include "the-netbsd-kernel.h"
++#include "internal/iprt.h"
++#include <iprt/semaphore.h>
++
++#include <iprt/assert.h>
++#include <iprt/asm.h>
++#include <iprt/err.h>
++#include <iprt/mem.h>
++#include <iprt/lockvalidator.h>
++
++#include "sleepqueue-r0drv-netbsd.h"
++#include "internal/magics.h"
++
++
++/*********************************************************************************************************************************
++* Defined Constants And Macros *
++*********************************************************************************************************************************/
++/** @name fStateAndGen values
++ * @{ */
++/** The state bit number. */
++#define RTSEMEVENTMULTIBSD_STATE_BIT 0
++/** The state mask. */
++#define RTSEMEVENTMULTIBSD_STATE_MASK RT_BIT_32(RTSEMEVENTMULTIBSD_STATE_BIT)
++/** The generation mask. */
++#define RTSEMEVENTMULTIBSD_GEN_MASK ~RTSEMEVENTMULTIBSD_STATE_MASK
++/** The generation shift. */
++#define RTSEMEVENTMULTIBSD_GEN_SHIFT 1
++/** The initial variable value. */
++#define RTSEMEVENTMULTIBSD_STATE_GEN_INIT UINT32_C(0xfffffffc)
++/** @} */
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++/**
++ * NetBSD multiple release event semaphore.
++ */
++typedef struct RTSEMEVENTMULTIINTERNAL
++{
++ /** Magic value (RTSEMEVENTMULTI_MAGIC). */
++ uint32_t volatile u32Magic;
++ /** The object state bit and generation counter.
++ * The generation counter is incremented every time the object is
++ * signalled. */
++ uint32_t volatile fStateAndGen;
++ /** Reference counter. */
++ uint32_t volatile cRefs;
++} RTSEMEVENTMULTIINTERNAL, *PRTSEMEVENTMULTIINTERNAL;
++
++
++RTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI phEventMultiSem)
++{
++ return RTSemEventMultiCreateEx(phEventMultiSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, NULL);
++}
++
++
++RTDECL(int) RTSemEventMultiCreateEx(PRTSEMEVENTMULTI phEventMultiSem, uint32_t fFlags, RTLOCKVALCLASS hClass,
++ const char *pszNameFmt, ...)
++{
++ PRTSEMEVENTMULTIINTERNAL pThis;
++
++ AssertReturn(!(fFlags & ~RTSEMEVENTMULTI_FLAGS_NO_LOCK_VAL), VERR_INVALID_PARAMETER);
++ pThis = (PRTSEMEVENTMULTIINTERNAL)RTMemAlloc(sizeof(*pThis));
++ if (pThis)
++ {
++ pThis->u32Magic = RTSEMEVENTMULTI_MAGIC;
++ pThis->fStateAndGen = RTSEMEVENTMULTIBSD_STATE_GEN_INIT;
++ pThis->cRefs = 1;
++
++ *phEventMultiSem = pThis;
++ return VINF_SUCCESS;
++ }
++ return VERR_NO_MEMORY;
++}
++
++
++/**
++ * Retain a reference to the semaphore.
++ *
++ * @param pThis The semaphore.
++ */
++DECLINLINE(void) rtR0SemEventMultiBsdRetain(PRTSEMEVENTMULTIINTERNAL pThis)
++{
++ uint32_t cRefs = ASMAtomicIncU32(&pThis->cRefs);
++ Assert(cRefs && cRefs < 100000);
++}
++
++
++/**
++ * Release a reference, destroy the thing if necessary.
++ *
++ * @param pThis The semaphore.
++ */
++DECLINLINE(void) rtR0SemEventMultiBsdRelease(PRTSEMEVENTMULTIINTERNAL pThis)
++{
++ if (RT_UNLIKELY(ASMAtomicDecU32(&pThis->cRefs) == 0))
++ {
++ Assert(pThis->u32Magic != RTSEMEVENTMULTI_MAGIC);
++ RTMemFree(pThis);
++ }
++}
++
++
++RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI hEventMultiSem)
++{
++ /*
++ * Validate input.
++ */
++ PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
++ if (pThis == NIL_RTSEMEVENTMULTI)
++ return VINF_SUCCESS;
++ AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
++ AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
++ Assert(pThis->cRefs > 0);
++
++ /*
++ * Invalidate it and signal the object just in case.
++ */
++ ASMAtomicWriteU32(&pThis->u32Magic, ~RTSEMEVENTMULTI_MAGIC);
++ ASMAtomicAndU32(&pThis->fStateAndGen, RTSEMEVENTMULTIBSD_GEN_MASK);
++ rtR0SemBsdBroadcast(pThis);
++ rtR0SemEventMultiBsdRelease(pThis);
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI hEventMultiSem)
++{
++ uint32_t fNew;
++ uint32_t fOld;
++
++ /*
++ * Validate input.
++ */
++ PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
++ if (!pThis)
++ return VERR_INVALID_PARAMETER;
++ AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
++ AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
++ rtR0SemEventMultiBsdRetain(pThis);
++
++ /*
++ * Signal the event object. The cause of the parnoia here is racing to try
++ * deal with racing RTSemEventMultiSignal calls (should probably be
++ * forbidden, but it's relatively easy to handle).
++ */
++ do
++ {
++ fNew = fOld = ASMAtomicUoReadU32(&pThis->fStateAndGen);
++ fNew += 1 << RTSEMEVENTMULTIBSD_GEN_SHIFT;
++ fNew |= RTSEMEVENTMULTIBSD_STATE_MASK;
++ }
++ while (!ASMAtomicCmpXchgU32(&pThis->fStateAndGen, fNew, fOld));
++
++ rtR0SemBsdBroadcast(pThis);
++ rtR0SemEventMultiBsdRelease(pThis);
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI hEventMultiSem)
++{
++ /*
++ * Validate input.
++ */
++ PRTSEMEVENTMULTIINTERNAL pThis = (PRTSEMEVENTMULTIINTERNAL)hEventMultiSem;
++ if (!pThis)
++ return VERR_INVALID_PARAMETER;
++ AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
++ AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
++ rtR0SemEventMultiBsdRetain(pThis);
++
++ /*
++ * Reset it.
++ */
++ ASMAtomicAndU32(&pThis->fStateAndGen, ~RTSEMEVENTMULTIBSD_STATE_MASK);
++
++ rtR0SemEventMultiBsdRelease(pThis);
++ return VINF_SUCCESS;
++}
++
++
++/**
++ * Worker for RTSemEventMultiWaitEx and RTSemEventMultiWaitExDebug.
++ *
++ * @returns VBox status code.
++ * @param pThis The event semaphore.
++ * @param fFlags See RTSemEventMultiWaitEx.
++ * @param uTimeout See RTSemEventMultiWaitEx.
++ * @param pSrcPos The source code position of the wait.
++ */
++static int rtR0SemEventMultiBsdWait(PRTSEMEVENTMULTIINTERNAL pThis, uint32_t fFlags, uint64_t uTimeout,
++ PCRTLOCKVALSRCPOS pSrcPos)
++{
++ uint32_t fOrgStateAndGen;
++ int rc;
++
++ /*
++ * Validate the input.
++ */
++ AssertPtrReturn(pThis, VERR_INVALID_PARAMETER);
++ AssertMsgReturn(pThis->u32Magic == RTSEMEVENTMULTI_MAGIC, ("%p u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_PARAMETER);
++ AssertReturn(RTSEMWAIT_FLAGS_ARE_VALID(fFlags), VERR_INVALID_PARAMETER);
++ rtR0SemEventMultiBsdRetain(pThis);
++
++ /*
++ * Is the event already signalled or do we have to wait?
++ */
++ fOrgStateAndGen = ASMAtomicUoReadU32(&pThis->fStateAndGen);
++ if (fOrgStateAndGen & RTSEMEVENTMULTIBSD_STATE_MASK)
++ rc = VINF_SUCCESS;
++ else
++ {
++ /*
++ * We have to wait.
++ */
++ RTR0SEMBSDSLEEP Wait;
++ rc = rtR0SemBsdWaitInit(&Wait, fFlags, uTimeout, pThis);
++ if (RT_SUCCESS(rc))
++ {
++ for (;;)
++ {
++ /* The destruction test. */
++ if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENTMULTI_MAGIC))
++ rc = VERR_SEM_DESTROYED;
++ else
++ {
++ rtR0SemBsdWaitPrepare(&Wait);
++
++ /* Check the exit conditions. */
++ if (RT_UNLIKELY(pThis->u32Magic != RTSEMEVENTMULTI_MAGIC))
++ rc = VERR_SEM_DESTROYED;
++ else if (ASMAtomicUoReadU32(&pThis->fStateAndGen) != fOrgStateAndGen)
++ rc = VINF_SUCCESS;
++ else if (rtR0SemBsdWaitHasTimedOut(&Wait))
++ rc = VERR_TIMEOUT;
++ else if (rtR0SemBsdWaitWasInterrupted(&Wait))
++ rc = VERR_INTERRUPTED;
++ else
++ {
++ /* Do the wait and then recheck the conditions. */
++ rtR0SemBsdWaitDoIt(&Wait);
++ continue;
++ }
++ }
++ break;
++ }
++
++ rtR0SemBsdWaitDelete(&Wait);
++ }
++ }
++
++ rtR0SemEventMultiBsdRelease(pThis);
++ return rc;
++}
++
++
++RTDECL(int) RTSemEventMultiWaitEx(RTSEMEVENTMULTI hEventMultiSem, uint32_t fFlags, uint64_t uTimeout)
++{
++#ifndef RTSEMEVENT_STRICT
++ return rtR0SemEventMultiBsdWait(hEventMultiSem, fFlags, uTimeout, NULL);
++#else
++ RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_NORMAL_API();
++ return rtR0SemEventMultiBsdWait(hEventMultiSem, fFlags, uTimeout, &SrcPos);
++#endif
++}
++RT_EXPORT_SYMBOL(RTSemEventMultiWaitEx);
++
++
++RTDECL(int) RTSemEventMultiWaitExDebug(RTSEMEVENTMULTI hEventMultiSem, uint32_t fFlags, uint64_t uTimeout,
++ RTHCUINTPTR uId, RT_SRC_POS_DECL)
++{
++ RTLOCKVALSRCPOS SrcPos = RTLOCKVALSRCPOS_INIT_DEBUG_API();
++ return rtR0SemEventMultiBsdWait(hEventMultiSem, fFlags, uTimeout, &SrcPos);
++}
++RT_EXPORT_SYMBOL(RTSemEventMultiWaitExDebug);
++
++
++RTDECL(uint32_t) RTSemEventMultiGetResolution(void)
++{
++ return rtR0SemBsdWaitGetResolution();
++}
++RT_EXPORT_SYMBOL(RTSemEventMultiGetResolution);
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semfastmutex-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semfastmutex-r0drv-netbsd.c
new file mode 100644
index 0000000..0d9c676
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semfastmutex-r0drv-netbsd.c
@@ -0,0 +1,119 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/semfastmutex-r0drv-netbsd.c.orig 2016-07-07 07:08:46.957643339 +0000
++++ src/VBox/Runtime/r0drv/netbsd/semfastmutex-r0drv-netbsd.c
+@@ -0,0 +1,114 @@
++/* semfastmutex-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Fast Mutex Semaphores, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++
++#include <iprt/semaphore.h>
++#include <iprt/err.h>
++#include <iprt/alloc.h>
++#include <iprt/assert.h>
++#include <iprt/asm.h>
++
++#include "internal/magics.h"
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++/**
++ * Wrapper for the NetBSD (sleep) mutex.
++ */
++typedef struct RTSEMFASTMUTEXINTERNAL
++{
++ /** Magic value (RTSEMFASTMUTEX_MAGIC). */
++ uint32_t u32Magic;
++ /** The NetBSD shared/exclusive lock mutex. */
++ struct sx SxLock;
++} RTSEMFASTMUTEXINTERNAL, *PRTSEMFASTMUTEXINTERNAL;
++
++
++RTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX phFastMtx)
++{
++ AssertCompile(sizeof(RTSEMFASTMUTEXINTERNAL) > sizeof(void *));
++ AssertPtrReturn(phFastMtx, VERR_INVALID_POINTER);
++
++ PRTSEMFASTMUTEXINTERNAL pThis = (PRTSEMFASTMUTEXINTERNAL)RTMemAllocZ(sizeof(*pThis));
++ if (pThis)
++ {
++ pThis->u32Magic = RTSEMFASTMUTEX_MAGIC;
++ sx_init_flags(&pThis->SxLock, "IPRT Fast Mutex Semaphore", SX_DUPOK);
++
++ *phFastMtx = pThis;
++ return VINF_SUCCESS;
++ }
++ return VERR_NO_MEMORY;
++}
++
++
++RTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX hFastMtx)
++{
++ PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
++ if (pThis == NIL_RTSEMFASTMUTEX)
++ return VINF_SUCCESS;
++ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
++ AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++
++ ASMAtomicWriteU32(&pThis->u32Magic, RTSEMFASTMUTEX_MAGIC_DEAD);
++ sx_destroy(&pThis->SxLock);
++ RTMemFree(pThis);
++
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX hFastMtx)
++{
++ PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
++ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
++ AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++
++ sx_xlock(&pThis->SxLock);
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTSemFastMutexRelease(RTSEMFASTMUTEX hFastMtx)
++{
++ PRTSEMFASTMUTEXINTERNAL pThis = hFastMtx;
++ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
++ AssertMsgReturn(pThis->u32Magic == RTSEMFASTMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++
++ sx_xunlock(&pThis->SxLock);
++ return VINF_SUCCESS;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semmutex-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semmutex-r0drv-netbsd.c
new file mode 100644
index 0000000..1bcecab
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_semmutex-r0drv-netbsd.c
@@ -0,0 +1,223 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/semmutex-r0drv-netbsd.c.orig 2016-07-07 07:08:46.967030335 +0000
++++ src/VBox/Runtime/r0drv/netbsd/semmutex-r0drv-netbsd.c
+@@ -0,0 +1,218 @@
++/* semmutex-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Mutex Semaphores, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (C) 2010-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#define RTSEMMUTEX_WITHOUT_REMAPPING
++#include "the-netbsd-kernel.h"
++#include "internal/iprt.h"
++#include <iprt/semaphore.h>
++
++#include <iprt/asm.h>
++#include <iprt/assert.h>
++#include <iprt/err.h>
++#include <iprt/mem.h>
++#include <iprt/thread.h>
++#include <iprt/time.h>
++
++#include "internal/magics.h"
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++/**
++ * Wrapper for the NetBSD (sleep) mutex.
++ */
++typedef struct RTSEMMUTEXINTERNAL
++{
++ /** Magic value (RTSEMMUTEX_MAGIC). */
++ uint32_t u32Magic;
++ /** The NetBSD shared/exclusive lock mutex. */
++ struct sx SxLock;
++} RTSEMMUTEXINTERNAL, *PRTSEMMUTEXINTERNAL;
++
++
++RTDECL(int) RTSemMutexCreate(PRTSEMMUTEX phMutexSem)
++{
++ AssertCompile(sizeof(RTSEMMUTEXINTERNAL) > sizeof(void *));
++ AssertPtrReturn(phMutexSem, VERR_INVALID_POINTER);
++
++ PRTSEMMUTEXINTERNAL pThis = (PRTSEMMUTEXINTERNAL)RTMemAllocZ(sizeof(*pThis));
++ if (pThis)
++ {
++ pThis->u32Magic = RTSEMMUTEX_MAGIC;
++ sx_init_flags(&pThis->SxLock, "IPRT Mutex Semaphore", SX_RECURSE);
++
++ *phMutexSem = pThis;
++ return VINF_SUCCESS;
++ }
++ return VERR_NO_MEMORY;
++}
++
++
++RTDECL(int) RTSemMutexDestroy(RTSEMMUTEX hMutexSem)
++{
++ PRTSEMMUTEXINTERNAL pThis = hMutexSem;
++ if (pThis == NIL_RTSEMMUTEX)
++ return VINF_SUCCESS;
++ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
++ AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++
++ AssertReturn(ASMAtomicCmpXchgU32(&pThis->u32Magic, RTSEMMUTEX_MAGIC_DEAD, RTSEMMUTEX_MAGIC), VERR_INVALID_HANDLE);
++
++ sx_destroy(&pThis->SxLock);
++ RTMemFree(pThis);
++
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTSemMutexRequest(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies)
++{
++ PRTSEMMUTEXINTERNAL pThis = hMutexSem;
++ int rc;
++ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
++ AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++
++ if (cMillies == RT_INDEFINITE_WAIT)
++ {
++ sx_xlock(&pThis->SxLock);
++ rc = VINF_SUCCESS;
++ }
++ else if (!cMillies)
++ {
++ if (sx_try_xlock(&pThis->SxLock))
++ rc = VINF_SUCCESS;
++ else
++ rc = VERR_TIMEOUT;
++ }
++ /*
++ * GROSS HACK: poll implementation of timeout.
++ */
++ /** @todo Implement timeouts in RTSemMutexRequest. */
++ else if (sx_try_xlock(&pThis->SxLock))
++ rc = VINF_SUCCESS;
++ else
++ {
++ uint64_t StartTS = RTTimeSystemMilliTS();
++ rc = VERR_TIMEOUT;
++ do
++ {
++ RTThreadSleep(1);
++ if (sx_try_xlock(&pThis->SxLock))
++ {
++ rc = VINF_SUCCESS;
++ break;
++ }
++ } while (RTTimeSystemMilliTS() - StartTS < cMillies);
++ }
++
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
++{
++ return RTSemMutexRequest(hMutexSem, cMillies);
++}
++
++
++RTDECL(int) RTSemMutexRequestNoResume(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies)
++{
++ PRTSEMMUTEXINTERNAL pThis = hMutexSem;
++ int rc;
++ AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
++ AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), VERR_INVALID_HANDLE);
++
++ if (cMillies == RT_INDEFINITE_WAIT)
++ {
++ if (!sx_xlock_sig(&pThis->SxLock))
++ rc = VINF_SUCCESS;
++ else
++ rc = VERR_INTERRUPTED;
++ }
++ else if (!cMillies)
++ {
++ if (sx_try_xlock(&pThis->SxLock))
++ rc = VINF_SUCCESS;
++ else
++ rc = VERR_TIMEOUT;
++ }
++ /*
++ * GROSS HACK: poll implementation of timeout.
++ */
++ /** @todo Implement timeouts and interrupt checks in
++ * RTSemMutexRequestNoResume. */
++ else if (sx_try_xlock(&pThis->SxLock))
++ rc = VINF_SUCCESS;
++ else
++ {
++ uint64_t StartTS = RTTimeSystemMilliTS();
++ rc = VERR_TIMEOUT;
++ do
++ {
++ RTThreadSleep(1);
++ if (sx_try_xlock(&pThis->SxLock))
++ {
++ rc = VINF_SUCCESS;
++ break;
++ }
++ } while (RTTimeSystemMilliTS() - StartTS < cMillies);
++ }
++
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTSemMutexRequestNoResumeDebug(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
++{
++ return RTSemMutexRequestNoResume(hMutexSem, cMillies);
++}
++
++
++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);
++
++ sx_xunlock(&pThis->SxLock);
++ return VINF_SUCCESS;
++}
++
++
++
++RTDECL(bool) RTSemMutexIsOwned(RTSEMMUTEX hMutexSem)
++{
++ PRTSEMMUTEXINTERNAL pThis = hMutexSem;
++ AssertPtrReturn(pThis, false);
++ AssertMsgReturn(pThis->u32Magic == RTSEMMUTEX_MAGIC, ("%p: u32Magic=%RX32\n", pThis, pThis->u32Magic), false);
++
++ return sx_xlocked(&pThis->SxLock);
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_sleepqueue-r0drv-netbsd.h b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_sleepqueue-r0drv-netbsd.h
new file mode 100644
index 0000000..5aeb041
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_sleepqueue-r0drv-netbsd.h
@@ -0,0 +1,334 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/sleepqueue-r0drv-netbsd.h.orig 2016-07-07 07:08:46.976604489 +0000
++++ src/VBox/Runtime/r0drv/netbsd/sleepqueue-r0drv-netbsd.h
+@@ -0,0 +1,329 @@
++/* sleepqueue-r0drv-netbsd.h $ */
++/** @file
++ * IPRT - NetBSD Ring-0 Driver Helpers for Abstracting Sleep Queues,
++ */
++
++/*
++ * Copyright (C) 2006-2015 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.
++ */
++
++
++#ifndef ___r0drv_netbsd_sleepqueue_r0drv_netbsd_h
++#define ___r0drv_netbsd_sleepqueue_r0drv_netbsd_h
++
++#include "the-netbsd-kernel.h"
++
++#include <iprt/asm-math.h>
++#include <iprt/err.h>
++#include <iprt/string.h>
++#include <iprt/time.h>
++
++/**
++ * Kernel mode MetBSD wait state structure.
++ */
++typedef struct RTR0SEMBSDSLEEP
++{
++ /** The absolute timeout given as nano seconds since the start of the
++ * monotonic clock. */
++ uint64_t uNsAbsTimeout;
++ /** The timeout in ticks. Updated after waiting. */
++ int iTimeout;
++ /** Set if it's an indefinite wait. */
++ bool fIndefinite;
++ /** Set if we've already timed out.
++ * Set by rtR0SemBsdWaitDoIt and read by rtR0SemBsdWaitHasTimedOut. */
++ bool fTimedOut;
++ /** Flag whether the wait was interrupted. */
++ bool fInterrupted;
++ /** flag whether the wait is interruptible or not. */
++ bool fInterruptible;
++ /** Opaque wait channel id. */
++ void *pvWaitChan;
++} RTR0SEMBSDSLEEP;
++/** Pointer to a MetBSD wait state. */
++typedef RTR0SEMBSDSLEEP *PRTR0SEMBSDSLEEP;
++
++
++/**
++ * Updates the timeout of the MetBSD wait.
++ *
++ * @returns RTSEMWAIT_FLAGS_INDEFINITE if the timeout value is too big.
++ * 0 otherwise
++ * @param pWait The wait structure.
++ * @param uTimeout The relative timeout in nanoseconds.
++ */
++DECLINLINE(uint32_t) rtR0SemBsdWaitUpdateTimeout(PRTR0SEMBSDSLEEP pWait, uint64_t uTimeout)
++{
++#if 0
++ struct timeval tv;
++
++ tv.tv_sec = uTimeout / UINT64_C(1000000000);
++ tv.tv_usec = (uTimeout % UINT64_C(1000000000)) / UINT64_C(1000);
++
++ pWait->iTimeout = tvtohz(&tv);
++#else
++ uint64_t cTicks = ASMMultU64ByU32DivByU32(uTimeout, hz, UINT32_C(1000000000));
++ if (cTicks >= INT_MAX)
++ return RTSEMWAIT_FLAGS_INDEFINITE;
++ else
++ pWait->iTimeout = (int)cTicks;
++#endif
++
++ return 0;
++}
++
++/**
++ * Initializes a wait.
++ *
++ * The caller MUST check the wait condition BEFORE calling this function or the
++ * timeout logic will be flawed.
++ *
++ * @returns VINF_SUCCESS or VERR_TIMEOUT.
++ * @param pWait The wait structure.
++ * @param fFlags The wait flags.
++ * @param uTimeout The timeout.
++ * @param pvWaitChan The opaque wait channel.
++ */
++DECLINLINE(int) rtR0SemBsdWaitInit(PRTR0SEMBSDSLEEP pWait, uint32_t fFlags, uint64_t uTimeout,
++ void *pvWaitChan)
++{
++ pWait->iTimeout = 0;
++ pWait->uNsAbsTimeout = 0; /* shut up gcc */
++
++ /*
++ * Process the flags and timeout.
++ */
++ if (!(fFlags & RTSEMWAIT_FLAGS_INDEFINITE))
++ {
++/** @todo optimize: millisecs -> nanosecs -> millisec -> jiffies */
++ if (fFlags & RTSEMWAIT_FLAGS_MILLISECS)
++ uTimeout = uTimeout < UINT64_MAX / UINT32_C(1000000) * UINT32_C(1000000)
++ ? uTimeout * UINT32_C(1000000)
++ : UINT64_MAX;
++ if (uTimeout == UINT64_MAX)
++ fFlags |= RTSEMWAIT_FLAGS_INDEFINITE;
++ else
++ {
++ uint64_t u64Now;
++ if (fFlags & RTSEMWAIT_FLAGS_RELATIVE)
++ {
++ if (uTimeout == 0)
++ return VERR_TIMEOUT;
++
++ u64Now = RTTimeSystemNanoTS();
++ if (u64Now + uTimeout < u64Now) /* overflow */
++ fFlags |= RTSEMWAIT_FLAGS_INDEFINITE;
++ else
++ pWait->uNsAbsTimeout = u64Now + uTimeout;
++ }
++ else
++ {
++ u64Now = RTTimeSystemNanoTS();
++ if (u64Now >= uTimeout)
++ return VERR_TIMEOUT;
++
++ pWait->uNsAbsTimeout = uTimeout;
++ uTimeout -= u64Now; /* Get a relative value. */
++ }
++ }
++ }
++
++ if (!(fFlags & RTSEMWAIT_FLAGS_INDEFINITE))
++ {
++ pWait->fIndefinite = false;
++ fFlags |= rtR0SemBsdWaitUpdateTimeout(pWait, uTimeout);
++ }
++
++ if (fFlags & RTSEMWAIT_FLAGS_INDEFINITE)
++ {
++ pWait->fIndefinite = true;
++ pWait->iTimeout = INT_MAX;
++ pWait->uNsAbsTimeout = UINT64_MAX;
++ }
++
++ pWait->fTimedOut = false;
++
++ /*
++ * Initialize the wait queue related bits.
++ */
++ pWait->fInterruptible = fFlags & RTSEMWAIT_FLAGS_INTERRUPTIBLE
++ ? true : false;
++ pWait->pvWaitChan = pvWaitChan;
++ pWait->fInterrupted = false;
++
++ return VINF_SUCCESS;
++}
++
++/**
++ * Prepares the next wait.
++ *
++ * This must be called before rtR0SemBsdWaitDoIt, and the caller should check
++ * the exit conditions inbetween the two calls.
++ *
++ * @param pWait The wait structure.
++ */
++DECLINLINE(void) rtR0SemBsdWaitPrepare(PRTR0SEMBSDSLEEP pWait)
++{
++ /* Lock the queues. */
++ sleepq_lock(pWait->pvWaitChan);
++}
++
++/**
++ * Do the actual wait.
++ *
++ * @param pWait The wait structure.
++ */
++DECLINLINE(void) rtR0SemBsdWaitDoIt(PRTR0SEMBSDSLEEP pWait)
++{
++ int rcBsd;
++ int fSleepqFlags = SLEEPQ_CONDVAR;
++
++ if (pWait->fInterruptible)
++ fSleepqFlags |= SLEEPQ_INTERRUPTIBLE;
++
++ sleepq_add(pWait->pvWaitChan, NULL, "VBoxIS", fSleepqFlags, 0);
++
++ if (!pWait->fIndefinite)
++ {
++ sleepq_set_timeout(pWait->pvWaitChan, pWait->iTimeout);
++
++ if (pWait->fInterruptible)
++ rcBsd = SLEEPQ_TIMEDWAIT_SIG(pWait->pvWaitChan);
++ else
++ rcBsd = SLEEPQ_TIMEDWAIT(pWait->pvWaitChan);
++ }
++ else
++ {
++ if (pWait->fInterruptible)
++ rcBsd = SLEEPQ_WAIT_SIG(pWait->pvWaitChan);
++ else
++ {
++ rcBsd = 0;
++ SLEEPQ_WAIT(pWait->pvWaitChan);
++ }
++ }
++
++ switch (rcBsd)
++ {
++ case 0:
++ break;
++ case ERESTART:
++ {
++ if (!pWait->fIndefinite)
++ {
++ /* Recalc timeout. */
++ uint64_t u64Now = RTTimeSystemNanoTS();
++ if (u64Now >= pWait->uNsAbsTimeout)
++ pWait->fTimedOut = true;
++ else
++ {
++ u64Now = pWait->uNsAbsTimeout - u64Now;
++ rtR0SemBsdWaitUpdateTimeout(pWait, u64Now);
++ }
++ }
++ break;
++ }
++ case EWOULDBLOCK:
++ pWait->fTimedOut = true;
++ break;
++ case EINTR:
++ Assert(pWait->fInterruptible);
++ pWait->fInterrupted = true;
++ break;
++ default:
++ AssertMsgFailed(("sleepq_* -> %d\n", rcBsd));
++ break;
++ }
++}
++
++
++/**
++ * Checks if a MetBSD wait was interrupted.
++ *
++ * @returns true / false
++ * @param pWait The wait structure.
++ * @remarks This shall be called before the first rtR0SemBsdWaitDoIt().
++ */
++DECLINLINE(bool) rtR0SemBsdWaitWasInterrupted(PRTR0SEMBSDSLEEP pWait)
++{
++ return pWait->fInterrupted;
++}
++
++
++/**
++ * Checks if a MetBSD wait has timed out.
++ *
++ * @returns true / false
++ * @param pWait The wait structure.
++ */
++DECLINLINE(bool) rtR0SemBsdWaitHasTimedOut(PRTR0SEMBSDSLEEP pWait)
++{
++ return pWait->fTimedOut;
++}
++
++
++/**
++ * Deletes a MetBSD wait.
++ *
++ * @param pWait The wait structure.
++ */
++DECLINLINE(void) rtR0SemBsdWaitDelete(PRTR0SEMBSDSLEEP pWait)
++{
++ sleepq_release(pWait->pvWaitChan);
++}
++
++
++/**
++ * Signals the wait channel.
++ *
++ * @param pvWaitChan The opaque wait channel handle.
++ */
++DECLINLINE(void) rtR0SemBsdSignal(void *pvWaitChan)
++{
++ sleepq_lock(pvWaitChan);
++ int fWakeupSwapProc = sleepq_signal(pvWaitChan, SLEEPQ_CONDVAR, 0, 0);
++ sleepq_release(pvWaitChan);
++ if (fWakeupSwapProc)
++ kick_proc0();
++}
++
++/**
++ * Wakes up all waiters on the wait channel.
++ *
++ * @param pvWaitChan The opaque wait channel handle.
++ */
++DECLINLINE(void) rtR0SemBsdBroadcast(void *pvWaitChan)
++{
++ sleepq_lock(pvWaitChan);
++ sleepq_broadcast(pvWaitChan, SLEEPQ_CONDVAR, 0, 0);
++ sleepq_release(pvWaitChan);
++}
++
++/**
++ * Gets the max resolution of the timeout machinery.
++ *
++ * @returns Resolution specified in nanoseconds.
++ */
++DECLINLINE(uint32_t) rtR0SemBsdWaitGetResolution(void)
++{
++ return 1000000000 / hz; /* ns */
++}
++
++#endif
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_spinlock-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_spinlock-r0drv-netbsd.c
new file mode 100644
index 0000000..974bbab
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_spinlock-r0drv-netbsd.c
@@ -0,0 +1,214 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/spinlock-r0drv-netbsd.c.orig 2016-07-07 07:08:46.986058035 +0000
++++ src/VBox/Runtime/r0drv/netbsd/spinlock-r0drv-netbsd.c
+@@ -0,0 +1,209 @@
++/* spinlock-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Spinlocks, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++#include "internal/iprt.h"
++
++#include <iprt/spinlock.h>
++#include <iprt/err.h>
++#include <iprt/alloc.h>
++#include <iprt/assert.h>
++#include <iprt/asm.h>
++#include <iprt/asm-amd64-x86.h>
++#include <iprt/thread.h>
++#include <iprt/mp.h>
++
++#include "internal/magics.h"
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++/**
++ * Wrapper for the struct mtx type.
++ */
++typedef struct RTSPINLOCKINTERNAL
++{
++ /** Spinlock magic value (RTSPINLOCK_MAGIC). */
++ uint32_t volatile u32Magic;
++ /** The spinlock. */
++ uint32_t volatile fLocked;
++ /** Saved interrupt flag. */
++ uint32_t volatile fIntSaved;
++ /** The spinlock creation flags. */
++ uint32_t fFlags;
++#ifdef RT_MORE_STRICT
++ /** The idAssertCpu variable before acquring the lock for asserting after
++ * releasing the spinlock. */
++ RTCPUID volatile idAssertCpu;
++ /** The CPU that owns the lock. */
++ RTCPUID volatile idCpuOwner;
++#endif
++} RTSPINLOCKINTERNAL, *PRTSPINLOCKINTERNAL;
++
++
++RTDECL(int) RTSpinlockCreate(PRTSPINLOCK pSpinlock, uint32_t fFlags, const char *pszName)
++{
++ RT_ASSERT_PREEMPTIBLE();
++ AssertReturn(fFlags == RTSPINLOCK_FLAGS_INTERRUPT_SAFE || fFlags == RTSPINLOCK_FLAGS_INTERRUPT_UNSAFE, VERR_INVALID_PARAMETER);
++
++ /*
++ * Allocate.
++ */
++ AssertCompile(sizeof(RTSPINLOCKINTERNAL) > sizeof(void *));
++ PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)RTMemAllocZ(sizeof(*pThis));
++ if (!pThis)
++ return VERR_NO_MEMORY;
++
++ /*
++ * Initialize & return.
++ */
++ pThis->u32Magic = RTSPINLOCK_MAGIC;
++ pThis->fLocked = 0;
++ pThis->fFlags = fFlags;
++ pThis->fIntSaved = 0;
++
++ *pSpinlock = pThis;
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTSpinlockDestroy(RTSPINLOCK Spinlock)
++{
++ /*
++ * Validate input.
++ */
++ RT_ASSERT_INTS_ON();
++ PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
++ if (!pThis)
++ return VERR_INVALID_PARAMETER;
++ AssertMsgReturn(pThis->u32Magic == RTSPINLOCK_MAGIC,
++ ("Invalid spinlock %p magic=%#x\n", pThis, pThis->u32Magic),
++ VERR_INVALID_PARAMETER);
++
++ /*
++ * Make the lock invalid and release the memory.
++ */
++ ASMAtomicIncU32(&pThis->u32Magic);
++ RTMemFree(pThis);
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(void) RTSpinlockAcquire(RTSPINLOCK Spinlock)
++{
++ PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
++ RT_ASSERT_PREEMPT_CPUID_VAR();
++ AssertPtr(pThis);
++ Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
++
++ if (pThis->fFlags & RTSPINLOCK_FLAGS_INTERRUPT_SAFE)
++ {
++ for (;;)
++ {
++ uint32_t fIntSaved = ASMIntDisableFlags();
++ critical_enter();
++
++ int c = 50;
++ for (;;)
++ {
++ if (ASMAtomicCmpXchgU32(&pThis->fLocked, 1, 0))
++ {
++ RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis);
++ pThis->fIntSaved = fIntSaved;
++ return;
++ }
++ if (--c <= 0)
++ break;
++ cpu_spinwait();
++ }
++
++ /* Enable interrupts while we sleep. */
++ ASMSetFlags(fIntSaved);
++ critical_exit();
++ DELAY(1);
++ }
++ }
++ else
++ {
++ for (;;)
++ {
++ critical_enter();
++
++ int c = 50;
++ for (;;)
++ {
++ if (ASMAtomicCmpXchgU32(&pThis->fLocked, 1, 0))
++ {
++ RT_ASSERT_PREEMPT_CPUID_SPIN_ACQUIRED(pThis);
++ return;
++ }
++ if (--c <= 0)
++ break;
++ cpu_spinwait();
++ }
++
++ critical_exit();
++ DELAY(1);
++ }
++ }
++}
++
++
++RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock)
++{
++ PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
++ RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE_VARS();
++
++ AssertPtr(pThis);
++ Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
++ RT_ASSERT_PREEMPT_CPUID_SPIN_RELEASE(pThis);
++
++ if (pThis->fFlags & RTSPINLOCK_FLAGS_INTERRUPT_SAFE)
++ {
++ uint32_t fIntSaved = pThis->fIntSaved;
++ pThis->fIntSaved = 0;
++ if (ASMAtomicCmpXchgU32(&pThis->fLocked, 0, 1))
++ ASMSetFlags(fIntSaved);
++ else
++ AssertMsgFailed(("Spinlock %p was not locked!\n", pThis));
++ }
++ else
++ {
++ if (!ASMAtomicCmpXchgU32(&pThis->fLocked, 0, 1))
++ AssertMsgFailed(("Spinlock %p was not locked!\n", pThis));
++ }
++
++ critical_exit();
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_the-netbsd-kernel.h b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_the-netbsd-kernel.h
new file mode 100644
index 0000000..0c85e5c
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_the-netbsd-kernel.h
@@ -0,0 +1,106 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/the-netbsd-kernel.h.orig 2016-07-07 07:08:46.995240419 +0000
++++ src/VBox/Runtime/r0drv/netbsd/the-netbsd-kernel.h
+@@ -0,0 +1,101 @@
++/* the-netbsd-kernel.h $ */
++/** @file
++ * IPRT - Ring-0 Driver, The NetBSD Kernel Headers.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++#ifndef ___the_netbsd_kernel_h
++#define ___the_netbsd_kernel_h
++
++#include <iprt/types.h>
++
++/* Deal with conflicts first. */
++#include <sys/param.h>
++#undef PVM
++#include <sys/bus.h>
++#include <sys/types.h>
++#include <sys/errno.h>
++#include <sys/kernel.h>
++#include <sys/uio.h>
++#include <sys/libkern.h>
++#include <sys/systm.h>
++#include <sys/malloc.h>
++#include <sys/pcpu.h>
++#include <sys/proc.h>
++#include <sys/limits.h>
++#include <sys/unistd.h>
++#include <sys/kthread.h>
++#include <sys/lock.h>
++#include <sys/rwlock.h>
++#include <sys/mutex.h>
++#include <sys/sched.h>
++#include <sys/callout.h>
++#include <sys/cpu.h>
++#include <sys/smp.h>
++#include <sys/sleepqueue.h>
++#include <sys/sx.h>
++#include <vm/vm.h>
++#include <vm/pmap.h> /* for vtophys */
++#include <vm/vm_map.h>
++#include <vm/vm_object.h>
++#include <vm/vm_kern.h>
++#include <vm/vm_param.h> /* KERN_SUCCESS ++ */
++#include <vm/vm_page.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 <sys/resourcevar.h>
++#include <machine/cpu.h>
++
++/**
++ * Wrappers around the sleepq_ KPI.
++ */
++# define SLEEPQ_TIMEDWAIT(EventInt) sleepq_timedwait(EventInt, 0)
++# define SLEEPQ_TIMEDWAIT_SIG(EventInt) sleepq_timedwait_sig(EventInt, 0)
++# define SLEEPQ_WAIT(EventInt) sleepq_wait(EventInt, 0)
++# define SLEEPQ_WAIT_SIG(EventInt) sleepq_wait_sig(EventInt, 0)
++
++/**
++ * Our pmap_enter version
++ */
++# define MY_PMAP_ENTER(pPhysMap, AddrR3, pPage, fProt, fWired) \
++ pmap_enter(pPhysMap, AddrR3, VM_PROT_NONE, pPage, fProt, fWired)
++
++/**
++ * Check whether we can use kmem_alloc_attr for low allocs.
++ */
++# define USE_KMEM_ALLOC_ATTR
++
++/**
++ * Check whether we can use kmem_alloc_prot.
++ */
++#if 0 /** @todo Not available yet. */
++# define USE_KMEM_ALLOC_PROT
++#endif
++
++#endif
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_thread-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_thread-r0drv-netbsd.c
new file mode 100644
index 0000000..c574f28
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_thread-r0drv-netbsd.c
@@ -0,0 +1,186 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/thread-r0drv-netbsd.c.orig 2016-07-07 07:08:47.004520434 +0000
++++ src/VBox/Runtime/r0drv/netbsd/thread-r0drv-netbsd.c
+@@ -0,0 +1,181 @@
++/* thread-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Threads (Part 1), Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (C) 2007-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++#include "internal/iprt.h"
++#include <iprt/thread.h>
++
++#include <iprt/asm.h>
++#include <iprt/asm-amd64-x86.h>
++#include <iprt/assert.h>
++#include <iprt/err.h>
++#include <iprt/mp.h>
++#include "internal/thread.h"
++
++
++RTDECL(RTNATIVETHREAD) RTThreadNativeSelf(void)
++{
++ return (RTNATIVETHREAD)curthread;
++}
++
++
++static int rtR0ThreadFbsdSleepCommon(RTMSINTERVAL cMillies)
++{
++ int rc;
++ int cTicks;
++
++ /*
++ * 0 ms sleep -> yield.
++ */
++ if (!cMillies)
++ {
++ RTThreadYield();
++ return VINF_SUCCESS;
++ }
++
++ /*
++ * 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;
++ }
++ }
++ else
++ cTicks = 0; /* requires giant lock! */
++
++ rc = tsleep((void *)RTThreadSleep,
++ PZERO | PCATCH,
++ "iprtsl", /* max 6 chars */
++ cTicks);
++ switch (rc)
++ {
++ case 0:
++ return VINF_SUCCESS;
++ case EWOULDBLOCK:
++ return VERR_TIMEOUT;
++ case EINTR:
++ case ERESTART:
++ return VERR_INTERRUPTED;
++ default:
++ AssertMsgFailed(("%d\n", rc));
++ return VERR_NO_TRANSLATION;
++ }
++}
++
++
++RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
++{
++ return rtR0ThreadFbsdSleepCommon(cMillies);
++}
++
++
++RTDECL(int) RTThreadSleepNoLog(RTMSINTERVAL cMillies)
++{
++ return rtR0ThreadFbsdSleepCommon(cMillies);
++}
++
++
++RTDECL(bool) RTThreadYield(void)
++{
++ kern_yield(curthread->td_user_pri);
++ return false; /** @todo figure this one ... */
++}
++
++
++RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
++{
++ Assert(hThread == NIL_RTTHREAD);
++
++ return curthread->td_critnest == 0
++ && ASMIntAreEnabled(); /** @todo is there a native netbsd function/macro for this? */
++}
++
++
++RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
++{
++ Assert(hThread == NIL_RTTHREAD);
++
++ return curthread->td_owepreempt == 1;
++}
++
++
++RTDECL(bool) RTThreadPreemptIsPendingTrusty(void)
++{
++ /* yes, RTThreadPreemptIsPending is reliable. */
++ return true;
++}
++
++
++RTDECL(bool) RTThreadPreemptIsPossible(void)
++{
++ /* yes, kernel preemption is possible. */
++ return true;
++}
++
++
++RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState)
++{
++ AssertPtr(pState);
++ Assert(pState->u32Reserved == 0);
++ pState->u32Reserved = 42;
++
++ critical_enter();
++ RT_ASSERT_PREEMPT_CPUID_DISABLE(pState);
++}
++
++
++RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
++{
++ AssertPtr(pState);
++ Assert(pState->u32Reserved == 42);
++ pState->u32Reserved = 0;
++
++ RT_ASSERT_PREEMPT_CPUID_RESTORE(pState);
++ critical_exit();
++}
++
++
++RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
++{
++ Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
++ /** @todo NetBSD: Implement RTThreadIsInInterrupt. Required for guest
++ * additions! */
++ return !ASMIntAreEnabled();
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_thread2-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_thread2-r0drv-netbsd.c
new file mode 100644
index 0000000..d64e6e7
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_thread2-r0drv-netbsd.c
@@ -0,0 +1,139 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/thread2-r0drv-netbsd.c.orig 2016-07-07 07:08:47.013842911 +0000
++++ src/VBox/Runtime/r0drv/netbsd/thread2-r0drv-netbsd.c
+@@ -0,0 +1,134 @@
++/* thread2-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Threads (Part 2), Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++
++#include <iprt/thread.h>
++#include <iprt/err.h>
++#include <iprt/assert.h>
++
++#include "internal/thread.h"
++
++
++DECLHIDDEN(int) rtThreadNativeInit(void)
++{
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(RTTHREAD) RTThreadSelf(void)
++{
++ return rtThreadGetByNative(RTThreadNativeSelf());
++}
++
++
++DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
++{
++ int iPriority;
++
++ switch (enmType)
++ {
++ case RTTHREADTYPE_INFREQUENT_POLLER: iPriority = PZERO + 8; break;
++ case RTTHREADTYPE_EMULATION: iPriority = PZERO + 4; break;
++ case RTTHREADTYPE_DEFAULT: iPriority = PZERO; break;
++ case RTTHREADTYPE_MSG_PUMP: iPriority = PZERO - 4; break;
++ case RTTHREADTYPE_IO: iPriority = PRIBIO; break;
++ case RTTHREADTYPE_TIMER: iPriority = PRI_MIN_KERN; break;
++ default:
++ AssertMsgFailed(("enmType=%d\n", enmType));
++ return VERR_INVALID_PARAMETER;
++ }
++
++ thread_lock(curthread);
++ sched_prio(curthread, iPriority);
++ thread_unlock(curthread);
++
++ return VINF_SUCCESS;
++}
++
++
++DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
++{
++ NOREF(pThread);
++ /* There is nothing special that needs doing here, but the
++ user really better know what he's cooking. */
++ return VINF_SUCCESS;
++}
++
++
++DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
++{
++ /** @todo fix RTThreadWait/RTR0Term race on netbsd. */
++ RTThreadSleep(1);
++}
++
++
++DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
++{
++ NOREF(pThread);
++}
++
++
++/**
++ * Native thread main function.
++ *
++ * @param pvThreadInt The thread structure.
++ */
++static void rtThreadNativeMain(void *pvThreadInt)
++{
++ const struct thread *Self = curthread;
++ PRTTHREADINT pThreadInt = (PRTTHREADINT)pvThreadInt;
++ int rc;
++
++ rc = rtThreadMain(pThreadInt, (RTNATIVETHREAD)Self, &pThreadInt->szName[0]);
++
++ kproc_exit(rc);
++}
++
++
++DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
++{
++ int rc;
++ struct proc *pProc;
++
++ rc = kproc_create(rtThreadNativeMain, pThreadInt, &pProc, RFHIGHPID, 0, "%s", pThreadInt->szName);
++ if (!rc)
++ {
++ *pNativeThread = (RTNATIVETHREAD)FIRST_THREAD_IN_PROC(pProc);
++ rc = VINF_SUCCESS;
++ }
++ else
++ rc = RTErrConvertFromErrno(rc);
++ return rc;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_time-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_time-r0drv-netbsd.c
new file mode 100644
index 0000000..2e38843
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_time-r0drv-netbsd.c
@@ -0,0 +1,78 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/time-r0drv-netbsd.c.orig 2016-07-07 07:08:47.023047744 +0000
++++ src/VBox/Runtime/r0drv/netbsd/time-r0drv-netbsd.c
+@@ -0,0 +1,73 @@
++/* time-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Time, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++#define RTTIME_INCL_TIMESPEC
++
++#include <iprt/time.h>
++
++
++RTDECL(uint64_t) RTTimeNanoTS(void)
++{
++ struct timespec tsp;
++ nanouptime(&tsp);
++ return tsp.tv_sec * RT_NS_1SEC_64
++ + tsp.tv_nsec;
++}
++
++
++RTDECL(uint64_t) RTTimeMilliTS(void)
++{
++ return RTTimeNanoTS() / RT_NS_1MS;
++}
++
++
++RTDECL(uint64_t) RTTimeSystemNanoTS(void)
++{
++ return RTTimeNanoTS();
++}
++
++
++RTDECL(uint64_t) RTTimeSystemMilliTS(void)
++{
++ return RTTimeMilliTS();
++}
++
++
++RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)
++{
++ struct timespec tsp;
++ nanotime(&tsp);
++ return RTTimeSpecSetTimespec(pTime, &tsp);
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_timer-r0drv-netbsd.c b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_timer-r0drv-netbsd.c
new file mode 100644
index 0000000..6939c0e
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r0drv_netbsd_timer-r0drv-netbsd.c
@@ -0,0 +1,290 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r0drv/netbsd/timer-r0drv-netbsd.c.orig 2016-07-07 07:08:47.032319693 +0000
++++ src/VBox/Runtime/r0drv/netbsd/timer-r0drv-netbsd.c
+@@ -0,0 +1,285 @@
++/* timer-r0drv-netbsd.c $ */
++/** @file
++ * IPRT - Memory Allocation, Ring-0 Driver, NetBSD.
++ */
++
++/*
++ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam%anduin.net@localhost>
++ *
++ * Permission is hereby granted, free of charge, to any person
++ * obtaining a copy of this software and associated documentation
++ * files (the "Software"), to deal in the Software without
++ * restriction, including without limitation the rights to use,
++ * copy, modify, merge, publish, distribute, sublicense, and/or sell
++ * copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following
++ * conditions:
++ *
++ * The above copyright notice and this permission notice shall be
++ * included in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
++ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
++ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
++ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
++ * OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include "the-netbsd-kernel.h"
++
++#include <iprt/timer.h>
++#include <iprt/time.h>
++#include <iprt/spinlock.h>
++#include <iprt/err.h>
++#include <iprt/asm.h>
++#include <iprt/assert.h>
++#include <iprt/alloc.h>
++
++#include "internal/magics.h"
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++/**
++ * The internal representation of an NetBSD timer handle.
++ */
++typedef struct RTTIMER
++{
++ /** Magic.
++ * This is RTTIMER_MAGIC, but changes to something else before the timer
++ * is destroyed to indicate clearly that thread should exit. */
++ uint32_t volatile u32Magic;
++ /** Flag indicating that the timer is suspended. */
++ uint8_t volatile fSuspended;
++ /** Whether the timer must run on a specific CPU or not. */
++ uint8_t fSpecificCpu;
++ /** The CPU it must run on if fSpecificCpu is set. */
++ uint32_t iCpu;
++ /** The NetBSD callout structure. */
++ struct callout Callout;
++ /** Callback. */
++ PFNRTTIMER pfnTimer;
++ /** User argument. */
++ void *pvUser;
++ /** The timer interval. 0 if one-shot. */
++ uint64_t u64NanoInterval;
++ /** The start of the current run.
++ * This is used to calculate when the timer ought to fire the next time. */
++ uint64_t volatile u64StartTS;
++ /** The start of the current run.
++ * This is used to calculate when the timer ought to fire the next time. */
++ uint64_t volatile u64NextTS;
++ /** The current tick number (since u64StartTS). */
++ uint64_t volatile iTick;
++} RTTIMER;
++
++
++/*********************************************************************************************************************************
++* Internal Functions *
++*********************************************************************************************************************************/
++static void rtTimerNetBSDCallback(void *pvTimer);
++
++
++
++RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, uint32_t fFlags, PFNRTTIMER pfnTimer, void *pvUser)
++{
++ *ppTimer = NULL;
++
++ /*
++ * Validate flags.
++ */
++ if (!RTTIMER_FLAGS_ARE_VALID(fFlags))
++ return VERR_INVALID_PARAMETER;
++ if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC)
++ && (fFlags & RTTIMER_FLAGS_CPU_ALL) != RTTIMER_FLAGS_CPU_ALL
++ && (fFlags & RTTIMER_FLAGS_CPU_MASK) > mp_maxid)
++ return VERR_CPU_NOT_FOUND;
++
++ /*
++ * Allocate and initialize the timer handle.
++ */
++ PRTTIMER pTimer = (PRTTIMER)RTMemAlloc(sizeof(*pTimer));
++ if (!pTimer)
++ return VERR_NO_MEMORY;
++
++ pTimer->u32Magic = RTTIMER_MAGIC;
++ pTimer->fSuspended = true;
++ pTimer->fSpecificCpu = !!(fFlags & RTTIMER_FLAGS_CPU_SPECIFIC);
++ pTimer->iCpu = fFlags & RTTIMER_FLAGS_CPU_MASK;
++ pTimer->pfnTimer = pfnTimer;
++ pTimer->pvUser = pvUser;
++ pTimer->u64NanoInterval = u64NanoInterval;
++ pTimer->u64StartTS = 0;
++ callout_init(&pTimer->Callout, CALLOUT_MPSAFE);
++
++ *ppTimer = pTimer;
++ return VINF_SUCCESS;
++}
++
++
++/**
++ * Validates the timer handle.
++ *
++ * @returns true if valid, false if invalid.
++ * @param pTimer The handle.
++ */
++DECLINLINE(bool) rtTimerIsValid(PRTTIMER pTimer)
++{
++ AssertReturn(VALID_PTR(pTimer), false);
++ AssertReturn(pTimer->u32Magic == RTTIMER_MAGIC, false);
++ return true;
++}
++
++
++RTDECL(int) RTTimerDestroy(PRTTIMER pTimer)
++{
++ /* It's ok to pass NULL pointer. */
++ if (pTimer == /*NIL_RTTIMER*/ NULL)
++ return VINF_SUCCESS;
++ if (!rtTimerIsValid(pTimer))
++ return VERR_INVALID_HANDLE;
++
++ /*
++ * Free the associated resources.
++ */
++ pTimer->u32Magic++;
++ callout_stop(&pTimer->Callout);
++ RTMemFree(pTimer);
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First)
++{
++ struct timeval tv;
++
++ if (!rtTimerIsValid(pTimer))
++ return VERR_INVALID_HANDLE;
++ if (!pTimer->fSuspended)
++ return VERR_TIMER_ACTIVE;
++ if ( pTimer->fSpecificCpu
++ && !RTMpIsCpuOnline(pTimer->idCpu))
++ return VERR_CPU_OFFLINE;
++
++ /*
++ * Calc when it should start firing.
++ */
++ u64First += RTTimeNanoTS();
++
++ pTimer->fSuspended = false;
++ pTimer->iTick = 0;
++ pTimer->u64StartTS = u64First;
++ pTimer->u64NextTS = u64First;
++
++ tv.tv_sec = u64First / 1000000000;
++ tv.tv_usec = (u64First % 1000000000) / 1000;
++ callout_reset(&pTimer->Callout, tvtohz(&tv), rtTimerNetBSDCallback, pTimer);
++
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTTimerStop(PRTTIMER pTimer)
++{
++ if (!rtTimerIsValid(pTimer))
++ return VERR_INVALID_HANDLE;
++ if (pTimer->fSuspended)
++ return VERR_TIMER_SUSPENDED;
++
++ /*
++ * Suspend the timer.
++ */
++ pTimer->fSuspended = true;
++ callout_stop(&pTimer->Callout);
++
++ return VINF_SUCCESS;
++}
++
++
++RTDECL(int) RTTimerChangeInterval(PRTTIMER pTimer, uint64_t u64NanoInterval)
++{
++ if (!rtTimerIsValid(pTimer))
++ return VERR_INVALID_HANDLE;
++ return VERR_NOT_SUPPORTED;
++}
++
++
++/**
++ * smp_rendezvous action callback.
++ *
++ * This will perform the timer callback if we're on the right CPU.
++ *
++ * @param pvTimer The timer.
++ */
++static void rtTimerNetBSDIpiAction(void *pvTimer)
++{
++ PRTTIMER pTimer = (PRTTIMER)pvTimer;
++ if ( pTimer->iCpu == RTTIMER_FLAGS_CPU_MASK
++ || (u_int)pTimer->iCpu == curcpu)
++ pTimer->pfnTimer(pTimer, pTimer->pvUser, pTimer->iTick);
++}
++
++
++static void rtTimerNetBSDCallback(void *pvTimer)
++{
++ PRTTIMER pTimer = (PRTTIMER)pvTimer;
++
++ /* calculate and set the next timeout */
++ pTimer->iTick++;
++ if (!pTimer->u64NanoInterval)
++ {
++ pTimer->fSuspended = true;
++ callout_stop(&pTimer->Callout);
++ }
++ else
++ {
++ struct timeval tv;
++ const uint64_t u64NanoTS = RTTimeNanoTS();
++ pTimer->u64NextTS = pTimer->u64StartTS + pTimer->iTick * pTimer->u64NanoInterval;
++ if (pTimer->u64NextTS < u64NanoTS)
++ pTimer->u64NextTS = u64NanoTS + RTTimerGetSystemGranularity() / 2;
++
++ tv.tv_sec = pTimer->u64NextTS / 1000000000;
++ tv.tv_usec = (pTimer->u64NextTS % 1000000000) / 1000;
++ callout_reset(&pTimer->Callout, tvtohz(&tv), rtTimerNetBSDCallback, pTimer);
++ }
++
++ /* callback */
++ if ( !pTimer->fSpecificCpu
++ || pTimer->iCpu == curcpu)
++ pTimer->pfnTimer(pTimer, pTimer->pvUser, pTimer->iTick);
++ else
++ smp_rendezvous(NULL, rtTimerNetBSDIpiAction, NULL, pvTimer);
++}
++
++
++RTDECL(uint32_t) RTTimerGetSystemGranularity(void)
++{
++ return 1000000000 / hz; /* ns */
++}
++
++
++RTDECL(int) RTTimerRequestSystemGranularity(uint32_t u32Request, uint32_t *pu32Granted)
++{
++ return VERR_NOT_SUPPORTED;
++}
++
++
++RTDECL(int) RTTimerReleaseSystemGranularity(uint32_t u32Granted)
++{
++ return VERR_NOT_SUPPORTED;
++}
++
++
++RTDECL(bool) RTTimerCanDoHighResolution(void)
++{
++ return false;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_init.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_init.cpp
new file mode 100644
index 0000000..26a01bd
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_init.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/init.cpp.orig 2016-03-04 19:30:02.000000000 +0000
++++ src/VBox/Runtime/r3/init.cpp
+@@ -143,7 +143,7 @@ RTDATADECL(bool) g_fRTAlignmentChecks =
+
+
+ #if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_HAIKU) \
+- || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS) /** @todo add host init hooks everywhere. */
++ || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS) || defined(RT_OS_NETBSD) /** @todo add host init hooks everywhere. */
+ /* Stubs */
+ DECLHIDDEN(int) rtR3InitNativeFirst(uint32_t fFlags) { return VINF_SUCCESS; }
+ DECLHIDDEN(int) rtR3InitNativeFinal(uint32_t fFlags) { return VINF_SUCCESS; }
+@@ -663,4 +663,3 @@ RTR3DECL(void) RTR3Term(void)
+ {
+ }
+ #endif
+-
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_fileaio-netbsd.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_fileaio-netbsd.cpp
new file mode 100644
index 0000000..a78acb9
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_fileaio-netbsd.cpp
@@ -0,0 +1,676 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/netbsd/fileaio-netbsd.cpp.orig 2016-07-07 07:08:47.041585007 +0000
++++ src/VBox/Runtime/r3/netbsd/fileaio-netbsd.cpp
+@@ -0,0 +1,671 @@
++/* fileaio-netbsd.cpp $ */
++/** @file
++ * IPRT - File async I/O, native implementation for the NetBSD host platform.
++ */
++
++/*
++ * Copyright (C) 2006-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#define LOG_GROUP RTLOGGROUP_FILE
++#include <iprt/asm.h>
++#include <iprt/file.h>
++#include <iprt/mem.h>
++#include <iprt/assert.h>
++#include <iprt/string.h>
++#include <iprt/err.h>
++#include <iprt/log.h>
++#include <iprt/thread.h>
++#include "internal/fileaio.h"
++
++#include <sys/types.h>
++#include <sys/event.h>
++#include <sys/time.h>
++#include <sys/sysctl.h>
++#include <aio.h>
++#include <errno.h>
++#include <unistd.h>
++#include <fcntl.h>
++
++
++/*********************************************************************************************************************************
++* Structures and Typedefs *
++*********************************************************************************************************************************/
++/**
++ * Async I/O completion context state.
++ */
++typedef struct RTFILEAIOCTXINTERNAL
++{
++ /** Handle to the kernel queue. */
++ int iKQueue;
++ /** Current number of requests active on this context. */
++ volatile int32_t cRequests;
++ /** The ID of the thread which is currently waiting for requests. */
++ volatile RTTHREAD hThreadWait;
++ /** Flag whether the thread was woken up. */
++ volatile bool fWokenUp;
++ /** Flag whether the thread is currently waiting in the syscall. */
++ volatile bool fWaiting;
++ /** Flags given during creation. */
++ uint32_t fFlags;
++ /** Magic value (RTFILEAIOCTX_MAGIC). */
++ uint32_t u32Magic;
++} RTFILEAIOCTXINTERNAL;
++/** Pointer to an internal context structure. */
++typedef RTFILEAIOCTXINTERNAL *PRTFILEAIOCTXINTERNAL;
++
++/**
++ * Async I/O request state.
++ */
++typedef struct RTFILEAIOREQINTERNAL
++{
++ /** The aio control block. Must be the FIRST
++ * element. */
++ struct aiocb AioCB;
++ /** Current state the request is in. */
++ RTFILEAIOREQSTATE enmState;
++ /** Flag whether this is a flush request. */
++ bool fFlush;
++ /** Opaque user data. */
++ void *pvUser;
++ /** Completion context we are assigned to. */
++ PRTFILEAIOCTXINTERNAL pCtxInt;
++ /** Number of bytes actually transferred. */
++ size_t cbTransfered;
++ /** Status code. */
++ int Rc;
++ /** Magic value (RTFILEAIOREQ_MAGIC). */
++ uint32_t u32Magic;
++} RTFILEAIOREQINTERNAL;
++/** Pointer to an internal request structure. */
++typedef RTFILEAIOREQINTERNAL *PRTFILEAIOREQINTERNAL;
++
++
++/*********************************************************************************************************************************
++* Defined Constants And Macros *
++*********************************************************************************************************************************/
++/** The max number of events to get in one call. */
++#define AIO_MAXIMUM_REQUESTS_PER_CONTEXT 64
++
++RTR3DECL(int) RTFileAioGetLimits(PRTFILEAIOLIMITS pAioLimits)
++{
++ int rcBSD = 0;
++ AssertPtrReturn(pAioLimits, VERR_INVALID_POINTER);
++
++ /*
++ * The AIO API is implemented in a kernel module which is not
++ * loaded by default.
++ * If it is loaded there are additional sysctl parameters.
++ */
++ int cReqsOutstandingMax = 0;
++ size_t cbParameter = sizeof(int);
++
++ rcBSD = sysctlbyname("vfs.aio.max_aio_per_proc", /* name */
++ &cReqsOutstandingMax, /* Where to store the old value. */
++ &cbParameter, /* Size of the memory pointed to. */
++ NULL, /* Where the new value is located. */
++ 0); /* Where the size of the new value is stored. */
++ if (rcBSD == -1)
++ {
++ /* ENOENT means the value is unknown thus the module is not loaded. */
++ if (errno == ENOENT)
++ return VERR_NOT_SUPPORTED;
++ else
++ return RTErrConvertFromErrno(errno);
++ }
++
++ pAioLimits->cReqsOutstandingMax = cReqsOutstandingMax;
++ pAioLimits->cbBufferAlignment = 0;
++
++ return VINF_SUCCESS;
++}
++
++RTR3DECL(int) RTFileAioReqCreate(PRTFILEAIOREQ phReq)
++{
++ AssertPtrReturn(phReq, VERR_INVALID_POINTER);
++
++ PRTFILEAIOREQINTERNAL pReqInt = (PRTFILEAIOREQINTERNAL)RTMemAllocZ(sizeof(RTFILEAIOREQINTERNAL));
++ if (RT_UNLIKELY(!pReqInt))
++ return VERR_NO_MEMORY;
++
++ /* Ininitialize static parts. */
++ pReqInt->AioCB.aio_sigevent.sigev_notify = SIGEV_KEVENT;
++ pReqInt->AioCB.aio_sigevent.sigev_value.sival_ptr = pReqInt;
++ pReqInt->pCtxInt = NULL;
++ pReqInt->u32Magic = RTFILEAIOREQ_MAGIC;
++ RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
++
++ *phReq = (RTFILEAIOREQ)pReqInt;
++
++ return VINF_SUCCESS;
++}
++
++RTDECL(int) RTFileAioReqDestroy(RTFILEAIOREQ hReq)
++{
++ /*
++ * Validate the handle and ignore nil.
++ */
++ if (hReq == NIL_RTFILEAIOREQ)
++ return VINF_SUCCESS;
++ PRTFILEAIOREQINTERNAL pReqInt = hReq;
++ RTFILEAIOREQ_VALID_RETURN(pReqInt);
++ RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
++
++ /*
++ * Trash the magic and free it.
++ */
++ ASMAtomicUoWriteU32(&pReqInt->u32Magic, ~RTFILEAIOREQ_MAGIC);
++ RTMemFree(pReqInt);
++ return VINF_SUCCESS;
++}
++
++/**
++ * Worker setting up the request.
++ */
++DECLINLINE(int) rtFileAioReqPrepareTransfer(RTFILEAIOREQ hReq, RTFILE hFile,
++ unsigned uTransferDirection,
++ RTFOFF off, void *pvBuf, size_t cbTransfer,
++ void *pvUser)
++{
++ /*
++ * Validate the input.
++ */
++ PRTFILEAIOREQINTERNAL pReqInt = hReq;
++ RTFILEAIOREQ_VALID_RETURN(pReqInt);
++ RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
++ Assert(hFile != NIL_RTFILE);
++ AssertPtr(pvBuf);
++ Assert(off >= 0);
++ Assert(cbTransfer > 0);
++
++ pReqInt->AioCB.aio_sigevent.sigev_notify = SIGEV_KEVENT;
++ pReqInt->AioCB.aio_sigevent.sigev_value.sival_ptr = pReqInt;
++ pReqInt->AioCB.aio_lio_opcode = uTransferDirection;
++ pReqInt->AioCB.aio_fildes = RTFileToNative(hFile);
++ pReqInt->AioCB.aio_offset = off;
++ pReqInt->AioCB.aio_nbytes = cbTransfer;
++ pReqInt->AioCB.aio_buf = pvBuf;
++ pReqInt->fFlush = false;
++ pReqInt->pvUser = pvUser;
++ pReqInt->pCtxInt = NULL;
++ pReqInt->Rc = VERR_FILE_AIO_IN_PROGRESS;
++ RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
++
++ return VINF_SUCCESS;
++}
++
++RTDECL(int) RTFileAioReqPrepareRead(RTFILEAIOREQ hReq, RTFILE hFile, RTFOFF off,
++ void *pvBuf, size_t cbRead, void *pvUser)
++{
++ return rtFileAioReqPrepareTransfer(hReq, hFile, LIO_READ,
++ off, pvBuf, cbRead, pvUser);
++}
++
++RTDECL(int) RTFileAioReqPrepareWrite(RTFILEAIOREQ hReq, RTFILE hFile, RTFOFF off,
++ void const *pvBuf, size_t cbWrite, void *pvUser)
++{
++ return rtFileAioReqPrepareTransfer(hReq, hFile, LIO_WRITE,
++ off, (void *)pvBuf, cbWrite, pvUser);
++}
++
++RTDECL(int) RTFileAioReqPrepareFlush(RTFILEAIOREQ hReq, RTFILE hFile, void *pvUser)
++{
++ PRTFILEAIOREQINTERNAL pReqInt = (PRTFILEAIOREQINTERNAL)hReq;
++
++ RTFILEAIOREQ_VALID_RETURN(pReqInt);
++ Assert(hFile != NIL_RTFILE);
++ RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
++
++ pReqInt->fFlush = true;
++ pReqInt->AioCB.aio_fildes = RTFileToNative(hFile);
++ pReqInt->AioCB.aio_offset = 0;
++ pReqInt->AioCB.aio_nbytes = 0;
++ pReqInt->AioCB.aio_buf = NULL;
++ pReqInt->pvUser = pvUser;
++ RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
++
++ return VINF_SUCCESS;
++}
++
++RTDECL(void *) RTFileAioReqGetUser(RTFILEAIOREQ hReq)
++{
++ PRTFILEAIOREQINTERNAL pReqInt = hReq;
++ RTFILEAIOREQ_VALID_RETURN_RC(pReqInt, NULL);
++
++ return pReqInt->pvUser;
++}
++
++RTDECL(int) RTFileAioReqCancel(RTFILEAIOREQ hReq)
++{
++ PRTFILEAIOREQINTERNAL pReqInt = hReq;
++ RTFILEAIOREQ_VALID_RETURN(pReqInt);
++ RTFILEAIOREQ_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_NOT_SUBMITTED);
++
++
++ int rcBSD = aio_cancel(pReqInt->AioCB.aio_fildes, &pReqInt->AioCB);
++
++ if (rcBSD == AIO_CANCELED)
++ {
++ /*
++ * Decrement request count because the request will never arrive at the
++ * completion port.
++ */
++ AssertMsg(VALID_PTR(pReqInt->pCtxInt),
++ ("Invalid state. Request was canceled but wasn't submitted\n"));
++
++ ASMAtomicDecS32(&pReqInt->pCtxInt->cRequests);
++ pReqInt->Rc = VERR_FILE_AIO_CANCELED;
++ RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
++ return VINF_SUCCESS;
++ }
++ else if (rcBSD == AIO_ALLDONE)
++ return VERR_FILE_AIO_COMPLETED;
++ else if (rcBSD == AIO_NOTCANCELED)
++ return VERR_FILE_AIO_IN_PROGRESS;
++ else
++ return RTErrConvertFromErrno(errno);
++}
++
++RTDECL(int) RTFileAioReqGetRC(RTFILEAIOREQ hReq, size_t *pcbTransfered)
++{
++ PRTFILEAIOREQINTERNAL pReqInt = hReq;
++ RTFILEAIOREQ_VALID_RETURN(pReqInt);
++ AssertPtrNull(pcbTransfered);
++ RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, SUBMITTED, VERR_FILE_AIO_IN_PROGRESS);
++ RTFILEAIOREQ_NOT_STATE_RETURN_RC(pReqInt, PREPARED, VERR_FILE_AIO_NOT_SUBMITTED);
++
++ if ( (RT_SUCCESS(pReqInt->Rc))
++ && (pcbTransfered))
++ *pcbTransfered = pReqInt->cbTransfered;
++
++ return pReqInt->Rc;
++}
++
++RTDECL(int) RTFileAioCtxCreate(PRTFILEAIOCTX phAioCtx, uint32_t cAioReqsMax,
++ uint32_t fFlags)
++{
++ int rc = VINF_SUCCESS;
++ PRTFILEAIOCTXINTERNAL pCtxInt;
++ AssertPtrReturn(phAioCtx, VERR_INVALID_POINTER);
++ AssertReturn(!(fFlags & ~RTFILEAIOCTX_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER);
++
++ pCtxInt = (PRTFILEAIOCTXINTERNAL)RTMemAllocZ(sizeof(RTFILEAIOCTXINTERNAL));
++ if (RT_UNLIKELY(!pCtxInt))
++ return VERR_NO_MEMORY;
++
++ /* Init the event handle. */
++ pCtxInt->iKQueue = kqueue();
++ if (RT_LIKELY(pCtxInt->iKQueue > 0))
++ {
++ pCtxInt->fFlags = fFlags;
++ pCtxInt->u32Magic = RTFILEAIOCTX_MAGIC;
++ *phAioCtx = (RTFILEAIOCTX)pCtxInt;
++ }
++ else
++ {
++ RTMemFree(pCtxInt);
++ rc = RTErrConvertFromErrno(errno);
++ }
++
++ return rc;
++}
++
++RTDECL(int) RTFileAioCtxDestroy(RTFILEAIOCTX hAioCtx)
++{
++ /* Validate the handle and ignore nil. */
++ if (hAioCtx == NIL_RTFILEAIOCTX)
++ return VINF_SUCCESS;
++ PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
++ RTFILEAIOCTX_VALID_RETURN(pCtxInt);
++
++ /* Cannot destroy a busy context. */
++ if (RT_UNLIKELY(pCtxInt->cRequests))
++ return VERR_FILE_AIO_BUSY;
++
++ close(pCtxInt->iKQueue);
++ ASMAtomicUoWriteU32(&pCtxInt->u32Magic, RTFILEAIOCTX_MAGIC_DEAD);
++ RTMemFree(pCtxInt);
++
++ return VINF_SUCCESS;
++}
++
++RTDECL(uint32_t) RTFileAioCtxGetMaxReqCount(RTFILEAIOCTX hAioCtx)
++{
++ return RTFILEAIO_UNLIMITED_REQS;
++}
++
++RTDECL(int) RTFileAioCtxAssociateWithFile(RTFILEAIOCTX hAioCtx, RTFILE hFile)
++{
++ return VINF_SUCCESS;
++}
++
++RTDECL(int) RTFileAioCtxSubmit(RTFILEAIOCTX hAioCtx, PRTFILEAIOREQ pahReqs, size_t cReqs)
++{
++ /*
++ * Parameter validation.
++ */
++ int rc = VINF_SUCCESS;
++ PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
++ RTFILEAIOCTX_VALID_RETURN(pCtxInt);
++ AssertReturn(cReqs > 0, VERR_INVALID_PARAMETER);
++ AssertPtrReturn(pahReqs, VERR_INVALID_POINTER);
++
++ do
++ {
++ int rcBSD = 0;
++ size_t cReqsSubmit = 0;
++ size_t i = 0;
++ PRTFILEAIOREQINTERNAL pReqInt;
++
++ while ( (i < cReqs)
++ && (i < AIO_LISTIO_MAX))
++ {
++ pReqInt = pahReqs[i];
++ if (RTFILEAIOREQ_IS_NOT_VALID(pReqInt))
++ {
++ /* Undo everything and stop submitting. */
++ for (size_t iUndo = 0; iUndo < i; iUndo++)
++ {
++ pReqInt = pahReqs[iUndo];
++ RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
++ pReqInt->pCtxInt = NULL;
++ pReqInt->AioCB.aio_sigevent.sigev_notify_kqueue = 0;
++ }
++ rc = VERR_INVALID_HANDLE;
++ break;
++ }
++
++ pReqInt->AioCB.aio_sigevent.sigev_notify_kqueue = pCtxInt->iKQueue;
++ pReqInt->pCtxInt = pCtxInt;
++ RTFILEAIOREQ_SET_STATE(pReqInt, SUBMITTED);
++
++ if (pReqInt->fFlush)
++ break;
++
++ cReqsSubmit++;
++ i++;
++ }
++
++ if (cReqsSubmit)
++ {
++ rcBSD = lio_listio(LIO_NOWAIT, (struct aiocb **)pahReqs, cReqsSubmit, NULL);
++ if (RT_UNLIKELY(rcBSD < 0))
++ {
++ if (errno == EAGAIN)
++ rc = VERR_FILE_AIO_INSUFFICIENT_RESSOURCES;
++ else
++ rc = RTErrConvertFromErrno(errno);
++
++ /* Check which requests got actually submitted and which not. */
++ for (i = 0; i < cReqs; i++)
++ {
++ pReqInt = pahReqs[i];
++ rcBSD = aio_error(&pReqInt->AioCB);
++ if ( rcBSD == -1
++ && errno == EINVAL)
++ {
++ /* Was not submitted. */
++ RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
++ pReqInt->pCtxInt = NULL;
++ }
++ else if (rcBSD != EINPROGRESS)
++ {
++ /* The request encountered an error. */
++ RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
++ pReqInt->Rc = RTErrConvertFromErrno(rcBSD);
++ pReqInt->pCtxInt = NULL;
++ pReqInt->cbTransfered = 0;
++ }
++ }
++ break;
++ }
++
++ ASMAtomicAddS32(&pCtxInt->cRequests, cReqsSubmit);
++ cReqs -= cReqsSubmit;
++ pahReqs += cReqsSubmit;
++ }
++
++ /* Check if we have a flush request now. */
++ if (cReqs && RT_SUCCESS_NP(rc))
++ {
++ pReqInt = pahReqs[0];
++ RTFILEAIOREQ_VALID_RETURN(pReqInt);
++
++ if (pReqInt->fFlush)
++ {
++ /*
++ * lio_listio does not work with flush requests so
++ * we have to use aio_fsync directly.
++ */
++ rcBSD = aio_fsync(O_SYNC, &pReqInt->AioCB);
++ if (RT_UNLIKELY(rcBSD < 0))
++ {
++ if (rcBSD == EAGAIN)
++ {
++ /* Was not submitted. */
++ RTFILEAIOREQ_SET_STATE(pReqInt, PREPARED);
++ pReqInt->pCtxInt = NULL;
++ return VERR_FILE_AIO_INSUFFICIENT_RESSOURCES;
++ }
++ else
++ {
++ RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
++ pReqInt->Rc = RTErrConvertFromErrno(errno);
++ pReqInt->cbTransfered = 0;
++ return pReqInt->Rc;
++ }
++ }
++
++ ASMAtomicIncS32(&pCtxInt->cRequests);
++ cReqs--;
++ pahReqs++;
++ }
++ }
++ } while (cReqs);
++
++ return rc;
++}
++
++RTDECL(int) RTFileAioCtxWait(RTFILEAIOCTX hAioCtx, size_t cMinReqs, RTMSINTERVAL cMillies,
++ PRTFILEAIOREQ pahReqs, size_t cReqs, uint32_t *pcReqs)
++{
++ int rc = VINF_SUCCESS;
++ int cRequestsCompleted = 0;
++
++ /*
++ * Validate the parameters, making sure to always set pcReqs.
++ */
++ AssertPtrReturn(pcReqs, VERR_INVALID_POINTER);
++ *pcReqs = 0; /* always set */
++ PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
++ RTFILEAIOCTX_VALID_RETURN(pCtxInt);
++ AssertPtrReturn(pahReqs, VERR_INVALID_POINTER);
++ AssertReturn(cReqs != 0, VERR_INVALID_PARAMETER);
++ AssertReturn(cReqs >= cMinReqs, VERR_OUT_OF_RANGE);
++
++ if ( RT_UNLIKELY(ASMAtomicReadS32(&pCtxInt->cRequests) == 0)
++ && !(pCtxInt->fFlags & RTFILEAIOCTX_FLAGS_WAIT_WITHOUT_PENDING_REQUESTS))
++ return VERR_FILE_AIO_NO_REQUEST;
++
++ /*
++ * Convert the timeout if specified.
++ */
++ struct timespec *pTimeout = NULL;
++ struct timespec Timeout = {0,0};
++ uint64_t StartNanoTS = 0;
++ if (cMillies != RT_INDEFINITE_WAIT)
++ {
++ Timeout.tv_sec = cMillies / 1000;
++ Timeout.tv_nsec = cMillies % 1000 * 1000000;
++ pTimeout = &Timeout;
++ StartNanoTS = RTTimeNanoTS();
++ }
++
++ /* Wait for at least one. */
++ if (!cMinReqs)
++ cMinReqs = 1;
++
++ /* For the wakeup call. */
++ Assert(pCtxInt->hThreadWait == NIL_RTTHREAD);
++ ASMAtomicWriteHandle(&pCtxInt->hThreadWait, RTThreadSelf());
++
++ while ( cMinReqs
++ && RT_SUCCESS_NP(rc))
++ {
++ struct kevent aKEvents[AIO_MAXIMUM_REQUESTS_PER_CONTEXT];
++ int cRequestsToWait = cMinReqs < AIO_MAXIMUM_REQUESTS_PER_CONTEXT ? cReqs : AIO_MAXIMUM_REQUESTS_PER_CONTEXT;
++ int rcBSD;
++ uint64_t StartTime;
++
++ ASMAtomicXchgBool(&pCtxInt->fWaiting, true);
++ rcBSD = kevent(pCtxInt->iKQueue, NULL, 0, aKEvents, cRequestsToWait, pTimeout);
++ ASMAtomicXchgBool(&pCtxInt->fWaiting, false);
++
++ if (RT_UNLIKELY(rcBSD < 0))
++ {
++ rc = RTErrConvertFromErrno(errno);
++ break;
++ }
++
++ uint32_t const cDone = rcBSD;
++
++ /* Process received events. */
++ for (uint32_t i = 0; i < cDone; i++)
++ {
++ PRTFILEAIOREQINTERNAL pReqInt = (PRTFILEAIOREQINTERNAL)aKEvents[i].udata;
++ AssertPtr(pReqInt);
++ Assert(pReqInt->u32Magic == RTFILEAIOREQ_MAGIC);
++
++ /*
++ * Retrieve the status code here already because the
++ * user may omit the RTFileAioReqGetRC() call and
++ * we will leak kernel resources then.
++ * This will result in errors during submission
++ * of other requests as soon as the max_aio_queue_per_proc
++ * limit is reached.
++ */
++ int cbTransfered = aio_return(&pReqInt->AioCB);
++
++ if (cbTransfered < 0)
++ {
++ pReqInt->Rc = RTErrConvertFromErrno(cbTransfered);
++ pReqInt->cbTransfered = 0;
++ }
++ else
++ {
++ pReqInt->Rc = VINF_SUCCESS;
++ pReqInt->cbTransfered = cbTransfered;
++ }
++ RTFILEAIOREQ_SET_STATE(pReqInt, COMPLETED);
++ pahReqs[cRequestsCompleted++] = (RTFILEAIOREQ)pReqInt;
++ }
++
++ /*
++ * Done Yet? If not advance and try again.
++ */
++ if (cDone >= cMinReqs)
++ break;
++ cMinReqs -= cDone;
++ cReqs -= cDone;
++
++ if (cMillies != RT_INDEFINITE_WAIT)
++ {
++ /* The API doesn't return ETIMEDOUT, so we have to fix that ourselves. */
++ uint64_t NanoTS = RTTimeNanoTS();
++ uint64_t cMilliesElapsed = (NanoTS - StartNanoTS) / 1000000;
++ if (cMilliesElapsed >= cMillies)
++ {
++ rc = VERR_TIMEOUT;
++ break;
++ }
++
++ /* The syscall supposedly updates it, but we're paranoid. :-) */
++ Timeout.tv_sec = (cMillies - (RTMSINTERVAL)cMilliesElapsed) / 1000;
++ Timeout.tv_nsec = (cMillies - (RTMSINTERVAL)cMilliesElapsed) % 1000 * 1000000;
++ }
++ }
++
++ /*
++ * Update the context state and set the return value.
++ */
++ *pcReqs = cRequestsCompleted;
++ ASMAtomicSubS32(&pCtxInt->cRequests, cRequestsCompleted);
++ Assert(pCtxInt->hThreadWait == RTThreadSelf());
++ ASMAtomicWriteHandle(&pCtxInt->hThreadWait, NIL_RTTHREAD);
++
++ /*
++ * Clear the wakeup flag and set rc.
++ */
++ if ( pCtxInt->fWokenUp
++ && RT_SUCCESS(rc))
++ {
++ ASMAtomicXchgBool(&pCtxInt->fWokenUp, false);
++ rc = VERR_INTERRUPTED;
++ }
++
++ return rc;
++}
++
++RTDECL(int) RTFileAioCtxWakeup(RTFILEAIOCTX hAioCtx)
++{
++ PRTFILEAIOCTXINTERNAL pCtxInt = hAioCtx;
++ RTFILEAIOCTX_VALID_RETURN(pCtxInt);
++
++ /** @todo r=bird: Define the protocol for how to resume work after calling
++ * this function. */
++
++ bool fWokenUp = ASMAtomicXchgBool(&pCtxInt->fWokenUp, true);
++
++ /*
++ * Read the thread handle before the status flag.
++ * If we read the handle after the flag we might
++ * end up with an invalid handle because the thread
++ * waiting in RTFileAioCtxWakeup() might get scheduled
++ * before we read the flag and returns.
++ * We can ensure that the handle is valid if fWaiting is true
++ * when reading the handle before the status flag.
++ */
++ RTTHREAD hThread;
++ ASMAtomicReadHandle(&pCtxInt->hThreadWait, &hThread);
++ bool fWaiting = ASMAtomicReadBool(&pCtxInt->fWaiting);
++ if ( !fWokenUp
++ && fWaiting)
++ {
++ /*
++ * If a thread waits the handle must be valid.
++ * It is possible that the thread returns from
++ * kevent() before the signal is send.
++ * This is no problem because we already set fWokenUp
++ * to true which will let the thread return VERR_INTERRUPTED
++ * and the next call to RTFileAioCtxWait() will not
++ * return VERR_INTERRUPTED because signals are not saved
++ * and will simply vanish if the destination thread can't
++ * receive it.
++ */
++ Assert(hThread != NIL_RTTHREAD);
++ RTThreadPoke(hThread);
++ }
++
++ return VINF_SUCCESS;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_mp-netbsd.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_mp-netbsd.cpp
new file mode 100644
index 0000000..946272c
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_mp-netbsd.cpp
@@ -0,0 +1,205 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/netbsd/mp-netbsd.cpp.orig 2016-07-07 07:08:47.050526272 +0000
++++ src/VBox/Runtime/r3/netbsd/mp-netbsd.cpp
+@@ -0,0 +1,200 @@
++/* mp-netbsd.cpp $ */
++/** @file
++ * IPRT - Multiprocessor, NetBSD.
++ */
++
++/*
++ * Copyright (C) 2008-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#define LOG_GROUP RTLOGGROUP_SYSTEM
++#include <unistd.h>
++#include <stdio.h>
++#include <errno.h>
++#include <sys/sysctl.h>
++
++#include <iprt/mp.h>
++#include <iprt/cpuset.h>
++#include <iprt/assert.h>
++#include <iprt/string.h>
++#include <iprt/alloc.h>
++#include <iprt/log.h>
++#include <iprt/once.h>
++#include <iprt/critsect.h>
++
++
++/**
++ * Internal worker that determines the max possible CPU count.
++ *
++ * @returns Max cpus.
++ */
++static RTCPUID rtMpNetBsdMaxCpus(void)
++{
++ int aiMib[2];
++ aiMib[0] = CTL_HW;
++ aiMib[1] = HW_NCPU;
++ int cCpus = -1;
++ size_t cb = sizeof(cCpus);
++ int rc = sysctl(aiMib, RT_ELEMENTS(aiMib), &cCpus, &cb, NULL, 0);
++ if (rc != -1 && cCpus >= 1)
++ return cCpus;
++ AssertFailed();
++ return 1;
++}
++
++
++RTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
++{
++ return idCpu < RTCPUSET_MAX_CPUS && idCpu < rtMpNetBsdMaxCpus() ? idCpu : -1;
++}
++
++
++RTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
++{
++ return (unsigned)iCpu < rtMpNetBsdMaxCpus() ? iCpu : NIL_RTCPUID;
++}
++
++
++RTDECL(RTCPUID) RTMpGetMaxCpuId(void)
++{
++ return rtMpNetBsdMaxCpus() - 1;
++}
++
++
++RTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
++{
++ /*
++ * NetBSD doesn't support CPU hotplugging so every CPU which appears
++ * in the tree is also online.
++ */
++ char szName[40];
++ RTStrPrintf(szName, sizeof(szName), "dev.cpu.%d.%%driver", (int)idCpu);
++
++ char szDriver[10];
++ size_t cbDriver = sizeof(szDriver);
++ RT_ZERO(szDriver); /* this shouldn't be necessary. */
++ int rcBsd = sysctlbyname(szName, szDriver, &cbDriver, NULL, 0);
++ if (rcBsd == 0)
++ return true;
++
++ return false;
++}
++
++
++RTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
++{
++ return idCpu != NIL_RTCPUID
++ && idCpu < rtMpNetBsdMaxCpus();
++}
++
++
++RTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
++{
++ RTCpuSetEmpty(pSet);
++ RTCPUID cMax = rtMpNetBsdMaxCpus();
++ for (RTCPUID idCpu = 0; idCpu < cMax; idCpu++)
++ if (RTMpIsCpuPossible(idCpu))
++ RTCpuSetAdd(pSet, idCpu);
++ return pSet;
++}
++
++
++RTDECL(RTCPUID) RTMpGetCount(void)
++{
++ return rtMpNetBsdMaxCpus();
++}
++
++
++RTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
++{
++ RTCpuSetEmpty(pSet);
++ RTCPUID cMax = rtMpNetBsdMaxCpus();
++ for (RTCPUID idCpu = 0; idCpu < cMax; idCpu++)
++ if (RTMpIsCpuOnline(idCpu))
++ RTCpuSetAdd(pSet, idCpu);
++ return pSet;
++}
++
++
++RTDECL(RTCPUID) RTMpGetOnlineCount(void)
++{
++ /*
++ * NetBSD has sysconf.
++ */
++ return sysconf(_SC_NPROCESSORS_ONLN);
++}
++
++
++RTDECL(uint32_t) RTMpGetCurFrequency(RTCPUID idCpu)
++{
++ int uFreqCurr = 0;
++ size_t cbParameter = sizeof(uFreqCurr);
++
++ if (!RTMpIsCpuOnline(idCpu))
++ return 0;
++
++ /* CPU's have a common frequency. */
++ int rc = sysctlbyname("dev.cpu.0.freq", &uFreqCurr, &cbParameter, NULL, 0);
++ if (rc)
++ return 0;
++
++ return (uint32_t)uFreqCurr;
++}
++
++
++RTDECL(uint32_t) RTMpGetMaxFrequency(RTCPUID idCpu)
++{
++ char szFreqLevels[20]; /* Should be enough to get the highest level which is always the first. */
++ size_t cbFreqLevels = sizeof(szFreqLevels);
++
++ if (!RTMpIsCpuOnline(idCpu))
++ return 0;
++
++ memset(szFreqLevels, 0, sizeof(szFreqLevels));
++
++ /*
++ * CPU 0 has the freq levels entry. ENOMEM is ok as we don't need all supported
++ * levels but only the first one.
++ */
++ int rc = sysctlbyname("dev.cpu.0.freq_levels", szFreqLevels, &cbFreqLevels, NULL, 0);
++ if ( (rc && (errno != ENOMEM))
++ || (cbFreqLevels == 0))
++ return 0;
++
++ /* Clear everything starting from the '/' */
++ unsigned i = 0;
++
++ do
++ {
++ if (szFreqLevels[i] == '/')
++ {
++ memset(&szFreqLevels[i], 0, sizeof(szFreqLevels) - i);
++ break;
++ }
++ i++;
++ } while (i < sizeof(szFreqLevels));
++
++ /* Returns 0 on failure. */
++ return RTStrToUInt32(szFreqLevels);
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_rtProcInitExePath-netbsd.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_rtProcInitExePath-netbsd.cpp
new file mode 100644
index 0000000..4ca53cc
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_rtProcInitExePath-netbsd.cpp
@@ -0,0 +1,77 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/netbsd/rtProcInitExePath-netbsd.cpp.orig 2016-07-07 07:08:47.060017160 +0000
++++ src/VBox/Runtime/r3/netbsd/rtProcInitExePath-netbsd.cpp
+@@ -0,0 +1,72 @@
++/* rtProcInitExePath-netbsd.cpp $ */
++/** @file
++ * IPRT - rtProcInitName, NetBSD.
++ */
++
++/*
++ * Copyright (C) 2006-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#define LOG_GROUP RTLOGGROUP_PROCESS
++#include <sys/param.h>
++#include <sys/sysctl.h>
++#include <unistd.h>
++#include <errno.h>
++#include <dlfcn.h>
++#include <link.h>
++
++#include <iprt/string.h>
++#include <iprt/assert.h>
++#include <iprt/err.h>
++#include <iprt/path.h>
++#include "internal/process.h"
++#include "internal/path.h"
++
++
++DECLHIDDEN(int) rtProcInitExePath(char *pszPath, size_t cchPath)
++{
++ int aiName[4];
++ aiName[0] = CTL_KERN;
++ aiName[1] = KERN_PROC_ARGS;
++ aiName[2] = -1; /* Shorthand for the current process. */
++ aiName[3] = KERN_PROC_PATHNAME;
++
++ size_t cchExePath = cchPath;
++ if (sysctl(aiName, RT_ELEMENTS(aiName), pszPath, &cchExePath, NULL, 0) == 0)
++ {
++ const char *pszTmp;
++ int rc = rtPathFromNative(&pszTmp, pszPath, NULL);
++ AssertMsgRCReturn(rc, ("rc=%Rrc pszPath=\"%s\"\nhex: %.*Rhxs\n", rc, pszPath, cchExePath, pszPath), rc);
++ if (pszTmp != pszPath)
++ {
++ rc = RTStrCopy(pszPath, cchPath, pszTmp);
++ rtPathFreeIprt(pszTmp, pszPath);
++ }
++ return rc;
++ }
++
++ int rc = RTErrConvertFromErrno(errno);
++ AssertMsgFailed(("rc=%Rrc errno=%d cchExePath=%d\n", rc, errno, cchExePath));
++ return rc;
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_systemmem-netbsd.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_systemmem-netbsd.cpp
new file mode 100644
index 0000000..b2b4392
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_netbsd_systemmem-netbsd.cpp
@@ -0,0 +1,79 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/netbsd/systemmem-netbsd.cpp.orig 2016-07-07 07:08:47.069137512 +0000
++++ src/VBox/Runtime/r3/netbsd/systemmem-netbsd.cpp
+@@ -0,0 +1,74 @@
++/* systemmem-netbsd.cpp $ */
++/** @file
++ * IPRT - RTSystemQueryTotalRam, NetBSD ring-3.
++ */
++
++/*
++ * Copyright (C) 2012-2015 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.
++ */
++
++
++/*********************************************************************************************************************************
++* Header Files *
++*********************************************************************************************************************************/
++#include <iprt/system.h>
++#include "internal/iprt.h"
++
++#include <iprt/err.h>
++#include <iprt/assert.h>
++#include <iprt/string.h>
++
++#include <sys/types.h>
++#include <sys/sysctl.h>
++#include <errno.h>
++
++
++RTDECL(int) RTSystemQueryTotalRam(uint64_t *pcb)
++{
++ int rc = VINF_SUCCESS;
++ u_long cbMemPhys = 0;
++ size_t cbParameter = sizeof(cbMemPhys);
++
++ AssertPtrReturn(pcb, VERR_INVALID_POINTER);
++
++ if (!sysctlbyname("hw.physmem64", &cbMemPhys, &cbParameter, NULL, 0))
++ {
++ *pcb = cbMemPhys;
++ return VINF_SUCCESS;
++ }
++ return RTErrConvertFromErrno(errno);
++}
++
++
++RTDECL(int) RTSystemQueryAvailableRam(uint64_t *pcb)
++{
++ int rc = VINF_SUCCESS;
++ u_long cbMemPhys = 0;
++ size_t cbParameter = sizeof(cbMemPhys);
++
++ AssertPtrReturn(pcb, VERR_INVALID_POINTER);
++
++ if (!sysctlbyname("hw.usermem64", &cbMemPhys, &cbParameter, NULL, 0))
++ {
++ *pcb = cbMemPhys;
++ return VINF_SUCCESS;
++ }
++ return RTErrConvertFromErrno(errno);
++}
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fileaio-posix.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fileaio-posix.cpp
new file mode 100644
index 0000000..0fb1cfe
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fileaio-posix.cpp
@@ -0,0 +1,59 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/posix/fileaio-posix.cpp.orig 2016-03-04 19:30:03.000000000 +0000
++++ src/VBox/Runtime/r3/posix/fileaio-posix.cpp
+@@ -40,11 +40,11 @@
+ #include <iprt/semaphore.h>
+ #include "internal/fileaio.h"
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <sys/types.h>
+ # include <sys/sysctl.h> /* for sysctlbyname */
+ #endif
+-#if defined(RT_OS_FREEBSD)
++#if defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <fcntl.h> /* O_SYNC */
+ #endif
+ #include <aio.h>
+@@ -316,7 +316,7 @@ RTR3DECL(int) RTFileAioGetLimits(PRTFILE
+
+ pAioLimits->cReqsOutstandingMax = cReqsOutstandingMax;
+ pAioLimits->cbBufferAlignment = 0;
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /*
+ * The AIO API is implemented in a kernel module which is not
+ * loaded by default.
+@@ -710,7 +710,7 @@ RTDECL(int) RTFileAioCtxSubmit(RTFILEAIO
+ {
+ cReqsSubmitted--;
+
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ if (errno == EINVAL)
+ #else
+ if (rcPosix == EINVAL)
+@@ -729,7 +729,7 @@ RTDECL(int) RTFileAioCtxSubmit(RTFILEAIO
+ * glibc returns the error code which would be in errno but Apple returns
+ * -1 and sets errno to the appropriate value
+ */
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ Assert(rcPosix == -1);
+ pReqInt->Rc = RTErrConvertFromErrno(errno);
+ #elif defined(RT_OS_LINUX)
+@@ -957,7 +957,7 @@ RTDECL(int) RTFileAioCtxWait(RTFILEAIOCT
+ }
+ else
+ {
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ pReq->Rc = RTErrConvertFromErrno(errno);
+ #else
+ pReq->Rc = RTErrConvertFromErrno(rcReq);
+@@ -1059,4 +1059,3 @@ RTDECL(int) RTFileAioCtxWakeup(RTFILEAIO
+
+ return VINF_SUCCESS;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fileio-posix.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fileio-posix.cpp
new file mode 100644
index 0000000..c4cd0a6
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fileio-posix.cpp
@@ -0,0 +1,45 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/posix/fileio-posix.cpp.orig 2016-03-04 19:30:03.000000000 +0000
++++ src/VBox/Runtime/r3/posix/fileio-posix.cpp
+@@ -48,7 +48,7 @@
+ #if defined(RT_OS_OS2) && (!defined(__INNOTEK_LIBC__) || __INNOTEK_LIBC__ < 0x006)
+ # include <io.h>
+ #endif
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <sys/disk.h>
+ #endif
+ #ifdef RT_OS_SOLARIS
+@@ -154,7 +154,7 @@ RTR3DECL(int) RTFileOpen(PRTFILE pFile,
+ if (fOpen & RTFILE_O_ASYNC_IO)
+ fOpenMode |= O_DIRECT;
+ #endif
+-#if defined(O_DIRECT) && (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD))
++#if defined(O_DIRECT) && (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)|| defined(RT_OS_NETBSD))
+ /* Disable the kernel cache. */
+ if (fOpen & RTFILE_O_NO_CACHE)
+ fOpenMode |= O_DIRECT;
+@@ -559,7 +559,7 @@ RTR3DECL(int) RTFileGetSize(RTFILE hFile
+ if ( st.st_size != 0
+ #if defined(RT_OS_SOLARIS)
+ || (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ || !S_ISCHR(st.st_mode)
+ #else
+ || !S_ISBLK(st.st_mode)
+@@ -595,7 +595,7 @@ RTR3DECL(int) RTFileGetSize(RTFILE hFile
+ if (errno == EINVAL || errno == ENOTTY)
+ return VINF_SUCCESS;
+
+-#elif defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ off_t cbMedia = 0;
+ if (!ioctl(RTFileToNative(hFile), DIOCGMEDIASIZE, &cbMedia))
+ {
+@@ -743,4 +743,3 @@ RTR3DECL(int) RTFileRename(const char *p
+ pszSrc, pszSrc, pszDst, pszDst, fRename, rc));
+ return rc;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fs-posix.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fs-posix.cpp
new file mode 100644
index 0000000..96b1928
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_fs-posix.cpp
@@ -0,0 +1,22 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/posix/fs-posix.cpp.orig 2016-03-04 19:30:03.000000000 +0000
++++ src/VBox/Runtime/r3/posix/fs-posix.cpp
+@@ -35,7 +35,7 @@
+ #ifdef RT_OS_LINUX
+ # include <mntent.h>
+ #endif
+-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # include <sys/mount.h>
+ #endif
+
+@@ -287,7 +287,7 @@ RTR3DECL(int) RTFsQueryType(const char *
+ else if (!strcmp("nfs", Stat.st_fstype))
+ *penmType = RTFSTYPE_NFS;
+
+-#elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ struct statfs statfsBuf;
+ if (!statfs(pszNativeFsPath, &statfsBuf))
+ {
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_path2-posix.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_path2-posix.cpp
new file mode 100644
index 0000000..5d02316
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_path2-posix.cpp
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/posix/path2-posix.cpp.orig 2016-03-04 19:30:03.000000000 +0000
++++ src/VBox/Runtime/r3/posix/path2-posix.cpp
+@@ -189,6 +189,7 @@ RTR3DECL(int) RTPathSetTimesEx(const cha
+ }
+ #if (defined(RT_OS_DARWIN) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050) \
+ || defined(RT_OS_FREEBSD) \
++ || defined(RT_OS_NETBSD) \
+ || defined(RT_OS_LINUX) \
+ || defined(RT_OS_OS2) /** @todo who really has lutimes? */
+ else
+@@ -287,4 +288,3 @@ RTR3DECL(int) RTPathSetOwnerEx(const cha
+ pszPath, pszPath, uid, gid, rc));
+ return rc;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_thread-posix.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_thread-posix.cpp
new file mode 100644
index 0000000..39dbc02
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_thread-posix.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/posix/thread-posix.cpp.orig 2016-03-04 19:30:04.000000000 +0000
++++ src/VBox/Runtime/r3/posix/thread-posix.cpp
+@@ -414,7 +414,7 @@ RTR3DECL(int) RTThreadGetExecutionTimeMi
+ *pUserTime = ts.ru_utime.tv_sec * 1000 + ts.ru_utime.tv_usec / 1000;
+ return VINF_SUCCESS;
+
+-#elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++#elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ /* on Linux, getrusage(RUSAGE_THREAD, ...) is available since 2.6.26 */
+ struct timespec ts;
+ int rc = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
+@@ -448,4 +448,3 @@ RTR3DECL(int) RTThreadGetExecutionTimeMi
+ return VERR_NOT_IMPLEMENTED;
+ #endif
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_thread2-posix.cpp b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_thread2-posix.cpp
new file mode 100644
index 0000000..375afaa
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Runtime_r3_posix_thread2-posix.cpp
@@ -0,0 +1,27 @@
+$NetBSD$
+
+--- src/VBox/Runtime/r3/posix/thread2-posix.cpp.orig 2016-03-04 19:30:04.000000000 +0000
++++ src/VBox/Runtime/r3/posix/thread2-posix.cpp
+@@ -62,7 +62,7 @@ RTDECL(int) RTThreadSleep(RTMSINTERVAL c
+ pthread_yield_np();
+ #elif defined(RT_OS_FREEBSD) /* void pthread_yield */
+ pthread_yield();
+-#elif defined(RT_OS_SOLARIS) || defined(RT_OS_HAIKU)
++#elif defined(RT_OS_SOLARIS) || defined(RT_OS_HAIKU) || defined(RT_OS_NETBSD)
+ sched_yield();
+ #else
+ if (!pthread_yield())
+@@ -101,7 +101,7 @@ RTDECL(int) RTThreadSleepNoLog(RTMSINTER
+ pthread_yield_np();
+ #elif defined(RT_OS_FREEBSD) /* void pthread_yield */
+ pthread_yield();
+-#elif defined(RT_OS_SOLARIS) || defined(RT_OS_HAIKU)
++#elif defined(RT_OS_SOLARIS) || defined(RT_OS_HAIKU) || defined(RT_OS_NETBSD)
+ sched_yield();
+ #else
+ if (!pthread_yield())
+@@ -144,4 +144,3 @@ RTDECL(bool) RTThreadYield(void)
+ #endif
+ return fRc;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_Storage_testcase_Makefile.kmk b/virtualbox/patches/patch-src_VBox_Storage_testcase_Makefile.kmk
new file mode 100644
index 0000000..b60b121
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_Storage_testcase_Makefile.kmk
@@ -0,0 +1,9 @@
+$NetBSD$
+
+--- src/VBox/Storage/testcase/Makefile.kmk.orig 2016-03-04 19:30:09.000000000 +0000
++++ src/VBox/Storage/testcase/Makefile.kmk
+@@ -169,4 +169,3 @@ if defined(VBOX_WITH_TESTCASES) || defin
+ endif
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_VBox_VMM_VMMR0_GMMR0.cpp b/virtualbox/patches/patch-src_VBox_VMM_VMMR0_GMMR0.cpp
new file mode 100644
index 0000000..6146523
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_VMM_VMMR0_GMMR0.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/VMM/VMMR0/GMMR0.cpp.orig 2016-03-04 19:30:11.000000000 +0000
++++ src/VBox/VMM/VMMR0/GMMR0.cpp
+@@ -809,7 +809,7 @@ GMMR0DECL(int) GMMR0Init(void)
+ else
+ SUPR0Printf("GMMR0Init: RTR0MemObjAllocPhysNC(,64K,Any) -> %d!\n", rc);
+ #else
+-# if defined(RT_OS_WINDOWS) || (defined(RT_OS_SOLARIS) && ARCH_BITS == 64) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++# if defined(RT_OS_WINDOWS) || (defined(RT_OS_SOLARIS) && ARCH_BITS == 64) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ pGMM->fLegacyAllocationMode = false;
+ # if ARCH_BITS == 32
+ /* Don't reuse possibly partial chunks because of the virtual
+@@ -5472,4 +5472,3 @@ GMMR0DECL(int) GMMR0ResetStatisticsReq(P
+
+ return GMMR0ResetStatistics(&pReq->Stats, pReq->pSession, pVM);
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_VMM_VMMR0_VMMR0.cpp b/virtualbox/patches/patch-src_VBox_VMM_VMMR0_VMMR0.cpp
new file mode 100644
index 0000000..9da86bc
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_VMM_VMMR0_VMMR0.cpp
@@ -0,0 +1,27 @@
+$NetBSD$
+
+--- src/VBox/VMM/VMMR0/VMMR0.cpp.orig 2016-03-04 19:30:11.000000000 +0000
++++ src/VBox/VMM/VMMR0/VMMR0.cpp
+@@ -122,7 +122,7 @@
+ * Internal Functions *
+ *********************************************************************************************************************************/
+ RT_C_DECLS_BEGIN
+-#if defined(RT_ARCH_X86) && (defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD))
++#if defined(RT_ARCH_X86) && (defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD))
+ extern uint64_t __udivdi3(uint64_t, uint64_t);
+ extern uint64_t __umoddi3(uint64_t, uint64_t);
+ #endif
+@@ -138,7 +138,7 @@ PFNRT g_VMMR0Deps[] =
+ {
+ (PFNRT)RTCrc32,
+ (PFNRT)RTOnce,
+-#if defined(RT_ARCH_X86) && (defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD))
++#if defined(RT_ARCH_X86) && (defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD))
+ (PFNRT)__udivdi3,
+ (PFNRT)__umoddi3,
+ #endif
+@@ -2284,4 +2284,3 @@ DECLEXPORT(void) RTCALL RTAssertMsg2Weak
+ */
+ RTAssertMsg2V(pszFormat, va);
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_VMM_VMMR3_PGMPhys.cpp b/virtualbox/patches/patch-src_VBox_VMM_VMMR3_PGMPhys.cpp
new file mode 100644
index 0000000..1e6c737
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_VMM_VMMR3_PGMPhys.cpp
@@ -0,0 +1,36 @@
+$NetBSD$
+
+--- src/VBox/VMM/VMMR3/PGMPhys.cpp.orig 2016-03-04 19:30:12.000000000 +0000
++++ src/VBox/VMM/VMMR3/PGMPhys.cpp
+@@ -926,7 +926,7 @@ static int pgmR3PhysFreePageRange(PVM pV
+ return rc;
+ }
+
+-#if HC_ARCH_BITS == 64 && (defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD))
++#if HC_ARCH_BITS == 64 && (defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD))
+
+ /**
+ * Rendezvous callback used by PGMR3ChangeMemBalloon that changes the memory balloon size
+@@ -1071,7 +1071,7 @@ static DECLCALLBACK(void) pgmR3PhysChang
+ RTMemFree(paPhysPage);
+ }
+
+-#endif /* 64-bit host && (Windows || Solaris || Linux || FreeBSD) */
++#endif /* 64-bit host && (Windows || Solaris || Linux || FreeBSD || NetBSD) */
+
+ /**
+ * Inflate or deflate a memory balloon
+@@ -1085,7 +1085,7 @@ static DECLCALLBACK(void) pgmR3PhysChang
+ VMMR3DECL(int) PGMR3PhysChangeMemBalloon(PVM pVM, bool fInflate, unsigned cPages, RTGCPHYS *paPhysPage)
+ {
+ /* This must match GMMR0Init; currently we only support memory ballooning on all 64-bit hosts except Mac OS X */
+-#if HC_ARCH_BITS == 64 && (defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD))
++#if HC_ARCH_BITS == 64 && (defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD))
+ int rc;
+
+ /* Older additions (ancient non-functioning balloon code) pass wrong physical addresses. */
+@@ -4652,4 +4652,3 @@ VMMR3DECL(int) PGMR3PhysTlbGCPhys2Ptr(PV
+ pgmUnlock(pVM);
+ return rc;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_VMM_VMMR3_VM.cpp b/virtualbox/patches/patch-src_VBox_VMM_VMMR3_VM.cpp
new file mode 100644
index 0000000..01b248f
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_VMM_VMMR3_VM.cpp
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/VMM/VMMR3/VM.cpp.orig 2016-03-04 19:30:12.000000000 +0000
++++ src/VBox/VMM/VMMR3/VM.cpp
+@@ -410,7 +410,7 @@ VMMR3DECL(int) VMR3Create(uint32_t cCp
+ "you the permission you need to access the device.");
+ # elif defined(RT_OS_WINDOWS)
+ pszError = N_("VirtualBox kernel driver is not accessible, permission problem.");
+-# else /* solaris, freebsd, ++. */
++# else /* solaris, freebsd, netbsd, ++. */
+ pszError = N_("VirtualBox kernel module is not accessible, permission problem. "
+ "If you have built VirtualBox yourself, make sure that you do "
+ "not have the vboxdrv kernel module from a different install loaded.");
+@@ -4510,4 +4510,3 @@ VMMR3DECL(int) VMR3SetPowerOffInsteadOfR
+ pVM->vm.s.fPowerOffInsteadOfReset = fPowerOffInsteadOfReset;
+ return VINF_SUCCESS;
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_VMM_VMMRC_VMMRCDeps.cpp b/virtualbox/patches/patch-src_VBox_VMM_VMMRC_VMMRCDeps.cpp
new file mode 100644
index 0000000..6a40ed3
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_VMM_VMMRC_VMMRCDeps.cpp
@@ -0,0 +1,32 @@
+$NetBSD$
+
+--- src/VBox/VMM/VMMRC/VMMRCDeps.cpp.orig 2016-03-04 19:30:13.000000000 +0000
++++ src/VBox/VMM/VMMRC/VMMRCDeps.cpp
+@@ -18,12 +18,12 @@
+ #include <iprt/crc.h>
+ #include <iprt/string.h>
+
+-#if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ RT_C_DECLS_BEGIN
+ extern uint64_t __udivdi3(uint64_t, uint64_t);
+ extern uint64_t __umoddi3(uint64_t, uint64_t);
+ RT_C_DECLS_END
+-#endif // RT_OS_SOLARIS || RT_OS_FREEBSD
++#endif // RT_OS_SOLARIS || RT_OS_FREEBSD || RT_OS_NETBSD
+
+ PFNRT g_VMMRCDeps[] =
+ {
+@@ -32,10 +32,9 @@ PFNRT g_VMMRCDeps[] =
+ (PFNRT)memchr,
+ (PFNRT)memcmp,
+ (PFNRT)RTCrc32,
+-#if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ (PFNRT)__udivdi3,
+ (PFNRT)__umoddi3,
+-#endif // RT_OS_SOLARIS || RT_OS_FREEBSD
++#endif // RT_OS_SOLARIS || RT_OS_FREEBSD || RT_OS_NETBSD
+ NULL
+ };
+-
diff --git a/virtualbox/patches/patch-src_VBox_VMM_testcase_mkdsk.sh b/virtualbox/patches/patch-src_VBox_VMM_testcase_mkdsk.sh
new file mode 100644
index 0000000..96b374c
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_VMM_testcase_mkdsk.sh
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- src/VBox/VMM/testcase/mkdsk.sh.orig 2016-03-04 19:30:15.000000000 +0000
++++ src/VBox/VMM/testcase/mkdsk.sh
+@@ -11,7 +11,7 @@
+ # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ #
+
+-if [ "x$3" == "x" ]; then
++if [ "x$3" = "x" ]; then
+
+ echo "syntax error"
+ echo "syntax: $0 imagename <size-in-KBs> <init prog> [tar files]"
diff --git a/virtualbox/patches/patch-src_VBox_VMM_testcase_tstX86-1.cpp b/virtualbox/patches/patch-src_VBox_VMM_testcase_tstX86-1.cpp
new file mode 100644
index 0000000..e8047bf
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_VMM_testcase_tstX86-1.cpp
@@ -0,0 +1,23 @@
+$NetBSD$
+
+--- src/VBox/VMM/testcase/tstX86-1.cpp.orig 2016-03-04 19:30:15.000000000 +0000
++++ src/VBox/VMM/testcase/tstX86-1.cpp
+@@ -112,6 +112,13 @@ static void sigHandler(int iSig, siginfo
+ uintptr_t uErr = ~(uintptr_t)0;
+ uintptr_t uCr2 = ~(uintptr_t)0;
+
++# elif defined(RT_ARCH_AMD64) && defined(RT_OS_NETBSD)
++ uintptr_t *puPC = (uintptr_t *)&pCtx->pc;
++ uintptr_t *puSP = (uintptr_t *)&pCtx->sp;
++ uintptr_t uTrapNo = ~(uintptr_t)0;
++ uintptr_t uErr = ~(uintptr_t)0;
++ uintptr_t uCr2 = ~(uintptr_t)0;
++
+ # elif defined(RT_ARCH_AMD64)
+ uintptr_t *puPC = (uintptr_t *)&pCtx->uc_mcontext.gregs[REG_RIP];
+ uintptr_t *puSP = (uintptr_t *)&pCtx->uc_mcontext.gregs[REG_RSP];
+@@ -267,4 +274,3 @@ int main()
+
+ return RTTestSummaryAndDestroy(hTest);
+ }
+-
diff --git a/virtualbox/patches/patch-src_VBox_ValidationKit_Makefile.kmk b/virtualbox/patches/patch-src_VBox_ValidationKit_Makefile.kmk
new file mode 100644
index 0000000..dcf28e7
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ValidationKit_Makefile.kmk
@@ -0,0 +1,45 @@
+$NetBSD$
+
+--- src/VBox/ValidationKit/Makefile.kmk.orig 2016-03-04 19:30:15.000000000 +0000
++++ src/VBox/ValidationKit/Makefile.kmk
+@@ -99,7 +99,7 @@ ifndef VBOX_WITHOUT_VALIDATIONKIT_ZIP
+ $$(filter $(PATH_STAGE)/$(INST_VALIDATIONKIT)%, $$($$(inst)_2_STAGE_TARGETS)))
+ $(call MSG_L1,Packing the Test Suite $@)
+ $(QUIET)$(RM) -f $@
+- $(foreach os, darwin freebsd linux os2 solaris win,$(foreach arch, x86 amd64 \
++ $(foreach os, darwin freebsd netbsd linux os2 solaris win,$(foreach arch, x86 amd64 \
+ ,$(if-expr defined(VBOX_WITH_VALIDATIONKIT_PACKING.$(os).$(arch))\
+ ,$(NLTAB)$(QUIET)$(REDIRECT) -C $(PATH_OUT_BASE)/$(os).$(arch)/$(KBUILD_TYPE)/ \
+ -- zip$(HOSTSUFF_EXE) -r9 $@ $(INST_VALIDATIONKIT) -x '*.pyc',)))
+@@ -114,7 +114,7 @@ ifndef VBOX_WITHOUT_VALIDATIONKIT_ZIP
+ $$(TestBoxHelper_2_STAGE_TARGETS)
+ $(call MSG_L1,Packing the TestBox Script files to $@)
+ $(QUIET)$(RM) -f $@
+- $(foreach os, darwin freebsd linux os2 solaris win,$(foreach arch, x86 amd64 \
++ $(foreach os, darwin freebsd netbsd linux os2 solaris win,$(foreach arch, x86 amd64 \
+ ,$(if-expr defined(VBOX_WITH_VALIDATIONKIT_PACKING.$(os).$(arch))\
+ ,$(NLTAB)$(QUIET)$(REDIRECT) -C $(PATH_OUT_BASE)/$(os).$(arch)/$(KBUILD_TYPE)/ \
+ -- zip$(HOSTSUFF_EXE) -r9 $@ $(INST_TESTBOXSCRIPT) -x '*.pyc',)))
+@@ -153,7 +153,7 @@ ifneq ($(KBUILD_HOST),os2)
+ endif
+
+ # Generate VBOX_PATH_VALIDATIONKIT.os.arch variables.
+-$(foreach os, darwin freebsd linux os2 solaris win,$(foreach arch, x86 amd64, \
++$(foreach os, darwin freebsd netbsd linux os2 solaris win,$(foreach arch, x86 amd64, \
+ $(eval VBOX_PATH_VALIDATIONKIT.$(os).$(arch) = $(PATH_OUT_BASE)/$(os).$(arch)/$(KBUILD_TYPE)/$(INST_VALIDATIONKIT)$(os)/$(arch)) \
+ ))
+
+@@ -179,7 +179,7 @@ $(foreach os, os2 win,$(foreach arch, x8
+ $(eval $(def_vbox_validationkit_common_files)) \
+ ))
+ TMP_SUFF_EXE=
+-$(foreach os, darwin freebsd linux solaris,$(foreach arch, x86 amd64, \
++$(foreach os, darwin freebsd netbsd linux solaris,$(foreach arch, x86 amd64, \
+ $(eval $(def_vbox_validationkit_common_files)) \
+ ))
+
+@@ -269,4 +269,3 @@ endif
+ # Alias for creating the iso.
+ .PHONY: validationkit-iso
+ validationkit-iso: $(VBOX_PATH_VALIDATIONKIT)/VBoxValidationKit.iso
+-
diff --git a/virtualbox/patches/patch-src_VBox_ValidationKit_testboxscript_testboxscript__real.py b/virtualbox/patches/patch-src_VBox_ValidationKit_testboxscript_testboxscript__real.py
new file mode 100644
index 0000000..e7a715e
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ValidationKit_testboxscript_testboxscript__real.py
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/VBox/ValidationKit/testboxscript/testboxscript_real.py.orig 2016-03-04 19:30:17.000000000 +0000
++++ src/VBox/ValidationKit/testboxscript/testboxscript_real.py
+@@ -267,7 +267,7 @@ class TestBoxScript(object):
+ # Platform specific mount code.
+ #
+ sHostOs = utils.getHostOs()
+- if sHostOs in ('darwin', 'freebsd'):
++ if sHostOs in ('darwin', 'freebsd', 'netbsd'):
+ utils.sudoProcessCall(['/sbin/umount', sMountPoint]);
+ utils.sudoProcessCall(['/bin/mkdir', '-p', sMountPoint]);
+ utils.sudoProcessCall(['/usr/sbin/chown', str(os.getuid()), sMountPoint]); # pylint: disable=E1101
+@@ -996,4 +996,3 @@ class TestBoxScript(object):
+
+ if __name__ == '__main__':
+ sys.exit(TestBoxScript.main());
+-
diff --git a/virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_base.py b/virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_base.py
new file mode 100644
index 0000000..c1ad3cf
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_base.py
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/VBox/ValidationKit/testdriver/base.py.orig 2016-03-04 19:30:17.000000000 +0000
++++ src/VBox/ValidationKit/testdriver/base.py
+@@ -827,6 +827,7 @@ class TestDriverBase(object): # pylint:
+ if self.sResourcePath is None:
+ if self.sHost == 'darwin': self.sResourcePath = "/Volumes/testrsrc/";
+ elif self.sHost == 'freebsd': self.sResourcePath = "/mnt/testrsrc/";
++ elif self.sHost == 'netbsd': self.sResourcePath = "/mnt/testrsrc/";
+ elif self.sHost == 'linux': self.sResourcePath = "/mnt/testrsrc/";
+ elif self.sHost == 'os2': self.sResourcePath = "T:/";
+ elif self.sHost == 'solaris': self.sResourcePath = "/mnt/testrsrc/";
+@@ -1719,4 +1720,3 @@ class TestDriverBaseTestCase(unittest.Te
+ if __name__ == '__main__':
+ unittest.main();
+ # not reached.
+-
diff --git a/virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_vbox.py b/virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_vbox.py
new file mode 100644
index 0000000..99a8a3c
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_vbox.py
@@ -0,0 +1,36 @@
+$NetBSD$
+
+--- src/VBox/ValidationKit/testdriver/vbox.py.orig 2016-03-04 19:30:17.000000000 +0000
++++ src/VBox/ValidationKit/testdriver/vbox.py
+@@ -1015,7 +1015,7 @@ class TestDriver(base.TestDriver):
+ cMsFudge = 1;
+ sVBoxSVC = '%s/VBoxSVC' % (self.oBuild.sInstallPath,); ## @todo .exe and stuff.
+ if self.fVBoxSvcInDebugger:
+- if self.sHost in ('darwin', 'freebsd', 'linux', 'solaris', ):
++ if self.sHost in ('darwin', 'freebsd', 'linux', 'solaris', 'netbsd'):
+ # Start VBoxSVC in gdb in a new terminal.
+ #sTerm = '/usr/bin/gnome-terminal'; - doesn't work, some fork+exec stuff confusing us.
+ sTerm = '/usr/bin/xterm';
+@@ -1057,7 +1057,7 @@ class TestDriver(base.TestDriver):
+ else:
+ reporter.error('Port me!');
+ else: # Run without a debugger attached.
+- if self.sHost in ('darwin', 'freebsd', 'linux', 'solaris', ):
++ if self.sHost in ('darwin', 'freebsd', 'linux', 'solaris', 'netbsd'):
+ #
+ # XPCOM - We can use a pipe to let VBoxSVC notify us when it's ready.
+ #
+@@ -1689,7 +1689,7 @@ class TestDriver(base.TestDriver):
+ if os.path.isfile(sVBoxSvcRelLog + sSuff):
+ reporter.addLogFile(sVBoxSvcRelLog + sSuff, 'log/release/svc', 'Release log file for VBoxSVC');
+ # Testbox debugging - START - TEMPORARY, REMOVE ASAP.
+- if self.sHost in ('darwin', 'freebsd', 'linux', 'solaris', ):
++ if self.sHost in ('darwin', 'freebsd', 'linux', 'solaris', 'netbsd'):
+ try:
+ print '> ls -la %s' % (os.path.join(self.sScratchPath, 'VBoxUserHome'),);
+ utils.processCall(['ls', '-la', os.path.join(self.sScratchPath, 'VBoxUserHome')]);
+@@ -3289,4 +3289,3 @@ class TestDriver(base.TestDriver):
+ return fRc;
+
+ # pylint: enable=R0914,R0913
+-
diff --git a/virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_vboxtestvms.py b/virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_vboxtestvms.py
new file mode 100644
index 0000000..f8ca409
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ValidationKit_testdriver_vboxtestvms.py
@@ -0,0 +1,55 @@
+$NetBSD$
+
+--- src/VBox/ValidationKit/testdriver/vboxtestvms.py.orig 2016-03-04 19:30:17.000000000 +0000
++++ src/VBox/ValidationKit/testdriver/vboxtestvms.py
+@@ -102,7 +102,8 @@ g_aaNameToDetails = \
+ [ 'Solaris', 'Solaris', g_k32, 1, 256, ['sol10', 'sol10u[0-9]']],
+ [ 'Solaris_64', 'Solaris_64', g_k64, 1, 256, ['sol10-64', 'sol10u-64[0-9]']],
+ [ 'Solaris_64', 'Solaris11_64', g_k64, 1, 256, ['sol11u1']],
+- [ 'BSD', 'FreeBSD_64', g_k32_64, 1, 1, ['bs-.*']], # boot sectors, wanted 64-bit type.
++ [ 'FreeBSD', 'FreeBSD_64', g_k32_64, 1, 1, ['bs-.*']], # boot sectors, wanted 64-bit type.
++ [ 'NetBSD', 'NetBSD_64', g_k32_64, 1, 1, ['bs-.*']], # boot sectors, wanted 64-bit type.
+ ];
+
+
+@@ -110,6 +111,7 @@ g_aaNameToDetails = \
+ ## @{
+ g_ksGuestOsTypeDarwin = 'darwin';
+ g_ksGuestOsTypeFreeBSD = 'freebsd';
++g_ksGuestOsTypeNetBSD = 'netbsd';
+ g_ksGuestOsTypeLinux = 'linux';
+ g_ksGuestOsTypeOS2 = 'os2';
+ g_ksGuestOsTypeSolaris = 'solaris';
+@@ -134,6 +136,7 @@ g_kasParavirtProviders = ( g_ksParavirtP
+ #g_kdaParavirtProvidersSupported = {
+ # g_ksGuestOsTypeDarwin : ( g_ksParavirtProviderMinimal, ),
+ # g_ksGuestOsTypeFreeBSD : ( g_ksParavirtProviderNone, g_ksParavirtProviderMinimal, ),
++# g_ksGuestOsTypeNetBSD : ( g_ksParavirtProviderNone, g_ksParavirtProviderMinimal, ),
+ # g_ksGuestOsTypeLinux : ( g_ksParavirtProviderNone, g_ksParavirtProviderMinimal, g_ksParavirtProviderHyperV, g_ksParavirtProviderKVM),
+ # g_ksGuestOsTypeOS2 : ( g_ksParavirtProviderNone, ),
+ # g_ksGuestOsTypeSolaris : ( g_ksParavirtProviderNone, ),
+@@ -146,6 +149,7 @@ g_kasParavirtProviders = ( g_ksParavirtP
+ g_kdaParavirtProvidersSupported = {
+ g_ksGuestOsTypeDarwin : ( g_ksParavirtProviderMinimal, ),
+ g_ksGuestOsTypeFreeBSD : ( g_ksParavirtProviderNone, ),
++ g_ksGuestOsTypeNetBSD : ( g_ksParavirtProviderNone, ),
+ g_ksGuestOsTypeLinux : ( g_ksParavirtProviderNone, g_ksParavirtProviderHyperV, g_ksParavirtProviderKVM),
+ g_ksGuestOsTypeOS2 : ( g_ksParavirtProviderNone, ),
+ g_ksGuestOsTypeSolaris : ( g_ksParavirtProviderNone, ),
+@@ -207,8 +211,10 @@ class TestVm(object):
+ """
+ if sType.lower().startswith('darwin'):
+ return g_ksGuestOsTypeDarwin
+- if sType.lower().startswith('bsd'):
++ if sType.lower().startswith('freebsd'):
+ return g_ksGuestOsTypeFreeBSD
++ if sType.lower().startswith('netbsd'):
++ return g_ksGuestOsTypeNetBSD
+ if sType.lower().startswith('linux'):
+ return g_ksGuestOsTypeLinux
+ if sType.lower().startswith('os2'):
+@@ -954,4 +960,3 @@ class TestVmManager(object):
+ def shutUpPyLint(self):
+ """ Shut up already! """
+ return self.sResourcePath;
+-
diff --git a/virtualbox/patches/patch-src_VBox_ValidationKit_testmanager_core_coreconsts.py b/virtualbox/patches/patch-src_VBox_ValidationKit_testmanager_core_coreconsts.py
new file mode 100644
index 0000000..01f3a06
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ValidationKit_testmanager_core_coreconsts.py
@@ -0,0 +1,28 @@
+$NetBSD$
+
+--- src/VBox/ValidationKit/testmanager/core/coreconsts.py.orig 2016-03-04 19:30:17.000000000 +0000
++++ src/VBox/ValidationKit/testmanager/core/coreconsts.py
+@@ -33,5 +33,5 @@ g_ksOsAgnostic = 'os-agnostic';
+ ## All known OSes, except the agnostic one.
+ # See KBUILD_OSES in kBuild/header.kmk for reference.
+-g_kasOses = ['darwin', 'dos', 'dragonfly', 'freebsd', 'haiku', 'l4', 'linux', 'netbsd', 'nt', 'openbsd', 'os2',
++g_kasOses = ['darwin', 'dos', 'dragonfly', 'freebsd', 'netbsd', 'haiku', 'l4', 'linux', 'netbsd', 'nt', 'openbsd', 'os2',
+ 'solaris', 'win'];
+ ## All known OSes, including the agnostic one.
+@@ -65,4 +65,5 @@ g_kasOsDotCpus = \
+ 'freebsd.amd64', 'freebsd.x86', 'freebsd.sparc64', 'freebsd.ia64', 'freebsd.ppc32', 'freebsd.ppc64', 'freebsd.arm',
+ 'freebsd.mips32', 'freebsd.mips64',
++ 'netbsd.amd64', 'netbsd.x86',
+ 'haiku.amd64', 'haiku.x86',
+ 'l4.amd64', 'l4.x86', 'l4.ppc32', 'l4.ppc64', 'l4.arm',
+@@ -73,5 +74,5 @@ g_kasOsDotCpus = \
+ ];
+ for sOs in g_kasOses:
+- if sOs not in ['darwin', 'dos', 'dragonfly', 'freebsd', 'haiku', 'l4', 'nt', 'win', 'os2', 'solaris']:
++ if sOs not in ['darwin', 'dos', 'dragonfly', 'freebsd', 'netbsd', 'haiku', 'l4', 'nt', 'win', 'os2', 'solaris']:
+ for sArch in g_kasCpuArches:
+ g_kasOsDotCpus.append(sOs + '.' + sArch);
+@@ -86,3 +87,2 @@ for sArch in g_kasCpuArchesAll:
+ g_kasOsDotCpusAll.append(g_ksOsAgnostic + '.' + sArch);
+ g_kasOsDotCpusAll.sort();
+-
diff --git a/virtualbox/patches/patch-src_VBox_ValidationKit_tests_autostart_tdAutostart1.py b/virtualbox/patches/patch-src_VBox_ValidationKit_tests_autostart_tdAutostart1.py
new file mode 100644
index 0000000..34286bf
--- /dev/null
+++ b/virtualbox/patches/patch-src_VBox_ValidationKit_tests_autostart_tdAutostart1.py
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/VBox/ValidationKit/tests/autostart/tdAutostart1.py.orig 2016-03-04 19:30:19.000000000 +0000
++++ src/VBox/ValidationKit/tests/autostart/tdAutostart1.py
+@@ -461,6 +461,7 @@ class tdAutostart(vbox.TestDriver):
+ ksOsDarwin = 'tst-darwin'
+ ksOsSolaris = 'tst-solaris'
+ ksOsFreeBSD = 'tst-freebsd'
++ ksOsNetBSD = 'tst-netbsd'
+
+ def __init__(self):
+ vbox.TestDriver.__init__(self);
+@@ -703,4 +704,3 @@ class tdAutostart(vbox.TestDriver):
+
+ if __name__ == '__main__':
+ sys.exit(tdAutostart().main(sys.argv));
+-
diff --git a/virtualbox/patches/patch-src_apps_Makefile.kmk b/virtualbox/patches/patch-src_apps_Makefile.kmk
new file mode 100644
index 0000000..d75ddd7
--- /dev/null
+++ b/virtualbox/patches/patch-src_apps_Makefile.kmk
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/apps/Makefile.kmk.orig 2016-03-04 19:30:20.000000000 +0000
++++ src/apps/Makefile.kmk
+@@ -28,11 +28,10 @@ ifeq ($(KBUILD_TARGET),linux)
+ include $(PATH_SUB_CURRENT)/tunctl/Makefile.kmk
+ endif
+ endif
+-if1of ($(KBUILD_TARGET),darwin solaris linux freebsd)
++if1of ($(KBUILD_TARGET),darwin solaris linux freebsd netbsd)
+ ifneq ($(wildcard $(PATH_SUB_CURRENT)/adpctl),)
+ include $(PATH_SUB_CURRENT)/adpctl/Makefile.kmk
+ endif
+ endif
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_libs_libxml2-2.9.2_include_vboxconfig.h b/virtualbox/patches/patch-src_libs_libxml2-2.9.2_include_vboxconfig.h
new file mode 100644
index 0000000..79bf2aa
--- /dev/null
+++ b/virtualbox/patches/patch-src_libs_libxml2-2.9.2_include_vboxconfig.h
@@ -0,0 +1,18 @@
+$NetBSD$
+
+--- src/libs/libxml2-2.9.2/include/vboxconfig.h.orig 2016-03-04 19:30:26.000000000 +0000
++++ src/libs/libxml2-2.9.2/include/vboxconfig.h
+@@ -9,7 +9,7 @@
+ #undef SUPPORT_IP6
+
+ /* Define if getaddrinfo is there */
+-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
++#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD)
+ # define HAVE_GETADDRINFO 1
+ #else
+ # undef HAVE_GETADDRINFO
+@@ -434,4 +434,3 @@
+ /* make sure LIBXML_ICONV_ENABLED is killed */
+ #include <libxml/xmlversion.h>
+ #undef LIBXML_ICONV_ENABLED
+-
diff --git a/virtualbox/patches/patch-src_recompiler_Makefile.kmk b/virtualbox/patches/patch-src_recompiler_Makefile.kmk
new file mode 100644
index 0000000..838ad42
--- /dev/null
+++ b/virtualbox/patches/patch-src_recompiler_Makefile.kmk
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- src/recompiler/Makefile.kmk.orig 2016-03-04 19:31:09.000000000 +0000
++++ src/recompiler/Makefile.kmk
+@@ -83,6 +83,7 @@ else
+ VBoxRemPrimary_DEFS.solaris = CONFIG_SOLARIS_VERSION=11
+ endif
+ VBoxRemPrimary_DEFS.freebsd += _BSD
++VBoxRemPrimary_DEFS.netbsd += _BSD
+ VBoxRemPrimary_DEFS.amd64 += __x86_64__
+ VBoxRemPrimary_DEFS.x86 += __i386__
+
+@@ -339,4 +340,3 @@ testmath_SOURCES = Sun/testmath.c
+
+
+ include $(FILE_KBUILD_SUB_FOOTER)
+-
diff --git a/virtualbox/patches/patch-src_recompiler_exec.c b/virtualbox/patches/patch-src_recompiler_exec.c
new file mode 100644
index 0000000..19152a7
--- /dev/null
+++ b/virtualbox/patches/patch-src_recompiler_exec.c
@@ -0,0 +1,35 @@
+$NetBSD$
+
+--- src/recompiler/exec.c.orig 2016-03-04 19:31:10.000000000 +0000
++++ src/recompiler/exec.c
+@@ -64,6 +64,7 @@
+ #if defined(CONFIG_USER_ONLY)
+ #include <qemu.h>
+ #include <signal.h>
++
+ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+ #include <sys/param.h>
+ #if __FreeBSD_version >= 700104
+@@ -79,6 +80,13 @@
+ #include <libutil.h>
+ #endif
+ #endif
++
++#if defined(__NetBSD__)
++#include <sys/param.h>
++#include <sys/time.h>
++#include <sys/proc.h>
++#endif
++
+ #endif
+
+ //#define DEBUG_TB_INVALIDATE
+@@ -603,7 +611,7 @@ static void code_gen_alloc(uintptr_t tb_
+ exit(1);
+ }
+ }
+-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__)
+ {
+ int flags;
+ void *addr = NULL;
diff --git a/virtualbox/patches/patch-tools_bin_gen-slickedit-workspace.sh b/virtualbox/patches/patch-tools_bin_gen-slickedit-workspace.sh
new file mode 100644
index 0000000..aa2682d
--- /dev/null
+++ b/virtualbox/patches/patch-tools_bin_gen-slickedit-workspace.sh
@@ -0,0 +1,17 @@
+$NetBSD$
+
+--- tools/bin/gen-slickedit-workspace.sh.orig 2016-03-04 19:31:11.000000000 +0000
++++ tools/bin/gen-slickedit-workspace.sh
+@@ -860,6 +860,7 @@ my_generate_project "REM" "src
+
+ # src/VBox/Additions
+ my_generate_project "Add-freebsd" "src/VBox/Additions/freebsd" --begin-incs "include" "src/VBox/Additions/freebsd" --end-includes "src/VBox/Additions/freebsd"
++my_generate_project "Add-netbsd" "src/VBox/Additions/netbsd" --begin-incs "include" "src/VBox/Additions/netbsd" --end-includes "src/VBox/Additions/netbsd"
+ my_generate_project "Add-linux" "src/VBox/Additions/linux" --begin-incs "include" "src/VBox/Additions/linux" --end-includes "src/VBox/Additions/linux"
+ my_generate_project "Add-os2" "src/VBox/Additions/os2" --begin-incs "include" "src/VBox/Additions/os2" --end-includes "src/VBox/Additions/os2"
+ my_generate_project "Add-solaris" "src/VBox/Additions/solaris" --begin-incs "include" "src/VBox/Additions/solaris" --end-includes "src/VBox/Additions/solaris"
+@@ -1037,4 +1038,3 @@ my_generate_usercpp_h
+
+
+ echo "done"
+-
Home |
Main Index |
Thread Index |
Old Index