ReactOS 0.4.16-dev-122-g325d74c
heapdbg.c File Reference
#include <rtl.h>
#include <heap.h>
#include <debug.h>
Include dependency graph for heapdbg.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

HANDLE NTAPI RtlDebugCreateHeap (ULONG Flags, PVOID Addr, SIZE_T ReserveSize, SIZE_T CommitSize, PVOID Lock, PRTL_HEAP_PARAMETERS Parameters)
 
BOOLEAN NTAPI RtlDebugDestroyHeap (HANDLE HeapPtr)
 
PVOID NTAPI RtlDebugAllocateHeap (PVOID HeapPtr, ULONG Flags, SIZE_T Size)
 
PVOID NTAPI RtlDebugReAllocateHeap (HANDLE HeapPtr, ULONG Flags, PVOID Ptr, SIZE_T Size)
 
BOOLEAN NTAPI RtlDebugFreeHeap (HANDLE HeapPtr, ULONG Flags, PVOID Ptr)
 
BOOLEAN NTAPI RtlDebugGetUserInfoHeap (PVOID HeapHandle, ULONG Flags, PVOID BaseAddress, PVOID *UserValue, PULONG UserFlags)
 
BOOLEAN NTAPI RtlDebugSetUserValueHeap (PVOID HeapHandle, ULONG Flags, PVOID BaseAddress, PVOID UserValue)
 
BOOLEAN NTAPI RtlDebugSetUserFlagsHeap (PVOID HeapHandle, ULONG Flags, PVOID BaseAddress, ULONG UserFlagsReset, ULONG UserFlagsSet)
 
SIZE_T NTAPI RtlDebugSizeHeap (HANDLE HeapPtr, ULONG Flags, PVOID Ptr)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file heapdbg.c.

Function Documentation

◆ RtlDebugAllocateHeap()

PVOID NTAPI RtlDebugAllocateHeap ( PVOID  HeapPtr,
ULONG  Flags,
SIZE_T  Size 
)

Definition at line 130 of file heapdbg.c.

133{
134 PHEAP Heap = (PHEAP)HeapPtr;
135 SIZE_T AllocSize = 1;
136 BOOLEAN HeapLocked = FALSE;
138
140 return RtlpPageHeapAllocate(HeapPtr, Flags, Size);
141
142 if (Heap->Signature != HEAP_SIGNATURE)
143 {
144 DPRINT1("HEAP: Invalid heap %p signature 0x%x\n", Heap, Heap->Signature);
145 return NULL;
146 }
147
148 /* Add settable user value flag */
150
151 /* Calculate size */
152 if (Size) AllocSize = Size;
153 AllocSize = ((AllocSize + Heap->AlignRound) & Heap->AlignMask) + sizeof(HEAP_ENTRY_EXTRA);
154
155 /* Check if size didn't exceed max one */
156 if (AllocSize < Size ||
157 AllocSize > Heap->MaximumAllocationSize)
158 {
159 DPRINT1("HEAP: Too big allocation size %x (max allowed %x)\n", Size, Heap->MaximumAllocationSize);
160 return NULL;
161 }
162
163 /* Lock the heap ourselves */
164 if (!(Flags & HEAP_NO_SERIALIZE))
165 {
167 HeapLocked = TRUE;
168
169 /* Add no serialize flag so that the main routine won't try to acquire the lock again */
171 }
172
173 /* Validate the heap if necessary */
174 RtlpValidateHeap(Heap, FALSE);
175
176 /* Call main routine to do the stuff */
177 Result = RtlAllocateHeap(HeapPtr, Flags, Size);
178
179 /* Validate heap headers */
181
182 if (Result)
183 {
185 RtlpValidateHeap(Heap, FALSE);
186 }
187
188 /* Release the lock */
189 if (HeapLocked) RtlLeaveHeapLock(Heap->LockVariable);
190
191 return Result;
192}
unsigned char BOOLEAN
#define DPRINT1
Definition: precomp.h:8
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
struct _HEAP * PHEAP
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI RtlEnterHeapLock(IN OUT PHEAP_LOCK Lock, IN BOOLEAN Exclusive)
Definition: libsupp.c:110
NTSTATUS NTAPI RtlLeaveHeapLock(IN OUT PHEAP_LOCK Lock)
Definition: libsupp.c:135
#define HEAP_SKIP_VALIDATION_CHECKS
Definition: rtltypes.h:165
#define HEAP_VALIDATE_ALL_ENABLED
Definition: rtltypes.h:166
#define HEAP_FLAG_PAGE_ALLOCS
Definition: rtltypes.h:160
#define HEAP_SETTABLE_USER_VALUE
Definition: nt_native.h:1704
#define HEAP_NO_SERIALIZE
Definition: nt_native.h:1692
BOOLEAN NTAPI RtlpValidateHeap(PHEAP Heap, BOOLEAN ForceValidation)
Definition: heap.c:3532
BOOLEAN NTAPI RtlpValidateHeapHeaders(PHEAP Heap, BOOLEAN Recalculate)
Definition: heap.c:3279
struct _HEAP_ENTRY_EXTRA HEAP_ENTRY_EXTRA
#define HEAP_SIGNATURE
Definition: heap.h:51
PVOID NTAPI RtlpPageHeapAllocate(IN PVOID HeapPtr, IN ULONG Flags, IN SIZE_T Size)
Definition: heappage.c:1758
Definition: heap.c:52
ULONG Flags
Definition: heap.h:226
ULONG_PTR AlignRound
Definition: heap.h:249
ULONG ForceFlags
Definition: heap.h:227
ULONG_PTR AlignMask
Definition: heap.h:250
ULONG Signature
Definition: heap.h:234
SIZE_T MaximumAllocationSize
Definition: heap.h:240
PHEAP_LOCK LockVariable
Definition: heap.h:260
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by RtlAllocateHeap().

