ReactOS  0.4.14-dev-50-g13bb5e2
heap.c File Reference
#include <freeldr.h>
#include <debug.h>
Include dependency graph for heap.c:

Go to the source code of this file.

Classes

struct  _BLOCK_DATA
 
struct  _HEAP_BLOCK
 
struct  _HEAP
 

Macros

#define FREELDR_HEAP_VERIFIER
 
#define REDZONE_MARK   0xCCCCCCCCCCCCCCCCULL
 
#define REDZONE_ALLOCATION   24
 
#define REDZONE_LOW_OFFSET   16
 
#define REDZONE_SIZE(Block)   ((ULONG64*)Block->Data)
 
#define REDZONE_LOW(Block)   ((ULONG64*)Block->Data + 1)
 
#define REDZONE_HI(Block)   ((ULONG64*)((PUCHAR)Block->Data + 16 + *REDZONE_SIZE(Block)))
 

Typedefs

typedef struct _BLOCK_DATA BLOCK_DATA
 
typedef struct _BLOCK_DATAPBLOCK_DATA
 
typedef struct _HEAP_BLOCK HEAP_BLOCK
 
typedef struct _HEAP_BLOCKPHEAP_BLOCK
 
typedef struct _HEAP HEAP
 
typedef struct _HEAPPHEAP
 

Functions

 DBG_DEFAULT_CHANNEL (HEAP)
 
PVOID FrLdrHeapCreate (SIZE_T MaximumSize, TYPE_OF_MEMORY MemoryType)
 
VOID FrLdrHeapDestroy (PVOID HeapHandle)
 
VOID FrLdrHeapVerify (PVOID HeapHandle)
 
VOID FrLdrHeapRelease (PVOID HeapHandle)
 
VOID FrLdrHeapCleanupAll (VOID)
 
static VOID FrLdrHeapRemoveFreeList (PHEAP Heap, PHEAP_BLOCK Block)
 
static VOID FrLdrHeapInsertFreeList (PHEAP Heap, PHEAP_BLOCK FreeBlock)
 
PVOID FrLdrHeapAllocateEx (PVOID HeapHandle, SIZE_T ByteSize, ULONG Tag)
 
VOID FrLdrHeapFreeEx (PVOID HeapHandle, PVOID Pointer, ULONG Tag)
 
VOID MmInitializeHeap (PVOID PageLookupTable)
 
PVOID NTAPI ExAllocatePoolWithTag (IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes, IN ULONG Tag)
 
