[Pkg-virtualbox-commits] [virtualbox] 01/03: Imported Upstream version 4.3.36-dfsg

Gianfranco Costamagna locutusofborg-guest at moszumanska.debian.org
Tue Jan 26 10:12:50 UTC 2016


This is an automated email from the git hooks/post-receive script.

locutusofborg-guest pushed a commit to branch jessie
in repository virtualbox.

commit 2a79299fc98cde2047ce66321482fd1563d2cca5
Author: Gianfranco Costamagna <costamagnagianfranco at yahoo.it>
Date:   Tue Jan 26 11:07:51 2016 +0100

    Imported Upstream version 4.3.36-dfsg
---
 Config.kmk                                         |   9 +-
 doc/manual/user_ChangeLogImpl.xml                  |  63 +++-
 include/iprt/initterm.h                            |   3 +
 src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp  |   2 +
 src/VBox/Additions/linux/drm/vboxvideo_drm.c       |  24 +-
 src/VBox/Additions/linux/installer/autorun.sh      |  17 +-
 src/VBox/Additions/linux/sharedfolders/lnkops.c    |  50 ++-
 src/VBox/Additions/x11/undefined_xorg              |   1 +
 src/VBox/Additions/x11/vboxvideo/Makefile.kmk      |  18 +-
 .../Graphics/BIOS/VBoxVgaBiosAlternative.asm       |   6 +-
 .../Graphics/BIOS/VBoxVgaBiosAlternative.md5sum    |   2 +-
 src/VBox/Devices/Graphics/BIOS/ose_logo.bmp        | Bin 630 -> 630 bytes
 src/VBox/Devices/PC/BIOS/VBoxBiosAlternative.asm   |   4 +-
 .../Devices/PC/BIOS/VBoxBiosAlternative.md5sum     |   2 +-
 .../Frontends/VBoxManage/VBoxInternalManage.cpp    |   2 +-
 .../Frontends/VirtualBox/src/runtime/UISession.cpp | 172 ++++++---
 .../OpenGL/state_tracker/state_framebuffer.c       |  18 +-
 src/VBox/GuestHost/OpenGL/util/vboxhgcm.c          |   7 +
 .../Support/win/SUPHardenedVerifyImage-win.cpp     |  16 +
 .../Support/win/SUPR3HardenedMain-win.cpp          |  26 +-
 .../VBoxNetFlt/linux/VBoxNetFlt-linux.c            |  25 +-
 src/VBox/HostServices/GuestProperties/service.cpp  |   5 +-
 src/VBox/Installer/common/virtualbox.desktop.in    |   4 +-
 src/VBox/Installer/linux/rpm/rules                 |   2 +-
 src/VBox/Installer/win/Stub/Makefile.kmk           |  42 ++-
 src/VBox/Installer/win/Stub/VBoxStub.cpp           |  25 +-
 src/VBox/Installer/win/Stub/crypt32.def            |  25 ++
 src/VBox/Installer/win/Stub/msi.def                |  23 ++
 src/VBox/Installer/win/Stub/shell32.def            |  22 ++
 src/VBox/Installer/win/Stub/user32.def             |  23 ++
 src/VBox/Installer/win/Stub/ws2_32.def             |  22 ++
 src/VBox/Main/src-all/ExtPackManagerImpl.cpp       |  21 ++
 src/VBox/Main/src-client/ConsoleImpl2.cpp          |   6 +-
 src/VBox/Runtime/Makefile.kmk                      |   4 +-
 src/VBox/Runtime/common/ldr/ldrEx.cpp              |  23 ++
 src/VBox/Runtime/common/ldr/ldrPE.cpp              |  19 +-
 src/VBox/Runtime/generic/critsectrw-generic.cpp    |  55 ++-
 src/VBox/Runtime/include/internal/ldr.h            |   1 +
 src/VBox/Runtime/r3/darwin/mp-darwin.cpp           |   6 +
 src/VBox/Runtime/r3/init.cpp                       |  11 +-
 src/VBox/Runtime/r3/init.h                         |   2 +-
 src/VBox/Runtime/r3/linux/sched-linux.cpp          |   2 +-
 src/VBox/Runtime/r3/posix/sched-posix.cpp          |   2 +-
 .../Runtime/r3/win/RTSystemQueryOSInfo-win.cpp     |   4 +
 src/VBox/Runtime/r3/win/init-win.cpp               |  54 ++-
 src/VBox/Runtime/r3/win/internal-r3-win.h          |  26 +-
 src/VBox/Runtime/r3/win/ldrNative-win.cpp          |   6 +
 src/VBox/Storage/testcase/vbox-img.cpp             |   2 +-
 src/VBox/VMM/VMMR0/GVMMR0.cpp                      | 223 ++++++-----
 src/VBox/VMM/VMMR3/VMReq.cpp                       |   4 +-
 src/bldprogs/Makefile.kmk                          |   3 +
 src/bldprogs/VBoxCheckImports.cpp                  | 371 ++++++++++++++++++
 src/bldprogs/VBoxDef2LazyLoad.cpp                  | 419 +++++++++++++++------
 src/libs/Makefile.kmk                              |   6 +-
 .../xptcall/src/md/unix/xptcstubs_gcc_x86_unix.cpp |   2 +
 55 files changed, 1567 insertions(+), 365 deletions(-)

diff --git a/Config.kmk b/Config.kmk
index f421d92..6bb58bb 100644
--- a/Config.kmk
+++ b/Config.kmk
@@ -208,7 +208,7 @@ VBOX_VERSION_MINOR = 3
 # This is the current build number. It should be increased every time we publish a
 # new build. The define is available in every source file. Only even build numbers
 # will be published, odd numbers are set during development.
-VBOX_VERSION_BUILD = 34
+VBOX_VERSION_BUILD = 36
 # The raw version string. This *must not* contain any other information/fields than
 # major, minor and build revision (as it is now) -- also will be used for host/guest version
 # comparison.
@@ -1864,6 +1864,9 @@ VBOX_MAKE_ALTERNATIVE_SOURCE ?= $(PATH_OBJ)/MakeAlternativeSource/MakeAlternativ
 # VBoxDef2LazyLoad (lazy dynamic library loader assembly generator)
 VBOX_DEF_2_LAZY_LOAD ?= $(PATH_OBJ)/VBoxDef2LazyLoad/VBoxDef2LazyLoad$(HOSTSUFF_EXE)
 
+# VBoxCheckImports (checks what we imports from on windows)
+VBOX_CHECK_IMPORTS ?= $(PATH_OBJ)/VBoxCheckImports/VBoxCheckImports$(HOSTSUFF_EXE)
+
 # GNU tar if present.
 if1of ($(KBUILD_TARGET), linux os2 win)
  VBOX_GTAR ?= tar
@@ -2866,7 +2869,7 @@ SDK_VBOX_LIBXML2_DEFS.win += WIN32 _WINDOWS _MBCS
 # libxml against VBoxRT
 
 SDK_VBOX_LIBPNG       = .
-SDK_VBOX_LIBPNG_INCS ?= $(PATH_ROOT)/src/libs/libpng-1.2.53
+SDK_VBOX_LIBPNG_INCS ?= $(PATH_ROOT)/src/libs/libpng-1.2.54
 SDK_VBOX_LIBPNG_LIBS ?= $(PATH_STAGE_LIB)/VBox-libpng$(VBOX_SUFF_LIB)
 
 SDK_VBOX_ZLIB         = .
@@ -5734,7 +5737,7 @@ endif
 SVN                    ?= svn$(HOSTSUFF_EXE)
 VBOX_SVN_REV_KMK        = $(PATH_OUT)/revision.kmk
 ifndef VBOX_SVN_REV
- VBOX_SVN_REV_FALLBACK := $(patsubst %:,,  $Rev: 104062 $  )
+ VBOX_SVN_REV_FALLBACK := $(patsubst %:,,  $Rev: 105129 $  )
  VBOX_SVN_DEP          := $(firstword $(wildcard $(PATH_ROOT)/.svn/wc.db $(abspath $(PATH_ROOT)/../.svn/wc.db) $(abspath $(PATH_ROOT)/../../.svn/wc.db) $(PATH_ROOT)/.svn/entries))
  ifeq ($(which $(SVN)),)
   VBOX_SVN_DEP         :=
diff --git a/doc/manual/user_ChangeLogImpl.xml b/doc/manual/user_ChangeLogImpl.xml
index c7839b5..df3b899 100644
--- a/doc/manual/user_ChangeLogImpl.xml
+++ b/doc/manual/user_ChangeLogImpl.xml
@@ -1,6 +1,67 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
   <sect1>
