SUPR3HardenedNoCrt-win.cpp revision 9f997e760f610c92e3a365be21ead6972bc46130
/* $Id$ */
/** @file
* VirtualBox Support Library - Hardened main(), windows bits.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <AccCtrl.h>
#include <AclApi.h>
#ifndef PROCESS_SET_LIMITED_INFORMATION
# define PROCESS_SET_LIMITED_INFORMATION 0x2000
#endif
#include <iprt/initterm.h>
#include "SUPLibInternal.h"
#include "win/SUPHardenedVerify-win.h"
/*
*/
RTDATADECL(const char * volatile) g_pszRTAssertExpr;
RTDATADECL(const char * volatile) g_pszRTAssertFile;
RTDATADECL(const char * volatile) g_pszRTAssertFunction;
RTDECL(bool) RTAssertMayPanic(void)
{
return true;
}
RTDECL(void) RTAssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
{
/*
* Fill in the globals.
*/
"\n!!Assertion Failed!!\n"
"Expression: %s\n"
"Location : %s(%d) %s\n",
}
{
else
supR3HardenedError(VERR_INTERNAL_ERROR, false/*fFatal*/, "%s%s", g_szRTAssertMsg1, g_szRTAssertMsg2);
}
/*
* Memory allocator.
*/
/** The handle of the heap we're using. */
/** Number of heaps used during early process init. */
static uint32_t g_cSupR3HardenedEarlyHeaps = 0;
/** Early process init heaps. */
static struct
{
/** The heap handle. */
/** The heap block pointer. */
void *pvBlock;
/** The size of the heap block. */
/** Number of active allocations on this heap. */
{
while (iHeap-- > 0)
if ((uintptr_t)pv - (uintptr_t)g_aSupR3HardenedEarlyHeaps[iHeap].pvBlock < g_aSupR3HardenedEarlyHeaps[iHeap].cbBlock)
return iHeap;
return UINT32_MAX;
}
static void supR3HardenedEarlyCompact(void)
{
while (iHeap-- > 0)
{
}
}
{
/*
* Try allocate on existing heaps.
*/
void *pv;
while (iHeap < g_cSupR3HardenedEarlyHeaps)
{
if (fZero)
else
if (pv)
{
#endif
return pv;
}
iHeap++;
}
/*
* Add another heap.
*/
cbBlock *= 2;
NTSTATUS rcNt = NtAllocateVirtualMemory(NtCurrentProcess(), &pvBlock, 0 /*ZeroBits*/, &cbBlock, MEM_COMMIT, PAGE_READWRITE);
if (!NT_SUCCESS(rcNt))
SUP_DPRINTF(("New simple heap: #%u %p LB %#zx (for %zu allocation)\n", iHeap, pvBlock, cbBlock, cb));
if (RT_FAILURE(rc))
if (fZero)
else
if (!pv)
supR3HardenedFatal("RTHeapSimpleAlloc[Z] failed allocating %#zx bytes on a %#zu heap.\n", cb, cbBlock);
#endif
return pv;
}
/**
* Lazy heap initialization function.
*
* @returns Heap handle.
*/
static HANDLE supR3HardenedHeapInit(void)
{
if (hHeap)
{
return hHeap;
}
supR3HardenedFatal("RtlCreateHeap failed.\n");
return NULL;
}
/**
*/
DECLHIDDEN(void) supR3HardenedWinCompactHeaps(void)
{
if (g_hSupR3HardenedHeap)
}
{
}
{
}
{
}
{
if (!hHeap)
{
}
if (!pv)
return pv;
}
{
if (!hHeap)
{
}
if (!pv)
return pv;
}
{
if (cbUnaligned >= 16)
else
}
{
if (cbUnaligned >= 16)
else
}
{
if (!pvOld)
void *pv;
{
if (iHeap != UINT32_MAX)
{
#if 0 /* RTHeapSimpleRealloc is not implemented */
/* If this is before we can use a regular heap, we try resize
within the simple heap. (There are a lot of array growing in
the ASN.1 code.) */
{
if (pv)
{
# ifdef SUPR3HARDENED_EARLY_HEAP_TRACE
# endif
return pv;
}
}
#endif
/* Either we can't reallocate it on the same simple heap, or we're
past hardened main and wish to migrate everything over on the
real heap. */
if (pv)
{
}
# ifdef SUPR3HARDENED_EARLY_HEAP_TRACE
# endif
return pv;
}
}
/* Allocate from the regular heap. */
if (!pv)
return pv;
}
{
if (pv)
{
{
if (iHeap != UINT32_MAX)
{
#endif
return;
}
}
}
}
/*
* Simplified version of RTMemWipeThoroughly that avoids dragging in the
* random number code.
*/
{
do
{
} while (cPasses-- > 0);
}
/*
*/
{
int rc;
/** @todo Rainy day: improve this by checking the process parameter block
* (needs to be normalized). */
else
{
/*
* GetCurrentDirectory may in some cases omit the drive letter, according
* to MSDN, thus the GetFullPathName call.
*/
{
else
}
else
}
return rc;
}