[Pkg-virtualbox-devel] Bug#632944: GNU/kFreeBSD support

Robert Millan rmh at debian.org
Thu Jul 7 09:12:11 UTC 2011


Package: virtualbox
Version: 4.0.10-dfsg-1
Severity: wishlist
User: debian-bsd at lists.debian.org
Usertags: kfreebsd

This is *work in progress* (I'm not adding the patch tag).

This patch makes virtualbox buildable on Debian GNU/kFreeBSD.  It does still
need some polishing (and some debugging) for which I don't have the time
right now.  I send it here so that it's not lost.

Outstanding problems:

- Build system attempts to build vboxdrv.ko in-place instead of just putting
  it in virtualbox-dkms (i.e. --disable-kmod has no effect).

- virtualbox-dkms (and virtualbox-source) aren't really binary-indep targets.
  The files they're based on are produced during Debian GNU/Linux builds.
  Should different binary-indep packages be produced for each kernel?  Should
  virtualbox-dkms.install only use files from src/ and ignore out/ directory
  completely?

- virtualbox-dkms won't work untill dkms is ported anyway (see #631657).

- Loading vboxdrv.ko doesn't create /dev/vboxdrv or print anything to dmesg.

- Unloading vboxdrv.ko causes machine reboot (triple fault maybe?).

- Userland frontend aborts on start ("Unable to load COM object" through
  GUI message box, plus a few errors in console).

-- System Information:
Debian Release: wheezy/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: kfreebsd-amd64 (x86_64)

Kernel: kFreeBSD 8.2-1-amd64
Locale: LANG=ca_AD.UTF-8, LC_CTYPE=ca_AD.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages virtualbox depends on:
ii  adduser                 3.113            add and remove users and groups
ii  libbsd0                 0.3.0-1          utility functions from BSD systems
ii  libc0.1                 2.13-10          Embedded GNU C Library: Shared lib
ii  libcurl3                7.21.6-3         Multi-protocol file transfer libra
ii  libgcc1                 1:4.6.1-1        GCC support library
ii  libpng12-0              1.2.44-2         PNG library - runtime
ii  libpython2.6            2.6.7-1          Shared Python runtime library (ver
ii  libqtcore4              4:4.7.3-4        Qt 4 core module
ii  libqtgui4               4:4.7.3-4        Qt 4 GUI module
ii  libsdl1.2debian         1.2.14-6.4       Simple DirectMedia Layer
ii  libssl1.0.0             1.0.0d-3         SSL shared libraries
ii  libstdc++6              4.6.1-1          GNU Standard C++ Library v3
ii  libvncserver0           0.9.7-3          API to write one's own vnc server
ii  libx11-6                2:1.4.3-2        X11 client-side library
ii  libxcursor1             1:1.1.12-1       X cursor management library
ii  libxml2                 2.7.8.dfsg-3     GNOME XML library
ii  python                  2.6.6-14         interactive high-level object-orie
ii  python-central          0.6.17           register and build utility for Pyt
ii  zlib1g                  1:1.2.3.4.dfsg-3 compression library - runtime

Versions of packages virtualbox recommends:
ii  libgl1-mesa-glx [libgl1]   7.10.3-3      free implementation of the OpenGL 
ii  libqt4-opengl              4:4.7.3-4     Qt 4 OpenGL module
pn  virtualbox-dkms | virtualb <none>        (no description available)
ii  virtualbox-qt              4.0.10-dfsg-1 x86 virtualization solution - Qt b

Versions of packages virtualbox suggests:
pn  vde2                          <none>     (no description available)
pn  virtualbox-guest-additions-is <none>     (no description available)

-- no debconf information
-------------- next part --------------
=== modified file 'Config.kmk'
--- Config.kmk	2011-07-05 17:05:22 +0000
+++ Config.kmk	2011-07-05 17:09:02 +0000
@@ -206,6 +206,8 @@
   VBOX_PACKAGE_OS = SOLARIS
 else ifeq ($(KBUILD_TARGET),os2)
   VBOX_PACKAGE_OS = OS2
+else if1of ($(KBUILD_TARGET), gnu gnukfreebsd)
+  VBOX_PACKAGE_OS = GNU
 else if1of ($(KBUILD_TARGET), dragonfly freebsd netbsd openbsd)
   VBOX_PACKAGE_OS = BSD
 else
@@ -235,8 +237,8 @@
 ## @{
 # This indicates that additions (of some kind or another) is being _built_.
 # VBOX_WITHOUT_ADDITIONS overrides it.
-#if1of ($(KBUILD_TARGET), freebsd linux os2 solaris win)
-if1of ($(KBUILD_TARGET), freebsd linux solaris win)
+#if1of ($(KBUILD_TARGET), freebsd gnukfreebsd linux os2 solaris win)
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd linux solaris win)
  VBOX_WITH_ADDITIONS = 1
 endif
 # Build the optional ring-0 part of the additions for syntax checking.
@@ -245,7 +247,7 @@
  VBOX_WITH_ADDITION_DRIVERS = 1
 endif
 # Build X11 additions. Can be disabled separately.
-if1of ($(KBUILD_TARGET), dragonfly freebsd linux netbsd openbsd solaris)
+if1of ($(KBUILD_TARGET), dragonfly freebsd gnukfreebsd linux netbsd openbsd solaris)
  VBOX_WITH_X11_ADDITIONS = 1
 endif
 # Enable the building of shared folders in the windows additions.
@@ -280,7 +282,7 @@
 # Include documentation in the package
 VBOX_WITH_DOCS_PACKING = 1
 # Include CHM when building docs (unset in LocalConfig.kmk to suppress CHM)
-ifn1of ($(KBUILD_TARGET), linux)
+ifn1of ($(KBUILD_TARGET), linux gnukfreebsd)
  VBOX_WITH_DOCS_CHM = 1
 endif
 # Don't bother with documentation, overrides VBOX_WITH_DOCS.
@@ -342,7 +344,7 @@
  VBOX_WITH_DBUS = 1
 endif
 # Enable building PAM modules
-if1of ($(KBUILD_TARGET), linux solaris)
+if1of ($(KBUILD_TARGET), linux gnukfreebsd solaris)
  VBOX_WITH_PAM = 1
 endif
 # Disable WINMM support for Windows (not implemented).
@@ -352,7 +354,7 @@
 # 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 gnukfreebsd win freebsd)
  VBOX_WITH_VIDEOHWACCEL = 1
 endif
 # Enable Wddm Video driver for Vista+ guests
@@ -408,7 +410,7 @@
 # Enable MSI support in devices
 VBOX_WITH_MSI_DEVICES = 1
 # Enable host network interface API.
-if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
+if1of ($(KBUILD_TARGET), darwin freebsd gnukfreebsd linux solaris win)
  VBOX_WITH_HOSTNETIF_API = 1
 endif
 ## @}
@@ -424,7 +426,7 @@
 VBOX_WITH_MAIN = 1
 # Set this to prefix all C symbols in XPCOM, to avoid dynamic linking problems
 # caused by our XPCOM library polluting the symbol namespace for system libs.
-if1of ($(KBUILD_TARGET), linux solaris)
+if1of ($(KBUILD_TARGET), linux gnukfreebsd solaris)
  VBOX_WITH_XPCOM_NAMESPACE_CLEANUP = 1
 endif
 # Set this to not use COM or XPCOM in places where it can be avoided.
@@ -461,7 +463,7 @@
 #VBOX_WITH_VBOXFB = 1
 # Enables the Python<->XPCOM and Python<->COM bindings.
 VBOX_WITH_PYTHON ?= 1
-if1of ($(KBUILD_TARGET), darwin linux solaris)
+if1of ($(KBUILD_TARGET), darwin linux gnukfreebsd solaris)
  # Enable Java<->XPCOM bridge + glue code
  VBOX_WITH_JXPCOM ?= 1
 endif
@@ -469,7 +471,7 @@
  # Enable Java<->MSCOM glue, bridge is provided by an external lib (Jacob)
  VBOX_WITH_JMSCOM ?= 1
 endif
-if1of ($(KBUILD_TARGET), darwin linux solaris)
+if1of ($(KBUILD_TARGET), darwin linux fixme solaris)
  # Enable Java<->JAX-WS bridge
  VBOX_WITH_JWS ?= 1
 endif
@@ -485,7 +487,7 @@
 VBOX_WITH_TESTCASES = 1
 # Enables the ffmpeg module for recording test runs.
 # TODO: Enable this for normal build server builds?
-#if1of ($(KBUILD_TARGET), linux)
+#if1of ($(KBUILD_TARGET), linux gnukfreebsd)
 # VBOX_WITH_FFMPEG = 1
 #endif
 # Enable shared folders
@@ -497,13 +499,13 @@
 # Enable this to prevent the guest from writing guest properties.
 VBOX_WITH_GUEST_PROPS_RDONLY_GUEST =
 # Enable the guest control service.
-if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
+if1of ($(KBUILD_TARGET), darwin freebsd gnukfreebsd linux 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 gnukfreebsd linux solaris win)
  VBOX_WITH_CROGL = 1
 endif
 # Enable the VNC server in VBoxHeadless (GPL only).
@@ -516,19 +518,19 @@
 ## @name Networking
 ## @{
 # Use VBoxNetFlt for host interface networking.
-if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
+if1of ($(KBUILD_TARGET), darwin freebsd gnukfreebsd linux solaris win)
  VBOX_WITH_NETFLT = 1
  ifeq ($(KBUILD_TARGET),solaris)
  # Disabled until some Nevada version ships the required headers.
  #  VBOX_WITH_NETFLT_CROSSBOW = 1
  endif
  # Use VBoxNetAdp for host only networking.
- if1of ($(KBUILD_TARGET), darwin freebsd linux solaris) ## @todo this should be set and used on windows too.
+ if1of ($(KBUILD_TARGET), darwin freebsd gnukfreebsd linux solaris) ## @todo this should be set and used on windows too.
   VBOX_WITH_NETADP = 1
  endif
 endif
 # Enable Virtual Distributed Ethernet or not.
-if1of ($(KBUILD_TARGET), freebsd linux)
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd linux)
  VBOX_WITH_VDE = 1
 endif
 ## @}
@@ -584,7 +586,7 @@
 # Where the application files are (going to be) installed.
 #VBOX_PATH_APP_PRIVATE       = /usr/lib/virtualbox
 ifdef VBOX_WITH_HARDENING
- if1of ($(KBUILD_TARGET), linux solaris)
+ if1of ($(KBUILD_TARGET), linux gnukfreebsd solaris)
   VBOX_PATH_APP_PRIVATE      = /opt/VirtualBox
  else ifeq ($(KBUILD_TARGET),darwin)
   VBOX_PATH_APP_PRIVATE      = /Applications/VirtualBox.app/Contents/MacOS
@@ -625,7 +627,7 @@
 ifdef VBOX_WITH_HARDENING
  if1of ($(KBUILD_TARGET), solaris)
   VBOX_WITH_RUNPATH = $(VBOX_PATH_APP_PRIVATE)/$(if-expr $(KBUILD_TARGET_ARCH) == "amd64",amd64,i386)
- else if1of ($(KBUILD_TARGET), freebsd linux)
+ else if1of ($(KBUILD_TARGET), freebsd gnukfreebsd linux)
   VBOX_WITH_RUNPATH = $(VBOX_PATH_APP_PRIVATE)
  endif
 endif
@@ -634,7 +636,7 @@
 # things gets a bit complicated since the $ORIGIN+setuid policy differs.
 #VBOX_WITH_ORIGIN = 1
 ifndef VBOX_WITH_HARDENING
- if1of ($(KBUILD_TARGET), linux solaris)
+ if1of ($(KBUILD_TARGET), linux gnukfreebsd solaris)
   VBOX_WITH_ORIGIN = 1
  endif
 endif
@@ -673,7 +675,7 @@
 ## For experimenting with disabling preemption instead of interrupts
 # when working VT-x/AMD-V in VMMR0.
 ## @todo os2? Reconsider perhaps windows? (see defect) This should be made the default.
-if1of ($(KBUILD_TARGET), darwin freebsd linux solaris win)
+if1of ($(KBUILD_TARGET), darwin freebsd gnukfreebsd linux solaris win)
  VBOX_WITH_VMMR0_DISABLE_PREEMPTION = 1
 endif
 # Mask all Local APIC interrupt vectors which are set up to NMI mode when switching
@@ -886,14 +888,14 @@
  VBOX_WITH_OS2_ADDITIONS_BIN=
  VBOX_WITH_SECURELABEL=
  VBOX_WITH_KCHMVIEWER=
- ifn1of ($(KBUILD_TARGET), linux)
+ ifn1of ($(KBUILD_TARGET), linux gnukfreebsd)
   VBOX_WITH_DOCS=
   VBOX_WITH_DOCS_PACKING=
  endif
  VBOX_WITH_TESTSUITE=
  VBOX_WITH_INTEL_PXE=
  VBOX_WITH_FFMPEG=
- ifn1of ($(KBUILD_TARGET), darwin linux solaris win)
+ ifn1of ($(KBUILD_TARGET), darwin linux gnukfreebsd solaris win)
   VBOX_WITH_INSTALLER=
  endif
  # branding
@@ -927,7 +929,7 @@
   VBOX_PATH_SHARED_LIBS=
   VBOX_PATH_APP_DOCS=
   VBOX_WITH_RUNPATH=
-  if1of ($(KBUILD_TARGET), linux solaris)
+  if1of ($(KBUILD_TARGET), linux gnukfreebsd solaris)
    VBOX_WITH_ORIGIN=1
   endif
  endif
@@ -1036,7 +1038,7 @@
 #
 # Image and object format config.
 #
-if1of ($(KBUILD_TARGET), freebsd linux l4 netbsd openbsd solaris)
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd linux l4 netbsd openbsd solaris)
  VBOX_LDR_FMT = elf
 endif
 ifeq ($(KBUILD_TARGET),darwin)
@@ -1293,6 +1295,7 @@
 DEFS.freebsd = RT_OS_FREEBSD __FREEBSD__
 DEFS.l4      = RT_OS_L4 __L4__ __L4ENV__ L4API_l4v2 ARCH_$(KBUILD_TARGET_ARCH) __NO_CTYPE _FILE_OFFSET_BITS=64
 DEFS.linux   = RT_OS_LINUX _FILE_OFFSET_BITS=64
+DEFS.gnukfreebsd = _FILE_OFFSET_BITS=64
 DEFS.netbsd  = RT_OS_NETBSD
 DEFS.openbsd = RT_OS_OPENBSD
 DEFS.os2     = RT_OS_OS2 __OS2__
@@ -1440,7 +1443,7 @@
 #
 # Add the output dir(s) to the dynamic loader search path.
 #
-if1of ($(KBUILD_HOST), freebsd linux l4 netbsd openbsd solaris)
+if1of ($(KBUILD_HOST), freebsd gnukfreebsd linux l4 netbsd openbsd solaris)
  export LD_LIBRARY_PATH:=$(PATH_BIN):$(PATH_LIB):$(LD_LIBRARY_PATH)
 endif
 ifeq ($(KBUILD_HOST),os2)
@@ -1473,7 +1476,7 @@
  LIB_XPCOM       = $(PATH_BIN)/VBoxXPCOM.s.so
  LIB_DDU         = $(PATH_BIN)/VBoxDDU.s.so
 endif
-if1of ($(KBUILD_TARGET), freebsd linux netbsd openbsd solaris)
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd linux netbsd openbsd solaris)
  LIB_RUNTIME     = $(PATH_BIN)/VBoxRT.so
  LIB_RUNTIME_EF  = $(PATH_LIB)/RuntimeEFCPP.a
  LIB_KPROFILE    = $(PATH_BIN)/kPrf2.so
@@ -1626,7 +1629,7 @@
 
 # We need to export YASM for OSE, but since it was converted to .zip we need to
 # allow for the location used by the zip to be properly cleaned up first.
-if1of ($(KBUILD_HOST).$(KBUILD_HOST_ARCH), linux.x86 solaris.x86 win.x86)
+if1of ($(KBUILD_HOST).$(KBUILD_HOST_ARCH), linux.x86 gnukfreebsd.x86 solaris.x86 win.x86)
  PATH_TOOL_YASM ?= $(PATH_DEVTOOLS_BLD)/bin
 endif
 
@@ -1863,7 +1866,7 @@
   VBOX_LIB_OGL_HOSTCRUTIL = $(PATH_BIN)/VBoxOGLhostcrutil$(VBOX_SUFF_DLL)
  endif
 
- if1of ($(KBUILD_TARGET), freebsd linux solaris)
+ if1of ($(KBUILD_TARGET), freebsd gnukfreebsd linux 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 = \
@@ -2282,7 +2285,7 @@
  SDK_VBOX_LIBXSLT_LIBS   ?= $(PATH_LIB)/VBox-libxslt$(VBOX_SUFF_LIB)
  SDK_VBOX_LIBXSLT_DEFS   ?=
  SDK_VBOX_LIBXSLT_DEFS.win += WIN32 _WINDOWS _MBCS _REENTRANT
-#else if1of ($(KBUILD_TARGET), linux)
+#else if1of ($(KBUILD_TARGET), linux gnukfreebsd)
 # SDK_VBOX_LIBXSLT_INCS      ?=
 # SDK_VBOX_LIBXSLT_LIBS      ?=
 # SDK_VBOX_LIBXSLT_CFLAGS    ?= $(shell pkg-config libxslt-1.0 --cflags)
@@ -2305,6 +2308,7 @@
  SDK_VBOX_ZLIB_INCS  ?=
  SDK_VBOX_ZLIB_LIBS  ?= z
  SDK_VBOX_ZLIB_DEFS.linux ?= _LARGEFILE64_SOURCE
+ SDK_VBOX_ZLIB_DEFS.gnukfreebsd ?= _LARGEFILE64_SOURCE
 endif
 
 SDK_VBOX_OPENSSL      = .
@@ -2313,7 +2317,7 @@
 SDK_VBOX_OPENSSL_ORDERDEPS ?= $(crypto-headers_1_TARGET)
 SDK_VBOX_OPENSSL_LIBS ?= $(PATH_LIB)/VBox-libcrypto$(VBOX_SUFF_LIB)
 # Build entire openssl library, not just the minimal subset.
-if1of ($(KBUILD_TARGET), linux solaris)
+if1of ($(KBUILD_TARGET), linux gnukfreebsd solaris)
  VBOX_OPENSSL_ALL = 1
 endif
 
@@ -2330,7 +2334,7 @@
 endif
 
 SDK_VBOX_FFMPEG       = .
-if1of ($(KBUILD_TARGET), darwin linux os2 solaris win)
+if1of ($(KBUILD_TARGET), darwin linux gnukfreebsd os2 solaris win)
  SDK_VBOX_FFMPEG_INCS ?= \
 	$(PATH_ROOT)/src/libs/ffmpeg-20060710/libavutil \
 	$(PATH_ROOT)/src/libs/ffmpeg-20060710/libavcodec \
@@ -2771,7 +2775,7 @@
 TEMPLATE_VBOXR0DRV_CXXFLAGS.amd64     = $(TEMPLATE_VBOXR0DRV_CFLAGS.amd64)
 endif # Solaris
 
-ifeq ($(KBUILD_TARGET),freebsd)
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
 # x86 FreeBSD (6.2 or something):
 #  cc -O2 -fno-strict-aliasing -pipe -Werror -D_KERNEL -DKLD_MODULE \
 #   -nostdinc -I- -I. -I@ -I@/contrib/altq -I@/../include -I/usr/include \
@@ -2798,9 +2802,9 @@
 # Note: @ -> /usr/src/sys  and  machine -> /usr/src/sys/i386/include
 
 ## The location of the FreeBSD kernel source.
-VBOX_FREEBSD_SRC ?= /usr/src/sys
+VBOX_FREEBSD_SRC ?= /usr/src/kfreebsd-headers-8.2-1-amd64/sys
 ## The FreeBSD /usr/include.
-VBOX_FREEBSD_SYS_INCS ?= /usr/include
+VBOX_FREEBSD_SYS_INCS ?= $(VBOX_FREEBSD_SRC)
 
 TEMPLATE_VBOXR0DRV_TOOL                = $(VBOX_GCC_TOOL)
 TEMPLATE_VBOXR0DRV_LDTOOL              = FREEBSDKMODLD
@@ -2815,7 +2819,7 @@
 	$(VBOX_GCC_WARN) -Wpointer-arith -Winline $(VBOX_GCC_Wno-pointer-sign) \
 	-Wstrict-prototypes -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs \
 	-Wimplicit-function-declaration -Werror-implicit-function-declaration \
-	-O2 -fformat-extensions -ffreestanding -fno-strict-aliasing -fno-common -finline-limit=8000 \
+	-O2 -ffreestanding -fno-strict-aliasing -fno-common -finline-limit=8000 \
 	$(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
 	-nostdinc -std=c99
 TEMPLATE_VBOXR0DRV_CFLAGS.x86          = -m32 -mno-align-long-strings -mpreferred-stack-boundary=2 -mno-mmx -mno-3dnow -mno-sse -mno-sse2
@@ -2824,7 +2828,7 @@
 	-mno-3dnow -msoft-float -fno-asynchronous-unwind-tables -Wundef
 TEMPLATE_VBOXR0DRV_CXXFLAGS            = -fno-exceptions -fno-rtti \
 	$(VBOX_GCC_WARN) -Wpointer-arith -Winline \
-	-O2 -fno-format-extensions -fno-strict-aliasing -fno-common -finline-limit=8000 \
+	-O2 -fno-strict-aliasing -fno-common -finline-limit=8000 \
 	$(VBOX_GCC_fno-stack-protector) $(VBOX_GCC_R0_OPT) $(VBOX_GCC_R0_FP) \
 	-nostdinc
 TEMPLATE_VBOXR0DRV_CXXFLAGS.x86        = $(TEMPLATE_VBOXR0DRV_CFLAGS.x86)
@@ -2847,8 +2851,8 @@
 		$(foreach p,$(libpath), -L$(p))\
 		$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
 # Strip non-exported symbols private and localize the exported ones.
-	awk -f $(VBOX_FREEBSD_SRC)/conf/kmod_syms.awk  $(out) $(if $(othersrc), $(othersrc),/dev/null) \
-		| xargs -J% objcopy % $(out)
+	original-awk -f $(VBOX_FREEBSD_SRC)/conf/kmod_syms.awk  $(out) $(if $(othersrc), $(othersrc),/dev/null) \
+		| while read i ; do objcopy $i $(out) ; done
 
 ## Strip debug info (comment out if debugging or something).
 	objcopy --strip-debug $(out)
@@ -2861,8 +2865,8 @@
 		$(foreach p,$(libpath), -L$(p))\
 		$(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib)))
 # Strip non-exported symbols private and localize the exported ones.