◆ RtlDebugCreateHeap()

HANDLE NTAPI RtlDebugCreateHeap ( ULONG  Flags,
PVOID  Addr,
SIZE_T  ReserveSize,
SIZE_T  CommitSize,
PVOID  Lock,
PRTL_HEAP_PARAMETERS  Parameters 
)

Definition at line 20 of file heapdbg.c.

26{
27 MEMORY_BASIC_INFORMATION MemoryInfo;
29 PHEAP Heap;
30
31 /* Validate parameters */
33 {
34 DPRINT1("HEAP: Incorrect ReserveSize %x\n", ReserveSize);
35 return NULL;
36 }
37
39 {
40 DPRINT1("HEAP: Incorrect CommitSize %x\n", CommitSize);
41 return NULL;
42 }
43
45 {
46 DPRINT1("HEAP: Can't specify Lock routine and have HEAP_NO_SERIALIZE flag set\n");
47 return NULL;
48 }
49
50 /* If the address is specified, check it's virtual memory */
51 if (Addr)
52 {
54 Addr,
56 &MemoryInfo,
57 sizeof(MemoryInfo),
58 NULL);
59
60 if (!NT_SUCCESS(Status))
61 {
62 DPRINT1("HEAP: Specified heap base address %p is invalid, Status 0x%08X\n", Addr, Status);
63 return NULL;
64 }
65
66 if (MemoryInfo.BaseAddress != Addr)
67 {
68 DPRINT1("HEAP: Specified heap base address %p is not really a base one %p\n", Addr, MemoryInfo.BaseAddress);
69 return NULL;
70 }
71
72 if (MemoryInfo.State == MEM_FREE)
73 {
74 DPRINT1("HEAP: Specified heap base address %p is free\n", Addr);
75 return NULL;
76 }
77 }
78
79 /* All validation performed, now call the real routine with skip validation check flag */
83
85 if (!Heap) return NULL;
86
87 // FIXME: Capture stack backtrace
88
90
91 return Heap;
92}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
NTSYSAPI NTSTATUS NTAPI ZwQueryVirtualMemory(_In_ HANDLE ProcessHandle, _In_ PVOID Address, _In_ MEMORY_INFORMATION_CLASS VirtualMemoryInformationClass, _Out_ PVOID VirtualMemoryInformation, _In_ SIZE_T Length, _Out_opt_ PSIZE_T ResultLength)
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T CommitSize
Definition: mmfuncs.h:406
@ MemoryBasicInformation
Definition: mmtypes.h:183
#define MEM_FREE
Definition: nt_native.h:1317
#define HEAP_FREE_CHECKING_ENABLED
Definition: nt_native.h:1698
NTSYSAPI PVOID NTAPI RtlCreateHeap(IN ULONG Flags, IN PVOID HeapBase OPTIONAL, IN ULONG ReserveSize OPTIONAL, IN ULONG CommitSize OPTIONAL, IN PVOID Lock OPTIONAL, IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL)
#define HEAP_TAIL_CHECKING_ENABLED
Definition: nt_native.h:1697
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define HEAP_ENTRY_SIZE
Definition: heap.h:17
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127
_In_opt_ PVOID _In_opt_ SIZE_T ReserveSize
Definition: rtlfuncs.h:2182

