ReactOS  0.4.11-dev-745-g76daaf9
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

#define FREELDR_HEAP_VERIFIER

Definition at line 23 of file heap.c.

#define REDZONE_ALLOCATION   24

Definition at line 28 of file heap.c.

Referenced by FrLdrHeapAllocateEx().

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

Definition at line 32 of file heap.c.

Referenced by FrLdrHeapAllocateEx(), FrLdrHeapFreeEx(), FrLdrHeapRelease(), and FrLdrHeapVerify().

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

Definition at line 31 of file heap.c.

Referenced by FrLdrHeapAllocateEx(), FrLdrHeapFreeEx(), FrLdrHeapRelease(), and FrLdrHeapVerify().

#define REDZONE_LOW_OFFSET   16

Definition at line 29 of file heap.c.

Referenced by FrLdrHeapAllocateEx(), and FrLdrHeapFreeEx().

#define REDZONE_MARK   0xCCCCCCCCCCCCCCCCULL

Definition at line 27 of file heap.c.

Referenced by FrLdrHeapAllocateEx(), FrLdrHeapFreeEx(), FrLdrHeapRelease(), and FrLdrHeapVerify().

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

Definition at line 30 of file heap.c.

Referenced by FrLdrHeapAllocateEx(), FrLdrHeapFreeEx(), FrLdrHeapRelease(), and FrLdrHeapVerify().

Typedef Documentation

typedef struct _HEAP HEAP
typedef struct _HEAP * PHEAP

Function Documentation

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

Definition at line 559 of file heap.c.

562 {
564 }
IN SIZE_T NumberOfBytes
Definition: ndis.h:3915
PVOID FrLdrHeapAllocateEx(PVOID HeapHandle, SIZE_T ByteSize, ULONG Tag)
Definition: heap.c:317
PVOID FrLdrDefaultHeap
Definition: heap.c:34
PVOID NTAPI ExAllocatePoolWithTag ( IN POOL_TYPE  PoolType,
IN SIZE_T  NumberOfBytes,
IN ULONG  Tag 
)

Definition at line 549 of file heap.c.

553 {
555 }
IN SIZE_T NumberOfBytes
Definition: ndis.h:3915
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
PVOID FrLdrHeapAllocateEx(PVOID HeapHandle, SIZE_T ByteSize, ULONG Tag)
Definition: heap.c:317
PVOID FrLdrDefaultHeap
Definition: heap.c:34
VOID NTAPI ExFreePool ( IN PVOID  P)

Definition at line 568 of file heap.c.

570 {
572 }
VOID FrLdrHeapFreeEx(PVOID HeapHandle, PVOID Pointer, ULONG Tag)
Definition: heap.c:435
PVOID FrLdrDefaultHeap
Definition: heap.c:34
#define P(row, col)
Definition: m_matrix.c:147
VOID NTAPI ExFreePoolWithTag ( IN PVOID  P,
IN ULONG  Tag 
)

Definition at line 576 of file heap.c.

579 {
581 }
VOID FrLdrHeapFreeEx(PVOID HeapHandle, PVOID Pointer, ULONG Tag)
Definition: heap.c:435
IN ULONG IN ULONG Tag
Definition: evtlib.h:159
PVOID FrLdrDefaultHeap
Definition: heap.c:34
#define P(row, col)
Definition: m_matrix.c:147
PVOID FrLdrHeapAllocateEx ( PVOID  HeapHandle,
SIZE_T  ByteSize,
ULONG  Tag 
)

Definition at line 317 of file heap.c.

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