-	awk -f $(VBOX_FREEBSD_SRC)/conf/kmod_syms.awk $(outbase).kld $(if $(othersrc), $(othersrc),/dev/null) \
-		| xargs -J% objcopy % $(outbase).kld
+	original-awk -f $(VBOX_FREEBSD_SRC)/conf/kmod_syms.awk $(outbase).kld $(if $(othersrc), $(othersrc),/dev/null) \
+		| while read i ; do objcopy $i $(outbase).kld ; done
 
 # Link the final .ko (a shared object).
 	ld $(flags) -Bshareable -o $(out) $(outbase).kld
@@ -2983,8 +2987,8 @@
 	-T$(L4_LIBDIR)/../main_dyn.ld -nostdlib \
 	-Wl,--export-dynamic,--dynamic-linker=libld-l4.s.so \
 	-Wl,--rpath-link,$(L4_LIBDIR)
-TEMPLATE_VBOXR3EXE_LDFLAGS.linux       = -Wl,-z,noexecstack $(VBOX_LD_as_needed)
- ifeq ($(KBUILD_TARGET),linux)
+TEMPLATE_VBOXR3EXE_LDFLAGS.gnukfreebsd       = -Wl,-z,noexecstack $(VBOX_LD_as_needed)
+ if1of ($(KBUILD_TARGET), linux gnukfreebsd)
 TEMPLATE_VBOXR3EXE_LIBS                = pthread m rt dl
  else ifeq ($(KBUILD_TARGET),l4)
 TEMPLATE_VBOXR3EXE_LIBS                = \
@@ -3033,6 +3037,7 @@
  endif
  ifdef VBOX_WITH_ORIGIN
   TEMPLATE_VBOXR3EXE_LDFLAGS.linux    += $(VBOX_GCC_ORIGIN_OPT)
+  TEMPLATE_VBOXR3EXE_LDFLAGS.gnukfreebsd    += $(VBOX_GCC_ORIGIN_OPT)
  endif
 endif
 
@@ -3075,7 +3080,7 @@
 #				       -
 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 gnukfreebsd.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)
@@ -3094,7 +3099,7 @@
 #				       -
 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 gnukfreebsd.x86)
  TEMPLATE_VBoxR3DllWarnNoPic_DEFS          = $(TEMPLATE_VBOXR3EXE_DEFS)
  TEMPLATE_VBoxR3DllWarnNoPic_CFLAGS        = $(TEMPLATE_VBOXR3EXE_CFLAGS)
  TEMPLATE_VBoxR3DllWarnNoPic_CXXFLAGS      = $(TEMPLATE_VBOXR3EXE_CXXFLAGS)
@@ -3190,6 +3195,7 @@
 ifn1of ($(KBUILD_TARGET), win os2)
  TEMPLATE_VBOXR3HARDENEDEXE_LDFLAGS       = $(filter-out '$(VBOX_GCC_RPATH_OPT)%,$(TEMPLATE_VBOXR3EXE_LDFLAGS))
  TEMPLATE_VBOXR3HARDENEDEXE_LDFLAGS.linux = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBOXR3EXE_LDFLAGS.linux))
+ TEMPLATE_VBOXR3HARDENEDEXE_LDFLAGS.gnukfreebsd = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBOXR3EXE_LDFLAGS.gnukfreebsd))
 endif
 
 #
@@ -3216,6 +3222,7 @@
  endif
  ifdef VBOX_WITH_ORIGIN
   TEMPLATE_VBoxR3SetUidToRoot_LDFLAGS.linux += $(VBOX_GCC_ORIGIN_OPT)
+  TEMPLATE_VBoxR3SetUidToRoot_LDFLAGS.gnukfreebsd += $(VBOX_GCC_ORIGIN_OPT)
  endif
 endif
 
@@ -3479,9 +3486,10 @@
 TEMPLATE_VBOXMAINEXE_OBJCXXFLAGS.kprofile= $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.kprofile)
 TEMPLATE_VBOXMAINEXE_LDFLAGS.x86         = -m32
 TEMPLATE_VBOXMAINEXE_LDFLAGS.amd64       = -m64
- ifeq ($(KBUILD_TARGET),linux)
+ if1of ($(KBUILD_TARGET), linux gnukfreebsd)
 TEMPLATE_VBOXMAINEXE_LIBS                = pthread m rt $(LIB_RUNTIME) dl
 TEMPLATE_VBOXMAINEXE_LDFLAGS.linux       = $(VBOX_LD_as_needed)
+TEMPLATE_VBOXMAINEXE_LDFLAGS.gnukfreebsd       = $(VBOX_LD_as_needed)
  else ifeq ($(KBUILD_TARGET),l4)
 TEMPLATE_VBOXMAINEXE_LIBS                = $(LIB_RUNTIME)
 # no libs as yet in l4 target - must be added later
@@ -3524,6 +3532,7 @@
  endif
  ifdef VBOX_WITH_ORIGIN
 TEMPLATE_VBOXMAINEXE_LDFLAGS.linux      += $(VBOX_GCC_ORIGIN_OPT)
+TEMPLATE_VBOXMAINEXE_LDFLAGS.gnukfreebsd      += $(VBOX_GCC_ORIGIN_OPT)
  endif
 
 endif # !win
@@ -3631,6 +3640,8 @@
 	NDEBUG TRIMMED
  TEMPLATE_VBOXMAINCLIENTEXE_CXXFLAGS.linux = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.linux) \
 	-pthread
+ TEMPLATE_VBOXMAINCLIENTEXE_CXXFLAGS.gnukfreebsd = $(TEMPLATE_VBOXMAINEXE_CXXFLAGS.gnukfreebsd) \
+	-pthread
 endif
 
 #
@@ -3668,7 +3679,7 @@
   TEMPLATE_VBoxR3ExtPack_CXXFLAGS = $(TEMPLATE_VBOXR3DLLNOXCPT_CXXFLAGS) -fno-rtti
  endif
  TEMPLATE_VBoxR3ExtPack_INST = $(INST_EXTPACK)YouShallOverrideThis/
- ifeq ($(KBUILD_TARGET),linux)
+ if1of ($(KBUILD_TARGET), linux gnukfreebsd)
   TEMPLATE_VBoxR3ExtPack_LDFLAGS = $(filter-out '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RUNPATH)' '$(VBOX_GCC_RPATH_OPT)$(VBOX_WITH_RELATIVE_RUNPATH)', $(TEMPLATE_VBOXR3DLLNOXCPT_LDFLAGS))
  else
   if !defined(VBOX_WITH_RUNPATH) && defined(VBOX_WITH_RELATIVE_RUNPATH)
@@ -3800,7 +3811,7 @@
 
  # Hack LD_LIBRARY_PATH for stuff in tools.
  ifdef VBOX_WITH_QT4_SUN
-  if1of ($(KBUILD_TARGET), linux)
+  if1of ($(KBUILD_TARGET), linux gnukfreebsd)
    export LD_LIBRARY_PATH := $(VBOX_PATH_QT4_LIB):$(LD_LIBRARY_PATH)
   endif
  endif
@@ -3868,6 +3879,7 @@
  else # the gcc guys:
   TEMPLATE_VBOXQT4GUIEXE_TOOL = $(VBOX_GCC_TOOL)
   TEMPLATE_VBOXQT4GUIEXE_DEFS.linux = _REENTRANT
+  TEMPLATE_VBOXQT4GUIEXE_DEFS.gnukfreebsd = _REENTRANT
 
   TEMPLATE_VBOXQT4GUIEXE_DEFS.solaris = _REENTRANT
 
@@ -3881,6 +3893,7 @@
   TEMPLATE_VBOXQT4GUIEXE_CXXFLAGS.x86 = -m32
   TEMPLATE_VBOXQT4GUIEXE_CXXFLAGS.amd64 = -m64
   TEMPLATE_VBOXQT4GUIEXE_CXXFLAGS.linux = -pthread
+  TEMPLATE_VBOXQT4GUIEXE_CXXFLAGS.gnukfreebsd = -pthread
   TEMPLATE_VBOXQT4GUIEXE_OBJCFLAGS = -g -pipe $(VBOX_GCC_PEDANTIC_C) -Wno-long-long -fno-exceptions
   TEMPLATE_VBOXQT4GUIEXE_OBJCFLAGS.x86 = $(TEMPLATE_VBOXQT4GUIEXE_CXXFLAGS.x86)
   TEMPLATE_VBOXQT4GUIEXE_OBJCFLAGS.amd64 = $(TEMPLATE_VBOXQT4GUIEXE_CXXFLAGS.amd64)
@@ -3898,7 +3911,7 @@
 	$(LIB_REM) \
 	$(LIB_VMM)
 
-  ifeq ($(KBUILD_TARGET),linux)
+  if1of ($(KBUILD_TARGET), linux gnukfreebsd)
    TEMPLATE_VBOXQT4GUIEXE_LDFLAGS += $(VBOX_LD_as_needed)
    TEMPLATE_VBOXQT4GUIEXE_LIBS += \
      $(VBOX_XCURSOR_LIBS) \
@@ -4085,7 +4098,7 @@
 TEMPLATE_VBOXBLDPROG_LDFLAGS.sparc32     = -m32
 TEMPLATE_VBOXBLDPROG_LDFLAGS.amd64       = -m64
 TEMPLATE_VBOXBLDPROG_LDFLAGS.sparc64     = -m64
- ifeq ($(KBUILD_HOST),linux)
+ if1of ($(KBUILD_HOST), linux gnukfreebsd)
 TEMPLATE_VBOXBLDPROG_LIBS                = pthread m rt dl crypt
  else ifeq ($(KBUILD_HOST),os2)
 TEMPLATE_VBOXBLDPROG_TOOL                = GXX3OMF
@@ -4160,6 +4173,10 @@
 	$(TEMPLATE_VBOXBLDPROG_LIBS) \
 	crypt \
 	$(TEMPLATE_VBOXBLDPROG_LIBS.linux)
+TEMPLATE_VBoxAdvBldProg_LIBS.gnukfreebsd = \
+	$(TEMPLATE_VBOXBLDPROG_LIBS) \
+	crypt \
+	$(TEMPLATE_VBOXBLDPROG_LIBS.gnukfreebsd)
 TEMPLATE_VBoxAdvBldProg_LIBS.solaris = \
 	$(TEMPLATE_VBOXBLDPROG_LIBS) \
 	contract \
@@ -4247,11 +4264,13 @@
  TEMPLATE_VBOXGUESTR3EXE_CXXFLAGS = $(TEMPLATE_VBOXR3EXE_CXXFLAGS) -fno-exceptions
  TEMPLATE_VBOXGUESTR3EXE_LDFLAGS  = $(filter-out '$(VBOX_GCC_RPATH_OPT)%,$(TEMPLATE_VBOXR3EXE_LDFLAGS))
  TEMPLATE_VBOXGUESTR3EXE_LDFLAGS.linux = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBOXR3EXE_LDFLAGS.linux))
+ TEMPLATE_VBOXGUESTR3EXE_LDFLAGS.gnukfreebsd = $(filter-out $(VBOX_GCC_ORIGIN_OPT),$(TEMPLATE_VBOXR3EXE_LDFLAGS.gnukfreebsd))
 endif
 TEMPLATE_VBOXGUESTR3EXE_INST      = $(INST_ADDITIONS)
 TEMPLATE_VBOXGUESTR3EXE_DEFS     := $(filter-out $(ARCH_BITS_DEFS), $(TEMPLATE_VBOXR3EXE_DEFS)) IN_GUEST IN_GUEST_R3 IN_RT_R3 $(VBOX_GC_ARCH_BITS_DEFS)
 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_DEFS.gnukfreebsd := $(TEMPLATE_VBOXR3EXE_DEFS.gnukfreebsd) LOG_USE_C99 RT_WITHOUT_EXEC_ALLOC
+if1of ($(KBUILD_TARGET), linux gnukfreebsd) # As few libs as possible on linux.
  TEMPLATE_VBOXGUESTR3EXE_LIBS     = pthread rt m
 endif
 if1of ($(KBUILD_TARGET), freebsd netbsd openbsd)
@@ -4334,7 +4353,7 @@
 TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.$(KBUILD_TARGET) = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.$(KBUILD_TYPE)   = $(NO_SUCH_VARIABLE)
 TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS          = -r
-if1of ($(KBUILD_TARGET), dragonfly freebsd linux netbsd openbsd) # the gnu ld guys.
+if1of ($(KBUILD_TARGET), dragonfly freebsd gnukfreebsd linux netbsd openbsd) # the gnu ld guys.
  TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.release = -S
  TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.x86     = -m elf_i386
  TEMPLATE_VBOXGUESTR3XF86MOD_LDFLAGS.amd64   = -m elf_x86_64
@@ -4368,7 +4387,7 @@
 ifeq ($(KBUILD_TARGET_ARCH),amd64)
  TEMPLATE_VBOXGUESTR3XORGMOD_DEFS += _XSERVER64
 endif
-if1of ($(KBUILD_TARGET), linux)
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
  TEMPLATE_VBOXGUESTR3XORGMOD_LDFLAGS = $(TEMPLATE_VBOXGUESTR3DLL_LDFLAGS)
 endif
 TEMPLATE_VBOXGUESTR3XORGMOD_LIBS = \
@@ -4424,6 +4443,7 @@
 TEMPLATE_VBOXCROGLR3HOSTDLL_DEFS             = CHROMIUM_THREADSAFE VBOX_WITH_HGCM UNPACKS
 TEMPLATE_VBOXCROGLR3HOSTDLL_DEFS.win         = _WIN32_WINNT=0x0500 WINDOWS=1
 TEMPLATE_VBOXCROGLR3HOSTDLL_DEFS.linux       = Linux=1 _GNU_SOURCE
+TEMPLATE_VBOXCROGLR3HOSTDLL_DEFS.gnukfreebsd = _GNU_SOURCE
 TEMPLATE_VBOXCROGLR3HOSTDLL_DEFS.solaris     = SunOS=1 _GNU_SOURCE #GLEXT_64_TYPES_DEFINED
 TEMPLATE_VBOXCROGLR3HOSTDLL_DEFS.darwin      = DARWIN=1 GL_GLEXT_LEGACY _GNU_SOURCE
 ifdef VBOX_WITH_COCOA_QT
@@ -4440,6 +4460,7 @@
 	-current_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD) \
 	-compatibility_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD)
 TEMPLATE_VBOXCROGLR3HOSTDLL_LDFLAGS.linux    = -Wl,--no-as-needed
+TEMPLATE_VBOXCROGLR3HOSTDLL_LDFLAGS.gnukfreebsd    = -Wl,--no-as-needed
 TEMPLATE_VBOXCROGLR3HOSTDLL_BLDDIRS          = $(VBOX_PATH_CROGL_GENFILES)/
 
 #
@@ -4458,6 +4479,7 @@
 TEMPLATE_VBOXCROGLR3GUESTDLL_DEFS             = CHROMIUM_THREADSAFE VBOX_WITH_HGCM
 TEMPLATE_VBOXCROGLR3GUESTDLL_DEFS.win         = WINDOWS=1
 TEMPLATE_VBOXCROGLR3GUESTDLL_DEFS.linux       = Linux=1 _GNU_SOURCE
+TEMPLATE_VBOXCROGLR3GUESTDLL_DEFS.gnukfreebsd = _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
 ifdef VBOX_WITH_COCOA_QT
@@ -4615,7 +4637,7 @@
 	$(QUIET)$(MV) -f $@.tmp $@
 
 if !defined(VBOX_OSE) && !defined(VBOX_NOINC_LICENSE_VER_KMK)
- if1of ($(KBUILD_TARGET), freebsd linux netbsd openbsd solaris)
+ if1of ($(KBUILD_TARGET), freebsd gnukfreebsd linux netbsd openbsd solaris)
   # VBOX_LICENSE_VER is used in several Makefiles
   VBOX_LICENSE_VER_KMK = $(PATH_OUT)/license-version.kmk
 $(VBOX_LICENSE_VER_KMK): $(VBOX_BRAND_LICENSE_HTML)
@@ -4730,7 +4752,7 @@
 
 else
 
- ifeq ($(KBUILD_TARGET),linux)
+ ifeq ($(KBUILD_TARGET),linux) # FIXME (see linux.x86 below)
   ifeq ($(origin VBOX_JAVA_HOME),undefined)
    # Add correct detection for you distro after the /usr/../java-6-sun line.
    VBOX_JAVA_HOME := $(firstword $(wildcard \

=== modified file 'configure'
--- configure	2011-07-05 17:05:22 +0000
+++ configure	2011-07-05 17:09:02 +0000
@@ -51,6 +51,9 @@
     ;;
   freebsd)
     ;;
+  gnu/kfreebsd)
+    OS='gnukfreebsd'
+    ;;
   sunos)
     OS='solaris'
     ;;
@@ -914,7 +917,7 @@
   [ -n "$INCZ" ] && I_INCZ=`prefix_I "$INCZ"`
   if test_compile "$LIBZ $I_INCZ" zlib zlib; then
     if test_execute; then
-      echo "if1of (\$(KBUILD_TARGET),darwin freebsd linux solaris)" >> $CNF
+      echo "if1of (\$(KBUILD_TARGET),darwin freebsd linux gnukfreebsd solaris)" >> $CNF
       cnf_append " SDK_VBOX_ZLIB_LIBS" "`strip_l "$LIBZ"`"
       cnf_append " SDK_VBOX_ZLIB_INCS" "$INCZ"
       echo "endif" >> $CNF
@@ -2162,7 +2165,7 @@
 [ $WITH_GSOAP   -eq 0 ] && echo "  --enable-webservice      enable the webservice stuff"
 [ $OSE          -eq 1 ] && echo "  --enable-vnc             enable the VNC server"
 [ $WITH_DOCS    -eq 1 ] && echo "  --disable-docs           don't build the documentation"
-[ "$OS" = "linux" -o "$OS" = "freebsd" ] && echo "  --enable-vde             enable VDE networking"
+[ "$OS" = "linux" -o "$OS" = "freebsd" -o "$OS" = "gnukfreebsd" ] && echo "  --enable-vde             enable VDE networking"
 cat << EOF
   --disable-hardening      don't be strict about /dev/vboxdrv access
   --build-libxml2          build libxml2 from sources
@@ -2544,7 +2547,7 @@
 [ $WITH_JAVA   -eq 1 ] && check_java
 
 # PulseAudio
-if [ "$OS" = "linux" -o "$OS" = "freebsd" ]; then
+if [ "$OS" = "linux" -o "$OS" = "freebsd" -o "$OS" = "gnukfreebsd" ]; then
   if [ $WITH_PULSE -eq 1 ]; then
     check_pulse
   elif [ $WITH_PULSE -eq 0 ]; then
