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.

266 lines
4.2 KiB

  1. //
  2. // Copyright (c) 2001 Microsoft Corporation
  3. //
  4. // Module Name
  5. //
  6. // gc.h
  7. //
  8. // Abstract
  9. //
  10. // Contains data structures for garbage collection
  11. // and the apis that modify them.
  12. //
  13. // Author
  14. //
  15. // Narayana Batchu (nbatchu) 21-Jun-01
  16. //
  17. #ifndef __GC_H__
  18. #define __GC_H__
  19. //
  20. // HEAP_BLOCK
  21. //
  22. // This represents a heap block in a heap.
  23. //
  24. // BlockAddress Address of the heap block
  25. //
  26. // BlockSize Size of the heap block
  27. //
  28. // RefCount Reference count to this block
  29. //
  30. // TraceIndex Index of the stack trace in the trace
  31. // database
  32. //
  33. typedef struct _HEAP_BLOCK {
  34. ULONG_PTR BlockAddress;
  35. ULONG BlockSize;
  36. ULONG RefCount;
  37. USHORT TraceIndex;
  38. } HEAP_BLOCK, *PHEAP_BLOCK;
  39. //
  40. // BLOCK_LIST
  41. //
  42. // This represents all the blocks in a heap
  43. //
  44. // HeapAddress Address of the heap
  45. //
  46. // Blocks Pointer to the array of blocks
  47. //
  48. // BlockCount Number of blocks in the heap
  49. //
  50. // Capacity Max capacity to hold blocks.
  51. //
  52. // ListSorted Boolean that represents the status
  53. // of the Blocks
  54. //
  55. typedef struct _BLOCK_LIST {
  56. ULONG_PTR HeapAddress;
  57. PHEAP_BLOCK Blocks;
  58. ULONG BlockCount;
  59. ULONG Capacity;
  60. BOOL ListSorted;
  61. } BLOCK_LIST, *PBLOCK_LIST;
  62. //
  63. // HEAP_LIST
  64. //
  65. // This represents all the heaps in the process
  66. //
  67. // HeapCount Number of heaps in the list
  68. //
  69. // Heaps Pointer to the array of heaps
  70. //
  71. // Capacity Max capacity to hold heaps.
  72. //
  73. typedef struct _HEAP_LIST {
  74. ULONG HeapCount;
  75. PBLOCK_LIST Heaps;
  76. ULONG Capacity;
  77. } HEAP_LIST, *PHEAP_LIST;
  78. //
  79. // ADDRESS_LIST
  80. //
  81. // This represents a doubly linked list with each node
  82. // having an Address field.
  83. //
  84. // Address Holds the address of a heap block
  85. //
  86. // Next Points to the LIST_ENTRY field of next
  87. // ADDRESS_LIST
  88. //
  89. typedef struct _ADDRESS_LIST {
  90. ULONG_PTR Address;
  91. LIST_ENTRY Next;
  92. } ADDRESS_LIST, *PADDRESS_LIST;
  93. VOID
  94. InitializeHeapBlock(
  95. PHEAP_BLOCK Block
  96. );
  97. VOID
  98. SetHeapBlock(
  99. PHEAP_BLOCK Block,
  100. ULONG_PTR BlockAddress,
  101. ULONG BlockSize,
  102. USHORT TraceIndex
  103. );
  104. BOOL
  105. InitializeBlockList(
  106. PBLOCK_LIST BlockList
  107. );
  108. VOID
  109. FreeBlockList(
  110. PBLOCK_LIST BlockList
  111. );
  112. BOOL
  113. InitializeHeapList(
  114. PHEAP_LIST HeapList
  115. );
  116. VOID
  117. FreeHeapList(
  118. PHEAP_LIST HeapList
  119. );
  120. VOID
  121. InitializeAddressList(
  122. PADDRESS_LIST AddressList
  123. );
  124. VOID
  125. FreeAddressList(
  126. PADDRESS_LIST AddressList
  127. );
  128. BOOL
  129. ResizeBlockList(
  130. PBLOCK_LIST BlockList
  131. );
  132. BOOL
  133. IncreaseBlockListCapacity(
  134. PBLOCK_LIST BlockList
  135. );
  136. BOOL
  137. IncreaseHeapListCapacity(
  138. PHEAP_LIST HeapList
  139. );
  140. ULONG
  141. InsertHeapBlock(
  142. PBLOCK_LIST BlockList,
  143. PHEAP_BLOCK Block
  144. );
  145. ULONG
  146. InsertBlockList(
  147. PHEAP_LIST HeapList,
  148. PBLOCK_LIST BlockList
  149. );
  150. DWORD
  151. GetThreadHandles(
  152. DWORD ProcessId,
  153. LPHANDLE ThreadHandles,
  154. ULONG Count
  155. );
  156. BOOL
  157. GetThreadContexts(
  158. PCONTEXT ThreadContexts,
  159. LPHANDLE ThreadHandles,
  160. ULONG Count
  161. );
  162. ULONG_PTR
  163. StackFilteredAddress(
  164. ULONG_PTR Address,
  165. SIZE_T Size,
  166. PCONTEXT ThreadContexts,
  167. ULONG Count
  168. );
  169. int __cdecl
  170. SortByBlockAddress(
  171. const void * arg1,
  172. const void * arg2
  173. );
  174. int __cdecl
  175. SortByTraceIndex (
  176. const void * arg1,
  177. const void * arg2
  178. );
  179. VOID
  180. SortBlockList(
  181. PBLOCK_LIST BlockList
  182. );
  183. VOID
  184. SortHeaps(
  185. PHEAP_LIST HeapList,
  186. int (__cdecl *compare )(const void *elem1, const void *elem2 )
  187. );
  188. PHEAP_BLOCK
  189. GetHeapBlock(
  190. ULONG_PTR Address,
  191. PHEAP_LIST HeapList
  192. );
  193. VOID
  194. InsertAddress(
  195. ULONG_PTR Address,
  196. PADDRESS_LIST List
  197. );
  198. VOID
  199. DumpLeakList(
  200. FILE * File,
  201. PHEAP_LIST HeapList
  202. );
  203. BOOL
  204. ScanHeapFreeBlocks(
  205. PHEAP_LIST HeapList,
  206. PADDRESS_LIST FreeList
  207. );
  208. BOOL
  209. ScanProcessVirtualMemory(
  210. ULONG PID,
  211. PADDRESS_LIST FreeList,
  212. PHEAP_LIST HeapList
  213. );
  214. VOID
  215. DetectLeaks(
  216. PHEAP_LIST HeapList,
  217. ULONG Pid,
  218. FILE * OutFile
  219. );
  220. #endif