Bug 167521 - [patch] emulators/virtualbox-ose has errors if $ENV not ash-compatible
Summary: [patch] emulators/virtualbox-ose has errors if $ENV not ash-compatible
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Virtualbox Team (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-02 12:10 UTC by Kurt Jaeger
Modified: 2013-01-03 13:50 UTC (History)
1 user (show)

See Also:


Attachments
file.diff (318 bytes, patch)
2012-05-02 12:10 UTC, Kurt Jaeger
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kurt Jaeger 2012-05-02 12:10:08 UTC
	see bugs.freebsd.org/167520 for the same issue

How-To-Repeat: 	see bugs.freebsd.org/167520 for the same repeat
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2012-05-02 12:10:18 UTC
Responsible Changed
From-To: freebsd-ports-bugs->vbox

Over to maintainer (via the GNATS Auto Assign Tool)
Comment 2 Bernhard Froehlich freebsd_committer freebsd_triage 2012-05-02 12:57:37 UTC
Please don't get me wrong but why should I care about what your shell 
XYZ does? It obviously does something stupid and messes up your 
environment so badly that configure or another shell script in the build 
process fails. Please show me the real error and not some hack that can 
workaround that if you seriously want to get that addressed.

-- 
Bernhard Froehlich
http://www.bluelife.at/
Comment 3 Kurt Jaeger 2012-05-02 13:05:42 UTC
Hi!

> Please don't get me wrong but why should I care about what your shell 
> XYZ does?

Because the port makefile uses ash internally and ash dies if
it encounters some $ENV contents.

So it's not my shell, it's the ash that the build uses internally.

The constructs I use in my .bashrc seem to trigger the ash
fail, but I'm not sure why ash is so sensible about my .bashrc.

> It obviously does something stupid and messes up your 
> environment so badly that configure or another shell script in the build 
> process fails. Please show me the real error and not some hack that can 
> workaround that if you seriously want to get that addressed.

Have a look at the breaking build and the .bashrc that triggers it:

http://opsec.eu/src/virtualbox/build-error
http://opsec.eu/src/virtualbox/env-file

-- 
pi@opsec.eu            +49 171 3101372                         8 years to go !
Comment 4 Bernhard Froehlich freebsd_committer freebsd_triage 2012-05-02 13:15:40 UTC
Could you please add "set -x" at the beginning of your .bashrc to get 
more
debugging output from the failing ash?

-- 
Bernhard Froehlich
http://www.bluelife.at/
Comment 5 Kurt Jaeger 2012-05-02 13:20:04 UTC
Hi!

> Could you please add "set -x" at the beginning of your .bashrc to get 
> more
> debugging output from the failing ash?

http://opsec.eu/src/virtualbox/build-2
-- 
pi@opsec.eu            +49 171 3101372                         8 years to go !
Comment 6 Bernhard Froehlich freebsd_committer freebsd_triage 2012-05-02 13:53:00 UTC
On 02.05.2012 14:20, Kurt Jaeger wrote:
> Hi!
>
>> Could you please add "set -x" at the beginning of your .bashrc to 
>> get
>> more
>> debugging output from the failing ash?
>
> http://opsec.eu/src/virtualbox/build-2

It seems that the function definitions in your bashrc are the cause of 
the
troubles. From the ash manpage http://linux.die.net/man/1/ash it looks 
like
the function delcaration syntax is supported but you probably should 
add a
space between the function name and the round brackets.

-- 
Bernhard Froehlich
http://www.bluelife.at/
Comment 7 Kurt Jaeger 2012-05-02 13:59:06 UTC
Hi!

> >> Could you please add "set -x" at the beginning of your .bashrc to 
> >> get
> >> more
> >> debugging output from the failing ash?
> >
> > http://opsec.eu/src/virtualbox/build-2
> 
> It seems that the function definitions in your bashrc are the cause of 
> the
> troubles. From the ash manpage http://linux.die.net/man/1/ash it looks 
> like
> the function delcaration syntax is supported but you probably should 
> add a
> space between the function name and the round brackets.

I just tried that, it still failed.

Putting unsetenv in the port makefile looks easier than debugging
every possible $ENV side effect, no ?

-- 
pi@opsec.eu            +49 171 3101372                         8 years to go !
Comment 8 Kurt Jaeger 2012-06-07 09:21:30 UTC
Hi!

> Putting unsetenv in the port makefile looks easier than debugging
> every possible $ENV side effect, no ?

Any news on this bug and the related one ?

http://www.freebsd.org/cgi/query-pr.cgi?pr=167520

It seems the unsetenv method fixes both without much trouble.

What is wrong about this fix ?

-- 
pi@opsec.eu            +49 171 3101372                         8 years to go !
Comment 9 dfilter service freebsd_committer freebsd_triage 2013-01-03 13:40:47 UTC
Author: decke
Date: Thu Jan  3 13:40:28 2013
New Revision: 309876
URL: http://svnweb.freebsd.org/changeset/ports/309876

Log:
  - Update to 4.2.6
  - Remove custom FreeBSD compiler flags that are only supported by our old
    base GCC 4.2 [1]
  - Fix building with ports GCC 4.6 [1]
  - Fix build on 10-CURRENT after removal of vm_page_lock_queues() in r242941 [2]
  - Improve waits for periods shorter than a single tick [1]
  - Fix dependency check when building with custom KMODDIR [3]
  - Fix recording with OSS Audio backend to record at a proper volume [4]
  - Initialize host-only interfaces at boot time so that other scripts and
    daemons can properly use them [2]
  - Fix build if $ENV not ash-compatible [5]
  - Fix ich9 bios to correctly configure pci bridge1 and pci bridge2 [6]
  - Add VLAN trunking support to vboxnetflt [7]
  
  PR:		ports/171730 [1], ports/167521 [5]
  Submitted by:	Andriy Gapon <avg@FreeBSD.org> [1]
  Submitted by:	Ed Maste <emaste@FreeBSD.org> [2]
  Submitted by:	Kurt Jaeger <fbsd-ports@opsec.eu> [5]
  Submitted by:	Gustau Perez i Querol <gperez@entel.upc.edu> [6]
  Submitted by:	Landon J Fuller <landonf at plausible.coop> [7]
  Reported by:	Daniel Braniss <danny@cs.huji.ac.il> [3]
  Obtained from:	https://www.virtualbox.org/ticket/10695 [4]
  See:		http://article.gmane.org/gmane.os.freebsd.devel.emulation/10438 [6]

Added:
  head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-x11-vboxvideo-Makefile.kmk   (contents, props changed)
  head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Runtime-r0drv-freebsd-the-freebsd-kernel.h   (contents, props changed)
  head/emulators/virtualbox-ose-kmod/files/extrapatch-Config.kmk   (contents, props changed)
  head/emulators/virtualbox-ose-kmod/files/extrapatch-src-VBox-HostDrivers-Support-freebsd-Makefile   (contents, props changed)
  head/emulators/virtualbox-ose-kmod/files/patch-Config.kmk   (contents, props changed)
  head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-Runtime-r0drv-freebsd-sleepqueue-r0drv-freebsd.h   (contents, props changed)
  head/emulators/virtualbox-ose/files/patch-Config.kmk   (contents, props changed)
  head/emulators/virtualbox-ose/files/patch-src-VBox-Devices-Audio-ossaudio.c   (contents, props changed)
  head/emulators/virtualbox-ose/files/patch-src-VBox-Devices-Bus-DevPciIch9.cpp   (contents, props changed)
  head/emulators/virtualbox-ose/files/patch-src-VBox-Main-scr-server-freebsd-PerformanceFreeBSD.cpp   (contents, props changed)
  head/emulators/virtualbox-ose/files/patch-src-VBox-Main-src-server-freebsd-HostHardwareFreeBSD.cpp   (contents, props changed)
  head/emulators/virtualbox-ose/files/patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c   (contents, props changed)
Deleted:
  head/emulators/virtualbox-ose-additions/files/extrapatch-include-iprt-string.h
  head/emulators/virtualbox-ose-additions/files/patch-include-iprt-types.h
  head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-x11-x11include-1.3-xorg-xf86_ansic.h
  head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-x11-x11include-1.4-xorg-xf86_ansic.h
  head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-x11-x11include-7.0-xorg-xf86_ansic.h
  head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-x11-x11include-7.1-xorg-xf86_ansic.h
  head/emulators/virtualbox-ose-kmod/files/patch-include-iprt-types.h
  head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-HostDrivers-Support-freebsd-SUPDrv-freebsd.c
  head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-HostDrivers-VBoxNetAdp-freebsd-Makefile
  head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-HostDrivers-VBoxNetAdp-freebsd-VBoxNetAdp-freebsd.c
  head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-Runtime-r0drv-freebsd-semfastmutex-r0drv-freebsd.c
  head/emulators/virtualbox-ose/files/extrapatch-include-iprt-string.h
  head/emulators/virtualbox-ose/files/patch-include-iprt-types.h
  head/emulators/virtualbox-ose/files/patch-src-VBox-Frontends-VBoxManage-VBoxInternalManage.cpp
  head/emulators/virtualbox-ose/files/patch-src-VBox-HostDrivers-Makefile.kmk
  head/emulators/virtualbox-ose/files/patch-src-VBox-HostServices-auth-pam-VBoxAuthPAM.c
  head/emulators/virtualbox-ose/files/patch-src-VBox-Main-src-server-MachineImpl.cpp
Modified:
  head/emulators/virtualbox-ose-additions/Makefile
  head/emulators/virtualbox-ose-additions/distinfo
  head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c   (contents, props changed)
  head/emulators/virtualbox-ose-kmod/Makefile
  head/emulators/virtualbox-ose-kmod/distinfo
  head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-HostDrivers-VBoxNetFlt-freebsd-VBoxNetFlt-freebsd.c   (contents, props changed)
  head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c   (contents, props changed)
  head/emulators/virtualbox-ose-kmod/files/vboxnet.in   (contents, props changed)
  head/emulators/virtualbox-ose/Makefile
  head/emulators/virtualbox-ose/distinfo
  head/emulators/virtualbox-ose/files/patch-configure   (contents, props changed)
  head/emulators/virtualbox-ose/files/patch-src-VBox-Main-src-server-freebsd-NetIf-freebsd.cpp   (contents, props changed)
  head/emulators/virtualbox-ose/pkg-message   (contents, props changed)
  head/emulators/virtualbox-ose/pkg-plist   (contents, props changed)

Modified: head/emulators/virtualbox-ose-additions/Makefile
==============================================================================
--- head/emulators/virtualbox-ose-additions/Makefile	Thu Jan  3 13:37:12 2013	(r309875)
+++ head/emulators/virtualbox-ose-additions/Makefile	Thu Jan  3 13:40:28 2013	(r309876)
@@ -1,12 +1,8 @@
-# New ports collection makefile for:	virtualbox-ose-additions
-# Date created:		2009-09-21
-# Whom:			Bernhard Froehlich <decke@bluelife.at>
-#
+# Created by:	Bernhard Froehlich <decke@bluelife.at>
 # $FreeBSD$
-#
 
 PORTNAME=	virtualbox-ose
-DISTVERSION=	4.1.22
+DISTVERSION=	4.2.6
 CATEGORIES=	emulators kld
 MASTER_SITES=	http://download.virtualbox.org/virtualbox/${DISTVERSION}/ \
 		http://tmp.chruetertee.ch/ \
@@ -22,12 +18,13 @@ LICENSE_FILE=	${WRKSRC}/COPYING
 
 BUILD_DEPENDS=	yasm:${PORTSDIR}/devel/yasm \
 		as86:${PORTSDIR}/devel/dev86 \
-		kmk:${PORTSDIR}/devel/kBuild-devel
+		kmk:${PORTSDIR}/devel/kBuild
 
 UNIQUENAME=	${PORTNAME}${PKGNAMESUFFIX}
 WRKSRC=		${WRKDIR}/VirtualBox-${PORTVERSION}
 USE_RC_SUBR=	vboxguest vboxservice
 ONLY_FOR_ARCHS=	i386 amd64
+FETCH_ARGS=	-pRr
 USE_BZIP2=	yes
 MAKE_JOBS_UNSAFE=	yes
 
@@ -38,7 +35,6 @@ CONFIGURE_ARGS+=--with-gcc="${CC}" --wit
 		--build-headless
 
 CONFLICTS=	bcc-[0-9]*
-CONFLICTS_BUILD=	kBuild-[0-9]*
 CONFLICTS_INSTALL=	virtualbox-ose-additions-devel-[3,4]* virtualbox-ose-[3,4]* virtualbox-ose-devel-[3,4]* virtualbox-ose-legacy-[3,4]*
 
 OPTIONS_DEFINE=	DEBUG X11 OPENGL
@@ -93,10 +89,6 @@ IGNORE=		requires kernel sources
 
 .include <bsd.port.pre.mk>
 
-.if ${OSVERSION} > 900012
-EXTRA_PATCHES=	${FILESDIR}/extrapatch-include-iprt-string.h
-.endif
-
 pre-everything::
 .if ${ARCH} == "amd64"
 .if !exists(/usr/lib32/libc.so)

Modified: head/emulators/virtualbox-ose-additions/distinfo
==============================================================================
--- head/emulators/virtualbox-ose-additions/distinfo	Thu Jan  3 13:37:12 2013	(r309875)
+++ head/emulators/virtualbox-ose-additions/distinfo	Thu Jan  3 13:40:28 2013	(r309876)
@@ -1,2 +1,2 @@
-SHA256 (VirtualBox-4.1.22.tar.bz2) = 7abb506203dd0d69b4b408fd999b5b9a479a9adce5f80e9b5569641c053dd153
-SIZE (VirtualBox-4.1.22.tar.bz2) = 73385514
+SHA256 (VirtualBox-4.2.6.tar.bz2) = 54526091bc2aa66b88ca878dd9ecc4466f96d607db2f6678a9d673ecf6646ae3
+SIZE (VirtualBox-4.2.6.tar.bz2) = 76291326

Added: head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-x11-vboxvideo-Makefile.kmk
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Additions-x11-vboxvideo-Makefile.kmk	Thu Jan  3 13:40:28 2013	(r309876)
@@ -0,0 +1,20 @@
+--- src/VBox/Additions/x11/vboxvideo/Makefile.kmk.orig	2012-10-26 18:23:35.000000000 +0200
++++ src/VBox/Additions/x11/vboxvideo/Makefile.kmk	2012-10-28 16:54:59.074303788 +0100
+@@ -196,7 +196,7 @@
+ vboxvideo_drv_15_TEMPLATE = VBOXGUESTR3XORGMOD
+ vboxvideo_drv_15_CFLAGS := $(vboxvideo_drv_70_CFLAGS)
+ vboxvideo_drv_15_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=100503000
+-if1of ($(KBUILD_TARGET), linux solaris)
++if1of ($(KBUILD_TARGET), freebsd linux solaris)
+  vboxvideo_drv_15_DEFS += VBOX_DRI
+ endif
+ vboxvideo_drv_15_INCS = \
+@@ -204,7 +204,7 @@
+ 	$(VBOX_PATH_X11_ROOT)/xorg-server-1.5.3
+ vboxvideo_drv_15_INCS += $(PATH_ROOT)/src/VBox/Runtime/include
+ vboxvideo_drv_15_SOURCES  = $(vboxvideo_drv_13_SOURCES)
+-if1of ($(KBUILD_TARGET), linux solaris)
++if1of ($(KBUILD_TARGET), freebsd linux solaris)
+  vboxvideo_drv_15_SOURCES += \
+ 	vboxvideo_dri.c
+ endif

Modified: head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c
==============================================================================
--- head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c	Thu Jan  3 13:37:12 2013	(r309875)
+++ head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c	Thu Jan  3 13:40:28 2013	(r309876)
@@ -1,25 +1,56 @@
-Remove explicit initialization of m->flags and m->oflags because per
-default vm_phys_alloc_contig() already initializes the page as unmanaged.
-Chase move of PG_UNMANAGED flag from m->flags to m->oflags and renaming
-to VPO_UNMANAGED for an additional assert.
+From Alan L. Cox on FreeBSD-current:
 
-Reviewed by:	kib
-See:		http://svnweb.freebsd.org/base?view=revision&revision=224746
---- src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c.orig	2011-04-05 14:34:09.000000000 +0200
-+++ src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c	2011-08-11 15:06:46.000000000 +0200
-@@ -394,9 +394,13 @@
-     pPage->wire_count = 1;
-     pPage->pindex     = iPage;
-     pPage->act_count  = 0;
--    pPage->oflags     = 0;
--    pPage->flags      = PG_UNMANAGED;
-     atomic_add_int(&cnt.v_wire_count, 1);
-+
-+#if __FreeBSD_version >= 900040
-+    Assert(pPage->oflags & VPO_UNMANAGED != 0);
-+#else
-+    Assert(pPage->flags & PG_UNMANAGED != 0);
+    I just glanced at the virtualbox code for a couple minutes.  For
+    FreeBSD 9 and 10, these lock acquires are completely unnecessary, and
+    have been since FreeBSD 9.0.  Just delete them.  They may be equally
+    unnecessary under FreeBSD 8, but I didn't look carefully enough to
+    answer that question.
+
+[1] http://lists.freebsd.org/pipermail/freebsd-current/2012-November/037963.html
+---
+ src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+diff --git a/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c b/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
+index 5c90cf3..1176b51 100644
+--- src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
++++ src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
+@@ -164,14 +164,19 @@ DECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
+         {
+             VM_OBJECT_LOCK(pMemFreeBSD->pObject);
+             vm_page_t pPage = vm_page_find_least(pMemFreeBSD->pObject, 0);
++#if __FreeBSD_version < 900000
++            /* See http://lists.freebsd.org/pipermail/freebsd-current/2012-November/037963.html */
+             vm_page_lock_queues();
++#endif
+             for (vm_page_t pPage = vm_page_find_least(pMemFreeBSD->pObject, 0);
+                  pPage != NULL;
+                  pPage = vm_page_next(pPage))
+             {
+                 vm_page_unwire(pPage, 0);
+             }
++#if __FreeBSD_version < 900000
+             vm_page_unlock_queues();
 +#endif
- }
- 
- 
+             VM_OBJECT_UNLOCK(pMemFreeBSD->pObject);
+             vm_object_deallocate(pMemFreeBSD->pObject);
+             break;
+@@ -263,11 +268,15 @@ static int rtR0MemObjFreeBSDPhysAllocHelper(vm_object_t pObject, u_long cPages,
+             while (iPage-- > 0)
+             {
+                 pPage = vm_page_lookup(pObject, iPage);
++#if __FreeBSD_version < 900000
+                 vm_page_lock_queues();
++#endif
+                 if (fWire)
+                     vm_page_unwire(pPage, 0);
+                 vm_page_free(pPage);
++#if __FreeBSD_version < 900000
+                 vm_page_unlock_queues();
++#endif
+             }
+             VM_OBJECT_UNLOCK(pObject);
+             return rcNoMem;
+-- 
+1.7.11.5
+

Added: head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Runtime-r0drv-freebsd-the-freebsd-kernel.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/virtualbox-ose-additions/files/patch-src-VBox-Runtime-r0drv-freebsd-the-freebsd-kernel.h	Thu Jan  3 13:40:28 2013	(r309876)
@@ -0,0 +1,10 @@
+--- ./src/VBox/Runtime/r0drv/freebsd/the-freebsd-kernel.h.orig	2012-06-12 02:54:01.440878507 +0400
++++ ./src/VBox/Runtime/r0drv/freebsd/the-freebsd-kernel.h	2012-06-12 00:08:55.218232972 +0400
+@@ -64,6 +64,7 @@
+ #include <vm/vm_kern.h>
+ #include <vm/vm_param.h>        /* KERN_SUCCESS ++ */
+ #include <vm/vm_page.h>
++#include <vm/vm_pageout.h>
+ #include <vm/vm_phys.h>         /* vm_phys_alloc_* */
+ #include <vm/vm_extern.h>       /* kmem_alloc_attr */
+ #include <sys/vmmeter.h>        /* cnt */

Modified: head/emulators/virtualbox-ose-kmod/Makefile
==============================================================================
--- head/emulators/virtualbox-ose-kmod/Makefile	Thu Jan  3 13:37:12 2013	(r309875)
+++ head/emulators/virtualbox-ose-kmod/Makefile	Thu Jan  3 13:40:28 2013	(r309876)
@@ -1,12 +1,8 @@
-# New ports collection makefile for:	virtualbox-ose-kmod
-# Date created:		2009-09-21
-# Whom:			Bernhard Froehlich <decke@bluelife.at>
-#
+# Created by:	Bernhard Froehlich <decke@bluelife.at>
 # $FreeBSD$
-#
 
 PORTNAME=	virtualbox-ose
-DISTVERSION=	4.1.22
+DISTVERSION=	4.2.6
 CATEGORIES=	emulators kld
 MASTER_SITES=	http://download.virtualbox.org/virtualbox/${DISTVERSION}/ \
 		http://tmp.chruetertee.ch/ \
@@ -22,12 +18,13 @@ LICENSE_FILE=	${WRKSRC}/COPYING
 
 BUILD_DEPENDS=	yasm:${PORTSDIR}/devel/yasm \
 		as86:${PORTSDIR}/devel/dev86 \
-		kmk:${PORTSDIR}/devel/kBuild-devel
+		kmk:${PORTSDIR}/devel/kBuild
 
 UNIQUENAME=	${PORTNAME}${PKGNAMESUFFIX}
 WRKSRC=		${WRKDIR}/VirtualBox-${PORTVERSION}
 USE_RC_SUBR=	vboxnet
 ONLY_FOR_ARCHS=	i386 amd64
+FETCH_ARGS=	-pRr
 USE_BZIP2=	yes
 
 HAS_CONFIGURE=	yes
@@ -37,30 +34,31 @@ CONFIGURE_ARGS+=--with-gcc="${CC}" --wit
 		--build-headless
 
 CONFLICTS=	bcc-[0-9]*
-CONFLICTS_BUILD=	kBuild-[0-9]*
 CONFLICTS_INSTALL=	virtualbox-ose-kmod-devel-[3,4]* virtualbox-ose-kmod-legacy-[3,4]*
 
 OPTIONS_DEFINE=	DEBUG VIMAGE
+DEBUG_DESC=	Debug symbols, additional logs and assertions
 VIMAGE_DESC=	VIMAGE virtual networking support
 
 .include <bsd.port.options.mk>
 
 PLIST_SUB+=	KMODDIR=${KMODDIR:C,^/,,}
 
-KMODDIR=	/boot/modules
+KMODDIR?=	/boot/modules
 SRC_BASE?=	/usr/src
 
 VBOX_BIN=	${WRKSRC}/out/${KMK_ARCH}/${KMK_BUILDTYPE}/bin/src
 
 KMK_BUILDTYPE=	release
 KMK_CONFIG=	VBOX_LIBPATH_X11=${LOCALBASE} VBOX_FREEBSD_SRC=${SRC_BASE}/sys
-KMK_FLAGS=	HostDrivers-src vboxdrv-mod VBoxNetFlt-src VBoxNetAdp-src
+KMK_FLAGS=	HostDrivers-scripts vboxdrv-mod VBoxNetFlt-src VBoxNetAdp-src
 
 MAKE_FLAGS=	SYSDIR=${SRC_BASE}/sys
 
 .if ${PORT_OPTIONS:MDEBUG}
 KMK_FLAGS+=	BUILD_TYPE=debug
 KMK_BUILDTYPE=	debug
+EXTRA_PATCHES+=	${FILESDIR}/extrapatch-Config.kmk ${FILESDIR}/extrapatch-src-VBox-HostDrivers-Support-freebsd-Makefile
 MAKE_FLAGS+=	DEBUG_FLAGS="-O1 -g"
 PLIST_SUB+=	WITH_DEBUG=""
 .else

Modified: head/emulators/virtualbox-ose-kmod/distinfo
==============================================================================
--- head/emulators/virtualbox-ose-kmod/distinfo	Thu Jan  3 13:37:12 2013	(r309875)
+++ head/emulators/virtualbox-ose-kmod/distinfo	Thu Jan  3 13:40:28 2013	(r309876)
@@ -1,2 +1,2 @@
-SHA256 (VirtualBox-4.1.22.tar.bz2) = 7abb506203dd0d69b4b408fd999b5b9a479a9adce5f80e9b5569641c053dd153
-SIZE (VirtualBox-4.1.22.tar.bz2) = 73385514
+SHA256 (VirtualBox-4.2.6.tar.bz2) = 54526091bc2aa66b88ca878dd9ecc4466f96d607db2f6678a9d673ecf6646ae3
+SIZE (VirtualBox-4.2.6.tar.bz2) = 76291326

Added: head/emulators/virtualbox-ose-kmod/files/extrapatch-Config.kmk
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/virtualbox-ose-kmod/files/extrapatch-Config.kmk	Thu Jan  3 13:40:28 2013	(r309876)
@@ -0,0 +1,11 @@
+--- Config.kmk.orig	2012-05-24 01:15:53.393052000 +0200
++++ Config.kmk	2012-05-24 01:16:15.883067161 +0200
+@@ -3188,7 +3188,7 @@
+ 		| xargs -J% objcopy % $(out)
+ 
+ ## Strip debug info (comment out if debugging or something).
+-	objcopy --strip-debug $(out)
++#	objcopy --strip-debug $(out)
+ endef
+  else # x86
+ TOOL_FREEBSDKMODLD_LINK_SYSMOD_OUTPUT = $(outbase).kld

Added: head/emulators/virtualbox-ose-kmod/files/extrapatch-src-VBox-HostDrivers-Support-freebsd-Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/virtualbox-ose-kmod/files/extrapatch-src-VBox-HostDrivers-Support-freebsd-Makefile	Thu Jan  3 13:40:28 2013	(r309876)
@@ -0,0 +1,11 @@
+--- src/VBox/HostDrivers/Support/freebsd/Makefile.orig	2012-10-18 16:23:16.000000000 +0200
++++ src/VBox/HostDrivers/Support/freebsd/Makefile	2012-10-20 08:13:07.301179212 +0200
+@@ -27,7 +27,7 @@
+ 
+ KMOD = vboxdrv
+ 
+-CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DSUPDRV_WITH_RELEASE_LOGGER -DVBOX -DRT_WITH_VBOX -Iinclude -I. -Ir0drv -w -DVBOX_WITH_HARDENING -DVBOX_WITH_64_BITS_GUESTS
++CFLAGS += -DRT_OS_FREEBSD -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DSUPDRV_WITH_RELEASE_LOGGER -DVBOX -DRT_WITH_VBOX -Iinclude -I. -Ir0drv -w -DVBOX_WITH_HARDENING -DVBOX_WITH_64_BITS_GUESTS -DEBUG
+ 
+ .if (${MACHINE_ARCH} == "i386")
+  CFLAGS += -DRT_ARCH_X86

Added: head/emulators/virtualbox-ose-kmod/files/patch-Config.kmk
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/emulators/virtualbox-ose-kmod/files/patch-Config.kmk	Thu Jan  3 13:40:28 2013	(r309876)
@@ -0,0 +1,56 @@
+--- Config.kmk.orig	2012-12-20 14:44:38.260858319 +0100
++++ Config.kmk	2012-12-20 14:55:59.491850177 +0100
+@@ -3239,7 +3239,7 @@
+ 	$(VBOX_GCC_WARN) -Wpointer-arith -Winline $(VBOX_GCC_Wno-pointer-sign) $(VBOX_GCC_fdiagnostics-show-option) \
+ 	-Wstrict-prototypes -Wmissing-prototypes -Wstrict-prototypes \
+ 	-Wimplicit-function-declaration -Werror-implicit-function-declaration \
+-	-O2 -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
+@@ -3248,7 +3248,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)
+@@ -3465,8 +3465,6 @@
+ 	/usr/X11R6/include \
+ 	/usr/local/include
+ TEMPLATE_VBOXR3EXE_LIBPATH            += \
+-	/usr/lib \
+-	/usr/X11R6/lib \
+ 	/usr/local/lib
+  else ifeq ($(KBUILD_TARGET),solaris)
+ TEMPLATE_VBOXR3EXE_TOOL                = GXX3PLAIN
+@@ -3955,8 +3953,6 @@
+ 	/usr/X11R6/include \
+ 	/usr/local/include
+ TEMPLATE_VBOXMAINEXE_LIBPATH            += \
+-	/usr/lib \
+-	/usr/X11R6/lib \
+ 	/usr/local/lib
+ else ifeq ($(KBUILD_TARGET),solaris)
+ TEMPLATE_VBOXMAINEXE_TOOL                = GXX3PLAIN
+@@ -4371,8 +4367,6 @@
+ 	/usr/X11R6/include \
+ 	/usr/local/include
+     TEMPLATE_VBOXQT4GUIEXE_LIBPATH += \
+-	/usr/lib \
+-	/usr/X11R6/lib \
+ 	/usr/local/lib
+    endif
+    ifeq ($(KBUILD_TARGET),solaris)
+@@ -4555,8 +4549,6 @@
+ 	/usr/X11R6/include \
+ 	/usr/local/include
+ TEMPLATE_VBOXBLDPROG_LIBPATH            += \
+-	/usr/lib \
+-	/usr/X11R6/lib \
+ 	/usr/local/lib
+  else ifeq ($(KBUILD_HOST),solaris)
+ TEMPLATE_VBOXBLDPROG_TOOL                = GXX3PLAIN

Modified: head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-HostDrivers-VBoxNetFlt-freebsd-VBoxNetFlt-freebsd.c
==============================================================================
--- head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-HostDrivers-VBoxNetFlt-freebsd-VBoxNetFlt-freebsd.c	Thu Jan  3 13:37:12 2013	(r309875)
+++ head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-HostDrivers-VBoxNetFlt-freebsd-VBoxNetFlt-freebsd.c	Thu Jan  3 13:40:28 2013	(r309876)
@@ -1,31 +1,23 @@
-The attached patch fixes a kernel crash on FreeBSD 10-CURRENT hosts
-with VIMAGE enabled when a VM is powered off.
+Add VLAN trunking support to vboxnetflt
 
-Submitted by:	Mikolaj Golub <trociny at freebsd.org>
---- src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c	2012-03-13 15:15:44.000000000 +0200
-+++ src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c	2012-04-01 13:43:02.000000000 +0300
-@@ -651,13 +651,13 @@ bool vboxNetFltOsMaybeRediscovered(PVBOX
-         ng_rmnode_self(pThis->u.s.node);
-         pThis->u.s.node = NULL;
-     }
-+    VBOXCURVNET_RESTORE();
+See:		http://lists.freebsd.org/pipermail/freebsd-emulation/2012-April/009698.html
+Submitted by:	Landon J Fuller <landonf at plausible.coop>
+--- src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c.orig	2012-04-12 17:27:56.035382846 -0400
++++ src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c	2012-04-12 17:30:13.038601065 -0400
+@@ -439,6 +439,16 @@
+         if (m == NULL)
+             break;
  
-     if (ifp0 != NULL)
-     {
-         vboxNetFltOsDeleteInstance(pThis);
-         vboxNetFltOsInitInstance(pThis, NULL);
-     }
--    VBOXCURVNET_RESTORE();
- 
-     return !ASMAtomicUoReadBool(&pThis->fDisconnectedFromHost);
- }
-@@ -671,8 +671,10 @@ void vboxNetFltOsDeleteInstance(PVBOXNET
-     mtx_destroy(&pThis->u.s.inq.ifq_mtx);
-     mtx_destroy(&pThis->u.s.outq.ifq_mtx);
- 
-+    VBOXCURVNET_SET_FROM_UCRED();
-     if (pThis->u.s.node != NULL)
-         ng_rmnode_self(pThis->u.s.node);
-+    VBOXCURVNET_RESTORE();
-     pThis->u.s.node = NULL;
- }
++        /* Preprend a VLAN header for consumption by the virtual switch */
++        if (m->m_flags & M_VLANTAG) {
++            m = ether_vlanencap(m, m->m_pkthdr.ether_vtag);
++            if (m == NULL) {
++                printf("vboxflt: unable to prepend VLAN header\n");
++                break;
++            }
++            m->m_flags &= ~M_VLANTAG;
++        }
++
+         for (m0 = m; m0 != NULL; m0 = m0->m_next)
+             if (m0->m_len > 0)
+                 cSegs++;