PVOID NTAPI ExAllocatePool (IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
 
VOID NTAPI ExFreePool (IN PVOID P)
 
VOID NTAPI ExFreePoolWithTag (IN PVOID P, IN ULONG Tag)
 
PVOID NTAPI RtlAllocateHeap (IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
 
BOOLEAN NTAPI RtlFreeHeap (IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
 

Variables

PVOID FrLdrDefaultHeap
 
PVOID FrLdrTempHeap
 

Macro Definition Documentation

◆ FREELDR_HEAP_VERIFIER

#define FREELDR_HEAP_VERIFIER

Definition at line 25 of file heap.c.

◆ REDZONE_ALLOCATION

#define REDZONE_ALLOCATION   24

Definition at line 28 of file heap.c.

◆ REDZONE_HI

#define REDZONE_HI (   Block)    ((ULONG64*)((PUCHAR)Block->Data + 16 + *REDZONE_SIZE(Block)))

Definition at line 32 of file heap.c.

◆ REDZONE_LOW

#define REDZONE_LOW (   Block)    ((ULONG64*)Block->Data + 1)

Definition at line 31 of file heap.c.

◆ REDZONE_LOW_OFFSET

#define REDZONE_LOW_OFFSET   16

Definition at line 29 of file heap.c.

◆ REDZONE_MARK

#define REDZONE_MARK   0xCCCCCCCCCCCCCCCCULL

Definition at line 27 of file heap.c.

◆ REDZONE_SIZE

#define REDZONE_SIZE (   Block)    ((ULONG64*)Block->Data)

Definition at line 30 of file heap.c.

Typedef Documentation

◆ BLOCK_DATA

◆ HEAP

typedef struct _HEAP HEAP

◆ HEAP_BLOCK

◆ PBLOCK_DATA

◆ PHEAP

typedef struct _HEAP * PHEAP

◆ PHEAP_BLOCK

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( HEAP  )

◆ ExAllocatePool()

PVOID NTAPI ExAllocatePool ( IN POOL_TYPE  PoolType,
IN SIZE_T  NumberOfBytes 
)

Definition at line 562 of file heap.c.

565 {
567 }
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:998
PVOID FrLdrHeapAllocateEx(PVOID HeapHandle, SIZE_T ByteSize, ULONG Tag)
Definition: heap.c:320
PVOID FrLdrDefaultHeap
Definition: heap.c:34

◆ ExAllocatePoolWithTag()

PVOID NTAPI ExAllocatePoolWithTag ( IN POOL_TYPE  PoolType,
IN SIZE_T  NumberOfBytes,
IN ULONG  Tag 
)

Definition at line 552 of file heap.c.

556 {
558 }
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:998
PVOID FrLdrHeapAllocateEx(PVOID HeapHandle, SIZE_T ByteSize, ULONG Tag)
Definition: heap.c:320
PVOID FrLdrDefaultHeap
Definition: heap.c:34

◆ ExFreePool()

VOID NTAPI ExFreePool ( IN PVOID  P)

Definition at line 571 of file heap.c.

573 {
575 }
VOID FrLdrHeapFreeEx(PVOID HeapHandle, PVOID Pointer, ULONG Tag)
Definition: heap.c:438
#define P(row, col)
PVOID FrLdrDefaultHeap
Definition: heap.c:34

◆ ExFreePoolWithTag()

VOID NTAPI ExFreePoolWithTag ( IN PVOID  P,
IN ULONG  Tag 
)

Definition at line 579 of file heap.c.

582 {
584 }
VOID FrLdrHeapFreeEx(PVOID HeapHandle, PVOID Pointer, ULONG Tag)
Definition: heap.c:438
#define P(row, col)
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
PVOID FrLdrDefaultHeap
Definition: heap.c:34

◆ FrLdrHeapAllocateEx()

PVOID FrLdrHeapAllocateEx ( PVOID  HeapHandle,
SIZE_T  ByteSize,
ULONG  Tag 
)

Definition at line 320 of file heap.c.

324 {
325  PHEAP Heap = HeapHandle;
326  PHEAP_BLOCK Block, NextBlock;
327  USHORT BlockSize, Remaining;
328 #if DBG && !defined(_M_ARM)
329  ULONGLONG Time = __rdtsc();
330 #endif
331 
332 #ifdef FREELDR_HEAP_VERIFIER
333  /* Verify the heap */
334  FrLdrHeapVerify(HeapHandle);
335 
336  /* Add space for a size field and 2 redzones */
338 #endif
339 
340  /* Check if the allocation is too large */
341  if ((ByteSize + sizeof(HEAP_BLOCK)) > MAXUSHORT * sizeof(HEAP_BLOCK))
342  {
343  ERR("HEAP: Allocation of 0x%lx bytes too large\n", ByteSize);
344  return NULL;
345  }
346 
347  /* We need a proper tag */
348  if (Tag == 0) Tag = 'enoN';
349 
350  /* Calculate alloc size */
351  BlockSize = (USHORT)((ByteSize + sizeof(HEAP_BLOCK) - 1) / sizeof(HEAP_BLOCK));
352 
353  /* Walk the free block list */
354  Block = &Heap->Blocks + Heap->TerminatingBlock;
355  for (Block = &Heap->Blocks + Block->Data[0].Flink;
356  Block->Size != 0;
357  Block = &Heap->Blocks + Block->Data[0].Flink)
358  {
359  ASSERT(Block->Tag == 0);
360 
361  /* Continue, if its too small */
362  if (Block->Size < BlockSize) continue;
363 
364  /* This block is just fine, use it */
365  Block->Tag = Tag;
366 
367  /* Remove this entry from the free list */
368  FrLdrHeapRemoveFreeList(Heap, Block);
369 
370  /* Calculate the remaining size */
371  Remaining = Block->Size - BlockSize;
372 
373  /* Check if the remaining space is large enough for a new block */
374  if (Remaining > 1)
375  {
376  /* Make the allocated block as large as necessary */
377  Block->Size = BlockSize;
378 
379  /* Get pointer to the new block */
380  NextBlock = Block + 1 + BlockSize;
381 
382  /* Make it a free block */
383  NextBlock->Tag = 0;
384  NextBlock->Size = Remaining - 1;
385  NextBlock->PreviousSize = BlockSize;
386  BlockSize = NextBlock->Size;
387  FrLdrHeapInsertFreeList(Heap, NextBlock);
388 
389  /* Advance to the next block */
390  NextBlock = NextBlock + 1 + BlockSize;
391  }
392  else
393  {
394  /* Not enough left, use the full block */
395  BlockSize = Block->Size;
396 
397  /* Get the next block */
398  NextBlock = Block + 1 + BlockSize;
399  }
400 
401  /* Update the next blocks back link */
402  NextBlock->PreviousSize = BlockSize;
403 
404  /* Update heap usage */
405  Heap->NumAllocs++;
406  Heap->CurrentAllocBytes += Block->Size * sizeof(HEAP_BLOCK);
407  Heap->MaxAllocBytes = max(Heap->MaxAllocBytes, Heap->CurrentAllocBytes);
409  Block->Size * sizeof(HEAP_BLOCK));
410 #if DBG && !defined(_M_ARM)
411  Heap->AllocationTime += (__rdtsc() - Time);
412 #endif
413  TRACE("HeapAllocate(%p, %ld, %.4s) -> return %p\n",
414  HeapHandle, ByteSize, &Tag, Block->Data);
415 
416  /* HACK: zero out the allocation */
417  RtlZeroMemory(Block->Data, Block->Size * sizeof(HEAP_BLOCK));
418 
419 #ifdef FREELDR_HEAP_VERIFIER
420  /* Write size and redzones */
422  *REDZONE_LOW(Block) = REDZONE_MARK;
423  *REDZONE_HI(Block) = REDZONE_MARK;
424 
425  /* Allocation starts after size field and redzone */
426  return (PUCHAR)Block->Data + REDZONE_LOW_OFFSET;
427 #endif
428  /* Return pointer to the data */
429  return Block->Data;
430  }
431 
432  /* We found nothing */
433  WARN("HEAP: nothing suitable found for 0x%lx bytes\n", ByteSize);
434  return NULL;
435 }
SIZE_T MaxAllocBytes
Definition: heap.c:55
HEAP_BLOCK Blocks
Definition: heap.c:62
ULONGLONG AllocationTime
Definition: heap.c:59
#define max(a, b)
Definition: svc.c:63
ULONG_PTR Flink
Definition: heap.c:39
#define REDZONE_MARK
Definition: heap.c:27
unsigned char * PUCHAR
Definition: retypes.h:3
#define WARN(fmt,...)
Definition: debug.h:111
VOID FrLdrHeapVerify(PVOID HeapHandle)
Definition: heap.c:156
USHORT PreviousSize
Definition: heap.c:46
ULONG Tag
Definition: heap.c:47
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
USHORT Size
Definition: heap.c:45
#define REDZONE_SIZE(Block)
Definition: heap.c:30
struct _HEAP_BLOCK HEAP_BLOCK
smooth NULL
Definition: ftsmooth.c:416
ULONG NumAllocs
Definition: heap.c:56
#define REDZONE_ALLOCATION
Definition: heap.c:28
#define TRACE(s)
Definition: solgame.cpp:4
uint64_t ULONGLONG
Definition: typedefs.h:65
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define REDZONE_LOW_OFFSET
Definition: heap.c:29
static VOID FrLdrHeapInsertFreeList(PHEAP Heap, PHEAP_BLOCK FreeBlock)
Definition: heap.c:298
#define ERR(fmt,...)
Definition: debug.h:109
BLOCK_DATA Data[]
Definition: heap.c:48
unsigned short USHORT
Definition: pedump.c:61
#define MAXUSHORT
Definition: typedefs.h:81
SIZE_T CurrentAllocBytes
Definition: heap.c:54
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
#define REDZONE_LOW(Block)
Definition: heap.c:31
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
ULONG_PTR TerminatingBlock
Definition: heap.c:61
#define REDZONE_HI(Block)
Definition: heap.c:32
_IRQL_requires_same_ _In_ CLONG ByteSize
Definition: rtltypes.h:389
SIZE_T LargestAllocation
Definition: heap.c:58
static PLARGE_INTEGER Time
Definition: time.c:105
Definition: heap.c:51
static VOID FrLdrHeapRemoveFreeList(PHEAP Heap, PHEAP_BLOCK Block)
Definition: heap.c:280

Referenced by ExAllocatePool(), ExAllocatePoolWithTag(), FrLdrHeapAlloc(), FrLdrTempAlloc(), RtlAllocateHeap(), and RtlpAllocateMemory().

◆ FrLdrHeapCleanupAll()

VOID FrLdrHeapCleanupAll ( VOID  )

Definition at line 248 of file heap.c.

249 {
250 #if DBG
251  PHEAP Heap;
252 
253  Heap = FrLdrDefaultHeap;
254  TRACE("Heap statistics for default heap:\n"
255  "CurrentAlloc=0x%lx, MaxAlloc=0x%lx, LargestAllocation=0x%lx\n"
256  "NumAllocs=%ld, NumFrees=%ld\n",
258  Heap->NumAllocs, Heap->NumFrees);
259  TRACE("AllocTime = %I64d, FreeTime = %I64d, sum = %I64d\n",
260  Heap->AllocationTime, Heap->FreeTime, Heap->AllocationTime + Heap->FreeTime);
261 #endif
262 
263  /* Release free pages from the default heap */
265 
266 #if DBG
267  Heap = FrLdrTempHeap;
268  TRACE("Heap statistics for temp heap:\n"
269  "CurrentAlloc=0x%lx, MaxAlloc=0x%lx, LargestAllocation=0x%lx\n"
270  "NumAllocs=%ld, NumFrees=%ld\n",
272  Heap->NumAllocs, Heap->NumFrees);
273 #endif
274 
275  /* Destroy the temp heap */
277 }
SIZE_T MaxAllocBytes
Definition: heap.c:55
ULONGLONG AllocationTime
Definition: heap.c:59
VOID FrLdrHeapRelease(PVOID HeapHandle)
Definition: heap.c:181
VOID FrLdrHeapDestroy(PVOID HeapHandle)
Definition: heap.c:137
ULONG NumAllocs
Definition: heap.c:56
#define TRACE(s)
Definition: solgame.cpp:4
ULONGLONG FreeTime
Definition: heap.c:60
PVOID FrLdrTempHeap
Definition: heap.c:35
ULONG NumFrees
Definition: heap.c:57
SIZE_T CurrentAllocBytes
Definition: heap.c:54
SIZE_T LargestAllocation
Definition: heap.c:58
PVOID FrLdrDefaultHeap
Definition: heap.c:34
Definition: heap.c:51

Referenced by WinLdrSetupMemoryLayout().

◆ FrLdrHeapCreate()

PVOID FrLdrHeapCreate ( SIZE_T  MaximumSize,
TYPE_OF_MEMORY  MemoryType 
)

Definition at line 66 of file heap.c.

69 {
70  PHEAP Heap;
71  PHEAP_BLOCK Block;
72  SIZE_T Remaining;
73  USHORT PreviousSize;
74  TRACE("HeapCreate(MemoryType=%ld)\n", MemoryType);
75 
76  /* Allocate some memory for the heap */
77  MaximumSize = ALIGN_UP_BY(MaximumSize, MM_PAGE_SIZE);
78  Heap = MmAllocateMemoryWithType(MaximumSize, MemoryType);
79  if (!Heap)
80  {
81  ERR("HEAP: Failed to allocate heap of size 0x%lx, Type\n",
82  MaximumSize, MemoryType);
83  return NULL;
84  }
85 
86  /* Initialize the heap header */
87  Heap->MaximumSize = MaximumSize;
88  Heap->CurrentAllocBytes = 0;
89  Heap->MaxAllocBytes = 0;
90  Heap->NumAllocs = 0;
91  Heap->NumFrees = 0;
92  Heap->LargestAllocation = 0;
93 
94  /* Calculate what's left to process */
95  Remaining = (MaximumSize - sizeof(HEAP)) / sizeof(HEAP_BLOCK);
96  TRACE("Remaining = %ld\n", Remaining);
97 
98  /* Substract 2 for the terminating entry (header + free entry) */
99  Remaining -= 2;
100 
101  Block = &Heap->Blocks;
102  PreviousSize = 0;
103 
104  /* Create free blocks */
105  while (Remaining > 1)
106  {
107  /* Initialize this free block */
108  Block->Size = (USHORT)min(MAXUSHORT, Remaining - 1);
109  Block->PreviousSize = PreviousSize;
110  Block->Tag = 0;
111  Block->Data[0].Flink = (Block - &Heap->Blocks) + Block->Size + 1;
112  Block->Data[0].Blink = (Block - &Heap->Blocks) - 1 - PreviousSize;
113 
114  /* Substract current block size from remainder */
115  Remaining -= (Block->Size + 1);
116 
117  /* Go to next block */
118  PreviousSize = Block->Size;
119  Block = Block + Block->Size + 1;
120 
121  TRACE("Remaining = %ld\n", Remaining);
122  }
123 
124  /* Now finish with a terminating block */
125  Heap->TerminatingBlock = Block - &Heap->Blocks;
126  Block->Size = 0;
127  Block->PreviousSize = PreviousSize;
128  Block->Tag = 'dnE#';
129  Block->Data[0].Flink = 0;
130  Block->Data[0].Blink = (Block - &Heap->Blocks) - 1 - PreviousSize;
131  Heap->Blocks.Data[0].Blink = Heap->TerminatingBlock;
132 
133  return Heap;
134 }
SIZE_T MaxAllocBytes
Definition: heap.c:55
HEAP_BLOCK Blocks
Definition: heap.c:62
ULONG_PTR Flink
Definition: heap.c:39
USHORT PreviousSize
Definition: heap.c:46
ULONG Tag
Definition: heap.c:47
USHORT Size
Definition: heap.c:45
struct _HEAP_BLOCK HEAP_BLOCK
ULONG_PTR Blink
Definition: heap.c:40
smooth NULL
Definition: ftsmooth.c:416
ULONG NumAllocs
Definition: heap.c:56
#define TRACE(s)
Definition: solgame.cpp:4
PVOID MmAllocateMemoryWithType(SIZE_T MemorySize, TYPE_OF_MEMORY MemoryType)
Definition: mm.c:31
#define ERR(fmt,...)
Definition: debug.h:109
ULONG_PTR SIZE_T
Definition: typedefs.h:78
BLOCK_DATA Data[]
Definition: heap.c:48
unsigned short USHORT
Definition: pedump.c:61
ULONG NumFrees
Definition: heap.c:57
struct _HEAP HEAP
#define min(a, b)
Definition: monoChain.cc:55
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:360
#define MAXUSHORT
Definition: typedefs.h:81
SIZE_T CurrentAllocBytes
Definition: heap.c:54
ULONG_PTR TerminatingBlock
Definition: heap.c:61
#define ALIGN_UP_BY(size, align)
SIZE_T LargestAllocation
Definition: heap.c:58
SIZE_T MaximumSize
Definition: heap.c:53
Definition: heap.c:51

Referenced by MmInitializeHeap().

◆ FrLdrHeapDestroy()

VOID FrLdrHeapDestroy ( PVOID  HeapHandle)

Definition at line 137 of file heap.c.

139 {
140  PHEAP Heap = HeapHandle;
141 
142  /* Mark all pages as firmware temporary, so they are free for the kernel */
144  (ULONG_PTR)Heap / MM_PAGE_SIZE,
145  (PFN_COUNT)(Heap->MaximumSize / MM_PAGE_SIZE),
147 
148 #if DBG
149  /* Make sure everything is dead */
150  RtlFillMemory(Heap, Heap->MaximumSize, 0xCCCCCCCC);
151 #endif
152 }
ULONG PFN_COUNT
Definition: mmtypes.h:102
uint32_t ULONG_PTR
Definition: typedefs.h:63
PVOID PageLookupTableAddress
Definition: meminit.c:26
VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, PFN_NUMBER StartPage, PFN_NUMBER PageCount, TYPE_OF_MEMORY PageAllocated)
Definition: meminit.c:504
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
SIZE_T MaximumSize
Definition: heap.c:53
Definition: heap.c:51

Referenced by FrLdrHeapCleanupAll().

◆ FrLdrHeapFreeEx()

VOID FrLdrHeapFreeEx ( PVOID  HeapHandle,
PVOID  Pointer,
ULONG  Tag 
)

Definition at line 438 of file heap.c.

442 {
443  PHEAP Heap = HeapHandle;
444  PHEAP_BLOCK Block, PrevBlock, NextBlock;
445 #if DBG && !defined(_M_ARM)
446  ULONGLONG Time = __rdtsc();
447 #endif
448  TRACE("HeapFree(%p, %p)\n", HeapHandle, Pointer);
449  ASSERT(Tag != 'dnE#');
450 
451 #ifdef FREELDR_HEAP_VERIFIER
452  /* Verify the heap */
453  FrLdrHeapVerify(HeapHandle);
454 #endif
455 
456  /* Check if the block is really inside this heap */
457  if ((Pointer < (PVOID)(Heap + 1)) ||
458  (Pointer > (PVOID)((PUCHAR)Heap + Heap->MaximumSize)))
459  {
460  ERR("HEAP: trying to free %p outside of heap %p\n", Pointer, Heap);
461  ASSERT(FALSE);
462  }
463 
464  Block = ((PHEAP_BLOCK)Pointer) - 1;
465 #ifdef FREELDR_HEAP_VERIFIER
466  Block = (PHEAP_BLOCK)((PUCHAR)Block - REDZONE_LOW_OFFSET);
467 
468  /* Verify size and redzones */
469  ASSERT(*REDZONE_SIZE(Block) <= Block->Size * sizeof(HEAP_BLOCK));
470  ASSERT(*REDZONE_LOW(Block) == REDZONE_MARK);
471  ASSERT(*REDZONE_HI(Block) == REDZONE_MARK);
472 #endif
473 
474  /* Check if the tag matches */
475  if ((Tag && (Block->Tag != Tag)) || (Block->Tag == 0))
476  {
477  ERR("HEAP: Bad tag! Pointer=%p: block tag '%.4s', requested '%.4s', size=0x%lx\n",
478  Pointer, &Block->Tag, &Tag, Block->Size);
479  ASSERT(FALSE);
480  }
481 
482  /* Mark as free */
483  Block->Tag = 0;
484 
485 #if DBG
486  /* Erase contents */
487  RtlFillMemory(Block->Data, Block->Size * sizeof(HEAP_BLOCK), 0xCCCCCCCC);
488 #endif
489 
490  /* Update heap usage */
491  Heap->NumFrees++;
492  Heap->CurrentAllocBytes -= Block->Size * sizeof(HEAP_BLOCK);
493 
494  /* Get pointers to the next and previous block */
495  PrevBlock = Block - Block->PreviousSize - 1;
496  NextBlock = Block + Block->Size + 1;
497 
498  /* Check if next block is free */
499  if ((NextBlock->Tag == 0) &&
500  ((Block->Size + NextBlock->Size + 1) <= MAXUSHORT))
501  {
502  /* Merge next block into current */
503  Block->Size += NextBlock->Size + 1;
504  FrLdrHeapRemoveFreeList(Heap, NextBlock);
505 
506  NextBlock = Block + Block->Size + 1;
507  }
508 
509  /* Check if there is a block before and it's free */
510  if ((Block->PreviousSize != 0) && (PrevBlock->Tag == 0) &&
511  ((PrevBlock->Size + Block->Size + 1) <= MAXUSHORT))
512  {
513  /* Merge current block into previous */
514  PrevBlock->Size += Block->Size + 1;
515  Block = PrevBlock;
516  }
517  else
518  {
519  /* Insert the entry into the free list */
520  FrLdrHeapInsertFreeList(Heap, Block);
521  }
522 
523  /* Update the next block's back link */
524  NextBlock->PreviousSize = Block->Size;
525 #if DBG && !defined(_M_ARM)
526  Heap->FreeTime += (__rdtsc() - Time);
527 #endif
528 }
#define REDZONE_MARK
Definition: heap.c:27
unsigned char * PUCHAR
Definition: retypes.h:3
VOID FrLdrHeapVerify(PVOID HeapHandle)
Definition: heap.c:156
USHORT PreviousSize
Definition: heap.c:46
ULONG Tag
Definition: heap.c:47
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
USHORT Size
Definition: heap.c:45
#define REDZONE_SIZE(Block)
Definition: heap.c:30
struct _HEAP_BLOCK HEAP_BLOCK
struct _HEAP_BLOCK * PHEAP_BLOCK
#define TRACE(s)
Definition: solgame.cpp:4
uint64_t ULONGLONG
Definition: typedefs.h:65
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
ULONGLONG FreeTime
Definition: heap.c:60
#define REDZONE_LOW_OFFSET
Definition: heap.c:29
static VOID FrLdrHeapInsertFreeList(PHEAP Heap, PHEAP_BLOCK FreeBlock)
Definition: heap.c:298
#define ERR(fmt,...)
Definition: debug.h:109
BLOCK_DATA Data[]
Definition: heap.c:48
ULONG NumFrees
Definition: heap.c:57
#define MAXUSHORT
Definition: typedefs.h:81
SIZE_T CurrentAllocBytes
Definition: heap.c:54
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
#define REDZONE_LOW(Block)
Definition: heap.c:31
#define REDZONE_HI(Block)
Definition: heap.c:32
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
SIZE_T MaximumSize
Definition: heap.c:53
static PLARGE_INTEGER Time
Definition: time.c:105
Definition: heap.c:51
static VOID FrLdrHeapRemoveFreeList(PHEAP Heap, PHEAP_BLOCK Block)
Definition: heap.c:280

Referenced by ExFreePool(), ExFreePoolWithTag(), FrLdrHeapFree(), FrLdrTempFree(), RtlFreeHeap(), and RtlpFreeMemory().

◆ FrLdrHeapInsertFreeList()

static VOID FrLdrHeapInsertFreeList ( PHEAP  Heap,
PHEAP_BLOCK  FreeBlock 
)
static

Definition at line 298 of file heap.c.

301 {
302  PHEAP_BLOCK ListHead, NextBlock;
303  ASSERT(FreeBlock->Tag == 0);
304 
305  /* Terminating block serves as free list head */
306  ListHead = &Heap->Blocks + Heap->TerminatingBlock;
307 
308  for (NextBlock = &Heap->Blocks + ListHead->Data[0].Flink;
309  NextBlock < FreeBlock;
310  NextBlock = &Heap->Blocks + NextBlock->Data[0].Flink);
311 
312  FreeBlock->Data[0].Flink = NextBlock - &Heap->Blocks;
313  FreeBlock->Data[0].Blink = NextBlock->Data[0].Blink;
314  NextBlock->Data[0].Blink = FreeBlock - &Heap->Blocks;
315  NextBlock = &Heap->Blocks + FreeBlock->Data[0].Blink;
316  NextBlock->Data[0].Flink = FreeBlock - &Heap->Blocks;
317 }
HEAP_BLOCK Blocks
Definition: heap.c:62
ULONG_PTR Flink
Definition: heap.c:39
ULONG Tag
Definition: heap.c:47
ULONG_PTR Blink
Definition: heap.c:40
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BLOCK_DATA Data[]
Definition: heap.c:48
ULONG_PTR TerminatingBlock
Definition: heap.c:61

Referenced by FrLdrHeapAllocateEx(), and FrLdrHeapFreeEx().

◆ FrLdrHeapRelease()

VOID FrLdrHeapRelease ( PVOID  HeapHandle)

Definition at line 181 of file heap.c.

183 {
184  PHEAP Heap = HeapHandle;
185  PHEAP_BLOCK Block;
186  PUCHAR StartAddress, EndAddress;
187  PFN_COUNT FreePages, AllFreePages = 0;
188 
189  TRACE("HeapRelease(%p)\n", HeapHandle);
190 
191  /* Loop all heap chunks */
192  for (Block = &Heap->Blocks;
193  Block->Size != 0;
194  Block = Block + 1 + Block->Size)
195  {
196  /* Continue, if its not free */
197  if (Block->Tag != 0)
198  {
199 #ifdef FREELDR_HEAP_VERIFIER
200  /* Verify size and redzones */
201  ASSERT(*REDZONE_SIZE(Block) <= Block->Size * sizeof(HEAP_BLOCK));
202  ASSERT(*REDZONE_LOW(Block) == REDZONE_MARK);
203  ASSERT(*REDZONE_HI(Block) == REDZONE_MARK);
204 #endif
205  continue;
206  }
207 
208  /* Calculate page aligned start address of the free region */
209  StartAddress = ALIGN_UP_POINTER_BY(Block->Data, PAGE_SIZE);
210 
211  /* Walk over adjacent free blocks */
212  while (Block->Tag == 0) Block = Block + Block->Size + 1;
213 
214  /* Check if this was the last block */
215  if (Block->Size == 0)
216  {
217  /* Align the end address up to cover the end of the heap */
218  EndAddress = ALIGN_UP_POINTER_BY(Block->Data, PAGE_SIZE);
219  }
220  else
221  {
222  /* Align the end address down to not cover any allocations */
223  EndAddress = ALIGN_DOWN_POINTER_BY(Block->Data, PAGE_SIZE);
224  }
225 
226  /* Check if we have free pages */
227  if (EndAddress > StartAddress)
228  {
229  /* Calculate the size of the free region in pages */
230  FreePages = (PFN_COUNT)((EndAddress - StartAddress) / MM_PAGE_SIZE);
231  AllFreePages += FreePages;
232 
233  /* Now mark the pages free */
235  (ULONG_PTR)StartAddress / MM_PAGE_SIZE,
236  FreePages,
237  LoaderFree);
238  }
239 
240  /* bail out, if it was the last block */
241  if (Block->Size == 0) break;
242  }
243 
244  TRACE("HeapRelease() done, freed %lu of %lu pages\n", AllFreePages, Heap->MaximumSize / MM_PAGE_SIZE);
245 }
HEAP_BLOCK Blocks
Definition: heap.c:62
ULONG PFN_COUNT
Definition: mmtypes.h:102
#define REDZONE_MARK
Definition: heap.c:27
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG Tag
Definition: heap.c:47
USHORT Size
Definition: heap.c:45
#define REDZONE_SIZE(Block)
Definition: heap.c:30
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define TRACE(s)
Definition: solgame.cpp:4
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ALIGN_UP_POINTER_BY(ptr, align)
Definition: umtypes.h:85
#define PAGE_SIZE
Definition: env_spec_w32.h:49
PVOID PageLookupTableAddress
Definition: meminit.c:26
BLOCK_DATA Data[]
Definition: heap.c:48
#define REDZONE_LOW(Block)
Definition: heap.c:31
#define REDZONE_HI(Block)
Definition: heap.c:32
VOID MmMarkPagesInLookupTable(PVOID PageLookupTable, PFN_NUMBER StartPage, PFN_NUMBER PageCount, TYPE_OF_MEMORY PageAllocated)
Definition: meminit.c:504
#define ALIGN_DOWN_POINTER_BY(ptr, align)
Definition: umtypes.h:82
SIZE_T MaximumSize
Definition: heap.c:53
Definition: heap.c:51

