Author: fireball
Date: Fri Feb 18 14:45:13 2011
New Revision: 50800
URL:
http://svn.reactos.org/svn/reactos?rev=50800&view=rev
Log:
[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.
Modified:
trunk/reactos/lib/rtl/heappage.c
Modified: trunk/reactos/lib/rtl/heappage.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/heappage.c?rev=508…
==============================================================================
--- trunk/reactos/lib/rtl/heappage.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/heappage.c [iso-8859-1] Fri Feb 18 14:45:13 2011
@@ -108,9 +108,6 @@
ULONG RtlpPageHeapDllRangeStart, RtlpPageHeapDllRangeEnd;
WCHAR RtlpDphTargetDlls[512];
-ULONG RtlpDphBreakOptions;
-ULONG RtlpDphDebugOptions;
-
LIST_ENTRY RtlpDphPageHeapList;
BOOLEAN RtlpDphPageHeapListInitialized;
RTL_CRITICAL_SECTION RtlpDphPageHeapListLock;
@@ -177,6 +174,10 @@
#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 @@
&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 @@
/* 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 @@
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 @@
SIZE_T Size)
{
PDPH_HEAP_BLOCK Node, AvailableNode;
- PVOID Base;
+ PVOID Base = NULL;
SIZE_T VirtualSize;
NTSTATUS Status;
@@ -937,18 +938,26 @@
}
/* 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 @@
PVOID Lock,
PRTL_HEAP_PARAMETERS Parameters)
{
- PVOID Base;
+ PVOID Base = NULL;
PHEAP HeapPtr;
PDPH_HEAP_ROOT DphRoot;
PDPH_HEAP_BLOCK DphNode;