Reactos
1//
2// heap_handle.cpp
3//
4// Copyright (c) Microsoft Corporation. All rights reserved.
5//
6// Defines the global CRT heap handle and initialization/termination functions.
7//
8#include <corecrt_internal.h>
9#include <malloc.h>
10
11
12
13// The CRT heap handle. This global variable is modified only during CRT
14// startup and CRT shutdown.
15extern "C" { HANDLE __acrt_heap = nullptr; }
16
17
18
19// Initializes the heap. This function must be called during CRT startup, and
20// must be called before any user code that might use the heap is executed.
21extern "C" bool __cdecl __acrt_initialize_heap()
22{
23 __acrt_heap = GetProcessHeap();
24 if (__acrt_heap == nullptr)
25 return false;
26
27 return true;
28}
29
30// Uninitializes the heap. This function should be called during CRT shutdown,
31// after any user code that might use the heap has stopped running.
32extern "C" bool __cdecl __acrt_uninitialize_heap(bool const /* terminating */)
33{
34 __acrt_heap = nullptr;
35 return true;
36}
37
38// Gets the HANDLE of the CRT heap. Because the CRT always uses the process
39// heap, this function always returns the same thing as GetProcessHeap().
40extern "C" intptr_t __cdecl _get_heap_handle()
41{
42 _ASSERTE(__acrt_heap != nullptr);
43 return reinterpret_cast<intptr_t>(__acrt_heap);
44}
45
46// Internal CRT function to get the HANDLE of the CRT heap, that returns a
47// HANDLE instead of an intptr_t.
48extern "C" HANDLE __acrt_getheap()
49{
50 _ASSERTE(__acrt_heap != nullptr);
51 return __acrt_heap;
52}