+    <title>Version 4.3.36 (201x-xx-xx)</title>
+
+    <para>This is a maintenance release. The following items were fixed and/or
+      added:</para>
+
+    <itemizedlist>
+
+      <listitem>
+        <para>GUI: improved handling of text selection mouse pointer (bug #750)</para>
+      </listitem>
+      
+      <listitem>
+        <para>GUI: properly limit the number of VCPUs to the number of physical
+          cores on Mac OS X (bug #15018)</para>
+      </listitem>
+
+      <listitem>
+        <para>3D: fixed state handling under certain conditions (bug #13487)</para>
+      </listitem>
+
+      <listitem>
+        <para>Host services: fixed a crash during VM shutdown under rare
+          conditions (4.3.32 regression; bug #14841)</para>
+      </listitem>
+
+      <listitem>
+        <para>ExtPack: black-list Extension Packs older than 4.3.30 due to
+          incompatible changes not being properly handled in the past</para>
+      </listitem>
+
+      <listitem>
+        <para>Linux hosts: .desktop file compatibility issue (bug #14808)</para>
+      </listitem>
+
+      <listitem>
+        <para>Linux hosts / guests: fixes for RHEL 7.2 (bug #14866)</para>
+      </listitem>
+
+      <listitem>
+        <para>Linux/Mac OS X hosts: fixed a VM hang during startup under certain
+          circumstances (bug #14933)</para>
+      </listitem>
+
+      <listitem>
+        <para>Linux Additions: prevent the compiler from doing dead-code
+          elemination on vital code in guest / host communication (bug #14497)</para>
+      </listitem>
+
+      <listitem>
+        <para>Linux Additions: fixes for Linux 4.5 (bug #15032)</para>
+      </listitem>
+
+      <listitem>
+        <para>X11 Additions: added basic support for X.Org Server 1.18 (3D
+          requires additional fixes)</para>
+      </listitem>
+
+    </itemizedlist>
+  </sect1>
+
+  <sect1>
     <title>Version 4.3.34 (2015-11-10)</title>
 
     <para>This is a maintenance release. The following items were fixed and/or
@@ -15,7 +76,7 @@
       <listitem>
         <para>NAT Network: fixed sporadic crashes on Windows hosts (bug #13899)</para>
       </listitem>
-      
+
       <listitem>
         <para>USB: fixed a crash under certain conditions on hosts with Linux
           kernels older than version 3.3</para>
diff --git a/include/iprt/initterm.h b/include/iprt/initterm.h
index 47d1823..c8d497c 100644
--- a/include/iprt/initterm.h
+++ b/include/iprt/initterm.h
@@ -50,6 +50,9 @@ RT_C_DECLS_BEGIN
 #define RTR3INIT_FLAGS_UNOBTRUSIVE  RT_BIT(2)
 /** The caller ensures that the argument bector is UTF-8. */
 #define RTR3INIT_FLAGS_UTF8_ARGV    RT_BIT(3)
+/** Indicates that this is a standalone application without any additional
+ * shared libraries in the application directory. Mainly windows loader mess. */
+#define RTR3INIT_FLAGS_STANDALONE_APP RT_BIT(4)
 /** @} */
 
 /** @name RTR3InitEx version
diff --git a/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp b/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp
index 776fba9..757244c 100644
--- a/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp
+++ b/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp
@@ -169,6 +169,8 @@ RTDECL(int) VBoxHGSMIBufferSubmit(PHGSMIGUESTCOMMANDCONTEXT pCtx,
     {
         /* Submit the buffer to the host. */
         VBoxVideoCmnPortWriteUlong(pCtx->port, offBuffer);
+        /* Make the compiler aware that the host has changed memory. */
+        ASMCompilerBarrier();
         return VINF_SUCCESS;
     }
 
diff --git a/src/VBox/Additions/linux/drm/vboxvideo_drm.c b/src/VBox/Additions/linux/drm/vboxvideo_drm.c
index ca5b2b7..9cad3c8 100644
--- a/src/VBox/Additions/linux/drm/vboxvideo_drm.c
+++ b/src/VBox/Additions/linux/drm/vboxvideo_drm.c
@@ -104,6 +104,26 @@
 # define DRM_NEW_BUS_INIT 1
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
+# ifdef RHEL_RELEASE_CODE
+#  if RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(7, 2)
+#   define DRM_HAVE_DRM_MAP
+#  endif
+# else
+#  define DRM_HAVE_DRM_MAP
+# endif
+#endif
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
+# define DRM_WANTS_SET_BUSID
+#else
+# ifdef RHEL_RELEASE_CODE
+#  if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 2)
+#   define DRM_WANTS_SET_BUSID
+#  endif
+# endif
+#endif
+
 static struct pci_device_id pciidlist[] = {
         vboxvideo_PCI_IDS
 };
@@ -122,7 +142,7 @@ static struct file_operations driver_fops =
         .open = drm_open,
         .release = drm_release,
         .unlocked_ioctl = drm_ioctl,
-# if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
+# ifdef DRM_HAVE_DRM_MAP
         /* This shouldn't be necessary even for old kernels as there is
          * nothing sensible to mmap. But we play safe and keep it for
          * legacy reasons. */
@@ -144,7 +164,7 @@ static struct drm_driver driver =
     .get_map_ofs = drm_core_get_map_ofs,
     .get_reg_ofs = drm_core_get_reg_ofs,
 #endif
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
+#ifdef DRM_WANTS_SET_BUSID
     /* If this is missing a warning gets printed to dmesg.  We will not
      * attempt to make kernels work to which the change (915b4d11b) got back-
      * ported, as the problem is only cosmetic. */
diff --git a/src/VBox/Additions/linux/installer/autorun.sh b/src/VBox/Additions/linux/installer/autorun.sh
index 45afb03..e14e277 100755
--- a/src/VBox/Additions/linux/installer/autorun.sh
+++ b/src/VBox/Additions/linux/installer/autorun.sh
@@ -111,6 +111,11 @@ elif test "$ostype" = "SunOS"; then
         fi
 
         # create temporary admin file for autoinstall
+        TMPFILE=`mktemp -q /tmp/vbox.XXXXXX`
+        if [ -z $TMPFILE ]; then
+            echo "Unable to create a temporary file"
+            exit 1
+        fi
         echo "basedir=default
 runlevel=nocheck
 conflict=quit
@@ -122,27 +127,27 @@ idepend=quit
 rdepend=quit
 space=quit
 mail=
-" > /tmp/vbox.autoinstall
+" > $TMPFILE
 
         # check gnome-terminal, use it if it exists.
         if test -f "/usr/bin/gnome-terminal"; then
             # use su/pfexec
             if test -z "$subin"; then
-                /usr/bin/gnome-terminal --title "Installing VirtualBox Additions" --command "/bin/sh -c '$pfexecbin $pkgaddbin -G -d $installfile -n -a /tmp/vbox.autoinstall SUNWvboxguest; /bin/echo press ENTER to close this window; /bin/read; /bin/rm -f /tmp/vbox.autoinstall'"
+                /usr/bin/gnome-terminal --title "Installing VirtualBox Additions" --command "/bin/sh -c '$pfexecbin $pkgaddbin -G -d $installfile -n -a $TMPFILE SUNWvboxguest; /bin/echo press ENTER to close this window; /bin/read'"
             else
-                /usr/bin/gnome-terminal --title "Installing VirtualBox Additions: Root password required." --command "/bin/sh -c '$subin - root -c \"$pkgaddbin -G -d $installfile -n -a /tmp/vbox.autoinstall SUNWvboxguest\"; /bin/echo press ENTER to close this window; /bin/read; /bin/rm -f /tmp/vbox.autoinstall'"
+                /usr/bin/gnome-terminal --title "Installing VirtualBox Additions: Root password required." --command "/bin/sh -c '$subin - root -c \"$pkgaddbin -G -d $installfile -n -a $TMPFILE SUNWvboxguest\"; /bin/echo press ENTER to close this window; /bin/read'"
             fi
         elif test -f "/usr/X11/bin/xterm"; then
             # use xterm
             if test -z "$subin"; then
-                /usr/X11/bin/xterm -title "Installing VirtualBox Additions" -e "$pfexecbin $pkgaddbin -G -d $installfile -n -a /tmp/vbox.autoinstall SUNWvboxguest; /bin/echo press ENTER to close this window; /bin/read; /bin/rm -f /tmp/vbox.autoinstall"
+                /usr/X11/bin/xterm -title "Installing VirtualBox Additions" -e "$pfexecbin $pkgaddbin -G -d $installfile -n -a $TMPFILE SUNWvboxguest; /bin/echo press ENTER to close this window; /bin/read"
             else
-                /usr/X11/bin/xterm -title "Installing VirtualBox Additions: Root password required." -e "$subin - root -c \"$pkgaddbin -G -d $installfile -n -a /tmp/vbox.autoinstall SUNWvboxguest\"; /bin/echo press ENTER to close this window; /bin/read; /bin/rm -f /tmp/vbox.autoinstall"
+                /usr/X11/bin/xterm -title "Installing VirtualBox Additions: Root password required." -e "$subin - root -c \"$pkgaddbin -G -d $installfile -n -a $TMPFILE SUNWvboxguest\"; /bin/echo press ENTER to close this window; /bin/read"
             fi
         else
             echo "No suitable terminal not found. -- install additions using pkgadd -d."
-            rm -f /tmp/vbox.autoinstall
         fi
+        rm -r $TMPFILE
 
         exit 0
     fi
diff --git a/src/VBox/Additions/linux/sharedfolders/lnkops.c b/src/VBox/Additions/linux/sharedfolders/lnkops.c
index 9ac005f..0705951 100644
--- a/src/VBox/Additions/linux/sharedfolders/lnkops.c
+++ b/src/VBox/Additions/linux/sharedfolders/lnkops.c
@@ -20,11 +20,12 @@
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
 
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+# if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
+#  if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
 static const char *sf_follow_link(struct dentry *dentry, void **cookie)
-# else
+#  else
 static void *sf_follow_link(struct dentry *dentry, struct nameidata *nd)
-# endif
+#  endif
 {
     struct inode *inode = dentry->d_inode;
     struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
@@ -44,32 +45,61 @@ static void *sf_follow_link(struct dentry *dentry, struct nameidata *nd)
             error = -EPROTO;
         }
     }
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
+#  if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
     return error ? ERR_PTR(error) : (*cookie = path);
-# else
+#  else
     nd_set_link(nd, error ? ERR_PTR(error) : path);
     return NULL;
-# endif
+#  endif
 }
 
-# if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
+#  if LINUX_VERSION_CODE < KERNEL_VERSION(4, 2, 0)
 static void sf_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
 {
     char *page = nd_get_link(nd);
     if (!IS_ERR(page))
         free_page((unsigned long)page);
 }
-#endif
+#  endif
+
+# else /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) */
+static const char *sf_get_link(struct dentry *dentry, struct inode *inode,
+                               struct delayed_call *done)
+{
+    struct sf_glob_info *sf_g = GET_GLOB_INFO(inode->i_sb);
+    struct sf_inode_info *sf_i = GET_INODE_INFO(inode);
+    char *path;
+    int rc;
+
+    if (!dentry)
+        return ERR_PTR(-ECHILD);
+    path = kzalloc(PAGE_SIZE, GFP_KERNEL);
+    if (!path)
+        return ERR_PTR(-ENOMEM);
+    rc = VbglR0SfReadLink(&client_handle, &sf_g->map, sf_i->path, PATH_MAX, path);
+    if (RT_FAILURE(rc))
+    {
+        LogFunc(("VbglR0SfReadLink failed, caller=%s, rc=%Rrc\n", __func__, rc));
+        kfree(path);
+        return ERR_PTR(-EPROTO);
+    }
+    set_delayed_call(done, kfree_link, path);
+    return path;
+}
+# endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0) */
 
 struct inode_operations sf_lnk_iops =
 {
     .readlink       = generic_readlink,
+# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
+    .get_link       = sf_get_link
+# elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
     .follow_link    = sf_follow_link,
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
     .put_link       = free_page_put_link,
 # else
+    .follow_link    = sf_follow_link,
     .put_link       = sf_put_link
 # endif
 };
 
-#endif
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) */
diff --git a/src/VBox/Additions/x11/undefined_xorg b/src/VBox/Additions/x11/undefined_xorg
index ea788cf..2cf64ef 100644
--- a/src/VBox/Additions/x11/undefined_xorg
+++ b/src/VBox/Additions/x11/undefined_xorg
@@ -178,4 +178,5 @@ xf86SetDesiredModes
 xf86SetModeDefaultName
 xf86SetSingleMode
 xf86UpdateDesktopDimensions
+XNFcallocarray
 __xstat64
diff --git a/src/VBox/Additions/x11/vboxvideo/Makefile.kmk b/src/VBox/Additions/x11/vboxvideo/Makefile.kmk
index 2468aac..4647c7b 100644
--- a/src/VBox/Additions/x11/vboxvideo/Makefile.kmk
+++ b/src/VBox/Additions/x11/vboxvideo/Makefile.kmk
@@ -19,7 +19,7 @@ SUB_DEPTH = ../../../../..
 include $(KBUILD_PATH)/subheader.kmk
 
 vboxvideo_70_DEFS := \
-	IN_MODULE XORG_7X RENDER=1 IN_RT_STATIC
+	IN_MODULE XORG_7X RENDER=1 IN_RT_STATIC X_BYTE_ORDER=X_LITTLE_ENDIAN
 ifeq ($(KBUILD_TARGET),solaris) # don't use .solaris or anything here.
  vboxvideo_70_DEFS += __EXTENSIONS__  ## @todo Why this?
 endif
@@ -382,6 +382,20 @@ vboxvideo_drv_117_INCS = \
 vboxvideo_drv_117_INCS += $(PATH_ROOT)/src/VBox/Runtime/include
 vboxvideo_drv_117_SOURCES := $(vboxvideo_drv_17_SOURCES)
 
+
+#
+# vboxvideo_drv_118
+#
+DLLS += vboxvideo_drv_118
+vboxvideo_drv_118_TEMPLATE = VBOXGUESTR3XORGMOD
+vboxvideo_drv_118_CFLAGS := $(vboxvideo_drv_70_CFLAGS)
+vboxvideo_drv_118_DEFS := $(vboxvideo_15_DEFS) XORG_VERSION_CURRENT=11800000
+vboxvideo_drv_118_INCS = \
+	$(vboxvideo_xorg_INCS) \
+	$(VBOX_PATH_X11_ROOT)/xorg-server-1.18.0
+vboxvideo_drv_118_INCS += $(PATH_ROOT)/src/VBox/Runtime/include
+vboxvideo_drv_118_SOURCES := $(vboxvideo_drv_17_SOURCES)
+
 ifdef VBOX_USE_SYSTEM_XORG_HEADERS
  # Build using local X.Org headers.  We assume X.Org Server 1.7 or later.
  DLLS    := $(filter-out vboxvideo_drv_%,$(DLLS)) vboxvideo_drv_system
@@ -435,7 +449,7 @@ $$(vboxvideo_drv_0_OUTDIR)/tstvboxvideo68.run: $$(vboxvideo_drv_1_STAGE_TARGET)
 	$$(QUIET)$$(APPEND) -t "$$@" "done"
     endef
 
-    $(foreach ver, _70 _71 _13 _14 _15 _16 _17 _18 _19 _110 _111 _112 _113 _114 _115 _116 _117, $(eval $(def_vboxvideo_test)))
+    $(foreach ver, _70 _71 _13 _14 _15 _16 _17 _18 _19 _110 _111 _112 _113 _114 _115 _116 _117 _118, $(eval $(def_vboxvideo_test)))
 
     endif # ! VBOX_ONLY_SDK
    endif # eq ($(KBUILD_HOST_ARCH),$(KBUILD_TARGET_ARCH))
diff --git a/src/VBox/Devices/Graphics/BIOS/VBoxVgaBiosAlternative.asm b/src/VBox/Devices/Graphics/BIOS/VBoxVgaBiosAlternative.asm
index 39101db..fcb4d9b 100644
--- a/src/VBox/Devices/Graphics/BIOS/VBoxVgaBiosAlternative.asm
+++ b/src/VBox/Devices/Graphics/BIOS/VBoxVgaBiosAlternative.asm
@@ -6779,7 +6779,7 @@ vesa_pm_end:                                 ; 0xc4714 LB 0x1
 
 section _DATA progbits vstart=0x4800 align=1 ; size=0x36e1 class=DATA group=DGROUP
 _msg_vga_init:                               ; 0xc4800 LB 0x2f
-    db  'Oracle VM VirtualBox Version 4.3.34 VGA BIOS', 00dh, 00ah, 000h
+    db  'Oracle VM VirtualBox Version 4.3.36 VGA BIOS', 00dh, 00ah, 000h
 _vga_modes:                                  ; 0xc482f LB 0x80
     db  000h, 000h, 000h, 004h, 000h, 0b8h, 0ffh, 002h, 001h, 000h, 000h, 004h, 000h, 0b8h, 0ffh, 002h
     db  002h, 000h, 000h, 004h, 000h, 0b8h, 0ffh, 002h, 003h, 000h, 000h, 004h, 000h, 0b8h, 0ffh, 002h
@@ -7667,7 +7667,7 @@ _vbebios_vendor_name:                        ; 0xc7e35 LB 0x13
 _vbebios_product_name:                       ; 0xc7e48 LB 0x21
     db  'Oracle VM VirtualBox VBE Adapter', 000h
 _vbebios_product_revision:                   ; 0xc7e69 LB 0x24
-    db  'Oracle VM VirtualBox Version 4.3.34', 000h
+    db  'Oracle VM VirtualBox Version 4.3.36', 000h
 _vbebios_info_string:                        ; 0xc7e8d LB 0x2b
     db  'VirtualBox VBE Display Adapter enabled', 00dh, 00ah, 00dh, 00ah, 000h
 _no_vbebios_info_string:                     ; 0xc7eb8 LB 0x29
@@ -7698,4 +7698,4 @@ section CONST2 progbits vstart=0x7ee2 align=1 ; size=0x0 class=DATA group=DGROUP
     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
     db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h
-    db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 058h
+    db  000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 000h, 054h
diff --git a/src/VBox/Devices/Graphics/BIOS/VBoxVgaBiosAlternative.md5sum b/src/VBox/Devices/Graphics/BIOS/VBoxVgaBiosAlternative.md5sum
index 6f14759..665e6f5 100644
--- a/src/VBox/Devices/Graphics/BIOS/VBoxVgaBiosAlternative.md5sum
+++ b/src/VBox/Devices/Graphics/BIOS/VBoxVgaBiosAlternative.md5sum
@@ -1 +1 @@
-138999b9d7e5869585864ee28a6acf44 *VBoxVgaBios.rom
+7959bedada4fa3a27a806ad7c721ac85 *VBoxVgaBios.rom
diff --git a/src/VBox/Devices/Graphics/BIOS/ose_logo.bmp b/src/VBox/Devices/Graphics/BIOS/ose_logo.bmp
index ae14b83..a4d5008 100644
Binary files a/src/VBox/Devices/Graphics/BIOS/ose_logo.bmp and b/src/VBox/Devices/Graphics/BIOS/ose_logo.bmp differ
diff --git a/src/VBox/Devices/PC/BIOS/VBoxBiosAlternative.asm b/src/VBox/Devices/PC/BIOS/VBoxBiosAlternative.asm
index 4322ef9..ae616cd 100644
--- a/src/VBox/Devices/PC/BIOS/VBoxBiosAlternative.asm
+++ b/src/VBox/Devices/PC/BIOS/VBoxBiosAlternative.asm
@@ -965,7 +965,7 @@ section CONST progbits vstart=0xb0 align=1 ; size=0xcf8 class=DATA group=DGROUP
 
 section CONST2 progbits vstart=0xda8 align=1 ; size=0x3fa class=DATA group=DGROUP
 _bios_cvs_version_string:                    ; 0xf0da8 LB 0x12
-    db  'VirtualBox 4.3.34', 000h
+    db  'VirtualBox 4.3.36', 000h
 _bios_prefix_string:                         ; 0xf0dba LB 0x8
     db  'BIOS: ', 000h, 000h
 _isotag:                                     ; 0xf0dc2 LB 0x6
@@ -16070,4 +16070,4 @@ dummy_iret:                                  ; 0xfff53 LB 0x9d
     db  'XM'
 cpu_reset:                                   ; 0xffff0 LB 0x10
     jmp far 0f000h:0e05bh                     ; ea 5b e0 00 f0
-    db  030h, 036h, 02fh, 032h, 033h, 02fh, 039h, 039h, 000h, 0fch, 0feh
+    db  030h, 036h, 02fh, 032h, 033h, 02fh, 039h, 039h, 000h, 0fch, 0fch
diff --git a/src/VBox/Devices/PC/BIOS/VBoxBiosAlternative.md5sum b/src/VBox/Devices/PC/BIOS/VBoxBiosAlternative.md5sum
index 7975320..1fb8b71 100644
--- a/src/VBox/Devices/PC/BIOS/VBoxBiosAlternative.md5sum
+++ b/src/VBox/Devices/PC/BIOS/VBoxBiosAlternative.md5sum
@@ -1 +1 @@
-a98983b2e1367f7a32369c8a8c3b3ef9 *VBoxPcBios.rom
+3e7ca7deef30df22fe0d644c2bef3c45 *VBoxPcBios.rom
diff --git a/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp b/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
index b8ac4f4..d29728a 100644
--- a/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
+++ b/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
@@ -181,7 +181,7 @@ void printUsageInternal(USAGECATEGORY u64Cmd, PRTSTREAM pStrm)
         ? "  createrawvmdk -filename <filename> -rawdisk <diskname>\n"
           "                [-partitions <list of partition numbers> [-mbr <filename>] ]\n"
           "                [-relative]\n"
-          "       Creates a new VMDK image which gives access to an entite host disk (if\n"
+          "       Creates a new VMDK image which gives access to an entire host disk (if\n"
           "       the parameter -partitions is not specified) or some partitions of a\n"
           "       host disk. If access to individual partitions is granted, then the\n"
           "       parameter -mbr can be used to specify an alternative MBR to be used\n"
diff --git a/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp b/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
index 1566e8e..b6a2ed1 100644
--- a/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
+++ b/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
@@ -1284,6 +1284,103 @@ WId UISession::winId() const
     return mainMachineWindow()->winId();
 }
 
+/** Generate a BGRA bitmap which approximates a XOR/AND mouse pointer.
+ *
+ * Pixels which has 1 in the AND mask and not 0 in the XOR mask are replaced by
+ * the inverted pixel and 8 surrounding pixels with the original color.
+ * Fort example a white pixel (W) is replaced with a black (B) pixel:
+ *         WWW
+ *  W   -> WBW
+ *         WWW
+ * The surrounding pixels are written only if the corresponding source pixel
+ * does not affect the screen, i.e. AND bit is 1 and XOR value is 0.
+ */
+static void renderCursorPixels(const uint32_t *pu32XOR, const uint8_t *pu8AND,
+                               uint32_t u32Width, uint32_t u32Height,
+                               uint32_t *pu32Pixels, uint32_t cbPixels)
+{
+    /* Output pixels set to 0 which allow to not write transparent pixels anymore. */
+    memset(pu32Pixels, 0, cbPixels);
+
+    const uint32_t *pu32XORSrc = pu32XOR;  /* Iterator for source XOR pixels. */
+    const uint8_t *pu8ANDSrcLine = pu8AND; /* The current AND mask scanline. */
+    uint32_t *pu32Dst = pu32Pixels;        /* Iterator for all destination BGRA pixels. */
+
+    /* Some useful constants. */
+    const int cbANDLine = ((int)u32Width + 7) / 8;
+
+    int y;
+    for (y = 0; y < (int)u32Height; ++y)
+    {
+        int x;
+        for (x = 0; x < (int)u32Width; ++x)
+        {
+            const uint32_t u32Pixel = *pu32XORSrc; /* Current pixel at (x,y) */
+            const uint8_t *pu8ANDSrc = pu8ANDSrcLine + x / 8; /* Byte which containt current AND bit. */
+
+            if ((*pu8ANDSrc << (x % 8)) & 0x80)
+            {
+                if (u32Pixel)
+                {
+                    const uint32_t u32PixelInverted = ~u32Pixel;
+
+                    /* Scan neighbor pixels and assign them if they are transparent. */
+                    int dy;
+                    for (dy = -1; dy <= 1; ++dy)
+                    {
+                        const int yn = y + dy;
+                        if (yn < 0 || yn >= (int)u32Height)
+                            continue; /* Do not cross the bounds. */
+
+                        int dx;
+                        for (dx = -1; dx <= 1; ++dx)
+                        {
+                            const int xn = x + dx;
+                            if (xn < 0 || xn >= (int)u32Width)
+                                continue;  /* Do not cross the bounds. */
+
+                            if (dx != 0 || dy != 0)
+                            {
+                                /* Check if the neighbor pixel is transparent. */
+                                const uint32_t *pu32XORNeighborSrc = &pu32XORSrc[dy * (int)u32Width + dx];
+                                const uint8_t *pu8ANDNeighborSrc = pu8ANDSrcLine + dy * cbANDLine + xn / 8;
+                                if (   *pu32XORNeighborSrc == 0
+                                    && ((*pu8ANDNeighborSrc << (xn % 8)) & 0x80) != 0)
+                                {
+                                    /* Transparent neighbor pixels are replaced with the source pixel value. */
+                                    uint32_t *pu32PixelNeighborDst = &pu32Dst[dy * (int)u32Width + dx];
+                                    *pu32PixelNeighborDst = u32Pixel | 0xFF000000;
+                                }
+                            }
+                            else
+                            {
+                                /* The pixel itself is replaced with inverted value. */
+                                *pu32Dst = u32PixelInverted | 0xFF000000;
+                            }
+                        }
+                    }
+                }
+                else
+                {
+                    /* The pixel does not affect the screen.
+                     * Do nothing. Do not touch destination which can already contain generated pixels.
+                     */
+                }
+            }
+            else
+            {
+                /* AND bit is 0, the pixel will be just drawn. */
+                *pu32Dst = u32Pixel | 0xFF000000;
+            }
+
+            ++pu32XORSrc; /* Next source pixel. */
+            ++pu32Dst;    /* Next destination pixel. */
+        }
+
+        /* Next AND scanline. */
+        pu8ANDSrcLine += cbANDLine;
+    }
+}
 void UISession::setPointerShape(const uchar *pShapeData, bool fHasAlpha,
                                 uint uXHot, uint uYHot, uint uWidth, uint uHeight)
 {
@@ -1432,39 +1529,15 @@ void UISession::setPointerShape(const uchar *pShapeData, bool fHasAlpha,
 
         XcursorPixel *dstShapePtr = img->pixels;
 
-        for (uint y = 0; y < uHeight; y ++)
+        if (fHasAlpha)
         {
-            memcpy (dstShapePtr, srcShapePtr, srcShapePtrScan);
-
-            if (!fHasAlpha)
-            {
-                /* Convert AND mask to the alpha channel: */
-                uchar byte = 0;
-                for (uint x = 0; x < uWidth; x ++)
-                {
-                    if (!(x % 8))
-                        byte = *(srcAndMaskPtr ++);
-                    else
-                        byte <<= 1;
-
-                    if (byte & 0x80)
-                    {
-                        /* Linux doesn't support inverted pixels (XOR ops,
-                         * to be exact) in cursor shapes, so we detect such
-                         * pixels and always replace them with black ones to
-                         * make them visible at least over light colors */
-                        if (dstShapePtr [x] & 0x00FFFFFF)
-                            dstShapePtr [x] = 0xFF000000;
-                        else
-                            dstShapePtr [x] = 0x00000000;
-                    }
-                    else
-                        dstShapePtr [x] |= 0xFF000000;
-                }
-            }
-
-            srcShapePtr += srcShapePtrScan;
-            dstShapePtr += uWidth;
+            memcpy(dstShapePtr, srcShapePtr, uHeight * srcShapePtrScan);
+        }
+        else
+        {
+            renderCursorPixels((uint32_t *)srcShapePtr, srcAndMaskPtr,
+                               uWidth, uHeight,
+                               dstShapePtr, uHeight * srcShapePtrScan);
         }
 
         /* Set the new cursor: */
@@ -1478,33 +1551,16 @@ void UISession::setPointerShape(const uchar *pShapeData, bool fHasAlpha,
 
     /* Create a ARGB image out of the shape data. */
     QImage image  (uWidth, uHeight, QImage::Format_ARGB32);
-    const uint8_t* pbSrcMask = static_cast<const uint8_t*> (srcAndMaskPtr);
-    unsigned cbSrcMaskLine = RT_ALIGN (uWidth, 8) / 8;
-    for (unsigned int y = 0; y < uHeight; ++y)
+
+    if (fHasAlpha)
     {
-        for (unsigned int x = 0; x < uWidth; ++x)
-        {
-           unsigned int color = ((unsigned int*)srcShapePtr)[y*uWidth+x];
-           /* If the alpha channel isn't in the shape data, we have to
-            * create them from the and-mask. This is a bit field where 1
-            * represent transparency & 0 opaque respectively. */
-           if (!fHasAlpha)
-           {
-               if (!(pbSrcMask[x / 8] & (1 << (7 - (x % 8)))))
-                   color  |= 0xff000000;
-               else
-               {
-                   /* This isn't quite right, but it's the best we can do I think... */
-                   if (color & 0x00ffffff)
-                       color = 0xff000000;
-                   else
-                       color = 0x00000000;
-               }
-           }
-           image.setPixel (x, y, color);
-        }
-        /* Move one scanline forward. */
-        pbSrcMask += cbSrcMaskLine;
+        memcpy(image.bits(), srcShapePtr, uHeight * uWidth * 4);
+    }
+    else
+    {
+        renderCursorPixels((uint32_t *)srcShapePtr, srcAndMaskPtr,
+                           uWidth, uHeight,
+                           (uint32_t *)image.bits(), uHeight * uWidth * 4);
     }
 
     /* Set the new cursor: */
diff --git a/src/VBox/GuestHost/OpenGL/state_tracker/state_framebuffer.c b/src/VBox/GuestHost/OpenGL/state_tracker/state_framebuffer.c
index 0326551..cf27ac8 100644
--- a/src/VBox/GuestHost/OpenGL/state_tracker/state_framebuffer.c
+++ b/src/VBox/GuestHost/OpenGL/state_tracker/state_framebuffer.c
@@ -497,6 +497,7 @@ unsigned int crLog2Floor(unsigned int x)
 
 static GLuint crStateFramebufferGet(CRFramebufferObjectState *fbo, GLenum target, CRFramebufferObject **apFBOs)
 {
+    /** @todo Since this function returns not more than one FBO, callers can be cleaned up. */
     GLuint cPBOs = 0;
     switch (target)
     {
@@ -504,23 +505,14 @@ static GLuint crStateFramebufferGet(CRFramebufferObjectState *fbo, GLenum target
             cPBOs = 1;
             apFBOs[0] = fbo->readFB;
             break;
+        /* OpenGL glFramebufferTexture, glFramebufferRenderbuffer, glFramebufferRenderbuffer specs:
+         * "GL_FRAMEBUFFER is equivalent to GL_DRAW_FRAMEBUFFER."
+         */
+        case GL_FRAMEBUFFER:
         case GL_DRAW_FRAMEBUFFER:
             cPBOs = 1;
             apFBOs[0] = fbo->drawFB;
             break;
-        case GL_FRAMEBUFFER:
-            if (fbo->readFB == fbo->drawFB)
-            {
-                cPBOs = 1;
-                apFBOs[0] = fbo->readFB;
-            }
-            else
-            {
-                cPBOs = 2;
-                apFBOs[0] = fbo->readFB;
-                apFBOs[1] = fbo->drawFB;
-            }
-            break;
         default:
             crWarning("unexpected target value: 0x%x", target);
             cPBOs = 0;
diff --git a/src/VBox/GuestHost/OpenGL/util/vboxhgcm.c b/src/VBox/GuestHost/OpenGL/util/vboxhgcm.c
index 6a5ea4a..eb4d733 100644
--- a/src/VBox/GuestHost/OpenGL/util/vboxhgcm.c
+++ b/src/VBox/GuestHost/OpenGL/util/vboxhgcm.c
@@ -1455,6 +1455,13 @@ static int crVBoxHGCMDoConnect( CRConnection *conn )
                 rc = VINF_SUCCESS;
             }
 
+            if (g_crvboxhgcm.u32HostCaps & CR_VBOX_CAP_HOST_CAPS_NOT_SUFFICIENT)
+            {
+                crDebug("HGCM connect: insufficient host capabilities\n");
+                g_crvboxhgcm.u32HostCaps = 0;
+                return FALSE;
+            }
+
             VBOXCRHGSMIPROFILE_FUNC_EPILOGUE();
             return RT_SUCCESS(rc);
         }
diff --git a/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp b/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp
index 4414839..8553464 100644
--- a/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp
+++ b/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp
@@ -2274,8 +2274,24 @@ static int supR3HardNtViCallWinVerifyTrust(HANDLE hFile, PCRTUTF16 pwszName, uin
             case TRUST_E_NOSIGNATURE:             pszErrConst = "TRUST_E_NOSIGNATURE";          break;
             case TRUST_E_FAIL:                    pszErrConst = "TRUST_E_FAIL";                 break;
             case TRUST_E_EXPLICIT_DISTRUST:       pszErrConst = "TRUST_E_EXPLICIT_DISTRUST";    break;
+            case CERT_E_EXPIRED:                  pszErrConst = "CERT_E_EXPIRED";               break;
+            case CERT_E_VALIDITYPERIODNESTING:    pszErrConst = "CERT_E_VALIDITYPERIODNESTING"; break;
+            case CERT_E_ROLE:                     pszErrConst = "CERT_E_ROLE";                  break;
+            case CERT_E_PATHLENCONST:             pszErrConst = "CERT_E_PATHLENCONST";          break;
+            case CERT_E_CRITICAL:                 pszErrConst = "CERT_E_CRITICAL";              break;
+            case CERT_E_PURPOSE:                  pszErrConst = "CERT_E_PURPOSE";               break;
+            case CERT_E_ISSUERCHAINING:           pszErrConst = "CERT_E_ISSUERCHAINING";        break;
+            case CERT_E_MALFORMED:                pszErrConst = "CERT_E_MALFORMED";             break;
+            case CERT_E_UNTRUSTEDROOT:            pszErrConst = "CERT_E_UNTRUSTEDROOT";         break;
             case CERT_E_CHAINING:                 pszErrConst = "CERT_E_CHAINING";              break;
+            case CERT_E_REVOKED:                  pszErrConst = "CERT_E_REVOKED";               break;
+            case CERT_E_UNTRUSTEDTESTROOT:        pszErrConst = "CERT_E_UNTRUSTEDTESTROOT";     break;
             case CERT_E_REVOCATION_FAILURE:       pszErrConst = "CERT_E_REVOCATION_FAILURE";    break;
+            case CERT_E_CN_NO_MATCH:              pszErrConst = "CERT_E_CN_NO_MATCH";           break;
+            case CERT_E_WRONG_USAGE:              pszErrConst = "CERT_E_WRONG_USAGE";           break;
+            case CERT_E_UNTRUSTEDCA:              pszErrConst = "CERT_E_UNTRUSTEDCA";           break;
+            case CERT_E_INVALID_POLICY:           pszErrConst = "CERT_E_INVALID_POLICY";        break;
+            case CERT_E_INVALID_NAME:             pszErrConst = "CERT_E_INVALID_NAME";          break;
             case CRYPT_E_FILE_ERROR:              pszErrConst = "CRYPT_E_FILE_ERROR";           break;
             case CRYPT_E_REVOKED:                 pszErrConst = "CRYPT_E_REVOKED";              break;
         }
diff --git a/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp b/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
index 4605c33..cf914a3 100644
--- a/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
+++ b/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
@@ -1133,6 +1133,28 @@ static void supR3HardenedWinVerifyCacheProcessWvtTodos(void)
 
 
 /**
+ * Translates VBox status code (from supHardenedWinVerifyImageTrust) to an NT
+ * status.
+ *
+ * @returns NT status.
+ * @param   rc                      VBox status code.
+ */
+static NTSTATUS supR3HardenedScreenImageCalcStatus(int rc)
+{
+    /* This seems to be what LdrLoadDll returns when loading a 32-bit DLL into
+       a 64-bit process.  At least here on windows 10 (2015-11-xx).
+
+       NtCreateSection probably returns something different, possibly a warning,
+       we currently don't distinguish between the too, so we stick with the
+       LdrLoadDll one as it's definitely an error.*/
+    if (rc == VERR_LDR_ARCH_MISMATCH)
+        return STATUS_INVALID_IMAGE_FORMAT;
+
+    return STATUS_TRUST_FAILURE;
+}
+
+
+/**
  * Screens an image file or file mapped with execute access.
  *
  * @returns NT status code.
@@ -1242,7 +1264,7 @@ static NTSTATUS supR3HardenedScreenImage(HANDLE hFile, bool fImage, bool fIgnore
             supR3HardenedError(VINF_SUCCESS, false,
                                "supR3HardenedScreenImage/%s: cached rc=%Rrc fImage=%d fProtect=%#x fAccess=%#x cHits=%u %ls\n",
                                pszCaller, pCacheHit->rc, fImage, *pfProtect, *pfAccess, cHits, uBuf.UniStr.Buffer);
-        return STATUS_TRUST_FAILURE;
+        return supR3HardenedScreenImageCalcStatus(pCacheHit->rc);
     }
 
     /*
@@ -1434,7 +1456,7 @@ static NTSTATUS supR3HardenedScreenImage(HANDLE hFile, bool fImage, bool fIgnore
                            pszCaller, rc, fImage, *pfAccess, *pfProtect, uBuf.UniStr.Buffer, ErrInfo.pszMsg);
         if (hMyFile != hFile)
             supR3HardenedWinVerifyCacheInsert(&uBuf.UniStr, hMyFile, rc, fWinVerifyTrust, fFlags);
-        return STATUS_TRUST_FAILURE;
+        return supR3HardenedScreenImageCalcStatus(rc);
     }
 
     /*
diff --git a/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c b/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c
index 13dd8d7..a465ac5 100644
--- a/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c
+++ b/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c
@@ -66,12 +66,6 @@ typedef struct VBOXNETFLTNOTIFIER {
 typedef struct VBOXNETFLTNOTIFIER *PVBOXNETFLTNOTIFIER;
 
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 20, 0)
-# define vlan_tx_tag_get(skb)       skb_vlan_tag_get(skb)
-# define vlan_tx_tag_present(skb)   skb_vlan_tag_present(skb)
-#endif
-
-
 /*******************************************************************************
 *   Defined Constants And Macros                                               *
 *******************************************************************************/
@@ -127,6 +121,21 @@ typedef struct VBOXNETFLTNOTIFIER *PVBOXNETFLTNOTIFIER;
 # endif
 #endif
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 20, 0)
+# define VBOX_HAVE_SKB_VLAN
+#else
+# ifdef RHEL_RELEASE_CODE
+#  if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 2)
+#   define VBOX_HAVE_SKB_VLAN
+#  endif
+# endif
+#endif
+
+#ifdef VBOX_HAVE_SKB_VLAN
+# define vlan_tx_tag_get(skb)       skb_vlan_tag_get(skb)
+# define vlan_tx_tag_present(skb)   skb_vlan_tag_present(skb)
+#endif
+
 #ifndef NET_IP_ALIGN
 # define NET_IP_ALIGN 2
 #endif
@@ -138,6 +147,7 @@ typedef struct VBOXNETFLTNOTIFIER *PVBOXNETFLTNOTIFIER;
 #endif
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
+
 /** Indicates that the linux kernel may send us GSO frames. */
 # define VBOXNETFLT_WITH_GSO                1
 
@@ -155,12 +165,13 @@ typedef struct VBOXNETFLTNOTIFIER *PVBOXNETFLTNOTIFIER;
  *  to the internal network.  */
 # define VBOXNETFLT_WITH_GSO_RECV           1
 
-#endif
+#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18) */
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)
 /** This enables or disables handling of GSO frames coming from the wire (GRO). */
 # define VBOXNETFLT_WITH_GRO                1
 #endif
+
 /*
  * GRO support was backported to RHEL 5.4
  */
diff --git a/src/VBox/HostServices/GuestProperties/service.cpp b/src/VBox/HostServices/GuestProperties/service.cpp
index a25825c..87f90d8 100644
--- a/src/VBox/HostServices/GuestProperties/service.cpp
+++ b/src/VBox/HostServices/GuestProperties/service.cpp
@@ -1559,7 +1559,7 @@ int Service::initialize()
                             this,
                             0 /* default stack size */,
                             RTTHREADTYPE_DEFAULT,
-                            0, /* no flags. */
+                            RTTHREADFLAGS_WAITABLE,
                             "GSTPROPNTFY");
     }
 
@@ -1586,7 +1586,8 @@ int Service::uninit()
         int rc = RTReqQueueCall(mhReqQNotifyHost, &pReq, 10000, (PFNRT)wakeupNotifyHost, 0);
         if (RT_SUCCESS(rc))
             RTReqRelease(pReq);
-
+        rc = RTThreadWait(mhThreadNotifyHost, 10000, NULL);
+        AssertRC(rc);
         rc = RTReqQueueDestroy(mhReqQNotifyHost);
         AssertRC(rc);
         mhReqQNotifyHost = NIL_RTREQQUEUE;
diff --git a/src/VBox/Installer/common/virtualbox.desktop.in b/src/VBox/Installer/common/virtualbox.desktop.in
index e87bb7f..02adfbc 100644
--- a/src/VBox/Installer/common/virtualbox.desktop.in
+++ b/src/VBox/Installer/common/virtualbox.desktop.in
@@ -6,10 +6,12 @@ GenericName=Virtual Machine
 Type=Application
 Exec=VirtualBox %U
 TryExec=VirtualBox
+Keywords=virtualization;
+Keywords[de]=Virtualisierung;
 MimeType=application/x-virtualbox-vbox;application/x-virtualbox-vbox-extpack;application/x-virtualbox-ovf;application/x-virtualbox-ova;
 DocPath=file://@VBOX_DOC_PATH@/UserManual.pdf
 Icon=virtualbox
-Categories=Emulator;System;X-MandrivaLinux-System;Application;
+Categories=Emulator;System;
 Comment=Run several virtual systems on a single host computer
 Comment[de]=Mehrere virtuelle Maschinen auf einem einzigen Rechner ausführen
 Comment[it]=Esegui più macchine virtuali su un singolo computer
diff --git a/src/VBox/Installer/linux/rpm/rules b/src/VBox/Installer/linux/rpm/rules
index 7cbe336..8bfd4ff 100755
--- a/src/VBox/Installer/linux/rpm/rules
+++ b/src/VBox/Installer/linux/rpm/rules
@@ -87,7 +87,7 @@ ifneq ($(MAKECMDGOALS),clean)
  ifeq ($(filter-out el5 el6 ol5 ol6 el7 centos5 centos6 fedora17 fedora18 fedora19 fedora20 fedora21 fedora22,$(rpmrel)),)
   rpmspec := rpm_redhat
  endif
- ifeq ($(filter-out openSUSE110 openSUSE111 openSUSE112 openSUSE113 openSUSE114 openSUSE123 sles10.1 sles11.0,$(rpmrel)),)
+ ifeq ($(filter-out openSUSE110 openSUSE111 openSUSE112 openSUSE113 openSUSE114 openSUSE123 openSUSE131 openSUSE132 sles10.1 sles11.0,$(rpmrel)),)
   rpmspec := rpm_suse
  endif
  ifeq ($(filter-out mdv2009.1 mdv2010.0 mdv2011.0,$(rpmrel)),)
diff --git a/src/VBox/Installer/win/Stub/Makefile.kmk b/src/VBox/Installer/win/Stub/Makefile.kmk
index 5117edd..ac7ffe9 100644
--- a/src/VBox/Installer/win/Stub/Makefile.kmk
+++ b/src/VBox/Installer/win/Stub/Makefile.kmk
@@ -37,7 +37,11 @@ if "$(KBUILD_TARGET_ARCH)" == "x86"
  	VBOX_NTDLL
  VBoxStub_LIBS = \
  	$(VBOX_LIB_RUNTIME_STATIC) \
- 	$(PATH_SDK_$(VBOX_WINPSDK)_LIB)/Msi.lib
+       $(PATH_TOOL_$(VBOX_VCC_TOOL)_LIB)/delayimp.lib
+ VBoxStub_LDFLAGS = \
+ 	-DelayLoad:comctl32.dll
+ VBoxStub_POST_CMDS = $(VBOX_CHECK_IMPORTS) --image $(out) ntdll.dll kernel32.dll
+ VBoxStub_LNK_DEPS  = $(VBOX_CHECK_IMPORTS)
 
  VBoxStub.cpp_DEFS += VBOX_SVN_REV=$(VBOX_SVN_REV)
  VBoxStub.cpp_DEPS  = $(VBOX_SVN_REV_KMK)
@@ -47,7 +51,6 @@ if "$(KBUILD_TARGET_ARCH)" == "x86"
  ifdef VBOX_SIGNING_MODE
 
   VBoxStub_SOURCES  += VBoxStubCertUtil.cpp
-  VBoxStub_LIBS     += crypt32.lib
   VBoxStub.cpp_DEPS += $(VBoxStub_0_OUTDIR)/VBoxStubPublicCert.h
   VBoxStub.cpp_INCS += $(VBoxStub_0_OUTDIR)
   VBoxStub.cpp_DEFS += VBOX_WITH_CODE_SIGNING
@@ -75,6 +78,41 @@ if "$(KBUILD_TARGET_ARCH)" == "x86"
  $$(VBoxStub_0_OUTDIR)/VBoxStub-manifest.rc: $(VBOX_STUB_MANIFEST_FILE) $(MAKEFILE_CURRENT) | $$(dir $$@)
 	$(APPEND) -t $@ 'APP_MANIFEST RT_MANIFEST "$(subst /,\\,$(VBOX_STUB_MANIFEST_FILE))"'
 
+ # Dynamic import no. 1: MSI.DLL
+ VBoxStub_SOURCES += $(VBoxStub_0_OUTDIR)/MsiLazyLoad.asm
+ $$(VBoxStub_0_OUTDIR)/MsiLazyLoad.asm: $(PATH_SUB_CURRENT)/msi.def $(VBOX_DEF_2_LAZY_LOAD) | $$(dir $$@)
+	$(call MSG_TOOL,VBoxDef2LazyLoad,VBoxStub,$(filter %.def, $^),$@)
+	$(QUIET)$(RM) -f -- "$@"
+	$(VBOX_DEF_2_LAZY_LOAD) --system --library MSI.DLL --output "$@" $(filter %.def, $^)
+
+ # Dynamic import no. 2: CRYPTO32.DLL
+ VBoxStub_SOURCES += $(VBoxStub_0_OUTDIR)/Crypt32LazyLoad.asm
+ $$(VBoxStub_0_OUTDIR)/Crypt32LazyLoad.asm: $(PATH_SUB_CURRENT)/crypt32.def $(VBOX_DEF_2_LAZY_LOAD) | $$(dir $$@)
+	$(call MSG_TOOL,VBoxDef2LazyLoad,VBoxStub,$(filter %.def, $^),$@)
+	$(QUIET)$(RM) -f -- "$@"
+	$(VBOX_DEF_2_LAZY_LOAD) --system --library CRYPT32.DLL --output "$@" $(filter %.def, $^)
+
+ # Dynamic import no. 3: WS2_32.DLL
+ VBoxStub_SOURCES += $(VBoxStub_0_OUTDIR)/Ws232LazyLoad.asm
+ $$(VBoxStub_0_OUTDIR)/Ws232LazyLoad.asm: $(PATH_SUB_CURRENT)/ws2_32.def $(VBOX_DEF_2_LAZY_LOAD) | $$(dir $$@)
+	$(call MSG_TOOL,VBoxDef2LazyLoad,VBoxStub,$(filter %.def, $^),$@)
+	$(QUIET)$(RM) -f -- "$@"
+	$(VBOX_DEF_2_LAZY_LOAD) --system --library WS2_32.DLL --output "$@" $(filter %.def, $^)
+
+ # Dynamic import no. 4: USER32.DLL
+ VBoxStub_SOURCES += $(VBoxStub_0_OUTDIR)/User32LazyLoad.asm
+ $$(VBoxStub_0_OUTDIR)/User32LazyLoad.asm: $(PATH_SUB_CURRENT)/user32.def $(VBOX_DEF_2_LAZY_LOAD) | $$(dir $$@)
+	$(call MSG_TOOL,VBoxDef2LazyLoad,VBoxStub,$(filter %.def, $^),$@)
+	$(QUIET)$(RM) -f -- "$@"
+	$(VBOX_DEF_2_LAZY_LOAD) --system --library USER32.DLL --output "$@" $(filter %.def, $^)
+
+ # Dynamic import no. 5: SHELL32.DLL
+ VBoxStub_SOURCES += $(VBoxStub_0_OUTDIR)/Shell32LazyLoad.asm
+ $$(VBoxStub_0_OUTDIR)/Shell32LazyLoad.asm: $(PATH_SUB_CURRENT)/shell32.def $(VBOX_DEF_2_LAZY_LOAD) | $$(dir $$@)
+	$(call MSG_TOOL,VBoxDef2LazyLoad,VBoxStub,$(filter %.def, $^),$@)
+	$(QUIET)$(RM) -f -- "$@"
+	$(VBOX_DEF_2_LAZY_LOAD) --system --library SHELL32.DLL --output "$@" $(filter %.def, $^)
+
 
 endif # x86 only
 
diff --git a/src/VBox/Installer/win/Stub/VBoxStub.cpp b/src/VBox/Installer/win/Stub/VBoxStub.cpp
index a60ee31..abad065 100644
--- a/src/VBox/Installer/win/Stub/VBoxStub.cpp
+++ b/src/VBox/Installer/win/Stub/VBoxStub.cpp
@@ -799,8 +799,19 @@ int WINAPI WinMain(HINSTANCE  hInstance,
     char **argv = __argv;
     int argc    = __argc;
 
-    /* Check if we're already running and jump out if so. */
-    /* Do not use a global namespace ("Global\\") for mutex name here, will blow up NT4 compatibility! */
+    /*
+     * Init IPRT. This is _always_ the very first thing we do.
+     */
+    int vrc = RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_STANDALONE_APP);
+    if (RT_FAILURE(vrc))
+        return RTMsgInitFailure(vrc);
+
+    /*
+     * Check if we're already running and jump out if so.
+     *
+     * Note! Do not use a global namespace ("Global\\") for mutex name here,
+     *       will blow up NT4 compatibility!
+     */
     HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, "VBoxStubInstaller");
     if (   hMutexAppRunning != NULL
         && GetLastError() == ERROR_ALREADY_EXISTS)
@@ -811,16 +822,6 @@ int WINAPI WinMain(HINSTANCE  hInstance,
         return RTEXITCODE_FAILURE;
     }
 
-    /* Init IPRT. */
-    int vrc = RTR3InitExe(argc, &argv, 0);
-    if (RT_FAILURE(vrc))
-    {
-        /* Close the mutex for this application instance. */
-        CloseHandle(hMutexAppRunning);
-        hMutexAppRunning = NULL;
-        return RTMsgInitFailure(vrc);
-    }
-
     /*
      * Parse arguments.
      */
diff --git a/src/VBox/Installer/win/Stub/crypt32.def b/src/VBox/Installer/win/Stub/crypt32.def
new file mode 100644
index 0000000..f72fccc
--- /dev/null
+++ b/src/VBox/Installer/win/Stub/crypt32.def
@@ -0,0 +1,25 @@
+; $Id: crypt32.def $
+;; @file
+; Definitions for CRYPT32.DLL lazy import library.
+;
+
+; 
+; Copyright (C) 2009-2016 Oracle Corporation
+; 
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+; 
+
+LIBRARY CRYPT32.DLL
+EXPORTS
+    _CertCreateCertificateContext at 12
+    _CertOpenStore at 20
+    _CertFreeCertificateContext at 4
+    _CertAddCertificateContextToStore at 16
+    _CertCloseStore at 8
+
diff --git a/src/VBox/Installer/win/Stub/msi.def b/src/VBox/Installer/win/Stub/msi.def
new file mode 100644
index 0000000..be50b14
--- /dev/null
+++ b/src/VBox/Installer/win/Stub/msi.def
@@ -0,0 +1,23 @@
+; $Id: msi.def $
+;; @file
+; Definitions for MSI.DLL lazy import library.
+;
+
+; 
+; Copyright (C) 2009-2016 Oracle Corporation
+; 
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+; 
+
+LIBRARY MSI.DLL
+EXPORTS
+    _MsiInstallProductW at 8
+    _MsiEnableLogW at 12
+    _MsiSetInternalUI at 8
+
diff --git a/src/VBox/Installer/win/Stub/shell32.def b/src/VBox/Installer/win/Stub/shell32.def
new file mode 100644
index 0000000..6468b82
--- /dev/null
+++ b/src/VBox/Installer/win/Stub/shell32.def
@@ -0,0 +1,22 @@
+; $Id: shell32.def $
+;; @file
+; Definitions for SHELL32.DLL lazy import library.
+;
+
+; 
+; Copyright (C) 2009-2016 Oracle Corporation
+; 
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+; 
+
+LIBRARY SHELL32.DLL
+EXPORTS
+    _CommandLineToArgvW at 8
+    _SHFileOperationW at 4
+
diff --git a/src/VBox/Installer/win/Stub/user32.def b/src/VBox/Installer/win/Stub/user32.def
new file mode 100644
index 0000000..d87dbbf
--- /dev/null
+++ b/src/VBox/Installer/win/Stub/user32.def
@@ -0,0 +1,23 @@
+; $Id: user32.def $
+;; @file
+; Definitions for USER32.DLL lazy import library.
+;
+
+; 
+; Copyright (C) 2009-2016 Oracle Corporation
+; 
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+; 
+
+LIBRARY USER32.DLL
+EXPORTS
+    _MessageBoxW at 16
+    _MessageBoxA at 16
+    _GetDesktopWindow at 0
+
diff --git a/src/VBox/Installer/win/Stub/ws2_32.def b/src/VBox/Installer/win/Stub/ws2_32.def
new file mode 100644
index 0000000..8106609
--- /dev/null
+++ b/src/VBox/Installer/win/Stub/ws2_32.def
@@ -0,0 +1,22 @@
+; $Id: ws2_32.def $
+;; @file
+; Definitions for WS2_32.DLL lazy import library.
+;
+
+; 
+; Copyright (C) 2009-2016 Oracle Corporation
+; 
+; This file is part of VirtualBox Open Source Edition (OSE), as
+; available from http://www.virtualbox.org. This file is free software;
+; you can redistribute it and/or modify it under the terms of the GNU
+; General Public License (GPL) as published by the Free Software
+; Foundation, in version 2 as it comes in the "COPYING" file of the
+; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+; 
+
+LIBRARY WS2_32.DLL
+EXPORTS
+    _WSASetLastError at 4
+    _WSAGetLastError at 0
+
diff --git a/src/VBox/Main/src-all/ExtPackManagerImpl.cpp b/src/VBox/Main/src-all/ExtPackManagerImpl.cpp
index 4946d9b..b57a119 100644
--- a/src/VBox/Main/src-all/ExtPackManagerImpl.cpp
+++ b/src/VBox/Main/src-all/ExtPackManagerImpl.cpp
@@ -1303,6 +1303,27 @@ void ExtPack::probeAndLoad(void)
     }
 
     /*
+     * Check for possibly incompatible extpack versions.
+     *
+     * - In 4.3.12 the PDMUSBREG structure was modified without updating the
+     *   version number.
+     * - In 4.3.16 (actually r95499) the VUSBIROOTHUBCONNECTOR interface changed without
+     *   also changing the UUID, with the result that our EHCI device could crash the
+     *   host process.
+     * - In 4.3.12 and 4.3.30 the VUSBREQ structure was updated without updating
+     *   the PDMUSBREG or any other version number.
+     *
+     *  Since this was from before VBOXEXTPACKREG::uVBoxFullVersion was
+     *  added, the check isn't all that generic.
+     */
+    if (   m->Desc.strName.equals("Oracle VM VirtualBox Extension Pack")
+        && RTStrVersionCompare(m->Desc.strVersion.c_str(), "4.3.30") < 0)
+    {
+        m->strWhyUnusable.printf(tr("Incompatible extension pack (version '%s'), please update"), m->Desc.strVersion.c_str());
+        return;
+    }
+
+    /*
      * Load the main DLL and call the predefined entry point.
      */
     bool fIsNative;
diff --git a/src/VBox/Main/src-client/ConsoleImpl2.cpp b/src/VBox/Main/src-client/ConsoleImpl2.cpp
index d5d9f0f..23167be 100644
--- a/src/VBox/Main/src-client/ConsoleImpl2.cpp
+++ b/src/VBox/Main/src-client/ConsoleImpl2.cpp
@@ -2450,8 +2450,10 @@ int Console::configConstructorInner(PUVM pUVM, PVM pVM, AutoWriteLock *pAlock)
                                    "Because the USB 2.0 controller state is part of the saved "
                                    "VM state, the VM cannot be started. To fix "
                                    "this problem, either install the '%s' or disable USB 2.0 "
-                                   "support in the VM settings"),
-                                s_pszUsbExtPackName);
+                                   "support in the VM settings.\n"
+                                   "Note! This error could also mean that an incompatible version of "
+                                   "the '%s' is installed"),
+                                s_pszUsbExtPackName, s_pszUsbExtPackName);
                     }
 # endif
                 }