@@ -2590,7 +2593,7 @@
 fi
 
 # VDE
-if [ "$OS" = "linux" -o "$OS" = "freebsd" ]; then
+if [ "$OS" = "linux" -o "$OS" = "freebsd" -o "$OS" = "gnukfreebsd" ]; then
   if [ $WITH_VDE -eq 1 ]; then
     cnf_append "VBOX_WITH_VDE" "1"
   fi

=== modified file 'debian/control'
--- debian/control	2011-07-05 17:05:22 +0000
+++ debian/control	2011-07-05 17:09:02 +0000
@@ -12,14 +12,16 @@
                dkms (>= 2.1.1.1),
                docbook-xml,
                docbook-xsl,
-               g++-multilib [amd64],
+               g++-multilib [any-amd64],
                genisoimage,
                gsoap,
                iasl,
                imagemagick,
                kbuild (>= 1:0.1.5svn2274),
-               libasound2-dev,
-               libcap-dev,
+               libasound2-dev [linux-any],
+               libbsd-dev [kfreebsd-any],
+               libc0.1-dev (>= 2.13-8) [kfreebsd-any], kfreebsd-headers-8.2-1-amd64 (>= 8.2-4) [kfreebsd-any],
+               libcap-dev [linux-any],
                libcurl4-openssl-dev,
                libdrm-dev,
                libfuse-dev,
@@ -69,7 +71,7 @@
 Vcs-Browser: http://git.debian.org/?p=pkg-virtualbox/virtualbox.git
 
 Package: virtualbox-qt
-Architecture: amd64 i386
+Architecture: amd64 i386 kfreebsd-amd64 kfreebsd-i386
 Depends: ${shlibs:Depends},
          ${misc:Depends},
          virtualbox (= ${binary:Version})
@@ -84,7 +86,7 @@
  This package provides the Qt based graphical user interface for VirtualBox.
 
 Package: virtualbox
-Architecture: amd64 i386
+Architecture: amd64 i386 kfreebsd-amd64 kfreebsd-i386
 Depends: ${shlibs:Depends},
          ${misc:Depends},
          ${python:Depends},
@@ -111,7 +113,7 @@
 Package: virtualbox-dbg
 Section: debug
 Priority: extra
-Architecture: amd64 i386
+Architecture: amd64 i386 kfreebsd-amd64 kfreebsd-i386
 Depends: ${misc:Depends},
          virtualbox (= ${binary:Version}) | virtualbox-guest-utils (= ${binary:Version})
 Breaks: virtualbox-ose-dbg (<< 4.0.6-dfsg-1~)
@@ -141,7 +143,7 @@
 
 Package: virtualbox-source
 Section: kernel
-Architecture: all
+Architecture: none
 Depends: ${misc:Depends},
          build-essential,
          debhelper (>= 5),
@@ -178,7 +180,7 @@
 
 Package: virtualbox-guest-source
 Section: kernel
-Architecture: all
+Architecture: none
 Depends: ${misc:Depends}, 
          build-essential,
          debhelper (>= 5),
@@ -199,7 +201,7 @@
 
 Package: virtualbox-guest-x11
 Section: x11
-Architecture: amd64 i386
+Architecture: amd64 i386 kfreebsd-amd64 kfreebsd-i386
 Depends: ${shlibs:Depends},
          ${misc:Depends},
          ${xserver:Depends},
@@ -219,7 +221,7 @@
  They provide closer integration and improve the interactive performance.
 
 Package: virtualbox-guest-utils
-Architecture: amd64 i386
+Architecture: amd64 i386 kfreebsd-amd64 kfreebsd-i386
 Depends: ${shlibs:Depends},
          ${misc:Depends},
          adduser,
@@ -239,7 +241,7 @@
  between the host system and the virtual machine.
 
 Package: virtualbox-fuse
-Architecture: amd64 i386
+Architecture: amd64 i386 kfreebsd-amd64 kfreebsd-i386
 Depends: ${shlibs:Depends},
          ${misc:Depends},
          virtualbox (= ${binary:Version})

=== modified file 'debian/rules'
--- debian/rules	2011-07-05 17:05:22 +0000
+++ debian/rules	2011-07-06 17:26:42 +0000
@@ -119,6 +119,7 @@
 	    --disable-kmods \
 	    --enable-webservice \
 	    --enable-vde \
+	    --build-debug \
 	    --enable-vnc
 
 override_dh_auto_build:
@@ -200,7 +201,7 @@
 	chmod 644 debian/$(sname)$(INSTALL_PATH)/sdk/bindings/xpcom/python/xpcom/client/*.py
 	chmod 644 debian/$(sname)$(INSTALL_PATH)/sdk/bindings/xpcom/java/vboxjxpcom.jar
 
-	chmod 755 debian/$(uxname)/usr/share/virtualbox/x11config.pl
+	-chmod 755 debian/$(uxname)/usr/share/virtualbox/x11config.pl
 	chmod 755 debian/$(sname)/usr/share/virtualbox/VBox.sh
 
 # check if arch-all packages are being built

=== modified file 'debian/virtualbox-dkms.install.in'
--- debian/virtualbox-dkms.install.in	2011-07-05 17:05:22 +0000
+++ debian/virtualbox-dkms.install.in	2011-07-05 17:09:02 +0000
@@ -1,31 +1,15 @@
 out/bin/src/vboxdrv/*.* /usr/src/virtualbox-CVERSION/vboxdrv
-out/bin/src/vboxdrv/linux /usr/src/virtualbox-CVERSION/vboxdrv
+out/bin/src/vboxdrv/freebsd /usr/src/virtualbox-CVERSION/vboxdrv
 out/bin/src/vboxdrv/Makefile /usr/src/virtualbox-CVERSION/vboxdrv
 
-out/bin/src/vboxnetflt/*.* /usr/src/virtualbox-CVERSION/vboxnetflt
-out/bin/src/vboxnetflt/linux /usr/src/virtualbox-CVERSION/vboxnetflt
-out/bin/src/vboxnetflt/Makefile /usr/src/virtualbox-CVERSION/vboxnetflt
-
-out/bin/src/vboxnetadp/*.* /usr/src/virtualbox-CVERSION/vboxnetadp
-out/bin/src/vboxnetadp/linux /usr/src/virtualbox-CVERSION/vboxnetadp
-out/bin/src/vboxnetadp/Makefile /usr/src/virtualbox-CVERSION/vboxnetadp
-
 out/bin/src/vboxdrv/*-generated.h /usr/src/virtualbox-CVERSION/include
 out/bin/src/vboxdrv/include/iprt/* /usr/src/virtualbox-CVERSION/include/iprt
 out/bin/src/vboxdrv/include/VBox/* /usr/src/virtualbox-CVERSION/include/VBox
 out/bin/src/vboxdrv/include/internal/* /usr/src/virtualbox-CVERSION/include/internal
 
-out/bin/src/vboxnetflt/include/iprt/* /usr/src/virtualbox-CVERSION/include/iprt
-out/bin/src/vboxnetflt/include/VBox/* /usr/src/virtualbox-CVERSION/include/VBox
-
-out/bin/src/vboxnetadp/include/iprt/* /usr/src/virtualbox-CVERSION/include/iprt
-out/bin/src/vboxnetadp/include/VBox/* /usr/src/virtualbox-CVERSION/include/VBox
-out/bin/src/vboxnetadp/include/internal/* /usr/src/virtualbox-CVERSION/include/internal
-
 out/bin/src/vboxdrv/r0drv /usr/src/virtualbox-CVERSION
 out/bin/src/vboxdrv/common /usr/src/virtualbox-CVERSION
 out/bin/src/vboxdrv/generic /usr/src/virtualbox-CVERSION
-out/bin/src/vboxdrv/math /usr/src/virtualbox-CVERSION
 out/bin/src/vboxdrv/VBox /usr/src/virtualbox-CVERSION
 out/bin/src/vboxdrv/include/iprt/nocrt /usr/src/virtualbox-CVERSION/include/iprt
 

=== modified file 'debian/virtualbox-guest-dkms.install.in'
--- debian/virtualbox-guest-dkms.install.in	2011-07-05 17:05:22 +0000
+++ debian/virtualbox-guest-dkms.install.in	2011-07-05 17:09:02 +0000
@@ -1,26 +1,5 @@
-out/bin/additions/src/vboxguest/*.* /usr/src/virtualbox-guest-CVERSION/vboxguest
-out/bin/additions/src/vboxguest/common /usr/src/virtualbox-guest-CVERSION/vboxguest
-out/bin/additions/src/vboxguest/generic /usr/src/virtualbox-guest-CVERSION/vboxguest
-out/bin/additions/src/vboxguest/VBox /usr/src/virtualbox-guest-CVERSION/vboxguest
-out/bin/additions/src/vboxguest/build_in_tmp /usr/src/virtualbox-guest-CVERSION/vboxguest
-out/bin/additions/src/vboxguest/Makefile /usr/src/virtualbox-guest-CVERSION/vboxguest
-
-out/bin/additions/src/vboxsf/*.* /usr/src/virtualbox-guest-CVERSION/vboxsf
-out/bin/additions/src/vboxsf/build_in_tmp /usr/src/virtualbox-guest-CVERSION/vboxsf
-out/bin/additions/src/vboxsf/Makefile /usr/src/virtualbox-guest-CVERSION/vboxsf
-
-out/bin/additions/src/vboxvideo/*.* /usr/src/virtualbox-guest-CVERSION/vboxvideo
-out/bin/additions/src/vboxvideo/build_in_tmp /usr/src/virtualbox-guest-CVERSION/vboxvideo
-out/bin/additions/src/vboxvideo/Makefile /usr/src/virtualbox-guest-CVERSION/vboxvideo
-
-out/bin/additions/src/vboxguest/include/iprt/* /usr/src/virtualbox-guest-CVERSION/include/iprt
-out/bin/additions/src/vboxguest/include/VBox/* /usr/src/virtualbox-guest-CVERSION/include/VBox
-out/bin/additions/src/vboxguest/include/internal/* /usr/src/virtualbox-guest-CVERSION/include/internal
-
-out/bin/additions/src/vboxsf/include/iprt/* /usr/src/virtualbox-guest-CVERSION/include/iprt
-out/bin/additions/src/vboxsf/include/VBox/* /usr/src/virtualbox-guest-CVERSION/include/VBox
-
-out/bin/additions/src/vboxguest/r0drv /usr/src/virtualbox-guest-CVERSION/
+out/bin/additions/src/vboxvideo_drm/*.* /usr/src/virtualbox-guest-CVERSION/vboxvideo_drm
+out/bin/additions/src/vboxvideo_drm/Makefile /usr/src/virtualbox-guest-CVERSION/vboxvideo_drm
 
 debian/virtualbox-guest-dkms.files/Makefile /usr/src/virtualbox-guest-CVERSION
 

=== modified file 'debian/virtualbox-guest-utils.install'
--- debian/virtualbox-guest-utils.install	2011-07-05 17:05:22 +0000
+++ debian/virtualbox-guest-utils.install	2011-07-05 17:09:02 +0000
@@ -1,4 +1,4 @@
-out/bin/additions/VBoxService	/usr/sbin
+#out/bin/additions/VBoxService	/usr/sbin
 out/bin/additions/VBoxControl	/usr/sbin
-out/bin/additions/mount.vboxsf	/sbin
+#out/bin/additions/mount.vboxsf	/sbin
 out/bin/additions/pam_vbox.so	/lib/security

=== modified file 'debian/virtualbox-guest-x11.install'
--- debian/virtualbox-guest-x11.install	2011-07-05 17:05:22 +0000
+++ debian/virtualbox-guest-x11.install	2011-07-05 17:09:02 +0000
@@ -1,6 +1,6 @@
-out/bin/additions/VBoxClient /usr/bin
-src/VBox/Additions/x11/Installer/x11config.pl /usr/share/virtualbox
-src/VBox/Additions/x11/Installer/98vboxadd-xclient /etc/X11/Xsession.d
-out/bin/additions/vboxmouse_drv.so /usr/lib/xorg/modules/input
-out/bin/additions/vboxvideo_drv.so /usr/lib/xorg/modules/drivers
+#out/bin/additions/VBoxClient /usr/bin
+#src/VBox/Additions/x11/Installer/x11config.pl /usr/share/virtualbox
+#src/VBox/Additions/x11/Installer/98vboxadd-xclient /etc/X11/Xsession.d
+#out/bin/additions/vboxmouse_drv.so /usr/lib/xorg/modules/input
+#out/bin/additions/vboxvideo_drv.so /usr/lib/xorg/modules/drivers
 out/bin/additions/VBoxOGL*.so /usr/lib

=== modified file 'include/VBox/VBoxGuest.h'
--- include/VBox/VBoxGuest.h	2011-07-05 17:05:22 +0000
+++ include/VBox/VBoxGuest.h	2011-07-05 17:09:02 +0000
@@ -175,7 +175,7 @@
 # define VBOXGUEST_IOCTL_CODE_FAST_(Function)       _IO(  'V', (Function))
 # define VBOXGUEST_IOCTL_STRIP_SIZE(Code)           VBOXGUEST_IOCTL_CODE_(_IOC_NR((Code)), 0)
 
-#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(__FreeBSD_kernel__) /** @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)

=== modified file 'include/VBox/usb.h'
--- include/VBox/usb.h	2011-07-05 17:05:22 +0000
+++ include/VBox/usb.h	2011-07-05 17:09:02 +0000
@@ -117,7 +117,7 @@
     uint8_t         bBus;
     /** The port number. */
     uint8_t         bPort;
-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
     /** Device number. */
     uint8_t         bDevNum;
 #endif

=== modified file 'include/iprt/alloca.h'
--- include/iprt/alloca.h	2011-07-05 17:05:22 +0000
+++ include/iprt/alloca.h	2011-07-05 17:09:02 +0000
@@ -37,19 +37,26 @@
  * When we're in kernel territory it starts getting a bit more
  * interesting of course...
  */
-#if defined(IN_RING0) \
- && (defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD))
+#ifdef IN_RING0
+
+# if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
 /* ASSUMES GNU C */
-# define alloca(cb) __builtin_alloca(cb)
+#  define alloca(cb) __builtin_alloca(cb)
+# else
+#  include <stdlib.h>
+#  include <malloc.h>
+# endif
 
 #else
+
 # include <stdlib.h>
-# if !defined(RT_OS_DARWIN) && !defined(RT_OS_FREEBSD)
+# if !defined(RT_OS_DARWIN) && !defined(RT_OS_FREEBSD) && !defined(__GLIBC__)
 #  include <malloc.h>
 # endif
 # ifdef RT_OS_SOLARIS
 #  include <alloca.h>
 # endif
+
 #endif
 
 #endif

=== modified file 'include/iprt/spinlock.h'
--- include/iprt/spinlock.h	2011-07-05 17:05:22 +0000
+++ include/iprt/spinlock.h	2011-07-05 17:09:02 +0000
@@ -61,7 +61,7 @@
     unsigned long   flFlags;
 #  define RTSPINLOCKTMP_INITIALIZER { 0 }
 
-# elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
+# elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__) || defined(RT_OS_SOLARIS)
     /** The saved [R|E]FLAGS. */
     RTCCUINTREG     uFlags;
 #  define RTSPINLOCKTMP_INITIALIZER { 0 }

=== modified file 'include/iprt/stdarg.h'
--- include/iprt/stdarg.h	2011-07-05 17:05:22 +0000
+++ include/iprt/stdarg.h	2011-07-05 17:09:02 +0000
@@ -27,10 +27,10 @@
 #define ___iprt_stdarg_h
 
 #if    !defined(IPRT_NO_CRT) \
