Index: /trunk/include/iprt/nt/nt.h
===================================================================
--- /trunk/include/iprt/nt/nt.h	(revision 52939)
+++ /trunk/include/iprt/nt/nt.h	(revision 52940)
@@ -1105,5 +1105,8 @@
 typedef PTEB_COMMON PTEB;
 
-#define NtCurrentPeb()  (((PTEB)NtCurrentTeb())->ProcessEnvironmentBlock)
+#define RTNtCurrentTeb()        ((PTEB)NtCurrentTeb())
+#define RTNtCurrentPeb()        (RTNtCurrentTeb()->ProcessEnvironmentBlock)
+#define NtCurrentPeb()          RTNtCurrentPeb()
+#define RTNtCurrentThreadId()   ((uint32_t)(uintptr_t)RTNtCurrentTeb()->ClientId.UniqueThread)
 
 /** @} */
@@ -1923,4 +1926,6 @@
 NTSYSAPI VOID NTAPI     LdrInitializeThunk(PVOID, PVOID, PVOID);
 NTSYSAPI NTSTATUS NTAPI RtlExpandEnvironmentStrings_U(PVOID, PUNICODE_STRING, PUNICODE_STRING, PULONG);
+NTSYSAPI VOID NTAPI     RtlExitProcess(NTSTATUS rcExitCode);
+NTSYSAPI VOID NTAPI     RtlExitThread(NTSTATUS rcExitCode);
 NTSYSAPI NTSTATUS NTAPI RtlDosApplyFileIsolationRedirection_Ustr(IN ULONG fFlags,
                                                                  IN PCUNICODE_STRING pOrgName,
@@ -1932,5 +1937,17 @@
                                                                  IN PSIZE_T pcbFilename OPTIONAL,
                                                                  IN PSIZE_T pcbNeeded OPTIONAL);
+# ifdef IPRT_NT_USE_WINTERNL
+NTSYSAPI PVOID NTAPI    RtlAllocateHeap(HANDLE hHeap, ULONG fFlags, SIZE_T cb);
+NTSYSAPI PVOID NTAPI    RtlReAllocateHeap(HANDLE hHeap, ULONG fFlags, PVOID pvOld, SIZE_T cbNew);
+NTSYSAPI BOOLEAN NTAPI  RtlFreeHeap(HANDLE hHeap, ULONG fFlags, PVOID pvMem);
+# endif /* IPRT_NT_USE_WINTERNL */
+NTSYSAPI SIZE_T NTAPI   RtlCompactHeap(HANDLE hHeap, ULONG fFlags);
 NTSYSAPI VOID NTAPI     RtlFreeUnicodeString(PUNICODE_STRING);
+NTSYSAPI SIZE_T NTAPI   RtlSizeHeap(HANDLE hHeap, ULONG fFlags, PVOID pvMem);
+NTSYSAPI NTSTATUS NTAPI RtlGetLastNtStatus(VOID);
+NTSYSAPI ULONG NTAPI    RtlGetLastWin32Error(VOID);
+NTSYSAPI VOID NTAPI     RtlSetLastWin32Error(ULONG uError);
+NTSYSAPI VOID NTAPI     RtlSetLastWin32ErrorAndNtStatusFromNtStatus(NTSTATUS rcNt);
+NTSYSAPI VOID NTAPI     RtlRestoreLastWin32Error(ULONG uError);
 
 RT_C_DECLS_END
Index: /trunk/src/VBox/HostDrivers/Support/Makefile.kmk
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/Makefile.kmk	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/Makefile.kmk	(revision 52940)
@@ -399,4 +399,5 @@
 #
 VBoxSupLib_TEMPLATE = $(if-expr "$(KBUILD_TARGET)" == "win" && defined(VBOX_WITH_HARDENING),VBOXR3HARDENEDLIB,VBOXR3)
+VBoxSupLib_SDKS.win = VBOX_NTDLL
 VBoxSupLib_LDFLAGS.win.amd64 = -Entry:DllMainEntrypoint
 VBoxSupLib_LDFLAGS.win.x86   = -Entry:DllMainEntrypoint
Index: /trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp	(revision 52940)
@@ -228,5 +228,5 @@
     for (;;)
 #ifdef RT_OS_WINDOWS
-        ExitProcess(rcExit);
+        RtlExitProcess(rcExit);
 #else
         _Exit(rcExit);
@@ -1478,10 +1478,10 @@
         supR3HardenedFatalMsg("supR3HardenedMainInitRuntime", kSupInitOp_IPRT, VERR_MODULE_NOT_FOUND,
                               "LoadLibrary \"%s\" failed (rc=%d)",
-                              szPath, GetLastError());
+                              szPath, RtlGetLastWin32Error());
     PFNRTR3INITEX pfnRTInitEx = (PFNRTR3INITEX)GetProcAddress(hMod, SUP_HARDENED_SYM("RTR3InitEx"));
     if (!pfnRTInitEx)
         supR3HardenedFatalMsg("supR3HardenedMainInitRuntime", kSupInitOp_IPRT, VERR_SYMBOL_NOT_FOUND,
                               "Entrypoint \"RTR3InitEx\" not found in \"%s\" (rc=%d)",
-                              szPath, GetLastError());
+                              szPath, RtlGetLastWin32Error());
 
     PFNSUPR3PREINIT pfnSUPPreInit = (PFNSUPR3PREINIT)GetProcAddress(hMod, SUP_HARDENED_SYM("supR3PreInit"));
@@ -1489,5 +1489,5 @@
         supR3HardenedFatalMsg("supR3HardenedMainInitRuntime", kSupInitOp_IPRT, VERR_SYMBOL_NOT_FOUND,
                               "Entrypoint \"supR3PreInit\" not found in \"%s\" (rc=%d)",
-                              szPath, GetLastError());
+                              szPath, RtlGetLastWin32Error());
 
 #else
@@ -1620,9 +1620,9 @@
     if (!hMod)
         supR3HardenedFatal("supR3HardenedMainGetTrustedMain: LoadLibrary \"%s\" failed, rc=%d\n",
-                            szPath, GetLastError());
+                            szPath, RtlGetLastWin32Error());
     FARPROC pfn = GetProcAddress(hMod, SUP_HARDENED_SYM("TrustedMain"));
     if (!pfn)
         supR3HardenedFatal("supR3HardenedMainGetTrustedMain: Entrypoint \"TrustedMain\" not found in \"%s\" (rc=%d)\n",
-                            szPath, GetLastError());
+                            szPath, RtlGetLastWin32Error());
     return (PFNSUPTRUSTEDMAIN)pfn;
 
