[RTL/HEAP]
[reactos.git] / reactos / lib / rtl / heap.h
index 81500d1..f00a8da 100644 (file)
 /* Segment flags */
 #define HEAP_USER_ALLOCATED    0x1
 
+/* A handy inline to distinguis normal heap, special "debug heap" and special "page heap" */
+FORCEINLINE BOOLEAN
+RtlpHeapIsSpecial(ULONG Flags)
+{
+    if (Flags & HEAP_SKIP_VALIDATION_CHECKS) return FALSE;
+
+    if (Flags & (HEAP_FLAG_PAGE_ALLOCS |
+                 HEAP_VALIDATE_ALL_ENABLED |
+                 HEAP_VALIDATE_PARAMETERS_ENABLED |
+                 HEAP_CAPTURE_STACK_BACKTRACES |
+                 HEAP_CREATE_ENABLE_TRACING))
+    {
+        /* This is a special heap */
+        return TRUE;
+    }
+
+    /* No need for a special treatment */
+    return FALSE;
+}
+
 /* Heap structures */
 struct _HEAP_COMMON_ENTRY
 {
@@ -162,6 +182,19 @@ typedef struct _HEAP_TUNING_PARAMETERS
     ULONG MaxPreCommittThreshold;
 } HEAP_TUNING_PARAMETERS, *PHEAP_TUNING_PARAMETERS;
 