321 {
322  PHEAP Heap = HeapHandle;
323  PHEAP_BLOCK Block, NextBlock;
324  USHORT BlockSize, Remaining;
325 #if DBG && !defined(_M_ARM)
326  ULONGLONG Time = __rdtsc();
327 #endif
328 
329 #ifdef FREELDR_HEAP_VERIFIER
330  /* Verify the heap */
331  FrLdrHeapVerify(HeapHandle);
332 
333  /* Add space for a size field and 2 redzones */
335 #endif
336 
337  /* Check if the allocation is too large */
338  if ((ByteSize + sizeof(HEAP_BLOCK)) > MAXUSHORT * sizeof(HEAP_BLOCK))
339  {
340  ERR("HEAP: Allocation of 0x%lx bytes too large\n", ByteSize);
341  return NULL;
342  }
343 
344  /* We need a proper tag */
345  if (Tag == 0) Tag = 'enoN';
346 
347  /* Calculate alloc size */
348  BlockSize = (USHORT)((ByteSize + sizeof(HEAP_BLOCK) - 1) / sizeof(HEAP_BLOCK));
349 
350  /* Walk the free block list */
351  Block = &Heap->Blocks + Heap->TerminatingBlock;
352  for (Block = &Heap->Blocks + Block->Data[0].Flink;
353  Block->Size != 0;
354  Block = &Heap->Blocks + Block->Data[0].Flink)
355  {
356  ASSERT(Block->Tag == 0);
357 
358  /* Continue, if its too small */
359  if (Block->Size < BlockSize) continue;
360 
361  /* This block is just fine, use it */
362  Block->Tag = Tag;
363 
364  /* Remove this entry from the free list */
365  FrLdrHeapRemoveFreeList(Heap, Block);
366 
367  /* Calculate the remaining size */
368  Remaining = Block->Size - BlockSize;
369 
370  /* Check if the remaining space is large enough for a new block */
371  if (Remaining > 1)
372  {
373  /* Make the allocated block as large as necessary */
374  Block->Size = BlockSize;
375 
376  /* Get pointer to the new block */
377  NextBlock = Block + 1 + BlockSize;
378 
379  /* Make it a free block */
380  NextBlock->Tag = 0;
381  NextBlock->Size = Remaining - 1;
382  NextBlock->PreviousSize = BlockSize;
383  BlockSize = NextBlock->Size;
384  FrLdrHeapInsertFreeList(Heap, NextBlock);
385 
386  /* Advance to the next block */
387  NextBlock = NextBlock + 1 + BlockSize;
388  }
389  else
390  {
391  /* Not enough left, use the full block */
392  BlockSize = Block->Size;
393 
394  /* Get the next block */
395  NextBlock = Block + 1 + BlockSize;
396  }
397 
398  /* Update the next blocks back link */
399  NextBlock->PreviousSize = BlockSize;
400 
401  /* Update heap usage */
402  Heap->NumAllocs++;
403  Heap->CurrentAllocBytes += Block->Size * sizeof(HEAP_BLOCK);
404  Heap->MaxAllocBytes = max(Heap->MaxAllocBytes, Heap->CurrentAllocBytes);
406  Block->Size * sizeof(HEAP_BLOCK));
407 #if DBG && !defined(_M_ARM)
408  Heap->AllocationTime += (__rdtsc() - Time);
409 #endif
410  TRACE("HeapAllocate(%p, %ld, %.4s) -> return %p\n",
411  HeapHandle, ByteSize, &Tag, Block->Data);
412 
413  /* HACK: zero out the allocation */
414  RtlZeroMemory(Block->Data, Block->Size * sizeof(HEAP_BLOCK));
415 
416 #ifdef FREELDR_HEAP_VERIFIER
417  /* Write size and redzones */
419  *REDZONE_LOW(Block) = REDZONE_MARK;
420  *REDZONE_HI(Block) = REDZONE_MARK;
421 
422  /* Allocation starts after size field and redzone */
423  return (PUCHAR)Block->Data + REDZONE_LOW_OFFSET;
424 #endif
425  /* Return pointer to the data */
426  return Block->Data;
427  }
428 
429  /* We found nothing */
430  WARN("HEAP: nothing suitable found for 0x%lx bytes\n", ByteSize);
431  return NULL;
432 }
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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
#define REDZONE_LOW_OFFSET
Definition: heap.c:29
static VOID FrLdrHeapInsertFreeList(PHEAP Heap, PHEAP_BLOCK FreeBlock)
Definition: heap.c:295
#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:277
VOID FrLdrHeapCleanupAll ( VOID  )

