Source code of Windows XP (NT5)
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.

333 lines
8.4 KiB

  1. /***
  2. *dbgint.h - Supports debugging features of the C runtime library.
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Support CRT debugging features.
  8. *
  9. * [Internal]
  10. *
  11. *Revision History:
  12. * 08-16-94 CFW Module created.
  13. * 11-28-94 CFW Add DumpClient.
  14. * 12-05-94 CFW Fix debug new handler support, clean up macros.
  15. * 12-06-94 CFW Export _CrtThrowMemoryException.
  16. * 12-08-94 CFW Export _assertfailed.
  17. * 01-05-95 CFW Asserts are errors, add report hook.
  18. * 01-05-95 CFW Filename pointers are const.
  19. * 01-10-95 CFW Lots moved to crtdbg.h
  20. * 01-11-95 CFW Add _xxxx_crt macros.
  21. * 01-13-95 CFW Add new() support.
  22. * 01-20-94 CFW Change unsigned chars to chars.
  23. * 02-14-95 CFW Clean up Mac merge.
  24. * 02-17-95 CFW new() proto moved to crtdbg.h.
  25. * 03-21-95 CFW Add _delete_crt.
  26. * 03-29-95 CFW Add error message to internal headers.
  27. * 03-21-95 CFW Remove _delete_crt, add _BLOCK_TYPE_IS_VALID.
  28. * 06-27-95 CFW Add win32s support for debug libs.
  29. * 12-14-95 JWM Add "#pragma once".
  30. * 04-17-96 JWM Make _CrtSetDbgBlockType() _CRTIMP (for msvcirtd.dll).
  31. * 02-05-97 GJF Removed use of obsolete DLL_FOR_WIN32S.
  32. * 01-04-00 GB Added support for debug version of _aligned routines.
  33. * 08-25-00 PML Reverse _CrtMemBlockHeader fields nDataSize and
  34. * nBlockUse on Win64 so size % 16 == 0 (vs7#153113).
  35. *
  36. ****/
  37. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  38. #pragma once
  39. #endif
  40. #ifndef _INC_DBGINT
  41. #define _INC_DBGINT
  42. #ifndef _CRTBLD
  43. /*
  44. * This is an internal C runtime header file. It is used when building
  45. * the C runtimes only. It is not to be used as a public header file.
  46. */
  47. #error ERROR: Use of C runtime library internal header file.
  48. #endif /* _CRTBLD */
  49. #include <crtdbg.h>
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif
  53. #ifndef _DEBUG
  54. /****************************************************************************
  55. *
  56. * Debug OFF
  57. * Debug OFF
  58. * Debug OFF
  59. *
  60. ***************************************************************************/
  61. #ifdef __cplusplus
  62. #define _new_crt new
  63. #endif /* __cplusplus */
  64. #define _malloc_crt malloc
  65. #define _calloc_crt calloc
  66. #define _realloc_crt realloc
  67. #define _expand_crt _expand
  68. #define _free_crt free
  69. #define _msize_crt _msize
  70. #define _malloc_base malloc
  71. #define _nh_malloc_base _nh_malloc
  72. #define _nh_malloc_dbg(s, n, t, f, l) _nh_malloc(s, n)
  73. #define _heap_alloc_base _heap_alloc
  74. #define _heap_alloc_dbg(s, t, f, l) _heap_alloc(s)
  75. #define _calloc_base calloc
  76. #define _realloc_base realloc
  77. #define _expand_base _expand
  78. #define _free_base free
  79. #define _msize_base _msize
  80. #define _aligned_malloc_base _aligned_malloc
  81. #define _aligned_realloc_base _aligned_realloc
  82. #define _aligned_offset_malloc_base _aligned_offset_malloc
  83. #define _aligned_offset_realloc_base _aligned_offset_realloc
  84. #define _aligned_free_base _aligned_free
  85. #ifdef _MT
  86. #define _calloc_dbg_lk(c, s, t, f, l) _calloc_lk(c, s)
  87. #define _realloc_dbg_lk(p, s, t, f, l) _realloc_lk(p, s)
  88. #define _free_base_lk _free_lk
  89. #define _free_dbg_lk(p, t) _free_lk(p)
  90. #else /* ndef _MT */
  91. #define _calloc_dbg_lk(c, s, t, f, l) calloc(c, s)
  92. #define _realloc_dbg_lk(p, s, t, f, l) realloc(p, s)
  93. #define _free_base_lk free
  94. #define _free_dbg_lk(p, t) free(p)
  95. #endif /* _MT */
  96. #else /* _DEBUG */
  97. /****************************************************************************
  98. *
  99. * Debug ON
  100. * Debug ON
  101. * Debug ON
  102. *
  103. ***************************************************************************/
  104. #define _THISFILE __FILE__
  105. #ifdef __cplusplus
  106. #define _new_crt new(_CRT_BLOCK, _THISFILE, __LINE__)
  107. #endif /* __cplusplus */
  108. #define _malloc_crt(s) _malloc_dbg(s, _CRT_BLOCK, _THISFILE, __LINE__)
  109. #define _calloc_crt(c, s) _calloc_dbg(c, s, _CRT_BLOCK, _THISFILE, __LINE__)
  110. #define _realloc_crt(p, s) _realloc_dbg(p, s, _CRT_BLOCK, _THISFILE, __LINE__)
  111. #define _expand_crt(p, s) _expand_dbg(p, s, _CRT_BLOCK)
  112. #define _free_crt(p) _free_dbg(p, _CRT_BLOCK)
  113. #define _msize_crt(p) _msize_dbg(p, _CRT_BLOCK)
  114. /*
  115. * Prototypes for malloc, free, realloc, etc are in malloc.h
  116. */
  117. void * __cdecl _malloc_base(
  118. size_t
  119. );
  120. void * __cdecl _nh_malloc_base (
  121. size_t,
  122. int
  123. );
  124. void * __cdecl _nh_malloc_dbg (
  125. size_t,
  126. int,
  127. int,
  128. const char *,
  129. int
  130. );
  131. void * __cdecl _heap_alloc_base(
  132. size_t
  133. );
  134. void * __cdecl _heap_alloc_dbg(
  135. size_t,
  136. int,
  137. const char *,
  138. int
  139. );
  140. void * __cdecl _calloc_base(
  141. size_t,
  142. size_t
  143. );
  144. void * __cdecl _realloc_base(
  145. void *,
  146. size_t
  147. );
  148. void * __cdecl _expand_base(
  149. void *,
  150. size_t
  151. );
  152. void __cdecl _free_base(
  153. void *
  154. );
  155. size_t __cdecl _msize_base (
  156. void *
  157. );
  158. void __cdecl _aligned_free_base(
  159. void *
  160. );
  161. void * __cdecl _aligned_malloc_base(
  162. size_t,
  163. size_t
  164. );
  165. void * __cdecl _aligned_offset_malloc_base(
  166. size_t,
  167. size_t,
  168. size_t
  169. );
  170. void * __cdecl _aligned_realloc_base(
  171. void *,
  172. size_t,
  173. size_t
  174. );
  175. void * __cdecl _aligned_offset_realloc_base(
  176. void *,
  177. size_t,
  178. size_t,
  179. size_t
  180. );
  181. #ifdef _MT
  182. /*
  183. * Prototypes and macros for multi-thread support
  184. */
  185. void * __cdecl _calloc_dbg_lk(
  186. size_t,
  187. size_t,
  188. int,
  189. char *,
  190. int
  191. );
  192. void * __cdecl _realloc_dbg_lk(
  193. void *,
  194. size_t,
  195. int,
  196. const char *,
  197. int
  198. );
  199. void __cdecl _free_base_lk(
  200. void *
  201. );
  202. void __cdecl _free_dbg_lk(
  203. void *,
  204. int
  205. );
  206. #else /* ndef _MT */
  207. #define _calloc_dbg_lk _calloc_dbg
  208. #define _realloc_dbg_lk _realloc_dbg
  209. #define _free_base_lk _free_base
  210. #define _free_dbg_lk _free_dbg
  211. #endif /* _MT */
  212. /*
  213. * For diagnostic purpose, blocks are allocated with extra information and
  214. * stored in a doubly-linked list. This makes all blocks registered with
  215. * how big they are, when they were allocated, and what they are used for.
  216. */
  217. #define nNoMansLandSize 4
  218. typedef struct _CrtMemBlockHeader
  219. {
  220. struct _CrtMemBlockHeader * pBlockHeaderNext;
  221. struct _CrtMemBlockHeader * pBlockHeaderPrev;
  222. char * szFileName;
  223. int nLine;
  224. #ifdef _WIN64
  225. /* These items are reversed on Win64 to eliminate gaps in the struct
  226. * and ensure that sizeof(struct)%16 == 0, so 16-byte alignment is
  227. * maintained in the debug heap.
  228. */
  229. int nBlockUse;
  230. size_t nDataSize;
  231. #else
  232. size_t nDataSize;
  233. int nBlockUse;
  234. #endif
  235. long lRequest;
  236. unsigned char gap[nNoMansLandSize];
  237. /* followed by:
  238. * unsigned char data[nDataSize];
  239. * unsigned char anotherGap[nNoMansLandSize];
  240. */
  241. } _CrtMemBlockHeader;
  242. #define pbData(pblock) ((unsigned char *)((_CrtMemBlockHeader *)pblock + 1))
  243. #define pHdr(pbData) (((_CrtMemBlockHeader *)pbData)-1)
  244. _CRTIMP void __cdecl _CrtSetDbgBlockType(
  245. void *,
  246. int
  247. );
  248. #define _BLOCK_TYPE_IS_VALID(use) (_BLOCK_TYPE(use) == _CLIENT_BLOCK || \
  249. (use) == _NORMAL_BLOCK || \
  250. _BLOCK_TYPE(use) == _CRT_BLOCK || \
  251. (use) == _IGNORE_BLOCK)
  252. extern _CRT_ALLOC_HOOK _pfnAllocHook; /* defined in dbghook.c */
  253. int __cdecl _CrtDefaultAllocHook(
  254. int,
  255. void *,
  256. size_t,
  257. int,
  258. long,
  259. const unsigned char *,
  260. int
  261. );
  262. #endif /* _DEBUG */
  263. #ifdef __cplusplus
  264. }
  265. #endif
  266. #endif /* _INC_DBGINT */