diff --git a/src/VBox/Runtime/Makefile.kmk b/src/VBox/Runtime/Makefile.kmk
index ed23226..4f21d16 100644
--- a/src/VBox/Runtime/Makefile.kmk
+++ b/src/VBox/Runtime/Makefile.kmk
@@ -945,7 +945,6 @@ RuntimeR3_SOURCES.darwin = \
 	generic/RTTimerCreate-generic.cpp \
 	generic/RTUuidCreate-generic.cpp \
 	generic/mppresent-generic.cpp \
-	generic/RTMpGetOnlineCoreCount-generic.cpp \
  	generic/RTSemEventMultiWait-2-ex-generic.cpp \
  	generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp \
 	generic/semrw-$(if-expr defined(VBOX_WITH_LOCKLESS_SEMRW),lockless-,)generic.cpp \
@@ -1172,7 +1171,7 @@ RuntimeR3_SOURCES.haiku = \
  	generic/RTSemEventMultiWait-2-ex-generic.cpp \
  	generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp \
 	generic/sched-generic.cpp \
-	generic/semrw-$(if-expr defined(VBOX_WITH_LOCKLESS_SEMRW),ockless-,)generic.cpp \
+	generic/semrw-$(if-expr defined(VBOX_WITH_LOCKLESS_SEMRW),lockless-,)generic.cpp \
 	generic/timer-generic.cpp \
 	generic/utf16locale-generic.cpp \
 	generic/uuid-generic.cpp\