Index: /trunk/src/VBox/HostDrivers/Support/SUPR3HardenedVerify.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/SUPR3HardenedVerify.cpp	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/SUPR3HardenedVerify.cpp	(revision 52940)
@@ -411,5 +411,5 @@
             else
             {
-                int err = GetLastError();
+                int err = RtlGetLastWin32Error();
                 rc = supR3HardenedError(VERR_PATH_NOT_FOUND, fFatal,
                                         "supR3HardenedVerifyDir: Failed to open \"%s\": err=%d\n",
@@ -525,5 +525,5 @@
             else
             {
-                int err = GetLastError();
+                int err = RtlGetLastWin32Error();
                 if (   !pFile->fOptional
                     || (    err != ERROR_FILE_NOT_FOUND
@@ -603,5 +603,5 @@
             pVerified->hFile = hFileOpened;
         else
-            CloseHandle((HANDLE)hFileOpened);
+            NtClose((HANDLE)hFileOpened);
     }
 
@@ -677,5 +677,5 @@
                 if (!fLeaveFileOpen)
                 {
-                    CloseHandle((HANDLE)pVerified->hFile);
+                    NtClose((HANDLE)pVerified->hFile);
                     pVerified->hFile = -1;
                 }
@@ -1740,9 +1740,9 @@
 #  endif
 # endif
-        CloseHandle(hVerify);
+        NtClose(hVerify);
     }
     else if (RT_SUCCESS(rc))
-        rc = RTErrInfoSetF(pErrInfo, RTErrConvertFromWin32(GetLastError()),
-                           "Error %u trying to open (or duplicate handle for) '%s'", GetLastError(), pszFilename);
+        rc = RTErrInfoSetF(pErrInfo, RTErrConvertFromWin32(RtlGetLastWin32Error()),
+                           "Error %u trying to open (or duplicate handle for) '%s'", RtlGetLastWin32Error(), pszFilename);
     if (RT_FAILURE(rc))
         return rc;
Index: /trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerify-win.h	(revision 52940)
@@ -214,7 +214,4 @@
 #  include <iprt/string.h>
 
-#  define suplibHardenedAllocZ       RTMemAllocZ
-#  define suplibHardenedReAlloc      RTMemRealloc
-#  define suplibHardenedFree         RTMemFree
 #  define suplibHardenedMemComp      memcmp
 #  define suplibHardenedMemCopy      memcpy
@@ -227,5 +224,5 @@
 # else   /* IN_SUP_HARDENED_R3 */
 #  include <iprt/mem.h>
-#if 0
+#  if 0
 #  define memcmp                     suplibHardenedMemComp
 #  define memcpy                     suplibHardenedMemCopy
@@ -236,14 +233,11 @@
 #  define strcmp                     suplibHardenedStrCmp
 #  define strncmp                    suplibHardenedStrNCmp
+#  endif
+# endif  /* IN_SUP_HARDENED_R3 */
+
+#endif /* SUP_CERTIFICATES_ONLY */
+
+RT_C_DECLS_END
+
 #endif
-DECLHIDDEN(void *)  suplibHardenedAllocZ(size_t cb);
-DECLHIDDEN(void *)  suplibHardenedReAlloc(void *pvOld, size_t cbNew);
-DECLHIDDEN(void)    suplibHardenedFree(void *pv);
-# endif  /* IN_SUP_HARDENED_R3 */
-
-#endif /* SUP_CERTIFICATES_ONLY */
-
-RT_C_DECLS_END
-
-#endif
-
+
Index: /trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyImage-win.cpp	(revision 52940)
@@ -1911,5 +1911,5 @@
         && fFlags
         && g_uNtVerCombined < SUP_MAKE_NT_VER_SIMPLE(6, 2)
-        && GetLastError() == ERROR_INVALID_PARAMETER)
+        && RtlGetLastWin32Error() == ERROR_INVALID_PARAMETER)
     {
         fFlags = 0;
@@ -1917,5 +1917,5 @@
     }
     if (hMod == NULL)
-        supR3HardenedFatal("Error loading '%s': %u [%ls]", pszName, GetLastError(), wszName);
+        supR3HardenedFatal("Error loading '%s': %u [%ls]", pszName, RtlGetLastWin32Error(), wszName);
     return hMod;
 }
@@ -1939,5 +1939,5 @@
 #define RESOLVE_CRYPT32_API(a_Name, a_pfnType) \
     a_pfnType pfn##a_Name = (a_pfnType)GetProcAddress(hCrypt32, #a_Name); \
-    if (pfn##a_Name == NULL) supR3HardenedFatal("Error locating '" #a_Name "' in 'crypt32.dll': %u", GetLastError())
+    if (pfn##a_Name == NULL) supR3HardenedFatal("Error locating '" #a_Name "' in 'crypt32.dll': %u", RtlGetLastWin32Error())
     RESOLVE_CRYPT32_API(CertOpenStore, PFNCERTOPENSTORE);
     RESOLVE_CRYPT32_API(CertCloseStore, PFNCERTCLOSESTORE);
@@ -2026,5 +2026,5 @@
     HMODULE hSupLibMod = (HMODULE)supR3HardenedWinLoadLibrary(szPath, true /*fSystem32Only*/);
     if (hSupLibMod == NULL)
-        supR3HardenedFatal("Error loading '%s': %u", szPath, GetLastError());
+        supR3HardenedFatal("Error loading '%s': %u", szPath, RtlGetLastWin32Error());
 # endif
 
@@ -2036,5 +2036,5 @@
         g_iTlsWinVerifyTrustRecursion = iTls;
     else
-        supR3HardenedError(GetLastError(), false /*fFatal*/, "TlsAlloc failed");
+        supR3HardenedError(RtlGetLastWin32Error(), false /*fFatal*/, "TlsAlloc failed");
 
     /*
@@ -2046,10 +2046,10 @@
         g_pfn##a_Name = (a_pfnType)GetProcAddress(hWintrust, #a_Name); \
         if (g_pfn##a_Name == NULL && (a_uMinWinVer) < g_uNtVerCombined) \
-            supR3HardenedFatal("Error locating '" #a_Name "' in 'Wintrust.dll': %u", GetLastError()); \
+            supR3HardenedFatal("Error locating '" #a_Name "' in 'Wintrust.dll': %u", RtlGetLastWin32Error()); \
     } while (0)
 
     PFNWINVERIFYTRUST pfnWinVerifyTrust = (PFNWINVERIFYTRUST)GetProcAddress(hWintrust, "WinVerifyTrust");
     if (!pfnWinVerifyTrust)
-        supR3HardenedFatal("Error locating 'WinVerifyTrust' in 'Wintrust.dll': %u", GetLastError());
+        supR3HardenedFatal("Error locating 'WinVerifyTrust' in 'Wintrust.dll': %u", RtlGetLastWin32Error());
 
     RESOLVE_CRYPT_API(CryptCATAdminAcquireContext,           PFNCRYPTCATADMINACQUIRECONTEXT,          0);
@@ -2374,5 +2374,5 @@
                                 if (!fFreshContext)
                                 {
-                                    SUP_DPRINTF(("supR3HardNtViCallWinVerifyTrustCatFile: Retrying with fresh context (CryptCATAdminEnumCatalogFromHash -> %u; iCat=%#x)\n", GetLastError(), iCat));
+                                    SUP_DPRINTF(("supR3HardNtViCallWinVerifyTrustCatFile: Retrying with fresh context (CryptCATAdminEnumCatalogFromHash -> %u; iCat=%#x)\n", RtlGetLastWin32Error(), iCat));
                                     if (hCatInfoPrev != NULL)
                                         g_pfnCryptCATAdminReleaseCatalogContext(hCatAdmin, hCatInfoPrev, 0 /*dwFlags*/);
@@ -2381,5 +2381,5 @@
                                 }
                                 if (iCat == 0)
