xref: /reactos/sdk/include/ucrt/crtdbg.h (revision 589bbcaa)
1 //
2 // crtdbg.h
3 //
4 //      Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // Public debugging facilities for the CRT
7 //
8 #pragma once
9 #ifndef _INC_CRTDBG // include guard for 3rd party interop
10 #define _INC_CRTDBG
11 
12 #include <corecrt.h>
13 #include <vcruntime_new_debug.h>
14 #include <intrin.h> // for __debugbreak() on GCC
15 
16 #pragma warning(push)
17 #pragma warning(disable: _UCRT_DISABLED_WARNINGS)
18 _UCRT_DISABLE_CLANG_WARNINGS
19 
20 _CRT_BEGIN_C_HEADER
21 
22 
23 
24 typedef void* _HFILE; // file handle pointer
25 
26 #define _CRT_WARN           0
27 #define _CRT_ERROR          1
28 #define _CRT_ASSERT         2
29 #define _CRT_ERRCNT         3
30 
31 #define _CRTDBG_MODE_FILE      0x1
32 #define _CRTDBG_MODE_DEBUG     0x2
33 #define _CRTDBG_MODE_WNDW      0x4
34 #define _CRTDBG_REPORT_MODE    -1
35 
36 #define _CRTDBG_INVALID_HFILE ((_HFILE)(intptr_t)-1)
37 #define _CRTDBG_HFILE_ERROR   ((_HFILE)(intptr_t)-2)
38 #define _CRTDBG_FILE_STDOUT   ((_HFILE)(intptr_t)-4)
39 #define _CRTDBG_FILE_STDERR   ((_HFILE)(intptr_t)-5)
40 #define _CRTDBG_REPORT_FILE   ((_HFILE)(intptr_t)-6)
41 
42 
43 
44 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
45 //
46 // Client-defined reporting and allocation hooks
47 //
48 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
49 
50 typedef int (__CRTDECL* _CRT_REPORT_HOOK )(int, char*,    int*);
51 typedef int (__CRTDECL* _CRT_REPORT_HOOKW)(int, wchar_t*, int*);
52 
53 #define _CRT_RPTHOOK_INSTALL  0
54 #define _CRT_RPTHOOK_REMOVE   1
55 
56 
57 typedef int (__CRTDECL* _CRT_ALLOC_HOOK)(int, void*, size_t, int, long, unsigned char const*, int);
58 
59 #ifdef _M_CEE
60     typedef int (__clrcall* _CRT_ALLOC_HOOK_M)(int, void*, size_t, int, long, unsigned char const*, int);
61 #endif
62 
63 #define _HOOK_ALLOC     1
64 #define _HOOK_REALLOC   2
65 #define _HOOK_FREE      3
66 
67 
68 
69 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 //
71 // Memory Management and State Tracking
72 //
73 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 
75 // Bit values for _crtDbgFlag flag. These bitflags control debug heap behavior.
76 #define _CRTDBG_ALLOC_MEM_DF        0x01  // Turn on debug allocation
77 #define _CRTDBG_DELAY_FREE_MEM_DF   0x02  // Don't actually free memory
78 #define _CRTDBG_CHECK_ALWAYS_DF     0x04  // Check heap every alloc/dealloc
79 #define _CRTDBG_RESERVED_DF         0x08  // Reserved - do not use
80 #define _CRTDBG_CHECK_CRT_DF        0x10  // Leak check/diff CRT blocks
81 #define _CRTDBG_LEAK_CHECK_DF       0x20  // Leak check at program exit
82 
83 // Some bit values for _crtDbgFlag which correspond to frequencies for checking
84 // the heap.
85 #define _CRTDBG_CHECK_EVERY_16_DF   0x00100000 // Check heap every 16 heap ops
86 #define _CRTDBG_CHECK_EVERY_128_DF  0x00800000 // Check heap every 128 heap ops
87 #define _CRTDBG_CHECK_EVERY_1024_DF 0x04000000 // Check heap every 1024 heap ops
88 
89 // We do not check the heap by default at this point because the cost was too
90 // high for some applications. You can still turn this feature on manually.
91 #define _CRTDBG_CHECK_DEFAULT_DF    0
92 
93 #define _CRTDBG_REPORT_FLAG         -1 // Query bitflag status
94 
95 #define _BLOCK_TYPE(block)          (block & 0xFFFF)
96 #define _BLOCK_SUBTYPE(block)       (block >> 16 & 0xFFFF)
97 
98 // Memory block identification
99 #define _FREE_BLOCK      0
100 #define _NORMAL_BLOCK    1
101 #define _CRT_BLOCK       2
102 #define _IGNORE_BLOCK    3
103 #define _CLIENT_BLOCK    4
104 #define _MAX_BLOCKS      5
105 
106 // _UNKNOWN_BLOCK is a sentinel value that may be passed to some functions that
107 // expect a block type as an argument.  If this value is passed, those functions
108 // will use the block type specified in the block header instead.  This is used
109 // in cases where the heap lock cannot be acquired to compute the block type
110 // before calling the function (e.g. when the caller is outside of the CoreCRT).
111 #define _UNKNOWN_BLOCK (-1)
112 
113 typedef void (__CRTDECL* _CRT_DUMP_CLIENT)(void*, size_t);
114 
115 #ifdef _M_CEE
116     typedef void (__clrcall* _CRT_DUMP_CLIENT_M)(void*, size_t);
117 #endif
118 
119 struct _CrtMemBlockHeader;
120 
121 typedef struct _CrtMemState
122 {
123     struct _CrtMemBlockHeader* pBlockHeader;
124     size_t lCounts[_MAX_BLOCKS];
125     size_t lSizes[_MAX_BLOCKS];
126     size_t lHighWaterCount;
127     size_t lTotalCount;
128 } _CrtMemState;
129 
130 #ifndef _DEBUG
131 
132     #define _CrtGetAllocHook()                  ((_CRT_ALLOC_HOOK)0)
133     #define _CrtSetAllocHook(f)                 ((_CRT_ALLOC_HOOK)0)
134 
135     #define _CrtGetDumpClient()                 ((_CRT_DUMP_CLIENT)0)
136     #define _CrtSetDumpClient(f)                ((_CRT_DUMP_CLIENT)0)
137 
138     #define _CrtCheckMemory()                   ((int)1)
139     #define _CrtDoForAllClientObjects(f, c)     ((void)0)
140     #define _CrtDumpMemoryLeaks()               ((int)0)
141     #define _CrtIsMemoryBlock(p, t, r, f, l)    ((int)1)
142     #define _CrtIsValidHeapPointer(p)           ((int)1)
143     #define _CrtIsValidPointer(p, n, r)         ((int)1)
144     #define _CrtMemCheckpoint(s)                ((void)0)
145     #define _CrtMemDifference(s1, s2, s3)       ((int)0)
146     #define _CrtMemDumpAllObjectsSince(s)       ((void)0)
147     #define _CrtMemDumpStatistics(s)            ((void)0)
148     #define _CrtReportBlockType(p)              ((int)-1)
149     #define _CrtSetBreakAlloc(a)                ((long)0)
150     #define _CrtSetDbgFlag(f)                   ((int)0)
151 
152 
153 #else // ^^^ !_DEBUG ^^^ // vvv _DEBUG vvv //
154 
155     #ifndef _M_CEE_PURE
156 
157         _ACRTIMP int*  __cdecl __p__crtDbgFlag(void);
158         _ACRTIMP long* __cdecl __p__crtBreakAlloc(void);
159 
160         #define _crtDbgFlag    (*__p__crtDbgFlag())
161         #define _crtBreakAlloc (*__p__crtBreakAlloc())
162 
163         _ACRTIMP _CRT_ALLOC_HOOK __cdecl _CrtGetAllocHook(void);
164 
165         _ACRTIMP _CRT_ALLOC_HOOK __cdecl _CrtSetAllocHook(
166             _In_opt_ _CRT_ALLOC_HOOK _PfnNewHook
167             );
168 
169         _ACRTIMP _CRT_DUMP_CLIENT __cdecl _CrtGetDumpClient(void);
170 
171         _ACRTIMP _CRT_DUMP_CLIENT __cdecl _CrtSetDumpClient(
172             _In_opt_ _CRT_DUMP_CLIENT _PFnNewDump
173             );
174 
175     #endif // _M_CEE_PURE
176 
177     _ACRTIMP int __cdecl _CrtCheckMemory(void);
178 
179     typedef void (__cdecl* _CrtDoForAllClientObjectsCallback)(void*, void*);
180 
181     _ACRTIMP void __cdecl _CrtDoForAllClientObjects(
182         _In_ _CrtDoForAllClientObjectsCallback _Callback,
183         _In_ void*                             _Context
184         );
185 
186     _ACRTIMP int __cdecl _CrtDumpMemoryLeaks(void);
187 
188     _ACRTIMP int __cdecl _CrtIsMemoryBlock(
189         _In_opt_  void const*  _Block,
190         _In_      unsigned int _Size,
191         _Out_opt_ long*        _RequestNumber,
192         _Out_opt_ char**       _FileName,
193         _Out_opt_ int*         _LineNumber
194         );
195 
196     _Check_return_
197     _ACRTIMP int __cdecl _CrtIsValidHeapPointer(
198         _In_opt_ void const* _Pointer
199         );
200 
201     _Check_return_
202     _ACRTIMP int __cdecl _CrtIsValidPointer(
203         _In_opt_ void const*  _Pointer,
204         _In_     unsigned int _Size,
205         _In_     int          _ReadWrite
206         );
207 
208     _ACRTIMP void __cdecl _CrtMemCheckpoint(
209         _Out_ _CrtMemState* _State
210         );
211 
212     _ACRTIMP int __cdecl _CrtMemDifference(
213         _Out_ _CrtMemState*       _State,
214         _In_  _CrtMemState const* _OldState,
215         _In_  _CrtMemState const* _NewState
216         );
217 
218     _ACRTIMP void __cdecl _CrtMemDumpAllObjectsSince(
219         _In_opt_ _CrtMemState const* _State
220         );
221 
222     _ACRTIMP void __cdecl _CrtMemDumpStatistics(
223         _In_ _CrtMemState const* _State
224         );
225 
226     _Check_return_
227     _ACRTIMP int __cdecl _CrtReportBlockType(
228         _In_opt_ void const* _Block
229         );
230 
231     _ACRTIMP long __cdecl _CrtSetBreakAlloc(
232         _In_ long _NewValue
233         );
234 
235     _ACRTIMP int __cdecl _CrtSetDbgFlag(
236         _In_ int _NewFlag
237         );
238 
239 #endif // _DEBUG
240 
241 
242 
243 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
244 //
245 // Debug Heap Routines
246 //
247 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
248 #ifndef _DEBUG
249 
250     #define _calloc_dbg(c, s, t, f, l)      calloc(c, s)
251     #define _expand_dbg(p, s, t, f, l)      _expand(p, s)
252     #define _free_dbg(p, t)                 free(p)
253     #define _malloc_dbg(s, t, f, l)         malloc(s)
254     #define _msize_dbg(p, t)                _msize(p)
255     #define _realloc_dbg(p, s, t, f, l)     realloc(p, s)
256     #define _recalloc_dbg(p, c, s, t, f, l) _recalloc(p, c, s)
257 
258     #define _aligned_free_dbg(p)                              _aligned_free(p)
259     #define _aligned_malloc_dbg(s, a, f, l)                   _aligned_malloc(s, a)
260     #define _aligned_msize_dbg(p, a, o)                       _aligned_msize(p, a, o)
261     #define _aligned_offset_malloc_dbg(s, a, o, f, l)         _aligned_offset_malloc(s, a, o)
262     #define _aligned_offset_realloc_dbg(p, s, a, o, f, l)     _aligned_offset_realloc(p, s, a, o)
263     #define _aligned_offset_recalloc_dbg(p, c, s, a, o, f, l) _aligned_offset_recalloc(p, c, s, a, o)
264     #define _aligned_realloc_dbg(p, s, a, f, l)               _aligned_realloc(p, s, a)
265     #define _aligned_recalloc_dbg(p, c, s, a, f, l)           _aligned_recalloc(p, c, s, a)
266 
267     #define _freea_dbg(p, t)         _freea(p)
268     #define _malloca_dbg(s, t, f, l) _malloca(s)
269 
270     #define _dupenv_s_dbg(ps1, size, s2, t, f, l)  _dupenv_s(ps1, size, s2)
271     #define _fullpath_dbg(s1, s2, le, t, f, l)     _fullpath(s1, s2, le)
272     #define _getcwd_dbg(s, le, t, f, l)            _getcwd(s, le)
273     #define _getdcwd_dbg(d, s, le, t, f, l)        _getdcwd(d, s, le)
274     #define _getdcwd_lk_dbg(d, s, le, t, f, l)     _getdcwd(d, s, le)
275     #define _mbsdup_dbg(s, t, f, l)                _mbsdup(s)
276     #define _strdup_dbg(s, t, f, l)                _strdup(s)
277     #define _tempnam_dbg(s1, s2, t, f, l)          _tempnam(s1, s2)
278     #define _wcsdup_dbg(s, t, f, l)                _wcsdup(s)
279     #define _wdupenv_s_dbg(ps1, size, s2, t, f, l) _wdupenv_s(ps1, size, s2)
280     #define _wfullpath_dbg(s1, s2, le, t, f, l)    _wfullpath(s1, s2, le)
281     #define _wgetcwd_dbg(s, le, t, f, l)           _wgetcwd(s, le)
282     #define _wgetdcwd_dbg(d, s, le, t, f, l)       _wgetdcwd(d, s, le)
283     #define _wgetdcwd_lk_dbg(d, s, le, t, f, l)    _wgetdcwd(d, s, le)
284     #define _wtempnam_dbg(s1, s2, t, f, l)         _wtempnam(s1, s2)
285 
286 #else // ^^^ !_DEBUG ^^^ // vvv _DEBUG vvv //
287 
288     #ifdef _CRTDBG_MAP_ALLOC
289 
290         #define calloc(c, s)       _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
291         #define _expand(p, s)      _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
292         #define free(p)            _free_dbg(p, _NORMAL_BLOCK)
293         #define malloc(s)          _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
294         #define _msize(p)          _msize_dbg(p, _NORMAL_BLOCK)
295         #define realloc(p, s)      _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
296         #define _recalloc(p, c, s) _recalloc_dbg(p, c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
297 
298         #define _aligned_free(p)                        _aligned_free_dbg(p)
299         #define _aligned_malloc(s, a)                   _aligned_malloc_dbg(s, a, __FILE__, __LINE__)
300         #define _aligned_msize(p, a, o)                 _aligned_msize_dbg(p, a, o)
301         #define _aligned_offset_malloc(s, a, o)         _aligned_offset_malloc_dbg(s, a, o, __FILE__, __LINE__)
302         #define _aligned_offset_realloc(p, s, a, o)     _aligned_offset_realloc_dbg(p, s, a, o, __FILE__, __LINE__)
303         #define _aligned_offset_recalloc(p, c, s, a, o) _aligned_offset_recalloc_dbg(p, c, s, a, o, __FILE__, __LINE__)
304         #define _aligned_realloc(p, s, a)               _aligned_realloc_dbg(p, s, a, __FILE__, __LINE__)
305         #define _aligned_recalloc(p, c, s, a)           _aligned_recalloc_dbg(p, c, s, a, __FILE__, __LINE__)
306 
307         #define _freea(p)   _freea_dbg(p, _NORMAL_BLOCK)
308         #define _malloca(s) _malloca_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
309 
310         #define _dupenv_s(ps1, size, s2)  _dupenv_s_dbg(ps1, size, s2, _NORMAL_BLOCK, __FILE__, __LINE__)
311         #define _fullpath(s1, s2, le)     _fullpath_dbg(s1, s2, le, _NORMAL_BLOCK, __FILE__, __LINE__)
312         #define _getcwd(s, le)            _getcwd_dbg(s, le, _NORMAL_BLOCK, __FILE__, __LINE__)
313         #define _getdcwd(d, s, le)        _getdcwd_dbg(d, s, le, _NORMAL_BLOCK, __FILE__, __LINE__)
314         #define _mbsdup(s)                _strdup_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
315         #define _strdup(s)                _strdup_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
316         #define _tempnam(s1, s2)          _tempnam_dbg(s1, s2, _NORMAL_BLOCK, __FILE__, __LINE__)
317         #define _wcsdup(s)                _wcsdup_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
318         #define _wdupenv_s(ps1, size, s2) _wdupenv_s_dbg(ps1, size, s2, _NORMAL_BLOCK, __FILE__, __LINE__)
319         #define _wfullpath(s1, s2, le)    _wfullpath_dbg(s1, s2, le, _NORMAL_BLOCK, __FILE__, __LINE__)
320         #define _wgetcwd(s, le)           _wgetcwd_dbg(s, le, _NORMAL_BLOCK, __FILE__, __LINE__)
321         #define _wgetdcwd(d, s, le)       _wgetdcwd_dbg(d, s, le, _NORMAL_BLOCK, __FILE__, __LINE__)
322         #define _wtempnam(s1, s2)         _wtempnam_dbg(s1, s2, _NORMAL_BLOCK, __FILE__, __LINE__)
323 
324         #if defined(_CRT_INTERNAL_NONSTDC_NAMES) && _CRT_INTERNAL_NONSTDC_NAMES
325             #define   strdup(s)          _strdup_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
326             #define   wcsdup(s)          _wcsdup_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
327             #define   tempnam(s1, s2)    _tempnam_dbg(s1, s2, _NORMAL_BLOCK, __FILE__, __LINE__)
328             #define   getcwd(s, le)      _getcwd_dbg(s, le, _NORMAL_BLOCK, __FILE__, __LINE__)
329         #endif
330 
331     #endif // _CRTDBG_MAP_ALLOC
332 
333     _ACRTIMP void __cdecl _aligned_free_dbg(
334         _Pre_maybenull_ _Post_invalid_ void* _Block
335         );
336 
337     _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size)
338     _ACRTIMP _CRTALLOCATOR void* __cdecl _aligned_malloc_dbg(
339         _In_       size_t      _Size,
340         _In_       size_t      _Alignment,
341         _In_opt_z_ char const* _FileName,
342         _In_       int         _LineNumber
343         );
344 
345     _ACRTIMP size_t __cdecl _aligned_msize_dbg(
346         _Pre_notnull_ void*  _Block,
347         _In_          size_t _Alignment,
348         _In_          size_t _Offset
349         );
350 
351     _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size)
352     _ACRTIMP _CRTALLOCATOR void* __cdecl _aligned_offset_malloc_dbg(
353         _In_       size_t      _Size,
354         _In_       size_t      _Alignment,
355         _In_       size_t      _Offset,
356         _In_opt_z_ char const* _FileName,
357         _In_       int         _LineNumber
358         );
359 
360     _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size)
361     _ACRTIMP _CRTALLOCATOR void* __cdecl _aligned_offset_realloc_dbg(
362         _Pre_maybenull_ _Post_invalid_ void*       _Block,
363         _In_                           size_t      _Size,
364         _In_                           size_t      _Alignment,
365         _In_                           size_t      _Offset,
366         _In_opt_z_                     char const* _FileName,
367         _In_                           int         _LineNumber
368         );
369 
370     _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size)
371     _ACRTIMP _CRTALLOCATOR void* __cdecl _aligned_offset_recalloc_dbg(
372         _Pre_maybenull_ _Post_invalid_ void*       _Block,
373         _In_                           size_t      _Count,
374         _In_                           size_t      _Size,
375         _In_                           size_t      _Alignment,
376         _In_                           size_t      _Offset,
377         _In_opt_z_                     char const* _FileName,
378         _In_                           int         _LineNumber
379         );
380 
381     _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size)
382     _ACRTIMP _CRTALLOCATOR void* __cdecl _aligned_realloc_dbg(
383         _Pre_maybenull_ _Post_invalid_ void*       _Block,
384         _In_                           size_t      _Size,
385         _In_                           size_t      _Alignment,
386         _In_opt_z_                     char const* _FileName,
387         _In_                           int         _LineNumber
388         );
389 
390     _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size)
391     _ACRTIMP _CRTALLOCATOR void* __cdecl _aligned_recalloc_dbg(
392         _Pre_maybenull_ _Post_invalid_ void*       _Block,
393         _In_                           size_t      _Count,
394         _In_                           size_t      _Size,
395         _In_                           size_t      _Alignment,
396         _In_opt_z_                     char const* _FileName,
397         _In_                           int         _LineNumber
398         );
399 
400     _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size)
401     _ACRTIMP _CRTALLOCATOR void* __cdecl _calloc_dbg(
402         _In_       size_t      _Count,
403         _In_       size_t      _Size,
404         _In_       int         _BlockUse,
405         _In_opt_z_ char const* _FileName,
406         _In_       int         _LineNumber
407         );
408 
409     _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size)
410     _ACRTIMP _CRTALLOCATOR void* __cdecl _expand_dbg(
411         _Pre_notnull_ void*       _Block,
412         _In_          size_t      _Size,
413         _In_          int         _BlockUse,
414         _In_opt_z_    char const* _FileName,
415         _In_          int         _LineNumber
416         );
417 
418     _ACRTIMP void __cdecl _free_dbg(
419         _Pre_maybenull_ _Post_invalid_ void* _Block,
420         _In_                           int   _BlockUse
421         );
422 
423     _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size)
424     _ACRTIMP _CRTALLOCATOR void* __cdecl _malloc_dbg(
425         _In_       size_t      _Size,
426         _In_       int         _BlockUse,
427         _In_opt_z_ char const* _FileName,
428         _In_       int         _LineNumber
429         );
430 
431     _ACRTIMP size_t __cdecl _msize_dbg(
432         _Pre_notnull_ void* _Block,
433         _In_          int   _BlockUse
434         );
435 
436     _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Size)
437     _ACRTIMP _CRTALLOCATOR void* __cdecl _realloc_dbg(
438         _Pre_maybenull_ _Post_invalid_ void*       _Block,
439         _In_                           size_t      _Size,
440         _In_                           int         _BlockUse,
441         _In_opt_z_                     char const* _FileName,
442         _In_                           int         _LineNumber
443         );
444 
445     _Success_(return != 0) _Check_return_ _Ret_maybenull_ _Post_writable_byte_size_(_Count * _Size)
446     _ACRTIMP _CRTALLOCATOR void* __cdecl _recalloc_dbg(
447         _Pre_maybenull_ _Post_invalid_ void*       _Block,
448         _In_                           size_t      _Count,
449         _In_                           size_t      _Size,
450         _In_                           int         _BlockUse,
451         _In_opt_z_                     char const* _FileName,
452         _In_                           int         _LineNumber
453         );
454 
455     _Success_(return == 0)
456     _Check_return_wat_
457     _DCRTIMP errno_t __cdecl _dupenv_s_dbg(
458         _Outptr_result_buffer_maybenull_(*_PBufferSizeInBytes) char** _PBuffer,
459         _Out_opt_                      size_t*     _PBufferSizeInBytes,
460         _In_z_                         char const* _VarName,
461         _In_                           int          _BlockType,
462         _In_opt_z_                     char const* _FileName,
463         _In_                           int          _LineNumber
464         );
465 
466     _Success_(return != 0)
467     _Check_return_ _Ret_maybenull_z_
468     _ACRTIMP _CRTALLOCATOR char* __cdecl _fullpath_dbg(
469         _Out_writes_opt_z_(_SizeInBytes) char*       _FullPath,
470         _In_z_                           char const* _Path,
471         _In_                             size_t      _SizeInBytes,
472         _In_                             int         _BlockType,
473         _In_opt_z_                       char const* _FileName,
474         _In_                             int         _LineNumber
475         );
476 
477     _Success_(return != 0)
478     _Check_return_ _Ret_maybenull_z_
479     _DCRTIMP _CRTALLOCATOR char* __cdecl _getcwd_dbg(
480         _Out_writes_opt_z_(_SizeInBytes) char*       _DstBuf,
481         _In_                             int         _SizeInBytes,
482         _In_                             int         _BlockType,
483         _In_opt_z_                       char const* _FileName,
484         _In_                             int         _LineNumber
485         );
486 
487 
488     _Success_(return != 0)
489     _Check_return_ _Ret_maybenull_z_
490     _DCRTIMP _CRTALLOCATOR char* __cdecl _getdcwd_dbg(
491         _In_                             int         _Drive,
492         _Out_writes_opt_z_(_SizeInBytes) char*       _DstBuf,
493         _In_                             int         _SizeInBytes,
494         _In_                             int         _BlockType,
495         _In_opt_z_                       char const* _FileName,
496         _In_                             int         _LineNumber
497         );
498 
499     _Check_return_ _Ret_maybenull_z_
500     _ACRTIMP _CRTALLOCATOR char* __cdecl _strdup_dbg(
501         _In_opt_z_ char const* _String,
502         _In_       int         _BlockUse,
503         _In_opt_z_ char const* _FileName,
504         _In_       int         _LineNumber
505         );
506 
507     _Check_return_ _Ret_maybenull_z_
508     _ACRTIMP _CRTALLOCATOR char* __cdecl _tempnam_dbg(
509         _In_opt_z_ char const* _DirName,
510         _In_opt_z_ char const* _FilePrefix,
511         _In_       int         _BlockType,
512         _In_opt_z_ char const* _FileName,
513         _In_       int         _LineNumber
514         );
515 
516     _Success_(return != 0)
517     _Check_return_ _Ret_maybenull_z_
518     _ACRTIMP _CRTALLOCATOR wchar_t* __cdecl _wcsdup_dbg(
519         _In_opt_z_ wchar_t const* _String,
520         _In_       int            _BlockUse,
521         _In_opt_z_ char const*    _FileName,
522         _In_       int            _LineNumber
523         );
524 
525     _Success_(return == 0)
526     _Check_return_wat_
527     _DCRTIMP errno_t __cdecl _wdupenv_s_dbg(
528         _Outptr_result_buffer_maybenull_(*_PBufferSizeInWords) wchar_t** _PBuffer,
529         _Out_opt_                        size_t*         _PBufferSizeInWords,
530         _In_z_                           wchar_t const* _VarName,
531         _In_                             int             _BlockType,
532         _In_opt_z_                       char const*    _FileName,
533         _In_                             int             _LineNumber
534         );
535 
536     _Success_(return != 0)
537     _Check_return_ _Ret_maybenull_z_
538     _ACRTIMP _CRTALLOCATOR wchar_t* __cdecl _wfullpath_dbg(
539         _Out_writes_opt_z_(_SizeInWords) wchar_t*       _FullPath,
540         _In_z_                           wchar_t const* _Path,
541         _In_                             size_t         _SizeInWords,
542         _In_                             int            _BlockType,
543         _In_opt_z_                       char const*    _FileName,
544         _In_                             int            _LineNumber
545         );
546 
547     _Success_(return != 0)
548     _Check_return_ _Ret_maybenull_z_
549     _DCRTIMP _CRTALLOCATOR wchar_t* __cdecl _wgetcwd_dbg(
550         _Out_writes_opt_z_(_SizeInWords) wchar_t*    _DstBuf,
551         _In_                             int         _SizeInWords,
552         _In_                             int         _BlockType,
553         _In_opt_z_                       char const* _FileName,
554         _In_                             int         _LineNumber
555         );
556 
557     _Success_(return != 0)
558     _Check_return_ _Ret_maybenull_z_
559     _DCRTIMP _CRTALLOCATOR wchar_t* __cdecl _wgetdcwd_dbg(
560         _In_                             int         _Drive,
561         _Out_writes_opt_z_(_SizeInWords) wchar_t*    _DstBuf,
562         _In_                             int         _SizeInWords,
563         _In_                             int         _BlockType,
564         _In_opt_z_                       char const* _FileName,
565         _In_                             int         _LineNumber
566         );
567 
568     _Check_return_ _Ret_maybenull_z_
569     _ACRTIMP _CRTALLOCATOR wchar_t* __cdecl _wtempnam_dbg(
570         _In_opt_z_ wchar_t const* _DirName,
571         _In_opt_z_ wchar_t const* _FilePrefix,
572         _In_       int            _BlockType,
573         _In_opt_z_ char const*    _FileName,
574         _In_       int            _LineNumber
575         );
576 
577     #define _malloca_dbg(s, t, f, l) _malloc_dbg(s, t, f, l)
578     #define _freea_dbg(p, t)         _free_dbg(p, t)
579 
580     #if defined __cplusplus && defined _CRTDBG_MAP_ALLOC
581     namespace std
582     {
583         using ::_calloc_dbg;
584         using ::_free_dbg;
585         using ::_malloc_dbg;
586         using ::_realloc_dbg;
587     }
588     #endif
589 
590 #endif // _DEBUG
591 
592 
593 
594 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
595 //
596 // Debug Reporting
597 //
598 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
599 
600 #ifndef _DEBUG
601 
602     #define _CrtSetDebugFillThreshold(t)        ((size_t)0)
603     #define _CrtSetReportFile(t, f)             ((_HFILE)0)
604     #define _CrtSetReportMode(t, f)             ((int)0)
605     #define _CrtGetReportHook()                 ((_CRT_REPORT_HOOK)0)
606     #define _CrtSetReportHook(f)                ((_CRT_REPORT_HOOK)0)
607     #define _CrtSetReportHook2(t, f)            ((int)0)
608     #define _CrtSetReportHookW2(t, f)           ((int)0)
609 
610 #else // ^^^ !_DEBUG ^^^ // vvv _DEBUG vvv //
611 
612     _ACRTIMP int __cdecl _CrtDbgReport(
613         _In_       int         _ReportType,
614         _In_opt_z_ char const* _FileName,
615         _In_       int         _Linenumber,
616         _In_opt_z_ char const* _ModuleName,
617         _In_opt_z_ char const* _Format,
618         ...);
619 
620     _ACRTIMP int __cdecl _CrtDbgReportW(
621         _In_       int            _ReportType,
622         _In_opt_z_ wchar_t const* _FileName,
623         _In_       int            _LineNumber,
624         _In_opt_z_ wchar_t const* _ModuleName,
625         _In_opt_z_ wchar_t const* _Format,
626         ...);
627 
628 
629     _ACRTIMP int __cdecl _VCrtDbgReportA(
630         _In_       int         _ReportType,
631         _In_opt_   void*       _ReturnAddress,
632         _In_opt_z_ char const* _FileName,
633         _In_       int         _LineNumber,
634         _In_opt_z_ char const* _ModuleName,
635         _In_opt_z_ char const* _Format,
636                    va_list     _ArgList
637         );
638 
639     _ACRTIMP int __cdecl _VCrtDbgReportW(
640         _In_       int            _ReportType,
641         _In_opt_   void*          _ReturnAddress,
642         _In_opt_z_ wchar_t const* _FileName,
643         _In_       int            _LineNumber,
644         _In_opt_z_ wchar_t const* _ModuleName,
645         _In_opt_z_ wchar_t const* _Format,
646                    va_list        _ArgList
647         );
648 
649     _ACRTIMP size_t __cdecl _CrtSetDebugFillThreshold(
650         _In_ size_t _NewDebugFillThreshold
651         );
652 
653     _ACRTIMP size_t __cdecl _CrtGetDebugFillThreshold(void);
654 
655     _ACRTIMP _HFILE __cdecl _CrtSetReportFile(
656         _In_     int    _ReportType,
657         _In_opt_ _HFILE _ReportFile
658         );
659 
660     _ACRTIMP int __cdecl _CrtSetReportMode(
661         _In_ int _ReportType,
662         _In_ int _ReportMode
663         );
664 
665     #ifndef _M_CEE_PURE
666 
667         extern long _crtAssertBusy;
668 
669         _ACRTIMP _CRT_REPORT_HOOK __cdecl _CrtGetReportHook(void);
670 
671         // _CrtSetReportHook[[W]2]:
672         // For IJW, we need two versions:  one for clrcall and one for cdecl.
673         // For pure and native, we just need clrcall and cdecl, respectively.
674         _ACRTIMP _CRT_REPORT_HOOK __cdecl _CrtSetReportHook(
675             _In_opt_ _CRT_REPORT_HOOK _PFnNewHook
676             );
677 
678         _ACRTIMP int __cdecl _CrtSetReportHook2(
679             _In_     int              _Mode,
680             _In_opt_ _CRT_REPORT_HOOK _PFnNewHook
681             );
682 
683         _ACRTIMP int __cdecl _CrtSetReportHookW2(
684             _In_     int               _Mode,
685             _In_opt_ _CRT_REPORT_HOOKW _PFnNewHook
686             );
687 
688     #endif // !_M_CEE_PURE
689 
690 #endif // _DEBUG
691 
692 
693 
694 
695 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
696 //
697 // Assertions and Error Reporting Macros
698 //
699 //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
700 #ifndef _DEBUG
701 
702     #define _CrtDbgBreak() ((void)0)
703 
704     #ifndef _ASSERT_EXPR
705         #define _ASSERT_EXPR(expr, msg) ((void)0)
706     #endif
707 
708     #ifndef _ASSERT
709         #define _ASSERT(expr) ((void)0)
710     #endif
711 
712     #ifndef _ASSERTE
713         #define _ASSERTE(expr) ((void)0)
714     #endif
715 
716     #define _RPT0(rptno, msg)
717     #define _RPTN(rptno, msg, ...)
718 
719     #define _RPTW0(rptno, msg)
720     #define _RPTWN(rptno, msg, ...)
721 
722     #define _RPTF0(rptno, msg)
723     #define _RPTFN(rptno, msg, ...)
724 
725     #define _RPTFW0(rptno, msg)
726     #define _RPTFWN(rptno, msg, ...)
727 
728 #else // ^^^ !_DEBUG ^^^ // vvv _DEBUG vvv //
729 
730     #define _CrtDbgBreak() __debugbreak()
731 
732     // !! is used to ensure that any overloaded operators used to evaluate expr
733     // do not end up at &&.
734     #ifndef _ASSERT_EXPR
735         #define _ASSERT_EXPR(expr, msg) \
736             (void)(                                                                                     \
737                 (!!(expr)) ||                                                                           \
738                 (1 != _CrtDbgReportW(_CRT_ASSERT, _CRT_WIDE(__FILE__), __LINE__, NULL, L"%ls", msg)) || \
739                 (_CrtDbgBreak(), 0)                                                                     \
740             )
741     #endif
742 
743     #ifndef _ASSERT
744         #define _ASSERT(expr) _ASSERT_EXPR((expr), NULL)
745     #endif
746 
747     #ifndef _ASSERTE
748         #define _ASSERTE(expr) _ASSERT_EXPR((expr), _CRT_WIDE(#expr))
749     #endif
750 
751     #define _RPT_BASE(...)                           \
752         (void) ((1 != _CrtDbgReport(__VA_ARGS__)) || \
753                 (_CrtDbgBreak(), 0))
754 
755     #define _RPT_BASE_W(...)                          \
756         (void) ((1 != _CrtDbgReportW(__VA_ARGS__)) || \
757                 (_CrtDbgBreak(), 0))
758 
759     #define _RPT0(rptno, msg)      _RPT_BASE(rptno, NULL, 0, NULL, "%s", msg)
760     #define _RPTN(rptno, msg, ...) _RPT_BASE(rptno, NULL, 0, NULL, msg, __VA_ARGS__)
761 
762     #define _RPTW0(rptno, msg)      _RPT_BASE_W(rptno, NULL, 0, NULL, L"%ls", msg)
763     #define _RPTWN(rptno, msg, ...) _RPT_BASE_W(rptno, NULL, 0, NULL, msg, __VA_ARGS__)
764 
765     #define _RPTF0(rptno, msg)      _RPT_BASE(rptno, __FILE__, __LINE__, NULL, "%s", msg)
766     #define _RPTFN(rptno, msg, ...) _RPT_BASE(rptno, __FILE__, __LINE__, NULL, msg, __VA_ARGS__)
767 
768     #define _RPTFW0(rptno, msg)      _RPT_BASE_W(rptno, _CRT_WIDE(__FILE__), __LINE__, NULL, L"%ls", msg)
769     #define _RPTFWN(rptno, msg, ...) _RPT_BASE_W(rptno, _CRT_WIDE(__FILE__), __LINE__, NULL, msg, __VA_ARGS__)
770 
771 #endif // _DEBUG
772 
773 // Asserts in debug.  Invokes Watson in both debug and release
774 #define _ASSERT_AND_INVOKE_WATSON(expr)                                              \
775     {                                                                                \
776         _ASSERTE((expr));                                                            \
777         if (!(expr))                                                                 \
778         {                                                                            \
779             _invoke_watson(_CRT_WIDE(#expr), __FUNCTIONW__, __FILEW__, __LINE__, 0); \
780         }                                                                            \
781     }
782 
783 // _ASSERT_BASE is provided only for backwards compatibility.
784 #ifndef _ASSERT_BASE
785     #define _ASSERT_BASE _ASSERT_EXPR
786 #endif
787 
788 #define _RPT1 _RPTN
789 #define _RPT2 _RPTN
790 #define _RPT3 _RPTN
791 #define _RPT4 _RPTN
792 #define _RPT5 _RPTN
793 
794 #define _RPTW1 _RPTWN
795 #define _RPTW2 _RPTWN
796 #define _RPTW3 _RPTWN
797 #define _RPTW4 _RPTWN
798 #define _RPTW5 _RPTWN
799 
800 #define _RPTF1 _RPTFN
801 #define _RPTF2 _RPTFN
802 #define _RPTF3 _RPTFN
803 #define _RPTF4 _RPTFN
804 #define _RPTF5 _RPTFN
805 
806 #define _RPTFW1 _RPTFWN
807 #define _RPTFW2 _RPTFWN
808 #define _RPTFW3 _RPTFWN
809 #define _RPTFW4 _RPTFWN
810 #define _RPTFW5 _RPTFWN
811 
812 
813 
814 _CRT_END_C_HEADER
815 _UCRT_RESTORE_CLANG_WARNINGS
816 #pragma warning(pop) // _UCRT_DISABLED_WARNINGS
817 #endif // _INC_CRTDBG
818