Definition at line 248 of file heap.c.

Referenced by WinLdrSetupMemoryLayout().

249 {
250  PHEAP Heap;
251 
252  Heap = FrLdrDefaultHeap;
253  TRACE("Heap statistics for default heap:\n"
254  "CurrentAlloc=0x%lx, MaxAlloc=0x%lx, LargestAllocation=0x%lx\n"
255  "NumAllocs=%ld, NumFrees=%ld\n",
257  Heap->NumAllocs, Heap->NumFrees);
258  TRACE("AllocTime = %I64d, FreeTime = %I64d, sum = %I64d\n",
259  Heap->AllocationTime, Heap->FreeTime, Heap->AllocationTime + Heap->FreeTime);
260 
261 
262  /* Release free pages from the default heap */
264 
265  Heap = FrLdrTempHeap;
266  TRACE("Heap statistics for temp heap:\n"
267  "CurrentAlloc=0x%lx, MaxAlloc=0x%lx, LargestAllocation=0x%lx\n"
268  "NumAllocs=%ld, NumFrees=%ld\n",
270  Heap->NumAllocs, Heap->NumFrees);
271 
272  /* Destroy the temp heap */
274 }
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
PVOID FrLdrHeapCreate ( SIZE_T  MaximumSize,
TYPE_OF_MEMORY  MemoryType 
)

Definition at line 66 of file heap.c.