-                                    SUP_DPRINTF(("supR3HardNtViCallWinVerifyTrustCatFile: CryptCATAdminEnumCatalogFromHash failed %u\n", GetLastError()));
+                                    SUP_DPRINTF(("supR3HardNtViCallWinVerifyTrustCatFile: CryptCATAdminEnumCatalogFromHash failed %u\n", RtlGetLastWin32Error()));
                                 break;
                             }
@@ -2445,7 +2445,7 @@
                             else
                             {
-                                rc = RTErrInfoSetF(pErrInfo, RTErrConvertFromWin32(GetLastError()),
+                                rc = RTErrInfoSetF(pErrInfo, RTErrConvertFromWin32(RtlGetLastWin32Error()),
                                                    "CryptCATCatalogInfoFromContext failed: %d [file=%s]",
-                                                   GetLastError(), pwszName);
+                                                   RtlGetLastWin32Error(), pwszName);
                                 SUP_DPRINTF(("supR3HardNtViCallWinVerifyTrustCatFile: CryptCATCatalogInfoFromContext failed\n"));
                             }
@@ -2461,6 +2461,6 @@
                 }
                 else
-                    rc = RTErrInfoSetF(pErrInfo, RTErrConvertFromWin32(GetLastError()),
-                                       "CryptCATAdminCalcHashFromFileHandle[2] failed: %d [file=%s]", GetLastError(), pwszName);
+                    rc = RTErrInfoSetF(pErrInfo, RTErrConvertFromWin32(RtlGetLastWin32Error()),
+                                       "CryptCATAdminCalcHashFromFileHandle[2] failed: %d [file=%s]", RtlGetLastWin32Error(), pwszName);
 
                 if (!ASMAtomicCmpXchgPtr(&s_aHashes[i].hCachedCatAdmin, hCatAdmin, NULL))
@@ -2469,6 +2469,6 @@
             }
             else
-                rc = RTErrInfoSetF(pErrInfo, RTErrConvertFromWin32(GetLastError()),
-                                   "CryptCATAdminAcquireContext[2] failed: %d [file=%s]", GetLastError(), pwszName);
+                rc = RTErrInfoSetF(pErrInfo, RTErrConvertFromWin32(RtlGetLastWin32Error()),
+                                   "CryptCATAdminAcquireContext[2] failed: %d [file=%s]", RtlGetLastWin32Error(), pwszName);
              iPolicy++;
         } while (   fTryNextPolicy
@@ -2528,5 +2528,5 @@
         else
         {
-            uint32_t const idCurrentThread = GetCurrentThreadId();
+            uint32_t const idCurrentThread = RTNtCurrentThreadId();
             fNoRecursion = ASMAtomicCmpXchgU32(&g_idActiveThread, idCurrentThread, UINT32_MAX);
         }
@@ -2592,5 +2592,5 @@
         && (   g_iTlsWinVerifyTrustRecursion != UINT32_MAX
             ?  (uintptr_t)TlsGetValue(g_iTlsWinVerifyTrustRecursion) == 0
-            : g_idActiveThread != GetCurrentThreadId() );
+            : g_idActiveThread != RTNtCurrentThreadId() );
 }
 
Index: /trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/win/SUPHardenedVerifyProcess-win.cpp	(revision 52940)
@@ -1606,5 +1606,5 @@
                                        pEntry->pszName, cbBits, cbBits);
 
-        pEntry->pbBits = (uint8_t *)suplibHardenedAllocZ(cbBits);
+        pEntry->pbBits = (uint8_t *)RTMemAllocZ(cbBits);
         if (!pEntry->pbBits)
             return supHardNtVpSetInfo1(pErrInfo, VERR_SUP_VP_NO_MEMORY, "Failed to allocate %zu bytes for image %s.",
@@ -1629,5 +1629,5 @@
     if (pEntry->pbBits)
     {
-        suplibHardenedFree(pEntry->pbBits);
+        RTMemFree(pEntry->pbBits);
         pEntry->pbBits = NULL;
     }
@@ -1926,5 +1926,5 @@
     int             rc;
     ULONG           cbUniStr = sizeof(UNICODE_STRING) + RTPATH_MAX * sizeof(RTUTF16);
-    PUNICODE_STRING pUniStr  = (PUNICODE_STRING)suplibHardenedAllocZ(cbUniStr);
+    PUNICODE_STRING pUniStr  = (PUNICODE_STRING)RTMemAllocZ(cbUniStr);
     if (!pUniStr)
         return supHardNtVpSetInfo2(pThis, VERR_SUP_VP_NO_MEMORY,
@@ -1947,5 +1947,5 @@
         rc = supHardNtVpSetInfo2(pThis, VERR_SUP_VP_NT_QI_PROCESS_NM_ERROR,
                                  "NtQueryInformationProcess/ProcessImageFileName failed: %#x", rcNt);
-    suplibHardenedFree(pUniStr);
+    RTMemFree(pUniStr);
     if (RT_FAILURE(rc))
         return rc;
@@ -2108,5 +2108,5 @@
          * Allocate and initialize memory for the state.
          */
-        PSUPHNTVPSTATE pThis = (PSUPHNTVPSTATE)suplibHardenedAllocZ(sizeof(*pThis));
+        PSUPHNTVPSTATE pThis = (PSUPHNTVPSTATE)RTMemAllocZ(sizeof(*pThis));
         if (pThis)
         {
@@ -2137,5 +2137,5 @@
                 supHardNTLdrCacheDeleteEntry(&pThis->aImages[i].CacheEntry);
 #endif
-            suplibHardenedFree(pThis);
+            RTMemFree(pThis);
         }
         else
Index: /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMain-win.cpp	(revision 52940)
@@ -92,5 +92,5 @@
         BOOL fRcAssert = (a_Expr); \
         if (fRcAssert == FALSE) \
-            supR3HardenedFatal("%s: %s -> %#x\n", __FUNCTION__, #a_Expr, GetLastError()); \
+            supR3HardenedFatal("%s: %s -> %#x\n", __FUNCTION__, #a_Expr, RtlGetLastWin32Error()); \
     } while (0)
 
@@ -321,52 +321,4 @@
 
 /**
- * Allocate zero filled memory on the heap.
- *
- * @returns Pointer to the memory.  Will never return NULL, triggers a fatal
- *          error instead.
- * @param   cb                  The number of bytes to allocate.
- */
-DECLHIDDEN(void *) suplibHardenedAllocZ(size_t cb)
-{
-    void *pv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb);
-    if (!pv)
-        supR3HardenedFatal("HeapAlloc failed to allocate %zu bytes.\n", cb);
-    return pv;
-}
-
-
-/**
- * Reallocates memory on the heap.
- *
- * @returns Pointer to the resized memory block.  Will never return NULL,
- *          triggers a fatal error instead.
- * @param   pvOld               The old memory block.
- * @param   cbNew               The new block size.
- */
-DECLHIDDEN(void *) suplibHardenedReAlloc(void *pvOld, size_t cbNew)
-{
-    if (!pvOld)
-        return suplibHardenedAllocZ(cbNew);
-    void *pv = HeapReAlloc(GetProcessHeap(), 0 /*dwFlags*/, pvOld, cbNew);
-    if (!pv)
-        supR3HardenedFatal("HeapReAlloc failed to allocate %zu bytes.\n", cbNew);
-    return pv;
-}
-
-
-/**
- * Frees memory allocated by suplibHardenedAlloc, suplibHardenedAllocZ or
- * suplibHardenedReAlloc.
- *
- * @param   pv                  Pointer to the memeory to be freed.
- */
-DECLHIDDEN(void) suplibHardenedFree(void *pv)
-{
-    if (pv)
-        HeapFree(GetProcessHeap(), 0 /* dwFlags*/, pv);
-}
-
-
-/**
  * Wrapper around LoadLibraryEx that deals with the UTF-8 to UTF-16 conversion
  * and supplies the right flags.
@@ -406,5 +358,5 @@
             && fFlags
             && g_uNtVerCombined < SUP_MAKE_NT_VER_SIMPLE(6, 2)
-            && GetLastError() == ERROR_INVALID_PARAMETER)
+            && RtlGetLastWin32Error() == ERROR_INVALID_PARAMETER)
             pvRet = (void *)LoadLibraryExW(wszPath, NULL /*hFile*/, 0);
 
@@ -543,6 +495,5 @@
      * Allocate and initalize a new entry.
      */
-    PVERIFIERCACHEENTRY pEntry = (PVERIFIERCACHEENTRY)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-                                                                sizeof(VERIFIERCACHEENTRY) + pUniStr->Length);
+    PVERIFIERCACHEENTRY pEntry = (PVERIFIERCACHEENTRY)RTMemAllocZ(sizeof(VERIFIERCACHEENTRY) + pUniStr->Length);
     if (pEntry)
     {
@@ -589,5 +540,5 @@
 
         /* Duplicate entry (may happen due to races). */
-        HeapFree(GetProcessHeap(), 0 /* dwFlags*/, pEntry);
+        RTMemFree(pEntry);
     }
     NtClose(hFile);