Referenced by FrLdrHeapCleanupAll().

◆ FrLdrHeapRemoveFreeList()

static VOID FrLdrHeapRemoveFreeList ( PHEAP  Heap,
PHEAP_BLOCK  Block 
)
static

Definition at line 280 of file heap.c.

283 {
284  PHEAP_BLOCK Previous, Next;
285 
286  Next = &Heap->Blocks + Block->Data[0].Flink;
287  Previous = &Heap->Blocks + Block->Data[0].Blink;
288  ASSERT((Next->Tag == 0) || (Next->Tag == 'dnE#'));
289  ASSERT(Next->Data[0].Blink == Block - &Heap->Blocks);
290  ASSERT((Previous->Tag == 0) || (Previous->Tag == 'dnE#'));
291  ASSERT(Previous->Data[0].Flink == Block - &Heap->Blocks);
292 
293  Next->Data[0].Blink = Previous - &Heap->Blocks;
294  Previous->Data[0].Flink = Next - &Heap->Blocks;
295 }
HEAP_BLOCK Blocks
Definition: heap.c:62
ULONG_PTR Flink
Definition: heap.c:39
ULONG Tag
Definition: heap.c:47
ULONG_PTR Blink
Definition: heap.c:40
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BLOCK_DATA Data[]
Definition: heap.c:48