@@ -1673,6 +1672,7 @@ RuntimeR0_SOURCES      := \
 	common/time/timesup.cpp \
 	generic/RTAssertShouldPanic-generic.cpp \
 	generic/critsect-generic.cpp \
+	generic/critsectrw-generic.cpp \
 	\
 	$(RuntimeNoCrt_SOURCES)
 
diff --git a/src/VBox/Runtime/common/ldr/ldrEx.cpp b/src/VBox/Runtime/common/ldr/ldrEx.cpp
index 554e5d8..4dbb62a 100644
--- a/src/VBox/Runtime/common/ldr/ldrEx.cpp
+++ b/src/VBox/Runtime/common/ldr/ldrEx.cpp
@@ -730,3 +730,26 @@ DECLHIDDEN(int) rtLdrReadAt(RTLDRMOD hLdrMod, void *pvBuf, uint32_t iDbgInfo, RT
     return pMod->pReader->pfnRead(pMod->pReader, pvBuf, cb, off);
 }
 
+
+/**
+ * Translates a RTLDRARCH value to a string.
+ *
+ * @returns Name corresponding to @a enmArch
+ * @param   enmArch             The value to name.
+ */
+DECLHIDDEN(const char *) rtLdrArchName(RTLDRARCH enmArch)
+{
+    switch (enmArch)
+    {
+        case RTLDRARCH_INVALID:     return "INVALID";
+        case RTLDRARCH_WHATEVER:    return "WHATEVER";
+        case RTLDRARCH_HOST:        return "HOST";
+        case RTLDRARCH_AMD64:       return "AMD64";
+        case RTLDRARCH_X86_32:      return "X86_32";
+
+        case RTLDRARCH_END:
+        case RTLDRARCH_32BIT_HACK:
+            break;
+    }
+    return "UNKNOWN";
+}
diff --git a/src/VBox/Runtime/common/ldr/ldrPE.cpp b/src/VBox/Runtime/common/ldr/ldrPE.cpp
index 759bdcb..7c1991c 100644
--- a/src/VBox/Runtime/common/ldr/ldrPE.cpp
+++ b/src/VBox/Runtime/common/ldr/ldrPE.cpp
@@ -3622,6 +3622,18 @@ static int rtldrPEValidateDirectoriesAndRememberStuff(PRTLDRMODPE pModPe, const
 }
 
 
+static const char *rtldrPEGetArchName(uint16_t uMachine)
+{
+    switch (uMachine)
+    {
+        case IMAGE_FILE_MACHINE_I386:   return "X86_32";
+        case IMAGE_FILE_MACHINE_AMD64:  return "AMD64";
+        default:                        return "Unknown";
+    }
+}
+
+
+
 /**
  * Open a PE image.
  *
@@ -3658,7 +3670,8 @@ int rtldrPEOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF
              && !(fFlags & RTLDR_O_WHATEVER_ARCH)) )
     {
         if (!(fFlags & RTLDR_O_IGNORE_ARCH_IF_NO_CODE))
-            return VERR_LDR_ARCH_MISMATCH;
+            return RTErrInfoSetF(pErrInfo, VERR_LDR_ARCH_MISMATCH, "Image is for '%s', only accepting images for '%s'.",
+                                 rtldrPEGetArchName(FileHdr.Machine), rtLdrArchName(enmArch));
         fArchNoCodeCheckPending = true;
     }
 
@@ -3675,7 +3688,9 @@ int rtldrPEOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTFOFF
     if (RT_FAILURE(rc))
         return rc;
     if (fArchNoCodeCheckPending && OptHdr.SizeOfCode != 0)
-        return VERR_LDR_ARCH_MISMATCH;
+        return RTErrInfoSetF(pErrInfo, VERR_LDR_ARCH_MISMATCH,
+                             "Image is for '%s' and contains code (%#x), only accepting images for '%s' with code.",
+                             rtldrPEGetArchName(FileHdr.Machine), OptHdr.SizeOfCode, rtLdrArchName(enmArch));
 
     /*
      * Read and validate section headers.
diff --git a/src/VBox/Runtime/generic/critsectrw-generic.cpp b/src/VBox/Runtime/generic/critsectrw-generic.cpp
index 41099ec..82975aa 100644
--- a/src/VBox/Runtime/generic/critsectrw-generic.cpp
+++ b/src/VBox/Runtime/generic/critsectrw-generic.cpp
@@ -66,6 +66,11 @@ RTDECL(int) RTCritSectRwInitEx(PRTCRITSECTRW pThis, uint32_t fFlags,
      */
     pThis->u32Magic         = RTCRITSECTRW_MAGIC_DEAD;
     pThis->fNeedReset       = false;
+#ifdef IN_RING0
+    pThis->fFlags           = (uint16_t)(fFlags | RTCRITSECT_FLAGS_RING0);
+#else
+    pThis->fFlags           = (uint16_t)(fFlags & ~RTCRITSECT_FLAGS_RING0);
+#endif
     pThis->u64State         = 0;
     pThis->hNativeWriter    = NIL_RTNATIVETHREAD;
     pThis->cWriterReads     = 0;
@@ -137,6 +142,11 @@ RTDECL(uint32_t) RTCritSectRwSetSubClass(PRTCRITSECTRW pThis, uint32_t uSubClass
 {
     AssertPtrReturn(pThis, RTLOCKVAL_SUB_CLASS_INVALID);
     AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, RTLOCKVAL_SUB_CLASS_INVALID);
+#ifdef IN_RING0
+    Assert(pThis->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pThis->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 #ifdef RTCRITSECTRW_STRICT
     AssertReturn(!(pThis->fFlags & RTCRITSECT_FLAGS_NOP), RTLOCKVAL_SUB_CLASS_INVALID);
 
@@ -157,6 +167,11 @@ static int rtCritSectRwEnterShared(PRTCRITSECTRW pThis, PCRTLOCKVALSRCPOS pSrcPo
      */
     AssertPtr(pThis);
     AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, VERR_SEM_DESTROYED);
+#ifdef IN_RING0
+    Assert(pThis->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pThis->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 
 #ifdef RTCRITSECTRW_STRICT
     RTTHREAD hThreadSelf = RTThreadSelfAutoAdopt();
@@ -256,13 +271,15 @@ static int rtCritSectRwEnterShared(PRTCRITSECTRW pThis, PCRTLOCKVALSRCPOS pSrcPo
                     rc = RTLockValidatorRecSharedCheckBlocking(pThis->pValidatorRead, hThreadSelf, pSrcPos, true,
                                                                RT_INDEFINITE_WAIT, RTTHREADSTATE_RW_READ, false);
                     if (RT_SUCCESS(rc))
-#else
+#elif defined(IN_RING3)
                     RTTHREAD hThreadSelf = RTThreadSelf();
                     RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_READ, false);
 #endif
                     {
                         rc = RTSemEventMultiWait(pThis->hEvtRead, RT_INDEFINITE_WAIT);
+#ifdef IN_RING3
                         RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_RW_READ);
+#endif
                         if (pThis->u32Magic != RTCRITSECTRW_MAGIC)
                             return VERR_SEM_DESTROYED;
                     }
@@ -387,6 +404,11 @@ RTDECL(int) RTCritSectRwLeaveShared(PRTCRITSECTRW pThis)
      */
     AssertPtr(pThis);
     AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, VERR_SEM_DESTROYED);
+#ifdef IN_RING0
+    Assert(pThis->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pThis->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 
     /*
      * Check the direction and take action accordingly.
@@ -460,6 +482,11 @@ static int rtCritSectRwEnterExcl(PRTCRITSECTRW pThis, PCRTLOCKVALSRCPOS pSrcPos,
      */
     AssertPtr(pThis);
     AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, VERR_SEM_DESTROYED);
+#ifdef IN_RING0
+    Assert(pThis->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pThis->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 
 #ifdef RTCRITSECTRW_STRICT
     RTTHREAD hThreadSelf = NIL_RTTHREAD;
@@ -583,13 +610,15 @@ static int rtCritSectRwEnterExcl(PRTCRITSECTRW pThis, PCRTLOCKVALSRCPOS pSrcPos,
             rc = RTLockValidatorRecExclCheckBlocking(pThis->pValidatorWrite, hThreadSelf, pSrcPos, true,
                                                      RT_INDEFINITE_WAIT, RTTHREADSTATE_RW_WRITE, false);
             if (RT_SUCCESS(rc))
-#else
+#elif defined(IN_RING3)
             RTTHREAD hThreadSelf = RTThreadSelf();
             RTThreadBlocking(hThreadSelf, RTTHREADSTATE_RW_WRITE, false);
 #endif
             {
                 rc = RTSemEventWait(pThis->hEvtWrite, RT_INDEFINITE_WAIT);
+#ifdef IN_RING3
                 RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_RW_WRITE);
+#endif
                 if (pThis->u32Magic != RTCRITSECTRW_MAGIC)
                     return VERR_SEM_DESTROYED;
             }
@@ -681,6 +710,11 @@ RTDECL(int) RTCritSectRwLeaveExcl(PRTCRITSECTRW pThis)
      */
     AssertPtr(pThis);
     AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, VERR_SEM_DESTROYED);
+#ifdef IN_RING0
+    Assert(pThis->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pThis->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 
     RTNATIVETHREAD hNativeSelf = RTThreadNativeSelf();
     RTNATIVETHREAD hNativeWriter;
@@ -772,6 +806,11 @@ RTDECL(bool) RTCritSectRwIsWriteOwner(PRTCRITSECTRW pThis)
      */
     AssertPtr(pThis);
     AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, false);
+#ifdef IN_RING0
+    Assert(pThis->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pThis->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 
     /*
      * Check ownership.
@@ -791,6 +830,11 @@ RTDECL(bool) RTCritSectRwIsReadOwner(PRTCRITSECTRW pThis, bool fWannaHear)
      */
     AssertPtr(pThis);
     AssertReturn(pThis->u32Magic == RTCRITSECTRW_MAGIC, false);
+#ifdef IN_RING0
+    Assert(pThis->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pThis->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 
     /*
      * Inspect the state.
@@ -890,6 +934,11 @@ RTDECL(int) RTCritSectRwDelete(PRTCRITSECTRW pThis)
     //Assert(pThis->cNestings == 0);
     //Assert(pThis->cLockers == -1);
     Assert(pThis->hNativeWriter == NIL_RTNATIVETHREAD);
+#ifdef IN_RING0
+    Assert(pThis->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pThis->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 
     /*
      * Invalidate the structure and free the semaphores.
@@ -908,8 +957,10 @@ RTDECL(int) RTCritSectRwDelete(PRTCRITSECTRW pThis)
     int rc1 = RTSemEventDestroy(hEvtWrite);     AssertRC(rc1);
     int rc2 = RTSemEventMultiDestroy(hEvtRead); AssertRC(rc2);
 
+#ifndef IN_RING0
     RTLockValidatorRecSharedDestroy(&pThis->pValidatorRead);
     RTLockValidatorRecExclDestroy(&pThis->pValidatorWrite);
+#endif
 
     return RT_SUCCESS(rc1) ? rc2 : rc1;
 }
diff --git a/src/VBox/Runtime/include/internal/ldr.h b/src/VBox/Runtime/include/internal/ldr.h
index d9fdaca..009dbf9 100644
--- a/src/VBox/Runtime/include/internal/ldr.h
+++ b/src/VBox/Runtime/include/internal/ldr.h
@@ -496,6 +496,7 @@ int rtldrMachoOpen(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, RTF
 
 
 DECLHIDDEN(int) rtLdrReadAt(RTLDRMOD hLdrMod, void *pvBuf, uint32_t iDbgInfo, RTFOFF off, size_t cb);
+DECLHIDDEN(const char *) rtLdrArchName(RTLDRARCH enmArch);
 
 RT_C_DECLS_END
 
diff --git a/src/VBox/Runtime/r3/darwin/mp-darwin.cpp b/src/VBox/Runtime/r3/darwin/mp-darwin.cpp
index bfdeb0d..fb5fafa 100644
--- a/src/VBox/Runtime/r3/darwin/mp-darwin.cpp
+++ b/src/VBox/Runtime/r3/darwin/mp-darwin.cpp
@@ -208,6 +208,12 @@ RTDECL(RTCPUID) RTMpGetOnlineCount(void)
 }
 
 
+RTDECL(RTCPUID) RTMpGetOnlineCoreCount(void)
+{
+    return rtMpDarwinOnlinePhysicalCpus();
+}
+
+
 RTDECL(uint32_t) RTMpGetCurFrequency(RTCPUID idCpu)
 {
     /** @todo figure out how to get the current cpu speed on darwin. Have to check what powermanagement does. */
diff --git a/src/VBox/Runtime/r3/init.cpp b/src/VBox/Runtime/r3/init.cpp
index 42265da..e7e58d1 100644
--- a/src/VBox/Runtime/r3/init.cpp
+++ b/src/VBox/Runtime/r3/init.cpp
@@ -147,7 +147,7 @@ RTDATADECL(bool) g_fRTAlignmentChecks = false;
 /* Stubs */
 DECLHIDDEN(int)  rtR3InitNativeFirst(uint32_t fFlags) { return VINF_SUCCESS; }
 DECLHIDDEN(int)  rtR3InitNativeFinal(uint32_t fFlags) { return VINF_SUCCESS; }
-DECLHIDDEN(void) rtR3InitNativeObtrusive(void) { }
+DECLHIDDEN(void) rtR3InitNativeObtrusive(uint32_t fFlags) { }
 #endif
 
 
@@ -555,7 +555,8 @@ static int rtR3Init(uint32_t fFlags, int cArgs, char ***papszArgs, const char *p
     Assert(!(fFlags & ~(  RTR3INIT_FLAGS_DLL
                         | RTR3INIT_FLAGS_SUPLIB
                         | RTR3INIT_FLAGS_UNOBTRUSIVE
-                        | RTR3INIT_FLAGS_UTF8_ARGV)));
+                        | RTR3INIT_FLAGS_UTF8_ARGV
+                        | RTR3INIT_FLAGS_STANDALONE_APP)));
     Assert(!(fFlags & RTR3INIT_FLAGS_DLL) || cArgs == 0);
 
     /*
@@ -576,14 +577,18 @@ static int rtR3Init(uint32_t fFlags, int cArgs, char ***papszArgs, const char *p
             g_fInitFlags |= RTR3INIT_FLAGS_SUPLIB;
         }
 #endif
+        g_fInitFlags |= fFlags & RTR3INIT_FLAGS_UTF8_ARGV;
 
         if (   !(fFlags      & RTR3INIT_FLAGS_UNOBTRUSIVE)
             && (g_fInitFlags & RTR3INIT_FLAGS_UNOBTRUSIVE))
         {
             g_fInitFlags &= ~RTR3INIT_FLAGS_UNOBTRUSIVE;
-            rtR3InitNativeObtrusive();
+            g_fInitFlags |= fFlags & RTR3INIT_FLAGS_STANDALONE_APP;
+            rtR3InitNativeObtrusive(g_fInitFlags | fFlags);
             rtThreadReInitObtrusive();
         }
+        else
+            Assert(!(fFlags & RTR3INIT_FLAGS_STANDALONE_APP) || (g_fInitFlags & RTR3INIT_FLAGS_STANDALONE_APP));
 
         int rc = VINF_SUCCESS;
         if (pszProgramPath)
diff --git a/src/VBox/Runtime/r3/init.h b/src/VBox/Runtime/r3/init.h
index fae5c41..eba2a3d 100644
--- a/src/VBox/Runtime/r3/init.h
+++ b/src/VBox/Runtime/r3/init.h
@@ -32,7 +32,7 @@
 
 DECLHIDDEN(int)  rtR3InitNativeFirst(uint32_t fFlags);
 DECLHIDDEN(int)  rtR3InitNativeFinal(uint32_t fFlags);
-DECLHIDDEN(void) rtR3InitNativeObtrusive(void);
+DECLHIDDEN(void) rtR3InitNativeObtrusive(uint32_t fFlags);
 
 #endif
 
diff --git a/src/VBox/Runtime/r3/linux/sched-linux.cpp b/src/VBox/Runtime/r3/linux/sched-linux.cpp
index 82eec1c..88fec62 100644
--- a/src/VBox/Runtime/r3/linux/sched-linux.cpp
+++ b/src/VBox/Runtime/r3/linux/sched-linux.cpp
@@ -324,7 +324,7 @@ static int rtSchedRunThread(void *(*pfnThread)(void *pvArg), void *pvArg)
         do
         {
             rc = pthread_join(Thread, &pvRet);
-        } while (errno == EINTR);
+        } while (rc == EINTR);
         if (rc)
             return RTErrConvertFromErrno(rc);
         return (int)(uintptr_t)pvRet;
diff --git a/src/VBox/Runtime/r3/posix/sched-posix.cpp b/src/VBox/Runtime/r3/posix/sched-posix.cpp
index 4fa2bb9..3b8628b 100644
--- a/src/VBox/Runtime/r3/posix/sched-posix.cpp
+++ b/src/VBox/Runtime/r3/posix/sched-posix.cpp
@@ -399,7 +399,7 @@ static int rtSchedCreateThread(void *(*pfnThread)(void *pvArg), void *pvArg)
                     do
                     {
                         rc = pthread_join(Thread, &pvRet);
-                    } while (errno == EINTR);
+                    } while (rc == EINTR);
                     if (rc)
                         return RTErrConvertFromErrno(rc);
                     return (int)(uintptr_t)pvRet;
diff --git a/src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp b/src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp
index 4a2503a..faf743e 100644
--- a/src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp
+++ b/src/VBox/Runtime/r3/win/RTSystemQueryOSInfo-win.cpp
@@ -214,9 +214,13 @@ static int rtSystemWinQueryOSVersion(RTSYSOSINFO enmInfo, char *pszInfo, size_t
                 }
                 case kRTWinOSType_2008:         strcpy(szTmp, "Windows 2008"); break;
                 case kRTWinOSType_7:            strcpy(szTmp, "Windows 7"); break;
+                case kRTWinOSType_2008R2:       strcpy(szTmp, "Windows 2008 R2"); break;
                 case kRTWinOSType_8:            strcpy(szTmp, "Windows 8"); break;
+                case kRTWinOSType_2012:         strcpy(szTmp, "Windows 2012"); break;
                 case kRTWinOSType_81:           strcpy(szTmp, "Windows 8.1"); break;
+                case kRTWinOSType_2012R2:       strcpy(szTmp, "Windows 2012 R2"); break;
                 case kRTWinOSType_10:           strcpy(szTmp, "Windows 10"); break;
+                case kRTWinOSType_2016:         strcpy(szTmp, "Windows 2016"); break;
 
                 case kRTWinOSType_NT_UNKNOWN:
                     RTStrPrintf(szTmp, sizeof(szTmp), "Unknown NT v%u.%u",
diff --git a/src/VBox/Runtime/r3/win/init-win.cpp b/src/VBox/Runtime/r3/win/init-win.cpp
index f58a45f..074b23f 100644
--- a/src/VBox/Runtime/r3/win/init-win.cpp
+++ b/src/VBox/Runtime/r3/win/init-win.cpp
@@ -153,16 +153,36 @@ static RTWINOSTYPE rtR3InitWinSimplifiedVersion(OSVERSIONINFOEXW const *pOSInfoE
         }
         else if (   dwMajorVersion == 6
                  && dwMinorVersion == 1)
-            enmVer = kRTWinOSType_7;
+        {
+            if (bProductType != VER_NT_WORKSTATION)
+                enmVer = kRTWinOSType_2008R2;
+            else
+                enmVer = kRTWinOSType_7;
+        }
         else if (   dwMajorVersion == 6
                  && dwMinorVersion == 2)
-            enmVer = kRTWinOSType_8;
+        {
+            if (bProductType != VER_NT_WORKSTATION)
+                enmVer = kRTWinOSType_2012;
+            else
+                enmVer = kRTWinOSType_8;
+        }
         else if (   dwMajorVersion == 6
                  && dwMinorVersion == 3)
-            enmVer = kRTWinOSType_81;
+        {
+            if (bProductType != VER_NT_WORKSTATION)
+               enmVer = kRTWinOSType_2012R2;
+            else
+                enmVer = kRTWinOSType_81;
+        }
         else if (   dwMajorVersion == 6
                  && dwMinorVersion == 4)
-            enmVer = kRTWinOSType_10;
+        {
+            if (bProductType != VER_NT_WORKSTATION)
+                enmVer = kRTWinOSType_2016;
+            else
+                enmVer = kRTWinOSType_10;
+        }
         else
             enmVer = kRTWinOSType_NT_UNKNOWN;
     }
@@ -225,7 +245,7 @@ static void rtR3InitWindowsVersion(void)
 }
 
 
-static int rtR3InitNativeObtrusiveWorker(void)
+static int rtR3InitNativeObtrusiveWorker(uint32_t fFlags)
 {
     /*
      * Disable error popups.
@@ -239,7 +259,8 @@ static int rtR3InitNativeObtrusiveWorker(void)
      *  - The first trick works on XP SP1+ and disables the searching of the
      *    current directory.
      *  - The second trick is W7 w/ KB2533623 and W8+, it restrict the DLL
-     *    searching to the application directory and the System32 directory.
+     *    searching to the application directory (except when
+     *    RTR3INIT_FLAGS_STANDALONE_APP is given) and the System32 directory.
      */
     int rc = VINF_SUCCESS;
 
@@ -253,16 +274,23 @@ static int rtR3InitNativeObtrusiveWorker(void)
             rc = VERR_INTERNAL_ERROR_3;
     }
 