@@ -761,5 +712,5 @@
                     uint32_t cbNeeded      = RT_OFFSETOF(VERIFIERCACHEIMPORT, szName[cbNameAligned])
                                            + (pawcDir ? (cwcDir + 1) * sizeof(RTUTF16) : 0);
-                    PVERIFIERCACHEIMPORT pImport = (PVERIFIERCACHEIMPORT)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNeeded);
+                    PVERIFIERCACHEIMPORT pImport = (PVERIFIERCACHEIMPORT)RTMemAllocZ(cbNeeded);
                     if (pImport)
                     {
@@ -994,5 +945,5 @@
                 SUP_DPRINTF(("supR3HardenedWinVerifyCacheProcessImportTodos: '%s' is in the cache.\n", pCur->szName));
 
-            HeapFree(GetProcessHeap(), 0 /* dwFlags*/, pCur);
+            RTMemFree(pCur);
         } while (pTodo);
     }
@@ -1576,5 +1527,5 @@
         if (fImage || fExecMap || fExecProt)
         {
-            DWORD dwSavedLastError = GetLastError();
+            DWORD dwSavedLastError = RtlGetLastWin32Error();
 
             bool fCallRealApi;
@@ -1584,5 +1535,5 @@
             //SUP_DPRINTF(("supR3HardenedMonitor_NtCreateSection: 2 rcNt=%#x fCallRealApi=%#x\n", rcNt, fCallRealApi));
 
-            SetLastError(dwSavedLastError);
+            RtlRestoreLastWin32Error(dwSavedLastError);
 
             if (!NT_SUCCESS(rcNt))
@@ -1656,5 +1607,5 @@
 supR3HardenedMonitor_LdrLoadDll(PWSTR pwszSearchPath, PULONG pfFlags, PUNICODE_STRING pName, PHANDLE phMod)
 {
-    DWORD    dwSavedLastError = GetLastError();
+    DWORD    dwSavedLastError = RtlGetLastWin32Error();
     NTSTATUS rcNt;
 
@@ -1671,5 +1622,5 @@
         supR3HardenedError(VINF_SUCCESS, false, "supR3HardenedMonitor_LdrLoadDll: name is NULL or have a zero length.\n");
         SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x (pName=%p)\n", STATUS_INVALID_PARAMETER, pName));
-        SetLastError(dwSavedLastError);
+        RtlRestoreLastWin32Error(dwSavedLastError);
         return STATUS_INVALID_PARAMETER;
     }
@@ -1685,5 +1636,5 @@
         supR3HardenedError(VINF_SUCCESS, false, "supR3HardenedMonitor_LdrLoadDll: too long name: %#x bytes\n", pName->Length);
         SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_NAME_TOO_LONG));
-        SetLastError(dwSavedLastError);
+        RtlRestoreLastWin32Error(dwSavedLastError);
         return STATUS_NAME_TOO_LONG;
     }
@@ -1725,5 +1676,5 @@
             {
                 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", rcNt));
-                SetLastError(dwSavedLastError);
+                RtlRestoreLastWin32Error(dwSavedLastError);
                 return rcNt;
             }
@@ -1794,5 +1745,5 @@
                                cwcName, pawcName);
             SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_OBJECT_NAME_INVALID));
-            SetLastError(dwSavedLastError);
+            RtlRestoreLastWin32Error(dwSavedLastError);
             return STATUS_OBJECT_NAME_INVALID;
         }
@@ -1820,5 +1771,5 @@
             {
                 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", rcNt));
-                SetLastError(dwSavedLastError);
+                RtlRestoreLastWin32Error(dwSavedLastError);
                 return rcNt;
             }
@@ -1834,7 +1785,7 @@
             {
                 supR3HardenedError(VINF_SUCCESS, false,
-                                   "supR3HardenedMonitor_LdrLoadDll: GetSystemDirectoryW failed: %u\n", GetLastError());
+                                   "supR3HardenedMonitor_LdrLoadDll: GetSystemDirectoryW failed: %u\n", RtlGetLastWin32Error());
                 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_UNEXPECTED_IO_ERROR));
