Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

685 lines
18 KiB

  1. /***
  2. *crtdbg.h - Supports debugging features of the C runtime library.
  3. *
  4. * Copyright (c) 1994-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Support CRT debugging features.
  8. *
  9. * [Public]
  10. *
  11. ****/
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif
  15. #ifndef _INC_CRTDBG
  16. #define _INC_CRTDBG
  17. #if !defined(_WIN32)
  18. #error ERROR: Only Win32 target supported!
  19. #endif
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif /* __cplusplus */
  23. /****************************************************************************
  24. *
  25. * Constants and types
  26. *
  27. ***************************************************************************/
  28. #if !defined(_W64)
  29. #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
  30. #define _W64 __w64
  31. #else
  32. #define _W64
  33. #endif
  34. #endif
  35. #ifndef _SIZE_T_DEFINED
  36. #ifdef _WIN64
  37. typedef unsigned __int64 size_t;
  38. #else
  39. typedef _W64 unsigned int size_t;
  40. #endif
  41. #define _SIZE_T_DEFINED
  42. #endif
  43. /* Define NULL pointer value */
  44. #ifndef NULL
  45. #ifdef __cplusplus
  46. #define NULL 0
  47. #else
  48. #define NULL ((void *)0)
  49. #endif
  50. #endif
  51. /****************************************************************************
  52. *
  53. * Debug Reporting
  54. *
  55. ***************************************************************************/
  56. typedef void *_HFILE; /* file handle pointer */
  57. #define _CRT_WARN 0
  58. #define _CRT_ERROR 1
  59. #define _CRT_ASSERT 2
  60. #define _CRT_ERRCNT 3
  61. #define _CRTDBG_MODE_FILE 0x1
  62. #define _CRTDBG_MODE_DEBUG 0x2
  63. #define _CRTDBG_MODE_WNDW 0x4
  64. #define _CRTDBG_REPORT_MODE -1
  65. #define _CRTDBG_INVALID_HFILE ((_HFILE)-1)
  66. #define _CRTDBG_HFILE_ERROR ((_HFILE)-2)
  67. #define _CRTDBG_FILE_STDOUT ((_HFILE)-4)
  68. #define _CRTDBG_FILE_STDERR ((_HFILE)-5)
  69. #define _CRTDBG_REPORT_FILE ((_HFILE)-6)
  70. typedef int (__cdecl * _CRT_REPORT_HOOK)(int, char *, int *);
  71. #define _CRT_RPTHOOK_INSTALL 0
  72. #define _CRT_RPTHOOK_REMOVE 1
  73. /****************************************************************************
  74. *
  75. * Heap
  76. *
  77. ***************************************************************************/
  78. /****************************************************************************
  79. *
  80. * Client-defined allocation hook
  81. *
  82. ***************************************************************************/
  83. #define _HOOK_ALLOC 1
  84. #define _HOOK_REALLOC 2
  85. #define _HOOK_FREE 3
  86. typedef int (__cdecl * _CRT_ALLOC_HOOK)(int, void *, size_t, int, long, const unsigned char *, int);
  87. /****************************************************************************
  88. *
  89. * Memory management
  90. *
  91. ***************************************************************************/
  92. /*
  93. * Bit values for _crtDbgFlag flag:
  94. *
  95. * These bitflags control debug heap behavior.
  96. */
  97. #define _CRTDBG_ALLOC_MEM_DF 0x01 /* Turn on debug allocation */
  98. #define _CRTDBG_DELAY_FREE_MEM_DF 0x02 /* Don't actually free memory */
  99. #define _CRTDBG_CHECK_ALWAYS_DF 0x04 /* Check heap every alloc/dealloc */
  100. #define _CRTDBG_RESERVED_DF 0x08 /* Reserved - do not use */
  101. #define _CRTDBG_CHECK_CRT_DF 0x10 /* Leak check/diff CRT blocks */
  102. #define _CRTDBG_LEAK_CHECK_DF 0x20 /* Leak check at program exit */
  103. /*
  104. * Some bit values for _crtDbgFlag which correspond to frequencies for checking
  105. * the the heap.
  106. */
  107. #define _CRTDBG_CHECK_EVERY_16_DF 0x00100000 /* check heap every 16 heap ops */
  108. #define _CRTDBG_CHECK_EVERY_128_DF 0x00800000 /* check heap every 128 heap ops */
  109. #define _CRTDBG_CHECK_EVERY_1024_DF 0x04000000 /* check heap every 1024 heap ops */
  110. #define _CRTDBG_CHECK_DEFAULT_DF _CRTDBG_CHECK_EVERY_1024_DF
  111. #define _CRTDBG_REPORT_FLAG -1 /* Query bitflag status */
  112. #define _BLOCK_TYPE(block) (block & 0xFFFF)
  113. #define _BLOCK_SUBTYPE(block) (block >> 16 & 0xFFFF)
  114. /****************************************************************************
  115. *
  116. * Memory state
  117. *
  118. ***************************************************************************/
  119. /* Memory block identification */
  120. #define _FREE_BLOCK 0
  121. #define _NORMAL_BLOCK 1
  122. #define _CRT_BLOCK 2
  123. #define _IGNORE_BLOCK 3
  124. #define _CLIENT_BLOCK 4
  125. #define _MAX_BLOCKS 5
  126. typedef void (__cdecl * _CRT_DUMP_CLIENT)(void *, size_t);
  127. struct _CrtMemBlockHeader;
  128. typedef struct _CrtMemState
  129. {
  130. struct _CrtMemBlockHeader * pBlockHeader;
  131. size_t lCounts[_MAX_BLOCKS];
  132. size_t lSizes[_MAX_BLOCKS];
  133. size_t lHighWaterCount;
  134. size_t lTotalCount;
  135. } _CrtMemState;
  136. /****************************************************************************
  137. *
  138. * Declarations, prototype and function-like macros
  139. *
  140. ***************************************************************************/
  141. #ifndef _DEBUG
  142. /****************************************************************************
  143. *
  144. * Debug OFF
  145. * Debug OFF
  146. * Debug OFF
  147. *
  148. ***************************************************************************/
  149. #define _ASSERT(expr) ((void)0)
  150. #define _ASSERTE(expr) ((void)0)
  151. #define _RPT0(rptno, msg)
  152. #define _RPT1(rptno, msg, arg1)
  153. #define _RPT2(rptno, msg, arg1, arg2)
  154. #define _RPT3(rptno, msg, arg1, arg2, arg3)
  155. #define _RPT4(rptno, msg, arg1, arg2, arg3, arg4)
  156. #define _RPTF0(rptno, msg)
  157. #define _RPTF1(rptno, msg, arg1)
  158. #define _RPTF2(rptno, msg, arg1, arg2)
  159. #define _RPTF3(rptno, msg, arg1, arg2, arg3)
  160. #define _RPTF4(rptno, msg, arg1, arg2, arg3, arg4)
  161. #define _malloc_dbg(s, t, f, l) malloc(s)
  162. #define _calloc_dbg(c, s, t, f, l) calloc(c, s)
  163. #define _realloc_dbg(p, s, t, f, l) realloc(p, s)
  164. #define _expand_dbg(p, s, t, f, l) _expand(p, s)
  165. #define _free_dbg(p, t) free(p)
  166. #define _msize_dbg(p, t) _msize(p)
  167. #define _aligned_malloc_dbg(s, a, f, l) _aligned_malloc(s, a)
  168. #define _aligned_realloc_dbg(p, s, a, f, l) _aligned_realloc(p, s, a)
  169. #define _aligned_free_dbg(p) _aligned_free(p)
  170. #define _aligned_offset_malloc_dbg(s, a, o, f, l) _aligned_offset_malloc(s, a, o)
  171. #define _aligned_offset_realloc_dbg(p, s, a, o, f, l) _aligned_offset_realloc(p, s, a, o)
  172. #define _CrtSetReportHook(f) ((_CRT_REPORT_HOOK)0)
  173. #define _CrtSetReportHook2(t, f) ((int)0)
  174. #define _CrtSetReportMode(t, f) ((int)0)
  175. #define _CrtSetReportFile(t, f) ((_HFILE)0)
  176. #define _CrtDbgBreak() ((void)0)
  177. #define _CrtSetBreakAlloc(a) ((long)0)
  178. #define _CrtSetAllocHook(f) ((_CRT_ALLOC_HOOK)0)
  179. #define _CrtCheckMemory() ((int)1)
  180. #define _CrtSetDbgFlag(f) ((int)0)
  181. #define _CrtDoForAllClientObjects(f, c) ((void)0)
  182. #define _CrtIsValidPointer(p, n, r) ((int)1)
  183. #define _CrtIsValidHeapPointer(p) ((int)1)
  184. #define _CrtIsMemoryBlock(p, t, r, f, l) ((int)1)
  185. #define _CrtReportBlockType(p) ((int)-1)
  186. #define _CrtSetDumpClient(f) ((_CRT_DUMP_CLIENT)0)
  187. #define _CrtMemCheckpoint(s) ((void)0)
  188. #define _CrtMemDifference(s1, s2, s3) ((int)0)
  189. #define _CrtMemDumpAllObjectsSince(s) ((void)0)
  190. #define _CrtMemDumpStatistics(s) ((void)0)
  191. #define _CrtDumpMemoryLeaks() ((int)0)
  192. #else /* _DEBUG */
  193. /****************************************************************************
  194. *
  195. * Debug ON
  196. * Debug ON
  197. * Debug ON
  198. *
  199. ***************************************************************************/
  200. /* Define _CRTIMP */
  201. #ifndef _CRTIMP
  202. #ifdef _DLL
  203. #define _CRTIMP __declspec(dllimport)
  204. #else /* ndef _DLL */
  205. #define _CRTIMP
  206. #endif /* _DLL */
  207. #endif /* _CRTIMP */
  208. /****************************************************************************
  209. *
  210. * Debug Reporting
  211. *
  212. ***************************************************************************/
  213. _CRTIMP extern long _crtAssertBusy;
  214. _CRTIMP _CRT_REPORT_HOOK __cdecl _CrtSetReportHook(
  215. _CRT_REPORT_HOOK
  216. );
  217. _CRTIMP int __cdecl _CrtSetReportHook2(
  218. int,
  219. _CRT_REPORT_HOOK
  220. );
  221. _CRTIMP int __cdecl _CrtSetReportMode(
  222. int,
  223. int
  224. );
  225. _CRTIMP _HFILE __cdecl _CrtSetReportFile(
  226. int,
  227. _HFILE
  228. );
  229. _CRTIMP int __cdecl _CrtDbgReport(
  230. int,
  231. const char *,
  232. int,
  233. const char *,
  234. const char *,
  235. ...);
  236. /* Asserts */
  237. #if _MSC_VER >= 1300 || !defined(_M_IX86) || defined(_CRT_PORTABLE)
  238. #define _ASSERT_BASE(expr, msg) \
  239. (void) ((expr) || \
  240. (1 != _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, msg)) || \
  241. (_CrtDbgBreak(), 0))
  242. #else
  243. #define _ASSERT_BASE(expr, msg) \
  244. do { if (!(expr) && \
  245. (1 == _CrtDbgReport(_CRT_ASSERT, __FILE__, __LINE__, NULL, msg))) \
  246. _CrtDbgBreak(); } while (0)
  247. #endif
  248. #define _ASSERT(expr) _ASSERT_BASE((expr), NULL)
  249. #define _ASSERTE(expr) _ASSERT_BASE((expr), #expr)
  250. /* Reports with no file/line info */
  251. #if _MSC_VER >= 1300 || !defined(_M_IX86) || defined(_CRT_PORTABLE)
  252. #define _RPT_BASE(args) \
  253. (void) ((1 != _CrtDbgReport args) || \
  254. (_CrtDbgBreak(), 0))
  255. #else
  256. #define _RPT_BASE(args) \
  257. do { if ((1 == _CrtDbgReport args)) \
  258. _CrtDbgBreak(); } while (0)
  259. #endif
  260. #define _RPT0(rptno, msg) \
  261. _RPT_BASE((rptno, NULL, 0, NULL, "%s", msg))
  262. #define _RPT1(rptno, msg, arg1) \
  263. _RPT_BASE((rptno, NULL, 0, NULL, msg, arg1))
  264. #define _RPT2(rptno, msg, arg1, arg2) \
  265. _RPT_BASE((rptno, NULL, 0, NULL, msg, arg1, arg2))
  266. #define _RPT3(rptno, msg, arg1, arg2, arg3) \
  267. _RPT_BASE((rptno, NULL, 0, NULL, msg, arg1, arg2, arg3))
  268. #define _RPT4(rptno, msg, arg1, arg2, arg3, arg4) \
  269. _RPT_BASE((rptno, NULL, 0, NULL, msg, arg1, arg2, arg3, arg4))
  270. /* Reports with file/line info */
  271. #define _RPTF0(rptno, msg) \
  272. _RPT_BASE((rptno, __FILE__, __LINE__, NULL, "%s", msg))
  273. #define _RPTF1(rptno, msg, arg1) \
  274. _RPT_BASE((rptno, __FILE__, __LINE__, NULL, msg, arg1))
  275. #define _RPTF2(rptno, msg, arg1, arg2) \
  276. _RPT_BASE((rptno, __FILE__, __LINE__, NULL, msg, arg1, arg2))
  277. #define _RPTF3(rptno, msg, arg1, arg2, arg3) \
  278. _RPT_BASE((rptno, __FILE__, __LINE__, NULL, msg, arg1, arg2, arg3))
  279. #define _RPTF4(rptno, msg, arg1, arg2, arg3, arg4) \
  280. _RPT_BASE((rptno, __FILE__, __LINE__, NULL, msg, arg1, arg2, arg3, arg4))
  281. #if _MSC_VER >= 1300 && !defined(_CRT_PORTABLE)
  282. #define _CrtDbgBreak() __debugbreak()
  283. #elif defined(_M_IX86) && !defined(_CRT_PORTABLE)
  284. #define _CrtDbgBreak() __asm { int 3 }
  285. #elif defined(_M_IA64) && !defined(_CRT_PORTABLE)
  286. void __break(int);
  287. #pragma intrinsic (__break)
  288. #define _CrtDbgBreak() __break(0x80016)
  289. #else
  290. _CRTIMP void __cdecl _CrtDbgBreak(
  291. void
  292. );
  293. #endif
  294. /****************************************************************************
  295. *
  296. * Heap routines
  297. *
  298. ***************************************************************************/
  299. #ifdef _CRTDBG_MAP_ALLOC
  300. #define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
  301. #define calloc(c, s) _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  302. #define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  303. #define _expand(p, s) _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
  304. #define free(p) _free_dbg(p, _NORMAL_BLOCK)
  305. #define _msize(p) _msize_dbg(p, _NORMAL_BLOCK)
  306. #define _aligned_malloc(s, a) _aligned_malloc_dbg(s, a, __FILE__, __LINE__)
  307. #define _aligned_realloc(p, s, a) _aligned_realloc_dbg(p, s, a, __FILE__, __LINE__)
  308. #define _aligned_offset_malloc(s, a, o) _aligned_offset_malloc_dbg(s, a, o, __FILE__, __LINE__)
  309. #define _aligned_offset_realloc(p, s, a, o) _aligned_offset_realloc_dbg(p, s, a, o, __FILE__, __LINE__)
  310. #define _aligned_free(p) _aligned_free_dbg(p)
  311. #endif /* _CRTDBG_MAP_ALLOC */
  312. _CRTIMP extern long _crtBreakAlloc; /* Break on this allocation */
  313. _CRTIMP long __cdecl _CrtSetBreakAlloc(
  314. long
  315. );
  316. /*
  317. * Prototypes for malloc, free, realloc, etc are in malloc.h
  318. */
  319. _CRTIMP void * __cdecl _malloc_dbg(
  320. size_t,
  321. int,
  322. const char *,
  323. int
  324. );
  325. _CRTIMP void * __cdecl _calloc_dbg(
  326. size_t,
  327. size_t,
  328. int,
  329. const char *,
  330. int
  331. );
  332. _CRTIMP void * __cdecl _realloc_dbg(
  333. void *,
  334. size_t,
  335. int,
  336. const char *,
  337. int
  338. );
  339. _CRTIMP void * __cdecl _expand_dbg(
  340. void *,
  341. size_t,
  342. int,
  343. const char *,
  344. int
  345. );
  346. _CRTIMP void __cdecl _free_dbg(
  347. void *,
  348. int
  349. );
  350. _CRTIMP size_t __cdecl _msize_dbg (
  351. void *,
  352. int
  353. );
  354. _CRTIMP void * __cdecl _aligned_malloc_dbg(
  355. size_t,
  356. size_t,
  357. const char *,
  358. int
  359. );
  360. _CRTIMP void * __cdecl _aligned_realloc_dbg(
  361. void *,
  362. size_t,
  363. size_t,
  364. const char *,
  365. int
  366. );
  367. _CRTIMP void * __cdecl _aligned_offset_malloc_dbg(
  368. size_t,
  369. size_t,
  370. size_t,
  371. const char *,
  372. int
  373. );
  374. _CRTIMP void * __cdecl _aligned_offset_realloc_dbg(
  375. void *,
  376. size_t,
  377. size_t,
  378. size_t,
  379. const char *,
  380. int
  381. );
  382. _CRTIMP void __cdecl _aligned_free_dbg(
  383. void *
  384. );
  385. /****************************************************************************
  386. *
  387. * Client-defined allocation hook
  388. *
  389. ***************************************************************************/
  390. _CRTIMP _CRT_ALLOC_HOOK __cdecl _CrtSetAllocHook(
  391. _CRT_ALLOC_HOOK
  392. );
  393. /****************************************************************************
  394. *
  395. * Memory management
  396. *
  397. ***************************************************************************/
  398. /*
  399. * Bitfield flag that controls CRT heap behavior
  400. * Default setting is _CRTDBG_ALLOC_MEM_DF
  401. */
  402. _CRTIMP extern int _crtDbgFlag;
  403. _CRTIMP int __cdecl _CrtCheckMemory(
  404. void
  405. );
  406. _CRTIMP int __cdecl _CrtSetDbgFlag(
  407. int
  408. );
  409. _CRTIMP void __cdecl _CrtDoForAllClientObjects(
  410. void (*pfn)(void *, void *),
  411. void *
  412. );
  413. _CRTIMP int __cdecl _CrtIsValidPointer(
  414. const void *,
  415. unsigned int,
  416. int
  417. );
  418. _CRTIMP int __cdecl _CrtIsValidHeapPointer(
  419. const void *
  420. );
  421. _CRTIMP int __cdecl _CrtIsMemoryBlock(
  422. const void *,
  423. unsigned int,
  424. long *,
  425. char **,
  426. int *
  427. );
  428. _CRTIMP int __cdecl _CrtReportBlockType(
  429. const void *
  430. );
  431. /****************************************************************************
  432. *
  433. * Memory state
  434. *
  435. ***************************************************************************/
  436. _CRTIMP _CRT_DUMP_CLIENT __cdecl _CrtSetDumpClient(
  437. _CRT_DUMP_CLIENT
  438. );
  439. _CRTIMP void __cdecl _CrtMemCheckpoint(
  440. _CrtMemState *
  441. );
  442. _CRTIMP int __cdecl _CrtMemDifference(
  443. _CrtMemState *,
  444. const _CrtMemState *,
  445. const _CrtMemState *
  446. );
  447. _CRTIMP void __cdecl _CrtMemDumpAllObjectsSince(
  448. const _CrtMemState *
  449. );
  450. _CRTIMP void __cdecl _CrtMemDumpStatistics(
  451. const _CrtMemState *
  452. );
  453. _CRTIMP int __cdecl _CrtDumpMemoryLeaks(
  454. void
  455. );
  456. #endif /* _DEBUG */
  457. #ifdef __cplusplus
  458. }
  459. #ifndef _MFC_OVERRIDES_NEW
  460. extern "C++" {
  461. #pragma warning(disable: 4507) /* Ignore faulty warning */
  462. #ifndef _DEBUG
  463. /****************************************************************************
  464. *
  465. * Debug OFF
  466. * Debug OFF
  467. * Debug OFF
  468. *
  469. ***************************************************************************/
  470. void * __cdecl operator new[](size_t);
  471. inline void * __cdecl operator new(size_t s, int, const char *, int)
  472. { return ::operator new(s); }
  473. inline void* __cdecl operator new[](size_t s, int, const char *, int)
  474. { return ::operator new[](s); }
  475. #if _MSC_VER >= 1200
  476. void __cdecl operator delete[](void *);
  477. inline void __cdecl operator delete(void * _P, int, const char *, int)
  478. { ::operator delete(_P); }
  479. inline void __cdecl operator delete[](void * _P, int, const char *, int)
  480. { ::operator delete[](_P); }
  481. #endif
  482. #else /* _DEBUG */
  483. /****************************************************************************
  484. *
  485. * Debug ON
  486. * Debug ON
  487. * Debug ON
  488. *
  489. ***************************************************************************/
  490. void * __cdecl operator new[](size_t);
  491. void * __cdecl operator new(
  492. size_t,
  493. int,
  494. const char *,
  495. int
  496. );
  497. void * __cdecl operator new[](
  498. size_t,
  499. int,
  500. const char *,
  501. int
  502. );
  503. #if _MSC_VER >= 1200
  504. void __cdecl operator delete[](void *);
  505. inline void __cdecl operator delete(void * _P, int, const char *, int)
  506. { ::operator delete(_P); }
  507. inline void __cdecl operator delete[](void * _P, int, const char *, int)
  508. { ::operator delete[](_P); }
  509. #endif
  510. #ifdef _CRTDBG_MAP_ALLOC
  511. inline void * __cdecl operator new(size_t s)
  512. { return ::operator new(s, _NORMAL_BLOCK, __FILE__, __LINE__); }
  513. inline void* __cdecl operator new[](size_t s)
  514. { return ::operator new[](s, _NORMAL_BLOCK, __FILE__, __LINE__); }
  515. #endif /* _CRTDBG_MAP_ALLOC */
  516. #endif /* _DEBUG */
  517. }
  518. #endif /* _MFC_OVERRIDES_NEW */
  519. #endif /* __cplusplus */
  520. #endif /* _INC_CRTDBG */