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.

413 lines
11 KiB

  1. /*++
  2. Copyright (c) 1994-2000 Microsoft Corporation
  3. Module Name:
  4. heappage.h
  5. Abstract:
  6. External interface for page heap manager.
  7. Author:
  8. Tom McGuire (TomMcg) 06-Jan-1995
  9. Silviu Calinoiu (SilviuC) 22-Feb-2000
  10. Revision History:
  11. --*/
  12. #ifndef _HEAP_PAGE_H_
  13. #define _HEAP_PAGE_H_
  14. //
  15. // #defining DEBUG_PAGE_HEAP will cause the page heap manager
  16. // to be compiled. Only #define this flag if NOT kernel mode.
  17. // Probably want to define this just for checked-build (DBG).
  18. //
  19. #ifndef NTOS_KERNEL_RUNTIME
  20. #define DEBUG_PAGE_HEAP 1
  21. #endif
  22. //silviuc: #include "heappagi.h"
  23. #ifndef DEBUG_PAGE_HEAP
  24. //
  25. // These macro-based hooks should be defined to nothing so they
  26. // simply "go away" during compile if the debug heap manager is
  27. // not desired (retail builds).
  28. //
  29. #define IS_DEBUG_PAGE_HEAP_HANDLE( HeapHandle ) FALSE
  30. #define IF_DEBUG_PAGE_HEAP_THEN_RETURN( Handle, ReturnThis )
  31. #define IF_DEBUG_PAGE_HEAP_THEN_CALL( Handle, CallThis )
  32. #define IF_DEBUG_PAGE_HEAP_THEN_BREAK( Handle, Text, ReturnThis )
  33. #define HEAP_FLAG_PAGE_ALLOCS 0
  34. #define RtlpDebugPageHeapValidate( HeapHandle, Flags, Address ) TRUE
  35. #else // DEBUG_PAGE_HEAP
  36. //
  37. // The following definitions and prototypes are the external interface
  38. // for hooking the debug heap manager in the retail heap manager.
  39. //
  40. #define HEAP_FLAG_PAGE_ALLOCS 0x01000000
  41. #define HEAP_PROTECTION_ENABLED 0x02000000
  42. #define HEAP_BREAK_WHEN_OUT_OF_VM 0x04000000
  43. #define HEAP_NO_ALIGNMENT 0x08000000
  44. #define IS_DEBUG_PAGE_HEAP_HANDLE( HeapHandle ) \
  45. (((PHEAP)(HeapHandle))->ForceFlags & HEAP_FLAG_PAGE_ALLOCS )
  46. #define IF_DEBUG_PAGE_HEAP_THEN_RETURN( Handle, ReturnThis ) \
  47. { \
  48. if ( IS_DEBUG_PAGE_HEAP_HANDLE( Handle )) \
  49. { \
  50. return ReturnThis; \
  51. } \
  52. }
  53. #define IF_DEBUG_PAGE_HEAP_THEN_CALL( Handle, CallThis ) \
  54. { \
  55. if ( IS_DEBUG_PAGE_HEAP_HANDLE( Handle )) \
  56. { \
  57. CallThis; \
  58. return; \
  59. } \
  60. }
  61. #define IF_DEBUG_PAGE_HEAP_THEN_BREAK( Handle, Text, ReturnThis ) \
  62. { \
  63. if ( IS_DEBUG_PAGE_HEAP_HANDLE( Handle )) \
  64. { \
  65. RtlpDebugPageHeapBreak( Text ); \
  66. return ReturnThis; \
  67. } \
  68. }
  69. PVOID
  70. RtlpDebugPageHeapCreate(
  71. IN ULONG Flags,
  72. IN PVOID HeapBase,
  73. IN SIZE_T ReserveSize,
  74. IN SIZE_T CommitSize,
  75. IN PVOID Lock,
  76. IN PRTL_HEAP_PARAMETERS Parameters
  77. );
  78. PVOID
  79. RtlpDebugPageHeapAllocate(
  80. IN PVOID HeapHandle,
  81. IN ULONG Flags,
  82. IN SIZE_T Size
  83. );
  84. BOOLEAN
  85. RtlpDebugPageHeapFree(
  86. IN PVOID HeapHandle,
  87. IN ULONG Flags,
  88. IN PVOID Address
  89. );
  90. PVOID
  91. RtlpDebugPageHeapReAllocate(
  92. IN PVOID HeapHandle,
  93. IN ULONG Flags,
  94. IN PVOID Address,
  95. IN SIZE_T Size
  96. );
  97. PVOID
  98. RtlpDebugPageHeapDestroy(
  99. IN PVOID HeapHandle
  100. );
  101. SIZE_T
  102. RtlpDebugPageHeapSize(
  103. IN PVOID HeapHandle,
  104. IN ULONG Flags,
  105. IN PVOID Address
  106. );
  107. ULONG
  108. RtlpDebugPageHeapGetProcessHeaps(
  109. ULONG NumberOfHeaps,
  110. PVOID *ProcessHeaps
  111. );
  112. ULONG
  113. RtlpDebugPageHeapCompact(
  114. IN PVOID HeapHandle,
  115. IN ULONG Flags
  116. );
  117. BOOLEAN
  118. RtlpDebugPageHeapValidate(
  119. IN PVOID HeapHandle,
  120. IN ULONG Flags,
  121. IN PVOID Address
  122. );
  123. NTSTATUS
  124. RtlpDebugPageHeapWalk(
  125. IN PVOID HeapHandle,
  126. IN OUT PRTL_HEAP_WALK_ENTRY Entry
  127. );
  128. BOOLEAN
  129. RtlpDebugPageHeapLock(
  130. IN PVOID HeapHandle
  131. );
  132. BOOLEAN
  133. RtlpDebugPageHeapUnlock(
  134. IN PVOID HeapHandle
  135. );
  136. BOOLEAN
  137. RtlpDebugPageHeapSetUserValue(
  138. IN PVOID HeapHandle,
  139. IN ULONG Flags,
  140. IN PVOID Address,
  141. IN PVOID UserValue
  142. );
  143. BOOLEAN
  144. RtlpDebugPageHeapGetUserInfo(
  145. IN PVOID HeapHandle,
  146. IN ULONG Flags,
  147. IN PVOID Address,
  148. OUT PVOID* UserValue,
  149. OUT PULONG UserFlags
  150. );
  151. BOOLEAN
  152. RtlpDebugPageHeapSetUserFlags(
  153. IN PVOID HeapHandle,
  154. IN ULONG Flags,
  155. IN PVOID Address,
  156. IN ULONG UserFlagsReset,
  157. IN ULONG UserFlagsSet
  158. );
  159. BOOLEAN
  160. RtlpDebugPageHeapSerialize(
  161. IN PVOID HeapHandle
  162. );
  163. NTSTATUS
  164. RtlpDebugPageHeapExtend(
  165. IN PVOID HeapHandle,
  166. IN ULONG Flags,
  167. IN PVOID Base,
  168. IN SIZE_T Size
  169. );
  170. NTSTATUS
  171. RtlpDebugPageHeapZero(
  172. IN PVOID HeapHandle,
  173. IN ULONG Flags
  174. );
  175. NTSTATUS
  176. RtlpDebugPageHeapReset(
  177. IN PVOID HeapHandle,
  178. IN ULONG Flags
  179. );
  180. NTSTATUS
  181. RtlpDebugPageHeapUsage(
  182. IN PVOID HeapHandle,
  183. IN ULONG Flags,
  184. IN OUT PRTL_HEAP_USAGE Usage
  185. );
  186. BOOLEAN
  187. RtlpDebugPageHeapIsLocked(
  188. IN PVOID HeapHandle
  189. );
  190. VOID
  191. RtlpDebugPageHeapBreak(
  192. PCH Text
  193. );
  194. //
  195. // Page Heap Global Flags
  196. //
  197. // These flags are kept in a global variable that can be set from
  198. // debugger. During heap creation these flags are stored in a per heap
  199. // structure and control the behavior of that particular heap.
  200. //
  201. // PAGE_HEAP_ENABLE_PAGE_HEAP
  202. //
  203. // This flag is set by default. It means that page heap allocations
  204. // should be used always. The flag is useful if we want to use page
  205. // heap only for certain heaps and stick with normal heaps for the
  206. // others. It can be changed on the fly (after heap creation) to direct
  207. // allocations in one heap or another.
  208. //
  209. // PAGE_HEAP_CATCH_BACKWARD_OVERRUNS
  210. //
  211. // Places the N/A page at the beginning of the block.
  212. //
  213. // PAGE_HEAP_UNALIGNED_ALLOCATIONS
  214. //
  215. // For historical reasons (related to RPC) by default page heap
  216. // aligns allocations at 8 byte boundaries. With this flag set
  217. // this does not happen and we can catch instantly off by one
  218. // errors for unaligned allocations.
  219. //
  220. // PAGE_HEAP_SMART_MEMORY_USAGE
  221. //
  222. // This flag reduces the committed memory consumption in half
  223. // by using decommitted ranges (reserved virtual space) instead
  224. // of N/A committed pages. This flag is disabled by catch backward
  225. // overruns.
  226. //
  227. // PAGE_HEAP_USE_SIZE_RANGE
  228. //
  229. // Use page heap for allocations in the size range specified by:
  230. // RtlpDphSizeRangeStart..RtlpDphSizeRangeEnd.
  231. //
  232. // PAGE_HEAP_USE_DLL_RANGE
  233. //
  234. // Use page heap for allocations in the address range specified by:
  235. // RtlpDphDllRangeStart..RtlpDphDllRangeEnd. If the stack trace
  236. // of the allocation contains one address in this range then
  237. // allocation will be made from page heap.
  238. //
  239. // PAGE_HEAP_USE_RANDOM_DECISION
  240. //
  241. // Use page heap if we randomly decide so.
  242. //
  243. // PAGE_HEAP_USE_DLL_NAMES
  244. //
  245. // Use page heap if allocation call was generated from on of the
  246. // target dlls.
  247. //
  248. // PAGE_HEAP_USE_FAULT_INJECTION
  249. //
  250. // Fault inject heap allocation calls based on a simple
  251. // probabilistic model (see FaultProbability and FaultTimeOut).
  252. //
  253. // PAGE_HEAP_PROTECT_META_DATA
  254. //
  255. // Keep page heap metadata read only if we are not executing inside
  256. // the page heap code.
  257. //
  258. // PAGE_CHECK_NO_SERIALIZE_ACCESS
  259. //
  260. // Additional checks for multi-threaded access for no_serialize
  261. // heaps. This flag can trigger false positives in MPheap. It needs
  262. // to be used only on processes that do not use MPheap-like heaps.
  263. //
  264. // PAGE_HEAP_USE_READONLY
  265. //
  266. // The page following (or preceding) the user allocation is marked
  267. // RO instead of NA. This is useful when testing RPC servers which
  268. // by design during unmarshalling might go off by a few bytes when
  269. // probing parameters. This is so for performance reasons.
  270. //
  271. #define PAGE_HEAP_ENABLE_PAGE_HEAP 0x0001
  272. #define PAGE_HEAP_COLLECT_STACK_TRACES 0x0002
  273. #define PAGE_HEAP_NO_UMDH_SUPPORT 0x0004
  274. #define PAGE_HEAP_RESERVED_08 0x0008
  275. #define PAGE_HEAP_CATCH_BACKWARD_OVERRUNS 0x0010
  276. #define PAGE_HEAP_UNALIGNED_ALLOCATIONS 0x0020
  277. #define PAGE_HEAP_SMART_MEMORY_USAGE 0x0040 // obsolete
  278. #define PAGE_HEAP_USE_SIZE_RANGE 0x0080
  279. #define PAGE_HEAP_USE_DLL_RANGE 0x0100
  280. #define PAGE_HEAP_USE_RANDOM_DECISION 0x0200
  281. #define PAGE_HEAP_USE_DLL_NAMES 0x0400
  282. #define PAGE_HEAP_USE_FAULT_INJECTION 0x0800
  283. #define PAGE_HEAP_PROTECT_META_DATA 0x1000
  284. #define PAGE_HEAP_CHECK_NO_SERIALIZE_ACCESS 0x2000
  285. #define PAGE_HEAP_NO_LOCK_CHECKS 0x4000
  286. #define PAGE_HEAP_USE_READONLY 0x8000
  287. //
  288. // Is page heap enabled for this process?
  289. //
  290. extern BOOLEAN RtlpDebugPageHeap;
  291. //
  292. // `RtlpDphGlobalFlags' stores the global page heap flags.
  293. // The value of this variable is copied into the per heap
  294. // flags (ExtraFlags field) during heap creation. This variable
  295. // might get its value from the `PageHeap' ImageFileOptions
  296. // registry key.
  297. //
  298. extern ULONG RtlpDphGlobalFlags;
  299. //
  300. // Page heap global flags. They might be read from the
  301. // `ImageFileOptions' registry key.
  302. //
  303. extern ULONG RtlpDphSizeRangeStart;
  304. extern ULONG RtlpDphSizeRangeEnd;
  305. extern ULONG RtlpDphDllRangeStart;
  306. extern ULONG RtlpDphDllRangeEnd;
  307. extern ULONG RtlpDphRandomProbability;
  308. extern WCHAR RtlpDphTargetDlls[];
  309. //
  310. // If not zero controls the probability with which
  311. // allocations will be failed on purpose by page heap
  312. // manager. Timeout represents the initial period during
  313. // process initialization when faults are not allowed.
  314. //
  315. extern ULONG RtlpDphFaultProbability;
  316. extern ULONG RtlpDphFaultTimeOut;
  317. //
  318. // Stuff needed for per dll logic implemented in the loader
  319. //
  320. const WCHAR *
  321. RtlpDphIsDllTargeted (
  322. const WCHAR * Name
  323. );
  324. VOID
  325. RtlpDphTargetDllsLoadCallBack (
  326. PUNICODE_STRING Name,
  327. PVOID Address,
  328. ULONG Size
  329. );
  330. //
  331. // Functions needed to turn on/off fault injection.
  332. // They are needed in the loader so that allocations
  333. // succeed while in LdrLoadDll code path.
  334. //
  335. VOID
  336. RtlpDphDisableFaultInjection (
  337. );
  338. VOID
  339. RtlpDphEnableFaultInjection (
  340. );
  341. #endif // DEBUG_PAGE_HEAP
  342. #endif // _HEAP_PAGE_H_