Referenced by MmInitializeHeap().

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);
79  if (!Heap)
80  {
81  ERR("HEAP: Failed to allocate heap of size 0x%lx, Type\n",
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
ACPI_EFI_MEMORY_TYPE
Definition: acefiex.h:128
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
VOID FrLdrHeapDestroy ( PVOID  HeapHandle)

Definition at line 137 of file heap.c.

Referenced by FrLdrHeapCleanupAll().

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
VOID FrLdrHeapFreeEx ( PVOID  HeapHandle,
PVOID  Pointer,
ULONG  Tag 
)

Definition at line 435 of file heap.c.

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

439 {
440  PHEAP Heap = HeapHandle;
441  PHEAP_BLOCK Block, PrevBlock, NextBlock;
442 #if DBG && !defined(_M_ARM)
443  ULONGLONG Time = __rdtsc();
444 #endif
445  TRACE("HeapFree(%p, %p)\n", HeapHandle, Pointer);
446  ASSERT(Tag != 'dnE#');
447 
448 #ifdef FREELDR_HEAP_VERIFIER
449  /* Verify the heap */
450  FrLdrHeapVerify(HeapHandle);
451 #endif
452 
453  /* Check if the block is really inside this heap */
454  if ((Pointer < (PVOID)(Heap + 1)) ||
455  (Pointer > (PVOID)((PUCHAR)Heap + Heap->MaximumSize)))
456  {
457  ERR("HEAP: trying to free %p outside of heap %p\n", Pointer, Heap);
458  ASSERT(FALSE);
459  }
460 
461  Block = ((PHEAP_BLOCK)Pointer) - 1;
462 #ifdef FREELDR_HEAP_VERIFIER
463  Block = (PHEAP_BLOCK)((PUCHAR)Block - REDZONE_LOW_OFFSET);
464 
465  /* Verify size and redzones */
466  ASSERT(*REDZONE_SIZE(Block) <= Block->Size * sizeof(HEAP_BLOCK));
467  ASSERT(*REDZONE_LOW(Block) == REDZONE_MARK);
468  ASSERT(*REDZONE_HI(Block) == REDZONE_MARK);
469 #endif
470 
471  /* Check if the tag matches */
472  if ((Tag && (Block->Tag != Tag)) || (Block->Tag == 0))
473  {
474  ERR("HEAP: Bad tag! Pointer=%p: block tag '%.4s', requested '%.4s', size=0x%lx\n",
475  Pointer, &Block->Tag, &Tag, Block->Size);
476  ASSERT(FALSE);
477  }
478 
479  /* Mark as free */
480  Block->Tag = 0;
481 
482 #if DBG
483  /* Erase contents */
484  RtlFillMemory(Block->Data, Block->Size * sizeof(HEAP_BLOCK), 0xCCCCCCCC);
485 #endif
486 
487  /* Update heap usage */
488  Heap->NumFrees++;
489  Heap->CurrentAllocBytes -= Block->Size * sizeof(HEAP_BLOCK);
490 
491  /* Get pointers to the next and previous block */
492  PrevBlock = Block - Block->PreviousSize - 1;
493  NextBlock = Block + Block->Size + 1;
494 
495  /* Check if next block is free */
496  if ((NextBlock->Tag == 0) &&
497  ((Block->Size + NextBlock->Size + 1) <= MAXUSHORT))
498  {
499  /* Merge next block into current */
500  Block->Size += NextBlock->Size + 1;
501  FrLdrHeapRemoveFreeList(Heap, NextBlock);
502 
503  NextBlock = Block + Block->Size + 1;
504  }
505 
506  /* Check if there is a block before and it's free */
507  if ((Block->PreviousSize != 0) && (PrevBlock->Tag == 0) &&
508  ((PrevBlock->Size + Block->Size + 1) <= MAXUSHORT))
509  {
510  /* Merge current block into previous */
511  PrevBlock->Size += Block->Size + 1;
512  Block = PrevBlock;
513  }
514  else
515  {
516  /* Insert the entry into the free list */
517  FrLdrHeapInsertFreeList(Heap, Block);
518  }
519 
520  /* Update the next block's back link */
521  NextBlock->PreviousSize = Block->Size;
522 #if DBG && !defined(_M_ARM)
523  Heap->FreeTime += (__rdtsc() - Time);
524 #endif
525 }
DWORD *typedef PVOID
Definition: winlogon.h:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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
#define FALSE
Definition: types.h:117
struct _HEAP_BLOCK * PHEAP_BLOCK
#define TRACE(s)
Definition: solgame.cpp:4
uint64_t ULONGLONG
Definition: typedefs.h:65
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:295
#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:277
static VOID FrLdrHeapInsertFreeList ( PHEAP  Heap,
PHEAP_BLOCK  FreeBlock 
)
static

Definition at line 295 of file heap.c.

Referenced by FrLdrHeapAllocateEx(), and FrLdrHeapFreeEx().

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

Definition at line 181 of file heap.c.

Referenced by FrLdrHeapCleanupAll().

183 {
184  PHEAP Heap = HeapHandle;
185  PHEAP_BLOCK Block;
186  PUCHAR StartAddress, EndAddress;
187  PFN_COUNT FreePages, AllPages, AllFreePages = 0;
188  TRACE("HeapRelease(%p)\n", HeapHandle);
189 
190  /* Loop all heap chunks */
191  for (Block = &Heap->Blocks;
192  Block->Size != 0;
193  Block = Block + 1 + Block->Size)
194  {
195  /* Continue, if its not free */
196  if (Block->Tag != 0)
197  {
198 #ifdef FREELDR_HEAP_VERIFIER
199  /* Verify size and redzones */
200  ASSERT(*REDZONE_SIZE(Block) <= Block->Size * sizeof(HEAP_BLOCK));
201  ASSERT(*REDZONE_LOW(Block) == REDZONE_MARK);
202  ASSERT(*REDZONE_HI(Block) == REDZONE_MARK);
203 #endif
204  continue;
205  }
206 
207  /* Calculate page aligned start address of the free region */
208  StartAddress = ALIGN_UP_POINTER_BY(Block->Data, PAGE_SIZE);
209 
210  /* Walk over adjacent free blocks */
211  while (Block->Tag == 0) Block = Block + Block->Size + 1;
212 
213  /* Check if this was the last block */
214  if (Block->Size == 0)
215  {
216  /* Align the end address up to cover the end of the heap */
217  EndAddress = ALIGN_UP_POINTER_BY(Block->Data, PAGE_SIZE);
218  }
219  else
220  {
221  /* Align the end address down to not cover any allocations */
222  EndAddress = ALIGN_DOWN_POINTER_BY(Block->Data, PAGE_SIZE);
223  }
224 
225  /* Check if we have free pages */
226  if (EndAddress > StartAddress)
227  {
228  /* Calculate the size of the free region in pages */
229  FreePages = (PFN_COUNT)((EndAddress - StartAddress) / MM_PAGE_SIZE);
230  AllFreePages += FreePages;
231 
232  /* Now mark the pages free */
234  (ULONG_PTR)StartAddress / MM_PAGE_SIZE,
235  FreePages,
236  LoaderFree);
237  }
238 
239  /* bail out, if it was the last block */
240  if (Block->Size == 0) break;
241  }
242 
243  AllPages = Heap->MaximumSize / MM_PAGE_SIZE;
244  TRACE("HeapRelease() done, freed %lu of %lu pages\n", AllFreePages, AllPages);
245 }
HEAP_BLOCK Blocks
Definition: heap.c:62
ULONG PFN_COUNT
Definition: mmtypes.h:102
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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
#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
static VOID FrLdrHeapRemoveFreeList ( PHEAP  Heap,
PHEAP_BLOCK  Block 
)
static

Definition at line 277 of file heap.c.

Referenced by FrLdrHeapAllocateEx(), and FrLdrHeapFreeEx().

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

Definition at line 156 of file heap.c.

Referenced by FrLdrHeapAllocateEx(), and FrLdrHeapFreeEx().

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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#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
#define REDZONE_LOW(Block)
Definition: heap.c:31
#define REDZONE_HI(Block)
Definition: heap.c:32
Definition: heap.c:51
VOID MmInitializeHeap ( PVOID  PageLookupTable)

Definition at line 531 of file heap.c.

Referenced by MmInitializeMemoryManager().

532 {
533  TRACE("MmInitializeHeap()\n");
534 
535  /* Create the default heap */
538 
539  /* Create a temporary heap */
542 
543  TRACE("MmInitializeHeap() done, default heap %p, temp heap %p\n",
545 }
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel)?(CompletionRoutine!=NULL):TRUE)
#define TEMP_HEAP_SIZE
Definition: mm.h:123
#define DEFAULT_HEAP_SIZE
Definition: mm.h:122
#define TRACE(s)
Definition: solgame.cpp:4
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
PVOID NTAPI RtlAllocateHeap ( IN PVOID  HeapHandle,
IN ULONG  Flags,
IN SIZE_T  Size 
)