Modified: head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c
==============================================================================
--- head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c	Thu Jan  3 13:37:12 2013	(r309875)
+++ head/emulators/virtualbox-ose-kmod/files/patch-src-VBox-Runtime-r0drv-freebsd-memobj-r0drv-freebsd.c	Thu Jan  3 13:40:28 2013	(r309876)
@@ -1,888 +1,56 @@
---- src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c.orig	2012-06-20 15:18:10.000000000 +0200
-+++ src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c	2012-07-25 18:04:01.534886951 +0200
-@@ -5,6 +5,7 @@
- 
- /*
-  * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
-+ * Copyright (c) 2011 Andriy Gapon <avg@FreeBSD.org>
-  *
-  * Permission is hereby granted, free of charge, to any person
-  * obtaining a copy of this software and associated documentation
-@@ -54,23 +55,8 @@
-     /** The core structure. */
-     RTR0MEMOBJINTERNAL  Core;
-     /** Type dependent data */
--    union
--    {
--        /** Non physical memory allocations */
--        struct
--        {
--            /** The VM object associated with the allocation. */
--            vm_object_t         pObject;
--        } NonPhys;
--        /** Physical memory allocations */
--        struct
--        {
--            /** Number of pages */
--            uint32_t            cPages;
--            /** Array of pages - variable */
--            vm_page_t           apPages[1];
--        } Phys;
--    } u;
-+    /** The VM object associated with the allocation. */
-+    vm_object_t         pObject;
- } RTR0MEMOBJFREEBSD, *PRTR0MEMOBJFREEBSD;
- 
- 
-@@ -125,25 +111,14 @@
- 
-     switch (pMemFreeBSD->Core.enmType)
-     {
--        case RTR0MEMOBJTYPE_CONT:
--            contigfree(pMemFreeBSD->Core.pv, pMemFreeBSD->Core.cb, M_IPRTMOBJ);
--            break;
--
-         case RTR0MEMOBJTYPE_PAGE:
-+        case RTR0MEMOBJTYPE_LOW:
-+        case RTR0MEMOBJTYPE_CONT:
-         {
-             rc = vm_map_remove(kernel_map,
-                                 (vm_offset_t)pMemFreeBSD->Core.pv,
-                                 (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
-             AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
--
--            vm_page_lock_queues();
--            for (uint32_t iPage = 0; iPage < pMemFreeBSD->u.Phys.cPages; iPage++)
--            {
--                vm_page_t pPage = pMemFreeBSD->u.Phys.apPages[iPage];
--                vm_page_unwire(pPage, 0);
--                vm_page_free(pPage);
--            }
--            vm_page_unlock_queues();
-             break;
-         }
- 
-@@ -165,8 +140,8 @@
-         case RTR0MEMOBJTYPE_RES_VIRT:
-         {
-             vm_map_t pMap = kernel_map;
--            if (pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
--                pMap = &((struct proc *)pMemFreeBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map;
-+            if (pMemFreeBSD->Core.u.ResVirt.R0Process != NIL_RTR0PROCESS)
-+                pMap = &((struct proc *)pMemFreeBSD->Core.u.ResVirt.R0Process)->p_vmspace->vm_map;
-             rc = vm_map_remove(pMap,
-                                (vm_offset_t)pMemFreeBSD->Core.pv,
-                                (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
-@@ -180,7 +155,6 @@
- 
-             if (pMemFreeBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS)
-                 pMap = &((struct proc *)pMemFreeBSD->Core.u.Mapping.R0Process)->p_vmspace->vm_map;
--
-             rc = vm_map_remove(pMap,
-                                (vm_offset_t)pMemFreeBSD->Core.pv,
-                                (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
-@@ -191,26 +165,21 @@
-         case RTR0MEMOBJTYPE_PHYS:
-         case RTR0MEMOBJTYPE_PHYS_NC:
-         {
-+            VM_OBJECT_LOCK(pMemFreeBSD->pObject);
-+            vm_page_t pPage = vm_page_find_least(pMemFreeBSD->pObject, 0);
+From Alan L. Cox on FreeBSD-current:
+
+    I just glanced at the virtualbox code for a couple minutes.  For
+    FreeBSD 9 and 10, these lock acquires are completely unnecessary, and
+    have been since FreeBSD 9.0.  Just delete them.  They may be equally
+    unnecessary under FreeBSD 8, but I didn't look carefully enough to
+    answer that question.
+
+[1] http://lists.freebsd.org/pipermail/freebsd-current/2012-November/037963.html
+---
+ src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+diff --git a/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c b/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
+index 5c90cf3..1176b51 100644
+--- src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
++++ src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
+@@ -164,14 +164,19 @@ DECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
+         {
+             VM_OBJECT_LOCK(pMemFreeBSD->pObject);
+             vm_page_t pPage = vm_page_find_least(pMemFreeBSD->pObject, 0);
++#if __FreeBSD_version < 900000
++            /* See http://lists.freebsd.org/pipermail/freebsd-current/2012-November/037963.html */
              vm_page_lock_queues();
--            for (uint32_t iPage = 0; iPage < pMemFreeBSD->u.Phys.cPages; iPage++)
-+            for (vm_page_t pPage = vm_page_find_least(pMemFreeBSD->pObject, 0);
-+                 pPage != NULL;
-+                 pPage = vm_page_next(pPage))
++#endif
+             for (vm_page_t pPage = vm_page_find_least(pMemFreeBSD->pObject, 0);
+                  pPage != NULL;
+                  pPage = vm_page_next(pPage))
              {
--                vm_page_t pPage = pMemFreeBSD->u.Phys.apPages[iPage];
                  vm_page_unwire(pPage, 0);
--                vm_page_free(pPage);
              }
++#if __FreeBSD_version < 900000
              vm_page_unlock_queues();
-+            VM_OBJECT_UNLOCK(pMemFreeBSD->pObject);
-+            vm_object_deallocate(pMemFreeBSD->pObject);
-             break;
-         }
- 
--#ifdef USE_KMEM_ALLOC_ATTR
--        case RTR0MEMOBJTYPE_LOW:
--        {
--            kmem_free(kernel_map, (vm_offset_t)pMemFreeBSD->Core.pv, pMemFreeBSD->Core.cb);
--            break;
--        }
--#else
--        case RTR0MEMOBJTYPE_LOW: /* unused */
--#endif
-         default:
-             AssertMsgFailed(("enmType=%d\n", pMemFreeBSD->Core.enmType));
-             return VERR_INTERNAL_ERROR;
-@@ -220,183 +189,183 @@
- }
- 
- 
--DECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
--{
--    int rc;
--    size_t cPages = cb >> PAGE_SHIFT;
--
--    /* create the object. */
--    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJFREEBSD, u.Phys.apPages[cPages]),
--                                                                       RTR0MEMOBJTYPE_PAGE, NULL, cb);
--    if (!pMemFreeBSD)
--        return VERR_NO_MEMORY;
--
--    pMemFreeBSD->u.Phys.cPages = cPages;
-+static vm_page_t FreeBSDContigPhysAllocHelper(vm_object_t pObject, vm_pindex_t iPIndex,
-+                                              u_long cPages, vm_paddr_t VmPhysAddrHigh,
-+                                              u_long uAlignment, bool fWire)
-+{
-+    vm_page_t pPages;
-+    int tries = 0;
-+#if __FreeBSD_version > 1000000
-+    int flags = VM_ALLOC_INTERRUPT | VM_ALLOC_NOBUSY;
-+
-+    if (fWire)
-+        flags |= VM_ALLOC_WIRED;
-+    while (1)
-+    {
-+        VM_OBJECT_LOCK(pObject);
-+        pPages = vm_page_alloc_contig(pObject, iPIndex, flags, cPages, 0, VmPhysAddrHigh, uAlignment, 0, VM_MEMATTR_DEFAULT);
-+        VM_OBJECT_UNLOCK(pObject);
-+        if (pPages || tries >= 1)
-+            break;
-+        vm_pageout_grow_cache(tries, 0, VmPhysAddrHigh);
-+        tries++;
-+    }
-+    return pPages;
-+#else
- 
--    vm_offset_t MapAddress = vm_map_min(kernel_map);
--    rc = vm_map_find(kernel_map,                /* map */
--                     NULL,                      /* object */
--                     0,                         /* offset */
--                     &MapAddress,               /* addr (IN/OUT) */
--                     cb,                        /* length */
--                     TRUE,                      /* find_space */
--                     fExecutable                /* protection */
--                     ? VM_PROT_ALL
--                     : VM_PROT_RW,
--                     VM_PROT_ALL,               /* max(_prot) */
--                     0);                        /* cow (copy-on-write) */
--    if (rc == KERN_SUCCESS)
-+    while (1)
-     {
--        rc = VINF_SUCCESS;
--
--        for (size_t iPage = 0; iPage < cPages; iPage++)
-+        pPages = vm_phys_alloc_contig(cPages, 0, VmPhysAddrHigh, uAlignment, 0);
-+        if (pPages || tries >= 1)
-+            break;
-+        vm_contig_grow_cache(tries, 0, VmPhysAddrHigh);
-+        tries++;
-+    }
-+    if (!pPages)
-+        return pPages;
-+    VM_OBJECT_LOCK(pObject);
-+    for (vm_pindex_t iPage = 0; iPage < cPages; iPage++)
-+    {
-+        vm_page_t pPage = pPages + iPage;
-+        vm_page_insert(pPage, pObject, iPIndex + iPage);
-+        pPage->valid = VM_PAGE_BITS_ALL;
-+        if (fWire)
-         {
--            vm_page_t   pPage;
-+            pPage->wire_count = 1;
-+            atomic_add_int(&cnt.v_wire_count, 1);
-+        }
-+    }
-+    VM_OBJECT_UNLOCK(pObject);
-+    return pPages;
 +#endif
-+}
- 
--            pPage = vm_page_alloc(NULL, iPage,
--                                  VM_ALLOC_SYSTEM |
--                                  VM_ALLOC_WIRED | VM_ALLOC_NOOBJ);
-+static int FreeBSDPhysAllocHelper(vm_object_t pObject, u_long cPages,
-+                                  vm_paddr_t VmPhysAddrHigh, u_long uAlignment,
-+                                  bool fContiguous, bool fWire)
-+{
-+    if (fContiguous)
-+    {
-+        if (FreeBSDContigPhysAllocHelper(pObject, 0, cPages, VmPhysAddrHigh, uAlignment, fWire) != NULL)
-+            return VINF_SUCCESS;
-+        else
-+            return VERR_NO_MEMORY;
-+    }
- 
--            if (!pPage)
-+    for (vm_pindex_t iPage = 0; iPage < cPages; iPage++)
-+    {
-+        vm_page_t pPage = FreeBSDContigPhysAllocHelper(pObject, iPage, 1, VmPhysAddrHigh, uAlignment, fWire);
-+        if (!pPage)
-+        {
-+            /* Free all allocated pages */
-+            VM_OBJECT_LOCK(pObject);
-+            while (iPage-- > 0)
+             VM_OBJECT_UNLOCK(pMemFreeBSD->pObject);
+             vm_object_deallocate(pMemFreeBSD->pObject);
+             break;
+@@ -263,11 +268,15 @@ static int rtR0MemObjFreeBSDPhysAllocHelper(vm_object_t pObject, u_long cPages,
+             while (iPage-- > 0)
              {
--                /*
--                    * Out of pages
--                    * Remove already allocated pages
--                    */
--                while (iPage-- > 0)
--                {
--                    pPage = pMemFreeBSD->u.Phys.apPages[iPage];
--                    vm_page_lock_queues();
-+                pPage = vm_page_lookup(pObject, iPage);
-+                vm_page_lock_queues();
-+                if (fWire)
+                 pPage = vm_page_lookup(pObject, iPage);
++#if __FreeBSD_version < 900000
+                 vm_page_lock_queues();
++#endif
+                 if (fWire)
                      vm_page_unwire(pPage, 0);
--                    vm_page_free(pPage);
--                    vm_page_unlock_queues();
--                }
--                rc = VERR_NO_MEMORY;
--                break;
-+                vm_page_free(pPage);
-+                vm_page_unlock_queues();
-             }
--
--            pPage->valid = VM_PAGE_BITS_ALL;
--            pMemFreeBSD->u.Phys.apPages[iPage] = pPage;
-+            VM_OBJECT_UNLOCK(pObject);
-+            return VERR_NO_MEMORY;
-         }
-+    }
-+    return VINF_SUCCESS;
-+}
- 
--        if (rc == VINF_SUCCESS)
--        {
--            vm_offset_t AddressDst = MapAddress;
-+static int FreeBSDAllocHelper(PRTR0MEMOBJFREEBSD pMemFreeBSD, bool fExecutable,
-+                              vm_paddr_t VmPhysAddrHigh, bool fContiguous)
-+{
-+    int rc;
-+    size_t cPages = atop(pMemFreeBSD->Core.cb);
- 
--            for (size_t iPage = 0; iPage < cPages; iPage++)
--            {
--                vm_page_t pPage = pMemFreeBSD->u.Phys.apPages[iPage];
-+    pMemFreeBSD->pObject = vm_object_allocate(OBJT_PHYS, cPages);
-+    vm_offset_t MapAddress = vm_map_min(kernel_map);
- 
--                MY_PMAP_ENTER(kernel_map->pmap, AddressDst, pPage,
--                              fExecutable
--                              ? VM_PROT_ALL
--                              : VM_PROT_RW,
--                              TRUE);
-+    // no additional object reference for auto-deallocation upon unmapping
-+    rc = vm_map_find(kernel_map, pMemFreeBSD->pObject, 0,
-+                     &MapAddress, pMemFreeBSD->Core.cb, VMFS_ANY_SPACE,
-+                     fExecutable ? VM_PROT_ALL : VM_PROT_RW, VM_PROT_ALL, 0);
- 
--                AddressDst += PAGE_SIZE;
--            }
-+    if (rc == KERN_SUCCESS)
-+    {
-+        rc = FreeBSDPhysAllocHelper(pMemFreeBSD->pObject, cPages, VmPhysAddrHigh, PAGE_SIZE, fContiguous, false);
-+        if (RT_SUCCESS(rc))
-+        {
-+            vm_map_wire(kernel_map, MapAddress, MapAddress + pMemFreeBSD->Core.cb, VM_MAP_WIRE_SYSTEM|VM_MAP_WIRE_NOHOLES);
- 
-             /* Store start address */
-             pMemFreeBSD->Core.pv = (void *)MapAddress;
--            *ppMem = &pMemFreeBSD->Core;
-             return VINF_SUCCESS;
-         }
--    }
--    rc = VERR_NO_MEMORY; /** @todo fix translation (borrow from darwin) */
- 
--    rtR0MemObjDelete(&pMemFreeBSD->Core);
-+        vm_map_remove(kernel_map, MapAddress, MapAddress + pMemFreeBSD->Core.cb);
-+    }
-+    else
-+    {
-+        rc = VERR_NO_MEMORY; /** @todo fix translation (borrow from darwin) */
-+        vm_object_deallocate(pMemFreeBSD->pObject);
-+    }
-     return rc;
- }
- 
--
--DECLHIDDEN(int) rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
-+DECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
- {
--#ifdef USE_KMEM_ALLOC_ATTR
--    /*
--     * Use kmem_alloc_attr, fExectuable is not needed because the
--     * memory will be executable by default
--     */
--    NOREF(fExecutable);
--
--    /* create the object. */
--    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_LOW, NULL, cb);
-+    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD),
-+                                                                       RTR0MEMOBJTYPE_PAGE, NULL, cb);
-     if (!pMemFreeBSD)
-         return VERR_NO_MEMORY;
- 
--    pMemFreeBSD->Core.pv = (void *)kmem_alloc_attr(kernel_map,          /* Kernel */
--                                                   cb,                  /* Amount */
--                                                   M_ZERO,              /* Zero memory */
--                                                   0,                   /* Low physical address */
--                                                   _4G - PAGE_SIZE,     /* Highest physical address */
--                                                   VM_MEMATTR_DEFAULT); /* Default memory attributes */
--    if (!pMemFreeBSD->Core.pv)
--        return VERR_NO_MEMORY;
--
--    *ppMem = &pMemFreeBSD->Core;
--
--    return VINF_SUCCESS;
--#else
--    /*
--     * Try a Alloc first and see if we get luck, if not try contigmalloc.
--     * Might wish to try find our own pages or something later if this
--     * turns into a problemspot on AMD64 boxes.
--     */
--    int rc = rtR0MemObjNativeAllocPage(ppMem, cb, fExecutable);
--    if (RT_SUCCESS(rc))
-+    int rc = FreeBSDAllocHelper(pMemFreeBSD, fExecutable, ~(vm_paddr_t)0, false);
-+    if (RT_FAILURE(rc))
-     {
--        size_t iPage = cb >> PAGE_SHIFT;
--        while (iPage-- > 0)
--            if (rtR0MemObjNativeGetPagePhysAddr(*ppMem, iPage) > (_4G - PAGE_SIZE))
--            {
--                RTR0MemObjFree(*ppMem, false);
--                *ppMem = NULL;
--                rc = VERR_NO_MEMORY;
--                break;
--            }
-+        rtR0MemObjDelete(&pMemFreeBSD->Core);
-+        return rc;
-     }
--    if (RT_FAILURE(rc))
--        rc = rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable);
-+
-+    *ppMem = &pMemFreeBSD->Core;
-     return rc;
--#endif
- }
- 
- 
--DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
-+DECLHIDDEN(int) rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
- {
--    /* create the object. */
--    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_CONT, NULL, cb);
-+    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD),
-+                                                                       RTR0MEMOBJTYPE_LOW, NULL, cb);
-     if (!pMemFreeBSD)
-         return VERR_NO_MEMORY;
- 
--    /* do the allocation. */
--    pMemFreeBSD->Core.pv = contigmalloc(cb,                   /* size */
--                                        M_IPRTMOBJ,           /* type */
--                                        M_NOWAIT | M_ZERO,    /* flags */
--                                        0,                    /* lowest physical address*/
--                                        _4G-1,                /* highest physical address */
--                                        PAGE_SIZE,            /* alignment. */
--                                        0);                   /* boundary */
--    if (pMemFreeBSD->Core.pv)
-+    int rc = FreeBSDAllocHelper(pMemFreeBSD, fExecutable, _4G - 1, false);
-+    if (RT_FAILURE(rc))
-     {
--        pMemFreeBSD->Core.u.Cont.Phys = vtophys(pMemFreeBSD->Core.pv);
--        *ppMem = &pMemFreeBSD->Core;
--        return VINF_SUCCESS;
-+        rtR0MemObjDelete(&pMemFreeBSD->Core);
-+        return rc;
-     }
- 
--    NOREF(fExecutable);
--    rtR0MemObjDelete(&pMemFreeBSD->Core);
--    return VERR_NO_MEMORY;
-+    *ppMem = &pMemFreeBSD->Core;
-+    return rc;
- }
- 
- 
--static void rtR0MemObjFreeBSDPhysPageInit(vm_page_t pPage, vm_pindex_t iPage)
-+DECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
- {
--    pPage->wire_count = 1;
--    pPage->pindex     = iPage;
--    pPage->act_count  = 0;
--    pPage->oflags     = 0;
--    pPage->flags      = PG_UNMANAGED;
--    atomic_add_int(&cnt.v_wire_count, 1);
-+    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD),
-+                                                                       RTR0MEMOBJTYPE_CONT, NULL, cb);
-+    if (!pMemFreeBSD)
-+        return VERR_NO_MEMORY;
-+
-+    int rc = FreeBSDAllocHelper(pMemFreeBSD, fExecutable, _4G - 1, true);
-+    if (RT_FAILURE(rc))
-+    {
-+        rtR0MemObjDelete(&pMemFreeBSD->Core);
-+        return rc;
-+    }
-+
-+    pMemFreeBSD->Core.u.Cont.Phys = vtophys(pMemFreeBSD->Core.pv);
-+    *ppMem = &pMemFreeBSD->Core;
-+    return rc;
- }
- 
- 
-@@ -405,69 +374,36 @@
-                                            RTHCPHYS PhysHighest, size_t uAlignment,
-                                            bool fContiguous)
- {
--    int        rc = VINF_SUCCESS;
--    uint32_t   cPages = cb >> PAGE_SHIFT;
-+    uint32_t   cPages = atop(cb);
-     vm_paddr_t VmPhysAddrHigh;
- 
-     /* create the object. */
--    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJFREEBSD, u.Phys.apPages[cPages]),
-+    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD),
-                                                                        enmType, NULL, cb);
-     if (!pMemFreeBSD)
-         return VERR_NO_MEMORY;
- 
--    pMemFreeBSD->u.Phys.cPages = cPages;
-+    pMemFreeBSD->pObject = vm_object_allocate(OBJT_PHYS, atop(cb));
- 
-     if (PhysHighest != NIL_RTHCPHYS)
-         VmPhysAddrHigh = PhysHighest;
-     else
-         VmPhysAddrHigh = ~(vm_paddr_t)0;
- 
--    if (fContiguous)
--    {
--        vm_page_t pPage = vm_phys_alloc_contig(cPages, 0, VmPhysAddrHigh, uAlignment, 0);
--
--        if (pPage)
--            for (uint32_t iPage = 0; iPage < cPages; iPage++)
--            {
--                rtR0MemObjFreeBSDPhysPageInit(&pPage[iPage], iPage);
--                pMemFreeBSD->u.Phys.apPages[iPage] = &pPage[iPage];
--            }
--        else
--            rc = VERR_NO_MEMORY;
--    }
--    else
--    {
--        /* Allocate page by page */
--        for (uint32_t iPage = 0; iPage < cPages; iPage++)
--        {
--            vm_page_t pPage = vm_phys_alloc_contig(1, 0, VmPhysAddrHigh, uAlignment, 0);
--
--            if (!pPage)
--            {
--                /* Free all allocated pages */
--                while (iPage-- > 0)
--                {
--                    pPage = pMemFreeBSD->u.Phys.apPages[iPage];
--                    vm_page_lock_queues();
--                    vm_page_unwire(pPage, 0);
--                    vm_page_free(pPage);
--                    vm_page_unlock_queues();
--                }
--                rc = VERR_NO_MEMORY;
--                break;
--            }
--            rtR0MemObjFreeBSDPhysPageInit(pPage, iPage);
--            pMemFreeBSD->u.Phys.apPages[iPage] = pPage;
--        }
--    }
-+    int rc = FreeBSDPhysAllocHelper(pMemFreeBSD->pObject, cPages, VmPhysAddrHigh, uAlignment, fContiguous, true);
- 
--    if (RT_FAILURE(rc))
-+    if (RT_FAILURE(rc)) {
-+        vm_object_deallocate(pMemFreeBSD->pObject);
-         rtR0MemObjDelete(&pMemFreeBSD->Core);
-+    }
-     else
-     {
--        if (enmType == RTR0MEMOBJTYPE_PHYS)
-+        if (fContiguous)
-         {
--            pMemFreeBSD->Core.u.Phys.PhysBase = VM_PAGE_TO_PHYS(pMemFreeBSD->u.Phys.apPages[0]);
-+            Assert(enmType == RTR0MEMOBJTYPE_PHYS);
-+            VM_OBJECT_LOCK(pMemFreeBSD->pObject);
-+            pMemFreeBSD->Core.u.Phys.PhysBase = VM_PAGE_TO_PHYS(vm_page_find_least(pMemFreeBSD->pObject, 0));
-+            VM_OBJECT_UNLOCK(pMemFreeBSD->pObject);
-             pMemFreeBSD->Core.u.Phys.fAllocated = true;
-         }
- 
-@@ -480,42 +416,13 @@
- 
- DECLHIDDEN(int) rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment)
- {
--#if 1
-     return rtR0MemObjFreeBSDAllocPhysPages(ppMem, RTR0MEMOBJTYPE_PHYS, cb, PhysHighest, uAlignment, true);
--#else
--    /* create the object. */
--    PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_CONT, NULL, cb);
--    if (!pMemFreeBSD)
--        return VERR_NO_MEMORY;
--
--    /* do the allocation. */
--    pMemFreeBSD->Core.pv = contigmalloc(cb,                   /* size */
--                                        M_IPRTMOBJ,           /* type */
--                                        M_NOWAIT | M_ZERO,    /* flags */
--                                        0,                    /* lowest physical address*/
--                                        _4G-1,                /* highest physical address */
--                                        uAlignment,           /* alignment. */
--                                        0);                   /* boundary */
--    if (pMemFreeBSD->Core.pv)
--    {
--        pMemFreeBSD->Core.u.Cont.Phys = vtophys(pMemFreeBSD->Core.pv);
--        *ppMem = &pMemFreeBSD->Core;
--        return VINF_SUCCESS;
--    }
--
--    rtR0MemObjDelete(&pMemFreeBSD->Core);
--    return VERR_NO_MEMORY;
--#endif
- }
- 
- 
- DECLHIDDEN(int) rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
- {
--#if 1
-     return rtR0MemObjFreeBSDAllocPhysPages(ppMem, RTR0MEMOBJTYPE_PHYS_NC, cb, PhysHighest, PAGE_SIZE, false);
--#else
--    return VERR_NOT_SUPPORTED;
--#endif
- }
- 
- 
-@@ -625,49 +532,41 @@
-     if (!pMemFreeBSD)
-         return VERR_NO_MEMORY;
- 
--    /*
--     * Allocate an empty VM object and map it into the requested map.
--     */

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
_______________________________________________
svn-ports-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-ports-all
To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
Comment 10 Bernhard Froehlich freebsd_committer freebsd_triage 2013-01-03 13:45:28 UTC
State Changed
From-To: open->closed

Committed. Thanks!