Referenced by RtlCreateHeap().

◆ RtlDebugDestroyHeap()

BOOLEAN NTAPI RtlDebugDestroyHeap ( HANDLE  HeapPtr)

Definition at line 95 of file heapdbg.c.

96{
97 SIZE_T Size = 0;
98 PHEAP Heap = (PHEAP)HeapPtr;
99
100 if (Heap == RtlGetCurrentPeb()->ProcessHeap)
101 {
102 DPRINT1("HEAP: It's forbidden delete process heap!");
103 return FALSE;
104 }
105
106 if (Heap->Signature != HEAP_SIGNATURE)
107 {
108 DPRINT1("HEAP: Invalid heap %p signature 0x%x\n", Heap, Heap->Signature);
109 return FALSE;
110 }
111
112 if (!RtlpValidateHeap(Heap, FALSE)) return FALSE;
113
114 /* Make heap invalid by zeroing its signature */
115 Heap->Signature = 0;
116
117 /* Free validate headers copy if it was existing */
118 if (Heap->HeaderValidateCopy)
119 {
120 ZwFreeVirtualMemory(NtCurrentProcess(),
121 &Heap->HeaderValidateCopy,
122 &Size,
124 }
125
126 return TRUE;
127}
NTSYSAPI PEB *WINAPI RtlGetCurrentPeb(void)
Definition: libsupp.c:65
#define MEM_RELEASE
Definition: nt_native.h:1316
PVOID HeaderValidateCopy
Definition: heap.h:243
PVOID ProcessHeap
Definition: ntddk_ex.h:249

Referenced by RtlDestroyHeap().

◆ RtlDebugFreeHeap()

BOOLEAN NTAPI RtlDebugFreeHeap ( HANDLE  HeapPtr,
ULONG  Flags,
PVOID  Ptr 
)

Definition at line 267 of file heapdbg.c.

270{
271 PHEAP Heap = (PHEAP)HeapPtr;
272 BOOLEAN HeapLocked = FALSE;
273 PHEAP_ENTRY HeapEntry;
275
277 return RtlpPageHeapFree(HeapPtr, Flags, Ptr);
278
279 if (Heap->Signature != HEAP_SIGNATURE)
280 {
281 DPRINT1("HEAP: Invalid heap %p signature 0x%x\n", Heap, Heap->Signature);
282 return FALSE;
283 }
284
285 /* Add skip validation flag */
287
288 /* Lock the heap ourselves */
289 if (!(Flags & HEAP_NO_SERIALIZE))
290 {
292 HeapLocked = TRUE;
293
294 /* Add no serialize flag so that the main routine won't try to acquire the lock again */
296 }
297
298 /* Validate the heap if necessary */
299 RtlpValidateHeap(Heap, FALSE);
300
301 /* Get the existing heap entry */
302 HeapEntry = (PHEAP_ENTRY)Ptr - 1;
303
304 /* Validate it */
305 if (RtlpValidateHeapEntry(Heap, HeapEntry))
306 {
307 /* If it succeeded - call the main routine */
308 Result = RtlFreeHeap(HeapPtr, Flags, Ptr);
309
310 /* Validate heap headers and then heap itself */
312 RtlpValidateHeap(Heap, FALSE);
313 }
314
315 /* Release the lock */
316 if (HeapLocked) RtlLeaveHeapLock(Heap->LockVariable);
317
318 return Result;
319}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
BOOLEAN NTAPI RtlpValidateHeapEntry(PHEAP Heap, PHEAP_ENTRY HeapEntry)
Definition: heap.c:3288
struct _HEAP_ENTRY * PHEAP_ENTRY
BOOLEAN NTAPI RtlpPageHeapFree(HANDLE HeapPtr, ULONG Flags, PVOID Ptr)
Definition: heappage.c:1923
Definition: heap.h:136

Referenced by RtlFreeHeap().

◆ RtlDebugGetUserInfoHeap()

BOOLEAN NTAPI RtlDebugGetUserInfoHeap ( PVOID  HeapHandle,
ULONG  Flags,
PVOID  BaseAddress,
PVOID UserValue,
PULONG  UserFlags 
)

Definition at line 322 of file heapdbg.c.

327{
328 PHEAP Heap = (PHEAP)HeapHandle;
329 BOOLEAN HeapLocked = FALSE;
330 PHEAP_ENTRY HeapEntry;
332
334 return RtlpPageHeapGetUserInfo(HeapHandle, Flags, BaseAddress, UserValue, UserFlags);
335
336 if (Heap->Signature != HEAP_SIGNATURE)
337 {
338 DPRINT1("HEAP: Invalid heap %p signature 0x%x\n", Heap, Heap->Signature);
339 return FALSE;
340 }
341
342 /* Add skip validation flag */
344
345 /* Lock the heap ourselves */
346 if (!(Flags & HEAP_NO_SERIALIZE))
347 {
349 HeapLocked = TRUE;
350
351 /* Add no serialize flag so that the main routine won't try to acquire the lock again */
353 }
354
355 /* Validate the heap if necessary */
356 RtlpValidateHeap(Heap, FALSE);
357
358 /* Get the existing heap entry */
359 HeapEntry = (PHEAP_ENTRY)BaseAddress - 1;
360
361 /* Validate it */
362 if (RtlpValidateHeapEntry(Heap, HeapEntry))
363 {
364 /* If it succeeded - call the main routine */
365 Result = RtlGetUserInfoHeap(HeapHandle, Flags, BaseAddress, UserValue, UserFlags);
366 }
367
368 /* Release the lock */
369 if (HeapLocked) RtlLeaveHeapLock(Heap->LockVariable);
370
371 return Result;
372}
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
BOOLEAN NTAPI RtlGetUserInfoHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID BaseAddress, OUT PVOID *UserValue, OUT PULONG UserFlags)
Definition: heap.c:3934
BOOLEAN NTAPI RtlpPageHeapGetUserInfo(PVOID HeapHandle, ULONG Flags, PVOID BaseAddress, PVOID *UserValue, PULONG UserFlags)
Definition: heappage.c:2185

