mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 16:36:33 +00:00
[RTL/DPH]
- Zero-initialize VM allocation base. - Don't reserve VM, just commit it right away. This was a premature optimisation. Instead, retry committing a smaller amount of memory if committing all memory fails. svn path=/trunk/; revision=50800
This commit is contained in:
parent
b58bdd0a99
commit
da4ba71aee
1 changed files with 24 additions and 15 deletions
|
@ -108,9 +108,6 @@ ULONG RtlpPageHeapSizeRangeStart, RtlpPageHeapSizeRangeEnd;
|
|||
ULONG RtlpPageHeapDllRangeStart, RtlpPageHeapDllRangeEnd;
|
||||
WCHAR RtlpDphTargetDlls[512];
|
||||
|
||||
ULONG RtlpDphBreakOptions;
|
||||
ULONG RtlpDphDebugOptions;
|
||||
|
||||
LIST_ENTRY RtlpDphPageHeapList;
|
||||
BOOLEAN RtlpDphPageHeapListInitialized;
|
||||
RTL_CRITICAL_SECTION RtlpDphPageHeapListLock;
|
||||
|
@ -177,6 +174,10 @@ LONG RtlpDphProtectFails;
|
|||
#define POINTER_REMOVE_BIAS(ptr) ((ULONG_PTR)(ptr) & ~(ULONG_PTR)1)
|
||||
#define POINTER_ADD_BIAS(ptr) ((ULONG_PTR)(ptr) & 1)
|
||||
|
||||
|
||||
ULONG RtlpDphBreakOptions = 0;//0xFFFFFFFF;
|
||||
ULONG RtlpDphDebugOptions;
|
||||
|
||||
/* FUNCTIONS ******************************************************************/
|
||||
|
||||
BOOLEAN NTAPI
|
||||
|
@ -312,7 +313,7 @@ RtlpDphAllocateVm(PVOID *Base, SIZE_T Size, ULONG Type, ULONG Protection)
|
|||
&Size,
|
||||
Type,
|
||||
Protection);
|
||||
|
||||
DPRINT1("Page heap: AllocVm (%p, %p, %x) status %x \n", Base, Size, Type, Status);
|
||||
/* Check for failures */
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
|
@ -348,7 +349,7 @@ RtlpDphFreeVm(PVOID Base, SIZE_T Size, ULONG Type)
|
|||
|
||||
/* Free the memory */
|
||||
Status = RtlpSecMemFreeVirtualMemory(NtCurrentProcess(), &Base, &Size, Type);
|
||||
|
||||
DPRINT1("Page heap: FreeVm (%p, %p, %x) status %x \n", Base, Size, Type, Status);
|
||||
/* Log/report failures */
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
|
@ -811,7 +812,7 @@ RtlpDphAllocateNode(PDPH_HEAP_ROOT DphRoot)
|
|||
PDPH_HEAP_BLOCK Node;
|
||||
NTSTATUS Status;
|
||||
SIZE_T Size = DPH_POOL_SIZE, SizeVirtual;
|
||||
PVOID Ptr;
|
||||
PVOID Ptr = NULL;
|
||||
|
||||
/* Check for the easy case */
|
||||
if (DphRoot->pUnusedNodeListHead)
|
||||
|
@ -920,7 +921,7 @@ RtlpDphGrowVirtual(PDPH_HEAP_ROOT DphRoot,
|
|||
SIZE_T Size)
|
||||
{
|
||||
PDPH_HEAP_BLOCK Node, AvailableNode;
|
||||
PVOID Base;
|
||||
PVOID Base = NULL;
|
||||
SIZE_T VirtualSize;
|
||||
NTSTATUS Status;
|
||||
|
||||
|
@ -937,18 +938,26 @@ RtlpDphGrowVirtual(PDPH_HEAP_ROOT DphRoot,
|
|||
}
|
||||
|
||||
/* Calculate size of VM to allocate by rounding it up */
|
||||
VirtualSize = (Size + 0xFFFF) & 0xFFFF0000;
|
||||
if (VirtualSize < DPH_RESERVE_SIZE)
|
||||
Size = ROUND_UP(Size, 0xFFFF);
|
||||
VirtualSize = Size;
|
||||
if (Size < DPH_RESERVE_SIZE)
|
||||
VirtualSize = DPH_RESERVE_SIZE;
|
||||
|
||||
/* Allocate the virtual memory */
|
||||
Status = RtlpDphAllocateVm(&Base, VirtualSize, MEM_RESERVE, PAGE_NOACCESS);
|
||||
// FIXME: Shouldn't it be MEM_RESERVE with later committing?
|
||||
Status = RtlpDphAllocateVm(&Base, VirtualSize, MEM_COMMIT, PAGE_NOACCESS);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* Free the allocated node and return failure */
|
||||
RtlpDphReturnNodeToUnusedList(DphRoot, Node);
|
||||
RtlpDphReturnNodeToUnusedList(DphRoot, AvailableNode);
|
||||
return FALSE;
|
||||
/* Retry again with a smaller size */
|
||||
VirtualSize = Size;
|
||||
Status = RtlpDphAllocateVm(&Base, VirtualSize, MEM_COMMIT, PAGE_NOACCESS);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* Free the allocated node and return failure */
|
||||
RtlpDphReturnNodeToUnusedList(DphRoot, Node);
|
||||
RtlpDphReturnNodeToUnusedList(DphRoot, AvailableNode);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set up our two nodes describing this VM */
|
||||
|
@ -1287,7 +1296,7 @@ RtlpPageHeapCreate(ULONG Flags,
|
|||
PVOID Lock,
|
||||
PRTL_HEAP_PARAMETERS Parameters)
|
||||
{
|
||||
PVOID Base;
|
||||
PVOID Base = NULL;
|
||||
PHEAP HeapPtr;
|
||||
PDPH_HEAP_ROOT DphRoot;
|
||||
PDPH_HEAP_BLOCK DphNode;
|
||||
|
|
Loading…
Reference in a new issue