ReactOS 0.4.15-dev-5893-g1bb4167
heapuser.c File Reference
#include <rtl.h>
#include <heap.h>
#include <debug.h>
Include dependency graph for heapuser.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI RtlpAddHeapToProcessList (PHEAP Heap)
 
VOID NTAPI RtlpRemoveHeapFromProcessList (PHEAP Heap)
 
VOID NTAPI RtlInitializeHeapManager (VOID)
 

Variables

RTL_CRITICAL_SECTION RtlpProcessHeapsListLock
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file heapuser.c.

Function Documentation

◆ RtlInitializeHeapManager()

VOID NTAPI RtlInitializeHeapManager ( VOID  )

Definition at line 116 of file heapuser.c.

117{
118 PPEB Peb;
119
120 /* Get PEB */
122
123 /* Initialize heap-related fields of PEB */
124 Peb->NumberOfHeaps = 0;
125
126 /* Initialize the process heaps list protecting lock */
128}
PPEB Peb
Definition: dllmain.c:27
RTL_CRITICAL_SECTION RtlpProcessHeapsListLock
Definition: heapuser.c:17
NTSYSAPI PEB *WINAPI RtlGetCurrentPeb(void)
Definition: libsupp.c:63
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
ULONG NumberOfHeaps
Definition: ntddk_ex.h:286

Referenced by LdrpInitializeProcess().

◆ RtlpAddHeapToProcessList()

VOID NTAPI RtlpAddHeapToProcessList ( PHEAP  Heap)

Definition at line 23 of file heapuser.c.

24{
25 PPEB Peb;
26
27 /* Get PEB */
29
30 /* Acquire the lock */
32
33 //_SEH2_TRY {
34 /* Check if max number of heaps reached */
36 {
37 // TODO: Handle this case
39 }
40
41 /* Add the heap to the process heaps */
45 // } _SEH2_FINALLY {
46
47 /* Release the lock */
49
50 // } _SEH2_END
51}
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
unsigned short USHORT
Definition: pedump.c:61
USHORT ProcessHeapsListIndex
Definition: heap.h:241
ULONG MaximumNumberOfHeaps
Definition: ntddk_ex.h:287
PVOID * ProcessHeaps
Definition: ntddk_ex.h:288

◆ RtlpRemoveHeapFromProcessList()

VOID NTAPI RtlpRemoveHeapFromProcessList ( PHEAP  Heap)

Definition at line 56 of file heapuser.c.

57{
58 PPEB Peb;
59 PHEAP *Current, *Next;
61
62 /* Get PEB */
64
65 /* Acquire the lock */
67
68 /* Check if we don't need anything to do */
69 if ((Heap->ProcessHeapsListIndex == 0) ||
71 (Peb->NumberOfHeaps == 0))
72 {
73 /* Release the lock */
75
76 return;
77 }
78
79 /* The process actually has more than one heap.
80 Use classic, lernt from university times algorithm for removing an entry
81 from a static array */
82
83 Current = (PHEAP *)&Peb->ProcessHeaps[Heap->ProcessHeapsListIndex - 1];
84 Next = Current + 1;
85
86 /* How many items we need to shift to the left */
88
89 /* Move them all in a loop */
90 while (--Count)
91 {
92 /* Copy it and advance next pointer */
93 *Current = *Next;
94
95 /* Update its index */
96 (*Current)->ProcessHeapsListIndex -= 1;
97
98 /* Advance pointers */
99 Current++;
100 Next++;
101 }
102
103 /* Decrease total number of heaps */
105
106 /* Zero last unused item */
108 Heap->ProcessHeapsListIndex = 0;
109
110 /* Release the lock */
112}
#define NULL
Definition: types.h:112
int Count
Definition: noreturn.cpp:7
Definition: heap.c:52
uint32_t ULONG
Definition: typedefs.h:59

Variable Documentation

◆ RtlpProcessHeapsListLock

RTL_CRITICAL_SECTION RtlpProcessHeapsListLock