-    && !(defined(RT_OS_FREEBSD) && defined(_KERNEL))
+    && !((defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && defined(_KERNEL))
 
 # include <stdarg.h>
-#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
+#elif (defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && defined(_KERNEL)
 # include <machine/stdarg.h>
 #else
 # include <iprt/types.h>

=== modified file 'include/iprt/stdint.h'
--- include/iprt/stdint.h	2011-07-05 17:05:22 +0000
+++ include/iprt/stdint.h	2011-07-05 17:09:02 +0000
@@ -34,6 +34,7 @@
  */
 #if !(defined(RT_OS_LINUX) && defined(__KERNEL__))  \
   && !(defined(RT_OS_FREEBSD) && defined(_KERNEL)) \
+  && !(defined(__FreeBSD_kernel__) && defined(_KERNEL)) \
   && !defined(_MSC_VER) \
   && !defined(__IBMC__) \
   && !defined(__IBMCPP__) \
@@ -62,7 +63,7 @@
 #  define UINT32_C(Value)   (Value ## U)
 # endif /* 64-bit darwin kludge. */
 
-#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
+#elif (defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && defined(_KERNEL)
 
 # ifndef __STDC_CONSTANT_MACROS
 #  define __STDC_CONSTANT_MACROS

=== modified file 'include/iprt/string.h'
--- include/iprt/string.h	2011-07-05 17:05:22 +0000
+++ include/iprt/string.h	2011-07-05 17:09:02 +0000
@@ -37,7 +37,12 @@
 RT_C_DECLS_BEGIN
 # include "xf86_ansic.h"
 RT_C_DECLS_END
-#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
+#elif (defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && defined(_KERNEL)
+/* stolen from http://vbox.innotek.de/pipermail/vbox-dev/2011-January/003561.html
+   hopefully fixes "link_elf_obj: symbol _Z6memcpyPvPKvm undefined" error
+   similar to http://lists.freebsd.org/pipermail/freebsd-current/2010-January/014715.html
+*/
+RT_C_DECLS_BEGIN
 /** @todo
  * XXX: Very ugly hack to get things build on recent FreeBSD builds. They have
  * memchr now and we need to include param.h to get __FreeBSD_version and make
@@ -65,6 +70,7 @@
    * Defining a macro using bcopy here
    */
 # define memmove(dst, src, size) bcopy(src, dst, size)
+RT_C_DECLS_END
 #elif defined(RT_OS_SOLARIS) && defined(_KERNEL)
   /*
    * Same case as with FreeBSD kernel:
@@ -90,7 +96,7 @@
 RT_C_DECLS_END
 #endif
 
-#if defined(RT_OS_FREEBSD) && defined(_KERNEL)
+#if (defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && defined(_KERNEL)
 RT_C_DECLS_BEGIN
 #if __FreeBSD_version < 900000
 void *memchr(const void *pv, int ch, size_t cb);

=== modified file 'include/iprt/types.h'
--- include/iprt/types.h	2011-07-05 17:05:22 +0000
+++ include/iprt/types.h	2011-07-05 17:09:02 +0000
@@ -53,7 +53,7 @@
 #  endif
 #  include <sys/types.h>
 
-# elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
+# elif (defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && defined(_KERNEL)
     /*
      * Kludge for the FreeBSD kernel:
      *  stddef.h and sys/types.h have slightly different offsetof definitions
@@ -71,7 +71,7 @@
 #   error "offsetof is not defined..."
 #  endif
 
-# elif defined(RT_OS_FREEBSD) && HC_ARCH_BITS == 64 && defined(RT_ARCH_X86)
+# elif (defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && HC_ARCH_BITS == 64 && defined(RT_ARCH_X86)
     /*
      * Kludge for compiling 32-bit code on a 64-bit FreeBSD:
      *  FreeBSD declares uint64_t and int64_t wrong (long unsigned and long int

=== modified file 'src/VBox/Additions/Makefile.kmk'
--- src/VBox/Additions/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Additions/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -52,7 +52,7 @@
   include $(PATH_SUB_CURRENT)/x11/Makefile.kmk
  endif
 
- ifeq ($(KBUILD_TARGET),freebsd)
+ if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
   include $(PATH_SUB_CURRENT)/freebsd/Makefile.kmk
  endif
  ifeq ($(KBUILD_TARGET),linux)

=== modified file 'src/VBox/Additions/common/VBoxGuest/Makefile.kmk'
--- src/VBox/Additions/common/VBoxGuest/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Additions/common/VBoxGuest/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -19,13 +19,15 @@
 include	$(KBUILD_PATH)/subheader.kmk
 
 
-if1of ($(KBUILD_TARGET), freebsd $(if $(defined VBOX_WITH_ADDITION_DRIVERS),linux,) os2 solaris win)
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd $(if $(defined VBOX_WITH_ADDITION_DRIVERS),linux,) os2 solaris win)
  #
  # VBoxGuest - The Guest Additions Driver.
  #
  SYSMODS += VBoxGuest
  VBoxGuest_TEMPLATE      = VBOXGUESTR0
- VBoxGuest_NAME.freebsd  = vboxguest
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+ VBoxGuest_NAME          = vboxguest
+endif
  VBoxGuest_NAME.linux    = vboxguest
  VBoxGuest_NAME.solaris  = vboxguest
  VBoxGuest_NOINST.linux  = true
@@ -46,10 +48,14 @@
  #VBoxGuest_DEFS.win     += LOG_ENABLED LOG_TO_BACKDOOR
  VBoxGuest_DEPS.solaris += $(VBOX_SVN_REV_KMK)
  VBoxGuest_DEPS.linux   += $(VBOX_SVN_REV_HEADER)
- VBoxGuest_DEPS.freebsd += $(VBOX_SVN_REV_HEADER)
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+ VBoxGuest_DEPS         += $(VBOX_SVN_REV_HEADER)
+endif
  VBoxGuest_DEFS          = VBGL_VBOXGUEST VBOX_WITH_HGCM
  VBoxGuest_INCS          = .
- VBoxGuest_INCS.freebsd  = $(PATH_VBoxGuest) $(PATH_INS)/gen-sys-hdrs
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+ VBoxGuest_INCS         += $(PATH_VBoxGuest) $(PATH_INS)/gen-sys-hdrs
+endif
  VBoxGuest_INCS.linux    = ../../../Runtime/r0drv/linux
  ifneq ($(KBUILD_TARGET),os2)
   ifeq ($(KBUILD_TARGET),win)
@@ -66,10 +72,12 @@
     VBoxGuest.cpp_SDKS   = WINDDKWLH
    endif
   endif # win
-  ifn1of ($(KBUILD_TARGET), linux freebsd solaris)
+  if1of ($(KBUILD_TARGET), linux freebsd solaris)
+   VBoxGuest_SOURCES    = VBoxGuest-$(KBUILD_TARGET).c
+  else ifeq ($(KBUILD_TARGET),gnukfreebsd)
+   VBoxGuest_SOURCES    = VBoxGuest-freebsd.c
+  else
    VBoxGuest_SOURCES    = VBoxGuest-$(KBUILD_TARGET).cpp
-  else
-   VBoxGuest_SOURCES    = VBoxGuest-$(KBUILD_TARGET).c
   endif
   VBoxGuest_SOURCES     += \
   	VBoxGuest.cpp \
@@ -82,10 +90,12 @@
   VBoxGuest_LIBS        += \
   	$(VBOX_LIB_VBGL_R0BASE) \
   	$(VBOX_LIB_IPRT_GUEST_R0)
-  VBoxGuest_ORDERDEPS.freebsd = \
+  if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+    VBoxGuest_ORDERDEPS += \
   	$(PATH_INS)/gen-sys-hdrs/pci_if.h \
   	$(PATH_INS)/gen-sys-hdrs/bus_if.h \
   	$(PATH_INS)/gen-sys-hdrs/device_if.h
+  endif
  else # OS/2:
   # The library order is crucial, so a bit of trickery is necessary.
   # A library is used to make sure that VBoxGuestA-os2.asm is first in the link. (temporary hack?)
@@ -205,7 +215,8 @@
 
 endif # Linux
 
-ifeq ($(KBUILD_TARGET),freebsd)
+# fixme: add dkms config (see linux case above)
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
  #
  # Install the source files and script(s).
  #

=== modified file 'src/VBox/Additions/common/crOpenGL/Makefile.kmk'
--- src/VBox/Additions/common/crOpenGL/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Additions/common/crOpenGL/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -195,7 +195,7 @@
 	$(VBOX_LIB_VBGL_R3_SHARED) \
 	$(VBOX_LIB_OGL_CRUTIL) \
 	$(PATH_LIB)/additions/VBoxOGLspuload$(VBOX_SUFF_LIB)
-if1of ($(KBUILD_TARGET), linux solaris freebsd)
+if1of ($(KBUILD_TARGET), linux solaris freebsd gnukfreebsd)
  VBoxOGL_LIBS += \
  	$(PATH_LIB)/libXcomposite.so \
  	$(PATH_LIB)/libXdamage.so \

=== modified file 'src/VBox/Additions/freebsd/Makefile.kmk'
--- src/VBox/Additions/freebsd/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Additions/freebsd/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -18,10 +18,6 @@
 SUB_DEPTH = ../../../..
 include	$(KBUILD_PATH)/subheader.kmk
 
-ifneq ($(KBUILD_HOST),freebsd)
-$(error "The FreeBSD guest additions installer can only be built on FreeBSD!")
-endif
-
 # Include sub-makefiles.
 #include $(PATH_SUB_CURRENT)/vboxvfs/Makefile.kmk
 include $(PATH_SUB_CURRENT)/drm/Makefile.kmk

=== modified file 'src/VBox/Additions/freebsd/drm/Makefile.kmk'
--- src/VBox/Additions/freebsd/drm/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Additions/freebsd/drm/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -24,9 +24,6 @@
 ifdef VBOX_WITH_ADDITION_DRIVERS
  SYSMODS  += vboxvideo_drm
 endif
-ifneq ($(KBUILD_HOST),freebsd)
-$(error "The FreeBSD guest additions can only be built on FreeBSD!")
-endif
 
 #
 # Populate FILES_VBOXVIDEO_DRM_NOBIN
@@ -45,14 +42,14 @@
 vboxvideo_drm_NAME          = vboxvideo
 vboxvideo_drm_DEFS          = VBOX_WITH_HGCM VBOX_SVN_REV=$(VBOX_SVN_REV)
 vboxvideo_drm_DEPS         += $(VBOX_SVN_REV_KMK)
-vboxvideo_drm_INCS.freebsd  = \
+vboxvideo_drm_INCS.gnukfreebsd  = \
 	$(vboxvideo_drm_0_OUTDIR) \
 	$(PATH_INS)/gen-sys-hdrs
 vboxvideo_drm_SOURCES       = vboxvideo_drm.c
 vboxvideo_drm_LIBS          = \
 	$(VBOX_LIB_VBGL_R0) \
 	$(VBOX_LIB_IPRT_GUEST_R0)
-vboxvideo_drm_ORDERDEPS.freebsd = \
+vboxvideo_drm_ORDERDEPS.gnukfreebsd = \
 	$(PATH_INS)/gen-sys-hdrs/pci_if.h \
 	$(PATH_INS)/gen-sys-hdrs/bus_if.h \
 	$(PATH_INS)/gen-sys-hdrs/device_if.h \

=== modified file 'src/VBox/Additions/x11/VBoxClient/Makefile.kmk'
--- src/VBox/Additions/x11/VBoxClient/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Additions/x11/VBoxClient/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -28,7 +28,9 @@
 ifdef VBOX_WITH_DBUS
  VBoxClient_DEFS += VBOX_WITH_DBUS
 endif
-VBoxClient_DEFS.linux += _GNU_SOURCE
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBoxClient_DEFS += _GNU_SOURCE
+endif
 VBoxClient_SOURCES = \
 	main.cpp
 VBoxClient_SOURCES += \
@@ -39,8 +41,10 @@
 	$(VBOX_LIBPATH32_X11)
 VBoxClient_LIBS.freebsd = \
 	iconv
-VBoxClient_LIBS.linux = \
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBoxClient_LIBS += \
 	dl
+endif
 VBoxClient_LIBS.solaris = \
 	dl
 VBoxClient_LIBS = \

=== modified file 'src/VBox/Devices/Makefile.kmk'
--- src/VBox/Devices/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Devices/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -96,8 +96,9 @@
   endif
  endif
 
- VBoxDDU_LDFLAGS.linux    = -Wl,--no-undefined
- VBoxDDU_LDFLAGS.l4       = -Wl,--no-undefined
+ if1of ($(KBUILD_TARGET), linux l4 gnukfreebsd)
+  VBoxDDU_LDFLAGS        += -Wl,--no-undefined
+ endif
 
  #
  # VBoxDDULnxHostR3 (Only needed for l4, currently for executing vditool on L4Linux.)
@@ -215,8 +216,9 @@
  	-framework IOKit \
  	-framework Carbon \
  	-framework DiskArbitration
- VBoxDD_LDFLAGS.linux    = -Wl,--no-undefined
- VBoxDD_LDFLAGS.l4       = -Wl,--no-undefined
+ if1of ($(KBUILD_TARGET), linux l4 gnukfreebsd)
+  VBoxDD_LDFLAGS        += -Wl,--no-undefined
+ endif
 
 
  #
@@ -244,8 +246,9 @@
  endif
  VBoxDD2_LIBS.darwin    += $(LIB_REM)
  VBoxDD2_LDFLAGS.darwin  = -install_name $(VBOX_DYLD_EXECUTABLE_PATH)/VBoxDD2.dylib
- VBoxDD2_LDFLAGS.linux   = -Wl,--no-undefined
- VBoxDD2_LDFLAGS.l4      = -Wl,--no-undefined
+ if1of ($(KBUILD_TARGET), linux l4 gnukfreebsd)
+  VBoxDD2_LDFLAGS       += -Wl,--no-undefined
+ endif
 
  ifdef VBOX_WITH_PXE_ROM
   VBoxDD2_DEFS          += VBOX_WITH_PXE_ROM
@@ -261,8 +264,9 @@
  	VBOX_HGCM_HOST_CODE \
  	VBOX_WITH_HGCM \
  	$(if $(VBOX_BIOS_DMI_FALLBACK),VBOX_BIOS_DMI_FALLBACK,)
- DevicesR3_DEFS.linux   += _GNU_SOURCE
- DevicesR3_DEFS.l4      += _GNU_SOURCE
+ if1of ($(KBUILD_TARGET), linux l4 gnukfreebsd)
+  DevicesR3_DEFS        += _GNU_SOURCE
+ endif
 
  DevicesR3_INCS          = \
  	build
@@ -931,13 +935,12 @@
  	Serial/DrvHostSerial.cpp
  endif # darwin
 
- ifeq ($(KBUILD_TARGET),freebsd)
+ if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
  Drivers_SOURCES      := $(filter-out \
  	Storage/DrvHostFloppy% \
  	, $(Drivers_SOURCES)) \
  	Audio/ossaudio.c \
- 	Serial/DrvHostSerial.cpp
- Drivers_SOURCES.freebsd = \
+ 	Serial/DrvHostSerial.cpp \
  	Network/DrvTAP.cpp
  endif # freebsd
 
@@ -1027,14 +1030,12 @@
  endif
 
  ifdef VBOX_WITH_PULSE
-  Drivers_DEFS.linux   += VBOX_WITH_PULSE
-  Drivers_SOURCES.linux+= \
- 	Audio/pulseaudio.c \
- 	Audio/pulse_stubs.c
-  Drivers_DEFS.freebsd += VBOX_WITH_PULSE
-  Drivers_SOURCES.freebsd+= \
- 	Audio/pulseaudio.c \
- 	Audio/pulse_stubs.c
+  if1of ($(KBUILD_TARGET), linux freebsd gnukfreebsd)
+   Drivers_DEFS        += VBOX_WITH_PULSE
+   Drivers_SOURCES     += \
+ 	Audio/pulseaudio.c \
+ 	Audio/pulse_stubs.c
+  endif
  endif
 
  ifdef VBOX_WITH_VUSB
@@ -1090,10 +1091,12 @@
  	USB/USBProxyDevice.cpp \
  	USB/solaris/USBProxyDevice-solaris.cpp
 
-  Drivers_DEFS.freebsd      += VUSB_HAVE_USBPROXY_DEVICE
-  Drivers_SOURCES.freebsd   += \
+  if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+   Drivers_DEFS           += VUSB_HAVE_USBPROXY_DEVICE
+   Drivers_SOURCES        += \
  	USB/USBProxyDevice.cpp \
  	USB/freebsd/USBProxyDevice-freebsd.cpp
+  endif
 
   ifdef VBOX_WITH_SCSI
    Drivers_SOURCES += \

=== modified file 'src/VBox/Devices/Network/slirp/slirp.c'
--- src/VBox/Devices/Network/slirp/slirp.c	2011-07-05 17:05:22 +0000
+++ src/VBox/Devices/Network/slirp/slirp.c	2011-07-05 17:09:02 +0000
@@ -41,6 +41,8 @@
  * THE SOFTWARE.
  */
 
+#define _GNU_SOURCE 1
+
 #include "slirp.h"
 #ifdef RT_OS_OS2
 # include <paths.h>

=== modified file 'src/VBox/Devices/PC/Etherboot-src/Makefile.kmk'
--- src/VBox/Devices/PC/Etherboot-src/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Devices/PC/Etherboot-src/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -18,7 +18,7 @@
 SUB_DEPTH = ../../../../..
 include $(KBUILD_PATH)/subheader.kmk
 
-if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), darwin.x86 darwin.amd64 os2.x86 solaris.x86 solaris.amd64 win.x86 win.amd64 linux.amd64 freebsd.amd64)
+if1of ($(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), darwin.x86 darwin.amd64 os2.x86 solaris.x86 solaris.amd64 win.x86 win.amd64 linux.amd64 freebsd.amd64 gnukfreebsd.amd64)
  #
  # Build it from a precompiled binary.
  # See notes about the binary load address and size way below.

=== modified file 'src/VBox/Devices/Serial/DrvHostSerial.cpp'
--- src/VBox/Devices/Serial/DrvHostSerial.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Devices/Serial/DrvHostSerial.cpp	2011-07-05 17:09:02 +0000
@@ -32,7 +32,7 @@
 #include <iprt/semaphore.h>
 #include <iprt/uuid.h>
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
 # include <errno.h>
 # ifdef RT_OS_SOLARIS
 #  include <sys/termios.h>
@@ -100,7 +100,7 @@
     /** the device path */
     char                        *pszDevicePath;
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
     /** the device handle */
     RTFILE                      DeviceFile;
 # ifdef RT_OS_DARWIN
@@ -193,7 +193,7 @@
 static DECLCALLBACK(int) drvHostSerialSetParameters(PPDMICHARCONNECTOR pInterface, unsigned Bps, char chParity, unsigned cDataBits, unsigned cStopBits)
 {
     PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
     struct termios *termiosSetup;
     int baud_rate;
 #elif defined(RT_OS_WINDOWS)
@@ -482,7 +482,7 @@
         {
             /* copy the send queue so we get a linear buffer with the maximal size. */
             uint8_t ch = pThis->u8SendByte;
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
 
             size_t cbWritten;
             rc = RTFileWrite(pThis->DeviceFile, &ch, 1, &cbWritten);
@@ -677,7 +677,7 @@
             }
             cbRemaining = cbRead;
 
-#elif defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#elif defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
 
             size_t cbRead;
             struct pollfd aFDs[2];
@@ -842,7 +842,7 @@
 static DECLCALLBACK(int) drvHostSerialWakeupRecvThread(PPDMDRVINS pDrvIns, PPDMTHREAD /*pThread*/)
 {
     PDRVHOSTSERIAL pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTSERIAL);
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
     return RTFileWrite(pThis->WakeupPipeW, "", 1, NULL);
 #elif defined(RT_OS_WINDOWS)
     if (!SetEvent(pThis->hHaltEventSem))
@@ -853,7 +853,7 @@
 #endif
 }
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
 /* -=-=-=-=- Monitor thread -=-=-=-=- */
 
 /**
@@ -973,7 +973,7 @@
 {
     PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
     int modemStateSet = 0;
     int modemStateClear = 0;
 
@@ -1021,7 +1021,7 @@
 {
     PDRVHOSTSERIAL pThis = PDMICHAR_2_DRVHOSTSERIAL(pInterface);
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
     if (fBreak)
         ioctl(pThis->DeviceFile, TIOCSBRK);
     else
@@ -1057,7 +1057,7 @@
     RTSemEventDestroy(pThis->SendSem);
     pThis->SendSem = NIL_RTSEMEVENT;
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
 
     if (pThis->WakeupPipeW != NIL_RTFILE)
     {
@@ -1119,7 +1119,7 @@
     /*
      * Init basic data members and interfaces.
      */
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
     pThis->DeviceFile  = NIL_RTFILE;
 # ifdef RT_OS_DARWIN
     pThis->DeviceFileR = NIL_RTFILE;
@@ -1211,7 +1211,7 @@
         {
             case VERR_ACCESS_DENIED:
                 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
                                            N_("Cannot open host device '%s' for read/write access. Check the permissions "
                                               "of that device ('/bin/ls -l %s'): Most probably you need to be member "
                                               "of the device group. Make sure that you logout/login after changing "
@@ -1229,7 +1229,7 @@
     }
 
     /* Set to non blocking I/O */
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
 
     fcntl(pThis->DeviceFile, F_SETFL, O_NONBLOCK);
 # ifdef RT_OS_DARWIN
@@ -1281,7 +1281,7 @@
     if (RT_FAILURE(rc))
         return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("HostSerial#%d cannot create send thread"), pDrvIns->iInstance);
 
-#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__GLIBC__)
     /* Linux & darwin needs a separate thread which monitors the status lines. */
 # ifndef RT_OS_LINUX
     ioctl(pThis->DeviceFile, TIOCMGET, &pThis->fStatusLines);

=== modified file 'src/VBox/Devices/Storage/DrvHostBase.cpp'
--- src/VBox/Devices/Storage/DrvHostBase.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Devices/Storage/DrvHostBase.cpp	2011-07-05 17:09:02 +0000
@@ -96,7 +96,7 @@
         /*IN*/ ULONG                Length,
         /*IN*/ FS_INFORMATION_CLASS FileSystemInformationClass );
 
-#elif defined(RT_OS_FREEBSD)
+#elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 # include <sys/cdefs.h>
 # include <sys/param.h>
 # include <errno.h>
@@ -146,14 +146,14 @@
     if (    pThis->fMediaPresent
         &&  pThis->ppScsiTaskDI
         &&  pThis->cbBlock)