Definition at line 585 of file heap.c.

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(), AddConsoleCtrlHandler(), AddDialogListEntry(), AddDiskToList(), AddLogicalDiskSpace(), 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(), CreateExtendedPartition(), CreateFiberEx(), CreateFileSystemList(), CreateFileW(), CreateGenericList(), CreateHardLinkW(), CreateHardwareTimer(), CreateLogicalPartition(), CreatePartitionList(), CreatePrimaryPartition(), 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_A(), DnsQuery_W(), DnsWToC(), do_reg_operation(), DosCreateDeviceNode(), DosReadFile(), DosStart(), DosStartProcess32(), DosWriteFile(), EmsDrvInitialize(), EmulatorCopyMemory(), EngCreateSemaphore(), EnumDisplaySettingsExA(), EnumDisplaySettingsExW(), EnumerateBiosDiskEntries(), EnumHKCRKey(), EnumHKCRValue(), EnumPropsA(), EnumPropsExA(), EnumPropsExW(), EnumPropsW(), EventThread(), 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(), InstallBtrfsBootCodeToDisk(), InstallDevice(), InstallDriver(), InstallFat12BootCodeToFloppy(), InstallFat16BootCode(), InstallFat32BootCode(), InstallMbrBootCodeToDiskHelper(), IntEnumFontFamilies(), InternalExplicitAccessAToW(), InternalGetAtomName(), InternalTrusteeAToW(), IntWriteConsoleOutput(), is_mounted_multi_device(), is_ssd(), IsAcpiComputer(), IsThereAValidBootSector(), LdrGetDllHandleEx(), LdrpAllocateDataTableEntry(), LdrpAllocateTls(), LdrpAllocateUnicodeString(), LdrpCheckForKnownDll(), LdrpGetProcedureAddress(), LdrpInitializeProcess(), LdrpInitializeProcessCompat(), LdrpInitializeTls(), LdrpResolveDllName(), LdrpRunInitializeRoutines(), LdrpSearchPath(), LdrQueryImageFileKeyOption(), LoadAllocStringW(), LoadInstallableVDD(), LoadLibraryA(), LoadModule(), LoadNotificationDll(), LocalAlloc(), LocalReAlloc(), LogfAllocAndBuildNewRecord(), LogfpAlloc(), LogonUserExW(), lookup_assembly(), lookup_manifest_file(), lookup_winsxs(), LsaApLogonUser(), LsapAddAuthPackage(), LsapAddDefaultGroups(), LsapAddLocalGroups(), LsapAddPrivilegeToTokenPrivileges(), LsapAddSamGroups(), LsapAllocateHeap(), LsapAllocateHeapZero(), LsapAppendSidToGroups(), LsapCallAuthenticationPackage(), LsapCheckLogonProcess(), LsapCopyLocalGroups(), LsapCreateAccountSd(), LsapCreateDatabaseObjects(), LsapCreateDbObject(), LsapCreateLogonSession(), LsapCreatePolicySd(), LsapCreateSecretSd(), LsapCreateSid(), LsapEnumLogonSessions(), LsapGetDomainInfo(), LsapGetLogonSessionData(), 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(), PrintMessageAnsi(), ProcessLangEntry(), QueryDosDeviceA(), 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(), 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().