Referenced by FrLdrHeapAllocateEx(), and FrLdrHeapFreeEx().

◆ FrLdrHeapVerify()

VOID FrLdrHeapVerify ( PVOID  HeapHandle)

Definition at line 156 of file heap.c.

158 {
159  PHEAP Heap = HeapHandle;
160  PHEAP_BLOCK Block;
161 
162  /* Loop all heap chunks */
163  for (Block = &Heap->Blocks;
164  Block->Size != 0;
165  Block = Block + 1 + Block->Size)
166  {
167  /* Continue, if its not free */
168  if (Block->Tag != 0)
169  {
170  /* Verify size and redzones */
171  ASSERT(*REDZONE_SIZE(Block) <= Block->Size * sizeof(HEAP_BLOCK));
172  ASSERT(*REDZONE_LOW(Block) == REDZONE_MARK);
173  ASSERT(*REDZONE_HI(Block) == REDZONE_MARK);
174  continue;
175  }
176  }
177 }
HEAP_BLOCK Blocks
Definition: heap.c:62
#define REDZONE_MARK
Definition: heap.c:27
ULONG Tag
Definition: heap.c:47
USHORT Size
Definition: heap.c:45
#define REDZONE_SIZE(Block)
Definition: heap.c:30
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define REDZONE_LOW(Block)
Definition: heap.c:31
#define REDZONE_HI(Block)
Definition: heap.c:32
Definition: heap.c:51