-#elif RT_OS_FREEBSD
+#elif RT_OS_FREEBSD || defined(__FreeBSD_kernel__)
     if (    pThis->fMediaPresent
         &&  pThis->cbBlock)
 #else
     if (pThis->fMediaPresent)
 #endif
     {
-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
         /*
          * Issue a READ(12) request.
          */
@@ -232,7 +232,7 @@
     {
         if (pThis->fMediaPresent)
         {
-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
             /** @todo write support... */
             rc = VERR_WRITE_PROTECT;
 
@@ -277,7 +277,7 @@
 
     if (pThis->fMediaPresent)
     {
-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
         rc = VINF_SUCCESS;
         /** @todo scsi device buffer flush... */
 #else
@@ -947,7 +947,7 @@
     *pFileDevice = FileDevice;
     return VINF_SUCCESS;
 
-#elif defined(RT_OS_FREEBSD)
+#elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
     int rc = VINF_SUCCESS;
     RTFILE FileDevice;
 
@@ -1134,7 +1134,7 @@
  */
 static int drvHostBaseGetMediaSize(PDRVHOSTBASE pThis, uint64_t *pcb)
 {
-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
     /*
      * Try a READ_CAPACITY command...
      */
@@ -1212,7 +1212,7 @@
 }
 
 
-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 /**
  * Execute a SCSI command.
  *
@@ -1323,7 +1323,7 @@
 
     (*ppScsiTaskI)->Release(ppScsiTaskI);
 
-# elif defined(RT_OS_FREEBSD)
+# elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
     int rc = VINF_SUCCESS;
     int rcBSD = 0;
     union ccb DeviceCCB;

=== modified file 'src/VBox/Devices/Storage/DrvHostBase.h'
--- src/VBox/Devices/Storage/DrvHostBase.h	2011-07-05 17:05:22 +0000
+++ src/VBox/Devices/Storage/DrvHostBase.h	2011-07-05 17:09:02 +0000
@@ -136,7 +136,7 @@
     uint8_t                *pbDoubleBuffer;
 #endif
 
-#ifdef RT_OS_FREEBSD
+#if defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
     /** The block size. Set when querying the media size. */
     uint32_t                cbBlock;
     /** SCSI bus number. */
@@ -185,7 +185,7 @@
 int DRVHostBaseMediaPresent(PDRVHOSTBASE pThis);
 void DRVHostBaseMediaNotPresent(PDRVHOSTBASE pThis);
 DECLCALLBACK(void) DRVHostBaseDestruct(PPDMDRVINS pDrvIns);
-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 DECLCALLBACK(int) DRVHostBaseScsiCmd(PDRVHOSTBASE pThis, const uint8_t *pbCmd, size_t cbCmd, PDMBLOCKTXDIR enmTxDir,
                                      void *pvBuf, uint32_t *pcbBuf, uint8_t *pbSense, size_t cbSense, uint32_t cTimeoutMillies);
 #endif

=== modified file 'src/VBox/Devices/Storage/DrvHostDVD.cpp'
--- src/VBox/Devices/Storage/DrvHostDVD.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Devices/Storage/DrvHostDVD.cpp	2011-07-05 17:09:02 +0000
@@ -89,7 +89,7 @@
 # undef _interlockedbittestandreset64
 # undef USE_MEDIA_POLLING
 
-#elif defined(RT_OS_FREEBSD)
+#elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 # include <sys/cdefs.h>
 # include <sys/param.h>
 # include <stdio.h>
@@ -146,7 +146,7 @@
             /*
              * Eject the disc.
              */
-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
             uint8_t abCmd[16] =
             {
                 SCSI_START_STOP_UNIT, 0, 0, 0, 2 /*eject+stop*/, 0,
@@ -236,7 +236,7 @@
  */
 static DECLCALLBACK(int) drvHostDvdDoLock(PDRVHOSTBASE pThis, bool fLock)
 {
-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
     uint8_t abCmd[16] =
     {
         SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL, 0, 0, 0, fLock, 0,
@@ -324,7 +324,7 @@
     /*
      * Poll for media change.
      */
-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 #ifdef RT_OS_DARWIN
     AssertReturn(pThis->ppScsiTaskDI, VERR_INTERNAL_ERROR);
 #endif
@@ -394,7 +394,7 @@
         /*
          * Poll for media change.
          */
-#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
         /* taken care of above. */
 #elif defined(RT_OS_LINUX)
         bool fMediaChanged = ioctl(pThis->FileDevice, CDROM_MEDIA_CHANGED, CDSL_CURRENT) == 1;
@@ -424,7 +424,7 @@
     int rc;
     LogFlow(("%s: cmd[0]=%#04x txdir=%d pcbBuf=%d timeout=%d\n", __FUNCTION__, pbCmd[0], enmTxDir, *pcbBuf, cTimeoutMillies));
 
-#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
+#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
     /*
      * Pass the request on to the internal scsi command interface.
      * The command seems to be 12 bytes long, the docs a bit copy&pasty on the command length point...

=== modified file 'src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp'
--- src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Devices/USB/freebsd/USBProxyDevice-freebsd.cpp	2011-07-05 17:09:02 +0000
@@ -26,7 +26,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <sys/poll.h>
+#include <bsd/sys/poll.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>

=== modified file 'src/VBox/Frontends/Common/Makefile.kmk'
--- src/VBox/Frontends/Common/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Frontends/Common/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -20,7 +20,7 @@
 
 # Include Sub-Makefiles
 ifneq ($(VBOX_WITH_QTGUI)$(VBOX_WITH_VBOXSDL),)
- ifeq ($(filter-out freebsd linux openbsd netbsd solaris,$(KBUILD_TARGET)),) # X11
+ ifeq ($(filter-out freebsd linux gnukfreebsd openbsd netbsd solaris,$(KBUILD_TARGET)),) # X11
   include $(PATH_SUB_CURRENT)/VBoxKeyboard/Makefile.kmk
  endif
 endif

=== modified file 'src/VBox/Frontends/Common/VBoxKeyboard/Makefile.kmk'
--- src/VBox/Frontends/Common/VBoxKeyboard/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Frontends/Common/VBoxKeyboard/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -18,7 +18,7 @@
 SUB_DEPTH = ../../../../..
 include $(KBUILD_PATH)/subheader.kmk
 
-if1of ($(KBUILD_TARGET), freebsd linux openbsd netbsd solaris) # X11
+if1of ($(KBUILD_TARGET), freebsd linux gnukfreebsd openbsd netbsd solaris) # X11
  DLLS        += VBoxKeyboard
  OTHERS      += $(PATH_BIN)/vboxkeyboard.tar.bz2
  OTHER_CLEAN += $(PATH_BIN)/vboxkeyboard.tar.bz2

=== modified file 'src/VBox/Frontends/VBoxBFE/Makefile.kmk'
--- src/VBox/Frontends/VBoxBFE/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Frontends/VBoxBFE/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -55,10 +55,12 @@
 ifdef VBOX_WITH_LINUX_COMPILER_H
 VBoxBFE_DEFS += VBOX_WITH_LINUX_COMPILER_H
 endif
-VBoxBFE_DEFS.freebsd = VBOXBFE_WITH_X11
-VBoxBFE_DEFS.l4 = _GNU_SOURCE
-VBoxBFE_DEFS.linux = _GNU_SOURCE VBOXBFE_WITH_X11
-VBoxBFE_DEFS.solaris = VBOXBFE_WITH_X11
+if1of ($(KBUILD_TARGET), linux l4 gnukfreebsd)
+VBoxBFE_DEFS += _GNU_SOURCE
+endif
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd linux solaris)
+VBoxBFE_DEFS += VBOXBFE_WITH_X11
+endif
 ifdef VBOX_WITH_CROSSBOW
  VBoxBFE_DEFS.solaris += VBOX_WITH_CROSSBOW
 endif

=== modified file 'src/VBox/Frontends/VBoxSDL/Makefile.kmk'
--- src/VBox/Frontends/VBoxSDL/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Frontends/VBoxSDL/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -59,9 +59,12 @@
   VBoxSDL_DEFS    += VBOX_SECURELABEL
  endif
 endif
-VBoxSDL_DEFS.freebsd = VBOXSDL_WITH_X11
-VBoxSDL_DEFS.linux = _GNU_SOURCE VBOXSDL_WITH_X11
-VBoxSDL_DEFS.solaris = VBOXSDL_WITH_X11
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBoxSDL_DEFS      += _GNU_SOURCE
+endif
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd linux solaris)
+VBoxSDL_DEFS      += VBOXSDL_WITH_X11
+endif
 ifdef VBOX_OPENGL
  #VBoxSDL_DEFS.linux += VBOX_OPENGL
 endif
@@ -70,7 +73,7 @@
 
 VBoxSDL_INCS = \
 	$(VBoxSDL_0_OUTDIR)
-ifeq ($(filter-out freebsd linux netbsd openbsd solaris,$(KBUILD_TARGET)),) # X11
+ifeq ($(filter-out freebsd linux gnukfreebsd netbsd openbsd solaris,$(KBUILD_TARGET)),) # X11
 VBoxSDL_INCS += \
 	$(VBOX_XCURSOR_INCS)
 endif
@@ -79,7 +82,7 @@
 VBoxSDL_LIBS = \
 	$(LIB_SDK_LIBSDL_SDLMAIN)
 endif
-ifeq ($(filter-out freebsd linux netbsd openbsd solaris,$(KBUILD_TARGET)),) # X11
+ifeq ($(filter-out freebsd linux gnukfreebsd netbsd openbsd solaris,$(KBUILD_TARGET)),) # X11
 VBoxSDL_LIBS += \
 	$(PATH_DLL)/VBoxKeyboard$(VBOX_SUFF_DLL) \
 	$(VBOX_XCURSOR_LIBS) \
@@ -136,7 +139,7 @@
 ifdef VBOX_OPENGL
 tstSDL_LIBS.linux += GL
 endif
-ifeq ($(filter-out freebsd linux netbsd openbsd solaris,$(KBUILD_TARGET)),) # X11
+ifeq ($(filter-out freebsd linux gnukfreebsd netbsd openbsd solaris,$(KBUILD_TARGET)),) # X11
 tstSDL_LIBPATH = \
 	$(VBOX_LIBPATH_X11)
 endif

=== modified file 'src/VBox/Frontends/VirtualBox/Makefile.kmk'
--- src/VBox/Frontends/VirtualBox/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Frontends/VirtualBox/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -90,7 +90,7 @@
  VirtualBox_INST.darwin = $(INST_BIN)VirtualBox $(INST_BIN)VirtualBoxVM
 endif
 VirtualBox_SDKS.win = WINPSDK DXSDK
-if1of ($(KBUILD_TARGET), freebsd linux netbsd openbsd os2) # X11 + os2 ## @todo solaris
+if1of ($(KBUILD_TARGET), freebsd linux gnukfreebsd netbsd openbsd os2) # X11 + os2 ## @todo solaris
  VirtualBox_SDKS += LIBSDL
 endif
 
@@ -107,6 +107,7 @@
 endif
 VirtualBox_DEFS.freebsd   = VBOX_GUI_USE_QIMAGE VBOX_GUI_USE_SDL
 VirtualBox_DEFS.linux     = VBOX_GUI_USE_QIMAGE VBOX_GUI_USE_SDL
+VirtualBox_DEFS.gnukfreebsd = VBOX_GUI_USE_QIMAGE VBOX_GUI_USE_SDL
 VirtualBox_DEFS.netbsd    = VBOX_GUI_USE_QIMAGE VBOX_GUI_USE_SDL
 VirtualBox_DEFS.openbsd   = VBOX_GUI_USE_QIMAGE VBOX_GUI_USE_SDL
 VirtualBox_DEFS.solaris   = VBOX_GUI_USE_QIMAGE #VBOX_GUI_USE_SDL
@@ -202,9 +203,9 @@
 VirtualBox_LIBS = $(LIB_DDU)
 
 # This library is required for multi-monitor support
-VirtualBox_LIBS.linux += Xinerama
-VirtualBox_LIBS.solaris += Xinerama
-VirtualBox_LIBS.freebsd += Xinerama
+if1of ($(KBUILD_TARGET), linux solaris freebsd gnukfreebsd)
+VirtualBox_LIBS += Xinerama
+endif
 
 ifneq ($(KBUILD_TARGET),win)
 VirtualBox_CXXFLAGS += -Wno-switch
@@ -217,7 +218,9 @@
 ifeq ($(KBUILD_TYPE),release)
  VirtualBox_LDFLAGS.win  += /SUBSYSTEM:windows
 else
- VirtualBox_LDFLAGS.linux+= -rdynamic # for backtrace_symbols()
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+ VirtualBox_LDFLAGS      += -rdynamic # for backtrace_symbols()
+endif
  ifeq ($(USERNAME),dmik)
   VirtualBox_LDFLAGS.win += /SUBSYSTEM:windows
  else
@@ -243,7 +246,7 @@
 	$(PATH_SDK_WINPSDK_LIB)/Htmlhelp.Lib \
 	$(PATH_SDK_DXSDK_LIB)/ddraw.lib \
 	$(PATH_SDK_DXSDK_LIB)/dxguid.lib
-if1of ($(KBUILD_TARGET), freebsd linux netbsd openbsd solaris) # X11
+if1of ($(KBUILD_TARGET), freebsd linux gnukfreebsd netbsd openbsd solaris) # X11
  VirtualBox_LIBS         += $(PATH_DLL)/VBoxKeyboard$(VBOX_SUFF_DLL)
 endif
 
@@ -252,6 +255,7 @@
  VirtualBox_LIBS.solaris += GL
  VirtualBox_LIBS.linux   += GL
  VirtualBox_LIBS.freebsd += GL
+ VirtualBox_LIBS.gnukfreebsd += GL
 endif
 
 # Headers containing definitions of classes that use the Q_OBJECT macro.
@@ -559,7 +563,7 @@
 	src/platform/darwin/UIWindowMenuManager.cpp \
 	src/platform/darwin/UICocoaDockIconPreview.mm
 
-if1of ($(KBUILD_TARGET), freebsd linux netbsd openbsd solaris) # X11
+if1of ($(KBUILD_TARGET), freebsd linux gnukfreebsd netbsd openbsd solaris) # X11
  VirtualBox_SOURCES += \
  	src/platform/x11/XKeyboard-new.cpp \
  	src/platform/x11/VBoxX11Helper.cpp \
@@ -929,7 +933,7 @@
 # App for testing GL support
 #
 if defined(VBOX_WITH_VIDEOHWACCEL)
- if1of ($(KBUILD_TARGET), win linux freebsd)
+ if1of ($(KBUILD_TARGET), win linux freebsd gnukfreebsd)
   LIBRARIES += VBoxOGL2D
   VBoxOGL2D_TEMPLATE = VBOXR3STATIC
   VBoxOGL2D_USES = qt4

=== modified file 'src/VBox/GuestHost/OpenGL/Makefile.kmk'
--- src/VBox/GuestHost/OpenGL/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/GuestHost/OpenGL/Makefile.kmk	2011-07-05 17:09:02 +0000
@@ -45,7 +45,7 @@
 endif
 VBoxOGLcrutil_SDKS.win      = DXSDK
 VBoxOGLcrutil_INTERMEDIATES = $(VBOX_PATH_CROGL_GENFILES)/cr_opcodes.h
-if1of ($(KBUILD_TARGET), linux solaris freebsd)
+if1of ($(KBUILD_TARGET), linux solaris freebsd gnukfreebsd)
  VBoxOGLcrutil_INCS += \
 	$(VBOX_MESA_INCS)
 endif
@@ -155,7 +155,7 @@
 VBoxOGLcrpacker_TEMPLATE = VBOXCROGLR3GUESTLIB
 VBoxOGLcrpacker_INCS = \
 	packer
-if1of ($(KBUILD_TARGET), linux solaris freebsd)
+if1of ($(KBUILD_TARGET), linux solaris freebsd gnukfreebsd)
  VBoxOGLcrpacker_INCS += \
 	$(VBOX_MESA_INCS)
 endif
@@ -300,7 +300,7 @@
 VBoxOGLspuload_TEMPLATE = VBOXCROGLR3GUESTLIB
 VBoxOGLspuload_INTERMEDIATES = \
 	$(VBOX_PATH_CROGL_GENFILES)/spu_dispatch_table.h
-if1of ($(KBUILD_TARGET), linux solaris freebsd)
+if1of ($(KBUILD_TARGET), linux solaris freebsd gnukfreebsd)
  VBoxOGLspuload_INCS += \
 	$(VBOX_MESA_INCS)
 endif
@@ -368,7 +368,7 @@
 VBoxOGLcrstate_TEMPLATE = VBOXCROGLR3GUESTLIB
 VBoxOGLcrstate_INCS = \
 	state_tracker
-if1of ($(KBUILD_TARGET), linux solaris freebsd)
+if1of ($(KBUILD_TARGET), linux solaris freebsd gnukfreebsd)
  VBoxOGLcrstate_INCS += \
 	$(VBOX_MESA_INCS)
 endif
@@ -555,7 +555,7 @@
 endif
 VBoxOGLerrorspu_INTERMEDIATES = \
 	$(VBOX_PATH_CROGL_GENFILES)/spu_dispatch_table.h
-if1of ($(KBUILD_TARGET), linux solaris freebsd)
+if1of ($(KBUILD_TARGET), linux solaris freebsd gnukfreebsd)
  VBoxOGLerrorspu_INCS += \
 	$(VBOX_MESA_INCS)
 endif

=== modified file 'src/VBox/GuestHost/OpenGL/include/cr_dll.h'
--- src/VBox/GuestHost/OpenGL/include/cr_dll.h	2011-07-05 17:05:22 +0000
+++ src/VBox/GuestHost/OpenGL/include/cr_dll.h	2011-07-05 17:09:02 +0000
@@ -22,7 +22,7 @@
 	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(__GLIBC__) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
 	void *hinstLib;
 #elif defined(DARWIN)
 	void *hinstLib;		/* void to avoid including the headers */

=== modified file 'src/VBox/GuestHost/OpenGL/include/cr_timer.h'
--- src/VBox/GuestHost/OpenGL/include/cr_timer.h	2011-07-05 17:05:22 +0000
+++ src/VBox/GuestHost/OpenGL/include/cr_timer.h	2011-07-05 17:09:03 +0000
@@ -35,7 +35,7 @@
 #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(__GLIBC__) || defined( FreeBSD ) || defined(DARWIN) || defined(AIX) || defined (SunOS) || defined(OSF1)
 	struct timeval timeofday;
 #endif
 } CRTimer;

=== modified file 'src/VBox/GuestHost/OpenGL/spu_loader/glloader.py'
--- src/VBox/GuestHost/OpenGL/spu_loader/glloader.py	2011-07-05 17:05:22 +0000
+++ src/VBox/GuestHost/OpenGL/spu_loader/glloader.py	2011-07-05 17:09:03 +0000
@@ -34,7 +34,7 @@
 #  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(__GLIBC__) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
 #include <string.h>
 #if defined(AIX)
 #define SYSTEM_GL "libGL.o"
@@ -143,7 +143,7 @@
 		 * version if it exists; otherwise, we'll use /usr/lib.
 		 */
 		/*crStrcpy(system_path, "/usr/lib");*/
-#if defined(__linux__) && defined(__amd64__)
+#if (defined(__linux__) || defined(__GLIBC_)) && defined(__amd64__)
 		/*if (sizeof(void *) == 8 && FileExists("/usr/lib64", lib)) {
 			crStrcat(system_path, "64");
 		}*/
@@ -154,7 +154,7 @@
 		}*/
 #endif
 	}
-#if !defined(__linux__) && !defined(SunOS) && !defined(__FreeBSD__)
+#if !defined(__linux__) && !defined(__GLIBC__) && !defined(SunOS) && !defined(__FreeBSD__)
 	crStrcat( system_path, "/" );
 #endif
 #if !defined(CR_NO_GL_SYSTEM_PATH)

=== modified file 'src/VBox/GuestHost/OpenGL/util/dll.c'
--- src/VBox/GuestHost/OpenGL/util/dll.c	2011-07-05 17:05:22 +0000
+++ src/VBox/GuestHost/OpenGL/util/dll.c	2011-07-05 17:09:03 +0000
@@ -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(__GLIBC__) || defined(FreeBSD) || defined(AIX) || defined(DARWIN) || defined(SunOS) || defined(OSF1)
 #include <dlfcn.h>
 #endif
 
@@ -203,7 +203,7 @@
 		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(__GLIBC__) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
 	if (resolveGlobal)
 		dll->hinstLib = dlopen( dllname, RTLD_LAZY | RTLD_GLOBAL );
 	else
@@ -256,7 +256,7 @@
 
 	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(__GLIBC__) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
 	return (CRDLLFunc) dlsym( dll->hinstLib, symname );
 #else
 #error CR DLL ARCHITETECTURE
@@ -300,7 +300,7 @@
 		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(__GLIBC__) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
 	/*
 	 * Unloading Nvidia's libGL will crash VirtualBox later during shutdown.
 	 * Therefore we will skip unloading it. It will be unloaded later anway

=== modified file 'src/VBox/GuestHost/OpenGL/util/timer.c'
--- src/VBox/GuestHost/OpenGL/util/timer.c	2011-07-05 17:05:22 +0000
+++ src/VBox/GuestHost/OpenGL/util/timer.c	2011-07-05 17:09:03 +0000
@@ -35,7 +35,7 @@
 #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(__GLIBC__) || defined( FreeBSD ) || defined(DARWIN) || defined(AIX) || defined(SunOS) || defined(OSF1)
 	gettimeofday( &t->timeofday, NULL );	
 	return t->timeofday.tv_sec + t->timeofday.tv_usec / 1000000.0;
 #else

=== modified file 'src/VBox/HostDrivers/Makefile.kmk'
--- src/VBox/HostDrivers/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/HostDrivers/Makefile.kmk	2011-07-05 17:09:03 +0000
@@ -27,12 +27,12 @@
  ifdef VBOX_WITH_USB
   include $(PATH_SUB_CURRENT)/VBoxUSB/Makefile.kmk
  endif
- if1of ($(KBUILD_TARGET), darwin solaris win linux freebsd)
+ if1of ($(KBUILD_TARGET), darwin solaris win linux freebsd gnukfreebsd)
   ifdef VBOX_WITH_NETFLT
    include $(PATH_SUB_CURRENT)/VBoxNetFlt/Makefile.kmk
   endif
  endif
- if1of ($(KBUILD_TARGET), darwin solaris linux freebsd)
+ if1of ($(KBUILD_TARGET), darwin solaris linux freebsd gnukfreebsd)
   ifdef VBOX_WITH_NETADP
    include $(PATH_SUB_CURRENT)/VBoxNetAdp/Makefile.kmk
   endif
@@ -41,7 +41,7 @@
   include $(PATH_SUB_CURRENT)/darwin/Makefile.kmk
  endif
 
- if1of ($(KBUILD_TARGET),linux freebsd)
+ if1of ($(KBUILD_TARGET),linux freebsd gnukfreebsd)
   #
   # Install the Makefile for module compilation on Linux and FreeBSD hosts
   #
@@ -50,9 +50,10 @@
   HostDrivers-src_MODE            = a+r,u+w
   HostDrivers-src_SOURCES.linux   = linux/Makefile
   HostDrivers-src_SOURCES.freebsd = freebsd/Makefile
+  HostDrivers-src_SOURCES.gnukfreebsd = freebsd/Makefile
  endif
 
- if1of ($(KBUILD_TARGET),linux)
+ if1of ($(KBUILD_TARGET),linux gnukfreebsd)
   INSTALLS += HostDrivers-dkms-sh
   HostDrivers-dkms-sh_INST    = bin/src/
   HostDrivers-dkms-sh_MODE    = a+rx,u+w

=== modified file 'src/VBox/HostDrivers/Support/Makefile.kmk'
--- src/VBox/HostDrivers/Support/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/HostDrivers/Support/Makefile.kmk	2011-07-05 17:09:03 +0000
@@ -45,12 +45,14 @@
  ifdef VBOX_WITH_VBOXDRV
   LIBRARIES       += SUPR0IdcClient
   SYSMODS.freebsd += vboxdrv
+  SYSMODS.gnukfreebsd += vboxdrv
   SYSMODS.linux   += vboxdrv
   SYSMODS.win     += VBoxDrv
   SYSMODS.os2     += VBoxDrv
   SYSMODS.solaris += vboxdrv
  endif
  INSTALLS.linux   += vboxdrv-mod vboxdrv-sh vboxdrv-dkms
+ INSTALLS.gnukfreebsd += vboxdrv-mod vboxdrv-sh vboxdrv-dkms
  INSTALLS.freebsd += vboxdrv-mod vboxdrv-sh
 
  #
@@ -64,7 +66,7 @@
  ifeq ($(KBUILD_TARGET),linux)
   include $(PATH_SUB_CURRENT)/linux/files_vboxdrv
  endif
- ifeq ($(KBUILD_TARGET),freebsd)
+ if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
   include $(PATH_SUB_CURRENT)/freebsd/files_vboxdrv
  endif
 endif # !VBOX_ONLY_DOCS && !VBOX_ONLY_EXTPACKS && !VBOX_ONLY_TESTSUITE
@@ -89,8 +91,14 @@
 	SUPLib.cpp \
 	SUPLibSem.cpp \
 	SUPR3HardenedIPRT.cpp \
-	SUPR3HardenedVerify.cpp \
+	SUPR3HardenedVerify.cpp
+ifeq ($(KBUILD_TARGET),gnukfreebsd)
+SUPR3_SOURCES      += \
+	freebsd/SUPLib-freebsd.cpp
+else
+SUPR3_SOURCES      += \
 	$(KBUILD_TARGET)/SUPLib-$(KBUILD_TARGET).cpp
+endif
 
 #
 # Static version of SUPR3.
@@ -109,8 +117,14 @@
 SUPR3HardenedStatic_INCS     = .
 SUPR3HardenedStatic_SOURCES  = \
 	SUPR3HardenedMain.cpp \
-	SUPR3HardenedVerify.cpp \
+	SUPR3HardenedVerify.cpp
+ifeq ($(KBUILD_TARGET),gnukfreebsd)
+SUPR3HardenedStatic_SOURCES += \
+	freebsd/SUPLib-freebsd.cpp
+else
+SUPR3HardenedStatic_SOURCES += \
 	$(KBUILD_TARGET)/SUPLib-$(KBUILD_TARGET).cpp
+endif
 
 #
 # VBoxSupSvc - The system wide service/daemon.
@@ -119,7 +133,15 @@
 VBoxSupSvc_SOURCES = \
 	SUPSvc.cpp \
 	SUPSvcGlobal.cpp \
+	
+ifeq ($(KBUILD_TARGET),gnukfreebsd)
+VBoxSupSvc_SOURCES += \
+	freebsd/SUPSvc-freebsd.cpp
+else
+VBoxSupSvc_SOURCES += \
 	$(KBUILD_TARGET)/SUPSvc-$(KBUILD_TARGET).cpp
+endif
+
 if1of ($(KBUILD_TARGET), win)
  VBoxSupSvc_SOURCES += \
 	SUPSvcGrant.cpp
@@ -158,8 +180,13 @@
 SUPR0IdcClient_TEMPLATE = VBOXR0DRV
 SUPR0IdcClient_DEFS = IN_RT_R0 IN_SUP_R0 IN_SUP_STATIC
 SUPR0IdcClient_SDKS.win = W2K3DDK WINPSDKINCS
+ifeq ($(KBUILD_TARGET),gnukfreebsd)
+SUPR0IdcClient_SOURCES.$(KBUILD_TARGET) = \
+	freebsd/SUPR0IdcClient-freebsd.c
+else
 SUPR0IdcClient_SOURCES.$(KBUILD_TARGET) = \
 	$(KBUILD_TARGET)/SUPR0IdcClient-$(KBUILD_TARGET).c
+endif
 SUPR0IdcClient_SOURCES = \
 	SUPR0IdcClient.c \
 	SUPR0IdcClientComponent.c \
@@ -396,7 +423,7 @@
 	SUPDrvSem.c
 
 endif # os2
-ifeq ($(KBUILD_TARGET),freebsd)
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
 
 #
 # vboxdrv.ko - The FreeBSD Kernel Module.
@@ -406,8 +433,8 @@
 vboxdrv_INCS         := $(PATH_SUB_CURRENT)
 vboxdrv_LIBS          = $(PATH_LIB)/RuntimeR0Drv$(VBOX_SUFF_LIB)
 vboxdrv_SOURCES      := \
-	$(KBUILD_TARGET)/SUPDrv-$(KBUILD_TARGET).c \
-	$(PATH_SUB_CURRENT)/$(KBUILD_TARGET)/SUPDrv-$(KBUILD_TARGET).def \
+	freebsd/SUPDrv-freebsd.c \
+	$(PATH_SUB_CURRENT)/freebsd/SUPDrv-freebsd.def \
 	SUPDrv.c \
 	SUPDrvSem.c
 ## @todo the SUPDrv-freebsd.def is most probably gonna break it and require build system hacking...

=== modified file 'src/VBox/HostDrivers/Support/SUPDrvIDC.h'
--- src/VBox/HostDrivers/Support/SUPDrvIDC.h	2011-07-05 17:05:22 +0000
+++ src/VBox/HostDrivers/Support/SUPDrvIDC.h	2011-07-05 17:09:03 +0000
@@ -226,7 +226,7 @@
 #if defined(RT_OS_DARWIN)
 extern int VBOXCALL SUPDrvDarwinIDC(uint32_t iReq, PSUPDRVIDCREQHDR pReq);
 
-#elif defined(RT_OS_FREEBSD)
+#elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 extern int VBOXCALL SUPDrvFreeBSDIDC(uint32_t iReq, PSUPDRVIDCREQHDR pReq);
 
 #elif defined(RT_OS_LINUX)

=== modified file 'src/VBox/HostDrivers/Support/SUPDrvInternal.h'
--- src/VBox/HostDrivers/Support/SUPDrvInternal.h	2011-07-05 17:05:22 +0000
+++ src/VBox/HostDrivers/Support/SUPDrvInternal.h	2011-07-05 17:09:03 +0000
@@ -115,7 +115,7 @@
 
 #elif defined(RT_OS_OS2)
 
-#elif defined(RT_OS_FREEBSD)
+#elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 #   define memset  libkern_memset /** @todo these are just hacks to get it compiling, check out later. */
 #   define memcmp  libkern_memcmp
 #   define strchr  libkern_strchr

=== modified file 'src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp'
--- src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp	2011-07-05 17:09:03 +0000
@@ -62,7 +62,7 @@
 #  ifndef CAP_TO_MASK
 #   define CAP_TO_MASK(cap) RT_BIT(cap)
 #  endif
-# elif defined(RT_OS_FREEBSD)
+# elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 #  include <sys/param.h>
 #  include <sys/sysctl.h>
 # elif defined(RT_OS_SOLARIS)
@@ -317,7 +317,7 @@
      *
      * Darwin, OS/2 and Windows all have proper APIs for getting the program file name.
      */
-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__) || defined(RT_OS_SOLARIS)
 # ifdef RT_OS_LINUX
     int cchLink = readlink("/proc/self/exe", &g_szSupLibHardenedExePath[0], sizeof(g_szSupLibHardenedExePath) - 1);
 

=== modified file 'src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c'
--- src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c	2011-07-05 17:05:22 +0000
+++ src/VBox/HostDrivers/Support/freebsd/SUPDrv-freebsd.c	2011-07-05 17:09:03 +0000
@@ -100,6 +100,9 @@
 static struct cdevsw        g_VBoxDrvFreeBSDChrDevSW =
 {
     .d_version =        D_VERSION,
+#ifndef __FreeBSD_version
+#error
+#endif
 #if __FreeBSD_version > 800061
     .d_flags =          D_PSEUDO | D_TRACKCLOSE | D_NEEDMINOR,
 #else
@@ -284,10 +287,10 @@
  * @param   pDev    The device node.
  * @param   fOpen   The open flags.
  * @param   pTd     The thread.
- * @param   pFd     The file descriptor. FreeBSD 7.0 and later.
- * @param   iFd     The file descriptor index(?). Pre FreeBSD 7.0.
+ * @param   pFd     The file descriptor. Introduced in FreeBSD 7.0-CURRENT.
+ * @param   iFd     The file descriptor index. Pre FreeBSD 7.0.
  */
-#if __FreeBSD__ >= 7
+#if __FreeBSD_version >= 700044
 static int VBoxDrvFreeBSDOpen(struct cdev *pDev, int fOpen, struct thread *pTd, struct file *pFd)
 #else
 static int VBoxDrvFreeBSDOpen(struct cdev *pDev, int fOpen, struct thread *pTd, int iFd)

=== modified file 'src/VBox/HostServices/auth/Makefile.kmk'
--- src/VBox/HostServices/auth/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/HostServices/auth/Makefile.kmk	2011-07-05 17:09:03 +0000
@@ -20,17 +20,21 @@
 
 # The plugin.
 ifndef VBOX_ONLY_SDK
- if ("$(KBUILD_TARGET)" != "linux" && "$(KBUILD_TARGET)" != "solaris") || defined(VBOX_WITH_PAM)
+ if ("$(KBUILD_TARGET)" != "linux" && "$(KBUILD_TARGET)" != "solaris" && "$(KBUILD_TARGET)" != "gnukfreebsd") || defined(VBOX_WITH_PAM)
   DLLS += VBoxAuth
  endif
 endif
 VBoxAuth_TEMPLATE = VBOXR3
-VBoxAuth_SOURCES.linux = pam/VBoxAuthPAM.c
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBoxAuth_SOURCES += pam/VBoxAuthPAM.c
+endif
 VBoxAuth_SOURCES.solaris = pam/VBoxAuthPAM.c
 VBoxAuth_SOURCES.freebsd = pam/VBoxAuthPAM.c
 VBoxAuth_SOURCES.win = winlogon/winlogon.cpp
 VBoxAuth_SOURCES.darwin = directoryservice/directoryservice.cpp
-VBoxAuth_LIBS.linux = $(LIB_RUNTIME) dl
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBoxAuth_LIBS += $(LIB_RUNTIME) dl
+endif
 VBoxAuth_LIBS.solaris = $(LIB_RUNTIME) dl
 VBoxAuth_LIBS.freebsd = $(LIB_RUNTIME)
 VBoxAuth_LIBS.darwin = $(LIB_RUNTIME)
@@ -50,7 +54,9 @@
 VBoxAuth-samples_INST = $(INST_SDK)/bindings/auth/
 VBoxAuth-samples_MODE = a+r,u+w
 VBoxAuth-samples_SOURCES = simple/VBoxAuthSimple.cpp
-VBoxAuth-samples_SOURCES.linux = pam/VBoxAuthPAM.c
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBoxAuth-samples_SOURCES += pam/VBoxAuthPAM.c
+endif
 VBoxAuth-samples_SOURCES.win = winlogon/winlogon.cpp
 
 # Install the SDK header.

=== modified file 'src/VBox/Installer/Makefile.kmk'
--- src/VBox/Installer/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Installer/Makefile.kmk	2011-07-05 17:09:03 +0000
@@ -28,6 +28,9 @@
  if "$(KBUILD_TARGET)" == "linux" && "$(KBUILD_HOST)" == "linux"
   include $(PATH_SUB_CURRENT)/linux/Makefile.kmk
  endif
+ if "$(KBUILD_TARGET)" == "gnukfreebsd" && "$(KBUILD_HOST)" == "gnukfreebsd"
+  include $(PATH_SUB_CURRENT)/linux/Makefile.kmk
+ endif
  if "$(KBUILD_TARGET)" == "solaris" && "$(KBUILD_HOST)" == "solaris"
   include $(PATH_SUB_CURRENT)/solaris/Makefile.kmk
  endif

=== modified file 'src/VBox/Installer/linux/Makefile.kmk'
--- src/VBox/Installer/linux/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Installer/linux/Makefile.kmk	2011-07-05 17:09:03 +0000
@@ -18,7 +18,7 @@
 SUB_DEPTH = ../../../..
 include $(KBUILD_PATH)/subheader.kmk
 
-ifneq ($(KBUILD_HOST),linux)
+ifn1of ($(KBUILD_HOST), linux gnukfreebsd)
  $(error "The Linux installer can only be built on Linux!")
 endif
 

=== modified file 'src/VBox/Main/Makefile.kmk'
--- src/VBox/Main/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/Makefile.kmk	2011-07-05 17:09:03 +0000
@@ -241,6 +241,7 @@
 # VBoxSVC_DEFS.linux += VBOX_USE_LIBHAL
 VBoxSVC_DEFS.solaris += VBOX_USE_LIBHAL
 VBoxSVC_DEFS.freebsd += VBOX_USE_LIBHAL
+VBoxSVC_DEFS.gnukfreebsd += VBOX_USE_LIBHAL
 
 VBoxSVC_CXXFLAGS = $(filter-out -Wno-unused,$(TEMPLATE_VBOXMAINEXE_CXXFLAGS))
 
@@ -259,6 +260,8 @@
 VBoxSVC_LIBS += \
 	$(PATH_LIB)/SSMStandalone$(VBOX_SUFF_LIB) \
 	$(LIB_DDU)
+VBoxSVC_LIBS.gnukfreebsd = \
+	bsd
 VBoxSVC_SDKS = VBOX_LIBPNG VBOX_ZLIB
 VBoxSVC_LIBS.solaris = \
 	adm \
@@ -348,8 +351,10 @@
 	src-server/linux/vbox-libhal.cpp \
 	src-server/solaris/DynLoadLibSolaris.cpp
 
-VBoxSVC_SOURCES.freebsd = \
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+VBoxSVC_SOURCES += \
 	src-server/freebsd/HostHardwareFreeBSD.cpp
+endif
 
 ifdef VBOX_WITH_USB
  ifdef VBOX_WITH_SYSFS_BY_DEFAULT
@@ -365,7 +370,9 @@
  VBoxSVC_SOURCES.os2     +=     src-server/os2/USBProxyServiceOs2.cpp
  VBoxSVC_SOURCES.solaris += src-server/solaris/USBProxyServiceSolaris.cpp
  VBoxSVC_SOURCES.win     +=     src-server/win/USBProxyServiceWindows.cpp
- VBoxSVC_SOURCES.freebsd += src-server/freebsd/USBProxyServiceFreeBSD.cpp
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+ VBoxSVC_SOURCES         += src-server/freebsd/USBProxyServiceFreeBSD.cpp
+endif
 endif
 
 ifdef VBOX_WITH_NETFLT
@@ -398,7 +405,9 @@
 	src-server/PerformanceImpl.cpp \
 	src-server/Performance.cpp
  VBoxSVC_SOURCES.darwin  +=  src-server/darwin/PerformanceDarwin.cpp
- VBoxSVC_SOURCES.freebsd += src-server/freebsd/PerformanceFreeBSD.cpp
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+ VBoxSVC_SOURCES         += src-server/freebsd/PerformanceFreeBSD.cpp
+endif
  VBoxSVC_SOURCES.linux   +=   src-server/linux/PerformanceLinux.cpp
  VBoxSVC_SOURCES.os2     +=     src-server/os2/PerformanceOs2.cpp
  VBoxSVC_SOURCES.solaris += src-server/solaris/PerformanceSolaris.cpp
@@ -414,9 +423,11 @@
  VBoxSVC_SOURCES.os2     +=     src-server/os2/NetIf-os2.cpp
  VBoxSVC_SOURCES.darwin  +=  src-server/darwin/NetIf-darwin.cpp
  VBoxSVC_SOURCES.solaris += src-server/solaris/NetIf-solaris.cpp
- VBoxSVC_SOURCES.freebsd += src-server/freebsd/NetIf-freebsd.cpp
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+ VBoxSVC_SOURCES         += src-server/freebsd/NetIf-freebsd.cpp
+endif
  VBoxSVC_DEFS            += VBOX_WITH_HOSTNETIF_API
- if1of ($(KBUILD_TARGET), linux darwin solaris freebsd)
+ if1of ($(KBUILD_TARGET), linux darwin solaris gnukfreebsd)
   VBoxSVC_SOURCES        += src-server/generic/NetIf-generic.cpp
  endif
 endif
@@ -439,6 +450,7 @@
 VBOX_XML_SCHEMA.darwin        = $(VBOX_PATH_MAIN_SRC)/xml/VirtualBox-settings-macosx.xsd
 VBOX_XML_SCHEMA.linux         = $(VBOX_PATH_MAIN_SRC)/xml/VirtualBox-settings-linux.xsd
 VBOX_XML_SCHEMA.freebsd       = $(VBOX_PATH_MAIN_SRC)/xml/VirtualBox-settings-freebsd.xsd
+VBOX_XML_SCHEMA.gnukfreebsd   = $(VBOX_PATH_MAIN_SRC)/xml/VirtualBox-settings-freebsd.xsd
 VBOX_XML_SCHEMA.win           = $(VBOX_PATH_MAIN_SRC)/xml/VirtualBox-settings-windows.xsd
 VBOX_XML_SCHEMA.os2           = $(VBOX_PATH_MAIN_SRC)/xml/VirtualBox-settings-os2.xsd
 VBOX_XML_SCHEMA.solaris       = $(VBOX_PATH_MAIN_SRC)/xml/VirtualBox-settings-solaris.xsd
@@ -511,7 +523,7 @@
    VBoxTestOGL_QT_MODULES += Core Gui OpenGL
    VBoxTestOGL_LDFLAGS.darwin += -framework OpenGL
    VBoxTestOGL_LIBS.win += $(PATH_SDK_WINPSDK_LIB)/Opengl32.lib
-   if1of ($(KBUILD_TARGET), solaris linux freebsd)
+   if1of ($(KBUILD_TARGET), solaris linux freebsd gnukfreebsd)
     # must come after VBoxOGL2D, therefore don't set the arch-specific LIBS variable here!
     VBoxTestOGL_LIBS += GL
    endif

=== modified file 'src/VBox/Main/cbinding/VBoxXPCOMCGlue.c'
--- src/VBox/Main/cbinding/VBoxXPCOMCGlue.c	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/cbinding/VBoxXPCOMCGlue.c	2011-07-05 17:09:03 +0000
@@ -44,7 +44,7 @@
 /*******************************************************************************
 *   Defined Constants And Macros                                               *
 *******************************************************************************/
-#if defined(__linux__) || defined(__linux_gnu__) || defined(__sun__) || defined(__FreeBSD__)
+#if defined(__linux__) || defined(__linux_gnu__) || defined(__GLIBC__) || defined(__sun__) || defined(__FreeBSD__)
 # define DYNLIB_NAME    "VBoxXPCOMC.so"
 #elif defined(__APPLE__)
 # define DYNLIB_NAME    "VBoxXPCOMC.dylib"
@@ -189,7 +189,7 @@
      * Try the known standard locations.
      */
     g_szVBoxErrMsg[0] = '\0';
-#if defined(__gnu__linux__) || defined(__linux__)
+#if defined(__gnu__linux__) || defined(__linux__) || defined(__GLIBC__)
     if (tryLoadOne("/opt/VirtualBox", 1) == 0)
         return 0;
     if (tryLoadOne("/usr/lib/virtualbox", 1) == 0)

=== modified file 'src/VBox/Main/include/ConsoleImpl.h'
--- src/VBox/Main/include/ConsoleImpl.h	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/include/ConsoleImpl.h	2011-07-05 17:09:03 +0000
@@ -447,7 +447,7 @@
     HRESULT powerDown(IProgress *aProgress = NULL);
 
 /* Note: FreeBSD needs this whether netflt is used or not. */
-#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
+#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__))
     HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
     HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
 #endif
@@ -707,7 +707,7 @@
     PPDMLED      mapSharedFolderLed;
     PPDMLED      mapUSBLed[2];
 /* Note: FreeBSD needs this whether netflt is used or not. */
-#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
+#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__))
     Utf8Str      maTAPDeviceName[8];
     RTFILE       maTapFD[8];
 #endif

=== modified file 'src/VBox/Main/include/HostUSBDeviceImpl.h'
--- src/VBox/Main/include/HostUSBDeviceImpl.h	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/include/HostUSBDeviceImpl.h	2011-07-05 17:09:03 +0000
@@ -329,7 +329,7 @@
 
     friend class USBProxyServiceDarwin;
 #endif
-#ifdef RT_OS_FreeBSD
+#if defined(RT_OS_FreeBSD) || defined(__FreeBSD_kernel__)
     friend class USBProxyServiceFreeBSD;
 #endif
 };

=== modified file 'src/VBox/Main/include/USBProxyService.h'
--- src/VBox/Main/include/USBProxyService.h	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/include/USBProxyService.h	2011-07-05 17:09:03 +0000
@@ -396,7 +396,7 @@
 };
 # endif /* RT_OS_WINDOWS */
 
-# ifdef RT_OS_FREEBSD
+# if defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 /**
  * The FreeBSD hosted USB Proxy Service.
  */

=== modified file 'src/VBox/Main/src-client/ConsoleImpl.cpp'
--- src/VBox/Main/src-client/ConsoleImpl.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/src-client/ConsoleImpl.cpp	2011-07-05 17:09:03 +0000
@@ -29,7 +29,7 @@
 #   include <stdio.h>
 #   include <stdlib.h>
 #   include <string.h>
-#elif defined(RT_OS_FREEBSD)
+#elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 #   include <errno.h>
 #   include <sys/ioctl.h>
 #   include <sys/poll.h>
@@ -7103,7 +7103,7 @@
 #endif /* VBOX_WITH_USB */
 
 /* Note: FreeBSD needs this whether netflt is used or not. */
-#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
+#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__))
 /**
  * Helper function to handle host interface device creation and attachment.
  *
@@ -7220,7 +7220,7 @@
         }
     }
 
-# elif defined(RT_OS_FREEBSD)
+# elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
     /*
      * Set/obtain the tap interface.
      */
@@ -7338,7 +7338,7 @@
     LogFlowThisFunc(("returning %d\n", rc));
     return rc;
 }
-#endif /* (RT_OS_LINUX || RT_OS_FREEBSD) && !VBOX_WITH_NETFLT */
+#endif /* (RT_OS_LINUX || RT_OS_FREEBSD || __FreeBSD_kernel__) && !VBOX_WITH_NETFLT */
 
 /**
  * Called at power down to terminate host interface networking.
@@ -7371,11 +7371,11 @@
         pNetworkAdapter->COMGETTER(AttachmentType)(&attachment);
         if (attachment == NetworkAttachmentType_Bridged)
         {
-#if ((defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT))
+#if ((defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && !defined(VBOX_WITH_NETFLT))
             HRESULT rc2 = detachFromTapInterface(pNetworkAdapter);
             if (FAILED(rc2) && SUCCEEDED(rc))
                 rc = rc2;
-#endif /* (RT_OS_LINUX || RT_OS_FREEBSD) && !VBOX_WITH_NETFLT */
+#endif /* (RT_OS_LINUX || RT_OS_FREEBSD || __FreeBSD_kernel__) && !VBOX_WITH_NETFLT */
         }
     }
 

