diff --git Config.kmk Config.kmk
index 26405c1..7fc412a 100644
--- Config.kmk
+++ Config.kmk
@@ -440,7 +440,7 @@ VBOX_WITH_VMSVGA = 1
 # Enable Host Guest Shared Memory Interface.
 VBOX_WITH_HGSMI = 1
 # Enable Video 2D Acceleration.
-if1of ($(KBUILD_TARGET), darwin linux win freebsd)
+if1of ($(KBUILD_TARGET), darwin linux win freebsd netbsd)
  VBOX_WITH_VIDEOHWACCEL = 1
 endif
 # Enable Wddm Video driver for Vista+ guests.
@@ -618,13 +618,13 @@ VBOX_WITH_GUEST_PROPS_RDONLY_GUEST =
 # Compile the host channel
 VBOX_WITH_HOST_CHANNEL = 1
 # Enable the guest control service.
-if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
+if1of ($(KBUILD_TARGET), darwin freebsd linux netbsd solaris win)
  VBOX_WITH_GUEST_CONTROL = 1
 endif
 # Enable ballooning
 VBOX_WITH_MEMBALLOON = 1
 # Enable crOpenGL service
-if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
+if1of ($(KBUILD_TARGET), darwin freebsd linux netbsd solaris win)
  VBOX_WITH_CROGL = 1
 endif
 # enable new wined3d code
@@ -632,7 +632,7 @@ VBOX_WITH_NEW_WINE = 1
 # Enable S3 support (requires libcurl)
 VBOX_WITH_S3 = 1
 # Enable Host=>Guest Drag'n'Drop
-if1of ($(KBUILD_TARGET), darwin linux solaris win)
+if1of ($(KBUILD_TARGET), darwin netbsd linux solaris win)
  VBOX_WITH_DRAG_AND_DROP = 1
  # Guest=>Host drag'n'drop doesn't work
  #VBOX_WITH_DRAG_AND_DROP_GH = 1
@@ -746,6 +746,8 @@ ifdef VBOX_WITH_HARDENING
   VBOX_PATH_APP_PRIVATE      = /Applications/VirtualBox.app/Contents/MacOS
  else ifeq ($(KBUILD_TARGET),freebsd)
   VBOX_PATH_APP_PRIVATE      = /usr/local/lib/virtualbox
+ else ifeq ($(KBUILD_TARGET),netbsd)
+  VBOX_PATH_APP_PRIVATE      = /usr/local/lib/virtualbox
  else ifeq ($(KBUILD_TARGET),haiku)
   VBOX_PATH_APP_PRIVATE      = /boot/apps/VirtualBox
  endif
@@ -893,7 +895,7 @@ ifeq ($(KBUILD_TARGET),darwin)
  VBOX_WITH_VBOXSDL=
 endif
 
-ifeq ($(KBUILD_TARGET),freebsd)
+if1of ($(KBUILD_TARGET),freebsd netbsd)
  VBOX_WITH_DOCS=
 endif
 