-    /** @bugref 6861: Observed GUI issues on Vista (32-bit and 64-bit). */
-    if (g_enmWinVer > kRTWinOSType_VISTA)
+    /** @bugref{6861} Observed GUI issues on Vista (32-bit and 64-bit) when using
+     *                SetDefaultDllDirectories.
+     *  @bugref{8194} Try use SetDefaultDllDirectories on Vista for standalone apps
+     *                despite potential GUI issues. */
+    if (   g_enmWinVer > kRTWinOSType_VISTA
+        || (fFlags & RTR3INIT_FLAGS_STANDALONE_APP))
     {
         typedef BOOL(WINAPI *PFNSETDEFAULTDLLDIRECTORIES)(DWORD);
         PFNSETDEFAULTDLLDIRECTORIES pfnSetDefDllDirs;
         pfnSetDefDllDirs = (PFNSETDEFAULTDLLDIRECTORIES)GetProcAddress(g_hModKernel32, "SetDefaultDllDirectories");
         if (pfnSetDefDllDirs)
         {
-            if (pfnSetDefDllDirs(LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32))
-                g_enmWinLdrProt = RTR3WINLDRPROT_SAFE;
+            DWORD fDllDirs = LOAD_LIBRARY_SEARCH_SYSTEM32;
+            if (!(fFlags & RTR3INIT_FLAGS_STANDALONE_APP))
+                fDllDirs |= LOAD_LIBRARY_SEARCH_APPLICATION_DIR;
+            if (pfnSetDefDllDirs(fDllDirs))
+                g_enmWinLdrProt = fDllDirs & LOAD_LIBRARY_SEARCH_APPLICATION_DIR ? RTR3WINLDRPROT_SAFE : RTR3WINLDRPROT_SAFER;
             else if (RT_SUCCESS(rc))
                 rc = VERR_INTERNAL_ERROR_4;
         }
@@ -288,15 +316,15 @@ DECLHIDDEN(int) rtR3InitNativeFirst(uint32_t fFlags)
 
     int rc = VINF_SUCCESS;
     if (!(fFlags & RTR3INIT_FLAGS_UNOBTRUSIVE))
-        rc = rtR3InitNativeObtrusiveWorker();
+        rc = rtR3InitNativeObtrusiveWorker(fFlags);
 
     return rc;
 }
 
 
-DECLHIDDEN(void) rtR3InitNativeObtrusive(void)
+DECLHIDDEN(void) rtR3InitNativeObtrusive(uint32_t fFlags)
 {
-    rtR3InitNativeObtrusiveWorker();
+    rtR3InitNativeObtrusiveWorker(fFlags);
 }
 
 
diff --git a/src/VBox/Runtime/r3/win/internal-r3-win.h b/src/VBox/Runtime/r3/win/internal-r3-win.h
index cc73b58..331b1cb 100644
--- a/src/VBox/Runtime/r3/win/internal-r3-win.h
+++ b/src/VBox/Runtime/r3/win/internal-r3-win.h
@@ -32,15 +32,20 @@ typedef enum RTWINOSTYPE
     kRTWinOSType_NT31       = kRTWinOSType_NTFIRST,
     kRTWinOSType_NT351,
     kRTWinOSType_NT4,
-    kRTWinOSType_2K,
-    kRTWinOSType_XP,
-    kRTWinOSType_2003,
-    kRTWinOSType_VISTA,
-    kRTWinOSType_2008,
-    kRTWinOSType_7,
-    kRTWinOSType_8,
-    kRTWinOSType_81,
-    kRTWinOSType_10,
+    kRTWinOSType_2K,                        /* 5.0 */
+    kRTWinOSType_XP,                        /* 5.1 */
+    kRTWinOSType_XP64,                      /* 5.2, workstation */
+    kRTWinOSType_2003,                      /* 5.2 */
+    kRTWinOSType_VISTA,                     /* 6.0, workstation */
+    kRTWinOSType_2008,                      /* 6.0, server */
+    kRTWinOSType_7,                         /* 6.1, workstation */
+    kRTWinOSType_2008R2,                    /* 6.1, server */
+    kRTWinOSType_8,                         /* 6.2, workstation */
+    kRTWinOSType_2012,                      /* 6.2, server */
+    kRTWinOSType_81,                        /* 6.3, workstation */
+    kRTWinOSType_2012R2,                    /* 6.3, server */
+    kRTWinOSType_10,                        /* 10.0, workstation */
+    kRTWinOSType_2016,                      /* 10.0, server */
     kRTWinOSType_NT_UNKNOWN = 199,
     kRTWinOSType_NT_LAST    = kRTWinOSType_UNKNOWN
 } RTWINOSTYPE;
@@ -53,7 +58,8 @@ typedef enum RTR3WINLDRPROT
     RTR3WINLDRPROT_INVALID = 0,
     RTR3WINLDRPROT_NONE,
     RTR3WINLDRPROT_NO_CWD,
-    RTR3WINLDRPROT_SAFE
+    RTR3WINLDRPROT_SAFE,
+    RTR3WINLDRPROT_SAFER
 } RTR3WINLDRPROT;
 
 
diff --git a/src/VBox/Runtime/r3/win/ldrNative-win.cpp b/src/VBox/Runtime/r3/win/ldrNative-win.cpp
index 8b26ab2..5cb45ee 100644
--- a/src/VBox/Runtime/r3/win/ldrNative-win.cpp
+++ b/src/VBox/Runtime/r3/win/ldrNative-win.cpp
@@ -44,6 +44,7 @@
 #include <iprt/once.h>
 #include <iprt/string.h>
 #include "internal/ldr.h"
+#include "internal-r3-win.h"
 
 
 int rtldrNativeLoad(const char *pszFilename, uintptr_t *phHandle, uint32_t fFlags, PRTERRINFO pErrInfo)
@@ -53,6 +54,8 @@ int rtldrNativeLoad(const char *pszFilename, uintptr_t *phHandle, uint32_t fFlag
     AssertLogRelMsgReturn(RTPathStartsWithRoot(pszFilename),  /* Relative names will still be applied to the search path. */
                           ("pszFilename='%s'\n", pszFilename),
                           VERR_INTERNAL_ERROR_2);
+    AssertReleaseMsg(g_hModKernel32,
+                     ("rtldrNativeLoad(%s,,) is called before IPRT has configured the windows loader!\n", pszFilename));
 
     /*
      * Do we need to add an extension?
@@ -116,6 +119,9 @@ DECLCALLBACK(int) rtldrNativeClose(PRTLDRMODINTERNAL pMod)
 
 int rtldrNativeLoadSystem(const char *pszFilename, const char *pszExt, uint32_t fFlags, PRTLDRMOD phLdrMod)
 {
+    AssertReleaseMsg(g_hModKernel32,
+                     ("rtldrNativeLoadSystem(%s,,) is called before IPRT has configured the windows loader!\n", pszFilename));
+
     /*
      * We only try the System32 directory.
      */
diff --git a/src/VBox/Storage/testcase/vbox-img.cpp b/src/VBox/Storage/testcase/vbox-img.cpp
index 4f14455..8452fe1 100644
--- a/src/VBox/Storage/testcase/vbox-img.cpp
+++ b/src/VBox/Storage/testcase/vbox-img.cpp
@@ -1645,7 +1645,7 @@ int main(int argc, char *argv[])
 {
     int exitcode = 0;
 
-    int rc = RTR3InitExe(argc, &argv, 0);
+    int rc = RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_STANDALONE_APP);
     if (RT_FAILURE(rc))
         return RTMsgInitFailure(rc);
 
diff --git a/src/VBox/VMM/VMMR0/GVMMR0.cpp b/src/VBox/VMM/VMMR0/GVMMR0.cpp
index 4160425..f834e55 100644
--- a/src/VBox/VMM/VMMR0/GVMMR0.cpp
+++ b/src/VBox/VMM/VMMR0/GVMMR0.cpp
@@ -62,6 +62,7 @@
 
 #include <iprt/asm.h>
 #include <iprt/asm-amd64-x86.h>
+#include <iprt/critsect.h>
 #include <iprt/mem.h>
 #include <iprt/semaphore.h>
 #include <iprt/time.h>
@@ -210,19 +211,20 @@ typedef struct GVMM
     uint32_t volatile   cEMTs;
     /** The number of EMTs that have halted in GVMMR0SchedHalt. */
     uint32_t volatile   cHaltedEMTs;
-    /** Alignment padding. */
-    uint32_t            u32Alignment;
+    /** Mini lock for restricting early wake-ups to one thread. */
+    bool volatile       fDoingEarlyWakeUps;
+    bool                afPadding[3]; /**< explicit alignment padding. */
     /** When the next halted or sleeping EMT will wake up.
      * This is set to 0 when it needs recalculating and to UINT64_MAX when
      * there are no halted or sleeping EMTs in the GVMM. */
     uint64_t            uNsNextEmtWakeup;
     /** The lock used to serialize VM creation, destruction and associated events that
      * isn't performance critical. Owners may acquire the list lock. */
-    RTSEMFASTMUTEX      CreateDestroyLock;
+    RTCRITSECT          CreateDestroyLock;
     /** The lock used to serialize used list updates and accesses.
      * This indirectly includes scheduling since the scheduler will have to walk the
      * used list to examin running VMs. Owners may not acquire any other locks. */
-    RTSEMFASTMUTEX      UsedLock;
+    RTCRITSECTRW        UsedLock;
     /** The handle array.
      * The size of this array defines the maximum number of currently running VMs.
      * The first entry is unused as it represents the NIL handle. */
@@ -242,19 +244,26 @@ typedef struct GVMM
      */
     uint32_t            nsMinSleepCompany;
     /** @gcfgm{/GVMM/EarlyWakeUp1, 32-bit, 0, 100000000, 25000, ns}
-     * The limit for the first round of early wakeups, given in nano seconds.
+     * The limit for the first round of early wake-ups, given in nano seconds.
      */
     uint32_t            nsEarlyWakeUp1;
     /** @gcfgm{/GVMM/EarlyWakeUp2, 32-bit, 0, 100000000, 50000, ns}
-     * The limit for the second round of early wakeups, given in nano seconds.
+     * The limit for the second round of early wake-ups, given in nano seconds.
      */
     uint32_t            nsEarlyWakeUp2;
 
+    /** Set if we're doing early wake-ups.
+     * This reflects  nsEarlyWakeUp1 and nsEarlyWakeUp2.  */
+    bool volatile       fDoEarlyWakeUps;
+
     /** The number of entries in the host CPU array (aHostCpus). */
     uint32_t            cHostCpus;
     /** Per host CPU data (variable length). */
     GVMMHOSTCPU         aHostCpus[1];
 } GVMM;
+AssertCompileMemberAlignment(GVMM, CreateDestroyLock, 8);
+AssertCompileMemberAlignment(GVMM, UsedLock, 8);
+AssertCompileMemberAlignment(GVMM, uNsNextEmtWakeup, 8);
 /** Pointer to the GVMM instance data. */
 typedef GVMM *PGVMM;
 
@@ -329,10 +338,11 @@ GVMMR0DECL(int) GVMMR0Init(void)
     PGVMM pGVMM = (PGVMM)RTMemAllocZ(RT_UOFFSETOF(GVMM, aHostCpus[cHostCpus]));
     if (!pGVMM)
         return VERR_NO_MEMORY;
-    int rc = RTSemFastMutexCreate(&pGVMM->CreateDestroyLock);
+    int rc = RTCritSectInitEx(&pGVMM->CreateDestroyLock, 0, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE,
+                              "GVMM-CreateDestroyLock");
     if (RT_SUCCESS(rc))
     {
-        rc = RTSemFastMutexCreate(&pGVMM->UsedLock);
+        rc = RTCritSectRwInitEx(&pGVMM->UsedLock, 0, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "GVMM-UsedLock");
         if (RT_SUCCESS(rc))
         {
             pGVMM->u32Magic = GVMM_MAGIC;
@@ -379,6 +389,7 @@ GVMMR0DECL(int) GVMMR0Init(void)
                 pGVMM->nsEarlyWakeUp1    = 0;
                 pGVMM->nsEarlyWakeUp2    = 0;
             }
+            pGVMM->fDoEarlyWakeUps = pGVMM->nsEarlyWakeUp1 > 0 && pGVMM->nsEarlyWakeUp2 > 0;
 
             /* The host CPU data. */
             pGVMM->cHostCpus = cHostCpus;
@@ -443,11 +454,9 @@ GVMMR0DECL(int) GVMMR0Init(void)
             }
 
             /* bail out. */
-            RTSemFastMutexDestroy(pGVMM->UsedLock);
-            pGVMM->UsedLock = NIL_RTSEMFASTMUTEX;
+            RTCritSectRwDelete(&pGVMM->UsedLock);
         }
-        RTSemFastMutexDestroy(pGVMM->CreateDestroyLock);
-        pGVMM->CreateDestroyLock = NIL_RTSEMFASTMUTEX;
+        RTCritSectDelete(&pGVMM->CreateDestroyLock);
     }
 
     RTMemFree(pGVMM);
@@ -495,10 +504,8 @@ GVMMR0DECL(void) GVMMR0Term(void)
      * Invalidate the and free resources.
      */
     pGVMM->u32Magic = ~GVMM_MAGIC;
-    RTSemFastMutexDestroy(pGVMM->UsedLock);
-    pGVMM->UsedLock = NIL_RTSEMFASTMUTEX;
-    RTSemFastMutexDestroy(pGVMM->CreateDestroyLock);
-    pGVMM->CreateDestroyLock = NIL_RTSEMFASTMUTEX;
+    RTCritSectRwDelete(&pGVMM->UsedLock);
+    RTCritSectDelete(&pGVMM->CreateDestroyLock);
 
     pGVMM->iFreeHead = 0;
     if (pGVMM->iUsedHead)