Referenced by RtlGetUserInfoHeap().

◆ RtlDebugReAllocateHeap()

PVOID NTAPI RtlDebugReAllocateHeap ( HANDLE  HeapPtr,
ULONG  Flags,
PVOID  Ptr,
SIZE_T  Size 
)

Definition at line 195 of file heapdbg.c.

199{
200 PHEAP Heap = (PHEAP)HeapPtr;
201 SIZE_T AllocSize = 1;
202 BOOLEAN HeapLocked = FALSE;
203 PVOID Result = NULL;
204 PHEAP_ENTRY HeapEntry;
205
207 return RtlpPageHeapReAllocate(HeapPtr, Flags, Ptr, Size);
208
209 if (Heap->Signature != HEAP_SIGNATURE)
210 {
211 DPRINT1("HEAP: Invalid heap %p signature 0x%x\n", Heap, Heap->Signature);
212 return NULL;
213 }
214
215 /* Add settable user value flag */
217
218 /* Calculate size */
219 if (Size) AllocSize = Size;
220 AllocSize = ((AllocSize + Heap->AlignRound) & Heap->AlignMask) + sizeof(HEAP_ENTRY_EXTRA);
221
222 /* Check if size didn't exceed max one */
223 if (AllocSize < Size ||
224 AllocSize > Heap->MaximumAllocationSize)
225 {
226 DPRINT1("HEAP: Too big allocation size %x (max allowed %x)\n", Size, Heap->MaximumAllocationSize);
227 return NULL;
228 }
229
230 /* Lock the heap ourselves */
231 if (!(Flags & HEAP_NO_SERIALIZE))
232 {
234 HeapLocked = TRUE;
235
236 /* Add no serialize flag so that the main routine won't try to acquire the lock again */
238 }
239
240 /* Validate the heap if necessary */
241 RtlpValidateHeap(Heap, FALSE);
242
243 /* Get the existing heap entry */
244 HeapEntry = (PHEAP_ENTRY)Ptr - 1;
245
246 /* Validate it */
247 if (RtlpValidateHeapEntry(Heap, HeapEntry))
248 {
249 /* Call main routine to do the stuff */
250 Result = RtlReAllocateHeap(HeapPtr, Flags, Ptr, Size);
251
252 if (Result)
253 {
254 /* Validate heap headers and then heap itself */
256 RtlpValidateHeap(Heap, FALSE);
257 }
258 }
259
260 /* Release the lock */
261 if (HeapLocked) RtlLeaveHeapLock(Heap->LockVariable);
262
263 return Result;
264}
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T)
Definition: heap.c:2686
PVOID NTAPI RtlpPageHeapReAllocate(HANDLE HeapPtr, ULONG Flags, PVOID Ptr, SIZE_T Size)
Definition: heappage.c:2015