-                SetLastError(dwSavedLastError);
+                RtlRestoreLastWin32Error(dwSavedLastError);
                 return STATUS_UNEXPECTED_IO_ERROR;
             }
@@ -1844,5 +1795,5 @@
                                    "supR3HardenedMonitor_LdrLoadDll: Name too long (system32): %.*ls\n", cwcName, pawcName);
                 SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x\n", STATUS_NAME_TOO_LONG));
-                SetLastError(dwSavedLastError);
+                RtlRestoreLastWin32Error(dwSavedLastError);
                 return STATUS_NAME_TOO_LONG;
             }
@@ -1895,5 +1846,5 @@
                     SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: returns rcNt=%#x '%ls'\n", rcNt, wszPath));
                 }
-                SetLastError(dwSavedLastError);
+                RtlRestoreLastWin32Error(dwSavedLastError);
                 return rcNt;
             }
@@ -1903,5 +1854,5 @@
         else
         {
-            DWORD dwErr = GetLastError();
+            DWORD dwErr = RtlGetLastWin32Error();
             SUP_DPRINTF(("supR3HardenedMonitor_LdrLoadDll: error opening '%ls': %u\n", wszPath, dwErr));
         }
@@ -1914,5 +1865,5 @@
                  (unsigned)pName->Length / sizeof(WCHAR), pName->Buffer, pfFlags ? *pfFlags : UINT32_MAX, pwszSearchPath,
                  !((uintptr_t)pwszSearchPath & 1) && (uintptr_t)pwszSearchPath >= 0x2000U ? pwszSearchPath : L"<flags>"));
-    SetLastError(dwSavedLastError);
+    RtlRestoreLastWin32Error(dwSavedLastError);
     rcNt = g_pfnLdrLoadDllReal(pwszSearchPath, pfFlags, pName, phMod);
 
@@ -1920,5 +1871,5 @@
      * Log the result and process pending WinVerifyTrust work if we can.
      */
-    dwSavedLastError = GetLastError();
+    dwSavedLastError = RtlGetLastWin32Error();
 
     if (NT_SUCCESS(rcNt) && phMod)
@@ -1928,5 +1879,5 @@
     supR3HardenedWinVerifyCacheProcessWvtTodos();
 
-    SetLastError(dwSavedLastError);
+    RtlRestoreLastWin32Error(dwSavedLastError);
 
     return rcNt;
@@ -2157,4 +2108,22 @@
     if (RT_FAILURE(rc))
         supR3HardenedFatal("supR3HardenedWinCreateParentWatcherThread: RTThreadCreate failed: %Rrc\n", rc);
+}
+
+
+/**
+ * Simplify NtProtectVirtualMemory interface.
+ *
+ * Modifies protection for the current process.  Caller must know the current
+ * protection as it's not returned.
+ *
+ * @returns NT status code.
+ * @param   pvMem               The memory to change protection for.
+ * @param   cbMem               The amount of memory to change.
+ * @param   fNewProt            The new protection.
+ */
+static NTSTATUS supR3HardenedWinProtectMemory(PVOID pvMem, SIZE_T cbMem, ULONG fNewProt)
+{
+    ULONG fOldProt = 0;
+    return NtProtectVirtualMemory(NtCurrentProcess(), &pvMem, &cbMem, fNewProt, &fOldProt);
 }
 
@@ -2291,13 +2260,11 @@
     *puJmpTab                           = (uintptr_t)supR3HardenedMonitor_NtCreateSection;
 
-    DWORD dwOldProt;
-    SUPR3HARDENED_ASSERT_WIN32_SUCCESS(VirtualProtectEx(NtCurrentProcess(), pbNtCreateSection, 16,
-                                                        PAGE_EXECUTE_READWRITE, &dwOldProt));
+    SUPR3HARDENED_ASSERT_NT_SUCCESS(supR3HardenedWinProtectMemory(pbNtCreateSection, 16, PAGE_EXECUTE_READWRITE));
+
     pbNtCreateSection[0] = 0xff;
     pbNtCreateSection[1] = 0x25;
     *(uint32_t *)&pbNtCreateSection[2] = (uint32_t)((uintptr_t)puJmpTab - (uintptr_t)&pbNtCreateSection[2+4]);
 
-    SUPR3HARDENED_ASSERT_WIN32_SUCCESS(VirtualProtectEx(NtCurrentProcess(), pbNtCreateSection, 16,
-                                                        PAGE_EXECUTE_READ, &dwOldProt));
+    SUPR3HARDENED_ASSERT_NT_SUCCESS(supR3HardenedWinProtectMemory(pbNtCreateSection, 16, PAGE_EXECUTE_READ));
     puJmpTab++;
 
@@ -2368,13 +2335,12 @@
     *(PFNRT *)&g_pfnNtCreateSectionReal = pfnCallReal;
 
-    DWORD dwOldProt;
-    SUPR3HARDENED_ASSERT_WIN32_SUCCESS(VirtualProtectEx(NtCurrentProcess(), pbNtCreateSection, 16,
-                                                        PAGE_EXECUTE_READWRITE, &dwOldProt));
+    SUPR3HARDENED_ASSERT_NT_SUCCESS(supR3HardenedWinProtectMemory(pbNtCreateSection, 16, PAGE_EXECUTE_READWRITE));
+
     pbNtCreateSection[0] = 0xe9;
     *(uint32_t *)&pbNtCreateSection[1] = (uintptr_t)supR3HardenedMonitor_NtCreateSection
                                        - (uintptr_t)&pbNtCreateSection[1+4];
 
-    SUPR3HARDENED_ASSERT_WIN32_SUCCESS(VirtualProtectEx(NtCurrentProcess(), pbNtCreateSection, 16,
-                                                        PAGE_EXECUTE_READ, &dwOldProt));
+    SUPR3HARDENED_ASSERT_NT_SUCCESS(supR3HardenedWinProtectMemory(pbNtCreateSection, 16, PAGE_EXECUTE_READ));
+
 #endif
 
@@ -2575,5 +2541,5 @@
     *puJmpTab = (uintptr_t)supR3HardenedMonitor_LdrLoadDll;
 
-    SUPR3HARDENED_ASSERT_WIN32_SUCCESS(VirtualProtectEx(NtCurrentProcess(), pbLdrLoadDll, 16, PAGE_EXECUTE_READWRITE, &dwOldProt));
+    SUPR3HARDENED_ASSERT_NT_SUCCESS(supR3HardenedWinProtectMemory(pbLdrLoadDll, 16, PAGE_EXECUTE_READWRITE));
 
     Assert(offJmpBack >= 6);
@@ -2582,5 +2548,5 @@
     *(uint32_t *)&pbLdrLoadDll[2] = (uint32_t)((uintptr_t)puJmpTab - (uintptr_t)&pbLdrLoadDll[2+4]);
 
