Author: fireball
Date: Wed Feb 16 13:09:18 2011
New Revision: 50734
URL:
http://svn.reactos.org/svn/reactos?rev=50734&view=rev
Log:
[RTL/DPH]
- Connect debug page heap routines in the debug heap implementation, so they are going to
be actually called now.
- Implement delayed free queue initialization and freeing.
Modified:
trunk/reactos/lib/rtl/heapdbg.c
trunk/reactos/lib/rtl/heappage.c
Modified: trunk/reactos/lib/rtl/heapdbg.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/heapdbg.c?rev=5073…
==============================================================================
--- trunk/reactos/lib/rtl/heapdbg.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/heapdbg.c [iso-8859-1] Wed Feb 16 13:09:18 2011
@@ -136,8 +136,8 @@
BOOLEAN HeapLocked = FALSE;
PVOID Result;
- //if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
- //return RtlpPageHeapAllocateHeap(HeapPtr, Flags, Size);
+ if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
+ return RtlpPageHeapAllocate(HeapPtr, Flags, Size);
if (Heap->Signature != HEAP_SIGNATURE)
{
@@ -203,8 +203,8 @@
PVOID Result = NULL;
PHEAP_ENTRY HeapEntry;
- //if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
- //return RtlpPageHeapReAllocateHeap(HeapPtr, Flags, Size);
+ if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
+ return RtlpPageHeapReAllocate(HeapPtr, Flags, Ptr, Size);
if (Heap->Signature != HEAP_SIGNATURE)
{
@@ -273,8 +273,8 @@
PHEAP_ENTRY HeapEntry;
BOOLEAN Result = FALSE;
- //if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
- //return RtlpPageHeapFreeHeap(HeapPtr, Flags, Size);
+ if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
+ return RtlpPageHeapFree(HeapPtr, Flags, Ptr);
if (Heap->Signature != HEAP_SIGNATURE)
{
@@ -330,8 +330,8 @@
PHEAP_ENTRY HeapEntry;
BOOLEAN Result = FALSE;
- //if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
- //return RtlpPageHeapGetUserInfoHeap(HeapPtr, Flags, Size);
+ if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
+ return RtlpPageHeapGetUserInfo(HeapHandle, Flags, BaseAddress, UserValue,
UserFlags);
if (Heap->Signature != HEAP_SIGNATURE)
{
@@ -382,8 +382,8 @@
PHEAP_ENTRY HeapEntry;
BOOLEAN Result = FALSE;
- //if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
- //return RtlpPageHeapSetUserValueHeap(HeapPtr, Flags, Size);
+ if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
+ return RtlpPageHeapSetUserValue(HeapHandle, Flags, BaseAddress, UserValue);
if (Heap->Signature != HEAP_SIGNATURE)
{
@@ -439,8 +439,8 @@
PHEAP_ENTRY HeapEntry;
BOOLEAN Result = FALSE;
- //if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
- //return RtlPageHeapSetUserFlagsHeap(HeapPtr, Flags, BaseAddress, UserFlagsReset,
UserFlagsSet);
+ if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
+ return RtlpPageHeapSetUserFlags(HeapHandle, Flags, BaseAddress, UserFlagsReset,
UserFlagsSet);
/* Check if this heap allows flags to be set at all */
if (UserFlagsSet & ~HEAP_SETTABLE_USER_FLAGS ||
@@ -500,8 +500,8 @@
PHEAP_ENTRY HeapEntry;
SIZE_T Result = ~(SIZE_T)0;
- //if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
- //return RtlPageHeapSizeHeap(HeapPtr, Flags, Ptr);
+ if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
+ return RtlpPageHeapSize(HeapPtr, Flags, Ptr);
/* Check heap signature */
if (Heap->Signature != HEAP_SIGNATURE)
Modified: trunk/reactos/lib/rtl/heappage.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/heappage.c?rev=507…
==============================================================================
--- trunk/reactos/lib/rtl/heappage.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/heappage.c [iso-8859-1] Wed Feb 16 13:09:18 2011
@@ -117,6 +117,12 @@
ULONG RtlpDphPageHeapListLength;
UNICODE_STRING RtlpDphTargetDllsUnicode;
+RTL_CRITICAL_SECTION RtlpDphDelayedFreeQueueLock;
+LIST_ENTRY RtlpDphDelayedFreeQueue;
+SLIST_HEADER RtlpDphDelayedTemporaryPushList;
+ULONG RtlpDphMemoryUsedByDelayedFreeBlocks;
+ULONG RtlpDphNumberOfDelayedFreeBlocks;
+
/* Counters */
LONG RtlpDphCounter;
LONG RtlpDphAllocFails;
@@ -174,6 +180,13 @@
BOOLEAN NTAPI
RtlpDphGrowVirtual(PDPH_HEAP_ROOT DphRoot, SIZE_T Size);
+BOOLEAN NTAPI
+RtlpDphIsNormalFreeHeapBlock(PVOID Block, PULONG ValidationInformation, BOOLEAN
CheckFillers);
+
+VOID NTAPI
+RtlpDphReportCorruptedBlock(PDPH_HEAP_ROOT DphRoot, ULONG Reserved, PVOID Block, ULONG
ValidationInfo);
+
+
PVOID NTAPI
RtlpDphPointerFromHandle(PVOID Handle)
{
@@ -884,15 +897,78 @@
NTSTATUS NTAPI
RtlpDphInitializeDelayedFreeQueue()
{
- UNIMPLEMENTED;
- return STATUS_SUCCESS;
+ NTSTATUS Status;
+
+ Status = RtlInitializeCriticalSection(&RtlpDphDelayedFreeQueueLock);
+ if (!NT_SUCCESS(Status))
+ {
+ // TODO: Log this error!
+ DPRINT1("Failure initializing delayed free queue critical section\n");
+ return Status;
+ }
+
+ /* Initialize lists */
+ InitializeListHead(&RtlpDphDelayedFreeQueue);
+ RtlInitializeSListHead(&RtlpDphDelayedTemporaryPushList);
+
+ /* Reset counters */
+ RtlpDphMemoryUsedByDelayedFreeBlocks = 0;
+ RtlpDphNumberOfDelayedFreeBlocks = 0;
+
+ return Status;
}
VOID NTAPI
RtlpDphFreeDelayedBlocksFromHeap(PDPH_HEAP_ROOT DphRoot,
PHEAP NormalHeap)
{
- UNIMPLEMENTED;
+ PLIST_ENTRY Current, Next;
+ PDPH_BLOCK_INFORMATION BlockInfo;
+ ULONG ValidationInfo;
+
+ /* The original routine seems to use a temporary SList to put blocks to be freed,
+ then it releases the lock and frees the blocks. But let's make it simple for
now */
+
+ /* Acquire the delayed free queue lock */
+ RtlEnterCriticalSection(&RtlpDphDelayedFreeQueueLock);
+
+ /* Traverse the list */
+ Current = RtlpDphDelayedFreeQueue.Flink;
+ while (Current != &RtlpDphDelayedFreeQueue);
+ {
+ /* Get the next entry pointer */
+ Next = Current->Flink;
+
+ BlockInfo = CONTAINING_RECORD(Current, DPH_BLOCK_INFORMATION, FreeQueue);
+
+ /* Check if it belongs to the same heap */
+ if (BlockInfo->Heap == DphRoot)
+ {
+ /* Remove it from the list */
+ RemoveEntryList(Current);
+
+ /* Reset its heap to NULL */
+ BlockInfo->Heap = NULL;
+
+ if (!RtlpDphIsNormalFreeHeapBlock(BlockInfo + 1, &ValidationInfo, TRUE))
+ {
+ RtlpDphReportCorruptedBlock(DphRoot, 10, BlockInfo + 1, ValidationInfo);
+ }
+
+ /* Decrement counters */
+ RtlpDphMemoryUsedByDelayedFreeBlocks -= BlockInfo->ActualSize;
+ RtlpDphNumberOfDelayedFreeBlocks--;
+
+ /* Free the normal heap */
+ RtlFreeHeap (NormalHeap, 0, BlockInfo);
+ }
+
+ /* Move to the next one */
+ Current = Next;
+ }
+
+ /* Release the delayed free queue lock */
+ RtlLeaveCriticalSection(&RtlpDphDelayedFreeQueueLock);
}
NTSTATUS NTAPI
@@ -1025,6 +1101,18 @@
}
return (SomethingWrong == FALSE);
+}
+
+BOOLEAN NTAPI
+RtlpDphIsNormalFreeHeapBlock(PVOID Block,
+ PULONG ValidationInformation,
+ BOOLEAN CheckFillers)
+{
+ ASSERT(ValidationInformation != NULL);
+
+ UNIMPLEMENTED;
+ *ValidationInformation = 0;
+ return TRUE;
}
NTSTATUS NTAPI