=== modified file 'src/VBox/Main/src-client/ConsoleImpl2.cpp'
--- src/VBox/Main/src-client/ConsoleImpl2.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/src-client/ConsoleImpl2.cpp	2011-07-05 17:09:03 +0000
@@ -87,7 +87,7 @@
 #  include <linux/types.h>
 #  include <linux/if.h>
 #  include <linux/wireless.h>
-# elif defined(RT_OS_FREEBSD)
+# elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 #  include <unistd.h>
 #  include <sys/types.h>
 #  include <sys/ioctl.h>
@@ -1995,14 +1995,14 @@
                 }
 # endif
 #endif /* RT_OS_LINUX */
-#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
+#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__) || defined(VBOX_WITH_SOLARIS_OSS)
                 case AudioDriverType_OSS:
                 {
                     InsertConfigString(pCfg, "AudioDriver", "oss");
                     break;
                 }
 #endif
-#ifdef RT_OS_FREEBSD
+#if defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 # ifdef VBOX_WITH_PULSE
                 case AudioDriverType_Pulse:
                 {
@@ -3531,7 +3531,7 @@
 
             case NetworkAttachmentType_Bridged:
             {
-#if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT)
+#if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && !defined(VBOX_WITH_NETFLT)
                 hrc = attachToTapInterface(aNetworkAdapter);
                 if (FAILED(hrc))
                 {
@@ -3743,8 +3743,8 @@
                 const char *pszTrunk = szTrunkName;
                 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
 
-# elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
-#  if defined(RT_OS_FREEBSD)
+# elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
+#  if defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
                 /*
                  * If we bridge to a tap interface open it the `old' direct way.
                  * This works and performs better than bridging a physical
@@ -3844,7 +3844,7 @@
                 }
                 else
                     Log(("Failed to open wireless socket\n"));
-# elif defined(RT_OS_FREEBSD)
+# elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
                 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
                 if (iSock >= 0)
                 {
@@ -3962,7 +3962,7 @@
             /* NOTHING TO DO HERE */
 #elif defined(RT_OS_LINUX)
 /// @todo aleksey: is there anything to be done here?
-#elif defined(RT_OS_FREEBSD)
+#elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 /** @todo FreeBSD: Check out this later (HIF networking). */
 #else
 # error "Port me"

=== modified file 'src/VBox/Main/src-server/MachineImpl.cpp'
--- src/VBox/Main/src-server/MachineImpl.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/src-server/MachineImpl.cpp	2011-07-05 17:09:03 +0000
@@ -1545,7 +1545,7 @@
 STDMETHODIMP Machine::COMSETTER(MemoryBalloonSize)(ULONG memoryBalloonSize)
 {
     /* This must match GMMR0Init; currently we only support memory ballooning on all 64-bit hosts except Mac OS X */
-#if HC_ARCH_BITS == 64 && (defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD))
+#if HC_ARCH_BITS == 64 && (defined(RT_OS_WINDOWS) || defined(RT_OS_SOLARIS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__))
     /* check limits */
     if (memoryBalloonSize >= VMMDEV_MAX_MEMORY_BALLOON(mHWData->mMemorySize))
         return setError(E_INVALIDARG,
@@ -10152,7 +10152,7 @@
                     E_FAIL);
 #elif defined(VBOX_WITH_SYS_V_IPC_SESSION_WATCHER)
 # ifdef VBOX_WITH_NEW_SYS_V_KEYGEN
-#  if defined(RT_OS_FREEBSD) && (HC_ARCH_BITS == 64)
+#  if (defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && (HC_ARCH_BITS == 64)
     /** @todo Check that this still works correctly. */
     AssertCompileSize(key_t, 8);
 #  else

=== modified file 'src/VBox/Main/src-server/freebsd/HostHardwareFreeBSD.cpp'
--- src/VBox/Main/src-server/freebsd/HostHardwareFreeBSD.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/src-server/freebsd/HostHardwareFreeBSD.cpp	2011-07-05 17:09:03 +0000
@@ -34,16 +34,15 @@
 #include <iprt/thread.h>  /* for RTThreadSleep() */
 #include <iprt/string.h>
 
-#ifdef RT_OS_FREEBSD
-# include <sys/types.h>
-# include <sys/stat.h>
-# include <unistd.h>
-# include <sys/ioctl.h>
-# include <fcntl.h>
-# include <cam/cam.h>
-# include <cam/cam_ccb.h>
-# include <cam/scsi/scsi_pass.h>
-#endif /* RT_OS_FREEBSD */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <stdio.h>	/* needed by <cam/cam.h> */
+#include <cam/cam.h>
+#include <cam/cam_ccb.h>
+#include <cam/scsi/scsi_pass.h>
 #include <vector>
 
 /******************************************************************************

=== modified file 'src/VBox/Main/src-server/freebsd/NetIf-freebsd.cpp'
--- src/VBox/Main/src-server/freebsd/NetIf-freebsd.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/src-server/freebsd/NetIf-freebsd.cpp	2011-07-05 17:09:03 +0000
@@ -44,6 +44,8 @@
 #include <netinet/in.h>
 
 #include <stdio.h>
+#include <stdlib.h>	/* malloc, free */
+#include <bsd/string.h>	/* strlcpy */
 #include <unistd.h>
 #include <errno.h>
 
@@ -159,10 +161,10 @@
             if (!pInfo->IPv6Address.s.Lo && !pInfo->IPv6Address.s.Hi)
             {
                 memcpy(pInfo->IPv6Address.au8,
-                       ((struct sockaddr_in6 *)addresses[RTAX_IFA])->sin6_addr.__u6_addr.__u6_addr8,
+                       ((struct sockaddr_in6 *)addresses[RTAX_IFA])->sin6_addr.s6_addr,
                        sizeof(pInfo->IPv6Address));
                 memcpy(pInfo->IPv6NetMask.au8,
-                       ((struct sockaddr_in6 *)addresses[RTAX_NETMASK])->sin6_addr.__u6_addr.__u6_addr8,
+                       ((struct sockaddr_in6 *)addresses[RTAX_NETMASK])->sin6_addr.s6_addr,
                        sizeof(pInfo->IPv6NetMask));
             }
             break;

=== modified file 'src/VBox/Main/xml/Settings.cpp'
--- src/VBox/Main/xml/Settings.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/xml/Settings.cpp	2011-07-05 17:09:03 +0000
@@ -109,6 +109,8 @@
 #   define VBOX_XML_PLATFORM     "solaris"
 #elif defined (RT_OS_WINDOWS)
 #   define VBOX_XML_PLATFORM     "windows"
+#elif defined (__GLIBC__)
+#   define VBOX_XML_PLATFORM     "gnu"
 #else
 #   error Unsupported platform!
 #endif

=== modified file 'src/VBox/Main/xml/VirtualBox-settings-freebsd.xsd'
--- src/VBox/Main/xml/VirtualBox-settings-freebsd.xsd	2011-07-05 17:05:22 +0000
+++ src/VBox/Main/xml/VirtualBox-settings-freebsd.xsd	2011-07-05 17:09:03 +0000
@@ -58,7 +58,7 @@
           <xsd:restriction base="xsd:token">
             <xsd:enumeration value="Null"/>
             <xsd:enumeration value="OSS"/>
-            <xsd:enumeration value="ALSA"/>
+            <xsd:enumeration value="Pulse"/>
           </xsd:restriction>
         </xsd:simpleType>
       </xsd:attribute>

=== modified file 'src/VBox/Runtime/Makefile.kmk'
--- src/VBox/Runtime/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/VBox/Runtime/Makefile.kmk	2011-07-05 17:09:03 +0000
@@ -500,7 +500,7 @@
 RuntimeR3_SOURCES += \
 	common/err/errmsgxpcom.cpp
 endif
-if1of ($(KBUILD_TARGET),freebsd linux netbsd openbsd solaris)
+if1of ($(KBUILD_TARGET),freebsd gnukfreebsd linux netbsd openbsd solaris)
 RuntimeR3_SOURCES += \
 	$(if $(VBOX_WITH_DBUS),VBox/dbus.cpp,)
 endif
@@ -640,6 +640,62 @@
  endif
 endif
 
+RuntimeR3_SOURCES.gnukfreebsd = \
+	generic/RTDirQueryInfo-generic.cpp \
+	generic/RTDirSetTimes-generic.cpp \
+	generic/RTFileMove-generic.cpp \
+	generic/RTLogWriteDebugger-generic.cpp \
+	generic/RTProcDaemonize-generic.cpp \
+ 	generic/RTSemEventMultiWait-2-ex-generic.cpp \
+ 	generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp \
+	generic/RTSystemQueryDmiString-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 \
+	r3/freebsd/mp-freebsd.cpp \
+	r3/freebsd/rtProcInitExePath-freebsd.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/rtmempage-exec-mmap-heap-posix.cpp \
+	r3/posix/dir-posix.cpp \
+	r3/posix/env-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/path-posix.cpp \
+	r3/posix/path2-posix.cpp \
+	r3/posix/pathhost-posix.cpp \
+	r3/posix/pipe-posix.cpp \
+	r3/posix/poll-posix.cpp \
+	r3/posix/process-posix.cpp \
+	r3/posix/process-creation-posix.cpp \
+	r3/posix/rand-posix.cpp \
+	r3/posix/semrw-posix.cpp \
+	r3/posix/symlink-posix.cpp \
+	r3/posix/thread-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 \
+ 	r3/posix/semevent-posix.cpp \
+ 	r3/posix/semeventmulti-posix.cpp \
+ 	r3/posix/semmutex-posix.cpp
+
 RuntimeR3_SOURCES.os2   = \
 	generic/RTDirQueryInfo-generic.cpp \
 	generic/RTDirSetTimes-generic.cpp \
@@ -1204,8 +1260,10 @@
 	r3/solaris/fileaio-solaris.cpp
 VBoxRT_SOURCES.darwin         += \
 	r3/posix/fileaio-posix.cpp
-VBoxRT_SOURCES.freebsd        += \
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+VBoxRT_SOURCES                += \
 	r3/freebsd/fileaio-freebsd.cpp
+endif
 VBoxRT_INCS                    = $(RuntimeR3_INCS)
 VBoxRT_INCS.$(KBUILD_TARGET)   = $(RuntimeR3_INCS.$(KBUILD_TARGET))
 VBoxRT_INCS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH) = $(RuntimeR3_INCS.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH))
@@ -1231,8 +1289,10 @@
 ifdef IPRT_WITH_LZO
  VBoxRT_LIBS                  += lzo2
 endif
-VBoxRT_LIBS.linux              = \
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBoxRT_LIBS                   += \
 	crypt
+endif
 VBoxRT_LIBS.darwin             = \
 	iconv
 VBoxRT_LIBS.freebsd            = \
@@ -1503,8 +1563,10 @@
 RuntimeR0Drv_DEFS.linux = MODULE KBUILD_MODNAME=KBUILD_STR\(vboxdrv\) KBUILD_BASENAME=KBUILD_STR\(vboxdrv\) IN_SUP_R0
 
 RuntimeR0Drv_INCS      := $(PATH_SUB_CURRENT) include
-RuntimeR0Drv_INCS.freebsd = \
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+RuntimeR0Drv_INCS      += \
 	$(PATH_INS)/gen-sys-hdrs
+endif
 RuntimeR0Drv_INCS.linux = \
 	r0drv/linux
 RuntimeR0Drv_INCS.solaris = \
@@ -1772,7 +1834,8 @@
 	r0drv/os2/timer-r0drv-os2.cpp \
 	r0drv/os2/timerA-r0drv-os2.asm
 
-RuntimeR0Drv_SOURCES.freebsd = \
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+RuntimeR0Drv_SOURCES += \
 	common/err/RTErrConvertFromErrno.cpp \
 	common/err/RTErrConvertToErrno.cpp \
 	common/misc/thread.cpp \
@@ -1806,6 +1869,7 @@
 	generic/timer-generic.cpp \
 	r0drv/memobj-r0drv.cpp \
 	r0drv/powernotification-r0drv.c
+endif
 
 RuntimeR0Drv_SOURCES.solaris = \
 	common/err/RTErrConvertFromErrno.cpp \
@@ -1846,10 +1910,11 @@
 
 ## PORTME: Porters create and add their selection of platform specific Ring-0 Driver files here.
 
-RuntimeR0Drv_ORDERDEPS.freebsd = \
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
+RuntimeR0Drv_ORDERDEPS += \
   	$(PATH_INS)/gen-sys-hdrs/bus_if.h \
   	$(PATH_INS)/gen-sys-hdrs/device_if.h
-
+endif
 
 #
 # RuntimeGuestR0 - Guest driver runtime.
@@ -2054,7 +2119,7 @@
 	$(QUIET)$(VBOX_XSLTPROC) -o $@ $< $(filter %.xidl,$^)
 
 
-if "$(KBUILD_TARGET)" == "freebsd"
+if1of ($(KBUILD_TARGET), freebsd gnukfreebsd)
 #
 # FreeBSDGeneratedKernelHeaders - Generate some kernel interface headers.
 #

=== modified file 'src/VBox/Runtime/VBox/log-vbox.cpp'
--- src/VBox/Runtime/VBox/log-vbox.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Runtime/VBox/log-vbox.cpp	2011-07-05 17:09:03 +0000
@@ -131,7 +131,7 @@
 #  include <Windows.h>
 # elif defined(RT_OS_LINUX)
 #  include <unistd.h>
-# elif defined(RT_OS_FREEBSD)
+# elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
 #  include <sys/param.h>
 #  include <sys/sysctl.h>
 #  include <sys/user.h>
@@ -368,7 +368,7 @@
             fclose(pFile);
         }
 
-#  elif defined(RT_OS_FREEBSD)
+#  elif defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)
         /* Retrieve the required length first */
         int aiName[4];
         aiName[0] = CTL_KERN;

=== modified file 'src/VBox/Runtime/common/err/RTErrConvertFromErrno.cpp'
--- src/VBox/Runtime/common/err/RTErrConvertFromErrno.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Runtime/common/err/RTErrConvertFromErrno.cpp	2011-07-05 17:09:03 +0000
@@ -37,7 +37,7 @@
 # include <sys/errno.h>
 #elif defined(RT_OS_LINUX) && defined(__KERNEL__)
 # include <linux/errno.h>
-#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
+#elif (defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && defined(_KERNEL)
 # include <sys/errno.h>
 #else
 # include <errno.h>

=== modified file 'src/VBox/Runtime/common/err/RTErrConvertToErrno.cpp'
--- src/VBox/Runtime/common/err/RTErrConvertToErrno.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Runtime/common/err/RTErrConvertToErrno.cpp	2011-07-05 17:09:03 +0000
@@ -38,7 +38,7 @@
 # include <sys/errno.h>
 #elif defined(RT_OS_LINUX) && defined(__KERNEL__)
 # include <linux/errno.h>
-#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
+#elif (defined(RT_OS_FREEBSD) || defined(__FreeBSD_kernel__)) && defined(_KERNEL)
 # include <sys/errno.h>
 #else
 # include <errno.h>

=== modified file 'src/VBox/Runtime/r0drv/freebsd/mp-r0drv-freebsd.c'
--- src/VBox/Runtime/r0drv/freebsd/mp-r0drv-freebsd.c	2011-07-05 17:05:22 +0000
+++ src/VBox/Runtime/r0drv/freebsd/mp-r0drv-freebsd.c	2011-07-05 17:09:03 +0000
@@ -163,17 +163,30 @@
     /* Will panic if no rendezvousing cpus, so check up front. */
     if (RTMpGetOnlineCount() > 1)
     {
-#if  __FreeBSD_version >= 700000
-        cpumask_t   Mask = ~(cpumask_t)curcpu;
-#endif
+#ifndef __FreeBSD_version
+#error
+#endif
+
+#if __FreeBSD_version >= 900000
+        cpuset_t    Mask;
+#elif __FreeBSD_version >= 700000
+        cpumask_t   Mask;
+#endif
+        RTCPUID     idCpu = curcpu;
         RTMPARGS    Args;
 
         Args.pfnWorker = pfnWorker;
         Args.pvUser1 = pvUser1;
         Args.pvUser2 = pvUser2;
-        Args.idCpu = RTMpCpuId();
+        Args.idCpu = idCpu;
         Args.cHits = 0;
 #if __FreeBSD_version >= 700000
+        Mask = all_cpus;
+#if __FreeBSD_version >= 900000
+        CPU_CLR(idCpu, &Mask);
+#else
+        Mask &= ~((cpumask_t)1 << idCpu);
+#endif
         smp_rendezvous_cpus(Mask, NULL, rtmpOnOthersFreeBSDWrapper, smp_no_rendevous_barrier, &Args);
 #else
         smp_rendezvous(NULL, rtmpOnOthersFreeBSDWrapper, NULL, &Args);
@@ -203,8 +216,10 @@
 
 RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
 {
-#if  __FreeBSD_version >= 700000
-    cpumask_t   Mask = 1 << idCpu;
+#if __FreeBSD_version >= 900000
+    cpuset_t    Mask;
+#elif __FreeBSD_version >= 700000
+    cpumask_t   Mask;
 #endif
     RTMPARGS    Args;
 
@@ -218,7 +233,11 @@
     Args.idCpu = idCpu;
     Args.cHits = 0;
 #if __FreeBSD_version >= 700000
+#if __FreeBSD_version >= 900000
+    CPU_SETOF(idCpu, &Mask);
+#else
     Mask = (cpumask_t)1 << idCpu;
+#endif
     smp_rendezvous_cpus(Mask, NULL, rtmpOnSpecificFreeBSDWrapper, smp_no_rendevous_barrier, &Args);
 #else
     smp_rendezvous(NULL, rtmpOnSpecificFreeBSDWrapper, NULL, &Args);
@@ -242,13 +261,21 @@
 
 RTDECL(int) RTMpPokeCpu(RTCPUID idCpu)
 {
+#if __FreeBSD_version >= 900000
+    cpuset_t    Mask;
+#else
     cpumask_t   Mask;
+#endif
 
     /* Will panic if no rendezvousing cpus, so make sure the cpu is online. */
     if (!RTMpIsCpuOnline(idCpu))
         return VERR_CPU_NOT_FOUND;
 
+#if __FreeBSD_version >= 900000
+    CPU_SETOF(idCpu, &Mask);
+#else
     Mask = (cpumask_t)1 << idCpu;
+#endif
     smp_rendezvous_cpus(Mask, NULL, rtmpFreeBSDPokeCallback, smp_no_rendevous_barrier, NULL);
 
     return VINF_SUCCESS;

=== modified file 'src/VBox/Runtime/r3/freebsd/fileaio-freebsd.cpp'
--- src/VBox/Runtime/r3/freebsd/fileaio-freebsd.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Runtime/r3/freebsd/fileaio-freebsd.cpp	2011-07-05 17:09:03 +0000
@@ -372,8 +372,12 @@
         size_t i = 0;
         PRTFILEAIOREQINTERNAL pReqInt;
 
+#ifndef AIO_LISTIO_MAX
+#define AIO_LISTIO_MAX sysconf(_SC_AIO_LISTIO_MAX)
+#endif
+
         while (   (i < cReqs)
-               && (i < AIO_LISTIO_MAX))
+               && (AIO_LISTIO_MAX == -1 || i < AIO_LISTIO_MAX))
         {
             pReqInt = pahReqs[i];
             if (RTFILEAIOREQ_IS_NOT_VALID(pReqInt))

=== modified file 'src/VBox/Runtime/r3/posix/utf8-posix.cpp'
--- src/VBox/Runtime/r3/posix/utf8-posix.cpp	2011-07-05 17:05:22 +0000
+++ src/VBox/Runtime/r3/posix/utf8-posix.cpp	2011-07-05 17:09:03 +0000
@@ -168,7 +168,7 @@
             size_t      cbOutLeft = cbOutput2;
             const void *pvInputLeft = pvInput;
             void       *pvOutputLeft = pvOutput;
-#if defined(RT_OS_LINUX) || (defined(RT_OS_DARWIN) && defined(_DARWIN_FEATURE_UNIX_CONFORMANCE)) /* there are different opinions about the constness of the input buffer. */
+#if defined(RT_OS_LINUX) || defined(__GLIBC__) || (defined(RT_OS_DARWIN) && defined(_DARWIN_FEATURE_UNIX_CONFORMANCE)) /* there are different opinions about the constness of the input buffer. */
             if (iconv(hIconv, (char **)&pvInputLeft, &cbInLeft, (char **)&pvOutputLeft, &cbOutLeft) != (size_t)-1)
 #else
             if (iconv(hIconv, (const char **)&pvInputLeft, &cbInLeft, (char **)&pvOutputLeft, &cbOutLeft) != (size_t)-1)
@@ -294,7 +294,7 @@
             size_t      cbOutLeft = cbOutput2;
             const void *pvInputLeft = pvInput;
             void       *pvOutputLeft = pvOutput;
-#if defined(RT_OS_LINUX) || (defined(RT_OS_DARWIN) && defined(_DARWIN_FEATURE_UNIX_CONFORMANCE)) /* there are different opinions about the constness of the input buffer. */
+#if defined(RT_OS_LINUX) || defined(__GLIBC__) || (defined(RT_OS_DARWIN) && defined(_DARWIN_FEATURE_UNIX_CONFORMANCE)) /* there are different opinions about the constness of the input buffer. */
             if (iconv(icHandle, (char **)&pvInputLeft, &cbInLeft, (char **)&pvOutputLeft, &cbOutLeft) != (size_t)-1)
 #else
             if (iconv(icHandle, (const char **)&pvInputLeft, &cbInLeft, (char **)&pvOutputLeft, &cbOutLeft) != (size_t)-1)

=== modified file 'src/apps/Makefile.kmk'
--- src/apps/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/apps/Makefile.kmk	2011-07-05 17:09:03 +0000
@@ -28,7 +28,7 @@
   include $(PATH_SUB_CURRENT)/tunctl/Makefile.kmk
  endif
 endif
-if1of ($(KBUILD_TARGET),darwin solaris linux freebsd)
+if1of ($(KBUILD_TARGET),darwin solaris linux freebsd gnukfreebsd)
  ifneq ($(wildcard $(PATH_SUB_CURRENT)/adpctl),)
   include $(PATH_SUB_CURRENT)/adpctl/Makefile.kmk
  endif

=== modified file 'src/libs/xpcom18a4/Config.kmk'
--- src/libs/xpcom18a4/Config.kmk	2011-07-05 17:05:22 +0000
+++ src/libs/xpcom18a4/Config.kmk	2011-07-05 17:09:03 +0000
@@ -56,7 +56,7 @@
 TEMPLATE_XPCOM_CFLAGS.profile      = -O
 TEMPLATE_XPCOM_CFLAGS.freebsd      = -pthread
 TEMPLATE_XPCOM_CFLAGS.l4           = -nostdinc
-TEMPLATE_XPCOM_CFLAGS.linux        = -pthread -ansi
+TEMPLATE_XPCOM_CFLAGS.gnukfreebsd  = -pthread -ansi
 TEMPLATE_XPCOM_CFLAGS.solaris      = -fno-omit-frame-pointer # for now anyway.
 TEMPLATE_XPCOM_DEFS                = \
 	MOZILLA_CLIENT=1 \
@@ -75,6 +75,7 @@
 TEMPLATE_XPCOM_DEFS.darwin.amd64   = VBOX_MACOSX_FOLLOWS_UNIX_IO
 TEMPLATE_XPCOM_DEFS.freebsd        = OSTYPE=\"FreeBSD5+\"   OSARCH=\"FreeBSD\" XP_UNIX=1 FREEBSD=1 HAVE_VISIBILITY_ATTRIBUTE=1
 TEMPLATE_XPCOM_DEFS.linux          = OSTYPE=\"Linux2.6\"    OSARCH=\"Linux\"  XP_UNIX=1 _GNU_SOURCE HAVE_VISIBILITY_ATTRIBUTE=1 ## @todo LINUX=1
+TEMPLATE_XPCOM_DEFS.gnukfreebsd    = OSTYPE=\"GNU\"         OSARCH=\"GNU\"  XP_UNIX=1 _GNU_SOURCE HAVE_VISIBILITY_ATTRIBUTE=1
 TEMPLATE_XPCOM_DEFS.l4             = OSTYPE=\"L4ENV\"       OSARCH=\"L4\"     XP_UNIX=1 L4ENV HAVE_VISIBILITY_ATTRIBUTE=1
 # Don't define BSD_SELECT because bsdselect() from kLIBC <= 0.6.3 has problems on SMP
 TEMPLATE_XPCOM_DEFS.os2            = OSTYPE=\"OS/2_4.5\"    OSARCH=\"OS/2\"   XP_OS2 XP_PC OS2=4
@@ -165,7 +166,7 @@
 	$(VBoxXPCOM_1_TARGET) \
 	$(TEMPLATE_XPCOM_LIBS)
 TEMPLATE_XPCOMEXE_LIBS.freebsd     = $(LIB_PTHREAD)
-TEMPLATE_XPCOMEXE_LIBS.linux       = dl $(LIB_PTHREAD)
+TEMPLATE_XPCOMEXE_LIBS.gnukfreebsd       = dl $(LIB_PTHREAD)
 TEMPLATE_XPCOMEXE_LIBS.l4          = $(LIB_RUNTIME) $(VBOX_GCC_LIBGCC)
 TEMPLATE_XPCOMEXE_LDFLAGS.darwin   = -bind_at_load $(filter-out -current_version -compatibility_version $(VBOX_VERSION_MAJOR).$(VBOX_VERSION_MINOR).$(VBOX_VERSION_BUILD),$(TEMPLATE_XPCOM_LDFLAGS.darwin))
 TEMPLATE_XPCOMEXE_LDFLAGS.l4       = $(L4_DIR)/lib/x86_586/crt0.o \

=== modified file 'src/libs/xpcom18a4/Makefile.kmk'
--- src/libs/xpcom18a4/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/libs/xpcom18a4/Makefile.kmk	2011-07-05 17:09:03 +0000
@@ -472,10 +472,12 @@
 	$(shell pkg-config --cflags libIDL-2.0)
  xpidl_LDFLAGS = \
 	$(shell pkg-config --libs-only-L libIDL-2.0)
-xpidl_LIBS.linux = \
+ if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+  xpidl_LIBS += \
 	$(shell pkg-config --libs-only-l libIDL-2.0 | sed -e 's/-l//g')
- xpidl_LDFLAGS.linux = \
+  xpidl_LDFLAGS += \
 	$(VBOX_LD_as_needed)
+ endif
 endif
 
 #
@@ -512,8 +514,8 @@
 	_PR_PTHREADS
 ## @todo filling in the missing stuff, please don't just copy it from linux.
 # FIXME: LINUX should be defined by _linux.cfg
-VBox-xpcom-nspr_DEFS.linux = \
-	LINUX=1 \
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBox-xpcom-nspr_DEFS      += \
 	_POSIX_SOURCE=1 \
 	_BSD_SOURCE=1 \
 	_SVID_SOURCE=1 \
@@ -522,6 +524,7 @@
 	HAVE_FCNTL_FILE_LOCKING=1 \
 	HAVE_CVAR_BUILT_ON_SEM \
 	_PR_PTHREADS
+endif
 # _BSD_SOURCE is here to keep the Glibc header files happy and make them include the right things
 # FIXME: L4 should be defined by _linux.cfg
 VBox-xpcom-nspr_DEFS.l4 = \
@@ -606,7 +609,7 @@
 	nsprpub/lib/libc/src/plerror.c \
 	nsprpub/lib/libc/src/plgetopt.c
 
-ifeq ($(filter-out darwin freebsd linux netbsd openbsd solaris,$(KBUILD_TARGET)),) # unixish
+ifeq ($(filter-out darwin freebsd linux gnukfreebsd netbsd openbsd solaris,$(KBUILD_TARGET)),) # unixish
 VBox-xpcom-nspr_SOURCES += \
 	nsprpub/pr/src/md/unix/unix.c \
 	nsprpub/pr/src/md/unix/unix_errors.c \
@@ -649,9 +652,11 @@
 VBox-xpcom-nspr_SOURCES.l4.x86 = nsprpub/pr/src/md/unix/os_Linux_x86.s
 VBox-xpcom-nspr_SOURCES.l4.amd64 = nsprpub/pr/src/md/unix/os_Linux_x86_64.s
 
-VBox-xpcom-nspr_SOURCES.linux = nsprpub/pr/src/md/unix/linux.c
-VBox-xpcom-nspr_SOURCES.linux.x86 = nsprpub/pr/src/md/unix/os_Linux_x86.s
-VBox-xpcom-nspr_SOURCES.linux.amd64 = nsprpub/pr/src/md/unix/os_Linux_x86_64.s
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBox-xpcom-nspr_SOURCES += nsprpub/pr/src/md/unix/linux.c
+VBox-xpcom-nspr_SOURCES.x86 += nsprpub/pr/src/md/unix/os_Linux_x86.s
+VBox-xpcom-nspr_SOURCES.amd64 += nsprpub/pr/src/md/unix/os_Linux_x86_64.s
+endif
 
 VBox-xpcom-nspr_SOURCES.os2 = \
 	nsprpub/pr/src/io/prdir.c \
@@ -815,7 +820,7 @@
 	xpcom/MoreFiles/MoreFilesX.c
 VBox-xpcom-io_SOURCES.l4 = \
 	xpcom/io/nsLocalFileL4.cpp
-if1of ($(KBUILD_TARGET) $(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), freebsd linux netbsd openbsd solaris darwin.amd64)
+if1of ($(KBUILD_TARGET) $(KBUILD_TARGET).$(KBUILD_TARGET_ARCH), freebsd linux gnukfreebsd netbsd openbsd solaris darwin.amd64)
 VBox-xpcom-io_SOURCES += \
 	xpcom/io/nsLocalFileUnix.cpp
 endif
@@ -879,10 +884,12 @@
                                          xpcom/reflect/xptcall/src/md/unix/xptcstubs_gcc_x86_unix.cpp
 VBox-xpcom-xptcall_SOURCES.freebsd.amd64=xpcom/reflect/xptcall/src/md/unix/xptcinvoke_x86_64_linux.cpp \
                                          xpcom/reflect/xptcall/src/md/unix/xptcstubs_x86_64_linux.cpp
-VBox-xpcom-xptcall_SOURCES.linux.x86   = xpcom/reflect/xptcall/src/md/unix/xptcinvoke_gcc_x86_unix.cpp \
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBox-xpcom-xptcall_SOURCES.x86        += xpcom/reflect/xptcall/src/md/unix/xptcinvoke_gcc_x86_unix.cpp \
                                          xpcom/reflect/xptcall/src/md/unix/xptcstubs_gcc_x86_unix.cpp
-VBox-xpcom-xptcall_SOURCES.linux.amd64 = xpcom/reflect/xptcall/src/md/unix/xptcinvoke_x86_64_linux.cpp \
+VBox-xpcom-xptcall_SOURCES.amd64      += xpcom/reflect/xptcall/src/md/unix/xptcinvoke_x86_64_linux.cpp \
                                          xpcom/reflect/xptcall/src/md/unix/xptcstubs_x86_64_linux.cpp
+endif
 VBox-xpcom-xptcall_SOURCES.os2         = xpcom/reflect/xptcall/src/md/os2/xptcinvoke_gcc_x86_os2.cpp \
                                          xpcom/reflect/xptcall/src/md/os2/xptcstubs_gcc_x86_os2.cpp
 VBox-xpcom-xptcall_SOURCES.solaris.x86 = xpcom/reflect/xptcall/src/md/unix/xptcinvoke_x86_solaris.cpp \
@@ -959,8 +966,10 @@
 VBoxXPCOM_NAME = $(basename $(notdir $(LIB_XPCOM)))
 VBoxXPCOM_DEFS = BUILD_DCONNECT="1" _IMPL_NS_COM
 ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
- VBoxXPCOM_LDFLAGS.linux    = -Wl,--version-script=$(XPCOM_C_NAMESPACE_MAP)
- VBoxXPCOM_LNK_DEPS.linux  += $(XPCOM_C_NAMESPACE_MAP)
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+ VBoxXPCOM_LDFLAGS += -Wl,--version-script=$(XPCOM_C_NAMESPACE_MAP)
+ VBoxXPCOM_LNK_DEPS += $(XPCOM_C_NAMESPACE_MAP)
+endif
  VBoxXPCOM_LDFLAGS.solaris  = -Wl,-M,$(XPCOM_C_NAMESPACE_MAP)
  VBoxXPCOM_LNK_DEPS.solaris+= $(XPCOM_C_NAMESPACE_MAP)
 endif
@@ -986,10 +995,12 @@
 	$(VBox-xpcom-proxy_1_TARGET) \
 	$(VBox-xpcom-nspr_1_TARGET) \
 	$(VBoxXPCOMGlue_s_1_TARGET)
-VBoxXPCOM_LIBS.linux = \
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBoxXPCOM_LIBS += \
 	pthread dl
+endif
 
-ifeq ($(filter-out freebsd l4 linux netbsd openbsd,$(KBUILD_TARGET)),) # gnu ld.
+ifeq ($(filter-out freebsd l4 linux gnukfreebsd netbsd openbsd,$(KBUILD_TARGET)),) # gnu ld.
 VBoxXPCOM_LDFLAGS = -Wl,--whole-archive \
 	$(VBox-xpcom-typelib_1_TARGET) \
 	$(VBox-xpcom-string_1_TARGET) \

=== modified file 'src/libs/xpcom18a4/nsprpub/configure'
--- src/libs/xpcom18a4/nsprpub/configure	2011-07-05 17:05:22 +0000
+++ src/libs/xpcom18a4/nsprpub/configure	2011-07-05 17:09:03 +0000
@@ -3662,7 +3662,7 @@
 	esac
     ;;
 
-*-linux*)
+*-linux* | *-*-gnu | *-gnu*)
     if test -z "$USE_NSPR_THREADS"; then
         USE_PTHREADS=1
         IMPL_STRATEGY=_PTH
@@ -3692,7 +3692,9 @@
 EOF
 
     cat >> confdefs.h <<\EOF
+#ifdef __linux__
 #define LINUX 1
+#endif
 EOF
 
     CFLAGS="$CFLAGS -ansi -Wall"

=== modified file 'src/libs/xpcom18a4/nsprpub/configure.in'
--- src/libs/xpcom18a4/nsprpub/configure.in	2011-07-05 17:05:22 +0000
+++ src/libs/xpcom18a4/nsprpub/configure.in	2011-07-05 17:09:03 +0000
@@ -1178,7 +1178,7 @@
 	esac
     ;;
 
-*-linux*)
+*-linux* | *-*-gnu | *-gnu*)
     if test -z "$USE_NSPR_THREADS"; then
         USE_PTHREADS=1
         IMPL_STRATEGY=_PTH