-    SUPR3HARDENED_ASSERT_WIN32_SUCCESS(VirtualProtectEx(NtCurrentProcess(), pbLdrLoadDll, 16, PAGE_EXECUTE_READ, &dwOldProt));
+    SUPR3HARDENED_ASSERT_NT_SUCCESS(supR3HardenedWinProtectMemory(pbLdrLoadDll, 16, PAGE_EXECUTE_READ));
     puJmpTab++;
 
@@ -2706,11 +2672,10 @@
 
     /* Patch LdrLoadDLl. */
-    SUPR3HARDENED_ASSERT_WIN32_SUCCESS(VirtualProtectEx(NtCurrentProcess(), pbLdrLoadDll, 16,
-                                                        PAGE_EXECUTE_READWRITE, &dwOldProt));
+    SUPR3HARDENED_ASSERT_NT_SUCCESS(supR3HardenedWinProtectMemory(pbLdrLoadDll, 16, PAGE_EXECUTE_READWRITE));
     Assert(offJmpBack >= 5);
     pbLdrLoadDll[0] = 0xe9;
     *(uint32_t *)&pbLdrLoadDll[1] = (uintptr_t)supR3HardenedMonitor_LdrLoadDll - (uintptr_t)&pbLdrLoadDll[1+4];
 
-    SUPR3HARDENED_ASSERT_WIN32_SUCCESS(VirtualProtectEx(NtCurrentProcess(), pbLdrLoadDll, 16, PAGE_EXECUTE_READ, &dwOldProt));
+    SUPR3HARDENED_ASSERT_NT_SUCCESS(supR3HardenedWinProtectMemory(pbLdrLoadDll, 16, PAGE_EXECUTE_READ));
 #endif
 
@@ -2718,6 +2683,5 @@
      * Seal the rwx page.
      */
-    SUPR3HARDENED_ASSERT_WIN32_SUCCESS(VirtualProtectEx(NtCurrentProcess(), g_abSupHardReadWriteExecPage, PAGE_SIZE,
-                                                        PAGE_EXECUTE_READ, &dwOldProt));
+    SUPR3HARDENED_ASSERT_NT_SUCCESS(supR3HardenedWinProtectMemory(g_abSupHardReadWriteExecPage, PAGE_SIZE, PAGE_EXECUTE_READ));
 }
 
@@ -2889,5 +2853,5 @@
      * Create a security descriptor with the above ACL.
      */
-    PSECURITY_DESCRIPTOR pSecDesc = (PSECURITY_DESCRIPTOR)suplibHardenedAllocZ(SECURITY_DESCRIPTOR_MIN_LENGTH);
+    PSECURITY_DESCRIPTOR pSecDesc = (PSECURITY_DESCRIPTOR)RTMemAllocZ(SECURITY_DESCRIPTOR_MIN_LENGTH);
     pCleanup->pSecDesc = pSecDesc;
 
@@ -2991,5 +2955,5 @@
                               "Command line is too long (%u chars)!", cwcCmdLine);
 
-    PRTUTF16 pwszCmdLine = (PRTUTF16)HeapAlloc(GetProcessHeap(), 0 /* dwFlags*/, (cwcCmdLine + 1) * sizeof(RTUTF16));
+    PRTUTF16 pwszCmdLine = (PRTUTF16)RTMemAlloc((cwcCmdLine + 1) * sizeof(RTUTF16));
     SUPR3HARDENED_ASSERT(pwszCmdLine != NULL);
 
@@ -3793,5 +3757,5 @@
                               "Error relaunching VirtualBox VM process: %u\n"
                               "Command line: '%ls'",
-                              GetLastError(), pwszCmdLine);
+                              RtlGetLastWin32Error(), pwszCmdLine);
     supR3HardenedWinDisableThreadCreation();
 
@@ -3952,5 +3916,5 @@
      */
     supR3HardenedWinFlushLoaderCache();
-    HeapCompact(GetProcessHeap(), 0 /*dwFlags*/);
+    RtlCompactHeap(GetProcessHeap(), 0 /*dwFlags*/);
 
     /*
@@ -4502,5 +4466,5 @@
     int    cArgs          = 0;
     int    cArgsAllocated = 4;
-    char **papszArgs      = (char **)suplibHardenedAllocZ(sizeof(char *) * cArgsAllocated);
+    char **papszArgs      = (char **)RTMemAllocZ(sizeof(char *) * cArgsAllocated);
     char  *pszSrc         = pszCmdLine;
     for (;;)
@@ -4517,5 +4481,5 @@
         {
             cArgsAllocated *= 2;
-            papszArgs = (char **)suplibHardenedReAlloc(papszArgs, sizeof(char *) * cArgsAllocated);
+            papszArgs = (char **)RTMemRealloc(papszArgs, sizeof(char *) * cArgsAllocated);
         }
         papszArgs[cArgs++] = pszSrc;
@@ -5143,6 +5107,6 @@
                                OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL /*hTemplateFile*/);
     if (hFile == NULL || hFile == INVALID_HANDLE_VALUE)
-        supR3HardenedFatalMsg("suplibHardenedWindowsMain", kSupInitOp_Integrity, RTErrConvertFromWin32(GetLastError()),
-                              "Error opening the executable: %u (%ls).", GetLastError());
+        supR3HardenedFatalMsg("suplibHardenedWindowsMain", kSupInitOp_Integrity, RTErrConvertFromWin32(RtlGetLastWin32Error()),
+                              "Error opening the executable: %u (%ls).", RtlGetLastWin32Error());
     RT_ZERO(g_SupLibHardenedExeNtPath);
     ULONG cbIgn;
Index: /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainA-win.asm
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainA-win.asm	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainA-win.asm	(revision 52940)
@@ -92,7 +92,8 @@
 ; @param 2  The parameter frame size on x86. Multiple of dword.
 ; @param 3  Non-zero expression if system call.
+; @param 4  Non-zero expression if early available call
 ;
 %define SUPHNTIMP_SYSCALL 1
-%macro SupHardNtImport 3
+%macro SupHardNtImport 4
         ;
         ; The data.
@@ -146,9 +147,21 @@
   %endif
 %endif
+
+%if %4 == 0
+global SUPHNTIMP_STDCALL_NAME(%1, %2) %+ _Early
+SUPHNTIMP_STDCALL_NAME(%1, %2) %+ _Early:
+        int3
+ %ifdef RT_ARCH_AMD64
+        ret
+ %else
+        ret     %2
+ %endif
+%endif
 %endmacro
 
 %define SUPHARNT_COMMENT(a_Comment)
-%define SUPHARNT_IMPORT_SYSCALL(a_Name, a_cbParamsX86) SupHardNtImport a_Name, a_cbParamsX86, SUPHNTIMP_SYSCALL
-%define SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86) SupHardNtImport a_Name, a_cbParamsX86, 0
+%define SUPHARNT_IMPORT_SYSCALL(a_Name, a_cbParamsX86)       SupHardNtImport a_Name, a_cbParamsX86, SUPHNTIMP_SYSCALL, 1
+%define SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86)       SupHardNtImport a_Name, a_cbParamsX86, 0,                 0
+%define SUPHARNT_IMPORT_STDCALL_EARLY(a_Name, a_cbParamsX86) SupHardNtImport a_Name, a_cbParamsX86, 0,                 1
 %include "import-template-ntdll.h"
 %include "import-template-kernel32.h"
