2 * PROJECT: ReactOS Win32 Base API
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/kernel32/mem/heap.c
5 * PURPOSE: Heap Memory APIs (wrappers for RtlHeap*)
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
9 /* INCLUDES ******************************************************************/
16 /* FUNCTIONS ***************************************************************/
23 HeapCreate(DWORD flOptions
,
30 /* Remove non-Win32 flags and tag this allocation */
31 Flags
= (flOptions
& (HEAP_GENERATE_EXCEPTIONS
| HEAP_NO_SERIALIZE
)) |
35 hRet
= RtlCreateHeap(Flags
,
42 /* Set the last error if we failed, and return the pointer */
43 if (!hRet
) SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
52 HeapDestroy(HANDLE hHeap
)
54 /* Return TRUE if the heap was destroyed */
55 if (!RtlDestroyHeap(hHeap
)) return TRUE
;
57 /* Otherwise, we got the handle back, so fail */
58 SetLastError(ERROR_INVALID_HANDLE
);
69 /* Call the RTL API */
70 return RtlGetProcessHeap();
78 GetProcessHeaps(DWORD NumberOfHeaps
,
81 /* Call the RTL API */
82 return RtlGetProcessHeaps(NumberOfHeaps
, ProcessHeaps
);
90 HeapLock(HANDLE hHeap
)
92 /* Call the RTL API */
93 return RtlLockHeap(hHeap
);
101 HeapUnlock(HANDLE hHeap
)
103 /* Call the RTL API */
104 return RtlUnlockHeap(hHeap
);
112 HeapCompact(HANDLE hHeap
, DWORD dwFlags
)
114 /* Call the RTL API */
115 return RtlCompactHeap(hHeap
, dwFlags
);
123 HeapValidate(HANDLE hHeap
,
127 /* Call the RTL API */
128 return RtlValidateHeap(hHeap
, dwFlags
, (PVOID
)lpMem
);
136 HeapCreateTagsW(HANDLE hHeap
,
141 /* Call the RTL API */
142 return RtlCreateTagHeap(hHeap
,
153 HeapExtend(HANDLE hHeap
,
160 /* Call the RTL API. Gone in Vista, so commented out. */
161 Status
= STATUS_NOT_IMPLEMENTED
; //RtlExtendHeap(hHeap, dwFlags, BaseAddress, dwBytes);
162 if (!NT_SUCCESS(Status
))
165 SetLastErrorByStatus(Status
);
178 HeapQueryTagW(HANDLE hHeap
,
184 /* Call the RTL API */
185 return RtlQueryTagHeap(hHeap
,
188 (BOOLEAN
)bResetCounters
,
197 HeapSummary(HANDLE hHeap
,
202 RTL_HEAP_USAGE Usage
;
204 /* Fill in the length information */
205 Usage
.Length
= sizeof(Usage
);
207 /* Call RTL. Gone in Vista, so commented out */
208 Status
= STATUS_NOT_IMPLEMENTED
; //RtlUsageHeap(hHeap, dwFlags, &Usage);
209 if (!NT_SUCCESS(Status
))
212 SetLastErrorByStatus(Status
);
216 /* FIXME: Summary == Usage?! */
217 RtlCopyMemory(Summary
, &Usage
, sizeof(Usage
));
226 HeapUsage(HANDLE hHeap
,
234 /* Call RTL. Gone in Vista, so commented out */
235 Status
= STATUS_NOT_IMPLEMENTED
; //RtlUsageHeap(hHeap, dwFlags, &Usage);
236 if (!NT_SUCCESS(Status
))
239 SetLastErrorByStatus(Status
);
242 else if (Status
== STATUS_MORE_ENTRIES
)
244 /* There are still more entries to parse */
248 /* Otherwise, we're completely done, so we return FALSE, but NO_ERROR */
249 SetLastError(NO_ERROR
);
258 HeapWalk(HANDLE hHeap
,
259 LPPROCESS_HEAP_ENTRY lpEntry
)
261 /* Not implemented */
262 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);