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.

336 lines
8.9 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. * 12-11-01 BWT Change malloc/calloc/realloc_crt to retry a few times
  36. * before giving up.
  37. *
  38. ****/
  39. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  40. #pragma once
  41. #endif
  42. #ifndef _INC_DBGINT
  43. #define _INC_DBGINT
  44. #ifndef _CRTBLD
  45. /*
  46. * This is an internal C runtime header file. It is used when building
  47. * the C runtimes only. It is not to be used as a public header file.
  48. */
  49. #error ERROR: Use of C runtime library internal header file.
  50. #endif /* _CRTBLD */
  51. #include <crtdbg.h>
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. #ifndef _DEBUG
  56. /****************************************************************************
  57. *
  58. * Debug OFF
  59. * Debug OFF
  60. * Debug OFF
  61. *
  62. ***************************************************************************/
  63. #ifdef __cplusplus
  64. #define _new_crt new
  65. #endif /* __cplusplus */
  66. #define _expand_crt _expand
  67. #define _free_crt free
  68. #define _msize_crt _msize
  69. #if defined( _POSIX_) || defined(_NTSUBSET_)
  70. #define _malloc_crt malloc
  71. #define _calloc_crt calloc
  72. #define _realloc_crt realloc
  73. #else
  74. void * __fastcall _malloc_crt(size_t cb);
  75. void * __fastcall _calloc_crt(size_t count, size_t size);
  76. void * __fastcall _realloc_crt(void *ptr, size_t size);
  77. #endif
  78. #define _malloc_base malloc
  79. #define _nh_malloc_base _nh_malloc
  80. #define _nh_malloc_dbg(s, n, t, f, l) _nh_malloc(s, n)
  81. #define _heap_alloc_dbg(s, t, f, l) _heap_alloc(s)
  82. #define _calloc_base calloc
  83. #define _realloc_base realloc
  84. #define _expand_base _expand
  85. #define _free_base free
  86. #define _msize_base _msize
  87. #define _aligned_malloc_base _aligned_malloc
  88. #define _aligned_realloc_base _aligned_realloc
  89. #define _aligned_offset_malloc_base _aligned_offset_malloc
  90. #define _aligned_offset_realloc_base _aligned_offset_realloc
  91. #define _aligned_free_base _aligned_free
  92. #ifdef _MT
  93. #define _calloc_dbg_lk(c, s, t, f, l) _calloc_lk(c, s)
  94. #define _realloc_dbg_lk(p, s, t, f, l) _realloc_lk(p, s)
  95. #define _free_base_lk _free_lk
  96. #define _free_dbg_lk(p, t) _free_lk(p)
  97. #else /* ndef _MT */
  98. #define _calloc_dbg_lk(c, s, t, f, l) calloc(c, s)
  99. #define _realloc_dbg_lk(p, s, t, f, l) realloc(p, s)
  100. #define _free_base_lk free
  101. #define _free_dbg_lk(p, t) free(p)
  102. #endif /* _MT */
  103. #else /* _DEBUG */
  104. /****************************************************************************
  105. *
  106. * Debug ON
  107. * Debug ON
  108. * Debug ON
  109. *
  110. ***************************************************************************/
  111. #define _THISFILE __FILE__
  112. #ifdef __cplusplus
  113. #define _new_crt new(_CRT_BLOCK, _THISFILE, __LINE__)
  114. #endif /* __cplusplus */
  115. #define _malloc_crt(s) _malloc_dbg(s, _CRT_BLOCK, _THISFILE, __LINE__)
  116. #define _calloc_crt(c, s) _calloc_dbg(c, s, _CRT_BLOCK, _THISFILE, __LINE__)
  117. #define _realloc_crt(p, s) _realloc_dbg(p, s, _CRT_BLOCK, _THISFILE, __LINE__)
  118. #define _expand_crt(p, s) _expand_dbg(p, s, _CRT_BLOCK)
  119. #define _free_crt(p) _free_dbg(p, _CRT_BLOCK)
  120. #define _msize_crt(p) _msize_dbg(p, _CRT_BLOCK)
  121. /*
  122. * Prototypes for malloc, free, realloc, etc are in malloc.h
  123. */
  124. void * __cdecl _malloc_base(
  125. size_t
  126. );
  127. void * __cdecl _nh_malloc_base (
  128. size_t,
  129. int
  130. );
  131. void * __cdecl _nh_malloc_dbg (
  132. size_t,
  133. int,
  134. int,
  135. const char *,
  136. int
  137. );
  138. void * __cdecl _heap_alloc_dbg(
  139. size_t,
  140. int,
  141. const char *,
  142. int
  143. );
  144. void * __cdecl _calloc_base(
  145. size_t,
  146. size_t
  147. );
  148. void * __cdecl _realloc_base(
  149. void *,
  150. size_t
  151. );
  152. void * __cdecl _expand_base(
  153. void *,
  154. size_t
  155. );
  156. void __cdecl _free_base(
  157. void *
  158. );
  159. size_t __cdecl _msize_base (
  160. void *
  161. );
  162. void __cdecl _aligned_free_base(
  163. void *
  164. );
  165. void * __cdecl _aligned_malloc_base(
  166. size_t,
  167. size_t
  168. );
  169. void * __cdecl _aligned_offset_malloc_base(
  170. size_t,
  171. size_t,
  172. size_t
  173. );
  174. void * __cdecl _aligned_realloc_base(
  175. void *,
  176. size_t,
  177. size_t
  178. );
  179. void * __cdecl _aligned_offset_realloc_base(
  180. void *,
  181. size_t,
  182. size_t,
  183. size_t
  184. );
  185. #ifdef _MT
  186. /*
  187. * Prototypes and macros for multi-thread support
  188. */
  189. void * __cdecl _calloc_dbg_lk(
  190. size_t,
  191. size_t,
  192. int,
  193. char *,
  194. int
  195. );
  196. void * __cdecl _realloc_dbg_lk(
  197. void *,
  198. size_t,
  199. int,
  200. const char *,
  201. int
  202. );
  203. void __cdecl _free_base_lk(
  204. void *
  205. );
  206. void __cdecl _free_dbg_lk(
  207. void *,
  208. int
  209. );
  210. #else /* ndef _MT */
  211. #define _calloc_dbg_lk _calloc_dbg
  212. #define _realloc_dbg_lk _realloc_dbg
  213. #define _free_base_lk _free_base
  214. #define _free_dbg_lk _free_dbg
  215. #endif /* _MT */
  216. /*
  217. * For diagnostic purpose, blocks are allocated with extra information and
  218. * stored in a doubly-linked list. This makes all blocks registered with
  219. * how big they are, when they were allocated, and what they are used for.
  220. */
  221. #define nNoMansLandSize 4
  222. typedef struct _CrtMemBlockHeader
  223. {
  224. struct _CrtMemBlockHeader * pBlockHeaderNext;
  225. struct _CrtMemBlockHeader * pBlockHeaderPrev;
  226. char * szFileName;
  227. int nLine;
  228. #ifdef _WIN64
  229. /* These items are reversed on Win64 to eliminate gaps in the struct
  230. * and ensure that sizeof(struct)%16 == 0, so 16-byte alignment is
  231. * maintained in the debug heap.
  232. */
  233. int nBlockUse;
  234. size_t nDataSize;
  235. #else
  236. size_t nDataSize;
  237. int nBlockUse;
  238. #endif
  239. long lRequest;
  240. unsigned char gap[nNoMansLandSize];
  241. /* followed by:
  242. * unsigned char data[nDataSize];
  243. * unsigned char anotherGap[nNoMansLandSize];
  244. */
  245. } _CrtMemBlockHeader;
  246. #define pbData(pblock) ((unsigned char *)((_CrtMemBlockHeader *)pblock + 1))
  247. #define pHdr(pbData) (((_CrtMemBlockHeader *)pbData)-1)
  248. _CRTIMP void __cdecl _CrtSetDbgBlockType(
  249. void *,
  250. int
  251. );
  252. #define _BLOCK_TYPE_IS_VALID(use) (_BLOCK_TYPE(use) == _CLIENT_BLOCK || \
  253. (use) == _NORMAL_BLOCK || \
  254. _BLOCK_TYPE(use) == _CRT_BLOCK || \
  255. (use) == _IGNORE_BLOCK)
  256. extern _CRT_ALLOC_HOOK _pfnAllocHook; /* defined in dbghook.c */
  257. int __cdecl _CrtDefaultAllocHook(
  258. int,
  259. void *,
  260. size_t,
  261. int,
  262. long,
  263. const unsigned char *,
  264. int
  265. );
  266. #endif /* _DEBUG */
  267. #ifdef __cplusplus
  268. }
  269. #endif
  270. #endif /* _INC_DBGINT */