Index: /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainImports-win.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainImports-win.cpp	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedMainImports-win.cpp	(revision 52940)
@@ -69,4 +69,7 @@
     /** Where to store the function address (think __imp_ApiName). */
     PFNRT              *ppfnImport;
+    /** Pointer to an early dummy function for imports that aren't available
+     * during early process initialization. */
+    PFNRT               pfnEarlyDummy;
 } SUPHNTIMPFUNC;
 /** Pointer to an import table entry.  */
@@ -151,11 +154,14 @@
  * Declare assembly symbols.
  */
-#define SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86) \
+#define SUPHARNT_IMPORT_STDCALL_EARLY(a_Name, a_cbParamsX86) \
     extern PFNRT    RT_CONCAT(g_pfn, a_Name);
 #define SUPHARNT_IMPORT_SYSCALL(a_Name, a_cbParamsX86) \
-    SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86) \
+    SUPHARNT_IMPORT_STDCALL_EARLY(a_Name, a_cbParamsX86) \
     extern uint32_t RT_CONCAT(g_uApiNo, a_Name); \
     extern FNRT     RT_CONCAT(a_Name, _SyscallType1); \
     extern FNRT     RT_CONCAT(a_Name, _SyscallType2);
+#define SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86) \
+    extern PFNRT    RT_CONCAT(g_pfn, a_Name); \
+    extern FNRT     RT_CONCAT(a_Name, _Early);
 
 RT_C_DECLS_BEGIN
@@ -168,7 +174,9 @@
  */
 #undef SUPHARNT_IMPORT_SYSCALL
+#undef SUPHARNT_IMPORT_STDCALL_EARLY
 #undef SUPHARNT_IMPORT_STDCALL
