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