@@ -572,14 +579,20 @@ GVMMR0DECL(int) GVMMR0SetConfig(PSUPDRVSESSION pSession, const char *pszName, ui
     else if (!strcmp(pszName, "EarlyWakeUp1"))
     {
         if (u64Value <= RT_NS_100MS)
+        {
             pGVMM->nsEarlyWakeUp1 = u64Value;
+            pGVMM->fDoEarlyWakeUps = pGVMM->nsEarlyWakeUp1 > 0 && pGVMM->nsEarlyWakeUp2 > 0;
+        }
         else
             rc = VERR_OUT_OF_RANGE;
     }
     else if (!strcmp(pszName, "EarlyWakeUp2"))
     {
         if (u64Value <= RT_NS_100MS)
+        {
             pGVMM->nsEarlyWakeUp2 = u64Value;
+            pGVMM->fDoEarlyWakeUps = pGVMM->nsEarlyWakeUp1 > 0 && pGVMM->nsEarlyWakeUp2 > 0;
+        }
         else
             rc = VERR_OUT_OF_RANGE;
     }
@@ -633,33 +646,44 @@ GVMMR0DECL(int) GVMMR0QueryConfig(PSUPDRVSESSION pSession, const char *pszName,
 
 
 /**
- * Try acquire the 'used' lock.
+ * Acquire the 'used' lock in shared mode.
+ *
+ * This prevents destruction of the VM while we're in ring-0.
  *
  * @returns IPRT status code, see RTSemFastMutexRequest.
- * @param   pGVMM   The GVMM instance data.
+ * @param   a_pGVMM     The GVMM instance data.
+ * @sa      GVMMR0_USED_SHARED_UNLOCK, GVMMR0_USED_EXCLUSIVE_LOCK
  */
-DECLINLINE(int) gvmmR0UsedLock(PGVMM pGVMM)
-{
-    LogFlow(("++gvmmR0UsedLock(%p)\n", pGVMM));
-    int rc = RTSemFastMutexRequest(pGVMM->UsedLock);
-    LogFlow(("gvmmR0UsedLock(%p)->%Rrc\n", pGVMM, rc));
-    return rc;
-}
+#define GVMMR0_USED_SHARED_LOCK(a_pGVMM)        RTCritSectRwEnterShared(&(a_pGVMM)->UsedLock)
+
+/**
+ * Release the 'used' lock in when owning it in shared mode.
+ *
+ * @returns IPRT status code, see RTSemFastMutexRequest.
+ * @param   a_pGVMM     The GVMM instance data.
+ * @sa      GVMMR0_USED_SHARED_LOCK
+ */
+#define GVMMR0_USED_SHARED_UNLOCK(a_pGVMM)      RTCritSectRwLeaveShared(&(a_pGVMM)->UsedLock)
 
+/**
+ * Acquire the 'used' lock in exclusive mode.
+ *
+ * Only use this function when making changes to the used list.
+ *
+ * @returns IPRT status code, see RTSemFastMutexRequest.
+ * @param   a_pGVMM     The GVMM instance data.
+ * @sa      GVMMR0_USED_EXCLUSIVE_UNLOCK
+ */
+#define GVMMR0_USED_EXCLUSIVE_LOCK(a_pGVMM)     RTCritSectRwEnterExcl(&(a_pGVMM)->UsedLock)
 
 /**
- * Release the 'used' lock.
+ * Release the 'used' lock when owning it in exclusive mode.
  *
  * @returns IPRT status code, see RTSemFastMutexRelease.
- * @param   pGVMM   The GVMM instance data.
+ * @param   a_pGVMM     The GVMM instance data.
+ * @sa      GVMMR0_USED_EXCLUSIVE_LOCK, GVMMR0_USED_SHARED_UNLOCK
  */
-DECLINLINE(int) gvmmR0UsedUnlock(PGVMM pGVMM)
-{
-    LogFlow(("--gvmmR0UsedUnlock(%p)\n", pGVMM));
-    int rc = RTSemFastMutexRelease(pGVMM->UsedLock);
-    AssertRC(rc);
-    return rc;
-}
+#define GVMMR0_USED_EXCLUSIVE_UNLOCK(a_pGVMM)   RTCritSectRwLeaveExcl(&(a_pGVMM)->UsedLock)
 
 
 /**
@@ -671,7 +695,7 @@ DECLINLINE(int) gvmmR0UsedUnlock(PGVMM pGVMM)
 DECLINLINE(int) gvmmR0CreateDestroyLock(PGVMM pGVMM)
 {
     LogFlow(("++gvmmR0CreateDestroyLock(%p)\n", pGVMM));
-    int rc = RTSemFastMutexRequest(pGVMM->CreateDestroyLock);
+    int rc = RTCritSectEnter(&pGVMM->CreateDestroyLock);
     LogFlow(("gvmmR0CreateDestroyLock(%p)->%Rrc\n", pGVMM, rc));
     return rc;
 }
@@ -686,7 +710,7 @@ DECLINLINE(int) gvmmR0CreateDestroyLock(PGVMM pGVMM)
 DECLINLINE(int) gvmmR0CreateDestroyUnlock(PGVMM pGVMM)
 {
     LogFlow(("--gvmmR0CreateDestroyUnlock(%p)\n", pGVMM));
-    int rc = RTSemFastMutexRelease(pGVMM->CreateDestroyLock);
+    int rc = RTCritSectLeave(&pGVMM->CreateDestroyLock);
     AssertRC(rc);
     return rc;
 }
@@ -782,7 +806,7 @@ GVMMR0DECL(int) GVMMR0CreateVM(PSUPDRVSESSION pSession, uint32_t cCpus, PVM *ppV
                 /*
                  * Move the handle from the free to used list and perform permission checks.
                  */
-                rc = gvmmR0UsedLock(pGVMM);
+                rc = GVMMR0_USED_EXCLUSIVE_LOCK(pGVMM);
                 AssertRC(rc);
 
                 pGVMM->iFreeHead = pHandle->iNext;
@@ -796,7 +820,7 @@ GVMMR0DECL(int) GVMMR0CreateVM(PSUPDRVSESSION pSession, uint32_t cCpus, PVM *ppV
                 pHandle->hEMT0    = NIL_RTNATIVETHREAD;
                 pHandle->ProcId   = NIL_RTPROCESS;
 
-                gvmmR0UsedUnlock(pGVMM);
+                GVMMR0_USED_EXCLUSIVE_UNLOCK(pGVMM);
 
                 rc = SUPR0ObjVerifyAccess(pHandle->pvObj, pSession, NULL);
                 if (RT_SUCCESS(rc))
@@ -876,7 +900,7 @@ GVMMR0DECL(int) GVMMR0CreateVM(PSUPDRVSESSION pSession, uint32_t cCpus, PVM *ppV
                                         AssertPtr((void *)pVM->paVMPagesR3);
 
                                         /* complete the handle - take the UsedLock sem just to be careful. */
-                                        rc = gvmmR0UsedLock(pGVMM);
+                                        rc = GVMMR0_USED_EXCLUSIVE_LOCK(pGVMM);
                                         AssertRC(rc);
 
                                         pHandle->pVM                  = pVM;
@@ -893,13 +917,15 @@ GVMMR0DECL(int) GVMMR0CreateVM(PSUPDRVSESSION pSession, uint32_t cCpus, PVM *ppV
                                         {
                                             VBOXVMM_R0_GVMM_VM_CREATED(pGVM, pVM, ProcId, (void *)hEMT0, cCpus);
 
-                                            gvmmR0UsedUnlock(pGVMM);
+                                            GVMMR0_USED_EXCLUSIVE_UNLOCK(pGVMM);
                                             gvmmR0CreateDestroyUnlock(pGVMM);
 
                                             *ppVM = pVM;
                                             Log(("GVMMR0CreateVM: pVM=%p pVMR3=%p pGVM=%p hGVM=%d\n", pVM, pVM->pVMR3, pGVM, iHandle));
                                             return VINF_SUCCESS;
                                         }
+
+                                        GVMMR0_USED_EXCLUSIVE_UNLOCK(pGVMM);
                                     }
 
                                     RTR0MemObjFree(pGVM->gvmm.s.VMMapObj, false /* fFreeMappings */);
@@ -1191,7 +1217,7 @@ static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, v
 
     int rc = gvmmR0CreateDestroyLock(pGVMM);
     AssertRC(rc);
-    rc = gvmmR0UsedLock(pGVMM);
+    rc = GVMMR0_USED_EXCLUSIVE_LOCK(pGVMM);
     AssertRC(rc);
 
     /*
@@ -1200,7 +1226,7 @@ static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, v
     if (RT_UNLIKELY(pHandle->iNext >= RT_ELEMENTS(pGVMM->aHandles)))
     {
         SUPR0Printf("GVM: used list index %d is out of range!\n", pHandle->iNext);
-        gvmmR0UsedUnlock(pGVMM);
+        GVMMR0_USED_EXCLUSIVE_UNLOCK(pGVMM);
         gvmmR0CreateDestroyUnlock(pGVMM);
         return;
     }
@@ -1216,7 +1242,7 @@ static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, v
             if (RT_UNLIKELY(iPrev >= RT_ELEMENTS(pGVMM->aHandles)))
             {
                 SUPR0Printf("GVM: used list index %d is out of range!\n", iPrev);
-                gvmmR0UsedUnlock(pGVMM);
+                GVMMR0_USED_EXCLUSIVE_UNLOCK(pGVMM);
                 gvmmR0CreateDestroyUnlock(pGVMM);
                 return;
             }
@@ -1233,7 +1259,7 @@ static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, v
         if (!iPrev)
         {
             SUPR0Printf("GVM: can't find the handle previous previous of %d!\n", pHandle->iSelf);
-            gvmmR0UsedUnlock(pGVMM);
+            GVMMR0_USED_EXCLUSIVE_UNLOCK(pGVMM);
             gvmmR0CreateDestroyUnlock(pGVMM);
             return;
         }
@@ -1252,7 +1278,7 @@ static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, v
         &&  pGVM->u32Magic == GVM_MAGIC)
     {
         pGVMM->cEMTs -= pGVM->cCpus;
-        gvmmR0UsedUnlock(pGVMM);
+        GVMMR0_USED_EXCLUSIVE_UNLOCK(pGVMM);
 
         gvmmR0CleanupVM(pGVM);
 
@@ -1298,7 +1324,7 @@ static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, v
         RTMemFree(pGVM);
 
         /* Re-acquire the UsedLock before freeing the handle since we're updating handle fields. */
-        rc = gvmmR0UsedLock(pGVMM);
+        rc = GVMMR0_USED_EXCLUSIVE_LOCK(pGVMM);
         AssertRC(rc);
     }
     /* else: GVMMR0CreateVM cleanup. */
@@ -1315,7 +1341,7 @@ static DECLCALLBACK(void) gvmmR0HandleObjDestructor(void *pvObj, void *pvGVMM, v
     ASMAtomicWriteHandle(&pHandle->hEMT0,        NIL_RTNATIVETHREAD);
     ASMAtomicWriteU32(&pHandle->ProcId,          NIL_RTPROCESS);
 
-    gvmmR0UsedUnlock(pGVMM);
+    GVMMR0_USED_EXCLUSIVE_UNLOCK(pGVMM);
     gvmmR0CreateDestroyUnlock(pGVMM);
     LogFlow(("gvmmR0HandleObjDestructor: returns\n"));
 }
@@ -1339,7 +1365,7 @@ GVMMR0DECL(int) GVMMR0RegisterVCpu(PVM pVM, VMCPUID idCpu)
      */
     PGVM pGVM;
     PGVMM pGVMM;
-    int rc = gvmmR0ByVM(pVM, &pGVM, &pGVMM, false /* fTakeUsedLock */);
+    int rc = gvmmR0ByVM(pVM, &pGVM, &pGVMM, false /* fTakeUsedLock */); /** @todo take lock here. */
     if (RT_FAILURE(rc))
         return rc;
 
@@ -1396,9 +1422,11 @@ GVMMR0DECL(PGVM) GVMMR0ByHandle(uint32_t hGVM)
  * @param   pVM             Pointer to the VM.
  * @param   ppGVM           Where to store the GVM pointer.
  * @param   ppGVMM          Where to store the pointer to the GVMM instance data.
- * @param   fTakeUsedLock   Whether to take the used lock or not.
- *                          Be very careful if not taking the lock as it's possible that
- *                          the VM will disappear then.
+ * @param   fTakeUsedLock   Whether to take the used lock or not.  We take it in
+ *                          shared mode when requested.
+ *
+ *                          Be very careful if not taking the lock as it's
+ *                          possible that the VM will disappear then!
  *
  * @remark  This will not assert on an invalid pVM but try return silently.
  */
@@ -1430,7 +1458,7 @@ static int gvmmR0ByVM(PVM pVM, PGVM *ppGVM, PGVMM *ppGVMM, bool fTakeUsedLock)
     PGVM pGVM;
     if (fTakeUsedLock)
     {
-        int rc = gvmmR0UsedLock(pGVMM);
+        int rc = GVMMR0_USED_SHARED_LOCK(pGVMM);
         AssertRCReturn(rc, rc);
 
         pGVM = pHandle->pGVM;
@@ -1440,7 +1468,7 @@ static int gvmmR0ByVM(PVM pVM, PGVM *ppGVM, PGVMM *ppGVMM, bool fTakeUsedLock)
                         ||  !VALID_PTR(pGVM)
                         ||  pGVM->pVM != pVM))
         {
-            gvmmR0UsedUnlock(pGVMM);
+            GVMMR0_USED_SHARED_UNLOCK(pGVMM);
             return VERR_INVALID_HANDLE;
         }
     }
@@ -1475,6 +1503,8 @@ static int gvmmR0ByVM(PVM pVM, PGVM *ppGVM, PGVMM *ppGVMM, bool fTakeUsedLock)
  *
  * @remark  This will not take the 'used'-lock because it doesn't do
  *          nesting and this function will be used from under the lock.
+ *          Update: This is no longer true.  Consider taking the lock in shared
+ *          mode!
  */
 GVMMR0DECL(int) GVMMR0ByVM(PVM pVM, PGVM *ppGVM)
 {
@@ -1632,8 +1662,7 @@ static unsigned gvmmR0SchedDoWakeUps(PGVMM pGVMM, uint64_t u64Now)
      * Skip this if we've got disabled because of high resolution wakeups or by
      * the user.
      */
-    if (   !pGVMM->nsEarlyWakeUp1
-        && !pGVMM->nsEarlyWakeUp2)
+    if (!pGVMM->fDoEarlyWakeUps)
         return 0;
 
 /** @todo Rewrite this algorithm. See performance defect XYZ. */
@@ -1647,6 +1676,12 @@ static unsigned gvmmR0SchedDoWakeUps(PGVMM pGVMM, uint64_t u64Now)
         return 0;
 
     /*
+     * Only one thread doing this at a time.
+     */
+    if (!ASMAtomicCmpXchgBool(&pGVMM->fDoingEarlyWakeUps, true, false))
+        return 0;
+
+    /*
      * The first pass will wake up VMs which have actually expired
      * and look for VMs that should be woken up in the 2nd and 3rd passes.
      */
@@ -1760,6 +1795,7 @@ static unsigned gvmmR0SchedDoWakeUps(PGVMM pGVMM, uint64_t u64Now)
      */
     pGVMM->uNsNextEmtWakeup = u64Min;
 
+    ASMAtomicWriteBool(&pGVMM->fDoingEarlyWakeUps, false);
     return cWoken;
 }
 
@@ -1792,12 +1828,16 @@ GVMMR0DECL(int) GVMMR0SchedHalt(PVM pVM, VMCPUID idCpu, uint64_t u64ExpireGipTim
     Assert(!pCurGVCpu->gvmm.s.u64HaltExpire);
 
     /*
-     * Take the UsedList semaphore, get the current time
-     * and check if anyone needs waking up.
-     * Interrupts must NOT be disabled at this point because we ask for GIP time!
+     * If we're doing early wake-ups, we must take the UsedList lock before we
+     * start querying the current time.
+     * Note! Interrupts must NOT be disabled at this point because we ask for GIP time!
      */
-    rc = gvmmR0UsedLock(pGVMM);
-    AssertRC(rc);
+    bool const fDoEarlyWakeUps = pGVMM->fDoEarlyWakeUps;
+    if (fDoEarlyWakeUps)
+    {
+        rc = GVMMR0_USED_SHARED_LOCK(pGVMM);
+        AssertRC(rc);
+    }
 
     pCurGVCpu->gvmm.s.iCpuEmt = ASMGetApicId();
 
@@ -1807,7 +1847,9 @@ GVMMR0DECL(int) GVMMR0SchedHalt(PVM pVM, VMCPUID idCpu, uint64_t u64ExpireGipTim
     Assert(ASMGetFlags() & X86_EFL_IF);
     const uint64_t u64NowSys = RTTimeSystemNanoTS();
     const uint64_t u64NowGip = RTTimeNanoTS();
-    pGVM->gvmm.s.StatsSched.cHaltWakeUps += gvmmR0SchedDoWakeUps(pGVMM, u64NowGip);
+
+    if (fDoEarlyWakeUps)
+        pGVM->gvmm.s.StatsSched.cHaltWakeUps += gvmmR0SchedDoWakeUps(pGVMM, u64NowGip);
 
     /*
      * Go to sleep if we must...
@@ -1822,11 +1864,14 @@ GVMMR0DECL(int) GVMMR0SchedHalt(PVM pVM, VMCPUID idCpu, uint64_t u64ExpireGipTim
         pGVM->gvmm.s.StatsSched.cHaltBlocking++;
         if (cNsInterval > RT_NS_1SEC)
             u64ExpireGipTime = u64NowGip + RT_NS_1SEC;
-        if (u64ExpireGipTime < pGVMM->uNsNextEmtWakeup)
-            pGVMM->uNsNextEmtWakeup = u64ExpireGipTime;
         ASMAtomicWriteU64(&pCurGVCpu->gvmm.s.u64HaltExpire, u64ExpireGipTime);
         ASMAtomicIncU32(&pGVMM->cHaltedEMTs);
-        gvmmR0UsedUnlock(pGVMM);
+        if (fDoEarlyWakeUps)
+        {
+            if (u64ExpireGipTime < pGVMM->uNsNextEmtWakeup)
+                pGVMM->uNsNextEmtWakeup = u64ExpireGipTime;
+            GVMMR0_USED_SHARED_UNLOCK(pGVMM);
+        }
 
         rc = RTSemEventMultiWaitEx(pCurGVCpu->gvmm.s.HaltEventMulti,
                                    RTSEMWAIT_FLAGS_ABSOLUTE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_INTERRUPTIBLE,
@@ -1847,7 +1892,8 @@ GVMMR0DECL(int) GVMMR0SchedHalt(PVM pVM, VMCPUID idCpu, uint64_t u64ExpireGipTim
     else
     {
         pGVM->gvmm.s.StatsSched.cHaltNotBlocking++;
-        gvmmR0UsedUnlock(pGVMM);
+        if (fDoEarlyWakeUps)
+            GVMMR0_USED_SHARED_UNLOCK(pGVMM);
         RTSemEventMultiReset(pCurGVCpu->gvmm.s.HaltEventMulti);
     }
 
@@ -1926,7 +1972,7 @@ GVMMR0DECL(int) GVMMR0SchedWakeUpEx(PVM pVM, VMCPUID idCpu, bool fTakeUsedLock)
              */
             rc = gvmmR0SchedWakeUpOne(pGVM, &pGVM->aCpus[idCpu]);
 
-            if (fTakeUsedLock)
+            if (fTakeUsedLock && pGVMM->fDoEarlyWakeUps)
             {
                 /*
                  * While we're here, do a round of scheduling.
@@ -1941,7 +1987,7 @@ GVMMR0DECL(int) GVMMR0SchedWakeUpEx(PVM pVM, VMCPUID idCpu, bool fTakeUsedLock)
 
         if (fTakeUsedLock)
         {
-            int rc2 = gvmmR0UsedUnlock(pGVMM);
+            int rc2 = GVMMR0_USED_SHARED_UNLOCK(pGVMM);
             AssertRC(rc2);
         }
     }
@@ -2023,7 +2069,7 @@ GVMMR0DECL(int) GVMMR0SchedPokeEx(PVM pVM, VMCPUID idCpu, bool fTakeUsedLock)
 
         if (fTakeUsedLock)
         {
-            int rc2 = gvmmR0UsedUnlock(pGVMM);
+            int rc2 = GVMMR0_USED_SHARED_UNLOCK(pGVMM);
             AssertRC(rc2);
         }
     }
@@ -2087,7 +2133,7 @@ GVMMR0DECL(int) GVMMR0SchedWakeUpAndPokeCpus(PVM pVM, PCVMCPUSET pSleepSet, PCVM
                 gvmmR0SchedPokeOne(pGVM, &pVM->aCpus[idCpu]);
         }
 
-        int rc2 = gvmmR0UsedUnlock(pGVMM);
+        int rc2 = GVMMR0_USED_SHARED_UNLOCK(pGVMM);
         AssertRC(rc2);
     }
 
@@ -2141,22 +2187,29 @@ GVMMR0DECL(int) GVMMR0SchedPoll(PVM pVM, VMCPUID idCpu, bool fYield)
     int rc = gvmmR0ByVMAndEMT(pVM, idCpu, &pGVM, &pGVMM);
     if (RT_SUCCESS(rc))
     {
-        rc = gvmmR0UsedLock(pGVMM);
-        AssertRC(rc);
-        pGVM->gvmm.s.StatsSched.cPollCalls++;
+        /*
+         * We currently only implement helping doing wakeups (fYield = false), so don't
+         * bother taking the lock if gvmmR0SchedDoWakeUps is not going to do anything.
+         */
+        if (!fYield && pGVMM->fDoEarlyWakeUps)
+        {
+            rc = GVMMR0_USED_SHARED_LOCK(pGVMM); AssertRC(rc);
+            pGVM->gvmm.s.StatsSched.cPollCalls++;
 
-        Assert(ASMGetFlags() & X86_EFL_IF);
-        const uint64_t u64Now = RTTimeNanoTS(); /* (GIP time) */
+            Assert(ASMGetFlags() & X86_EFL_IF);
+            const uint64_t u64Now = RTTimeNanoTS(); /* (GIP time) */
 
-        if (!fYield)
             pGVM->gvmm.s.StatsSched.cPollWakeUps += gvmmR0SchedDoWakeUps(pGVMM, u64Now);
-        else
-        {
-            /** @todo implement this... */
-            rc = VERR_NOT_IMPLEMENTED;
-        }
 
-        gvmmR0UsedUnlock(pGVMM);
+            GVMMR0_USED_SHARED_UNLOCK(pGVMM);
+        }
+        /*
+         * Not quite sure what we could do here...
+         */
+        else if (fYield)
+            rc = VERR_NOT_IMPLEMENTED; /** @todo implement this... */
+        else
+            rc = VINF_SUCCESS;
     }
 
     LogFlow(("GVMMR0SchedWakeUp: returns %Rrc\n", rc));
@@ -2368,7 +2421,7 @@ GVMMR0DECL(int) GVMMR0QueryStatistics(PGVMMSTATS pStats, PSUPDRVSESSION pSession
         GVMM_GET_VALID_INSTANCE(pGVMM, VERR_GVMM_INSTANCE);
         memset(&pStats->SchedVM, 0, sizeof(pStats->SchedVM));
 
-        int rc = gvmmR0UsedLock(pGVMM);
+        int rc = GVMMR0_USED_SHARED_LOCK(pGVMM);
         AssertRCReturn(rc, rc);
     }
 
@@ -2441,7 +2494,7 @@ GVMMR0DECL(int) GVMMR0QueryStatistics(PGVMMSTATS pStats, PSUPDRVSESSION pSession
     }
     pStats->cHostCpus = iDstCpu;
 
-    gvmmR0UsedUnlock(pGVMM);
+    GVMMR0_USED_SHARED_UNLOCK(pGVMM);
 
     return VINF_SUCCESS;
 }
@@ -2516,7 +2569,7 @@ GVMMR0DECL(int) GVMMR0ResetStatistics(PCGVMMSTATS pStats, PSUPDRVSESSION pSessio
     {
         GVMM_GET_VALID_INSTANCE(pGVMM, VERR_GVMM_INSTANCE);
 
-        int rc = gvmmR0UsedLock(pGVMM);
+        int rc = GVMMR0_USED_SHARED_LOCK(pGVMM);
         AssertRCReturn(rc, rc);
     }
 
@@ -2556,7 +2609,7 @@ GVMMR0DECL(int) GVMMR0ResetStatistics(PCGVMMSTATS pStats, PSUPDRVSESSION pSessio
         }
     }
 
-    gvmmR0UsedUnlock(pGVMM);
+    GVMMR0_USED_SHARED_UNLOCK(pGVMM);
 
     return VINF_SUCCESS;
 }
diff --git a/src/VBox/VMM/VMMR3/VMReq.cpp b/src/VBox/VMM/VMMR3/VMReq.cpp
index ec3ab79..57ff973 100644
--- a/src/VBox/VMM/VMMR3/VMReq.cpp
+++ b/src/VBox/VMM/VMMR3/VMReq.cpp
@@ -1193,7 +1193,7 @@ static int  vmR3ReqProcessOneU(PUVM pUVM, PVMREQ pReq)
 {
     LogFlow(("vmR3ReqProcessOneU: pReq=%p type=%d fFlags=%#x\n", pReq, pReq->enmType, pReq->fFlags));
 
-#if 1 /*def VBOX_STRICT */
+#if 0 /* Should not be necessary, see trunk r104712. Fixes out of memory runtime error. */
     /*
      * Disable rendezvous if servicing a priority request.  Priority requests
      * can not make use of the EMT rendezvous API.
@@ -1344,7 +1344,7 @@ static int  vmR3ReqProcessOneU(PUVM pUVM, PVMREQ pReq)
         }
     }
 
-#if 1 /*def VBOX_STRICT */
+#if 0 /* Should not be necessary, see trunk r104712. Fixes out of memory runtime error. */
     /*
      * Restore the rendezvous disabled state.
      */
diff --git a/src/bldprogs/Makefile.kmk b/src/bldprogs/Makefile.kmk
index 2e0f671..aea5796 100644
--- a/src/bldprogs/Makefile.kmk
+++ b/src/bldprogs/Makefile.kmk
@@ -61,6 +61,9 @@ BLDPROGS.win += VBoxPeSetVersion
 VBoxPeSetVersion_TEMPLATE = VBoxBldProg
 VBoxPeSetVersion_SOURCES  = VBoxPeSetVersion.cpp
 
+BLDPROGS.win += VBoxCheckImports
+VBoxCheckImports_TEMPLATE = VBoxBldProg
+VBoxCheckImports_SOURCES  = VBoxCheckImports.cpp
 
 BLDPROGS += VBoxDef2LazyLoad
 VBoxDef2LazyLoad_TEMPLATE = VBoxBldProg
diff --git a/src/bldprogs/VBoxCheckImports.cpp b/src/bldprogs/VBoxCheckImports.cpp
new file mode 100644
index 0000000..96543d9
--- /dev/null
+++ b/src/bldprogs/VBoxCheckImports.cpp
@@ -0,0 +1,371 @@
+/* $Id: VBoxCheckImports.cpp $ */
+/** @file
+ * IPRT - Checks that a windows image only imports from a given set of DLLs.
+ */
+
+/*
+ * Copyright (C) 2012-2015 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include "../VBox/Runtime/include/internal/ldrPE.h"
+#include "../VBox/Runtime/include/internal/ldrMZ.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/*********************************************************************************************************************************
+*   Structures and Typedefs                                                                                                      *
+*********************************************************************************************************************************/
+typedef struct
+{
+    const char *pszImage;
+    FILE       *pFile;
+    bool        f32Bit;
+    union
+    {
+        IMAGE_NT_HEADERS32 Nt32;
+        IMAGE_NT_HEADERS64 Nt64;
+    } Hdrs;
+
+    uint32_t                cSections;
+    PIMAGE_SECTION_HEADER   paSections;
+} MYIMAGE;
+
+
+static bool Failed(MYIMAGE *pThis, const char *pszFmt, ...)
+{
+    va_list va;
+    fprintf(stderr, "error '%s': ", pThis->pszImage);
+    va_start(va, pszFmt);
+    vfprintf(stderr, pszFmt, va);
+    va_end(va);
+    fprintf(stderr, "\n");
+    return false;
+}
+
+
+static bool ReadPeHeaders(MYIMAGE *pThis)
+{
+    /*
+     * MZ header.
+     */
+    IMAGE_DOS_HEADER MzHdr;
+    if (fread(&MzHdr, sizeof(MzHdr), 1, pThis->pFile) != 1)
+        return Failed(pThis, "Reading DOS header");
+
+    if (MzHdr.e_magic != IMAGE_DOS_SIGNATURE)
+        return Failed(pThis, "No MZ magic (found %#x)", MzHdr.e_magic);
+
+    if (fseek(pThis->pFile, MzHdr.e_lfanew, SEEK_SET) != 0)
+        return Failed(pThis, "Seeking to %#lx", (unsigned long)MzHdr.e_lfanew);
+
+    /*
+     * NT signature + file header.
+     */
+    if (fread(&pThis->Hdrs.Nt32, offsetof(IMAGE_NT_HEADERS32, OptionalHeader), 1, pThis->pFile) != 1)
+        return Failed(pThis, "Reading NT file header");
+
+    if (pThis->Hdrs.Nt32.Signature != IMAGE_NT_SIGNATURE)
+        return Failed(pThis, "No PE magic (found %#x)", pThis->Hdrs.Nt32.Signature);
+
+    if (pThis->Hdrs.Nt32.FileHeader.SizeOfOptionalHeader == sizeof(pThis->Hdrs.Nt32.OptionalHeader))
+        pThis->f32Bit = true;
+    else if (pThis->Hdrs.Nt32.FileHeader.SizeOfOptionalHeader == sizeof(pThis->Hdrs.Nt64.OptionalHeader))
+        pThis->f32Bit = false;
+    else
+        return Failed(pThis, "Unsupported SizeOfOptionalHeaders value: %#x",
+                      pThis->Hdrs.Nt32.FileHeader.SizeOfOptionalHeader);
+
+    /*
+     * NT optional header.
+     */
+    if (fread(&pThis->Hdrs.Nt32.OptionalHeader, pThis->Hdrs.Nt32.FileHeader.SizeOfOptionalHeader, 1, pThis->pFile) != 1)
+        return Failed(pThis, "Reading NT optional header");
+
+    if (   pThis->Hdrs.Nt32.OptionalHeader.Magic
+        != (pThis->f32Bit ? IMAGE_NT_OPTIONAL_HDR32_MAGIC : IMAGE_NT_OPTIONAL_HDR64_MAGIC) )
+        return Failed(pThis, "Bad optional header magic: %#x", pThis->Hdrs.Nt32.OptionalHeader.Magic);
+
+    uint32_t NumberOfRvaAndSizes = pThis->f32Bit
+                                 ? pThis->Hdrs.Nt32.OptionalHeader.NumberOfRvaAndSizes
+                                 : pThis->Hdrs.Nt64.OptionalHeader.NumberOfRvaAndSizes;
+    if (NumberOfRvaAndSizes != IMAGE_NUMBEROF_DIRECTORY_ENTRIES)
+        return Failed(pThis, "Unsupported NumberOfRvaAndSizes value: %#x", NumberOfRvaAndSizes);
+
+    /*
+     * Read the section table.
+     */
+    pThis->cSections  = pThis->Hdrs.Nt32.FileHeader.NumberOfSections;
+    if (!pThis->cSections)
+        return Failed(pThis, "No sections in image!");
+    pThis->paSections = (PIMAGE_SECTION_HEADER)calloc(sizeof(pThis->paSections[0]), pThis->cSections);
+    if (!pThis->paSections)
+        return Failed(pThis, "Out of memory!");
+    if (fread(pThis->paSections, sizeof(pThis->paSections[0]), pThis->cSections, pThis->pFile) != pThis->cSections)
+        return Failed(pThis, "Reading NT section headers");
+
+
+    return true;
+}
+
+
+static bool ReadAtRva(MYIMAGE *pThis, uint32_t uRva, void *pvBuf, size_t cbToRead)
+{
+    unsigned const uRvaOrg     = uRva;
+    size_t   const cbToReadOrg = cbToRead;
+
+    /*
+     * Header section.
+     */
+    int      iSh        = -1;
+    uint32_t uSectRva   = 0;
+    uint32_t offSectRaw = 0;
+    uint32_t cbSectRaw  = pThis->f32Bit
+                        ? pThis->Hdrs.Nt32.OptionalHeader.SizeOfHeaders
+                        : pThis->Hdrs.Nt64.OptionalHeader.SizeOfHeaders;
+    uint32_t cbSectMax  = pThis->paSections[0].VirtualAddress;
+
+    for (;;)
+    {
+        /* Read if we've got a match. */
+        uint32_t off = uRva - uSectRva;
+        if (off < cbSectMax)
+        {
+            uint32_t cbThis = cbSectMax - off;
+            if (cbThis > cbToRead)
+                cbThis = (uint32_t)cbToRead;
+
+            memset(pvBuf, 0, cbThis);
+
+            if (off < cbSectRaw)
+            {
+                if (fseek(pThis->pFile, offSectRaw + off, SEEK_SET) != 0)
+                    return Failed(pThis, "Seeking to %#x", offSectRaw + off);
+                if (fread(pvBuf, RT_MIN(cbThis, cbSectRaw - off), 1, pThis->pFile) != 1)
+                    return Failed(pThis, "Reading %u bytes at %#x", RT_MIN(cbThis, cbSectRaw - off), offSectRaw + off);
+            }
+
+            cbToRead -= cbThis;
+            if (!cbToRead)
+                return true;
+            pvBuf = (uint8_t *)pvBuf + cbThis;
+        }
+
+        /* next section */
+        iSh++;
+        if ((unsigned)iSh >= pThis->cSections)
+            return Failed(pThis, "RVA %#x LB %u is outside the image", uRvaOrg, cbToReadOrg);
+        uSectRva   = pThis->paSections[iSh].VirtualAddress;
+        offSectRaw = pThis->paSections[iSh].PointerToRawData;
+        cbSectRaw  = pThis->paSections[iSh].SizeOfRawData;
+        if ((unsigned)iSh + 1 < pThis->cSections)
+            cbSectMax = pThis->paSections[iSh + 1].VirtualAddress - uSectRva;
+        else
+            cbSectMax = pThis->paSections[iSh].Misc.VirtualSize;
+    }
+}
+
+
+static bool ReadStringAtRva(MYIMAGE *pThis, uint32_t uRva, char *pszBuf, size_t cbMax)
+{
+    uint32_t const uRvaOrg = uRva;
+
+    /*
+     * Try read the whole string at once.
+     */
+    uint32_t cbImage = pThis->f32Bit
+                     ? pThis->Hdrs.Nt32.OptionalHeader.SizeOfImage
+                     : pThis->Hdrs.Nt64.OptionalHeader.SizeOfImage;
+    uint32_t cbThis = uRva < cbImage ? cbImage - uRva : 1;
+    if (cbThis > cbMax)
+        cbThis = (uint32_t)cbMax;
+    if (!ReadAtRva(pThis, uRva, pszBuf, cbThis))
+        return false;
+    if (memchr(pszBuf, 0, cbThis) != NULL)
+        return true;
+
+    /*
+     * Read more, byte-by-byte.
+     */
+    for (;;)
+    {
+        cbMax -= cbThis;
+        if (!cbMax)
+            return Failed(pThis, "String to long at %#x", uRvaOrg);
+        pszBuf += cbThis;
+        uRva   += cbThis;
+
+        cbThis = 1;
+        if (!ReadAtRva(pThis, uRva, pszBuf, cbThis))
+            return false;
+        if (!*pszBuf)
+            return true;
+    }
+}
+
+
+static void *ReadAtRvaAlloc(MYIMAGE *pThis, uint32_t uRva, size_t cbToRead)
+{
+    void *pvBuf = malloc(cbToRead);
+    if (pvBuf)
+    {
+        if (ReadAtRva(pThis, uRva, pvBuf, cbToRead))
+            return pvBuf;
+        free(pvBuf);
+    }
+    else
+        Failed(pThis, "Out of memory!");
+    return NULL;
+}
+
+
+static bool ParseAndCheckImports(MYIMAGE *pThis,  const char **papszAllowed, unsigned cAllowed)
+{
+    /*
+     * Do we have an import directory? If so, read it.
+     */
+    IMAGE_DATA_DIRECTORY ImpDir = pThis->f32Bit
+                                ? pThis->Hdrs.Nt32.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]
+                                : pThis->Hdrs.Nt64.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
+    if (ImpDir.Size == 0)
+        return true;
+
+    uint32_t cImps = ImpDir.Size / sizeof(IMAGE_IMPORT_DESCRIPTOR);
+    if (cImps * sizeof(IMAGE_IMPORT_DESCRIPTOR) != ImpDir.Size)
+        return Failed(pThis, "Import directory size is not a multiple of IMAGE_IMPORT_DESCRIPTOR: %#x", ImpDir.Size);
+
+    PIMAGE_IMPORT_DESCRIPTOR paImps = (PIMAGE_IMPORT_DESCRIPTOR)ReadAtRvaAlloc(pThis, ImpDir.VirtualAddress, ImpDir.Size);
+    if (!paImps)
+        return false;
+
+    /* There is usually an empty entry at the end. */
+    if (   paImps[cImps - 1].Name       == 0
+        || paImps[cImps - 1].FirstThunk == 0)
+           cImps--;
+
+    /*
+     * Do the processing.
+     */
+    bool fRc = true;
+    for (uint32_t i = 0; i < cImps; i++)
+    {
+        /* Read the import name string. */
+        char szName[128];
+        if (!ReadStringAtRva(pThis, paImps[i].Name, szName, sizeof(szName)))
+        {
+            fRc = false;
+            break;
+        }
+
+        /* Check it against the list of allowed DLLs. */
+        bool fFound = false;
+        unsigned j = cAllowed;
+        while (j-- > 0)
+            if (stricmp(papszAllowed[j], szName) == 0)
+            {
+                fFound = true;
+                break;
+            }
+        if (!fFound)
+            fRc = Failed(pThis, "Illegal import: '%s'", szName);
+    }
+
+    free(paImps);
+    return fRc;
+}
+
+
+static int usage(const char *argv0)
+{
+    printf("usage: %s --image <image> [allowed-dll [..]]\n");
+    return RTEXITCODE_SUCCESS;
+}
+
+
+int main(int argc, char **argv)
+{
+    /*
+     * Parse arguments.
+     */
+    const char  *pszImage     = NULL;
+    const char **papszAllowed = (const char **)calloc(argc, sizeof(const char *));
+    unsigned     cAllowed     = 0;
+
+    for (int i = 1; i < argc; i++)
+    {
+        const char *psz = argv[i];
+        if (*psz == '-')
+        {
+            if (!strcmp(psz, "--image") || !strcmp(psz, "-i"))
+            {
+                if (++i >= argc)
+                {
+                    fprintf(stderr, "syntax error: File name expected after '%s'.\n", psz);
+                    return RTEXITCODE_SYNTAX;
+                }
+                pszImage = argv[i];
+            }
+            else if (   !strcmp(psz, "--help")
+                     || !strcmp(psz, "-help")
+                     || !strcmp(psz, "-h")
+                     || !strcmp(psz, "-?") )
+                return usage(argv[0]);
+            else if (   !strcmp(psz, "--version")
+                     || !strcmp(psz, "-V"))
+            {
+                printf("$Revision: 105009 $\n");
+                return RTEXITCODE_SUCCESS;
+            }
+            else
+            {
+                fprintf(stderr, "syntax error: Unknown option '%s'.\n", psz);
+                return RTEXITCODE_SYNTAX;
+            }
+        }
+        else
+            papszAllowed[cAllowed++] = argv[i];
+    }
+
+    if (!pszImage)
+    {
+        fprintf(stderr, "syntax error: No input file specified.\n");
+        return RTEXITCODE_SYNTAX;
+    }
+
+    /*
+     * Open the image and process headers.
+     */
+    RTEXITCODE  rcExit = RTEXITCODE_FAILURE;
+    MYIMAGE     MyImage;
+    memset(&MyImage, 0, sizeof(MyImage));
+    MyImage.pszImage = pszImage;
+    MyImage.pFile     = fopen(pszImage, "rb");
+    if (MyImage.pFile)
+    {
+        if (   ReadPeHeaders(&MyImage)
+            && ParseAndCheckImports(&MyImage, papszAllowed, cAllowed))
+               rcExit = RTEXITCODE_SUCCESS;
+
+        fclose(MyImage.pFile);
+        free(MyImage.paSections);
+    }
+    else
+        Failed(&MyImage, "Failed to open image for binary reading.");
+
+    return rcExit;
+}
+
+
diff --git a/src/bldprogs/VBoxDef2LazyLoad.cpp b/src/bldprogs/VBoxDef2LazyLoad.cpp
index a513bc8..2bb08bf 100644
--- a/src/bldprogs/VBoxDef2LazyLoad.cpp
+++ b/src/bldprogs/VBoxDef2LazyLoad.cpp
@@ -33,8 +33,12 @@
 typedef struct MYEXPORT
 {
     struct MYEXPORT    *pNext;
-    bool                fNoName;
+    /** Pointer to unmangled name for stdcall (after szName), NULL if not. */
+    char               *pszUnstdcallName;
+    /** Pointer to the exported name. */
+    char const         *pszExportedNm;
     unsigned            uOrdinal;
+    bool                fNoName;
     char                szName[1];
 } MYEXPORT;
 typedef MYEXPORT *PMYEXPORT;
@@ -52,6 +56,7 @@ static const char  *g_apszInputs[8] = { NULL, NULL, NULL, NULL,  NULL, NULL, NUL
 static unsigned     g_cInputs = 0;
 static bool         g_fIgnoreData = true;
 static bool         g_fWithExplictLoadFunction = false;
+static bool         g_fSystemLibrary = false;
 /** @} */
 
 /** Pointer to the export name list head. */
@@ -174,7 +179,7 @@ static RTEXITCODE parseInputInner(FILE *pInput, const char *pszInput)
                 psz = leftStrip(psz + wordLength(psz));
             }
 
-            bool     fNoName  = true;
+            bool     fNoName  = false;
             unsigned uOrdinal = ~0U;
             if (*psz == '@')
             {
@@ -194,13 +199,8 @@ static RTEXITCODE parseInputInner(FILE *pInput, const char *pszInput)
                 cch = wordLength(psz);
                 if (WORD_CMP(psz, cch, "NONAME"))
                 {
-#if 0
                     fNoName = true;
                     psz = leftStrip(psz + cch);
-#else
-                    fprintf(stderr, "%s:%u: error: NONAME export not implemented.\n", pszInput, iLine);
-                    return RTEXITCODE_FAILURE;
-#endif
                 }
             }
 
@@ -226,9 +226,25 @@ static RTEXITCODE parseInputInner(FILE *pInput, const char *pszInput)
             }
 
             /*
+             * Check for stdcall mangling.
+             */
+            size_t   cbExp = sizeof(MYEXPORT) + cchName;
+            unsigned cchStdcall = 0;
+            if (cchName > 3 && *pchName == '_' && isdigit(pchName[cchName - 1]))
+            {
+                if (cchName > 3 && pchName[cchName - 2] == '@')
+                    cchStdcall = 2;
+                else if (cchName > 4 && pchName[cchName - 3] == '@' && isdigit(pchName[cchName - 2]))
+                    cchStdcall = 3;
+                if (cchStdcall)
+                    cbExp += cchName - 1 - cchStdcall;
+            }
+
+            /*
              * Add the export.
              */