-#define SUPHARNT_IMPORT_SYSCALL(a_Name, a_cbParamsX86) { #a_Name, &RT_CONCAT(g_pfn, a_Name) },
-#define SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86) { #a_Name, &RT_CONCAT(g_pfn, a_Name) },
+#define SUPHARNT_IMPORT_SYSCALL(a_Name, a_cbParamsX86)          { #a_Name, &RT_CONCAT(g_pfn, a_Name), NULL },
+#define SUPHARNT_IMPORT_STDCALL_EARLY(a_Name, a_cbParamsX86)    { #a_Name, &RT_CONCAT(g_pfn, a_Name), NULL },
+#define SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86)          { #a_Name, &RT_CONCAT(g_pfn, a_Name), RT_CONCAT(a_Name,_Early) },
 static const SUPHNTIMPFUNC g_aSupNtImpNtDllFunctions[] =
 {
@@ -188,4 +196,5 @@
 #undef SUPHARNT_IMPORT_SYSCALL
 #undef SUPHARNT_IMPORT_STDCALL
+#undef SUPHARNT_IMPORT_STDCALL_EARLY
 #ifdef RT_ARCH_AMD64
 # define SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86) \
@@ -199,4 +208,5 @@
     { &RT_CONCAT(g_uApiNo, a_Name), &RT_CONCAT(a_Name,_SyscallType1), &RT_CONCAT(a_Name, _SyscallType2), a_cbParamsX86 },
 #endif
+#define SUPHARNT_IMPORT_STDCALL_EARLY(a_Name, a_cbParamsX86) SUPHARNT_IMPORT_STDCALL(a_Name, a_cbParamsX86)
 static const SUPHNTIMPSYSCALL g_aSupNtImpNtDllSyscalls[] =
 {
Index: /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedNoCrt-win.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedNoCrt-win.cpp	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/win/SUPR3HardenedNoCrt-win.cpp	(revision 52940)
@@ -117,5 +117,8 @@
 RTDECL(void *) RTMemAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
 {
-    return suplibHardenedAllocZ(cb);
+    void *pv = RtlAllocateHeap(GetProcessHeap(), 0 /*fFlags*/, cb);
+    if (!pv)
+        supR3HardenedFatal("RtlAllocateHeap failed to allocate %zu bytes.\n", cb);
+    return pv;
 }
 
@@ -123,5 +126,8 @@
 RTDECL(void *) RTMemAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW
 {
-    return suplibHardenedAllocZ(cb);
+    void *pv = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, cb);
+    if (!pv)
+        supR3HardenedFatal("RtlAllocateHeap failed to allocate %zu bytes.\n", cb);
+    return pv;
 }
 
@@ -151,5 +157,11 @@
 RTDECL(void *) RTMemReallocTag(void *pvOld, size_t cbNew, const char *pszTag) RT_NO_THROW
 {
-    return suplibHardenedReAlloc(pvOld, cbNew);
+    if (!pvOld)
+        return RTMemAllocZTag(cbNew, pszTag);
+
+    void *pv = RtlReAllocateHeap(GetProcessHeap(), 0 /*dwFlags*/, pvOld, cbNew);
+    if (!pv)
+        supR3HardenedFatal("RtlReAllocateHeap failed to allocate %zu bytes.\n", cbNew);
+    return pv;
 }
 
@@ -157,5 +169,6 @@
 RTDECL(void) RTMemFree(void *pv) RT_NO_THROW
 {
-    suplibHardenedFree(pv);
+    if (pv)
+        RtlFreeHeap(GetProcessHeap(), 0 /* dwFlags*/, pv);
 }
 
Index: /trunk/src/VBox/HostDrivers/Support/win/VBoxSupLib-win.cpp
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/win/VBoxSupLib-win.cpp	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/win/VBoxSupLib-win.cpp	(revision 52940)
@@ -52,5 +52,5 @@
             SetLastError(NO_ERROR);
             if (   GetModuleFileNameW((HMODULE)hModule, wszName, RT_ELEMENTS(wszName)) > 0
-                && GetLastError() == NO_ERROR)
+                && RtlGetLastWin32Error() == NO_ERROR)
             {
                 int cExtraLoads = 2;
Index: /trunk/src/VBox/HostDrivers/Support/win/import-template-kernel32.h
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/win/import-template-kernel32.h	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/win/import-template-kernel32.h	(revision 52940)
@@ -1,9 +1,5 @@
-SUPHARNT_IMPORT_STDCALL(CloseHandle, 4)
 SUPHARNT_IMPORT_STDCALL(CreateFileW, 28)
 SUPHARNT_IMPORT_STDCALL(CreateProcessW, 40)
-SUPHARNT_IMPORT_STDCALL(ExitProcess, 4)
-SUPHARNT_IMPORT_STDCALL(GetCurrentThreadId, 0)
 SUPHARNT_IMPORT_STDCALL(GetFullPathNameA, 16)
-SUPHARNT_IMPORT_STDCALL(GetLastError, 0)
 SUPHARNT_IMPORT_STDCALL(GetModuleFileNameW, 12)
 SUPHARNT_IMPORT_STDCALL(GetModuleHandleA, 4)
@@ -13,16 +9,9 @@
 SUPHARNT_IMPORT_STDCALL(GetSystemDirectoryW, 8)
 SUPHARNT_IMPORT_STDCALL(GetTickCount, 0)
-SUPHARNT_IMPORT_STDCALL(HeapAlloc, 12)
-SUPHARNT_IMPORT_STDCALL(HeapCompact, 8)
-SUPHARNT_IMPORT_STDCALL(HeapFree, 8)
-SUPHARNT_IMPORT_STDCALL(HeapReAlloc, 16)
 SUPHARNT_IMPORT_STDCALL(LoadLibraryExW, 12)
 SUPHARNT_IMPORT_STDCALL(OutputDebugStringA, 4)
-SUPHARNT_IMPORT_STDCALL(SetLastError, 4)
-SUPHARNT_IMPORT_STDCALL(Sleep, 4)
 SUPHARNT_IMPORT_STDCALL(TlsAlloc, 0)
 SUPHARNT_IMPORT_STDCALL(TlsGetValue, 4)
 SUPHARNT_IMPORT_STDCALL(TlsSetValue, 8)
-SUPHARNT_IMPORT_STDCALL(VirtualProtectEx, 20)
 SUPHARNT_IMPORT_STDCALL(WriteFile, 20)
 
Index: /trunk/src/VBox/HostDrivers/Support/win/import-template-ntdll.h
===================================================================
--- /trunk/src/VBox/HostDrivers/Support/win/import-template-ntdll.h	(revision 52939)
+++ /trunk/src/VBox/HostDrivers/Support/win/import-template-ntdll.h	(revision 52940)
@@ -54,4 +54,6 @@
 SUPHARNT_IMPORT_STDCALL(RtlAddAccessAllowedAce, 16)
 SUPHARNT_IMPORT_STDCALL(RtlAddAccessDeniedAce, 16)
+SUPHARNT_IMPORT_STDCALL(RtlAllocateHeap, 12)
+SUPHARNT_IMPORT_STDCALL(RtlCompactHeap, 8)
 SUPHARNT_IMPORT_STDCALL(RtlCopySid, 12)
 SUPHARNT_IMPORT_STDCALL(RtlCreateAcl, 12)
@@ -63,10 +65,20 @@
 SUPHARNT_IMPORT_STDCALL(RtlDosApplyFileIsolationRedirection_Ustr, 36)
 SUPHARNT_IMPORT_STDCALL(RtlEqualSid, 8)
+SUPHARNT_IMPORT_STDCALL(RtlExitProcess, 4)
+SUPHARNT_IMPORT_STDCALL(RtlExitThread, 4)
 SUPHARNT_IMPORT_STDCALL(RtlExpandEnvironmentStrings_U, 16)
+SUPHARNT_IMPORT_STDCALL(RtlFreeHeap, 12)
 SUPHARNT_IMPORT_STDCALL(RtlFreeUnicodeString, 4)
+SUPHARNT_IMPORT_STDCALL(RtlGetLastNtStatus, 0)
+SUPHARNT_IMPORT_STDCALL(RtlGetLastWin32Error, 0)
 SUPHARNT_IMPORT_STDCALL(RtlGetVersion, 4)
 SUPHARNT_IMPORT_STDCALL(RtlInitializeSid, 12)
 SUPHARNT_IMPORT_STDCALL(RtlNtStatusToDosError, 4)
+SUPHARNT_IMPORT_STDCALL(RtlReAllocateHeap, 16)
+SUPHARNT_IMPORT_STDCALL(RtlRestoreLastWin32Error, 4)
 SUPHARNT_IMPORT_STDCALL(RtlSetDaclSecurityDescriptor, 16)
+SUPHARNT_IMPORT_STDCALL(RtlSetLastWin32Error, 4)
+SUPHARNT_IMPORT_STDCALL(RtlSetLastWin32ErrorAndNtStatusFromNtStatus, 4)
+SUPHARNT_IMPORT_STDCALL(RtlSizeHeap, 12)
 SUPHARNT_IMPORT_STDCALL(RtlSubAuthoritySid, 8)
 
Index: /trunk/src/VBox/Runtime/r3/win/ntdll-mini-implib.def
===================================================================
--- /trunk/src/VBox/Runtime/r3/win/ntdll-mini-implib.def	(revision 52939)
+++ /trunk/src/VBox/Runtime/r3/win/ntdll-mini-implib.def	(revision 52940)
@@ -87,4 +87,6 @@
     RtlAddAccessAllowedAce                ;;= _RtlAddAccessAllowedAce@16
     RtlAddAccessDeniedAce                 ;;= _RtlAddAccessDeniedAce@16
+    RtlAllocateHeap                       ;;= _RtlAllocateHeap@12
+    RtlCompactHeap                        ;;= _RtlCompactHeap@8
     RtlCopySid                            ;;= _RtlCopySid@12
     RtlCreateAcl                          ;;= _RtlCreateAcl@12
@@ -96,11 +98,20 @@
     RtlDosApplyFileIsolationRedirection_Ustr ;;= _RtlDosApplyFileIsolationRedirection_Ustr@36
     RtlEqualSid                           ;;= _RtlEqualSid@8
+    RtlExitProcess                        ;;= _RtlExitProcess@4
+    RtlExitThread                         ;;= _RtlExitThread@4
     RtlExpandEnvironmentStrings_U         ;;= _RtlExpandEnvironmentStrings_U@16
+    RtlFreeHeap                           ;;= _RtlFreeHeap@12
     RtlFreeUnicodeString                  ;;= _RtlFreeUnicodeString@4
+    RtlGetLastNtStatus                    ;;= _RtlGetLastNtStatus@0
+    RtlGetLastWin32Error                  ;;= _RtlGetLastWin32Error@0
     RtlGetVersion                         ;;= _RtlGetVersion@4
     RtlInitializeSid                      ;;= _RtlInitializeSid@12
     RtlNtStatusToDosError                 ;;= _RtlNtStatusToDosError@4
+    RtlReAllocateHeap                     ;;= _RtlReAllocateHeap@16
+    RtlRestoreLastWin32Error              ;;= _RtlRestoreLastWin32Error@4
     RtlSetDaclSecurityDescriptor          ;;= _RtlSetDaclSecurityDescriptor@16
+    RtlSetLastWin32Error                  ;;= _RtlSetLastWin32Error@4
+    RtlSetLastWin32ErrorAndNtStatusFromNtStatus ;;= _RtlSetLastWin32ErrorAndNtStatusFromNtStatus@4
+    RtlSizeHeap                           ;;= _RtlSizeHeap@12
     RtlSubAuthoritySid                    ;;= _RtlSubAuthoritySid@8
 
-
