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.

251 lines
6.1 KiB

  1. /*++ BUILD Version: 0001 // Increment this if a change has global effects
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. heap.h
  5. Abstract:
  6. This module contains private heap functions used by USER, WIN32K and WINSRV
  7. Author:
  8. Corneliu Lupu (clupu) 16-Nov-1998
  9. Revision History:
  10. --*/
  11. #ifndef _WIN32_HEAP_H_
  12. #define _WIN32_HEAP_H_
  13. #include "nturtl.h"
  14. // Max number of heaps per process
  15. #define MAX_HEAPS 64
  16. // WIN32HEAP flags
  17. #define WIN32_HEAP_INUSE 0x00000001
  18. #define WIN32_HEAP_USE_GUARDS 0x00000002
  19. #define WIN32_HEAP_FAIL_ALLOC 0x00000004
  20. #define WIN32_HEAP_USE_HM_TAGS 0x00000008
  21. // max size of the head and tail strings
  22. #define HEAP_CHECK_SIZE 8
  23. #define HEAP_ALLOC_TRACE_SIZE 6
  24. #define HEAP_ALLOC_MARK 0xDADADADA
  25. #if i386 && !FPO
  26. #define HEAP_ALLOC_TRACE
  27. #endif
  28. typedef struct tagWIN32HEAP* PWIN32HEAP;
  29. typedef struct tagDbgHeapHead {
  30. ULONG mark;
  31. DWORD tag;
  32. PWIN32HEAP pheap;
  33. SIZE_T size; // the size of the allocation (doesn't include
  34. // neither this structure nor the head and
  35. // tail strings)
  36. DWORD pid;
  37. struct tagDbgHeapHead * pPrev; // pointer to the previous allocation in the heap
  38. struct tagDbgHeapHead * pNext; // pointer to the next allocation in the heap
  39. #ifdef HEAP_ALLOC_TRACE
  40. PVOID trace[HEAP_ALLOC_TRACE_SIZE];
  41. #endif // HEAP_ALLOC_TRACE
  42. } DbgHeapHead , *PDbgHeapHead ;
  43. typedef struct tagWIN32HEAP {
  44. PVOID heap;
  45. DWORD dwFlags;
  46. char szHead[HEAP_CHECK_SIZE];
  47. char szTail[HEAP_CHECK_SIZE];
  48. SIZE_T heapReserveSize;
  49. SIZE_T crtMemory;
  50. SIZE_T crtAllocations;
  51. SIZE_T maxMemory;
  52. SIZE_T maxAllocations;
  53. #ifdef _USERK_
  54. FAST_MUTEX* pFastMutex;
  55. #else
  56. RTL_CRITICAL_SECTION critSec;
  57. #endif
  58. PDbgHeapHead pFirstAlloc;
  59. } WIN32HEAP, *PWIN32HEAP;
  60. #define RECORD_HEAP_STACK_TRACE_SIZE 6
  61. typedef struct tagHEAPRECORD {
  62. PVOID p;
  63. PWIN32HEAP pheap;
  64. SIZE_T size;
  65. PVOID trace[RECORD_HEAP_STACK_TRACE_SIZE];
  66. } HEAPRECORD, *PHEAPRECORD;
  67. /*
  68. * Heap Functions
  69. */
  70. #if DBG
  71. PVOID Win32HeapGetHandle(
  72. PWIN32HEAP pheap);
  73. ULONG Win32HeapCreateTag(
  74. PWIN32HEAP pheap,
  75. ULONG Flags,
  76. PWSTR TagPrefix,
  77. PWSTR TagNames);
  78. PWIN32HEAP Win32HeapCreate(
  79. char* pszHead,
  80. char* pszTail,
  81. ULONG Flags,
  82. PVOID HeapBase,
  83. SIZE_T ReserveSize,
  84. SIZE_T CommitSize,
  85. PVOID Lock,
  86. PRTL_HEAP_PARAMETERS Parameters);
  87. BOOL Win32HeapDestroy(
  88. PWIN32HEAP pheap);
  89. PVOID Win32HeapAlloc(
  90. PWIN32HEAP pheap,
  91. SIZE_T uSize,
  92. ULONG tag,
  93. ULONG Flags);
  94. BOOL Win32HeapFree(
  95. PWIN32HEAP pheap,
  96. PVOID p);
  97. BOOL Win32HeapCheckAlloc(
  98. PWIN32HEAP pheap,
  99. PVOID p);
  100. VOID Win32HeapDump(
  101. PWIN32HEAP pheap);
  102. VOID Win32HeapFailAllocations(
  103. BOOL bFail);
  104. SIZE_T Win32HeapSize(
  105. PWIN32HEAP pheap,
  106. PVOID p);
  107. PVOID Win32HeapReAlloc(
  108. PWIN32HEAP pheap,
  109. PVOID p,
  110. SIZE_T uSize,
  111. ULONG Flags);
  112. BOOL Win32HeapValidate(
  113. PWIN32HEAP pheap);
  114. BOOL InitWin32HeapStubs(
  115. VOID);
  116. VOID CleanupWin32HeapStubs(
  117. VOID);
  118. #else // !DBG
  119. #define Win32HeapGetHandle(pheap) ((PVOID)(pheap))
  120. ULONG __inline Win32HeapCreateTag(
  121. PWIN32HEAP pheap,
  122. ULONG Flags,
  123. PWSTR TagPrefix,
  124. PWSTR TagNames)
  125. {
  126. #ifndef _USERK_
  127. return RtlCreateTagHeap((PVOID)pheap, Flags, TagPrefix, TagNames);
  128. #else
  129. return 0;
  130. #endif
  131. }
  132. PWIN32HEAP __inline Win32HeapCreate(
  133. char* pszHead,
  134. char* pszTail,
  135. ULONG Flags,
  136. PVOID HeapBase,
  137. SIZE_T ReserveSize,
  138. SIZE_T CommitSize,
  139. PVOID Lock,
  140. PRTL_HEAP_PARAMETERS Parameters)
  141. {
  142. return RtlCreateHeap(Flags,
  143. HeapBase,
  144. ReserveSize,
  145. CommitSize,
  146. Lock,
  147. Parameters);
  148. UNREFERENCED_PARAMETER(pszHead);
  149. UNREFERENCED_PARAMETER(pszTail);
  150. }
  151. BOOL __inline Win32HeapDestroy(PWIN32HEAP pheap)
  152. {
  153. RtlDestroyHeap((PVOID)pheap);
  154. return TRUE;
  155. }
  156. PVOID __inline Win32HeapAlloc(PWIN32HEAP pheap, SIZE_T uSize, DWORD tag, ULONG Flags)
  157. {
  158. return RtlAllocateHeap((PVOID)pheap, Flags, uSize);
  159. UNREFERENCED_PARAMETER(tag);
  160. }
  161. BOOL __inline Win32HeapFree(PWIN32HEAP pheap, PVOID p)
  162. {
  163. return RtlFreeHeap((PVOID)pheap, 0, p);
  164. }
  165. #define Win32HeapCheckAlloc(pheap, p)
  166. #define Win32HeapDump(pheap)
  167. #define Win32HeapFailAllocations(pheap, bFail)
  168. SIZE_T __inline Win32HeapSize(PWIN32HEAP pheap, PVOID p)
  169. {
  170. return RtlSizeHeap((PVOID)pheap, 0, p);
  171. }
  172. PVOID __inline Win32HeapReAlloc(
  173. PWIN32HEAP pheap,
  174. PVOID p,
  175. SIZE_T uSize,
  176. ULONG Flags)
  177. {
  178. return RtlReAllocateHeap((PVOID)pheap, Flags, p, uSize);
  179. }
  180. BOOL __inline Win32HeapValidate(PWIN32HEAP pheap)
  181. {
  182. #ifndef _USERK_
  183. return RtlValidateHeap((PVOID)pheap, 0, NULL);
  184. #else
  185. return TRUE;
  186. #endif // _USERK_
  187. }
  188. #define InitWin32HeapStubs() TRUE
  189. #define CleanupWin32HeapStubs()
  190. #endif // DBG
  191. #endif // _WIN32_HEAP_H_