Referenced by RtlReAllocateHeap().

◆ RtlDebugSetUserFlagsHeap()

BOOLEAN NTAPI RtlDebugSetUserFlagsHeap ( PVOID  HeapHandle,
ULONG  Flags,
PVOID  BaseAddress,
ULONG  UserFlagsReset,
ULONG  UserFlagsSet 
)

Definition at line 431 of file heapdbg.c.

436{
437 PHEAP Heap = (PHEAP)HeapHandle;
438 BOOLEAN HeapLocked = FALSE;
439 PHEAP_ENTRY HeapEntry;
441
443 return RtlpPageHeapSetUserFlags(HeapHandle, Flags, BaseAddress, UserFlagsReset, UserFlagsSet);
444
445 /* Check if this heap allows flags to be set at all */
446 if (UserFlagsSet & ~HEAP_SETTABLE_USER_FLAGS ||
447 UserFlagsReset & ~HEAP_SETTABLE_USER_FLAGS)
448 {
449 return FALSE;
450 }
451
452 if (Heap->Signature != HEAP_SIGNATURE)
453 {
454 DPRINT1("HEAP: Invalid heap %p signature 0x%x\n", Heap, Heap->Signature);
455 return FALSE;
456 }
457
458 /* Add skip validation flag */
460
461 /* Lock the heap ourselves */
462 if (!(Flags & HEAP_NO_SERIALIZE))
463 {
465 HeapLocked = TRUE;
466
467 /* Add no serialize flag so that the main routine won't try to acquire the lock again */
469 }
470
471 /* Validate the heap if necessary */
472 RtlpValidateHeap(Heap, FALSE);
473
474 /* Get the existing heap entry */
475 HeapEntry = (PHEAP_ENTRY)BaseAddress - 1;
476
477 /* Validate it */
478 if (RtlpValidateHeapEntry(Heap, HeapEntry))
479 {
480 /* If it succeeded - call the main routine */
481 Result = RtlSetUserFlagsHeap(HeapHandle, Flags, BaseAddress, UserFlagsReset, UserFlagsSet);
482
483 /* Validate the heap */
484 RtlpValidateHeap(Heap, FALSE);
485 }
486
487 /* Release the lock */
488 if (HeapLocked) RtlLeaveHeapLock(Heap->LockVariable);
489
490 return Result;
491}
#define HEAP_SETTABLE_USER_FLAGS
Definition: nt_native.h:1708
BOOLEAN NTAPI RtlSetUserFlagsHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID BaseAddress, IN ULONG UserFlagsReset, IN ULONG UserFlagsSet)
Definition: heap.c:3879
BOOLEAN NTAPI RtlpPageHeapSetUserFlags(PVOID HeapHandle, ULONG Flags, PVOID BaseAddress, ULONG UserFlagsReset, ULONG UserFlagsSet)
Definition: heappage.c:2268

Referenced by RtlSetUserFlagsHeap().

◆ RtlDebugSetUserValueHeap()

BOOLEAN NTAPI RtlDebugSetUserValueHeap ( PVOID  HeapHandle,
ULONG  Flags,
PVOID  BaseAddress,
PVOID  UserValue 
)