-            PMYEXPORT pExp = (PMYEXPORT)malloc(sizeof(*pExp) + cchName);
+
+            PMYEXPORT pExp = (PMYEXPORT)malloc(cbExp);
             if (!pExp)
             {
                 fprintf(stderr, "%s:%u: error: Out of memory.\n", pszInput, iLine);
@@ -236,11 +252,23 @@ static RTEXITCODE parseInputInner(FILE *pInput, const char *pszInput)
             }
             memcpy(pExp->szName, pchName, cchName);
             pExp->szName[cchName] = '\0';
-            pExp->uOrdinal = uOrdinal;
-            pExp->fNoName  = fNoName;
-            pExp->pNext    = NULL;
-            *g_ppExpNext   = pExp;
-            g_ppExpNext    = &pExp->pNext;
+            if (!cchStdcall)
+            {
+                pExp->pszUnstdcallName = NULL;
+                pExp->pszExportedNm = pExp->szName;
+            }
+            else
+            {
+                pExp->pszUnstdcallName = &pExp->szName[cchName + 1];
+                memcpy(pExp->pszUnstdcallName, pchName + 1, cchName - 1 - cchStdcall);
+                pExp->pszUnstdcallName[cchName - 1 - cchStdcall] = '\0';
+                pExp->pszExportedNm = pExp->pszUnstdcallName;
+            }
+            pExp->uOrdinal   = uOrdinal;
+            pExp->fNoName    = fNoName;
+            pExp->pNext      = NULL;
+            *g_ppExpNext     = pExp;
+            g_ppExpNext      = &pExp->pNext;
         }
     }
 
@@ -320,13 +348,26 @@ static RTEXITCODE generateOutputInner(FILE *pOutput)
             ";\n"
             "BEGINCODE\n");
     for (PMYEXPORT pExp = g_pExpHead; pExp; pExp = pExp->pNext)
-        fprintf(pOutput,
-                "BEGINPROC %s\n"
-                "    jmp RTCCPTR_PRE [g_pfn%s xWrtRIP]\n"
-                "ENDPROC   %s\n",
-                pExp->szName,
-                pExp->szName,
-                pExp->szName);
+        if (!pExp->pszUnstdcallName)
+            fprintf(pOutput,
+                    "BEGINPROC %s\n"
+                    "    jmp   RTCCPTR_PRE [g_pfn%s xWrtRIP]\n"
+                    "ENDPROC   %s\n",
+                    pExp->szName, pExp->szName, pExp->szName);
+        else
+            fprintf(pOutput,
+                    "%%ifdef RT_ARCH_X86\n"
+                    "global    %s\n"
+                    "%s:\n"
+                    "    jmp   RTCCPTR_PRE [g_pfn%s xWrtRIP]\n"
+                    "%%else\n"
+                    "BEGINPROC %s\n"
+                    "    jmp   RTCCPTR_PRE [g_pfn%s xWrtRIP]\n"
+                    "ENDPROC   %s\n"
+                    "%%endif\n",
+                    pExp->szName, pExp->szName, pExp->pszUnstdcallName,
+                    pExp->pszUnstdcallName, pExp->pszUnstdcallName, pExp->pszUnstdcallName);
+
     fprintf(pOutput,
             "\n"
             "\n");
@@ -346,11 +387,12 @@ static RTEXITCODE generateOutputInner(FILE *pOutput)
                 "global __imp_%s\n"
                 "__imp_%s:\n"
                 "%%endif\n"
-                "g_pfn%s RTCCPTR_DEF ___LazyLoad___%s\n",
+                "g_pfn%s RTCCPTR_DEF ___LazyLoad___%s\n"
+                "\n",
                 pExp->szName,
                 pExp->szName,
-                pExp->szName,
-                pExp->szName);
+                pExp->pszExportedNm,
+                pExp->pszExportedNm);
     fprintf(pOutput,
             "RTCCPTR_DEF 0 ; Terminator entry for traversal.\n"
             "\n"
@@ -367,14 +409,21 @@ static RTEXITCODE generateOutputInner(FILE *pOutput)
             "; Imported names.\n"
             ";\n"
             "BEGINCODE\n"
-            "g_szLibrary db '%s',0\n"
+            "g_szLibrary:        db '%s',0\n"
+            "\n"
             "g_szzNames:\n",
             g_pszLibrary);
     for (PMYEXPORT pExp = g_pExpHead; pExp; pExp = pExp->pNext)