@@ -1861,7 +1863,7 @@ VBOX_DEF_2_LAZY_LOAD ?= $(PATH_OBJ)/VBoxDef2LazyLoad/VBoxDef2LazyLoad$(HOSTSUFF_
 # 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
 
@@ -2191,7 +2193,7 @@ ifdef VBOX_WITH_CROGL
   VBOX_LIB_OGL_HOSTCRUTIL = $(PATH_STAGE_BIN)/VBoxOGLhostcrutil$(VBOX_SUFF_DLL)
  endif
 
- if1of ($(KBUILD_TARGET), freebsd linux solaris)
+ if1of ($(KBUILD_TARGET), freebsd linux netbsd solaris)
  # VBOX_PATH_MESA_SOURCE = $(PATH_ROOT)/src/libs/mesa-7.2
   VBOX_PATH_MESA_SOURCE = $(VBOX_PATH_X11_ROOT)/mesa-7.2
   VBOX_MESA_INCS = \
@@ -3124,7 +3126,7 @@ ifdef VBOX_WITH_RAW_MODE
    ## @todo WTF doesn't the globals work? Debug info is supposed to be split everywhere. GRR
    TEMPLATE_VBoxRc_LD_DEBUG          = split
   endif
-  ifn1of ($(KBUILD_TARGET), solaris freebsd)
+  ifn1of ($(KBUILD_TARGET), solaris freebsd netbsd)
    TEMPLATE_VBoxRc_LIBS               = \
 	$(VBOX_GCC32_LIBGCC) # instricts
   endif
@@ -3269,7 +3271,7 @@ else
  ## @todo WTF doesn't the globals work? Debug info is supposed to be split everywhere. GRR
  TEMPLATE_VBoxR0_LD_DEBUG           = split
 endif
-ifn1of ($(KBUILD_TARGET),solaris freebsd)
+ifn1of ($(KBUILD_TARGET),solaris freebsd netbsd)
  TEMPLATE_VBoxR0_LIBS               = \
 	$(VBOX_GCC_LIBGCC) # instricts
 endif
@@ -3544,6 +3546,65 @@ endef
 
 endif # FreeBSD
 
+ifeq ($(KBUILD_TARGET),netbsd)
+
+## The location of the NetBSD kernel headers.
+VBOX_NETBSD_SRC ?= /usr/src/sys
+
+ifeq ($(KBUILD_TARGET_ARCH),amd64)
+VBOX_NETBSD_MACHINE_SRC=$(VBOX_NETBSD_SRC)/arch/amd64
+else
+VBOX_NETBSD_MACHINE_SRC=$(VBOX_NETBSD_SRC)/arch/i386
+endif
+
+TEMPLATE_VBOXR0DRV_TOOL                = $(VBOX_GCC_TOOL)
+TEMPLATE_VBOXR0DRV_DEFS               += _KERNEL _MODULE
+TEMPLATE_VBOXR0DRV_INCS                = \
+	$(VBOX_NETBSD_SRC) \
+	$(VBOX_NETBSD_SRC)/../common/include \
+	$(PATH_OBJ)/netbsd/include
+
+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=gnu99 -msoft-float
+TEMPLATE_VBOXR0DRV_CFLAGS.x86          = -m32 -mno-align-long-strings \
+    -mpreferred-stack-boundary=2 -mno-mmx -mno-sse -mno-avx \
+    -mno-fp-ret-in-387
+TEMPLATE_VBOXR0DRV_CFLAGS.amd64        = -m64 --param inline-unit-growth=100 \
+    --param large-function-growth=1000 -fno-omit-frame-pointer \
+    -mcmodel=kernel -mno-red-zone -mno-sse -mno-mmx -mno-avx \
+	-fno-asynchronous-unwind-tables -mno-fp-ret-in-387
+TEMPLATE_VBOXR0DRV_CXXFLAGS            = -fno-exceptions -fno-rtti \
+	$(VBOX_GCC_WARN) -Wpointer-arith -Winline \
+	-O2 -fno-strict-aliasing -fno-common -finline-limit=8000 \
+	$(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
+	-nostdinc -msoft-float
+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
+TEMPLATE_VBOXR0DRV_LDFLAGS.amd64       = -m elf_x86_64
+
+TEMPLATE_VBOXR0DRV_ORDERDEPS = \
+	$(PATH_OBJ)/netbsd/include/machine/cdefs.h \
+	$(PATH_OBJ)/netbsd/include/x86/cpu.h
+
+$$(PATH_OBJ)/netbsd/include/machine/cdefs.h: $(VBOX_NETBSD_MACHINE_SRC)/include/cdefs.h
+	$(QUIET)$(MKDIR) -p $(@D)
+	$(QUIET)cp $(VBOX_NETBSD_MACHINE_SRC)/include/*.h $(@D)/
+
+$$(PATH_OBJ)/netbsd/include/x86/cpu.h: $(VBOX_NETBSD_SRC)/arch/x86/include/cpu.h
+	$(QUIET)$(MKDIR) -p $(@D)/x86
+	$(QUIET)cp $(VBOX_NETBSD_SRC)/arch/x86/include/*.h $(@D)/
+
+endif # NetBSD
+
 ifeq ($(KBUILD_TARGET),haiku)
 ## The Haiku include directories
 VBOX_HAIKU_SYS_INCS ?= /boot/develop/headers/os/kernel /boot/develop/headers/os/drivers
@@ -3728,7 +3789,7 @@ TEMPLATE_VBOXR3EXE_LIBPATH            += \
 TEMPLATE_VBOXR3EXE_CFLAGS             += -fno-pic
 TEMPLATE_VBOXR3EXE_CXXFLAGS           += -fno-pic
 TEMPLATE_VBOXR3EXE_LDFLAGS            += -fno-pic
- else if1of ($(KBUILD_TARGET), freebsd netbsd openbsd)
+ else if1of ($(KBUILD_TARGET), freebsd openbsd)
 TEMPLATE_VBOXR3EXE_TOOL                = GXX3
 TEMPLATE_VBOXR3EXE_LIBS                = pthread
 TEMPLATE_VBOXR3EXE_INCS               += \
@@ -3739,6 +3800,15 @@ TEMPLATE_VBOXR3EXE_LIBPATH            += \
 	/usr/lib \
 	/usr/X11R6/lib \
 	/usr/local/lib
+ else if1of ($(KBUILD_TARGET), netbsd)
+TEMPLATE_VBOXR3EXE_TOOL                = GXX3
+TEMPLATE_VBOXR3EXE_LIBS                = pthread
+TEMPLATE_VBOXR3EXE_INCS               += \
+	/usr/include \
+	/usr/X11R7/include
+TEMPLATE_VBOXR3EXE_LIBPATH            += \
+	/usr/lib \
+	/usr/X11R7/lib
  else ifeq ($(KBUILD_TARGET),solaris)
 TEMPLATE_VBOXR3EXE_TOOL                = GXX3PLAIN
 TEMPLATE_VBOXR3EXE_DEFS               += LIBICONV_PLUG _REENTRANT # Avoid the GNU libiconv, for now at least.
@@ -3810,7 +3880,7 @@ TEMPLATE_VBoxR3Dll-x86_DEFS           = $(filter-out HC_ARCH_BITS%,$(TEMPLATE_VB
 #
 TEMPLATE_VBoxR3DllNoPic                    = VBox ring-3 SO/DLLs without PIC, without warnings.
 TEMPLATE_VBoxR3DllNoPic_EXTENDS            = VBOXR3
-if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), linux.x86 freebsd.x86)
+if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), linux.x86 freebsd.x86 netbsd.x86)
  TEMPLATE_VBoxR3DllNoPic_DEFS              = $(TEMPLATE_VBOXR3EXE_DEFS)
  TEMPLATE_VBoxR3DllNoPic_CFLAGS            = $(TEMPLATE_VBOXR3EXE_CFLAGS)   $(VBOX_GCC_WERR)
  TEMPLATE_VBoxR3DllNoPic_CXXFLAGS          = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) $(VBOX_GCC_WERR)
@@ -3841,7 +3911,7 @@ TEMPLATE_VBoxR3DllNoPic-x86_DEFS           = $(filter-out HC_ARCH_BITS%,$(TEMPLA
 #
 TEMPLATE_VBoxR3DllWarnNoPic                = VBox ring-3 SO/DLLs without PIC, with warnings.
 TEMPLATE_VBoxR3DllWarnNoPic_EXTENDS        = VBOXR3
-if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), linux.x86 freebsd.x86)
+if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), linux.x86 freebsd.x86 netbsd.x86)
  TEMPLATE_VBoxR3DllWarnNoPic_DEFS          = $(TEMPLATE_VBOXR3EXE_DEFS)
  TEMPLATE_VBoxR3DllWarnNoPic_CFLAGS        = $(TEMPLATE_VBOXR3EXE_CFLAGS)
  TEMPLATE_VBoxR3DllWarnNoPic_CXXFLAGS      = $(TEMPLATE_VBOXR3EXE_CXXFLAGS)
@@ -4380,7 +4450,7 @@ TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME)
  else ifeq ($(KBUILD_TARGET),haiku)
 TEMPLATE_VBOXMAINEXE_TOOL                = GXX3
 TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME) network stdc++ supc++
- else if1of ($(KBUILD_TARGET), freebsd netbsd openbsd)
+ else if1of ($(KBUILD_TARGET), freebsd openbsd)
 TEMPLATE_VBOXMAINEXE_TOOL                = GXX3
 TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME)
 TEMPLATE_VBOXMAINEXE_INCS               += \
@@ -4391,6 +4461,17 @@ TEMPLATE_VBOXMAINEXE_LIBPATH            += \
 	/usr/lib \
 	/usr/X11R6/lib \
 	/usr/local/lib
+ else if1of ($(KBUILD_TARGET), netbsd)
+TEMPLATE_VBOXMAINEXE_TOOL                = GXX3
+TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME)
+TEMPLATE_VBOXMAINEXE_INCS               += \
+	/usr/include \
+	/usr/X11R7/include \
+	/usr/local/include
+TEMPLATE_VBOXMAINEXE_LIBPATH            += \
+	/usr/lib \
+	/usr/X11R7/lib \
+	/usr/local/lib
 else ifeq ($(KBUILD_TARGET),solaris)
 TEMPLATE_VBOXMAINEXE_TOOL                = GXX3PLAIN
 TEMPLATE_VBOXMAINEXE_DEFS               += _REENTRANT
@@ -5046,7 +5127,7 @@ TEMPLATE_VBoxBldProg_TOOL                = GXX3
 TEMPLATE_VBoxBldProg_LIBS                = network iconv
 TEMPLATE_VBoxBldProg_LIBPATH            += \
 	/boot/common/lib
- else if1of ($(KBUILD_HOST), freebsd netbsd openbsd)
+ else if1of ($(KBUILD_HOST), freebsd openbsd)
 TEMPLATE_VBoxBldProg_TOOL                = GXX3
 TEMPLATE_VBoxBldProg_LIBS                = pthread
 TEMPLATE_VBoxBldProg_INCS               += \
@@ -5057,6 +5138,17 @@ TEMPLATE_VBoxBldProg_LIBPATH            += \
 	/usr/lib \
 	/usr/X11R6/lib \
 	/usr/local/lib
+ else if1of ($(KBUILD_HOST), netbsd)
+TEMPLATE_VBoxBldProg_TOOL                = GXX3
+TEMPLATE_VBoxBldProg_LIBS                = pthread
+TEMPLATE_VBoxBldProg_INCS               += \
+	/usr/include \
+	/usr/X11R7/include \
+	/usr/local/include
+TEMPLATE_VBoxBldProg_LIBPATH            += \
+	/usr/lib \
+	/usr/X11R7/lib \
+	/usr/local/lib
  else ifeq ($(KBUILD_HOST),solaris)
 TEMPLATE_VBoxBldProg_TOOL                = GXX3PLAIN
 TEMPLATE_VBoxBldProg_LIBS                = rt
@@ -5099,6 +5191,10 @@ TEMPLATE_VBoxAdvBldProg_LIBS.linux = \
 	$(TEMPLATE_VBoxAdvBldProg_LIBS) \
 	crypt \
 	$(TEMPLATE_VBoxBldProg_LIBS.linux)
+TEMPLATE_VBoxAdvBldProg_LIBS.netbsd = \
+	$(TEMPLATE_VBoxAdvBldProg_LIBS) \
+	rt \
+	$(TEMPLATE_VBoxBldProg_LIBS.netbsd)
 TEMPLATE_VBoxAdvBldProg_LIBS.solaris = \
 	$(TEMPLATE_VBoxAdvBldProg_LIBS) \
 	contract \
@@ -5182,8 +5278,10 @@ TEMPLATE_VBOXGUESTR3EXE_DEFS     := $(filter-out $(ARCH_BITS_DEFS), $(TEMPLATE_V
 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), netbsd)
+ TEMPLATE_VBOXGUESTR3EXE_LIBS     = pthread
 else ifeq ($(KBUILD_TARGET), solaris)
  TEMPLATE_VBOXGUESTR3EXE_LIBS     = $(TEMPLATE_VBOXR3EXE_LIBS) nsl
 endif
@@ -5410,6 +5508,7 @@ TEMPLATE_VBOXCROGLR3HOSTDLL_DEFS.solaris     = SunOS=1 _GNU_SOURCE #GLEXT_64_TYP
 TEMPLATE_VBOXCROGLR3HOSTDLL_DEFS.darwin      = DARWIN=1 GL_GLEXT_LEGACY _GNU_SOURCE VBOX_WITH_COCOA_QT
 TEMPLATE_VBOXCROGLR3HOSTDLL_LDFLAGS.darwin   = -framework AppKit
 TEMPLATE_VBOXCROGLR3HOSTDLL_DEFS.freebsd     = FreeBSD=1 _GNU_SOURCE
+TEMPLATE_VBOXCROGLR3HOSTDLL_DEFS.netbsd      = NetBSD=1 _GNU_SOURCE
 TEMPLATE_VBOXCROGLR3HOSTDLL_INCS             = $(VBOX_PATH_CROGL_INCLUDE) $(VBOX_PATH_CROGL_GENFILES)
 TEMPLATE_VBOXCROGLR3HOSTDLL_SDKS.darwin      = DARWIN-OPENGL
 TEMPLATE_VBOXCROGLR3HOSTDLL_LDFLAGS.darwin  += \
@@ -5438,7 +5537,9 @@ TEMPLATE_VBOXCROGLR3GUESTDLL_DEFS.linux       = Linux=1 _GNU_SOURCE
 TEMPLATE_VBOXCROGLR3GUESTDLL_DEFS.solaris     = SunOS=1 _GNU_SOURCE #GLEXT_64_TYPES_DEFINED
 TEMPLATE_VBOXCROGLR3GUESTDLL_DEFS.darwin      = DARWIN=1 GL_GLEXT_LEGACY _GNU_SOURCE VBOX_WITH_COCOA_QT
 TEMPLATE_VBOXCROGLR3GUESTDLL_LDFLAGS.darwin   = -framework AppKit
+TEMPLATE_VBOXCROGLR3GUESTDLL_LDFLAGS.netbsd   = -Wl,-rpath,/usr/X11R7/lib
 TEMPLATE_VBOXCROGLR3GUESTDLL_DEFS.freebsd     = FreeBSD=1 _GNU_SOURCE
+TEMPLATE_VBOXCROGLR3GUESTDLL_DEFS.netbsd      = NetBSD=1 _GNU_SOURCE
 TEMPLATE_VBOXCROGLR3GUESTDLL_INCS             = $(VBOX_PATH_CROGL_INCLUDE) $(VBOX_PATH_CROGL_GENFILES)
 TEMPLATE_VBOXCROGLR3GUESTDLL_SDKS.darwin      = DARWIN-OPENGL
 TEMPLATE_VBOXCROGLR3GUESTDLL_LDFLAGS.darwin  += \
diff --git configure configure
index 83fa74c..cda20f1 100755
--- configure
+++ configure
@@ -51,6 +51,8 @@ case "$OS" in
     ;;
   freebsd)
     ;;
+  netbsd)
+    ;;
   sunos)
     OS='solaris'
     ;;
@@ -140,6 +142,16 @@ if [ "$OS" = "freebsd" ]; then
   LIBPULSE="-L/usr/local/lib"
   INCPNG="-I/usr/local/include"
   LIBPNG="-L/usr/local/lib -lpng"
+elif [ "$OS" = "netbsd" ]; then
+  INCCURL="-I/usr/pkg/include"
+  LIBCURL="-L/usr/pkg/lib -lcurl"
+  INCPULSE="-I/usr/pkg/include"
+  LIBPULSE="-L/usr/pkg/lib"
+  INCPNG="-I/usr/pkg/include"
+  LIBPNG="-L/usr/pkg/lib -lpng"
+  INCX11="-I/usr/X11R7/include"
+  LIBX11="-L/usr/X11R7/lib -lXext -lX11"
+  NETBSD=/usr/src/sys
 else
   INCCURL=""
   LIBCURL="-lcurl"
@@ -1742,6 +1754,24 @@ EOF
   fi
 }
 
+#
+# Check for NetBSD sources
+#
+check_netbsd()
+{
+  test_header "NetBSD kernel sources"
+  echo "checking for ${NETBSD}/sys/systm.h" >>$LOG
+  if [ ! -f "${NETBSD}/sys/systm.h" ]
+  then
+    echo "  NetBSD kernel sources not found at $NETBSD"
+    echo "  Check the file $LOG for detailed error information."
+    fail
+  else
+    if test_execute; then
+      cnf_append "VBOX_NETBSD_SRC" "`cd $NETBSD ; pwd`"
+    fi
+  fi
+}
 
 #
 # Check for kchmviewer, needed to display the online help
@@ -2263,6 +2293,7 @@ EOF
 [ $WITH_GSOAP  -eq 1 ] && echo "  --with-gsoap-dir=PATH    directory for gSOAP compiler/headers/libraries"
 [ $WITH_GSOAP  -eq 1 ] && echo "                           (soapcpp2 and wsdl2h, soapstd2.h, libgsoap++.a/so)"
 [ $WITH_GSOAP  -eq 1 ] && echo "  --with-gsoap-import=PATH directory for gSOAP import files (stlvector.h)"
+[ "$OS"    = "netbsd" ] && echo "  --with-netbsd=DIR         NetBSD kernel source directory [$NETBSD]"
 cat << EOF
   --with-openssl-dir=DIR   directory for OpenSSL headers/libraries
   --with-ow-dir=DIR        directory where Open Watcom can be found [$WATCOM]
@@ -2508,6 +2539,9 @@ for option in $*; do
     --setup-wine)
       [ "$OS" != "darwin" ] && SETUP_WINE=1
       ;;
+    --with-netbsd=*)
+      NETBSD=`echo $option | cut -d'=' -f2`
+      ;;
     *)
       echo
       echo "Unrecognized option \"$option\""
@@ -2708,6 +2742,18 @@ if [ "$OS" = "linux" ]; then
   [ $OSE -ge 1 ] && check_makeself
 fi
 
+# NetBSD-specific
+if [ "$OS" = "netbsd" ]; then
+  if [ $WITH_KMODS -eq 1 ]; then
+    check_netbsd
+  else
+    cnf_append "VBOX_NETBSD_SRC" ""
+    cnf_append "VBOX_NETBSD_MACHINE_INCS" ""
+    cnf_append "VBOX_WITH_VBOXDRV" ""
+    cnf_append "VBOX_WITH_ADDITION_DRIVERS" ""
+  fi
+fi
+
 [ -n "$SETUP_WINE" ] && setup_wine
 
 if [ $WITH_GSOAP -eq 1 ]; then
diff --git include/VBox/VBoxGuest.h include/VBox/VBoxGuest.h
index 9c025eb..4ecf135 100644
--- include/VBox/VBoxGuest.h
+++ include/VBox/VBoxGuest.h
@@ -185,7 +185,7 @@ typedef const VBGLBIGREQ *PCVBGLBIGREQ;
 # define VBOXGUEST_IOCTL_CODE_FAST_(Function)       (0x56420000 | (Function))
 # define VBOXGUEST_IOCTL_STRIP_SIZE(Code)           (Code)
 
-#elif defined(RT_OS_FREEBSD) /** @todo r=bird: Please do it like SUPDRVIOC to keep it as similar as possible. */
+#elif defined(RT_OS_FREEBSD) || 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)
@@ -508,7 +508,7 @@ typedef VBOXGUESTOS2IDCCONNECT *PVBOXGUESTOS2IDCCONNECT;
 
 #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?) */
@@ -528,7 +528,7 @@ typedef VBOXGUESTOS2IDCCONNECT *PVBOXGUESTOS2IDCCONNECT;
 # 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_NETBSD */
 
 /** @} */
 #endif /* !defined(IN_RC) && !defined(IN_RING0_AGNOSTIC) && !defined(IPRT_NO_CRT) */
diff --git include/iprt/alloca.h include/iprt/alloca.h
index c47771c..c9ce7d1 100644
--- include/iprt/alloca.h
+++ include/iprt/alloca.h
@@ -41,10 +41,11 @@
  && (defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD))
 /* ASSUMES GNU C */
 # define alloca(cb) __builtin_alloca(cb)
-
+#elif defined(IN_RING0) && defined(RT_OS_NETBSD)
+# include <lib/libkern/libkern.h>
 #else
 # include <stdlib.h>
-# if !defined(RT_OS_DARWIN) && !defined(RT_OS_FREEBSD)
+# if !defined(RT_OS_DARWIN) && !defined(RT_OS_FREEBSD) && !defined(RT_OS_NETBSD)
 #  include <malloc.h>
 # endif
 # ifdef RT_OS_SOLARIS
diff --git include/iprt/errno.h include/iprt/errno.h
index ee57065..fbad6d9 100644
--- include/iprt/errno.h
+++ include/iprt/errno.h
@@ -34,6 +34,8 @@
 #  include <linux/errno.h>
 # elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
 #  include <sys/errno.h>
+# elif defined(RT_OS_NETBSD) && defined(_KERNEL)
+#  include <sys/errno.h>
 # else
 #  include <errno.h>
 # endif
diff --git include/iprt/stdarg.h include/iprt/stdarg.h
index 4b93fb0..61b2820 100644
--- include/iprt/stdarg.h
+++ include/iprt/stdarg.h
@@ -33,6 +33,8 @@
 # include <iprt/cdefs.h>
 # if defined(RT_OS_FREEBSD) && defined(_KERNEL)
 #  include <machine/stdarg.h>
+# elif defined(RT_OS_NETBSD) && defined(_KERNEL)
+#  include <sys/stdarg.h>
 # elif defined(RT_OS_SOLARIS) && defined(_KERNEL) && defined(__GNUC__)
 #  include <stdarg.h>
 #  if __GNUC__ >= 4 /* System headers refers to __builtin_stdarg_start. */
diff --git include/iprt/stdint.h include/iprt/stdint.h
index ae94d66..c8c9551 100644
--- include/iprt/stdint.h
+++ include/iprt/stdint.h
@@ -34,6 +34,7 @@
  */
 #if !(defined(RT_OS_LINUX) && defined(__KERNEL__))  \
   && !(defined(RT_OS_FREEBSD) && defined(_KERNEL)) \
+  && !(defined(RT_OS_NETBSD) && defined(_KERNEL)) \
   && !defined(_MSC_VER) \
   && !defined(__IBMC__) \
   && !defined(__IBMCPP__) \
@@ -72,6 +73,16 @@
 # endif
 # include <sys/stdint.h>
 
+#elif defined(RT_OS_NETBSD) && defined(_KERNEL)
+
+# ifndef __STDC_CONSTANT_MACROS
+#  define __STDC_CONSTANT_MACROS
+# endif
+# ifndef __STDC_LIMIT_MACROS
+#  define __STDC_LIMIT_MACROS
+# endif
+# include <sys/stdint.h>
+
 #else /* No system stdint.h */
 
 /*
diff --git include/iprt/string.h include/iprt/string.h
index 22a4097..c0a7299 100644
--- include/iprt/string.h
+++ include/iprt/string.h
@@ -83,6 +83,12 @@
 # undef ffs
 # undef strpbrk
 
+#elif defined(RT_OS_NETBSD) && defined(_KERNEL)
+
+  RT_C_DECLS_BEGIN
+# include <lib/libkern/libkern.h>
+  RT_C_DECLS_END
+
 #else
 # include <string.h>
 #endif
diff --git include/iprt/time.h include/iprt/time.h
index a0021ba..9d4cbfd 100644
--- include/iprt/time.h
+++ include/iprt/time.h
@@ -330,7 +330,7 @@ DECLINLINE(PRTTIMESPEC) RTTimeSpecSubSeconds(PRTTIMESPEC pTime, int64_t i64Secon
 
 
 /* PORTME: Add struct timeval guard macro here. */
-#if defined(RTTIME_INCL_TIMEVAL) || defined(_STRUCT_TIMEVAL) || defined(_SYS__TIMEVAL_H_) || defined(_SYS_TIME_H) || defined(_TIMEVAL) || defined(_LINUX_TIME_H)
+#if defined(RTTIME_INCL_TIMEVAL) || defined(_STRUCT_TIMEVAL) || defined(_SYS__TIMEVAL_H_) || defined(_SYS_TIME_H) || defined(_TIMEVAL) || defined(_LINUX_TIME_H) || defined(_SYS_TIME_H_)
 /**
  * Gets the time as POSIX timeval.
  *
diff --git include/iprt/types.h include/iprt/types.h
index 52ddeef..b7bbfb3 100644
--- include/iprt/types.h
+++ include/iprt/types.h
@@ -88,6 +88,10 @@ RT_C_DECLS_END
 #  define _INTPTR_T_DECLARED
 #  include <sys/types.h>
 
+# elif defined(RT_OS_NETBSD) && defined(_KERNEL)
+
+#  include <sys/types.h>
+
 # elif defined(RT_OS_LINUX) && defined(__KERNEL__)
     /*
      * Kludge for the linux kernel:
@@ -207,6 +211,9 @@ typedef uint8_t bool;
 #   ifndef __bool_true_false_are_defined
 typedef _Bool bool;
 #   endif
+#  elif defined(RT_OS_NETBSD)
+#    undef bool
+typedef _Bool bool;
 #  else
 #   if (defined(RT_OS_DARWIN) || defined(RT_OS_HAIKU)) && (defined(_STDBOOL_H) || defined(__STDBOOL_H))
 #    undef bool
diff --git src/VBox/Additions/Makefile.kmk src/VBox/Additions/Makefile.kmk
index 413408a..5fb853c 100644
--- src/VBox/Additions/Makefile.kmk
+++ src/VBox/Additions/Makefile.kmk
@@ -73,6 +73,9 @@ ifndef VBOX_ONLY_TESTSUITE
  ifeq ($(KBUILD_TARGET),haiku)
   include $(PATH_SUB_CURRENT)/haiku/Makefile.kmk
  endif
+ ifeq ($(KBUILD_TARGET),netbsd)
+  include $(PATH_SUB_CURRENT)/netbsd/Makefile.kmk
+ endif
 
  ifeq ($(KBUILD_TARGET),linux)
   INSTALLS += LnxAddIso-scripts
diff --git src/VBox/Additions/common/VBoxGuest/Makefile.kmk src/VBox/Additions/common/VBoxGuest/Makefile.kmk
index 1ae3c47..fe775ff 100644
--- src/VBox/Additions/common/VBoxGuest/Makefile.kmk
+++ src/VBox/Additions/common/VBoxGuest/Makefile.kmk
@@ -19,7 +19,7 @@ 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 haiku $(if $(defined VBOX_WITH_ADDITION_DRIVERS),linux,) netbsd os2 solaris win)
  #
  # VBoxGuest - The Guest Additions Driver.
  #
@@ -28,6 +28,7 @@ if1of ($(KBUILD_TARGET), darwin freebsd haiku $(if $(defined VBOX_WITH_ADDITION_
  VBoxGuest_NAME.freebsd  = vboxguest
  VBoxGuest_NAME.haiku    = vboxguest
  VBoxGuest_NAME.linux    = vboxguest
+ VBoxGuest_NAME.netbsd  = vboxguest
  VBoxGuest_NAME.solaris  = vboxguest
  VBoxGuest_INST.darwin   = $(INST_ADDITIONS)VBoxGuest.kext/Contents/MacOS/
  ifdef VBOX_SIGN_ADDITIONS # See Additions/WINNT/Makefile.kmk?
@@ -53,10 +54,12 @@ if1of ($(KBUILD_TARGET), darwin freebsd haiku $(if $(defined VBOX_WITH_ADDITION_
  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)
  VBoxGuest_INCS.linux    = ../../../Runtime/r0drv/linux
  ifeq ($(KBUILD_HOST),solaris)
   VBoxGuest_LDFLAGS.solaris         += -N misc/ctf
@@ -79,7 +82,7 @@ if1of ($(KBUILD_TARGET), darwin freebsd haiku $(if $(defined VBOX_WITH_ADDITION_
     VBoxGuest.cpp_SDKS   = $(VBOX_WINDDK_GST_WLH)
    endif
   endif # win
-  ifn1of ($(KBUILD_TARGET), linux freebsd solaris haiku)
+  ifn1of ($(KBUILD_TARGET), linux freebsd solaris haiku netbsd)
    VBoxGuest_SOURCES    = VBoxGuest-$(KBUILD_TARGET).cpp
   else
    VBoxGuest_SOURCES    = VBoxGuest-$(KBUILD_TARGET).c
diff --git src/VBox/Additions/common/VBoxGuest/VBoxGuest-netbsd.c src/VBox/Additions/common/VBoxGuest/VBoxGuest-netbsd.c
new file mode 100644
index 0000000..920b798
--- /dev/null
+++ src/VBox/Additions/common/VBoxGuest/VBoxGuest-netbsd.c
@@ -0,0 +1,597 @@
+/* $Id: VBoxGuest-netbsd.c $ */
+/** @file
+ * VirtualBox Guest Additions Driver for NetBSD.
+ */
+
+/*
+ * Copyright (C) 2007-2011 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. */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/select.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+#include <sys/module.h>
+#include <sys/device.h>
+#include <sys/bus.h>
+#include <sys/poll.h>
+#include <sys/proc.h>
+#include <sys/stat.h>
+#include <sys/selinfo.h>
+#include <sys/queue.h>
+#include <sys/lock.h>
+#include <sys/types.h>
+#include <sys/conf.h>
+#include <sys/malloc.h>
+#include <sys/uio.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/vfs_syscalls.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcidevs.h>
+
+#ifdef PVM
+#  undef PVM
+#endif
+#include "VBoxGuestInternal.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>
+
+/** The module name. */
+#define DEVICE_NAME    "vboxguest"
+
+typedef struct VBoxGuestDeviceState
+{
+    device_t sc_dev;
+    struct pci_attach_args *pa;
+    bus_space_tag_t io_tag;
+    bus_space_handle_t io_handle;
+    bus_addr_t uIOPortBase;
+    bus_size_t io_regsize;
+    bus_space_tag_t iVMMDevMemResId;
+    bus_space_handle_t VMMDevMemHandle;
+    bus_addr_t pMMIOBase;
+    bus_size_t VMMDevMemSize;
+
+    pci_intr_handle_t ih;
+    /** Pointer to the IRQ handler. */
+    void              *pfnIrqHandler;
+    /** Controller features, limits and status. */
+    u_int                   vboxguest_state;
+} vboxguest_softc;
+
+
+struct vboxguest_session
+{
+    vboxguest_softc *sc;
+    PVBOXGUESTSESSION       session;
+};
+
+#define VBOXGUEST_STATE_INITOK 1 << 0
+
+/*
+ * Character device file handlers.
+ */
+static int VBoxGuestNetBSDOpen(dev_t device, int flags, int fmt, struct lwp *process);
+static int VBoxGuestNetBSDClose(struct file *fp);
+static int VBoxGuestNetBSDIOCtl(struct file *fp, u_long cmd, void *addr);
+static int VBoxGuestNetBSDPoll(struct file *fp, int events);
+static void VBoxGuestNetBSDAttach(device_t, device_t, void*);
+static int VBoxGuestNetBSDDetach(device_t pDevice, int flags);
+
+/*
+ * IRQ related functions.
+ */
+static void VBoxGuestNetBSDRemoveIRQ(vboxguest_softc *sc);
+static int  VBoxGuestNetBSDAddIRQ(vboxguest_softc *pvState);
+static int  VBoxGuestNetBSDISR(void *pvState);
+
+/*
+ * Device node entry points.
+ */
+static struct cdevsw g_VBoxGuestNetBSDChrDevSW =
+{
+    VBoxGuestNetBSDOpen,
+    noclose,
+    noread,
+    nowrite,
+    noioctl,
+    nostop,
+    notty,
+    nopoll,
+    nommap,
+    nokqfilter,
+    nodiscard
+};
+
+static const struct fileops vboxguest_fileops = {
+	.fo_read = fbadop_read,
+	.fo_write = fbadop_write,
+	.fo_ioctl = VBoxGuestNetBSDIOCtl,
+	.fo_fcntl = fnullop_fcntl,
+	.fo_poll = VBoxGuestNetBSDPoll,
+	.fo_stat = fbadop_stat,
+	.fo_close = VBoxGuestNetBSDClose,
+	.fo_kqfilter = fnullop_kqfilter,
+	.fo_restart = fnullop_restart
+};
+
+/** Device extention & session data association structure. */
+static VBOXGUESTDEVEXT      g_DevExt;
+/** selinfo structure used for polling. */
+static struct selinfo       g_SelInfo;
+/** Reference counter */
+static volatile uint32_t    cUsers;
+
+CFDRIVER_DECL(vboxguest, DV_DULL, NULL);
+extern struct cfdriver vboxguest_cd;
+
+/**
+ * File open handler
+ *
+ */
+static int VBoxGuestNetBSDOpen(dev_t device, int flags, int fmt, struct lwp *process)
+{
+    int rc;
+    vboxguest_softc *vboxguest;
+    struct vboxguest_session *session;
+    file_t *fp;
+    int fd, error;
+
+    LogFlow((DEVICE_NAME ":VBoxGuestNetBSDOpen\n"));
+
+    if ((vboxguest = device_lookup_private(&vboxguest_cd, minor(device))) == NULL) {
+        printf("device_lookup_private failed\n");
+        return (ENXIO);
+    }
+    if ((vboxguest->vboxguest_state & VBOXGUEST_STATE_INITOK) == 0) {
+        aprint_error_dev(vboxguest->sc_dev, "device not configured\n");
+        return (ENXIO);
+    }
+
+    session = kmem_alloc(sizeof(*session), KM_SLEEP);
+    if (session == NULL) {
+        return (ENOMEM);
+    }
+
+    session->sc = vboxguest;
+
+    if ((error = fd_allocfile(&fp, &fd)) != 0) {
+        kmem_free(session, sizeof(*session));
+        return error;
+    }
+
+    /*
+     * Create a new session.
+     */
+    rc = VBoxGuestCreateUserSession(&g_DevExt, &session->session);
+    if (! RT_SUCCESS(rc))
+    {
+        aprint_error_dev(vboxguest->sc_dev, "VBox session creation failed\n");
+        closef(fp); /* ??? */
+        kmem_free(session, sizeof(*session));
+        return RTErrConvertToErrno(rc);
+    }
+    ASMAtomicIncU32(&cUsers);
+    return fd_clone(fp, fd, flags, &vboxguest_fileops, session);
+
+}
+
+/**
+ * File close handler
+ *
+ */
+static int VBoxGuestNetBSDClose(struct file *fp)
+{
+    struct vboxguest_session *session = fp->f_data;
+    vboxguest_softc *vboxguest = session->sc;
+
+    VBoxGuestCloseSession(&g_DevExt, session->session);
+    ASMAtomicDecU32(&cUsers);
+
+    kmem_free(session, sizeof(*session));
+
+    return 0;
+}
+
+/**
+ * IOCTL handler
+ *
+ */
+static int VBoxGuestNetBSDIOCtl(struct file *fp, u_long command, void *data)
+{
+    struct vboxguest_session *session = fp->f_data;
+    vboxguest_softc *vboxguest = session->sc;
+
+    int rc = 0;
+
+    /*
+     * Validate the request wrapper.
+     */
+    if (IOCPARM_LEN(command) != sizeof(VBGLBIGREQ)) {
+        Log((DEVICE_NAME ": VBoxGuestFreeBSDIOCtl: bad request %lu size=%lu expected=%d\n", command, IOCPARM_LEN(command), sizeof(VBGLBIGREQ)));
+        return ENOTTY;
+    }
+
+    PVBGLBIGREQ ReqWrap = (PVBGLBIGREQ)data;
+    if (ReqWrap->u32Magic != VBGLBIGREQ_MAGIC)
+    {
+        Log((DEVICE_NAME ": VBoxGuestNetBSDIOCtl: bad magic %#x; pArg=%p Cmd=%lu.\n", ReqWrap->u32Magic, data, command));
+        return EINVAL;
+    }
+    if (RT_UNLIKELY(   ReqWrap->cbData == 0
+                    || ReqWrap->cbData > _1M*16))
+    {
+        printf(DEVICE_NAME ": VBoxGuestNetBSDIOCtl: bad size %#x; pArg=%p Cmd=%lu.\n", ReqWrap->cbData, data, command);
+        return EINVAL;
+    }
+
+    /*
+     * Read the request.
+     */
+    void *pvBuf = RTMemTmpAlloc(ReqWrap->cbData);
+    if (RT_UNLIKELY(!pvBuf))
+    {
+        Log((DEVICE_NAME ":VBoxGuestNetBSDIOCtl: 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((DEVICE_NAME ":VBoxGuestNetBSDIOCtl: copyin failed; pvBuf=%p pArg=%p Cmd=%lu. rc=%d\n", pvBuf, data, command, rc));
+aprint_error_dev(vboxguest->sc_dev, "copyin failed\n");
+        return EFAULT;
+    }
+    if (RT_UNLIKELY(   ReqWrap->cbData != 0
+                    && !VALID_PTR(pvBuf)))
+    {
+        RTMemTmpFree(pvBuf);
+        Log((DEVICE_NAME ":VBoxGuestNetBSDIOCtl: pvBuf invalid pointer %p\n", pvBuf));
+        return EINVAL;
+    }
+
+    /*
+     * Process the IOCtl.
+     */
+    size_t cbDataReturned;
+    rc = VBoxGuestCommonIOCtl(command, &g_DevExt, session->session, pvBuf, ReqWrap->cbData, &cbDataReturned);
+    if (RT_SUCCESS(rc)) {
+        rc = 0;
+        if (RT_UNLIKELY(cbDataReturned > ReqWrap->cbData))
+        {
+            Log((DEVICE_NAME ":VBoxGuestNetBSDIOCtl: 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((DEVICE_NAME ":VBoxGuestNetBSDIOCtl: copyout failed; pvBuf=%p pArg=%p. rc=%d\n", pvBuf, data, rc));
+            }
+        }
+    } else {
+        Log((DEVICE_NAME ":VBoxGuestNetBSDIOCtl: VBoxGuestCommonIOCtl failed. rc=%d\n", rc));
+        rc = -rc;
+    }
+    RTMemTmpFree(pvBuf);
+    return rc;
+}
+
+static int VBoxGuestNetBSDPoll(struct file *fp, int events)
+{
+    struct vboxguest_session *session = fp->f_data;
+    vboxguest_softc *vboxguest = session->sc;
+
+    int rc = 0;
+    int events_processed;
+
+    uint32_t u32CurSeq = ASMAtomicUoReadU32(&g_DevExt.u32MousePosChangedSeq);
+    if (session->session->u32MousePosChangedSeq != u32CurSeq) {
+        events_processed = events & (POLLIN | POLLRDNORM);
+        session->session->u32MousePosChangedSeq = u32CurSeq;
+    } else {
+        events_processed = 0;
+
+        selrecord(curlwp, &g_SelInfo);
+    }
+
+    return events_processed;
+}
+
+static int VBoxGuestNetBSDDetach(device_t self, int flags)
+{
+    vboxguest_softc *vboxguest;
+    vboxguest = device_private(self);
+
+    if (cUsers > 0)
+        return EBUSY;
+
+    if ((vboxguest->vboxguest_state & VBOXGUEST_STATE_INITOK) == 0) {
+        return 0;
+    }
+
+    /*
+     * Reverse what we did in VBoxGuestNetBSDAttach.
+     */
+
+    VBoxGuestNetBSDRemoveIRQ(vboxguest);
+
+    VBoxGuestDeleteDevExt(&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 VBoxGuestNetBSDISR(void *pvState)
+{
+    LogFlow((DEVICE_NAME ":VBoxGuestNetBSDISR pvState=%p\n", pvState));
+
+    bool fOurIRQ = VBoxGuestCommonISR(&g_DevExt);
+
+    return fOurIRQ ? 0 : 1;
+}
+
+void VBoxGuestNativeISRMousePollEvent(PVBOXGUESTDEVEXT pDevExt)
+{
+    LogFlow((DEVICE_NAME "::NativeISRMousePollEvent:\n"));
+
+    /*
+     * Wake up poll waiters.
+     */
+    selnotify(&g_SelInfo, 0, 0);
+}
+
+/**
+ * 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 VBoxGuestNetBSDAddIRQ(vboxguest_softc *vboxguest)
+{
+    int iResId = 0;
+    int rc = 0;
+    struct pci_attach_args *pa = vboxguest->pa;
+    const char *intrstr;
+    char intstrbuf[100];
+
+    if (pci_intr_map(pa, &vboxguest->ih)) {
+        aprint_error_dev(vboxguest->sc_dev, "couldn't map interrupt.\n");
+        return VERR_DEV_IO_ERROR;
+    }
+    intrstr = pci_intr_string(vboxguest->pa->pa_pc, vboxguest->ih,
+            intstrbuf, sizeof(intstrbuf));
+    aprint_normal_dev(vboxguest->sc_dev, "interrupting at %s\n", intrstr);
+    vboxguest->pfnIrqHandler = pci_intr_establish(vboxguest->pa->pa_pc, vboxguest->ih, IPL_BIO, VBoxGuestNetBSDISR, vboxguest);
+    if (vboxguest->pfnIrqHandler == NULL) {
+        aprint_error_dev(vboxguest->sc_dev, "couldn't establish interrupt\n");
+        return VERR_DEV_IO_ERROR;
+    }
+
+    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 VBoxGuestNetBSDRemoveIRQ(vboxguest_softc *vboxguest)
+{
+    if (vboxguest->pfnIrqHandler)
+    {
+        pci_intr_disestablish(vboxguest->pa->pa_pc, vboxguest->pfnIrqHandler);
+    }
+}
+
+static void VBoxGuestNetBSDAttach(device_t parent, device_t self, void *aux)
+{
+    int rc = VINF_SUCCESS;
+    int iResId = 0;
+    vboxguest_softc *vboxguest;
+    struct pci_attach_args *pa = aux;
+    bus_space_tag_t iot, memt;
+    bus_space_handle_t ioh, memh;
+    bus_dma_segment_t seg;
+    int ioh_valid, memh_valid;
+
+    cUsers = 0;
+
+    aprint_normal(": VirtualBox Guest\n");
+
+    vboxguest = device_private(self);
+    vboxguest->sc_dev = self;
+
+    /*
+     * Initialize IPRT R0 driver, which internally calls OS-specific r0 init.
+     */
+    rc = RTR0Init(0);
+    if (RT_FAILURE(rc))
+    {
+        LogFunc(("RTR0Init failed.\n"));
+        aprint_error_dev(vboxguest->sc_dev, "RTR0Init failed\n");
+        return ;
+    }
+
+    vboxguest->pa = pa;
+
+    /*
+     * Allocate I/O port resource.
+     */
+    ioh_valid = (pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0, &vboxguest->io_tag, &vboxguest->io_handle, &vboxguest->uIOPortBase, &vboxguest->io_regsize) == 0);
+
+    if (ioh_valid)
+    {
+
+        /*
+         * Map the MMIO region.
+         */
+        memh_valid = (pci_mapreg_map(pa, PCI_MAPREG_START+4, PCI_MAPREG_TYPE_MEM, BUS_SPACE_MAP_LINEAR, &vboxguest->iVMMDevMemResId, &vboxguest->VMMDevMemHandle, &vboxguest->pMMIOBase, &vboxguest->VMMDevMemSize) == 0);
+        if (memh_valid)
+        {
+            /*
+             * Call the common device extension initializer.
+             */
+            rc = VBoxGuestInitDevExt(&g_DevExt, vboxguest->uIOPortBase,
+                    bus_space_vaddr(vboxguest->iVMMDevMemResId,
+                            vboxguest->VMMDevMemHandle),
+                                    vboxguest->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 = VBoxGuestNetBSDAddIRQ(vboxguest);
+                if (RT_SUCCESS(rc))
+                {
+                    vboxguest->vboxguest_state |= VBOXGUEST_STATE_INITOK;
+                    return ;
+                }
+                VBoxGuestDeleteDevExt(&g_DevExt);
+            } else {
+                aprint_error_dev(vboxguest->sc_dev, "init failed\n");
+            }
+        } else {
+            aprint_error_dev(vboxguest->sc_dev, "MMIO mapping failed\n");
+        }
+    } else {
+        aprint_error_dev(vboxguest->sc_dev, "IO mapping failed\n");
+    }
+
+    RTR0Term();
+    return ;
+}
+
+static int
+VBoxGuestNetBSDMatch(device_t parent, cfdata_t match, void *aux)
+{
+    const struct pci_attach_args *pa = aux;
+    if ((PCI_VENDOR(pa->pa_id) == VMMDEV_VENDORID)
+            && (PCI_PRODUCT(pa->pa_id) == VMMDEV_DEVICEID)) {
+        return 1;
+    } else {
+        return 2;
+    }
+}
+
+/* Common code that depend on g_DevExt. */
+#include "VBoxGuestIDC-unix.c.h"
+
+CFATTACH_DECL_NEW(vboxguest, sizeof(vboxguest_softc),
+    VBoxGuestNetBSDMatch, VBoxGuestNetBSDAttach, VBoxGuestNetBSDDetach, NULL);
+
+MODULE(MODULE_CLASS_DRIVER, vboxguest, "pci");
+
+static int loc[2] = {-1, -1};
+
+static const struct cfparent pspec = {
+	"pci", "pci", DVUNIT_ANY
+};
+
+static struct cfdata vboxguest_cfdata[] = {
+        {
+                .cf_name = "vboxguest",
+                .cf_atname = "vboxguest",
+                .cf_unit = 0,           /* Only unit 0 is ever used  */
+                .cf_fstate = FSTATE_STAR,
+                .cf_loc = loc,
+                .cf_flags = 0,
+                .cf_pspec = &pspec,
+        },
+        { NULL, NULL, 0, 0, NULL, 0, NULL }
+};
+
+static int
+vboxguest_modcmd(modcmd_t cmd, void *opaque)
+{
+    devmajor_t bmajor, cmajor;
+    int error;
+    register_t retval;
+
+    bmajor = cmajor = NODEVMAJOR;
+    switch (cmd) {
+        case MODULE_CMD_INIT:
+                error = config_cfdriver_attach(&vboxguest_cd);
+                if (error) {
+                    printf("config_cfdriver_attach failed: %d", error);
+                    break;
+                }
+                error = config_cfattach_attach(vboxguest_cd.cd_name, &vboxguest_ca);
+                if (error) {
+                    config_cfdriver_detach(&vboxguest_cd);
+                    printf("%s: unable to register cfattach\n", vboxguest_cd.cd_name);
+                    break;
+                }
+
+                error = config_cfdata_attach(vboxguest_cfdata, 1);
+                if (error) {
+                        printf("%s: unable to attach cfdata\n", vboxguest_cd.cd_name);
+                        config_cfattach_detach(vboxguest_cd.cd_name, &vboxguest_ca);
+                        config_cfdriver_detach(&vboxguest_cd);
+                        break;
+                }
+
+                error = devsw_attach("vboxguest", NULL, &bmajor, &g_VBoxGuestNetBSDChrDevSW, &cmajor);
+                
+                if (error == EEXIST)
+                        error = 0; /* maybe built-in ... improve eventually */
+                if (error)
+                        break;
+
+                error = do_sys_mknod(curlwp, "/dev/vboxguest", 0666|S_IFCHR, makedev(cmajor, 0), &retval, UIO_SYSSPACE);
+                if (error == EEXIST)
+                        error = 0;
+                break;
+        case MODULE_CMD_FINI:
+                error = config_cfdata_detach(vboxguest_cfdata);
+                if (error)
+                    break;
+                error = config_cfattach_detach(vboxguest_cd.cd_name, &vboxguest_ca);
+                if (error)
+                    break;
+                config_cfdriver_detach(&vboxguest_cd);
+                error = devsw_detach(NULL, &g_VBoxGuestNetBSDChrDevSW);
+                break;
+        default:
+                return ENOTTY;
+    }
+    return error;
+}
diff --git src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp
index 7abe60e..70e7290 100644
--- src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp
+++ src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3Lib.cpp
@@ -40,10 +40,11 @@
    || defined(RT_OS_FREEBSD) \
    || defined(RT_OS_HAIKU) \
    || defined(RT_OS_LINUX) \
+   || defined(RT_OS_NETBSD) \
    || defined(RT_OS_SOLARIS)
 # include <sys/types.h>
 # include <sys/stat.h>
-# if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) /** @todo check this on solaris+freebsd as well. */
+# if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_NETBSD) /** @todo check this on solaris+freebsd as well. */
 #  include <sys/ioctl.h>
 # endif
 # if defined(RT_OS_DARWIN)
@@ -252,7 +253,7 @@ static int vbglR3Init(const char *pszDeviceName)
 
 #else
 
-    /* The default implementation. (linux, solaris, freebsd, haiku) */
+    /* The default implementation. (linux, solaris, freebsd, haiku, netbsd) */
     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, void *pvData, size_t cbData)
     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, void *pvData, size_t cbData)
     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
diff --git src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
index d8dbe7c..929716f 100644
--- src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
+++ src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
@@ -47,7 +47,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 */
@@ -1015,7 +1015,7 @@ static int vboxserviceVMInfoWriteNetwork(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 */
diff --git src/VBox/Additions/common/crOpenGL/Makefile.kmk src/VBox/Additions/common/crOpenGL/Makefile.kmk
index 1827856..e0fd6c3 100644
--- src/VBox/Additions/common/crOpenGL/Makefile.kmk
+++ src/VBox/Additions/common/crOpenGL/Makefile.kmk
@@ -31,7 +31,7 @@ DLLS.win += \
     VBoxOGLpackspu \
     VBoxOGLfeedbackspu
 
-if1of ($(KBUILD_TARGET), linux solaris freebsd)
+if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
 DLLS += \
     VBoxOGL \
     VBoxOGLarrayspu \
@@ -51,7 +51,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
@@ -60,7 +60,7 @@ if1of ($(KBUILD_TARGET), linux solaris freebsd)
  # 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
@@ -72,7 +72,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 \
@@ -127,7 +127,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
@@ -145,6 +145,8 @@ if1of ($(KBUILD_TARGET), linux solaris freebsd)
  	$(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
@@ -158,6 +160,9 @@ if1of ($(KBUILD_TARGET), linux solaris freebsd)
    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
@@ -165,6 +170,8 @@ if1of ($(KBUILD_TARGET), linux solaris freebsd)
   	$(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 += \
@@ -173,6 +180,8 @@ if1of ($(KBUILD_TARGET), linux solaris freebsd)
   	$(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
 
@@ -213,14 +222,14 @@ VBoxOGL_LIBS = \
 	$(VBOX_LIB_VBGL_R3_SHARED) \
 	$(VBOX_LIB_OGL_CRUTIL) \
 	$(PATH_STAGE_LIB)/additions/VBoxOGLspuload$(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)
+  if1of ($(KBUILD_TARGET), freebsd netbsd)
     VBoxOGL_LIBS += \
         elf
   else
@@ -301,8 +310,8 @@ $(VBOX_PATH_CROGL_GENFILES)/cropengl-x86.def: $(PATH_SUB_CURRENT)/defs.py $(VBOX
  endif #ifdef VBOX_WITH_WDDM
 
 
-else if1of ($(KBUILD_TARGET), freebsd linux solaris)
- # FreeBSD, Linux, Solaris
+else if1of ($(KBUILD_TARGET), freebsd linux netbsd solaris)
+ # FreeBSD, Linux, NetBSD, Solaris
 $(VBOX_PATH_CROGL_GENFILES)/getprocaddress.c: $(PATH_SUB_CURRENT)/getprocaddress.py $(VBOX_CROGL_API_FILES) | $$(dir $$@)
 	$(call MSG_GENERATE,python,$@,$<)
 	$(QUIET)$(call VBOX_CROGL_PYTHON_ENV,$(VBOX_PATH_CROGL_PYTHON_INCLUDE),$@) $(VBOX_BLD_PYTHON) $< $(VBOX_PATH_CROGL_GLAPI)
@@ -324,6 +333,14 @@ $(VBOX_PATH_CROGL_GENFILES)/freebsd_exports.c: \
 	$(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 \
@@ -362,6 +379,14 @@ $(VBOX_PATH_CROGL_GENFILES)/freebsd_exports_dri.asm: \
 	$(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 \
@@ -416,6 +441,15 @@ $(VBOX_PATH_CROGL_GENFILES)/freebsd_exports.c: \
 		| $$(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 \
@@ -435,7 +469,7 @@ endif
 VBoxOGLarrayspu_TEMPLATE      = VBOXCROGLR3GUESTDLL
 VBoxOGLarrayspu_INCS          = \
 	array
-if1of ($(KBUILD_TARGET), linux solaris freebsd)
+if1of ($(KBUILD_TARGET), linux solaris freebsd netbsd)
  VBoxOGLarrayspu_INCS += \
         $(VBOX_MESA_INCS)
 endif
@@ -483,7 +517,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
@@ -532,7 +566,7 @@ VBoxOGLpackspu_TEMPLATE      = VBOXCROGLR3GUESTDLL
 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
@@ -631,7 +665,7 @@ $(VBOX_PATH_CROGL_GENFILES)/packspu_proto.h: $(addprefix $(PATH_SUB_CURRENT)/pac
 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
diff --git src/VBox/Additions/common/crOpenGL/NetBSD_exports.py src/VBox/Additions/common/crOpenGL/NetBSD_exports.py
new file mode 100644
index 0000000..8f63e0a
--- /dev/null
+++ 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 src/VBox/Additions/common/crOpenGL/fakedri_drv.c src/VBox/Additions/common/crOpenGL/fakedri_drv.c
index f6793da..1ba261d 100644
--- src/VBox/Additions/common/crOpenGL/fakedri_drv.c
+++ 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/divers/"
 # 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/divers/"
 # 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, void *pDst, const void *pSrc, unsigned lo
 
 #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
@@ -696,6 +702,20 @@ void __attribute__ ((constructor)) vbox_install_into_mesa(void)
     vboxFillGLXAPITable(&glxim);
     /* Now patch functions exported by libGL.so */
     vboxPatchMesaExports();
+
+#if defined(RT_OS_NETBSD)
+    /*
+     * libGL.so will fail to load this because
+     * "core dri or dri2 extension not found".
+     * As it happens with vboxvideo, this is something that more or less should
+     * happen. However, in that case this library will be unloaded and
+     * everything breaks.
+     * So open self to prevent this.
+     * XXX: I don't know why things work on Linux but not on NetBSD.
+     */
+    /* XXX: hardcoded path */
+    dlopen("/usr/X11R7/lib/modules/dri/vboxvideo_dri.so", 0);
+#endif
 }
 
 /*
diff --git src/VBox/Additions/common/crOpenGL/load.c src/VBox/Additions/common/crOpenGL/load.c
index 5864aea..60c2078 100644
--- src/VBox/Additions/common/crOpenGL/load.c
+++ src/VBox/Additions/common/crOpenGL/load.c
@@ -481,7 +481,11 @@ static void stubSPUSafeTearDown(void)
 }
 
 
+#if defined(RT_OS_NETBSD)
+static void __attribute__ ((destructor)) stubExitHandler(void)
+#else
 static void stubExitHandler(void)
+#endif
 {
     stubSPUSafeTearDown();
     signal(SIGTERM, SIG_DFL);
@@ -570,7 +574,7 @@ static void stubInitVars(void)
 #endif
     crHashtableAdd(stub.windowTable, 0, defaultWin);
 
-#if 1
+#if !defined(RT_OS_NETBSD)
     atexit(stubExitHandler);
     signal(SIGTERM, stubSignalHandler);
     signal(SIGINT, stubSignalHandler);
diff --git src/VBox/Additions/netbsd/Makefile.kmk src/VBox/Additions/netbsd/Makefile.kmk
new file mode 100644
index 0000000..4d0de81
--- /dev/null
+++ src/VBox/Additions/netbsd/Makefile.kmk
@@ -0,0 +1,29 @@
+# $Id: Makefile.kmk $
+## @file
+# Sub-Makefile for the NetBSD guest additions base directory.
+#
+
+#
+# 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.
+#
+
+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
+
+include $(FILE_KBUILD_SUB_FOOTER)
diff --git src/VBox/Additions/netbsd/drm/Makefile.kmk src/VBox/Additions/netbsd/drm/Makefile.kmk
new file mode 100644
index 0000000..3a742de
--- /dev/null
+++ src/VBox/Additions/netbsd/drm/Makefile.kmk
@@ -0,0 +1,53 @@
+# $Id: Makefile.kmk $
+## @file
+# Sub-Makefile for the vboxvideo DRM module (NetBSD kernel OpenGL module).
+#
+
+#
+# Copyright (C) 2009-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.
+#
+
+
+SUB_DEPTH = ../../../../..
+include $(KBUILD_PATH)/subheader.kmk
+
+ifdef VBOX_WITH_ADDITION_DRIVERS
+ SYSMODS  += vboxdrm
+endif
+ifneq ($(KBUILD_HOST),netbsd)
+$(error "The NetBSD guest additions can only be built on NetBSD!")
+endif
+
+#
+# vboxdrm - The Video DRM (Direct Rendering Module) kernel module
+#
+vboxdrm_TEMPLATE      = VBOXGUESTR0
+vboxdrm_NAME          = vboxdrm
+vboxdrm_DEFS          = _MODULE _KERNEL __KERNEL__
+vboxdrm_INCS.netbsd  += \
+    $(vboxdrm_0_OUTDIR) \
+    $(VBOX_NETBSD_SRC)/external/bsd/common/include \
+    $(VBOX_NETBSD_SRC)/external/bsd/drm2/include \
+    $(VBOX_NETBSD_SRC)/external/bsd/drm2/dist/uapi \
+    $(VBOX_NETBSD_SRC)/external/bsd/drm2/dist/include
+
+vboxdrm_SOURCES       = vbox_drv.c
+vboxdrm_LIBS          = 
+vboxdrm_ORDERDEPS.netbsd = $(vboxdrm_0_OUTDIR)/opt_drm.h
+vboxdrm_CLEAN.netbsd = $(vboxdrm_DEPS)
+
+# Header for DRM not included by us.
+$$(vboxdrm_0_OUTDIR)/opt_drm.h:
+	$(QUIET)$(MKDIR) -p $(vboxdrm_0_OUTDIR)
+	$(QUIET)touch $(vboxdrm_0_OUTDIR)/opt_drm.h
+
+include $(FILE_KBUILD_SUB_FOOTER)
+
diff --git src/VBox/Additions/netbsd/drm/vbox_drv.c src/VBox/Additions/netbsd/drm/vbox_drv.c
new file mode 100644
index 0000000..f1bb8b7
--- /dev/null
+++ src/VBox/Additions/netbsd/drm/vbox_drv.c
@@ -0,0 +1,214 @@
+/* $NetBSD: vbox_drv.c,v 1.2 2011/08/28 17:18:31 jmcneill Exp $ */
+
+/*
+ * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: vbox_drv.c,v 1.2 2011/08/28 17:18:31 jmcneill Exp $");
+
+#include "product-generated.h"
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+#include <sys/module.h>
+#include <sys/mount.h>
+#include <drm/drmP.h>
+#include <dev/pci/pcivar.h>
+
+struct vboxdrm_softc {
+    device_t dev;
+    struct pci_dev pci_dev;
+    struct drm_device *drm_dev;
+};
+
+static int
+vboxdrm_driver_load(struct drm_device *dev, unsigned long flags)
+{
+    return 0;
+}
+
+static struct drm_driver vboxdrm_driver =
+{
+    .load = vboxdrm_driver_load,
+    .mmap_object = &drm_gem_or_legacy_mmap_object,
+    .fops = NULL,
+    .name = "vboxvideo",
+    .desc = VBOX_PRODUCT " Graphics Card",
+    .date = "20090303",
+    .major = 1,
+    .minor = 0,
+    .patchlevel = 0
+};
+
+static int
+vboxdrm_match(device_t parent, cfdata_t match, void *opaque)
+{
+    const struct pci_attach_args *const pa = opaque;
+
+printf("vboxdrm_match\n");
+
+    if (PCI_VENDOR(pa->pa_id) != 0x80EE) {
+        return 0;
+    }
+    if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY) {
+        return 0;
+    }
+    if (PCI_PRODUCT(pa->pa_id) != 0xBEEF) {
+        return 0;
+    }
+
+    return 1;
+}
+
+static void
+vboxdrm_attach(device_t parent, device_t self, void *opaque)
+{
+    const struct pci_attach_args *const pa = opaque;
+    struct vboxdrm_softc *sc = device_private(self);
+    const unsigned long cookie = (unsigned long)(uintptr_t)sc;
+    int error;
+
+    sc->dev = self;
+
+    pci_aprint_devinfo(pa, NULL);
+
+	pmf_device_register(self, NULL, NULL);
+
+    error = -drm_pci_attach(self, pa, &sc->pci_dev, &vboxdrm_driver, cookie,
+        &sc->drm_dev);
+    if (error) {
+        aprint_error_dev(self, "drm_pci_attach: %d\n", error);
+        return;
+    }
+}
+
+static int
+vboxdrm_detach(device_t self, int flags)
+{
+    struct vboxdrm_softc *sc = device_private(self);
+    int error;
+
+	pmf_device_deregister(self);
+
+    if (sc->drm_dev == NULL) {
+        return 0;
+    }
+
+    error = -drm_pci_detach(sc->drm_dev, flags);
+    if (error) {
+        aprint_error_dev(self, "drm_pci_detach: %d\n", error);
+        return error;
+    }
+    sc->drm_dev = NULL;
+
+    return 0;
+}
+
+CFATTACH_DECL_NEW(
+    vboxdrm,
+    sizeof(struct vboxdrm_softc),
+    vboxdrm_match,
+    vboxdrm_attach,
+    vboxdrm_detach,
+    NULL
+);
+
+MODULE(MODULE_CLASS_DRIVER, vboxdrm, "drmkms,drmkms_pci");
+
+CFDRIVER_DECL(vboxdrm, DV_DULL, NULL);
+
+static struct cfdriver * const cfdriver_ioconf_vboxdrm[] = {
+	&vboxdrm_cd,
+	NULL
+};
+
+extern struct cfattach vboxdrm_ca;
+
+/* locators */
+static int loc[1] = {-1};
+
+static const struct cfparent pspec0 = {
+	"drm", NULL, DVUNIT_ANY
+};
+
+#define NORM FSTATE_NOTFOUND
+#define STAR FSTATE_STAR
+
+static struct cfdata cfdata_ioconf_vboxdrm[] = {
+    /* driver           attachment    unit state loc   flags pspec */
+/*  0: vboxdrm* at pci? dev ? function ? */
+    { "vboxdrm",		"vboxdrm",	 0, STAR,     loc,      0, &pspec0 },
+    { NULL,		NULL,		 0, 0,    NULL,      0, NULL }
+};
+
+static struct cfattach * const vboxdrm_cfattachinit[] = {
+	&vboxdrm_ca, NULL
+};
+
+static const struct cfattachinit cfattach_ioconf_vboxdrm[] = {
+	{ "vboxdrm", vboxdrm_cfattachinit },
+	{ NULL, NULL }
+};
+
+static int
+vboxdrm_modcmd(modcmd_t cmd, void *opaque)
+{
+    extern int drm_guarantee_initialized(void);
+
+    int error;
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+        error = drm_guarantee_initialized();
+        if (error) {
+            aprint_error("vboxdrm: drm_guarantee_initialized: %d\n", error);
+            return error;
+        }
+        error = drm_pci_init(&vboxdrm_driver, NULL);
+        if (error) {
+            aprint_error("vboxdrm: drm_pci_init failed\n");
+            return error;
+        }
+		error = config_init_component(cfdriver_ioconf_vboxdrm,
+		    cfattach_ioconf_vboxdrm, cfdata_ioconf_vboxdrm);
+        if (error) {
+            aprint_error("vboxdrm: failed to init component: %d\n", error);
+            return error;
+        }
+        return 0;
+	case MODULE_CMD_FINI:
+		error = config_fini_component(cfdriver_ioconf_vboxdrm,
+		    cfattach_ioconf_vboxdrm, cfdata_ioconf_vboxdrm);
+        if (error) {
+            aprint_error("vboxdrm: failed to fini component: %d\n", error);
+            return error;
+        }
+        drm_pci_exit(&vboxdrm_driver, NULL);
+        return 0;
+	default:
+		return ENOTTY;
+	}
+}
diff --git src/VBox/Additions/x11/VBoxClient/Makefile.kmk src/VBox/Additions/x11/VBoxClient/Makefile.kmk
index 9a4e587..6611827 100644
--- src/VBox/Additions/x11/VBoxClient/Makefile.kmk
+++ src/VBox/Additions/x11/VBoxClient/Makefile.kmk
@@ -41,6 +41,8 @@ VBoxClient_LIBS.freebsd = \
 	iconv
 VBoxClient_LIBS.linux = \
 	dl
+VBoxClient_LIBS.netbsd = \
+	pthread
 VBoxClient_LIBS.solaris = \
 	dl
 VBoxClient_LIBS = \
@@ -52,6 +54,8 @@ VBoxClient_LIBS = \
 VBoxClient_LIBS += \
 	supc++ \
 	gcc_eh
+VBoxClient_LDFLAGS.netbsd += \
+    -Wl,-rpath /usr/X11R7/lib
 ifdef VBOX_X11_SEAMLESS_GUEST
  VBoxClient_DEFS += SEAMLESS_GUEST DYNAMIC_RESIZE
  VBoxClient_SOURCES += \
diff --git src/VBox/Additions/x11/VBoxClient/seamless-guest.h src/VBox/Additions/x11/VBoxClient/seamless-guest.h
index e468531..9d6b05c 100644
--- src/VBox/Additions/x11/VBoxClient/seamless-guest.h
+++ src/VBox/Additions/x11/VBoxClient/seamless-guest.h
@@ -43,7 +43,7 @@ public:
     };
 };
 
-#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)
 # include "seamless-x11.h"  /* for VBoxGuestSeamlessGuestImpl */
 #else
 # error Port me
diff --git src/VBox/Additions/x11/vboxvideo/Makefile.kmk src/VBox/Additions/x11/vboxvideo/Makefile.kmk
index 7a9a0c8..edc6ffb 100644
--- src/VBox/Additions/x11/vboxvideo/Makefile.kmk
+++ src/VBox/Additions/x11/vboxvideo/Makefile.kmk
@@ -33,7 +33,7 @@ endif
 vboxvideo_13_DEFS := $(vboxvideo_70_DEFS) VBOXVIDEO_13
 vboxvideo_15_DEFS := \
 	$(vboxvideo_13_DEFS) NO_ANSIC PCIACCESS XSERVER_LIBPCIACCESS
-if1of ($(KBUILD_TARGET), linux solaris)
+if1of ($(KBUILD_TARGET), linux netbsd solaris)
  vboxvideo_15_DEFS += \
  	VBOX_DRI
 endif
@@ -198,7 +198,7 @@ DLLS += vboxvideo_drv_15
 vboxvideo_drv_15_TEMPLATE = VBOXGUESTR3XORGMOD
 vboxvideo_drv_15_CFLAGS := $(vboxvideo_drv_70_CFLAGS)
 vboxvideo_drv_15_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=100503000
-if1of ($(KBUILD_TARGET), linux solaris)
+if1of ($(KBUILD_TARGET), linux netbsd solaris)
  vboxvideo_drv_15_DEFS += \
  	VBOX_DRI_OLD
 endif
@@ -207,7 +207,7 @@ vboxvideo_drv_15_INCS = \
 	$(VBOX_PATH_X11_ROOT)/xorg-server-1.5.3
 vboxvideo_drv_15_INCS += $(PATH_ROOT)/src/VBox/Runtime/include
 vboxvideo_drv_15_SOURCES  = $(vboxvideo_drv_13_SOURCES)
-if1of ($(KBUILD_TARGET), linux solaris)
+if1of ($(KBUILD_TARGET), linux netbsd solaris)
  vboxvideo_drv_15_SOURCES += \
  	vboxvideo_dri.c
 endif
@@ -220,7 +220,7 @@ DLLS += vboxvideo_drv_16
 vboxvideo_drv_16_TEMPLATE = VBOXGUESTR3XORGMOD
 vboxvideo_drv_16_CFLAGS := $(vboxvideo_drv_70_CFLAGS)
 vboxvideo_drv_16_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=100600000
-if1of ($(KBUILD_TARGET), linux solaris)
+if1of ($(KBUILD_TARGET), linux netbsd solaris)
  vboxvideo_drv_16_DEFS += \
  	VBOX_DRI_OLD
 endif
@@ -243,12 +243,11 @@ vboxvideo_drv_17_INCS = \
 	$(VBOX_PATH_X11_ROOT)/xorg-server-1.7.7
 vboxvideo_drv_17_INCS += $(PATH_ROOT)/src/VBox/Runtime/include
 vboxvideo_drv_17_SOURCES := $(vboxvideo_drv_13_SOURCES)
-if1of ($(KBUILD_TARGET), linux solaris)
+if1of ($(KBUILD_TARGET), linux netbsd solaris)
  vboxvideo_drv_17_SOURCES += \
  	vboxvideo_dri2.c
 endif
 
-
 #
 # vboxvideo_drv_18
 #
diff --git src/VBox/Additions/x11/x11stubs/Makefile.kmk src/VBox/Additions/x11/x11stubs/Makefile.kmk
index d7c4d86..e7a703b 100644
--- src/VBox/Additions/x11/x11stubs/Makefile.kmk
+++ src/VBox/Additions/x11/x11stubs/Makefile.kmk
@@ -27,6 +27,7 @@ libXcomposite_TEMPLATE   = VBoxGuestR3Dll
 libXcomposite_INST       = $(INST_LIB)
 # This may need fixing later.
 libXcomposite_SONAME     = libXcomposite.so.1
+libXcomposite_SONAME.netbsd     = libXcomposite.so.2
 libXcomposite_SOURCES    = libXcomposite-1.0.0/libXcomposite.c
 
 #
@@ -37,6 +38,7 @@ libXdamage_TEMPLATE   = VBoxGuestR3Dll
 libXdamage_INST       = $(INST_LIB)
 # This may need fixing later.
 libXdamage_SONAME     = libXdamage.so.1
+libXdamage_SONAME.netbsd     = libXdamage.so.2
 libXdamage_SOURCES    = libXdamage-1.1.0/libXdamage.c
 
 #
@@ -48,6 +50,7 @@ libXfixes_INST       = $(INST_LIB)
 # This may need fixing later.
 libXfixes_SONAME.linux      = libXfixes.so.3
 libXfixes_SONAME.solaris    = libXfixes.so.1
+libXfixes_SONAME.netbsd     = libXfixes.so.4
 libXfixes_SOURCES    = libXfixes-3.1.0/libXfixes.c
 
 #
@@ -58,6 +61,7 @@ libXext_TEMPLATE   = VBoxGuestR3Dll
 libXext_INST       = $(INST_LIB)
 # This may need fixing later.
 libXext_SONAME.linux       = libXext.so.6
+libXext_SONAME.netbsd      = libXext.so.7
 libXext_SONAME.solaris     = libXext.so.0
 libXext_SOURCES    = libXext-6.4.0/libXext.c
 
diff --git src/VBox/GuestHost/OpenGL/include/chromium.h src/VBox/GuestHost/OpenGL/include/chromium.h
index 816aee9..dc54d2d 100644
--- src/VBox/GuestHost/OpenGL/include/chromium.h
+++ 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 src/VBox/GuestHost/OpenGL/include/cr_dll.h src/VBox/GuestHost/OpenGL/include/cr_dll.h
index 4258b57..6ca184c 100644
--- src/VBox/GuestHost/OpenGL/include/cr_dll.h
+++ 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 src/VBox/GuestHost/OpenGL/include/cr_timer.h src/VBox/GuestHost/OpenGL/include/cr_timer.h
index 316ba34..dc5111e 100644
--- src/VBox/GuestHost/OpenGL/include/cr_timer.h
+++ 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 src/VBox/GuestHost/OpenGL/spu_loader/glloader.py src/VBox/GuestHost/OpenGL/spu_loader/glloader.py
index a84f729..6e8c3f6 100644
--- src/VBox/GuestHost/OpenGL/spu_loader/glloader.py
+++ src/VBox/GuestHost/OpenGL/spu_loader/glloader.py
@@ -34,7 +34,7 @@ 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(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1) || defined(NetBSD)
 #include <string.h>
 #if defined(AIX)
 #define SYSTEM_GL "libGL.o"
@@ -150,7 +150,7 @@ __findSystemLib( const char *provided_system_path, char *lib )
 		}*/
 #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)
diff --git src/VBox/GuestHost/OpenGL/util/dll.c src/VBox/GuestHost/OpenGL/util/dll.c
index dbc6175..bdc5117 100644
--- src/VBox/GuestHost/OpenGL/util/dll.c
+++ 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, int resolveGlobal )
 		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, const char *symname )
 
 	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 src/VBox/GuestHost/OpenGL/util/environment.c src/VBox/GuestHost/OpenGL/util/environment.c
index 82fd619..092cd26 100644
--- src/VBox/GuestHost/OpenGL/util/environment.c
+++ 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 src/VBox/GuestHost/OpenGL/util/timer.c src/VBox/GuestHost/OpenGL/util/timer.c
index cad0d95..b4f34b8 100644
--- src/VBox/GuestHost/OpenGL/util/timer.c
+++ 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 src/VBox/GuestHost/OpenGL/util/vboxhgcm.c src/VBox/GuestHost/OpenGL/util/vboxhgcm.c
index 7290b7b..ec7b794 100644
--- src/VBox/GuestHost/OpenGL/util/vboxhgcm.c
+++ src/VBox/GuestHost/OpenGL/util/vboxhgcm.c
@@ -623,7 +623,7 @@ static int crVBoxHGCMCall(CRConnection *conn, void *pvData, unsigned cbData)
     }
 # 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( CRConnection *conn )
                         &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);
@@ -1560,7 +1560,7 @@ static void crVBoxHGCMDoDisconnect( CRConnection *conn )
         {
             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 src/VBox/GuestHost/OpenGL/util/vboxhgsmi.c src/VBox/GuestHost/OpenGL/util/vboxhgsmi.c
index 3da3496..06c1b0e 100644
--- src/VBox/GuestHost/OpenGL/util/vboxhgsmi.c
+++ src/VBox/GuestHost/OpenGL/util/vboxhgsmi.c
@@ -255,7 +255,7 @@ static int crVBoxHGCMCall(void *pvData, unsigned cbData)
     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( CRConnection *conn )
                         &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( CRConnection *conn )
         {
             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 src/VBox/Makefile.kmk src/VBox/Makefile.kmk
index 7bb7035..14f819a 100644
--- src/VBox/Makefile.kmk
+++ 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
diff --git src/VBox/Runtime/Makefile.kmk src/VBox/Runtime/Makefile.kmk
index b015047..a5806fd 100644
--- src/VBox/Runtime/Makefile.kmk
+++ src/VBox/Runtime/Makefile.kmk
@@ -1047,6 +1047,75 @@ RuntimeR3_SOURCES.freebsd = \
 	r3/posix/tls-posix.cpp \
 	r3/posix/utf8-posix.cpp
 
+## @todo Make BSD sched, implement RTMP*.
+RuntimeR3_SOURCES.netbsd = \
+	generic/cdrom-generic.cpp \
+	generic/RTDirQueryInfo-generic.cpp \
+	generic/RTDirSetTimes-generic.cpp \
+	generic/RTFileMove-generic.cpp \
+	generic/RTLogWriteDebugger-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/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/RTSystemQueryTotalRam-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.solaris = \
 	generic/cdrom-generic.cpp \
 	generic/RTDirQueryInfo-generic.cpp \
@@ -1351,6 +1420,8 @@ VBoxRT_LIBS.darwin             = \
 VBoxRT_LIBS.freebsd            = \
 	iconv \
 	rt
+VBoxRT_LIBS.netbsd             = \
+	rt
 VBoxRT_LIBS.haiku              = \
 	iconv
 VBoxRT_LIBS.solaris            = \
@@ -1453,6 +1524,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            = \
@@ -1628,7 +1701,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 \
@@ -1682,7 +1755,6 @@ RuntimeR0_SOURCES.win = \
 RuntimeR0_SOURCES.os2 = \
 	os2/sys0.asm
 
-
 #
 # RuntimeR0Stub - Ring-0 context startup stub for Windows and Solaris.
 #
@@ -2122,6 +2194,38 @@ 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/memcmp.asm \
+	common/string/strchr.asm \
+	generic/RTAssertShouldPanic-generic.cpp \
+	generic/RTLogWriteDebugger-generic.cpp \
+	generic/RTLogWriteStdOut-stub-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/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 \
@@ -2194,7 +2298,6 @@ RuntimeR0Drv_ORDERDEPS.freebsd = \
 	$(PATH_STAGE)/gen-sys-hdrs/bus_if.h \
 	$(PATH_STAGE)/gen-sys-hdrs/device_if.h
 
-
 #
 # RuntimeGuestR0 - Guest driver runtime.
 #                  This is almost the same as the RuntimeR0Drv, the main difference
@@ -2477,7 +2580,6 @@ $$(FreeBSDGeneratedKernelHeaders_0_OUTDIR)/pci_if.h: $(VBOX_FREEBSD_SRC)/dev/pci
 	$(QUIET)$(RM) $(@D)/pci_if.m
 endif # FreeBSD
 
-
 #
 # Aliases for .cpp.h files so we can more easily do syntax checking from the editor.
 #
diff --git src/VBox/Runtime/r0drv/netbsd/alloc-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/alloc-r0drv-netbsd.c
new file mode 100644
index 0000000..f781fe3
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/alloc-r0drv-netbsd.c
@@ -0,0 +1,117 @@
+/*******************************************************************************
+*   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"
+
+
+DECLHIDDEN(int) rtR0MemAllocEx(size_t cb, uint32_t fFlags, PRTMEMHDR *ppHdr)
+{
+    size_t      cbAllocated = cb;
+    PRTMEMHDR   pHdr        = NULL;
+
+    {
+        if (fFlags & RTMEMHDR_FLAG_ZEROED) {
+            pHdr = kmem_zalloc(cb + sizeof(RTMEMHDR), KM_NOSLEEP);
+        } else {
+            pHdr = kmem_alloc(cb + sizeof(RTMEMHDR), KM_NOSLEEP);
+        }
+    }
+
+    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;
+
+    kmem_free(pHdr, pHdr->cb + sizeof(RTMEMHDR));
+}
+
+RTR0DECL(void) RTMemContFree(void *pv, size_t cb)
+{
+    if (pv)
+    {
+        cb = round_page(cb);
+
+        paddr_t pa;
+        pmap_extract(pmap_kernel(), (vaddr_t)pv, &pa);
+
+        /*
+         * Reconstruct pglist to free the physical pages
+         */
+        struct pglist rlist;
+        TAILQ_INIT(&rlist);
+
+        for (paddr_t pa2 = pa ; pa2 < pa + cb ; pa2 += PAGE_SIZE) {
+            struct vm_page *page = PHYS_TO_VM_PAGE(pa2);
+            TAILQ_INSERT_TAIL(&rlist, page, pageq.queue);
+        }
+
+        /* Unmap */
+        pmap_kremove((vaddr_t)pv, cb);
+
+        /* Free the virtual space */
+        uvm_km_free(kernel_map, (vaddr_t)pv, cb, UVM_KMF_VAONLY);
+
+        /* Free the physical pages */
+        uvm_pglistfree(&rlist);
+    }
+}
+
+RTR0DECL(void *) RTMemContAlloc(PRTCCPHYS pPhys, size_t cb)
+{
+    /*
+     * Validate input.
+     */
+    AssertPtr(pPhys);
+    Assert(cb > 0);
+
+    cb = round_page(cb);
+
+    vaddr_t virt = uvm_km_alloc(kernel_map, cb, 0,
+            UVM_KMF_VAONLY | UVM_KMF_WAITVA | UVM_KMF_CANFAIL);
+    if (virt == 0) {
+        return NULL;
+    }
+
+    struct pglist rlist;
+
+    if (uvm_pglistalloc(cb, 0, (paddr_t)0xFFFFFFFF,
+            PAGE_SIZE, 0, &rlist, 1, 1) != 0) {
+        uvm_km_free(kernel_map, virt, cb, UVM_KMF_VAONLY);
+        return NULL;
+    }
+
+    struct vm_page *page;
+    vaddr_t virt2 = virt;
+    TAILQ_FOREACH(page, &rlist, pageq.queue)
+    {
+        pmap_kenter_pa(virt2, VM_PAGE_TO_PHYS(page),
+                VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE, 0);
+        virt2 += PAGE_SIZE;
+    }
+
+    page = TAILQ_FIRST(&rlist);
+    *pPhys = VM_PAGE_TO_PHYS(page);
+
+    return (void *)virt;
+
+}
diff --git src/VBox/Runtime/r0drv/netbsd/assert-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/assert-r0drv-netbsd.c
new file mode 100644
index 0000000..d048272
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/assert-r0drv-netbsd.c
@@ -0,0 +1,62 @@
+/* $Id: assert-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - Assertion Workers, Ring-0 Drivers, NetBSD.
+ */
+
+/*
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * 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/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)
+{
+    /** @todo implement rtR0AssertNativeMsg2V. */
+}
+
+
+RTR0DECL(void) RTR0AssertPanicSystem(void)
+{
+    panic("%s%s", g_szRTAssertMsg1, g_szRTAssertMsg2);
+
+}
diff --git src/VBox/Runtime/r0drv/netbsd/initterm-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/initterm-r0drv-netbsd.c
new file mode 100644
index 0000000..f2ad115
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/initterm-r0drv-netbsd.c
@@ -0,0 +1,52 @@
+/* $Id: initterm-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - Initialization & Termination, Ring-0 Driver, NetBSD.
+ */
+
+/*
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * 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 src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c
new file mode 100644
index 0000000..060db9b
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/memobj-r0drv-netbsd.c
@@ -0,0 +1,519 @@
+/* $Id: memobj-r0drv-freebsd.c $ */
+/** @file
+ * IPRT - Ring-0 Memory Objects, NetBSD.
+ */
+
+/*******************************************************************************
+*   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;
+    size_t              size;
+    struct pglist       pglist;
+} RTR0MEMOBJNETBSD, *PRTR0MEMOBJNETBSD;
+
+
+typedef struct vm_map* vm_map_t;
+
+/**
+ * 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:
+        {
+            kmem_free(pMemNetBSD->Core.pv, pMemNetBSD->Core.cb);
+            break;
+        }
+        case RTR0MEMOBJTYPE_LOW:
+        case RTR0MEMOBJTYPE_CONT:
+        {
+            /* Unmap */
+            pmap_kremove((vaddr_t)pMemNetBSD->Core.pv, pMemNetBSD->Core.cb);
+            /* Free the virtual space */
+            uvm_km_free(kernel_map, (vaddr_t)pMemNetBSD->Core.pv, pMemNetBSD->Core.cb, UVM_KMF_VAONLY);
+            /* Free the physical pages */
+            uvm_pglistfree(&pMemNetBSD->pglist);
+            break;
+        }
+        case RTR0MEMOBJTYPE_PHYS:
+        case RTR0MEMOBJTYPE_PHYS_NC:
+        {
+            /* Free the physical pages */
+            uvm_pglistfree(&pMemNetBSD->pglist);
+            break;
+        }
+        case RTR0MEMOBJTYPE_LOCK:
+            if (pMemNetBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS) {
+                uvm_map_pageable(
+                        &((struct proc *)pMemNetBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map,
+                        (vaddr_t)pMemNetBSD->Core.pv,
+                        ((vaddr_t)pMemNetBSD->Core.pv) + pMemNetBSD->Core.cb,
+                        1, 0);
+            }
+            break;
+        case RTR0MEMOBJTYPE_RES_VIRT:
+            if (pMemNetBSD->Core.u.Lock.R0Process == NIL_RTR0PROCESS) {
+                uvm_km_free(kernel_map, (vaddr_t)pMemNetBSD->Core.pv, pMemNetBSD->Core.cb, UVM_KMF_VAONLY);
+            }
+            break;
+        case RTR0MEMOBJTYPE_MAPPING:
+            if (pMemNetBSD->Core.u.Lock.R0Process == NIL_RTR0PROCESS) {
+                pmap_kremove((vaddr_t)pMemNetBSD->Core.pv, pMemNetBSD->Core.cb);
+                uvm_km_free(kernel_map, (vaddr_t)pMemNetBSD->Core.pv, pMemNetBSD->Core.cb, UVM_KMF_VAONLY);
+            }
+            break;
+
+        default:
+            AssertMsgFailed(("enmType=%d\n", pMemNetBSD->Core.enmType));
+            return VERR_INTERNAL_ERROR;
+    }
+
+    return VINF_SUCCESS;
+}
+
+static int rtR0MemObjNetBSDAllocHelper(PRTR0MEMOBJNETBSD pMemNetBSD, size_t cb, bool fExecutable,
+                                         paddr_t VmPhysAddrHigh, bool fContiguous)
+{
+    /* Virtual space first */
+    vaddr_t virt = uvm_km_alloc(kernel_map, cb, 0,
+            UVM_KMF_VAONLY | UVM_KMF_WAITVA | UVM_KMF_CANFAIL);
+    if (virt == 0) {
+        return VERR_NO_MEMORY;
+    }
+
+    struct pglist *rlist = &pMemNetBSD->pglist;
+
+    int nsegs = fContiguous ? 1 : INT_MAX;
+
+    /* Physical pages */
+    if (uvm_pglistalloc(cb, 0, VmPhysAddrHigh,
+            PAGE_SIZE, 0, rlist, nsegs, 1) != 0) {
+        uvm_km_free(kernel_map, virt, cb, UVM_KMF_VAONLY);
+        return VERR_NO_MEMORY;
+    }
+
+    /* Map */
+    struct vm_page *page;
+    vm_prot_t prot = VM_PROT_READ | VM_PROT_WRITE;
+    if (fExecutable) {
+        prot |= VM_PROT_EXECUTE;
+    }
+    vaddr_t virt2 = virt;
+    TAILQ_FOREACH(page, rlist, pageq.queue)
+    {
+        pmap_kenter_pa(virt2, VM_PAGE_TO_PHYS(page), prot, 0);
+        virt2 += PAGE_SIZE;
+    }
+
+    pMemNetBSD->Core.pv = (void *)virt;
+    if (fContiguous) {
+        page = TAILQ_FIRST(rlist);
+        pMemNetBSD->Core.u.Cont.Phys = VM_PAGE_TO_PHYS(page);
+    }
+    return VINF_SUCCESS;
+}
+
+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;
+
+    void *pvMem = kmem_alloc(cb, KM_SLEEP);
+    if (RT_UNLIKELY(!pvMem))
+    {
+        rtR0MemObjDelete(&pMemNetBSD->Core);
+        return VERR_NO_PAGE_MEMORY;
+    }
+    if (fExecutable) {
+        pmap_protect(pmap_kernel(), (vaddr_t)pvMem, ((vaddr_t)pvMem) + cb,
+                VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
+    }
+
+    pMemNetBSD->Core.pv = pvMem;
+    *ppMem = &pMemNetBSD->Core;
+    return VINF_SUCCESS;
+}
+
+
+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, cb, fExecutable, _4G - 1, false);
+    if (rc)
+    {
+        rtR0MemObjDelete(&pMemNetBSD->Core);
+        return rc;
+    }
+
+    *ppMem = &pMemNetBSD->Core;
+    return VINF_SUCCESS;
+}
+
+
+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, cb, fExecutable, _4G - 1, true);
+    if (rc)
+    {
+        rtR0MemObjDelete(&pMemNetBSD->Core);
+        return rc;
+    }
+
+    *ppMem = &pMemNetBSD->Core;
+    return VINF_SUCCESS;
+}
+
+
+static int rtR0MemObjNetBSDAllocPhysPages(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJTYPE enmType,
+                                           size_t cb,
+                                           RTHCPHYS PhysHighest, size_t uAlignment,
+                                           bool fContiguous)
+{
+    paddr_t VmPhysAddrHigh;
+
+    /* create the object. */
+    PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD),
+                                                                       enmType, NULL, cb);
+    if (!pMemNetBSD)
+        return VERR_NO_MEMORY;
+
+    if (PhysHighest != NIL_RTHCPHYS)
+        VmPhysAddrHigh = PhysHighest;
+    else
+        VmPhysAddrHigh = ~(paddr_t)0;
+
+    int nsegs = fContiguous ? 1 : INT_MAX;
+
+    int error = uvm_pglistalloc(cb, 0, VmPhysAddrHigh, uAlignment, 0, &pMemNetBSD->pglist, nsegs, 1);
+    if (error) {
+        rtR0MemObjDelete(&pMemNetBSD->Core);
+        return VERR_NO_MEMORY;
+    }
+
+    if (fContiguous)
+    {
+        Assert(enmType == RTR0MEMOBJTYPE_PHYS);
+        const struct vm_page * const pg = TAILQ_FIRST(&pMemNetBSD->pglist);
+        pMemNetBSD->Core.u.Phys.PhysBase = VM_PAGE_TO_PHYS(pg);
+        pMemNetBSD->Core.u.Phys.fAllocated = true;
+    }
+    *ppMem = &pMemNetBSD->Core;
+
+    return VINF_SUCCESS;
+}
+
+
+DECLHIDDEN(int) rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment)
+{
+    return rtR0MemObjNetBSDAllocPhysPages(ppMem, RTR0MEMOBJTYPE_PHYS, cb, PhysHighest, uAlignment, true);
+}
+
+
+DECLHIDDEN(int) rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
+{
+    return rtR0MemObjNetBSDAllocPhysPages(ppMem, RTR0MEMOBJTYPE_PHYS_NC, cb, PhysHighest, PAGE_SIZE, false);
+}
+
+
+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;
+    TAILQ_INIT(&pMemNetBSD->pglist);
+    *ppMem = &pMemNetBSD->Core;
+    return VINF_SUCCESS;
+}
+
+
+DECLHIDDEN(int) rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process)
+{
+    PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
+    if (!pMemNetBSD)
+        return VERR_NO_MEMORY;
+
+    int rc = uvm_map_pageable(
+            &((struct proc *)R0Process)->p_vmspace->vm_map,
+            R3Ptr,
+            R3Ptr + cb,
+            0, 0);
+    if (rc) {
+        rtR0MemObjDelete(&pMemNetBSD->Core);
+        return VERR_NO_MEMORY;
+    }
+
+    pMemNetBSD->Core.u.Lock.R0Process = R0Process;
+    *ppMem = &pMemNetBSD->Core;
+    return VINF_SUCCESS;
+}
+
+
+DECLHIDDEN(int) rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess)
+{
+    /* Kernel memory (always?) wired; all memory allocated by vbox code is? */
+    PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD), RTR0MEMOBJTYPE_LOCK, pv, cb);
+    if (!pMemNetBSD)
+        return VERR_NO_MEMORY;
+
+    pMemNetBSD->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
+    pMemNetBSD->Core.pv = pv;
+    *ppMem = &pMemNetBSD->Core;
+    return VINF_SUCCESS;
+}
+
+DECLHIDDEN(int) rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
+{
+    if (pvFixed != (void *)-1) {
+        /* can we support this? or can we assume the virtual space is already reserved? */
+        printf("reserve specified kernel virtual address not supported\n");
+        return VERR_NOT_SUPPORTED;
+    }
+
+    PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD), RTR0MEMOBJTYPE_RES_VIRT, NULL, cb);
+    if (!pMemNetBSD)
+        return VERR_NO_MEMORY;
+
+    vaddr_t virt = uvm_km_alloc(kernel_map, cb, uAlignment,
+            UVM_KMF_VAONLY | UVM_KMF_WAITVA | UVM_KMF_CANFAIL);
+    if (virt == 0) {
+        rtR0MemObjDelete(&pMemNetBSD->Core);
+        return VERR_NO_MEMORY;
+    }
+
+    pMemNetBSD->Core.u.ResVirt.R0Process = NIL_RTR0PROCESS;
+    pMemNetBSD->Core.pv = (void *)virt;
+    *ppMem = &pMemNetBSD->Core;
+    return VINF_SUCCESS;
+}
+
+
+DECLHIDDEN(int) rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
+{
+    printf("NativeReserveUser\n");
+    return VERR_NOT_SUPPORTED;
+}
+
+
+DECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
+                                          unsigned fProt, size_t offSub, size_t cbSub)
+{
+    if (pvFixed != (void *)-1) {
+        /* can we support this? or can we assume the virtual space is already reserved? */
+        printf("map to specified kernel virtual address not supported\n");
+        return VERR_NOT_SUPPORTED;
+    }
+
+    PRTR0MEMOBJNETBSD pMemNetBSD0 = (PRTR0MEMOBJNETBSD)pMemToMap;
+    if ((pMemNetBSD0->Core.enmType != RTR0MEMOBJTYPE_PHYS)
+        && (pMemNetBSD0->Core.enmType != RTR0MEMOBJTYPE_PHYS_NC)) {
+        printf("memory to map is not physical\n");
+        return VERR_NOT_SUPPORTED;
+    }
+    size_t sz = cbSub > 0 ? cbSub : pMemNetBSD0->Core.cb;
+
+    PRTR0MEMOBJNETBSD pMemNetBSD = (PRTR0MEMOBJNETBSD)rtR0MemObjNew(sizeof(*pMemNetBSD), RTR0MEMOBJTYPE_MAPPING, NULL, sz);
+
+    vaddr_t virt = uvm_km_alloc(kernel_map, sz, uAlignment,
+            UVM_KMF_VAONLY | UVM_KMF_WAITVA | UVM_KMF_CANFAIL);
+    if (virt == 0) {
+        rtR0MemObjDelete(&pMemNetBSD->Core);
+        return VERR_NO_MEMORY;
+    }
+
+    vm_prot_t prot = 0;
+
+    if ((fProt & RTMEM_PROT_READ) == RTMEM_PROT_READ)
+        prot |= VM_PROT_READ;
+    if ((fProt & RTMEM_PROT_WRITE) == RTMEM_PROT_WRITE)
+        prot |= VM_PROT_WRITE;
+    if ((fProt & RTMEM_PROT_EXEC) == RTMEM_PROT_EXEC)
+        prot |= VM_PROT_EXECUTE;
+
+    struct vm_page *page;
+    vaddr_t virt2 = virt;
+    size_t map_pos = 0;
+    TAILQ_FOREACH(page, &pMemNetBSD0->pglist, pageq.queue)
+    {
+        if (map_pos >= offSub) {
+            if (cbSub > 0 && (map_pos >= offSub + cbSub)) {
+                break;
+            }
+            pmap_kenter_pa(virt2, VM_PAGE_TO_PHYS(page), prot, 0);
+            virt2 += PAGE_SIZE;
+        }
+        map_pos += PAGE_SIZE;
+    }
+
+    pMemNetBSD->Core.pv = (void *)virt;
+    pMemNetBSD->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;
+    *ppMem = &pMemNetBSD->Core;
+
+    return VINF_SUCCESS;
+}
+
+
+DECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment,
+                                        unsigned fProt, RTR0PROCESS R0Process)
+{
+    printf("NativeMapUser\n");
+    return VERR_NOT_SUPPORTED;
+}
+
+
+DECLHIDDEN(int) rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
+{
+    vm_prot_t          ProtectionFlags = 0;
+    vaddr_t        AddrStart       = (vaddr_t)pMem->pv + offSub;
+    vm_map_t           pVmMap          = rtR0MemObjNetBSDGetMap(pMem);
+
+    if (!pVmMap)
+        return VERR_NOT_SUPPORTED;
+
+    if ((fProt & RTMEM_PROT_READ) == RTMEM_PROT_READ)
+        ProtectionFlags |= UVM_PROT_R;
+    if ((fProt & RTMEM_PROT_WRITE) == RTMEM_PROT_WRITE)
+        ProtectionFlags |= UVM_PROT_W;
+    if ((fProt & RTMEM_PROT_EXEC) == RTMEM_PROT_EXEC)
+        ProtectionFlags |= UVM_PROT_X;
+
+    int error = uvm_map_protect(pVmMap, AddrStart, AddrStart + cbSub,
+        ProtectionFlags, 0);
+    if (!error)
+        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_PAGE:
+        case RTR0MEMOBJTYPE_LOW:
+        {
+            vaddr_t va = (vaddr_t)pMemNetBSD->Core.pv + ptoa(iPage);
+            paddr_t pa = 0;
+            pmap_extract(pmap_kernel(), va, &pa);
+            return pa;
+        }
+        case RTR0MEMOBJTYPE_CONT:
+            return pMemNetBSD->Core.u.Cont.Phys + ptoa(iPage);
+        case RTR0MEMOBJTYPE_PHYS:
+            return pMemNetBSD->Core.u.Phys.PhysBase + ptoa(iPage);
+        case RTR0MEMOBJTYPE_PHYS_NC:
+        {
+            struct vm_page *page;
+            size_t i = 0;
+            TAILQ_FOREACH(page, &pMemNetBSD->pglist, pageq.queue)
+            {
+                if (i == iPage)
+                    break;
+                i++;
+            }
+            return VM_PAGE_TO_PHYS(page);
+        }
+        case RTR0MEMOBJTYPE_LOCK:
+        case RTR0MEMOBJTYPE_MAPPING:
+        {
+            pmap_t pmap;
+            if (pMem->u.Lock.R0Process == NIL_RTR0PROCESS) {
+                pmap = pmap_kernel();
+            } else {
+                pmap = ((struct proc *)pMem->u.Lock.R0Process)->p_vmspace->vm_map.pmap;
+            }
+            vaddr_t va = (vaddr_t)pMemNetBSD->Core.pv + ptoa(iPage);
+            paddr_t pa = 0;
+            pmap_extract(pmap, va, &pa);
+            return pa;
+        }
+        case RTR0MEMOBJTYPE_RES_VIRT:
+            return NIL_RTHCPHYS;
+        default:
+            return NIL_RTHCPHYS;
+    }
+}
diff --git src/VBox/Runtime/r0drv/netbsd/memuserkernel-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/memuserkernel-r0drv-netbsd.c
new file mode 100644
index 0000000..712aa0d
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/memuserkernel-r0drv-netbsd.c
@@ -0,0 +1,84 @@
+/* $Id: memuserkernel-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - User & Kernel Memory, Ring-0 Driver, NetBSD.
+ */
+
+/*
+ * Copyright (C) 2009-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.
+ *
+ * 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 src/VBox/Runtime/r0drv/netbsd/mp-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/mp-r0drv-netbsd.c
new file mode 100644
index 0000000..d26e7e7
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/mp-r0drv-netbsd.c
@@ -0,0 +1,44 @@
+/* $Id: mp-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - Multiprocessor, Ring-0 Driver, NetBSD.
+ */
+
+/*
+ * Copyright (C) 2008-2011 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 cpu_number();
+}
+
diff --git src/VBox/Runtime/r0drv/netbsd/process-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/process-r0drv-netbsd.c
new file mode 100644
index 0000000..4a0c7f8
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/process-r0drv-netbsd.c
@@ -0,0 +1,48 @@
+/* $Id: process-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - Process Management, Ring-0 Driver, NetBSD.
+ */
+
+/*
+ * 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 src/VBox/Runtime/r0drv/netbsd/semevent-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/semevent-r0drv-netbsd.c
new file mode 100644
index 0000000..2e8a2ab
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/semevent-r0drv-netbsd.c
@@ -0,0 +1,255 @@
+/* $Id: 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>
+ *
+ * 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 src/VBox/Runtime/r0drv/netbsd/semeventmulti-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/semeventmulti-r0drv-netbsd.c
new file mode 100644
index 0000000..174a49e
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/semeventmulti-r0drv-netbsd.c
@@ -0,0 +1,318 @@
+/* $Id: semeventmulti-r0drv-freebsd.c $ */
+/** @file
+ * IPRT - Multiple Release Event Semaphores, Ring-0 Driver, FreeBSD.
+ */
+
+/*
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * 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                                                    *
+*******************************************************************************/
+/**
+ * FreeBSD 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 src/VBox/Runtime/r0drv/netbsd/semfastmutex-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/semfastmutex-r0drv-netbsd.c
new file mode 100644
index 0000000..af64ef0
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/semfastmutex-r0drv-netbsd.c
@@ -0,0 +1,114 @@
+/* $Id: semfastmutex-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - Fast Mutex Semaphores, Ring-0 Driver, NetBSD.
+ */
+
+/*
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * 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. */
+    krwlock_t           Mtx;
+} 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;
+        rw_init(&pThis->Mtx);
+
+        *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);
+    rw_destroy(&pThis->Mtx);
+    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);
+
+    rw_enter(&pThis->Mtx, RW_WRITER);
+    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);
+
+    rw_exit(&pThis->Mtx);
+    return VINF_SUCCESS;
+}
+
diff --git src/VBox/Runtime/r0drv/netbsd/semmutex-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/semmutex-r0drv-netbsd.c
new file mode 100644
index 0000000..83f9278
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/semmutex-r0drv-netbsd.c
@@ -0,0 +1,219 @@
+/* $Id: semmutex-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - Mutex Semaphores, Ring-0 Driver, NetBSD.
+ */
+
+/*
+ * Copyright (C) 2010-2011 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 rc;
+}
+
+
+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 rc;
+}
+
+
+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 src/VBox/Runtime/r0drv/netbsd/sleepqueue-r0drv-netbsd.h src/VBox/Runtime/r0drv/netbsd/sleepqueue-r0drv-netbsd.h
new file mode 100644
index 0000000..ed99072
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/sleepqueue-r0drv-netbsd.h
@@ -0,0 +1,280 @@
+/* $Id: sleepqueue-r0drv-netbsd.h $ */
+/** @file
+ * IPRT - NetBSD Ring-0 Driver Helpers for Abstracting Sleep Queues,
+ */
+
+/*
+ * Copyright (C) 2006-2012 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * 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/time.h>
+
+static syncobj_t vbox_syncobj = {
+        SOBJ_SLEEPQ_FIFO,
+        sleepq_unsleep,
+        sleepq_changepri,
+        sleepq_lendpri,
+        syncobj_noowner,
+};
+
+/**
+ * Kernel mode Linux 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. */
+    wchan_t         wchan;
+    sleepq_t *sq;
+    kmutex_t *sq_lock;
+} RTR0SEMBSDSLEEP;
+/** Pointer to a NetBSD wait state. */
+typedef RTR0SEMBSDSLEEP *PRTR0SEMBSDSLEEP;
+
+
+/**
+ * Updates the timeout of the NetBSD 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(void) rtR0SemBsdWaitUpdateTimeout(PRTR0SEMBSDSLEEP pWait)
+{
+    /* Convert absolute timeout to ticks */
+    uint64_t now = RTTimeNanoTS();
+    if (now >= pWait->uNsAbsTimeout) {
+        pWait->iTimeout = 0;
+    } else {
+        uint64_t nanos = pWait->uNsAbsTimeout - now;
+        pWait->iTimeout = hz * nanos / 1000000000;
+        /* for 1ms wait, wait at least one tick ?? */
+        if ((pWait->iTimeout == 0) && (nanos >= 1000000)) {
+            pWait->iTimeout = 1;
+        }
+    }
+}
+
+/**
+ * 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)
+{
+    if (fFlags & RTSEMWAIT_FLAGS_INDEFINITE) {
+        pWait->fIndefinite      = true;
+        pWait->iTimeout = 0;
+        pWait->uNsAbsTimeout = 0;
+    } else {
+        if (fFlags & RTSEMWAIT_FLAGS_RELATIVE) {
+            if (fFlags & RTSEMWAIT_FLAGS_MILLISECS) {
+                pWait->uNsAbsTimeout = uTimeout * 1000000 + RTTimeSystemNanoTS();
+            } else {
+                pWait->uNsAbsTimeout = uTimeout + RTTimeSystemNanoTS();
+            }
+        } else {
+            if (fFlags & RTSEMWAIT_FLAGS_MILLISECS) {
+                pWait->uNsAbsTimeout = uTimeout * 1000000;
+            } else {
+                pWait->uNsAbsTimeout = uTimeout;
+            }
+        }
+        rtR0SemBsdWaitUpdateTimeout(pWait);
+        if (pWait->iTimeout == 0) {
+            return VERR_TIMEOUT;
+        }
+    }
+
+    pWait->fTimedOut   = false;
+    /*
+     * Initialize the wait queue related bits.
+     */
+    pWait->fInterruptible = fFlags & RTSEMWAIT_FLAGS_INTERRUPTIBLE
+                            ? true : false;
+    pWait->fInterrupted   = false;
+    pWait->wchan = pvWaitChan;
+    pWait->sq = NULL;
+    pWait->sq_lock = NULL;
+
+    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)
+{
+    pWait->sq = sleeptab_lookup(&sleeptab, pWait->wchan, &pWait->sq_lock);
+}
+
+/**
+ * Do the actual wait.
+ *
+ * @param   pWait               The wait structure.
+ */
+DECLINLINE(void) rtR0SemBsdWaitDoIt(PRTR0SEMBSDSLEEP pWait)
+{
+    sleepq_enter(pWait->sq, curlwp, pWait->sq_lock);
+    sleepq_enqueue(pWait->sq, pWait->wchan, "VBoxIS", &vbox_syncobj);
+
+    pWait->sq = NULL;
+    pWait->sq_lock = NULL;
+
+    int error = sleepq_block(pWait->iTimeout, pWait->fInterruptible);
+    if (error == EWOULDBLOCK) {
+        if (!pWait->fIndefinite) {
+            pWait->fTimedOut = true;
+        }
+    } else if (error == ERESTART) {
+        if (pWait->fInterruptible) {
+            pWait->fInterrupted = true;
+        } else if (!pWait->fIndefinite) {
+            rtR0SemBsdWaitUpdateTimeout(pWait);
+            if (pWait->iTimeout == 0) {
+                pWait->fTimedOut = true;
+            }
+        }
+    } else if (error == EINTR) {
+        if (pWait->fInterruptible) {
+            pWait->fInterrupted = true;
+        } else if (!pWait->fIndefinite) {
+            rtR0SemBsdWaitUpdateTimeout(pWait);
+            if (pWait->iTimeout == 0) {
+                pWait->fTimedOut = true;
+            }
+        }
+    } else if (error) {
+        AssertMsgFailed(("sleepq_block -> %d\n", error));
+    }
+}
+
+
+/**
+ * Checks if a NetBSD wait was interrupted.
+ *
+ * @returns true / false
+ * @param   pWait               The wait structure.
+ * @remarks This shall be called before the first rtR0SemLnxWaitDoIt().
+ */
+DECLINLINE(bool) rtR0SemBsdWaitWasInterrupted(PRTR0SEMBSDSLEEP pWait)
+{
+    return pWait->fInterrupted;
+}
+
+
+/**
+ * Checks if a NetBSD wait has timed out.
+ *
+ * @returns true / false
+ * @param   pWait               The wait structure.
+ */
+DECLINLINE(bool) rtR0SemBsdWaitHasTimedOut(PRTR0SEMBSDSLEEP pWait)
+{
+    return pWait->fTimedOut;
+}
+
+
+/**
+ * Deletes a NetBSD wait.
+ *
+ * @param   pWait               The wait structure.
+ */
+DECLINLINE(void) rtR0SemBsdWaitDelete(PRTR0SEMBSDSLEEP pWait)
+{
+    if (pWait->sq_lock != NULL) {
+        mutex_spin_exit(pWait->sq_lock);
+        pWait->sq = NULL;
+        pWait->sq_lock = NULL;
+    }
+}
+
+
+/**
+ * Signals the wait channel.
+ *
+ * @param  pvWaitChan           The opaque wait channel handle.
+ */
+DECLINLINE(void) rtR0SemBsdSignal(void *pvWaitChan)
+{
+    kmutex_t *mp;
+    sleepq_t *sq = sleeptab_lookup(&sleeptab, pvWaitChan, &mp);
+    sleepq_wake(sq, pvWaitChan, 1, mp);
+}
+
+/**
+ * Wakes up all waiters on the wait channel.
+ *
+ * @param  pvWaitChan           The opaque wait channel handle.
+ */
+DECLINLINE(void) rtR0SemBsdBroadcast(void *pvWaitChan)
+{
+    kmutex_t *mp;
+    sleepq_t *sq = sleeptab_lookup(&sleeptab, pvWaitChan, &mp);
+    sleepq_wake(sq, pvWaitChan, ~0u, mp);
+}
+
+/**
+ * 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 src/VBox/Runtime/r0drv/netbsd/spinlock-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/spinlock-r0drv-netbsd.c
new file mode 100644
index 0000000..31046d9
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/spinlock-r0drv-netbsd.c
@@ -0,0 +1,160 @@
+/* $Id: spinlock-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - Spinlocks, Ring-0 Driver, NetBSD.
+ */
+
+/*
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * 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. */
+    kmutex_t            pSpinLock;
+    /** Saved interrupt flag. */
+    uint32_t volatile   fIntSaved;
+    /** The spinlock creation flags. */
+    uint32_t            fFlags;
+} 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->fFlags    = fFlags;
+    pThis->fIntSaved = 0;
+    if (fFlags & RTSPINLOCK_FLAGS_INTERRUPT_SAFE) {
+        mutex_init(&pThis->pSpinLock, MUTEX_DEFAULT, IPL_BIO);
+    } else {
+        mutex_init(&pThis->pSpinLock, MUTEX_DEFAULT, IPL_NONE);
+    }
+
+    *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);
+    mutex_destroy(&pThis->pSpinLock);
+    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) {
+        mutex_spin_enter(&pThis->pSpinLock);
+    } else {
+        mutex_enter(&pThis->pSpinLock);
+    }
+}
+
+
+RTDECL(void) RTSpinlockRelease(RTSPINLOCK Spinlock)
+{
+    PRTSPINLOCKINTERNAL pThis = (PRTSPINLOCKINTERNAL)Spinlock;
+    AssertPtr(pThis);
+    Assert(pThis->u32Magic == RTSPINLOCK_MAGIC);
+
+    if (pThis->fFlags & RTSPINLOCK_FLAGS_INTERRUPT_SAFE) {
+        mutex_spin_exit(&pThis->pSpinLock);
+    } else {
+        mutex_exit(&pThis->pSpinLock);
+    }
+}
+
+
+RTDECL(void) RTSpinlockReleaseNoInts(RTSPINLOCK Spinlock)
+{
+#if 1
+    if (RT_UNLIKELY(!(Spinlock->fFlags & RTSPINLOCK_FLAGS_INTERRUPT_SAFE)))
+        RTAssertMsg2("RTSpinlockReleaseNoInts: %p (magic=%#x)\n", Spinlock, Spinlock->u32Magic);
+#else
+    AssertRelease(Spinlock->fFlags & RTSPINLOCK_FLAGS_INTERRUPT_SAFE);
+#endif
+    RTSpinlockRelease(Spinlock);
+}
+
diff --git src/VBox/Runtime/r0drv/netbsd/the-netbsd-kernel.h src/VBox/Runtime/r0drv/netbsd/the-netbsd-kernel.h
new file mode 100644
index 0000000..ef13f16
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/the-netbsd-kernel.h
@@ -0,0 +1,72 @@
+/* $Id: the-netbsd-kernel.h $ */
+/** @file
+ * IPRT - Ring-0 Driver, The NetBSD Kernel Headers.
+ */
+
+/*
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * 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/systm.h>
+#include <sys/malloc.h>
+#include <sys/proc.h>
+#include <sys/syslimits.h>
+#include <sys/sleepq.h>
+#include <sys/unistd.h>
+#include <sys/kthread.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/sched.h>
+#include <sys/callout.h>
+#include <sys/rwlock.h>
+#include <sys/kmem.h>
+#include <sys/cpu.h>
+#include <sys/vmmeter.h>        /* cnt */
+#include <sys/resourcevar.h>
+#include <uvm/uvm.h>
+#include <uvm/uvm_extern.h>
+#include <uvm/uvm_page.h>
+#include <machine/cpu.h>
+
+/**
+ * Check whether we can use kmem_alloc_prot.
+ */
+#if 0 /** @todo Not available yet. */
+# define USE_KMEM_ALLOC_PROT
+#endif
+
+#endif
diff --git src/VBox/Runtime/r0drv/netbsd/thread-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/thread-r0drv-netbsd.c
new file mode 100644
index 0000000..3fd1ceb
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/thread-r0drv-netbsd.c
@@ -0,0 +1,180 @@
+/* $Id: thread-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - Threads (Part 1), Ring-0 Driver, NetBSD.
+ */
+
+/*
+ * Copyright (C) 2007-2011 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)curlwp;
+}
+
+
+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)
+{
+    yield();
+    return true;
+}
+
+
+RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread)
+{
+    Assert(hThread == NIL_RTTHREAD);
+
+    return curlwp->l_dopreempt == 0
+        && ASMIntAreEnabled(); /** @todo is there a native netbsd function/macro for this? */
+}
+
+
+RTDECL(bool) RTThreadPreemptIsPending(RTTHREAD hThread)
+{
+    Assert(hThread == NIL_RTTHREAD);
+
+    return curlwp->l_dopreempt;
+}
+
+
+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);
+
+    curlwp->l_nopreempt++;
+    __insn_barrier();
+}
+
+
+RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState)
+{
+
+    AssertPtr(pState);
+    __insn_barrier();
+    if (--curlwp->l_nopreempt != 0)
+        return;
+    __insn_barrier();
+    if (__predict_false(curlwp->l_dopreempt))
+        kpreempt(0);
+    __insn_barrier();
+}
+
+RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread)
+{
+    Assert(hThread == NIL_RTTHREAD); NOREF(hThread);
+    /** @todo NetBSD: Implement RTThreadIsInInterrupt. Required for guest
+     *        additions! */
+    return !ASMIntAreEnabled();
+}
+
diff --git src/VBox/Runtime/r0drv/netbsd/thread2-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/thread2-r0drv-netbsd.c
new file mode 100644
index 0000000..b125100
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/thread2-r0drv-netbsd.c
@@ -0,0 +1,130 @@
+/* $Id: thread2-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - Threads (Part 2), Ring-0 Driver, NetBSD.
+ */
+
+/*
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * 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 = PSWP;           break;
+        default:
+            AssertMsgFailed(("enmType=%d\n", enmType));
+            return VERR_INVALID_PARAMETER;
+    }
+
+    lwp_lock(curlwp);
+    sched_nice(curproc, iPriority);
+    curlwp->l_priority = iPriority;
+    lwp_unlock(curlwp);
+
+    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) rtThreadNativeDestroy(PRTTHREADINT pThread)
+{
+    NOREF(pThread);
+}
+
+
+/**
+ * Native thread main function.
+ *
+ * @param   pvThreadInt     The thread structure.
+ */
+static void rtThreadNativeMain(void *pvThreadInt)
+{
+    const struct lwp *Self = curlwp;
+    PRTTHREADINT pThreadInt = (PRTTHREADINT)pvThreadInt;
+    int rc;
+
+    rc = rtThreadMain(pThreadInt, (RTNATIVETHREAD)Self, &pThreadInt->szName[0]);
+
+    kthread_exit(rc);
+}
+
+
+DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
+{
+    int rc;
+    struct proc *pProc;
+    struct lwp *l;
+
+    rc = kthread_create(PRI_NONE, 0, NULL, rtThreadNativeMain, (void *)pThreadInt, &l, "%s", pThreadInt->szName);
+
+    if (!rc)
+    {
+        *pNativeThread = (RTNATIVETHREAD)l;
+        rc = VINF_SUCCESS;
+    }
+    else
+        rc = RTErrConvertFromErrno(rc);
+    return rc;
+}
+
diff --git src/VBox/Runtime/r0drv/netbsd/time-r0drv-netbsd.c src/VBox/Runtime/r0drv/netbsd/time-r0drv-netbsd.c
new file mode 100644
index 0000000..0ea101f
--- /dev/null
+++ src/VBox/Runtime/r0drv/netbsd/time-r0drv-netbsd.c
@@ -0,0 +1,73 @@
+/* $Id: time-r0drv-netbsd.c $ */
+/** @file
+ * IPRT - Time, Ring-0 Driver, NetBSD.
+ */
+
+/*
+ * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
+ *
+ * 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;
+    nanotime(&tsp);
+    return tsp.tv_sec * UINT64_C(1000000000)
+         + tsp.tv_nsec;
+}
+
+
+RTDECL(uint64_t) RTTimeMilliTS(void)
+{
+    return RTTimeNanoTS() / 1000000;
+}
+
+
+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 src/VBox/Runtime/r3/init.cpp src/VBox/Runtime/r3/init.cpp
index 1f680bf..3ebe9e1 100644
--- src/VBox/Runtime/r3/init.cpp
+++ src/VBox/Runtime/r3/init.cpp
@@ -143,7 +143,8 @@ RTDATADECL(bool) g_fRTAlignmentChecks = false;
 
 
 #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_NETBSD)  || defined(RT_OS_OS2)   \
+ || defined(RT_OS_SOLARIS) /** @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; }
diff --git src/VBox/Runtime/r3/netbsd/rtProcInitExePath-netbsd.cpp src/VBox/Runtime/r3/netbsd/rtProcInitExePath-netbsd.cpp
new file mode 100644
index 0000000..7d7c0ea
--- /dev/null
+++ src/VBox/Runtime/r3/netbsd/rtProcInitExePath-netbsd.cpp
@@ -0,0 +1,100 @@
+/* $Id: rtProcInitExePath-netbsd.cpp $ */
+/** @file
+ * IPRT - rtProcInitName, NetBSD.
+ */
+
+/*
+ * 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.
+ *
+ * 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)
+{
+    /*
+     * Read the /proc/curproc/file link, convert to native and return it.
+     */
+    int cchLink = readlink("/proc/curproc/exe", pszPath, cchPath - 1);
+    if (cchLink > 0 && (size_t)cchLink <= cchPath - 1)
+    {
+        pszPath[cchLink] = '\0';
+
+        char const *pszTmp;
+        int rc = rtPathFromNative(&pszTmp, pszPath, NULL);
+        AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhxs\n", rc, pszPath, cchLink, pszPath), rc);
+        if (pszTmp != pszPath)
+        {
+            rc = RTStrCopy(pszPath, cchPath, pszTmp);
+            rtPathFreeIprt(pszTmp, pszPath);
+        }
+        return rc;
+    }
+
+    int err = errno;
+
+    /*
+     * Fall back on the dynamic linker since /proc is optional.
+     */
+    void *hExe = dlopen(NULL, 0);
+    if (hExe)
+    {
+        struct link_map const *pLinkMap = 0;
+        if (dlinfo(hExe, RTLD_DI_LINKMAP, &pLinkMap) == 0)
+        {
+            const char *pszImageName = pLinkMap->l_name;
+            if (*pszImageName == '/') /* this may not always be absolute, despite the docs. :-( */
+            {
+                char const *pszTmp;
+                int rc = rtPathFromNative(&pszTmp, pszImageName, NULL);
+                AssertMsgRCReturn(rc, ("rc=%Rrc pszImageName=\"%s\"\n", rc, pszImageName), rc);
+                if (pszTmp != pszPath)
+                {
+                    rc = RTStrCopy(pszPath, cchPath, pszTmp);
+                    rtPathFreeIprt(pszTmp, pszPath);
+                }
+                return rc;
+            }
+            /** @todo Try search the PATH for the file name or append the current
+             *        directory, which ever makes sense... */
+        }
+    }
+
+    int rc = RTErrConvertFromErrno(err);
+    AssertMsgFailed(("rc=%Rrc err=%d cchLink=%d hExe=%p\n", rc, err, cchLink, hExe));
+    return rc;
+}
+
diff --git src/VBox/Runtime/r3/posix/fileio-posix.cpp src/VBox/Runtime/r3/posix/fileio-posix.cpp
index 1af2918..706f682 100644
--- src/VBox/Runtime/r3/posix/fileio-posix.cpp
+++ 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, const char *pszFilename, uint64_t fOpen)
     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;