@@ -1189,7 +1189,9 @@
     AC_DEFINE(_SVID_SOURCE)
     AC_DEFINE(_LARGEFILE64_SOURCE)
     AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
-    AC_DEFINE(LINUX)
+    case "${target_os}" in
+        linux*) AC_DEFINE(LINUX) ;;
+    esac
     CFLAGS="$CFLAGS -ansi -Wall"
     CXXFLAGS="$CXXFLAGS -ansi -Wall"
     MDCPUCFG_H=_linux.cfg

=== modified file 'src/libs/xpcom18a4/nsprpub/pr/include/md/_vbox.cfg'
--- src/libs/xpcom18a4/nsprpub/pr/include/md/_vbox.cfg	2011-07-05 17:05:22 +0000
+++ src/libs/xpcom18a4/nsprpub/pr/include/md/_vbox.cfg	2011-07-05 17:09:03 +0000
@@ -45,7 +45,7 @@
 # include <md/_freebsd.cfg>
 #elif defined(RT_OS_L4)
 # include <md/_l4v2.cfg>
-#elif defined(RT_OS_LINUX)
+#elif defined(RT_OS_LINUX) || defined(__GNU__) || defined(__GLIBC__)
 # include <md/_linux.cfg>
 #elif defined(RT_OS_NETBSD)
 # include <md/_netbsd.cfg>