Definition at line 375 of file heapdbg.c.

379{
380 PHEAP Heap = (PHEAP)HeapHandle;
381 BOOLEAN HeapLocked = FALSE;
382 PHEAP_ENTRY HeapEntry;
384
386 return RtlpPageHeapSetUserValue(HeapHandle, Flags, BaseAddress, UserValue);
387
388 if (Heap->Signature != HEAP_SIGNATURE)
389 {
390 DPRINT1("HEAP: Invalid heap %p signature 0x%x\n", Heap, Heap->Signature);
391 return FALSE;
392 }
393
394 /* Add skip validation flag */
396
397 /* Lock the heap ourselves */
398 if (!(Flags & HEAP_NO_SERIALIZE))
399 {
401 HeapLocked = TRUE;
402
403 /* Add no serialize flag so that the main routine won't try to acquire the lock again */
405 }
406
407 /* Validate the heap if necessary */
408 RtlpValidateHeap(Heap, FALSE);
409
410 /* Get the existing heap entry */
411 HeapEntry = (PHEAP_ENTRY)BaseAddress - 1;
412
413 /* Validate it */
414 if (RtlpValidateHeapEntry(Heap, HeapEntry))
415 {
416 /* If it succeeded - call the main routine */
417 Result = RtlSetUserValueHeap(HeapHandle, Flags, BaseAddress, UserValue);
418
419 /* Validate the heap */
420 RtlpValidateHeap(Heap, FALSE);
421 }
422
423 /* Release the lock */
424 if (HeapLocked) RtlLeaveHeapLock(Heap->LockVariable);
425
426 return Result;
427}
BOOLEAN NTAPI RtlSetUserValueHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID BaseAddress, IN PVOID UserValue)
Definition: heap.c:3817
BOOLEAN NTAPI RtlpPageHeapSetUserValue(PVOID HeapHandle, ULONG Flags, PVOID BaseAddress, PVOID UserValue)
Definition: heappage.c:2227

Referenced by RtlSetUserValueHeap().

◆ RtlDebugSizeHeap()

SIZE_T NTAPI RtlDebugSizeHeap ( HANDLE  HeapPtr,
ULONG  Flags,
PVOID  Ptr 
)

Definition at line 494 of file heapdbg.c.

497{
498 PHEAP Heap = (PHEAP)HeapPtr;
499 BOOLEAN HeapLocked = FALSE;
500 PHEAP_ENTRY HeapEntry;
501 SIZE_T Result = ~(SIZE_T)0;
502
504 return RtlpPageHeapSize(HeapPtr, Flags, Ptr);
505
506 /* Check heap signature */
507 if (Heap->Signature != HEAP_SIGNATURE)
508 {
509 DPRINT1("HEAP: Invalid heap %p signature 0x%x\n", Heap, Heap->Signature);
510 return FALSE;
511 }
512
513 /* Add skip validation flag */
515
516 /* Lock the heap ourselves */
517 if (!(Flags & HEAP_NO_SERIALIZE))
518 {
520 HeapLocked = TRUE;
521
522 /* Add no serialize flag so that the main routine won't try to acquire the lock again */
524 }
525
526 /* Validate the heap if necessary */
527 RtlpValidateHeap(Heap, FALSE);
528
529 /* Get the existing heap entry */
530 HeapEntry = (PHEAP_ENTRY)Ptr - 1;
531
532 /* Validate it */
533 if (RtlpValidateHeapEntry(Heap, HeapEntry))
534 {
535 /* If it succeeded - call the main routine */
536 Result = RtlSizeHeap(HeapPtr, Flags, Ptr);
537 }
538
539 /* Release the lock */
540 if (HeapLocked) RtlLeaveHeapLock(Heap->LockVariable);
541
542 return Result;
543}
NTSYSAPI SIZE_T NTAPI RtlSizeHeap(_In_ PVOID HeapHandle, _In_ ULONG Flags, _In_ PVOID MemoryPointer)
SIZE_T NTAPI RtlpPageHeapSize(HANDLE HeapPtr, ULONG Flags, PVOID Ptr)
Definition: heappage.c:2310

Referenced by RtlSizeHeap().