[RTL/DPH]
authorAleksey Bragin <aleksey@reactos.org>
Thu, 24 Feb 2011 12:59:52 +0000 (12:59 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Thu, 24 Feb 2011 12:59:52 +0000 (12:59 +0000)
- Implement ValidateHeap API for DPH. Fixes attempts to validate DPH as a normal heap.

svn path=/trunk/; revision=50892

reactos/lib/rtl/heap.c
reactos/lib/rtl/heap.h
reactos/lib/rtl/heappage.c

index 9b0a6f7..31bab04 100644 (file)
@@ -3707,7 +3707,9 @@ BOOLEAN NTAPI RtlValidateHeap(
     BOOLEAN HeapLocked = FALSE;
     BOOLEAN HeapValid;
 
-    // FIXME Check for special heap
+    /* Check for page heap */
+    if (Heap->ForceFlags & HEAP_FLAG_PAGE_ALLOCS)
+        return RtlpDebugPageHeapValidate(HeapPtr, Flags, Block);
 
     /* Check signature */
     if (Heap->Signature != HEAP_SIGNATURE)
index 4ea5f09..8038ed8 100644 (file)
@@ -435,6 +435,12 @@ RtlpPageHeapSetUserFlags(PVOID HeapHandle,
                          ULONG UserFlagsReset,
                          ULONG UserFlagsSet);
 
+BOOLEAN
+NTAPI
+RtlpDebugPageHeapValidate(PVOID HeapPtr,
+                          ULONG Flags,
+                          PVOID Block);
+
 SIZE_T NTAPI
 RtlpPageHeapSize(HANDLE HeapPtr,
                  ULONG Flags,
index 15b3431..19b536e 100644 (file)
@@ -191,6 +191,10 @@ RtlpDphIsNormalFreeHeapBlock(PVOID Block, PULONG ValidationInformation, BOOLEAN
 VOID NTAPI
 RtlpDphReportCorruptedBlock(PDPH_HEAP_ROOT DphRoot, ULONG Reserved, PVOID Block, ULONG ValidationInfo);
 
+BOOLEAN NTAPI
+RtlpDphNormalHeapValidate(PDPH_HEAP_ROOT DphRoot, ULONG Flags, PVOID BaseAddress);
+
+
 VOID NTAPI
 RtlpDphRaiseException(NTSTATUS Status)
 {
@@ -2224,4 +2228,68 @@ RtlpPageHeapSize(HANDLE HeapHandle,
     return Size;
 }
 
+BOOLEAN
+NTAPI
+RtlpDebugPageHeapValidate(PVOID HeapHandle,
+                          ULONG Flags,
+                          PVOID BaseAddress)
+{
+    PDPH_HEAP_ROOT DphRoot;
+    PDPH_HEAP_BLOCK Node = NULL;
+    BOOLEAN Valid = FALSE;
+
+    /* Get a pointer to the heap root */
+    DphRoot = RtlpDphPointerFromHandle(HeapHandle);
+    if (!DphRoot) return -1;
+
+    /* Add heap flags */
+    Flags |= DphRoot->HeapFlags;
+
+    /* Acquire the heap lock */
+    RtlpDphPreProcessing(DphRoot, Flags);
+
+    /* Find busy memory */
+    if (BaseAddress)
+        Node = RtlpDphFindBusyMemory(DphRoot, BaseAddress);
+
+    if (!Node)
+    {
+        /* This block was not found in page heap, or the request is to validate all normal heap */
+        Valid = RtlpDphNormalHeapValidate(DphRoot, Flags, BaseAddress);
+    }
+
+    /* Leave the heap lock */
+    RtlpDphPostProcessing(DphRoot);
+
+    /* Return result of a normal heap validation */
+    if (BaseAddress && !Node)
+        return Valid;
+
+    /* Otherwise return our own result */
+    if (!BaseAddress || Node) Valid = TRUE;
+
+    return Valid;
+}
+
+BOOLEAN
+NTAPI
+RtlpDphNormalHeapValidate(PDPH_HEAP_ROOT DphRoot,
+                          ULONG Flags,
+                          PVOID BaseAddress)
+{
+    PDPH_BLOCK_INFORMATION BlockInfo = (PDPH_BLOCK_INFORMATION)BaseAddress - 1;
+    if (!BaseAddress)
+    {
+        /* Validate all normal heap */
+        return RtlValidateHeap(DphRoot->NormalHeap, Flags, NULL);
+    }
+
+    // FIXME: Check is this a normal heap block
+    /*if (!RtlpDphIsNormalHeapBlock(DphRoot, BaseAddress, &ValidationInfo))
+    {
+    }*/
+
+    return RtlValidateHeap(DphRoot->NormalHeap, Flags, BlockInfo);
+}
+
 /* EOF */