=== modified file 'src/recompiler/Makefile-old.kmk'
--- src/recompiler/Makefile-old.kmk	2011-07-05 17:05:22 +0000
+++ src/recompiler/Makefile-old.kmk	2011-07-05 17:09:03 +0000
@@ -108,7 +108,7 @@
 #$(REM_MOD)_DEFS           += REM_PHYS_ADDR_IN_TLB
 #$(REM_MOD)_DEFS           += DEBUG_ALL_LOGGING DEBUG_DISAS DEBUG_PCALL DEBUG_EXEC DEBUG_FLUSH DEBUG_IOPORT DEBUG_SIGNAL DEBUG_TLB_CHECK DEBUG_TB_INVALIDATE DEBUG_TLB  # Enables huge amounts of debug logging.
 #$(REM_MOD)_DEFS           += DEBUG_TMP_LOGGING # log qemu parts to "/tmp/vbox-qemu.log" - does not work with VBoxREM2.
-$(REM_MOD)_DEFS.linux      = _GNU_SOURCE
+$(REM_MOD)_DEFS.gnukfreebsd      = _GNU_SOURCE
 ifdef VBOX_SOLARIS_10
  $(REM_MOD)_DEFS.solaris   = HOST_SOLARIS=10
 else

=== modified file 'src/recompiler/Makefile.kmk'
--- src/recompiler/Makefile.kmk	2011-07-05 17:05:22 +0000
+++ src/recompiler/Makefile.kmk	2011-07-05 17:09:03 +0000
@@ -64,7 +64,9 @@
 #VBoxRemPrimary_DEFS           += REM_PHYS_ADDR_IN_TLB
 #VBoxRemPrimary_DEFS           += DEBUG_ALL_LOGGING DEBUG_DISAS DEBUG_PCALL DEBUG_EXEC DEBUG_FLUSH DEBUG_IOPORT DEBUG_SIGNAL DEBUG_TLB_CHECK DEBUG_TB_INVALIDATE DEBUG_TLB  # Enables huge amounts of debug logging.
 #VBoxRemPrimary_DEFS           += DEBUG_TMP_LOGGING # log qemu parts to "/tmp/vbox-qemu.log" - does not work with VBoxREM2.
-VBoxRemPrimary_DEFS.linux      = _GNU_SOURCE
+if1of ($(KBUILD_TARGET), linux gnukfreebsd)
+VBoxRemPrimary_DEFS           += _GNU_SOURCE
+endif
 ifdef VBOX_SOLARIS_10
  VBoxRemPrimary_DEFS.solaris   = HOST_SOLARIS=10
 else



More information about the Pkg-virtualbox-devel mailing list