-        fprintf(pOutput, "g_sz%s: db '%s',0\n", pExp->szName, pExp->szName);
+        if (!pExp->fNoName)
+            fprintf(pOutput, "  g_sz%s:\n    db '%s',0\n", pExp->pszExportedNm, pExp->pszExportedNm);
+        else
+            fprintf(pOutput, "  g_sz%s:\n    db '#%u',0\n", pExp->pszExportedNm, pExp->uOrdinal);
     fprintf(pOutput,
             "g_EndOfNames: db 0\n"
             "\n"
+            "g_szFailLoadFmt:    db 'Lazy loader failed to load \"%%s\": %%Rrc', 10, 0\n"
+            "g_szFailResolveFmt: db 'Lazy loader failed to resolve symbol \"%%s\" in \"%%s\": %%Rrc', 10, 0\n"
+            "\n"
             "\n");
 
     /*
@@ -386,31 +435,64 @@ static RTEXITCODE generateOutputInner(FILE *pOutput)
             ";\n"
             "BEGINCODE\n");
     for (PMYEXPORT pExp = g_pExpHead; pExp; pExp = pExp->pNext)
-        fprintf(pOutput,
-                "___LazyLoad___%s:\n"
-                /* "int3\n" */
-                "%%ifdef RT_ARCH_AMD64\n"
-                "    lea     rax, [g_sz%s wrt rip]\n"
-                "    lea     r10, [g_pfn%s wrt rip]\n"
-                "%%elifdef RT_ARCH_X86\n"
-                "    push    g_sz%s\n"
-                "    push    g_pfn%s\n"
-                "%%else\n"
-                " %%error \"Unsupported architecture\"\n"
-                "%%endif\n"
-                "    call    LazyLoadResolver\n"
-                "%%ifdef RT_ARCH_X86\n"
-                "    add     esp, 8h\n"
-                "%%endif\n"
-                "    jmp     NAME(%s)\n"
-                "\n"
-                ,
-                pExp->szName,
-                pExp->szName,
-                pExp->szName,
-                pExp->szName,
-                pExp->szName,
-                pExp->szName);
+    {
+        if (!pExp->fNoName)
+            fprintf(pOutput,
+                    "___LazyLoad___%s:\n"
+                    /* "int3\n" */
+                    "%%ifdef RT_ARCH_AMD64\n"
+                    "    lea     rax, [g_sz%s wrt rip]\n"
+                    "    lea     r10, [g_pfn%s wrt rip]\n"
+                    "    call    LazyLoadResolver\n"
+                    "%%elifdef RT_ARCH_X86\n"
+                    "    push    g_sz%s\n"
+                    "    push    g_pfn%s\n"
+                    "    call    LazyLoadResolver\n"
+                    "    add     esp, 8h\n"
+                    "%%else\n"
+                    " %%error \"Unsupported architecture\"\n"
+                    "%%endif\n"
+                    ,
+                    pExp->pszExportedNm,
+                    pExp->pszExportedNm,
+                    pExp->pszExportedNm,
+                    pExp->pszExportedNm,
+                    pExp->pszExportedNm);
+        else
+            fprintf(pOutput,
+                    "___LazyLoad___%s:\n"
+                    /* "int3\n" */
+                    "%%ifdef RT_ARCH_AMD64\n"
+                    "    mov     eax, %u\n"
+                    "    lea     r10, [g_pfn%s wrt rip]\n"
+                    "    call    LazyLoadResolver\n"
+                    "%%elifdef RT_ARCH_X86\n"
+                    "    push    %u\n"
+                    "    push    g_pfn%s\n"
+                    "    call    LazyLoadResolver\n"
+                    "    add     esp, 8h\n"
+                    "%%else\n"
+                    " %%error \"Unsupported architecture\"\n"
+                    "%%endif\n"
+                    ,
+                    pExp->pszExportedNm,
+                    pExp->uOrdinal,
+                    pExp->pszExportedNm,
+                    pExp->uOrdinal,
+                    pExp->pszExportedNm);
+        if (!pExp->pszUnstdcallName)
+            fprintf(pOutput, "    jmp     NAME(%s)\n", pExp->szName);
+        else
+            fprintf(pOutput,
+                    "%%ifdef RT_ARCH_X86\n"
+                    "    jmp     %s\n"
+                    "%%else\n"
+                    "    jmp     NAME(%s)\n"
+                    "%%endif\n"
+                    ,
+                    pExp->szName, pExp->szName);
+        fprintf(pOutput, "\n");
+    }
     fprintf(pOutput,
             "\n"
             "\n"
@@ -435,57 +517,141 @@ static RTEXITCODE generateOutputInner(FILE *pOutput)
      * The LazyLoading routine returns the module handle in RCX/ECX, caller
      * saved all necessary registers.
      */
+    if (!g_fSystemLibrary)
+        fprintf(pOutput,
+                ";\n"
+                ";SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod,\n"
+                ";                                           uint32_t fFlags, PRTERRINFO pErrInfo);\n"
+                ";\n"
+                "EXTERN_IMP2 SUPR3HardenedLdrLoadAppPriv\n"
+                "%%ifdef IN_RT_R3\n"
+                "extern NAME(RTAssertMsg2Weak)\n"
+                "%%else\n"
+                "EXTERN_IMP2 RTAssertMsg2Weak\n"
+                "%%endif\n"
+                "BEGINCODE\n"
+                "\n"
+                "LazyLoading:\n"
+                "    mov     xCX, [g_hMod xWrtRIP]\n"
+                "    or      xCX, xCX\n"
+                "    jnz     .return\n"
+                "\n"
+                "%%ifdef ASM_CALL64_GCC\n"
+                "    xor     rcx, rcx               ; pErrInfo\n"
+                "    xor     rdx, rdx               ; fFlags (local load)\n"
+                "    lea     rsi, [g_hMod wrt rip]  ; phLdrMod\n"
+                "    lea     rdi, [g_szLibrary wrt rip] ; pszFilename\n"
+                "    sub     rsp, 08h\n"
+                "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
+                "    add     rsp, 08h\n"
+                "\n"
+                "%%elifdef ASM_CALL64_MSC\n"
+                "    xor     r9, r9                 ; pErrInfo\n"
+                "    xor     r8, r8                 ; fFlags (local load)\n"
+                "    lea     rdx, [g_hMod wrt rip]  ; phLdrMod\n"
+                "    lea     rcx, [g_szLibrary wrt rip] ; pszFilename\n"
+                "    sub     rsp, 28h\n"
+                "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
+                "    add     rsp, 28h\n"
+                "\n"
+                "%%elifdef RT_ARCH_X86\n"
+                "    sub     xSP, 0ch\n"
+                "    push    0              ; pErrInfo\n"
+                "    push    0              ; fFlags (local load)\n"
+                "    push    g_hMod         ; phLdrMod\n"
+                "    push    g_szLibrary    ; pszFilename\n"
+                "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
+                "    add     esp, 1ch\n"
+                "%%else\n"
+                " %%error \"Unsupported architecture\"\n"
+                "%%endif\n");
+    else
+        fprintf(pOutput,
+                ";\n"
+                "; RTDECL(int) RTLdrLoadSystem(const char *pszFilename, bool fNoUnload, PRTLDRMOD phLdrMod);\n"
+                ";\n"
+                "%%ifdef IN_RT_R3\n"
+                "extern NAME(RTLdrLoadSystem)\n"
+                "extern NAME(RTAssertMsg2Weak)\n"
+                "%%else\n"
+                "EXTERN_IMP2 RTLdrLoadSystem\n"
+                "EXTERN_IMP2 RTAssertMsg2Weak\n"
+                "%%endif\n"
+                "BEGINCODE\n"
+                "\n"
+                "LazyLoading:\n"
+                "    mov     xCX, [g_hMod xWrtRIP]\n"
+                "    or      xCX, xCX\n"
+                "    jnz     .return\n"
+                "\n"
+                "%%ifdef ASM_CALL64_GCC\n"
+                "    lea     rdx, [g_hMod wrt rip]  ; phLdrMod\n"
+                "    mov     esi, 1                 ; fNoUnload=true\n"
+                "    lea     rdi, [g_szLibrary wrt rip] ; pszFilename\n"
+                "    sub     rsp, 08h\n"
+                " %%ifdef IN_RT_R3\n"
+                "    call    NAME(RTLdrLoadSystem)\n"
+                " %%else\n"
+                "    call    IMP2(RTLdrLoadSystem)\n"
+                " %%endif\n"
+                "    add     rsp, 08h\n"
+                "\n"
+                "%%elifdef ASM_CALL64_MSC\n"
+                "    lea     r8, [g_hMod wrt rip]   ; phLdrMod\n"
+                "    mov     edx, 1                 ; fNoUnload=true\n"
+                "    lea     rcx, [g_szLibrary wrt rip] ; pszFilename\n"
+                "    sub     rsp, 28h\n"
+                " %%ifdef IN_RT_R3\n"
+                "    call    NAME(RTLdrLoadSystem)\n"
+                " %%else\n"
+                "    call    IMP2(RTLdrLoadSystem)\n"
+                " %%endif\n"
+                "    add     rsp, 28h\n"
+                "\n"
+                "%%elifdef RT_ARCH_X86\n"
+                "    push    g_hMod         ; phLdrMod\n"
+                "    push    1              ; fNoUnload=true\n"
+                "    push    g_szLibrary    ; pszFilename\n"
+                " %%ifdef IN_RT_R3\n"
+                "    call    NAME(RTLdrLoadSystem)\n"
+                " %%else\n"
+                "    call    IMP2(RTLdrLoadSystem)\n"
+                " %%endif\n"
+                "    add     esp, 0ch\n"
+                "%%else\n"
+                " %%error \"Unsupported architecture\"\n"
+                "%%endif\n");
     fprintf(pOutput,
-            ";\n"
-            ";SUPR3DECL(int) SUPR3HardenedLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod,\n"
-            ";                                           uint32_t fFlags, PRTERRINFO pErrInfo);\n"
-            ";\n"
-            "EXTERN_IMP2 SUPR3HardenedLdrLoadAppPriv\n"
-            "BEGINCODE\n"
-            "\n"
-            "LazyLoading:\n"
+            "    or      eax, eax\n"
+            "    jnz    .badload\n"
             "    mov     xCX, [g_hMod xWrtRIP]\n"
-            "    or      xCX, xCX\n"
-            "    jnz     .return\n"
+            ".return:\n"
+            "    ret\n"
             "\n"
+            ".badload:\n"
             "%%ifdef ASM_CALL64_GCC\n"
-            "    xor     rcx, rcx               ; pErrInfo\n"
-            "    xor     rdx, rdx               ; fFlags (local load)\n"
-            "    lea     rsi, [g_hMod wrt rip]  ; phLdrMod\n"
-            "    lea     rdi, [g_szLibrary wrt rip] ; pszFilename\n"
+            "    mov     edx, eax\n"
+            "    lea     rsi, [g_szLibrary wrt rip]\n"
+            "    lea     rdi, [g_szFailLoadFmt wrt rip]\n"
             "    sub     rsp, 08h\n"
-            "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
-            "    add     rsp, 08h\n"
-            "\n"
             "%%elifdef ASM_CALL64_MSC\n"
-            "    xor     r9, r9                 ; pErrInfo\n"
-            "    xor     r8, r8                 ; fFlags (local load)\n"
-            "    lea     rdx, [g_hMod wrt rip]  ; phLdrMod\n"
-            "    lea     rcx, [g_szLibrary wrt rip] ; pszFilename\n"
+            "    mov     r8d, eax\n"
+            "    lea     rdx, [g_szLibrary wrt rip]\n"
+            "    lea     rcx, [g_szFailLoadFmt wrt rip]\n"
             "    sub     rsp, 28h\n"
-            "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
-            "    add     rsp, 28h\n"
-            "\n"
             "%%elifdef RT_ARCH_X86\n"
-            "    sub     xSP, 0ch\n"
-            "    push    0              ; pErrInfo\n"
-            "    push    0              ; fFlags (local load)\n"
-            "    push    g_hMod         ; phLdrMod\n"
-            "    push    g_szLibrary    ; pszFilename\n"
-            "    call    IMP2(SUPR3HardenedLdrLoadAppPriv)\n"
-            "    add     esp, 1ch\n"
+            "    push    eax\n"
+            "    push    g_szLibrary\n"
+            "    push    g_szFailLoadFmt\n"
+            "%%endif\n"
+            "%%ifdef IN_RT_R3\n"
+            "    call    NAME(RTAssertMsg2Weak)\n"
             "%%else\n"
-            " %%error \"Unsupported architecture\"\n"
+            "    call    IMP2(RTAssertMsg2Weak)\n"
             "%%endif\n"
-            "    or      eax, eax\n"
-            "    jz      .loadok\n"
-            ".badload:\n"
+            ".badloadloop:\n"
             "    int3\n"
-            "    jmp     .badload\n"
-            ".loadok:\n"
-            "    mov     xCX, [g_hMod xWrtRIP]\n"
-            ".return:\n"
-            "    ret\n"
+            "    jmp     .badloadloop\n"
             "LazyLoading_End:\n"
             "\n"
             "\n");
@@ -495,7 +661,11 @@ static RTEXITCODE generateOutputInner(FILE *pOutput)
             ";\n"
             ";RTDECL(int) RTLdrGetSymbol(RTLDRMOD hLdrMod, const char *pszSymbol, void **ppvValue);\n"
             ";\n"
+            "%%ifdef IN_RT_R3\n"
+            "extern NAME(RTLdrGetSymbol)\n"
+            "%%else\n"
             "EXTERN_IMP2 RTLdrGetSymbol\n"
+            "%%endif\n"
             "BEGINCODE\n"
             "LazyLoadResolver:\n"
             "%%ifdef RT_ARCH_AMD64\n"
@@ -529,13 +699,13 @@ static RTEXITCODE generateOutputInner(FILE *pOutput)
             "    mov     rdx, r15       ; pszSymbol\n"
             "    mov     r8, r14        ; ppvValue\n"
             " %%endif\n"
+            " %%ifdef IN_RT_R3\n"
+            "    call    NAME(RTLdrGetSymbol)\n"
+            " %%else\n"
             "    call    IMP2(RTLdrGetSymbol)\n"
+            " %%endif\n"
             "    or      eax, eax\n"
-            "    jz      .symok\n"
-            ".badsym:\n"
-            "    int3\n"
-            "    jmp     .badsym\n"
-            ".symok:\n"
+            "    jnz     .badsym\n"
             "\n"
             "    mov     rsp, r12\n"
             " %%ifdef ASM_CALL64_GCC\n"
@@ -560,19 +730,17 @@ static RTEXITCODE generateOutputInner(FILE *pOutput)
             "    and     esp, 0fffffff0h\n"
             "\n"
             ".loaded:\n"
-            "    mov     eax, [ebp + 4] ; value addr\n"
-            "    push    eax\n"
-            "    mov     edx, [ebp + 8] ; symbol name\n"
-            "    push    edx\n"
-            "    call    LazyLoading    ; returns handle in ecx\n"
-            "    mov     ecx, [g_hMod]\n"
+            "    call    LazyLoading      ; returns handle in ecx\n"
+            "    push    dword [ebp + 8]  ; value addr\n"
+            "    push    dword [ebp + 12] ; symbol name\n"
+            "    push    ecx\n"
+            " %%ifdef IN_RT_R3\n"
+            "    call    NAME(RTLdrGetSymbol)\n"
+            " %%else\n"
             "    call    IMP2(RTLdrGetSymbol)\n"
+            " %%endif\n"
             "    or      eax, eax\n"
-            "    jz      .symok\n"
-            ".badsym:\n"
-            "    int3\n"
-            "    jmp     .badsym\n"
-            ".symok:\n"
+            "    jnz     .badsym\n"
             "    lea     esp, [ebp - 0ch]\n"
             "    pop     edx\n"
             "    pop     ecx\n"
@@ -582,6 +750,35 @@ static RTEXITCODE generateOutputInner(FILE *pOutput)
             " %%error \"Unsupported architecture\"\n"
             "%%endif\n"
             "    ret\n"
+            "\n"
+            ".badsym:\n"
+            "%%ifdef ASM_CALL64_GCC\n"
+            "    mov     ecx, eax\n"
+            "    lea     rdx, [g_szLibrary wrt rip]\n"
+            "    mov     rsi, r15\n"
+            "    lea     rdi, [g_szFailResolveFmt wrt rip]\n"
+            "    sub     rsp, 08h\n"
+            "%%elifdef ASM_CALL64_MSC\n"
+            "    mov     r9d, eax\n"
+            "    mov     r8, r15\n"
+            "    lea     rdx, [g_szLibrary wrt rip]\n"
+            "    lea     rcx, [g_szFailResolveFmt wrt rip]\n"
+            "    sub     rsp, 28h\n"
+            "%%elifdef RT_ARCH_X86\n"
+            "    push    eax\n"
+            "    push    dword [ebp + 12]\n"
+            "    push    g_szLibrary\n"
+            "    push    g_szFailResolveFmt\n"
+            "%%endif\n"
+            "%%ifdef IN_RT_R3\n"
+            "    call    NAME(RTAssertMsg2Weak)\n"
+            "%%else\n"
+            "    call    IMP2(RTAssertMsg2Weak)\n"
+            "%%endif\n"
+            ".badsymloop:\n"
+            "    int3\n"
+            "    jmp     .badsymloop\n"
+            "\n"
             "LazyLoadResolver_End:\n"
             "\n"
             "\n"
@@ -595,6 +792,12 @@ static RTEXITCODE generateOutputInner(FILE *pOutput)
      */
     if (g_fWithExplictLoadFunction)
     {
+        if (g_fSystemLibrary) /* Lazy bird. */
+        {
+            fprintf(stderr, "error: cannot use --system with --explicit-load-function, sorry\n");
+            return RTEXITCODE_FAILURE;
+        }
+
         int cchLibBaseName = (int)(strchr(g_pszLibrary, '.') ? strchr(g_pszLibrary, '.') - g_pszLibrary : strlen(g_pszLibrary));
         fprintf(pOutput,
                 ";;\n"
@@ -833,6 +1036,8 @@ int main(int argc, char **argv)
                 g_fWithExplictLoadFunction = true;
             else if (!strcmp(psz, "--no-explicit-load-function"))
                 g_fWithExplictLoadFunction = false;
+            else if (!strcmp(psz, "--system"))
+                g_fSystemLibrary = true;
             /** @todo Support different load methods so this can be used on system libs and
              *        such if we like. */
             else if (   !strcmp(psz, "--help")
@@ -843,7 +1048,7 @@ int main(int argc, char **argv)
             else if (   !strcmp(psz, "--version")
                      || !strcmp(psz, "-V"))
             {
-                printf("$Revision: 98272 $\n");
+                printf("$Revision: 105009 $\n");
                 return RTEXITCODE_SUCCESS;
             }
             else
diff --git a/src/libs/Makefile.kmk b/src/libs/Makefile.kmk
index a298562..4e12747 100644
--- a/src/libs/Makefile.kmk
+++ b/src/libs/Makefile.kmk
@@ -33,8 +33,8 @@ endif
 
 # PNG support (for screenshots).
 if !defined(VBOX_ONLY_DOCS) && !defined(VBOX_ONLY_SDK) && !defined(VBOX_ONLY_TESTSUITE) \
- && "$(SDK_VBOX_LIBPNG_INCS)" == "$(PATH_ROOT)/src/libs/libpng-1.2.53"
- include $(PATH_SUB_CURRENT)/libpng-1.2.53/Makefile.kmk
+ && "$(SDK_VBOX_LIBPNG_INCS)" == "$(PATH_ROOT)/src/libs/libpng-1.2.54"
+ include $(PATH_SUB_CURRENT)/libpng-1.2.54/Makefile.kmk
 endif # !VBOX_ONLY_DOCS
 
 # Libcurl for inet access
@@ -52,7 +52,7 @@ endif
 if !defined(VBOX_ONLY_SDK) \
  && (   "$(SDK_VBOX_OPENSSL_INCS)" == "$(SDK_VBOX_OPENSSL_VBOX_DEFAULT_INCS)" \
      || defined(VBOX_WITH_EXTPACK_PUEL_BUILD))
- include $(PATH_SUB_CURRENT)/openssl-1.0.1p/Makefile.kmk
+ include $(PATH_SUB_CURRENT)/openssl-1.0.1q/Makefile.kmk
 endif
 
 # libjpeg for VRDP video redirection
diff --git a/src/libs/xpcom18a4/xpcom/reflect/xptcall/src/md/unix/xptcstubs_gcc_x86_unix.cpp b/src/libs/xpcom18a4/xpcom/reflect/xptcall/src/md/unix/xptcstubs_gcc_x86_unix.cpp
index 9d93908..5f71263 100644
--- a/src/libs/xpcom18a4/xpcom/reflect/xptcall/src/md/unix/xptcstubs_gcc_x86_unix.cpp
+++ b/src/libs/xpcom18a4/xpcom/reflect/xptcall/src/md/unix/xptcstubs_gcc_x86_unix.cpp
@@ -62,6 +62,8 @@ PrepareAndDispatch(uint32 methodIndex, nsXPTCStubBase* self, PRUint32* args)
 
     self->GetInterfaceInfo(&iface_info);
     NS_ASSERTION(iface_info,"no interface info");
+    if (!iface_info)
+        return NS_ERROR_UNEXPECTED;
 
     iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
     NS_ASSERTION(info,"no interface info");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-virtualbox/virtualbox.git



More information about the Pkg-virtualbox-commits mailing list