ReactOS 0.4.15-dev-8417-gb6b82fe
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)
 
ULONG NTAPI RtlGetProcessHeaps (_In_ ULONG HeapCount, _Out_cap_(HeapCount) HANDLE *HeapArray)
 

Variables

RTL_CRITICAL_SECTION RtlpProcessHeapsListLock
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file heapuser.c.

Function Documentation

◆ RtlGetProcessHeaps()

ULONG NTAPI RtlGetProcessHeaps ( _In_ ULONG  HeapCount,
_Out_cap_(HeapCount) HANDLE HeapArray 
)

Definition at line 131 of file heapuser.c.

132{
134
136 ULONG nHeaps = Peb->NumberOfHeaps;
137
139 {
140 if (HeapArray)
141 {
142 for (ULONG n = 0; n < min(nHeaps, HeapCount); ++n)
143 {
144 HeapArray[n] = Peb->ProcessHeaps[n];
145 }
146 }
147 }
149 {
151 }
152 _SEH2_END;
153
154 /* TODO: Add RtlpDphPageHeapList here */
155
156 return nHeaps;
157}
PPEB Peb
Definition: dllmain.c:27
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
GLdouble n
Definition: glext.h:7729
RTL_CRITICAL_SECTION RtlpProcessHeapsListLock
Definition: heapuser.c:17
NTSYSAPI PEB *WINAPI RtlGetCurrentPeb(void)
Definition: libsupp.c:65
#define min(a, b)
Definition: monoChain.cc:55
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
PVOID * ProcessHeaps
Definition: ntddk_ex.h:288
ULONG NumberOfHeaps
Definition: ntddk_ex.h:286
uint32_t ULONG
Definition: typedefs.h:59

◆ 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}
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)

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
unsigned short USHORT
Definition: pedump.c:61
USHORT ProcessHeapsListIndex
Definition: heap.h:241
ULONG MaximumNumberOfHeaps
Definition: ntddk_ex.h:287

◆ 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

Variable Documentation

◆ RtlpProcessHeapsListLock