@@ -560,7 +560,7 @@ RTR3DECL(int) RTFileGetSize(RTFILE hFile, uint64_t *pcbSize)
         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)
diff --git src/VBox/Runtime/r3/posix/semevent-posix.cpp src/VBox/Runtime/r3/posix/semevent-posix.cpp
index 67d69cb..6725353 100644
--- src/VBox/Runtime/r3/posix/semevent-posix.cpp
+++ src/VBox/Runtime/r3/posix/semevent-posix.cpp
@@ -48,7 +48,7 @@
 # define pthread_yield() pthread_yield_np()
 #endif
 
-#if defined(RT_OS_SOLARIS) || defined(RT_OS_HAIKU)
+#if defined(RT_OS_SOLARIS) || defined(RT_OS_HAIKU) || defined(RT_OS_NETBSD)
 # include <sched.h>
 # define pthread_yield() sched_yield()
 #endif
diff --git src/VBox/Runtime/r3/posix/semmutex-posix.cpp src/VBox/Runtime/r3/posix/semmutex-posix.cpp
index 89fa962..842af89 100644
--- src/VBox/Runtime/r3/posix/semmutex-posix.cpp
+++ src/VBox/Runtime/r3/posix/semmutex-posix.cpp
@@ -65,7 +65,7 @@ struct RTSEMMUTEXINTERNAL
 #endif
 };
 
