mirror of
https://github.com/reactos/reactos.git
synced 2024-08-04 10:30:59 +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
|
@ -108,9 +108,6 @@ ULONG RtlpPageHeapSizeRangeStart, RtlpPageHeapSizeRangeEnd;
|
||||||
ULONG RtlpPageHeapDllRangeStart, RtlpPageHeapDllRangeEnd;
|
ULONG RtlpPageHeapDllRangeStart, RtlpPageHeapDllRangeEnd;
|
||||||
WCHAR RtlpDphTargetDlls[512];
|
WCHAR RtlpDphTargetDlls[512];
|
||||||
|
|
||||||
ULONG RtlpDphBreakOptions;
|
|
||||||
ULONG RtlpDphDebugOptions;
|
|
||||||
|
|
||||||
LIST_ENTRY RtlpDphPageHeapList;
|
LIST_ENTRY RtlpDphPageHeapList;
|
||||||
BOOLEAN RtlpDphPageHeapListInitialized;
|
BOOLEAN RtlpDphPageHeapListInitialized;
|
||||||
RTL_CRITICAL_SECTION RtlpDphPageHeapListLock;
|
RTL_CRITICAL_SECTION RtlpDphPageHeapListLock;
|
||||||
|
@ -177,6 +174,10 @@ LONG RtlpDphProtectFails;
|
||||||
#define POINTER_REMOVE_BIAS(ptr) ((ULONG_PTR)(ptr) & ~(ULONG_PTR)1)
|
#define POINTER_REMOVE_BIAS(ptr) ((ULONG_PTR)(ptr) & ~(ULONG_PTR)1)
|
||||||
#define POINTER_ADD_BIAS(ptr) ((ULONG_PTR)(ptr) & 1)
|
#define POINTER_ADD_BIAS(ptr) ((ULONG_PTR)(ptr) & 1)
|
||||||
|
|
||||||
|
|
||||||
|
ULONG RtlpDphBreakOptions = 0;//0xFFFFFFFF;
|
||||||
|
ULONG RtlpDphDebugOptions;
|
||||||
|
|
||||||
/* FUNCTIONS ******************************************************************/
|
/* FUNCTIONS ******************************************************************/
|
||||||
|
|
||||||
BOOLEAN NTAPI
|
BOOLEAN NTAPI
|
||||||
|
@ -312,7 +313,7 @@ RtlpDphAllocateVm(PVOID *Base, SIZE_T Size, ULONG Type, ULONG Protection)
|
||||||
&Size,
|
&Size,
|
||||||
Type,
|
Type,
|
||||||
Protection);
|
Protection);
|
||||||
|
DPRINT1("Page heap: AllocVm (%p, %p, %x) status %x \n", Base, Size, Type, Status);
|
||||||
/* Check for failures */
|
/* Check for failures */
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
@ -348,7 +349,7 @@ RtlpDphFreeVm(PVOID Base, SIZE_T Size, ULONG Type)
|
||||||
|
|
||||||
/* Free the memory */
|
/* Free the memory */
|
||||||
Status = RtlpSecMemFreeVirtualMemory(NtCurrentProcess(), &Base, &Size, Type);
|
Status = RtlpSecMemFreeVirtualMemory(NtCurrentProcess(), &Base, &Size, Type);
|
||||||
|
DPRINT1("Page heap: FreeVm (%p, %p, %x) status %x \n", Base, Size, Type, Status);
|
||||||
/* Log/report failures */
|
/* Log/report failures */
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
@ -811,7 +812,7 @@ RtlpDphAllocateNode(PDPH_HEAP_ROOT DphRoot)
|
||||||
PDPH_HEAP_BLOCK Node;
|
PDPH_HEAP_BLOCK Node;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
SIZE_T Size = DPH_POOL_SIZE, SizeVirtual;
|
SIZE_T Size = DPH_POOL_SIZE, SizeVirtual;
|
||||||
PVOID Ptr;
|
PVOID Ptr = NULL;
|
||||||
|
|
||||||
/* Check for the easy case */
|
/* Check for the easy case */
|
||||||
if (DphRoot->pUnusedNodeListHead)
|
if (DphRoot->pUnusedNodeListHead)
|
||||||
|
@ -920,7 +921,7 @@ RtlpDphGrowVirtual(PDPH_HEAP_ROOT DphRoot,
|
||||||
SIZE_T Size)
|
SIZE_T Size)
|
||||||
{
|
{
|
||||||
PDPH_HEAP_BLOCK Node, AvailableNode;
|
PDPH_HEAP_BLOCK Node, AvailableNode;
|
||||||
PVOID Base;
|
PVOID Base = NULL;
|
||||||
SIZE_T VirtualSize;
|
SIZE_T VirtualSize;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
|
@ -937,12 +938,19 @@ RtlpDphGrowVirtual(PDPH_HEAP_ROOT DphRoot,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate size of VM to allocate by rounding it up */
|
/* Calculate size of VM to allocate by rounding it up */
|
||||||
VirtualSize = (Size + 0xFFFF) & 0xFFFF0000;
|
Size = ROUND_UP(Size, 0xFFFF);
|
||||||
if (VirtualSize < DPH_RESERVE_SIZE)
|
VirtualSize = Size;
|
||||||
|
if (Size < DPH_RESERVE_SIZE)
|
||||||
VirtualSize = DPH_RESERVE_SIZE;
|
VirtualSize = DPH_RESERVE_SIZE;
|
||||||
|
|
||||||
/* Allocate the virtual memory */
|
/* 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))
|
||||||
|
{
|
||||||
|
/* Retry again with a smaller size */
|
||||||
|
VirtualSize = Size;
|
||||||
|
Status = RtlpDphAllocateVm(&Base, VirtualSize, MEM_COMMIT, PAGE_NOACCESS);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
/* Free the allocated node and return failure */
|
/* Free the allocated node and return failure */
|
||||||
|
@ -950,6 +958,7 @@ RtlpDphGrowVirtual(PDPH_HEAP_ROOT DphRoot,
|
||||||
RtlpDphReturnNodeToUnusedList(DphRoot, AvailableNode);
|
RtlpDphReturnNodeToUnusedList(DphRoot, AvailableNode);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Set up our two nodes describing this VM */
|
/* Set up our two nodes describing this VM */
|
||||||
Node->pVirtualBlock = Base;
|
Node->pVirtualBlock = Base;
|
||||||
|
@ -1287,7 +1296,7 @@ RtlpPageHeapCreate(ULONG Flags,
|
||||||
PVOID Lock,
|
PVOID Lock,
|
||||||
PRTL_HEAP_PARAMETERS Parameters)
|
PRTL_HEAP_PARAMETERS Parameters)
|
||||||
{
|
{
|
||||||
PVOID Base;
|
PVOID Base = NULL;
|
||||||
PHEAP HeapPtr;
|
PHEAP HeapPtr;
|
||||||
PDPH_HEAP_ROOT DphRoot;
|
PDPH_HEAP_ROOT DphRoot;
|
||||||
PDPH_HEAP_BLOCK DphNode;
|
PDPH_HEAP_BLOCK DphNode;
|
||||||
|
|
Loading…
Reference in a new issue