589 {
590  PVOID ptr;
591 
592  ptr = FrLdrHeapAllocateEx(FrLdrDefaultHeap, Size, ' ltR');
593  if (ptr && (Flags & HEAP_ZERO_MEMORY))
594  {
595  RtlZeroMemory(ptr, Size);
596  }
597 
598  return ptr;
599 }
DWORD *typedef PVOID
Definition: winlogon.h:61
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
static PVOID ptr
Definition: dispmode.c:27
UINTN Size
Definition: acefiex.h:555
#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:317
PVOID FrLdrDefaultHeap
Definition: heap.c:34
BOOLEAN NTAPI RtlFreeHeap ( IN PVOID  HeapHandle,
IN ULONG  Flags,
IN PVOID  HeapBase 
)

Definition at line 603 of file heap.c.

Referenced by __RegisterConsoleVDM(), _tmain(), AccpOpenNamedObject(), actctx_release(), add_entry(), AddBootStoreEntry(), AddConsoleCtrlHandler(), AddDiskToList(), AddProvider(), AfdBind(), AfdConnect(), AfdCreateSocket(), AfdSendTo(), AttachToConsoleInternal(), AVrfInitializeVerifier(), BackupEventLogW(), BaseCheckRunApp(), BaseCheckVDM(), BaseCleanupDefineDosDevice(), BasepComputeProcessPath(), BasepFreeActivationContextActivationBlock(), BasepFreeAppCompatData(), BasepGetVolumeNameFromReparsePoint(), BasepIsProcessAllowed(), BasepMoveFileDelayed(), BasePushProcessParameters(), BaseQuerySystemFirmware(), BaseRundownFls(), BaseSrvCleanupVDMResources(), BaseSrvDestroyConsoleRecord(), BaseSrvFreeVDMInfo(), CallNt(), ChangeDisplaySettingsExA(), CheckForCurrentHostname(), CheckTokenMembership(), CleanupNotifications(), clear_first_megabyte(), ClearEventLogW(), CloseAllProcessHandles(), CloseIniBootLoaderStore(), cmdGroup(), cmdLocalGroup(), CommandDumpSector(), CommandPartInfo(), ConDrvWriteConsole(), ConDrvWriteConsoleOutputString(), ConvertFiberToThread(), create_lost_and_found(), 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(), DefineDosDeviceW(), DeleteCurrentPartition(), DeleteFiber(), DeleteFileW(), DesktopHeapFree(), DesktopHeapReAlloc(), DestroyFileSystemList(), DestroyGenericList(), DestroyHardwareTimer(), DestroyPartitionList(), DestroyProgressBar(), DisplayGroup(), DisplayLocalGroup(), DisplayMessage(), disposeResInfo(), DnsAcquireContextHandle_W(), DnsApiFree(), DnsFree(), DnsIntFreeRecordList(), DnsQuery_A(), DnsQuery_W(), DnsReleaseContextHandle(), do_reg_operation(), DosDeleteDevice(), DosReadFile(), DosStartProcess32(), DosWriteFile(), EmsDrvCleanup(), EmsDrvInitialize(), EngDeleteSemaphore(), EnumDisplaySettingsExA(), EnumDisplaySettingsExW(), EnumerateBiosDiskEntries(), EnumHKCRKey(), EnumHKCRValue(), EnumPropsA(), EnumPropsExA(), EnumPropsExW(), EnumPropsW(), EventThread(), 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(), IsThereAValidBootSector(), LdrGetDllHandleEx(), LdrpCheckForKnownDll(), LdrpCheckForLoadedDll(), LdrpFinalizeAndDeallocateDataTableEntry(), LdrpFreeTls(), LdrpFreeUnicodeString(), LdrpGetProcedureAddress(), LdrpMapDll(), LdrpResolveDllName(), LdrpRunInitializeRoutines(), LdrpSearchPath(), LdrQueryImageFileKeyOption(), LdrShutdownThread(), LoadInstallableVDD(), LoadLibraryA(), LoadLibraryExW(), LoadModule(), LocalReAlloc(), LogfFreeRecord(), LogfpFree(), LogonUserExW(), lookup_assembly(), lookup_manifest_file(), lookup_winsxs(), LsaApLogonUser(), LsaFreeMemory(), LsapAddAuthPackage(), LsapAddDefaultGroups(), LsapAddLocalGroups(), LsapAddPrivilegeToTokenPrivileges(), LsapAddSamGroups(), LsapAppendSidToGroups(), LsapCallAuthenticationPackage(), LsapCloseDbObject(), LsapCopyLocalGroups(), LsapCreateAccountSd(), LsapCreateDatabaseObjects(), LsapCreateLogonSession(), LsapCreatePolicySd(), LsapCreateSecretSd(), LsapCreateSid(), LsapDeleteDbObject(), LsapDeleteLogonSession(), LsapDeregisterLogonProcess(), LsapEnumLogonSessions(), LsapFreeHeap(), LsapGetDomainInfo(), LsapGetLogonSessionData(), 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(), NetUserGetGroups(), NetUserGetLocalGroups(), NetUserModalsGet(), NtLdrEnumerateBootEntries(), OpenAccountDomain(), OpenBackupEventLogW(), OpenBuiltinDomain(), OpenFile(), OpenIniBootLoaderStore(), parse_manifest(), PeekNamedPipe(), PrintMessageAnsi(), PrivMoveFileIdentityW(), QueryDosDeviceA(), 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(), 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().

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

Variable Documentation

PVOID FrLdrTempHeap

Definition at line 35 of file heap.c.

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