-#ifdef RT_OS_DARWIN
+#if defined(RT_OS_DARWIN) || defined(RT_OS_NETBSD)
 /**
  * This function emulate pthread_mutex_timedlock on Mac OS X
  */
@@ -300,10 +300,10 @@ DECL_FORCE_INLINE(int) rtSemMutexRequest(RTSEMMUTEX hMutexSem, RTMSINTERVAL cMil
         }
 
         /* take mutex */
-#ifndef RT_OS_DARWIN
-        int rc = pthread_mutex_timedlock(&pThis->Mutex, &ts);
-#else
+#if defined(RT_OS_DARWIN) || defined(RT_OS_NETBSD)
         int rc = DarwinPthreadMutexTimedlock(&pThis->Mutex, &ts);
+#else
+        int rc = pthread_mutex_timedlock(&pThis->Mutex, &ts);
 #endif
         RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_MUTEX);
         if (rc)
diff --git src/VBox/Runtime/r3/posix/thread2-posix.cpp src/VBox/Runtime/r3/posix/thread2-posix.cpp
index bd7e030..7da1cec 100644
--- src/VBox/Runtime/r3/posix/thread2-posix.cpp
+++ src/VBox/Runtime/r3/posix/thread2-posix.cpp
@@ -62,7 +62,7 @@ RTDECL(int) RTThreadSleep(RTMSINTERVAL cMillies)
         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(RTMSINTERVAL cMillies)
         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())
@@ -130,7 +130,7 @@ RTDECL(bool) RTThreadYield(void)
 #endif
 #ifdef RT_OS_DARWIN
     pthread_yield_np();
-#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
     pthread_yield();
diff --git src/VBox/Runtime/r3/posix/utf8-posix.cpp src/VBox/Runtime/r3/posix/utf8-posix.cpp
index cb723eb..40968d9 100644
--- src/VBox/Runtime/r3/posix/utf8-posix.cpp
+++ src/VBox/Runtime/r3/posix/utf8-posix.cpp
@@ -173,7 +173,7 @@ static int rtstrConvertCached(const void *pvInput, size_t cbInput, const char *p
         iconv_t hIconv = (iconv_t)*phIconv;
         if (hIconv == (iconv_t)-1)
         {
-#ifdef RT_OS_SOLARIS
+#if defined(RT_OS_SOLARIS) || defined(RT_OS_NETBSD)
             /* Solaris doesn't grok empty codeset strings, so help it find the current codeset. */
             if (!*pszInputCS)
                 pszInputCS = rtStrGetLocaleCodeset();