+typedef struct _HEAP_LIST_LOOKUP
+{
+    struct _HEAP_LIST_LOOKUP *ExtendedLookup;
+    ULONG ArraySize;
+    ULONG ExtraItem;
+    ULONG ItemCount;
+    ULONG OutOfRangeItems;
+    ULONG BaseIndex;
+    PLIST_ENTRY ListHead;
+    PULONG ListsInUseUlong;
+    PLIST_ENTRY *ListHints;
+} HEAP_LIST_LOOKUP, *PHEAP_LIST_LOOKUP;
+
 typedef struct _HEAP
 {
     HEAP_ENTRY Entry;
@@ -178,6 +211,7 @@ typedef struct _HEAP
     USHORT SegmentAllocatorBackTraceIndex;
     USHORT Reserved;
     LIST_ENTRY UCRSegmentList;
+
     ULONG Flags;
     ULONG ForceFlags;
     ULONG CompatibilityFlags;
@@ -200,6 +234,7 @@ typedef struct _HEAP
     USHORT MaximumTagIndex;
     PHEAP_TAG_ENTRY TagEntries;
     LIST_ENTRY UCRList;
+    LIST_ENTRY UCRSegments; // FIXME: non-Vista
     ULONG AlignRound;
     ULONG AlignMask;
     LIST_ENTRY VirtualAllocdBlocks;
@@ -207,10 +242,11 @@ typedef struct _HEAP
     struct _HEAP_SEGMENT *Segments[HEAP_SEGMENTS]; //FIXME: non-Vista
     USHORT AllocatorBackTraceIndex;
     ULONG NonDedicatedListLength;
-    PVOID BlocksIndex;
+    PVOID BlocksIndex; // HEAP_LIST_LOOKUP
     PVOID UCRIndex;
     PHEAP_PSEUDO_TAG_ENTRY PseudoTagEntries;
     LIST_ENTRY FreeLists[HEAP_FREELISTS]; //FIXME: non-Vista
+    //LIST_ENTRY FreeLists;
     union
     {
         ULONG FreeListsInUseUlong[HEAP_FREELISTS / (sizeof(ULONG) * 8)]; //FIXME: non-Vista
@@ -252,6 +288,13 @@ typedef struct _HEAP_UCR_DESCRIPTOR
     ULONG Size;
 } HEAP_UCR_DESCRIPTOR, *PHEAP_UCR_DESCRIPTOR;
 
+typedef struct _HEAP_UCR_SEGMENT
+{
+    LIST_ENTRY ListEntry;
+    SIZE_T ReservedSize;
+    SIZE_T CommittedSize;
+} HEAP_UCR_SEGMENT, *PHEAP_UCR_SEGMENT;
+
 typedef struct _HEAP_ENTRY_EXTRA
 {
      union
@@ -293,7 +336,71 @@ RtlpCoalesceFreeBlocks (PHEAP Heap,
 PHEAP_ENTRY_EXTRA NTAPI
 RtlpGetExtraStuffPointer(PHEAP_ENTRY HeapEntry);
 
+BOOLEAN NTAPI
+RtlpValidateHeap(PHEAP Heap, BOOLEAN ForceValidation);
+
+BOOLEAN NTAPI
+RtlpValidateHeapEntry(PHEAP Heap, PHEAP_ENTRY HeapEntry);
+
+BOOLEAN NTAPI
+RtlpValidateHeapHeaders(PHEAP Heap, BOOLEAN Recalculate);
+
 /* heapdbg.c */
+HANDLE NTAPI
+RtlDebugCreateHeap(ULONG Flags,
+                   PVOID Addr,
+                   SIZE_T TotalSize,
+                   SIZE_T CommitSize,
+                   PVOID Lock,
+                   PRTL_HEAP_PARAMETERS Parameters);
+
+BOOLEAN NTAPI
+RtlDebugDestroyHeap(HANDLE HeapPtr);
+
+PVOID NTAPI
+RtlDebugAllocateHeap(PVOID HeapPtr,
+                     ULONG Flags,
+                     SIZE_T Size);
+
+PVOID NTAPI
+RtlDebugReAllocateHeap(HANDLE HeapPtr,
+                       ULONG Flags,
+                       PVOID Ptr,
+                       SIZE_T Size);
+
+BOOLEAN NTAPI
+RtlDebugFreeHeap(HANDLE HeapPtr,
+                 ULONG Flags,
+                 PVOID Ptr);
+
+BOOLEAN NTAPI
+RtlDebugGetUserInfoHeap(PVOID HeapHandle,
+                        ULONG Flags,
+                        PVOID BaseAddress,
+                        PVOID *UserValue,
+                        PULONG UserFlags);
+
+BOOLEAN NTAPI
+RtlDebugSetUserValueHeap(PVOID HeapHandle,
+                         ULONG Flags,
+                         PVOID BaseAddress,
+                         PVOID UserValue);
+
+BOOLEAN
+NTAPI
+RtlDebugSetUserFlagsHeap(PVOID HeapHandle,
+                         ULONG Flags,
+                         PVOID BaseAddress,
+                         ULONG UserFlagsReset,
+                         ULONG UserFlagsSet);
+
+SIZE_T NTAPI
+RtlDebugSizeHeap(HANDLE HeapPtr,
+                 ULONG Flags,
+                 PVOID Ptr);
+
+/* heappage.c */
+
 HANDLE NTAPI
 RtlpPageHeapCreate(ULONG Flags,
                    PVOID Addr,
@@ -302,4 +409,55 @@ RtlpPageHeapCreate(ULONG Flags,
                    PVOID Lock,
                    PRTL_HEAP_PARAMETERS Parameters);
 
+PVOID NTAPI
+RtlpPageHeapDestroy(HANDLE HeapPtr);
+
+PVOID NTAPI
+RtlpPageHeapAllocate(IN PVOID HeapPtr,
+                     IN ULONG Flags,
+                     IN SIZE_T Size);
+
+BOOLEAN NTAPI
+RtlpPageHeapFree(HANDLE HeapPtr,
+                 ULONG Flags,
+                 PVOID Ptr);
+
+PVOID NTAPI
+RtlpPageHeapReAllocate(HANDLE HeapPtr,
+                       ULONG Flags,
+                       PVOID Ptr,
+                       SIZE_T Size);
+
+BOOLEAN NTAPI
+RtlpPageHeapGetUserInfo(PVOID HeapHandle,
+                        ULONG Flags,
+                        PVOID BaseAddress,
+                        PVOID *UserValue,
+                        PULONG UserFlags);
+
+BOOLEAN NTAPI
+RtlpPageHeapSetUserValue(PVOID HeapHandle,
+                         ULONG Flags,
+                         PVOID BaseAddress,
+                         PVOID UserValue);
+
+BOOLEAN
+NTAPI
+RtlpPageHeapSetUserFlags(PVOID HeapHandle,
+                         ULONG Flags,
+                         PVOID BaseAddress,
+                         ULONG UserFlagsReset,
+                         ULONG UserFlagsSet);
+
+BOOLEAN
+NTAPI
+RtlpDebugPageHeapValidate(PVOID HeapPtr,
+                          ULONG Flags,
+                          PVOID Block);
+
+SIZE_T NTAPI
+RtlpPageHeapSize(HANDLE HeapPtr,
+                 ULONG Flags,
+                 PVOID Ptr);
+
 #endif