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.

291 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1995-2001 Microsoft Corporation
  3. Module Name:
  4. heapdbg.h
  5. Abstract:
  6. Domain Name System (DNS) Library
  7. Heap debugging definitions and declarations.
  8. Author:
  9. Jim Gilroy (jamesg) January 31, 1995
  10. Revision History:
  11. --*/
  12. #ifndef _HEAPDBG_INCLUDED_
  13. #define _HEAPDBG_INCLUDED_
  14. //
  15. // Heap blob
  16. //
  17. typedef struct _HeapBlob
  18. {
  19. HANDLE hHeap;
  20. LIST_ENTRY ListHead;
  21. // flags
  22. BOOL fCreated;
  23. BOOL fHeaders;
  24. DWORD Tag;
  25. BOOL fDnsLib;
  26. BOOL fCheckAll;
  27. DWORD FailureException;
  28. DWORD AllocFlags;
  29. DWORD DefaultFlags;
  30. // stats
  31. DWORD AllocMem;
  32. DWORD FreeMem;
  33. DWORD CurrentMem;
  34. DWORD AllocCount;
  35. DWORD FreeCount;
  36. DWORD CurrentCount;
  37. PSTR pszDefaultFile;
  38. DWORD DefaultLine;
  39. CRITICAL_SECTION ListCs;
  40. }
  41. HEAP_BLOB, *PHEAP_BLOB;
  42. //
  43. // Heap Header
  44. //
  45. #define HEAP_HEADER_FILE_SIZE (16)
  46. typedef struct _HEAP_HEADER
  47. {
  48. //
  49. // Note, if move or add fields, MUST update list entry offset below
  50. //
  51. ULONG HeapCodeBegin;
  52. ULONG AllocCount;
  53. ULONG AllocSize;
  54. ULONG RequestSize;
  55. //
  56. // Put LIST_ENTRY in middle of header
  57. // - keep begin code at front
  58. // - less likely to be corrupted
  59. //
  60. LIST_ENTRY ListEntry;
  61. PHEAP_BLOB pHeap;
  62. PSTR FileName;
  63. DWORD LineNo;
  64. DWORD AllocTime;
  65. ULONG CurrentMem;
  66. ULONG CurrentCount;
  67. ULONG HeapCodeEnd;
  68. }
  69. HEAP_HEADER, * PHEAP_HEADER;
  70. //
  71. // Heap Trailer
  72. //
  73. typedef struct _HEAP_TRAILER
  74. {
  75. ULONG HeapCodeBegin;
  76. ULONG AllocCount;
  77. ULONG AllocSize;
  78. ULONG HeapCodeEnd;
  79. }
  80. HEAP_TRAILER, * PHEAP_TRAILER;
  81. //
  82. // Header from list entry
  83. //
  84. #define HEAP_HEADER_LIST_ENTRY_OFFSET (16)
  85. #define HEAP_HEADER_FROM_LIST_ENTRY( pList ) \
  86. ( (PHEAP_HEADER)( (PCHAR)pList - HEAP_HEADER_LIST_ENTRY_OFFSET ))
  87. //
  88. // Validation
  89. //
  90. PHEAP_HEADER
  91. Dns_DbgHeapValidateMemory(
  92. IN PVOID pMem,
  93. IN BOOL fAtHeader
  94. );
  95. VOID
  96. Dns_DbgHeapValidateAllocList(
  97. IN PHEAP_BLOB pHeap
  98. );
  99. //
  100. // Debug print
  101. //
  102. VOID
  103. Dns_DbgHeapGlobalInfoPrint(
  104. IN PHEAP_BLOB pHeap
  105. );
  106. VOID
  107. Dns_DbgHeapHeaderPrint(
  108. IN PHEAP_HEADER h,
  109. IN PHEAP_TRAILER t
  110. );
  111. VOID
  112. Dns_DbgHeapDumpAllocList(
  113. IN PHEAP_BLOB pHeap
  114. );
  115. //
  116. // Init\cleanup
  117. //
  118. DNS_STATUS
  119. Dns_HeapInitialize(
  120. IN OUT PHEAP_BLOB pHeap,
  121. IN HANDLE hHeap,
  122. IN DWORD dwCreateFlags,
  123. IN BOOL fUseHeaders,
  124. IN BOOL fResetDnslib,
  125. IN BOOL fFullHeapChecks,
  126. IN DWORD dwException,
  127. IN DWORD dwDefaultFlags,
  128. IN PSTR pszDefaultFileName,
  129. IN DWORD dwDefaultFileLine
  130. );
  131. VOID
  132. Dns_HeapCleanup(
  133. IN OUT PHEAP_BLOB pHeap
  134. );
  135. //
  136. // Full debug heap routines
  137. //
  138. PVOID
  139. Dns_DbgHeapAllocEx(
  140. IN OUT PHEAP_BLOB pHeap,
  141. IN DWORD dwFlags,
  142. IN INT iSize,
  143. IN LPSTR pszFile,
  144. IN DWORD dwLine
  145. );
  146. PVOID
  147. Dns_DbgHeapReallocEx(
  148. IN OUT PHEAP_BLOB pHeap,
  149. IN DWORD dwFlags,
  150. IN OUT PVOID pMem,
  151. IN INT iSize,
  152. IN LPSTR pszFile,
  153. IN DWORD dwLine
  154. );
  155. VOID
  156. Dns_DbgHeapFreeEx(
  157. IN OUT PHEAP_BLOB pHeap,
  158. IN DWORD dwFlags,
  159. IN OUT PVOID pMem
  160. );
  161. //
  162. // Dnslib compatible versions of full debug versions
  163. //
  164. PVOID
  165. Dns_DbgHeapAlloc(
  166. IN INT iSize
  167. );
  168. PVOID
  169. Dns_DbgHeapRealloc(
  170. IN OUT PVOID pMem,
  171. IN INT iSize
  172. );
  173. VOID
  174. Dns_DbgHeapFree(
  175. IN OUT PVOID pMem
  176. );
  177. //
  178. // Non-debug-header versions
  179. //
  180. // These allow you to use a private heap with some of the features
  181. // of the debug heap
  182. // - same initialization
  183. // - specifying individual heap
  184. // - redirection of dnslib (without building your own routines)
  185. // - alloc and free counts
  186. // but without the overhead of the headers.
  187. //
  188. PVOID
  189. Dns_HeapAllocEx(
  190. IN OUT PHEAP_BLOB pHeap,
  191. IN DWORD dwFlags,
  192. IN INT iSize
  193. );
  194. PVOID
  195. Dns_HeapReallocEx(
  196. IN OUT PHEAP_BLOB pHeap,
  197. IN DWORD dwFlags,
  198. IN OUT PVOID pMem,
  199. IN INT iSize
  200. );
  201. VOID
  202. Dns_HeapFreeEx(
  203. IN OUT PHEAP_BLOB pHeap,
  204. IN DWORD dwFlags,
  205. IN OUT PVOID pMem
  206. );
  207. //
  208. // Dnslib compatible versions of non-debug-header versions
  209. //
  210. PVOID
  211. Dns_HeapAlloc(
  212. IN INT iSize
  213. );
  214. PVOID
  215. Dns_HeapRealloc(
  216. IN OUT PVOID pMem,
  217. IN INT iSize
  218. );
  219. VOID
  220. Dns_HeapFree(
  221. IN OUT PVOID pMem
  222. );
  223. #endif // _HEAPDBG_INCLUDED_