Referenced by FrLdrHeapAllocateEx(), and FrLdrHeapFreeEx().

◆ MmInitializeHeap()

VOID MmInitializeHeap ( PVOID  PageLookupTable)

Definition at line 534 of file heap.c.

535 {
536  TRACE("MmInitializeHeap()\n");
537 
538  /* Create the default heap */
541 
542  /* Create a temporary heap */
545 
546  TRACE("MmInitializeHeap() done, default heap %p, temp heap %p\n",
548 }
#define TEMP_HEAP_SIZE
Definition: mm.h:123
#define DEFAULT_HEAP_SIZE
Definition: mm.h:122
#define TRACE(s)
Definition: solgame.cpp:4
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PVOID FrLdrTempHeap
Definition: heap.c:35
PVOID FrLdrHeapCreate(SIZE_T MaximumSize, TYPE_OF_MEMORY MemoryType)
Definition: heap.c:66
PVOID FrLdrDefaultHeap
Definition: heap.c:34

Referenced by MmInitializeMemoryManager().

◆ RtlAllocateHeap()

PVOID NTAPI RtlAllocateHeap ( IN PVOID  HeapHandle,
IN ULONG  Flags,
IN SIZE_T  Size 
)
Examples
/srv/doxygen/reactos/win32ss/gdi/gdi32/objects/utils.c.

Definition at line 588 of file heap.c.

592 {
593  PVOID ptr;
594 
596  if (ptr && (Flags & HEAP_ZERO_MEMORY))
597  {
599  }
600 
601  return ptr;
602 }
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
static PVOID ptr
Definition: dispmode.c:27
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
PVOID FrLdrHeapAllocateEx(PVOID HeapHandle, SIZE_T ByteSize, ULONG Tag)
Definition: heap.c:320
PVOID FrLdrDefaultHeap
Definition: heap.c:34

Referenced by __RegisterConsoleVDM(), add_assembly(), add_chunk(), add_compat_context(), add_dependent_assembly_id(), add_dll_redirect(), add_entity(), add_entry(), add_item(), add_root(), AddBootStoreEntry(), AddBSMRequest(), AddConsoleCtrlHandler(), AddDialogListEntry(), AddDiskToList(), AddNotificationDll(), AddNTOSInstallation(), AddPartitionToDisk(), AddProvider(), AfdBind(), AfdConnect(), AfdCreateSocket(), AfdSendTo(), AppendGenericListEntry(), ApphelpCheckRunAppEx(), AttachToConsoleInternal(), AVrfInitializeVerifier(), BaseCheckVDM(), BaseInitializeStaticServerData(), BasepAllocateActivationContextActivationBlock(), BasepComputeProcessPath(), BasepGetVolumeNameFromReparsePoint(), BasepIsProcessAllowed(), BasepMoveFileDelayed(), BaseQuerySystemFirmware(), BaseSrvCopyCommand(), BaseSrvCreateConsoleRecord(), BaseSrvInitializeIniFileMappings(), build_assembly_dir(), build_assembly_id(), build_clr_surrogate_section(), build_comserver_section(), build_dllredirect_section(), build_ifaceps_section(), build_progid_section(), build_tlib_section(), build_wndclass_section(), BuildSubSysCommandLine(), CallNt(), calloc(), CheckForCurrentHostname(), CheckTokenMembership(), clear_first_megabyte(), cmdGroup(), cmdLocalGroup(), com_class_add_progid(), CommandDumpSector(), CommandPartInfo(), ConDrvWriteConsole(), ConDrvWriteConsoleOutputString(), ConvertBitmapInfo(), ConvertThreadToFiberEx(), create_lost_and_found(), CreateBaseAcls(), CreateDirectoryExW(), CreateFiberEx(), CreateFileSystemList(), CreateFileW(), CreateGenericList(), CreateHardLinkW(), CreateHardwareTimer(), CreateInsertBlankRegion(), CreatePartitionList(), CreateProcessInternalW(), CreateProgressBarEx(), CreateUmaDescriptor(), CSR_API(), CsrAllocateCaptureBuffer(), CsrAllocateNtSession(), CsrAllocateProcess(), CsrAllocateThread(), CsrApiPortInitialize(), CsrCaptureArguments(), CsrCreateLocalSystemSD(), CsrGetProcessLuid(), CsrInitCsrRootProcess(), CsrInitializeWait(), CsrLoadServerDll(), CsrpConnectToServer(), CsrSbApiPortInitialize(), CsrSetProcessSecurity(), CsrSrvCreateSharedSection(), DefaultProcessEntry(), DesktopHeapAlloc(), DesktopHeapReAlloc(), DisplayGroup(), DisplayLocalGroup(), DisplayMessage(), DnsAcquireContextHandle_W(), DnsApiAlloc(), DnsCToW(), DnsQuery_CodePage(), DnsQuery_W(), DnsUTF8ToW(), DnsWToC(), DnsWToUTF8(), do_reg_operation(), DosCreateDeviceNode(), DosReadFile(), DosStart(), DosStartProcess32(), DosWriteFile(), EmsDrvInitialize(), EmulatorCopyMemory(), EngCreateSemaphore(), EnumDisplaySettingsExA(), EnumDisplaySettingsExW(), EnumerateBiosDiskEntries(), EnumHKCRKey(), EnumHKCRValue(), EnumPropsA(), EnumPropsExA(), EnumPropsExW(), EnumPropsW(), ExpandEnvironmentStringsA(), ext2_add_entry(), ext2_alloc_block(), ext2_allocate_block_bitmap(), ext2_allocate_group_desc(), ext2_allocate_inode_bitmap(), ext2_build_bdl(), ext2_expand_block(), ext2_get_block(), ext2_new_dir_block(), ext2_write_block_bitmap(), ext2_write_inode_bitmap(), Ext2ReadDisk(), Ext2WriteDisk(), Fat12WriteBootSector(), Fat12WriteFAT(), Fat12WriteRootDirectory(), Fat16WriteBootSector(), Fat16WriteFAT(), Fat16WriteRootDirectory(), Fat32WriteBootSector(), Fat32WriteFAT(), Fat32WriteFsInfo(), Fat32WriteRootDirectory(), FatWipeSectors(), Fatx16WriteFAT(), Fatx32WriteFAT(), FatxWriteBootSector(), FatxWriteRootDirectory(), FilterConnectCommunicationPort(), FilterLoadUnload(), find_actctx_dll(), FindFirstFileExW(), FindFirstStreamW(), FindFirstVolumeA(), FindFirstVolumeW(), FindNextVolumeA(), FlsAlloc(), FlsSetValue(), FormatEx2(), FreeLdrEnumerateBootEntries(), get_buffer(), get_manifest_in_associated_manifest(), get_module_filename(), GetAccountDomainSid(), GetBuiltinDomainSid(), GetClipboardFormatNameA(), GetComputerIdentifier(), GetComputerNameExA(), GetComputerNameFromRegistry(), GetDisplayIdentifier(), GetDosDevicesProtection(), GetEnvironmentStringsA(), GetEnvironmentStringsW(), GetEnvironmentVariableA(), GetFullPathNameA(), GetKeyName(), GetLongPathNameA(), GetLongPathNameW(), GetModuleFileNameA(), GetNamedPipeHandleStateA(), GetNtAuthorityDomainSid(), GetShortPathNameA(), GetShortPathNameW(), GetSiteSidFromToken(), GetStartupInfoA(), GetSystemTimes(), GetTempFileNameA(), GetVolumeInformationA(), GetVolumeInformationW(), GetVolumeNameForRoot(), GetVolumeNameForVolumeMountPointA(), GetVolumePathNameA(), GetVolumePathNamesForVolumeNameA(), GetVolumePathNamesForVolumeNameW(), GetVolumePathNameW(), GlobalAlloc(), GlobalReAlloc(), HEAP_alloc(), INF_GetDataField(), IniCacheAddKey(), IniCacheAddSection(), IniCacheAppendSection(), IniCacheCreate(), IniCacheFindFirstValue(), IniCacheInsertKey(), IniCacheLoadByHandle(), IniCacheLoadFromMemory(), IniCacheSaveByHandle(), init_fs_tree(), InitFunctionPtrs(), InitializeFmIfsOnce(), InitTTFontCache(), InstallBtrfsBootCodeToDisk(), InstallDevice(), InstallDriver(), InstallFat12BootCodeToFloppy(), InstallFat16BootCode(), InstallFat32BootCode(), InstallMbrBootCodeToDiskHelper(), IntEnumFontFamilies(), InternalExplicitAccessAToW(), InternalGetAtomName(), InternalTrusteeAToW(), IntWriteConsoleOutput(), is_mounted_multi_device(), is_ssd(), IsAcpiComputer(), IsGlobalDeviceMap(), IsGlobalSymbolicLink(), IsThereAValidBootSector(), LdrGetDllHandleEx(), LdrpAllocateDataTableEntry(), LdrpAllocateTls(), LdrpAllocateUnicodeString(), LdrpCheckForKnownDll(), LdrpGetProcedureAddress(), LdrpInitializeDotLocalSupport(), LdrpInitializeProcess(), LdrpInitializeProcessCompat(), LdrpInitializeTls(), LdrpResolveDllName(), LdrpRunInitializeRoutines(), LdrpSearchPath(), LdrQueryImageFileKeyOption(), LoadAllocStringW(), LoadInstallableVDD(), LoadLibraryA(), LoadModule(), LocalAlloc(), LocalReAlloc(), LogfAllocAndBuildNewRecord(), LogfpAlloc(), LogonUserExW(), lookup_assembly(), lookup_manifest_file(), lookup_winsxs(), LsaApLogonUserEx2(), LsapAddAuthPackage(), LsapAddDefaultGroups(), LsapAddLocalGroups(), LsapAddPrivilegeToTokenPrivileges(), LsapAddSamGroups(), LsapAllocateHeap(), LsapAllocateHeapZero(), LsapAppendSidToGroups(), LsapCallAuthenticationPackage(), LsapCheckLogonProcess(), LsapCopyLocalGroups(), LsapCreateAccountSd(), LsapCreateDatabaseObjects(), LsapCreateDbObject(), LsapCreateLogonSession(), LsapCreatePolicySd(), LsapCreateSecretSd(), LsapCreateSid(), LsapEnumLogonSessions(), LsapGetDomainInfo(), LsapGetLogonSessionData(), LsapIsTrustedClient(), LsapLogonUser(), LsapOpenDbObject(), LsapRegEnumerateSubKey(), LsapRegEnumerateValue(), LsapRegisterNotification(), LsapRegQueryValue(), LsapSetLogonSessionData(), LsarAddAccountRights(), LsarEnumerateAccounts(), LsarEnumerateAccountsWithUserRight(), LsarRemoveAccountRights(), LsarSetAccountDomain(), LsarSetAuditEvents(), LsarSetPrimaryDomain(), LsarSetSecurityObject(), malloc(), MBToWCSEx(), MemInstallFastMemoryHook(), MessageBoxTextToClipboard(), midl_user_allocate(), MoveFileWithProgressW(), MsgiAnsiToUnicodeMessage(), MsgiUnicodeToAnsiMessage(), MSZipAlloc(), MyLogonUser(), NetGroupSetUsers(), NtLdrEnumerateBootEntries(), NtProcessStartup(), OpenIniBootLoaderStore(), parse_manifest(), PeekNamedPipe(), PNP_RegisterNotification(), PnpEventThread(), PrintMessageAnsi(), ProcessLangEntry(), QueryDosDeviceA(), QueryDosDeviceW(), ReadDisk(), RegDeleteTreeW(), RegEnumKeyExA(), RegEnumKeyExW(), RegEnumValueA(), RegOpenUserClassesRoot(), RegpCopyTree(), RegQueryInfoKeyW(), RegQueryValueExA(), RemoveDirectoryW(), ReplaceFileW(), RosSymAllocMemUM(), RtlAcquirePrivilege(), RtlActivateActivationContextEx(), RtlAddAttributeActionToRXact(), RtlAllocateActivationContextStack(), RtlCopySecurityDescriptor(), RtlCreateActivationContext(), RtlCreateProcessParameters(), RtlCreateTimer(), RtlCreateTimerQueue(), RtlDebugAllocateHeap(), RtlDefaultNpAcl(), RtlDosSearchPath_U(), RtlGetFullPathName_Ustr(), RtlInitializeRXact(), RtlpAddVectoredHandler(), RtlpAllocateDebugInfo(), RtlpAllocateMemory(), RtlpAllocAtomTable(), RtlpAllocAtomTableEntry(), RtlpCheckDeviceName(), RtlpDosPathNameToRelativeNtPathName_Ustr(), RtlpNtEnumerateSubKey(), RtlpNtQueryValueKey(), RtlpSetSecurityObject(), RtlpWin32NTNameToNtPathName_U(), RtlQueueWorkItem(), RtlReAllocateHeap(), RtlRegisterWait(), RtlSetCurrentDirectory_U(), RtlStartRXact(), SampCreateAccountDomainSD(), SampCreateAccountSid(), SampCreateAliasSD(), SampCreateBuiltinDomainSD(), SampCreateDbObject(), SampCreateGroupSD(), SampCreateServerSD(), SampCreateUserSD(), SampDeleteAccountDbObject(), SampInitializeSAM(), SampOpenDbObject(), SampRegEnumerateSubKey(), SampRegEnumerateValue(), SampRegQueryValue(), SamrSetSecurityObject(), SaveBootSector(), SaveProcessHandle(), SaveThreadHandle(), ScAllocateAndInitializeSid(), ScanForUnpartitionedDiskSpace(), ScDomainIdToSid(), ScmCreateAcls(), ScmCreateDefaultSD(), ScmCreateDefaultServiceSD(), ScmCreatePipeSD(), ScmCreateSids(), ScmReadSecurityDescriptor(), SdbPackAppCompatData(), SdbpAlloc(), SearchPathA(), SetAdministratorPassword(), SetDIBitsToDevice(), SetFileShortNameW(), SetupCreateDirectory(), SetupMoveFile(), SetupOpenFileQueue(), SetupQueueCopyWithCab(), SetupQueueDeleteW(), SetupQueueRenameW(), SetVolumeLabelW(), SmLookupSubsystem(), SmpAcquirePrivilege(), SmpAllocateSessionId(), SmpConfigureEnvironment(), SmpCreateEmergencyPagingFile(), SmpCreatePagingFileDescriptor(), SmpCreateSecurityDescriptors(), SmpCreateVolumeDescriptors(), SmpHandleConnectionRequest(), SmpInitializeKnownDllPath(), SmpLoadSubSystem(), SmpParseCommandLine(), SmpParseToken(), SmpProcessFileRenames(), SmpSaveRegistryValue(), SmpSbCreateSession(), SoftModalMessageBox(), split(), START_TEST(), StartServiceCtrlDispatcherA(), StartServiceCtrlDispatcherW(), strdupW(), StretchDIBits(), SystemConfigurationDataQueryRoutine(), Test_KeyFullInformation(), Test_KeyNameInformation(), test_specialhandling(), TlsAlloc(), TlsSetValue(), User32CreateWindowEx(), UserHeapAlloc(), UserHeapReAlloc(), UserInitializeDesktop(), UserpCaptureStringParameters(), UserpFormatMessages(), UserpGetClientFileName(), UserpShowInformationBalloon(), VDDInstallMemoryHook(), VDDInstallUserHook(), VgaInitializePalette(), WaitForMultipleObjectsEx(), WaitNamedPipeW(), WCSToMBEx(), write_roots(), write_superblocks(), WriteConsoleOutputCharacterA(), WriteConsoleOutputCharacterW(), WriteDisk(), xmlstrdupW(), xstrsave(), xstrsaveA(), zap_sector(), and zero_blocks().

◆ RtlFreeHeap()

BOOLEAN NTAPI RtlFreeHeap ( IN PVOID  HeapHandle,
IN ULONG  Flags,
IN PVOID  HeapBase 
)

Definition at line 606 of file heap.c.

610 {
612  return TRUE;
613 }
#define TRUE
Definition: types.h:120
VOID FrLdrHeapFreeEx(PVOID HeapHandle, PVOID Pointer, ULONG Tag)
Definition: heap.c:438
_In_opt_ PVOID HeapBase
Definition: rtlfuncs.h:2169
PVOID FrLdrDefaultHeap
Definition: heap.c:34

Referenced by __RegisterConsoleVDM(), _tmain(), AccpOpenNamedObject(), actctx_release(), add_entry(), AddBootStoreEntry(), AddConsoleCtrlHandler(), AddDiskToList(), AddNotificationDll(), AddProvider(), AfdBind(), AfdConnect(), AfdCreateSocket(), AfdSendTo(), AttachToConsoleInternal(), AVrfInitializeVerifier(), BackupEventLogW(), BaseCheckRunApp(), BaseCheckVDM(), BasepComputeProcessPath(), BasepFreeActivationContextActivationBlock(), BasepFreeAppCompatData(), BasepGetVolumeNameFromReparsePoint(), BasepIsProcessAllowed(), BasepMoveFileDelayed(), BasePushProcessParameters(), BaseQuerySystemFirmware(), BaseRundownFls(), BaseSrvBSMThread(), BaseSrvCleanupVDMResources(), BaseSrvDestroyConsoleRecord(), BaseSrvFreeVDMInfo(), CallNt(), ChangeDisplaySettingsExA(), CheckForCurrentHostname(), CheckTokenMembership(), CleanupNotifications(), clear_first_megabyte(), ClearEventLogW(), ClearTTFontCache(), CloseAllProcessHandles(), CloseIniBootLoaderStore(), cmdGroup(), cmdLocalGroup(), CommandDumpSector(), CommandPartInfo(), ConDrvWriteConsole(), ConDrvWriteConsoleOutputString(), ConvertFiberToThread(), create_lost_and_found(), CreateBaseAcls(), CreateDIBitmap(), CreateDIBPatternBrush(), CreateDIBPatternBrushPt(), CreateDIBSection(), CreateDirectoryExW(), CreateDirectoryW(), CreateFiberEx(), CreateFileW(), CreateHardLinkW(), CreateMailslotW(), CreateNamedPipeW(), CreatePartitionList(), CreateProcessInternalA(), CreateProcessInternalW(), CSR_API(), CsrCaptureArguments(), CsrCreateLocalSystemSD(), CsrCreateWait(), CsrDeallocateProcess(), CsrDeallocateThread(), CsrDereferenceNtSession(), CsrDereferenceWait(), CsrFreeCaptureBuffer(), CsrGetProcessLuid(), CsrLoadServerDll(), CsrNotifyWaitBlock(), CsrReleaseCapturedArguments(), CsrSbApiPortInitialize(), CsrSetProcessSecurity(), DeleteFiber(), DeleteFileW(), DeletePartition(), DesktopHeapFree(), DesktopHeapReAlloc(), DestroyFileSystemList(), DestroyGenericList(), DestroyHardwareTimer(), DestroyPartitionList(), DestroyProgressBar(), DeviceInstallThread(), DisplayGroup(), DisplayLocalGroup(), DisplayMessage(), disposeResInfo(), DnsAcquireContextHandle_W(), DnsApiFree(), DnsFree(), DnsIntFreeRecordList(), DnsQuery_CodePage(), DnsQuery_W(), DnsReleaseContextHandle(), do_reg_operation(), DosDeleteDevice(), DosReadFile(), DosStartProcess32(), DosWriteFile(), EmsDrvCleanup(), EmsDrvInitialize(), EngDeleteSemaphore(), EnumDisplaySettingsExA(), EnumDisplaySettingsExW(), EnumerateBiosDiskEntries(), EnumHKCRKey(), EnumHKCRValue(), EnumPropsA(), EnumPropsExA(), EnumPropsExW(), EnumPropsW(), ExpandEnvironmentStringsA(), ext2_alloc_block(), ext2_allocate_block_bitmap(), ext2_allocate_inode_bitmap(), ext2_build_bdl(), ext2_expand_block(), ext2_free_generic_bitmap(), ext2_free_group_desc(), ext2_get_block(), ext2_mkdir(), ext2_read_inode(), ext2_write_block_bitmap(), ext2_write_inode(), ext2_write_inode_bitmap(), Ext2ReadDisk(), Ext2WriteDisk(), ExtCreatePen(), Fat12WriteBootSector(), Fat12WriteFAT(), Fat12WriteRootDirectory(), Fat16WriteBootSector(), Fat16WriteFAT(), Fat16WriteRootDirectory(), Fat32WriteBootSector(), Fat32WriteFAT(), Fat32WriteFsInfo(), Fat32WriteRootDirectory(), FatWipeSectors(), Fatx16WriteFAT(), Fatx32WriteFAT(), FatxWriteBootSector(), FatxWriteRootDirectory(), FilterConnectCommunicationPort(), FilterLoadUnload(), find_actctx_dll(), find_clr_surrogate(), find_cominterface_redirection(), find_comserver_redirection(), find_dll_redirection(), find_progid_redirection(), find_tlib_redirection(), find_window_class(), FindClose(), FindFirstChangeNotificationW(), FindFirstFileExW(), FindFirstStreamW(), FindFirstVolumeA(), FindFirstVolumeW(), FindNextVolumeA(), FindVolumeClose(), FormatEx2(), free(), free_assembly_identity(), free_chunks(), free_depend_manifests(), free_entity_array(), free_roots(), FreeDosDevicesProtection(), FreeEnvironmentStringsA(), FreeEnvironmentStringsW(), FreeLdrEnumerateBootEntries(), freep(), FreeUmaDescriptor(), GetBuiltinDomainSid(), GetClipboardFormatNameA(), GetComputerIdentifier(), GetComputerNameExA(), GetComputerNameFromRegistry(), GetDiskFreeSpaceExW(), GetDiskFreeSpaceW(), GetDisplayIdentifier(), GetDosDevicesProtection(), GetDriveTypeW(), GetEnvironmentStringsA(), GetEnvironmentVariableA(), GetFileSecurityW(), GetFontResourceInfoW(), GetFullPathNameA(), GetKeyName(), GetLongPathNameA(), GetLongPathNameW(), GetModuleFileNameA(), GetModuleHandleForUnicodeString(), GetNamedPipeHandleStateA(), GetShortPathNameA(), GetShortPathNameW(), GetSiteSidFromToken(), GetStartupInfoA(), GetSystemTimes(), GetTempFileNameA(), GetVolumeInformationA(), GetVolumeInformationW(), GetVolumeNameForRoot(), GetVolumeNameForVolumeMountPointA(), GetVolumePathNameA(), GetVolumePathNamesForVolumeNameA(), GetVolumePathNamesForVolumeNameW(), GetVolumePathNameW(), GlobalFree(), GlobalReAlloc(), HEAP_free(), INF_FreeData(), INF_GetDataField(), IniCacheAddKey(), IniCacheAddSection(), IniCacheAppendSection(), IniCacheDestroy(), IniCacheFindClose(), IniCacheFreeKey(), IniCacheFreeSection(), IniCacheInsertKey(), IniCacheLoadByHandle(), IniCacheSaveByHandle(), init_fs_tree(), InitFunctionPtrs(), InitializeFmIfsOnce(), InstallBtrfsBootCodeToDisk(), InstallDevice(), InstallDriver(), InstallFat12BootCodeToFloppy(), InstallFat16BootCode(), InstallFat32BootCode(), InstallMbrBootCodeToDiskHelper(), InstallReactOS(), IntEnumFontFamilies(), InternalExplicitAccessAToW(), InternalFreeConvertedTrustee(), InternalGetAtomName(), InternalTrusteeAToW(), IntWriteConsoleOutput(), is_mounted_multi_device(), is_ssd(), IsAcpiComputer(), IsGlobalDeviceMap(), IsGlobalSymbolicLink(), IsThereAValidBootSector(), LdrGetDllHandleEx(), LdrpCheckForKnownDll(), LdrpCheckForLoadedDll(), LdrpFinalizeAndDeallocateDataTableEntry(), LdrpFreeTls(), LdrpFreeUnicodeString(), LdrpGetProcedureAddress(), LdrpInitializeDotLocalSupport(), LdrpMapDll(), LdrpResolveDllName(), LdrpRunInitializeRoutines(), LdrpSearchPath(), LdrQueryImageFileKeyOption(), LdrShutdownThread(), LoadInstallableVDD(), LoadLibraryA(), LoadLibraryExW(), LoadModule(), LocalReAlloc(), LogfFreeRecord(), LogfpFree(), LogonUserExW(), lookup_assembly(), lookup_manifest_file(), lookup_winsxs(), LsaApLogonUserEx2(), LsaFreeMemory(), LsapAddAuthPackage(), LsapAddDefaultGroups(), LsapAddLocalGroups(), LsapAddPrivilegeToTokenPrivileges(), LsapAddSamGroups(), LsapAppendSidToGroups(), LsapCallAuthenticationPackage(), LsapCloseDbObject(), LsapCopyLocalGroups(), LsapCreateAccountSd(), LsapCreateDatabaseObjects(), LsapCreateLogonSession(), LsapCreatePolicySd(), LsapCreateSecretSd(), LsapCreateSid(), LsapDeleteDbObject(), LsapDeleteLogonSession(), LsapDeregisterLogonProcess(), LsapEnumLogonSessions(), LsapFreeHeap(), LsapGetDomainInfo(), LsapGetLogonSessionData(), LsapIsTrustedClient(), LsapLogonUser(), LsapRegEnumerateSubKey(), LsapRegEnumerateValue(), LsapRegisterNotification(), LsapRegQueryValue(), LsarAddAccountRights(), LsarCreateSecret(), LsarEnumerateAccounts(), LsarEnumerateAccountsWithUserRight(), LsarpCreateAccount(), LsarRemoveAccountRights(), LsarSetAccountDomain(), LsarSetAuditEvents(), LsarSetPrimaryDomain(), LsarSetSecurityObject(), MemCleanup(), MemRemoveFastMemoryHook(), MessageBoxTextToClipboard(), MessageBoxTimeoutIndirectW(), midl_user_free(), MoveFileWithProgressW(), MsgiAnsiToUnicodeCleanup(), MsgiUnicodeToAnsiCleanup(), MsgiUnicodeToAnsiMessage(), MSZipFree(), MyLogonUser(), NetGroupSetUsers(), NetUserEnum(), NetUserGetGroups(), NetUserGetInfo(), NetUserGetLocalGroups(), NetUserModalsGet(), NtLdrEnumerateBootEntries(), OpenAccountDomain(), OpenBackupEventLogW(), OpenBuiltinDomain(), OpenFile(), OpenIniBootLoaderStore(), parse_manifest(), PeekNamedPipe(), PerformMount(), PnpEventThread(), PrintMessageAnsi(), PrivMoveFileIdentityW(), QueryDosDeviceA(), QueryDosDeviceW(), queue_remove_timer(), read_bitmaps(), ReadDisk(), RegDeleteTreeW(), RegEnumKeyExA(), RegEnumKeyExW(), RegEnumValueA(), RegisterInShimCache(), RegLoadKeyW(), RegOpenUserClassesRoot(), RegpCopyTree(), RegQueryInfoKeyW(), RegQueryValueExA(), RegReplaceKeyW(), RegRestoreKeyW(), RegSaveKeyW(), RemoveComSpecInfo(), RemoveDialogListEntry(), RemoveDirectoryW(), RemoveHandles(), ReplaceFileW(), RosSymFreeMemUM(), RtlAbortRXact(), RtlAcquirePrivilege(), RtlAddAttributeActionToRXact(), RtlCreateActivationContext(), RtlCreateTimer(), RtlCreateTimerQueue(), RtlCreateUserSecurityObject(), RtlDeactivateActivationContext(), RtlDebugFreeHeap(), RtlDefaultNpAcl(), RtlDeleteSecurityObject(), RtlDeregisterWaitEx(), RtlDestroyProcessParameters(), RtlDoesFileExists_UstrEx(), RtlDosSearchPath_U(), RtlFreeActivationContextStack(), RtlFreeLargeString(), RtlGetFullPathName_Ustr(), RtlInitializeRXact(), RtlpCallVectoredHandlers(), RtlpCheckDeviceName(), RtlpDosPathNameToRelativeNtPathName_Ustr(), RtlpDphFreeDelayedBlocksFromHeap(), RtlpExecuteIoWorkItem(), RtlpExecuteWorkItem(), RtlpFreeAtomTable(), RtlpFreeAtomTableEntry(), RtlpFreeDebugInfo(), RtlpFreeMemory(), RtlpNtEnumerateSubKey(), RtlpNtQueryValueKey(), RtlpRemoveVectoredHandler(), RtlpSetSecurityObject(), RtlQueryInformationActivationContext(), RtlQueueWorkItem(), RtlReAllocateHeap(), RtlRegisterWait(), RtlReleasePrivilege(), RtlReleaseRelativeName(), RtlSetCurrentDirectory_U(), RunApphelpCacheControlTests(), SampCloseDbObject(), SampCreateAccountDomainSD(), SampCreateAccountSid(), SampCreateAliasSD(), SampCreateBuiltinDomainSD(), SampCreateDbObject(), SampCreateGroupSD(), SampCreateServerSD(), SampCreateUserSD(), SampDeleteAccountDbObject(), SampInitializeSAM(), SampOpenDbObject(), SampRegEnumerateSubKey(), SampRegEnumerateValue(), SampRegQueryValue(), SampSetupCreateAliasAccount(), SampSetupCreateDomain(), SampSetupCreateGroupAccount(), SampSetupCreateServer(), SampSetupCreateUserAccount(), SamrCreateAliasInDomain(), SamrCreateGroupInDomain(), SamrCreateUser2InDomain(), SamrCreateUserInDomain(), SamrSetSecurityObject(), SaveBootSector(), ScDomainIdToSid(), ScmCreateDefaultServiceSD(), ScmFreeAcls(), ScmFreeDefaultSD(), ScmFreePipeSD(), ScmFreeSids(), ScmReadSecurityDescriptor(), SdbPackAppCompatData(), SdbpFree(), SearchPathA(), SearchPathW(), SetDIBitsToDevice(), SetEntriesInAclA(), SetFileAttributesW(), SetFileSecurityW(), SetFileShortNameW(), SetupCloseFileQueue(), SetupCreateDirectory(), SetupDeleteQueueEntry(), SetupMoveFile(), SetupQueueCopyWithCab(), SetupQueueDeleteW(), SetupQueueRenameW(), SetVolumeLabelW(), SmLookupSubsystem(), SmpAcquirePrivilege(), SmpCreatePagingFileDescriptor(), SmpCreateSecurityDescriptors(), SmpCreateVolumeDescriptors(), SmpDeleteSession(), SmpDereferenceSubsystem(), SmpExecuteCommand(), SmpExecuteInitialCommand(), SmpHandleConnectionRequest(), SmpInitializeDosDevices(), SmpInitializeKnownDlls(), SmpInitializeKnownDllsInternal(), SmpLoadDataFromRegistry(), SmpLoadSubSystem(), SmpLoadSubSystemsForMuSession(), SmpParseCommandLine(), SmpProcessFileRenames(), SmpReleasePrivilege(), SmpSaveRegistryValue(), SoftModalMessageBox(), split(), START_TEST(), StartServiceCtrlDispatcherA(), StartServiceCtrlDispatcherW(), StretchDIBits(), Test_ApphelpCheckRunApp(), Test_KeyFullInformation(), Test_KeyNameInformation(), Test_Shimdata(), test_specialhandling(), timer_queue_thread_proc(), UserHeapFree(), UserHeapReAlloc(), UserpCaptureStringParameters(), UserpFreeStringParameters(), UserpGetClientFileName(), UserpShowInformationBalloon(), VDDDeInstallMemoryHook(), VDDDeInstallUserHook(), VDDInstallMemoryHook(), VgaInitializePalette(), Wait_thread_proc(), WaitForMultipleObjectsEx(), WaitNamedPipeW(), write_roots(), write_superblocks(), WriteConsoleOutputCharacterA(), WriteConsoleOutputCharacterW(), WriteDisk(), zap_sector(), and zero_blocks().

Variable Documentation

◆ FrLdrDefaultHeap

◆ FrLdrTempHeap

PVOID FrLdrTempHeap

Definition at line 35 of file heap.c.

Referenced by FrLdrHeapCleanupAll(), FrLdrTempAlloc(), FrLdrTempFree(), and MmInitializeHeap().