3 Copyright (c) Alex Ionescu. All rights reserved.
11 Type definitions for the Memory Manager
15 Alex Ionescu (alexi@tinykrnl.org) - Updated - 27-Feb-2006
26 #include <arch/mmtypes.h>
29 // Page-Rounding Macros
31 #define PAGE_ROUND_DOWN(x) (((ULONG_PTR)x)&(~(PAGE_SIZE-1)))
32 #define PAGE_ROUND_UP(x) \
33 ( (((ULONG_PTR)x)%PAGE_SIZE) ? ((((ULONG_PTR)x)&(~(PAGE_SIZE-1)))+PAGE_SIZE) : ((ULONG_PTR)x) )
35 #define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
37 #define ROUND_TO_ALLOCATION_GRANULARITY(Size) (((ULONG_PTR)(Size) + MM_ALLOCATION_GRANULARITY - 1) \
38 & ~(MM_ALLOCATION_GRANULARITY - 1))
41 // Macro for generating pool tags
43 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
48 // Section Flags for NtCreateSection
50 #define SEC_BASED 0x00200000
51 #define SEC_NO_CHANGE 0x00400000
54 // Section Inherit Flags for NtCreateSection
56 typedef enum _SECTION_INHERIT
65 typedef enum _POOL_TYPE
69 NonPagedPoolMustSucceed
,
71 NonPagedPoolCacheAligned
,
72 PagedPoolCacheAligned
,
73 NonPagedPoolCacheAlignedMustS
,
75 NonPagedPoolSession
= 32,
77 NonPagedPoolMustSucceedSession
,
78 DontUseThisTypeSession
,
79 NonPagedPoolCacheAlignedSession
,
80 PagedPoolCacheAlignedSession
,
81 NonPagedPoolCacheAlignedMustSSession
86 // Per Processor Non Paged Lookaside List IDs
88 typedef enum _PP_NPAGED_LOOKASIDE_NUMBER
90 LookasideSmallIrpList
= 0,
91 LookasideLargeIrpList
= 1,
93 LookasideCreateInfoList
= 3,
94 LookasideNameBufferList
= 4,
95 LookasideTwilightList
= 5,
96 LookasideCompletionList
= 6,
97 LookasideMaximumList
= 7
98 } PP_NPAGED_LOOKASIDE_NUMBER
;
101 // Memory Information Classes for NtQueryVirtualMemory
103 typedef enum _MEMORY_INFORMATION_CLASS
105 MemoryBasicInformation
,
106 MemoryWorkingSetList
,
108 MemoryBasicVlmInformation
109 } MEMORY_INFORMATION_CLASS
;
112 // Section Information Clasess for NtQuerySection
114 typedef enum _SECTION_INFORMATION_CLASS
116 SectionBasicInformation
,
117 SectionImageInformation
,
118 } SECTION_INFORMATION_CLASS
;
120 #ifdef NTOS_MODE_USER
123 // Virtual Memory Counters
125 typedef struct _VM_COUNTERS
127 SIZE_T PeakVirtualSize
;
129 ULONG PageFaultCount
;
130 SIZE_T PeakWorkingSetSize
;
131 SIZE_T WorkingSetSize
;
132 SIZE_T QuotaPeakPagedPoolUsage
;
133 SIZE_T QuotaPagedPoolUsage
;
134 SIZE_T QuotaPeakNonPagedPoolUsage
;
135 SIZE_T QuotaNonPagedPoolUsage
;
136 SIZE_T PagefileUsage
;
137 SIZE_T PeakPagefileUsage
;
138 } VM_COUNTERS
, *PVM_COUNTERS
;
140 typedef struct _VM_COUNTERS_EX
142 SIZE_T PeakVirtualSize
;
144 ULONG PageFaultCount
;
145 SIZE_T PeakWorkingSetSize
;
146 SIZE_T WorkingSetSize
;
147 SIZE_T QuotaPeakPagedPoolUsage
;
148 SIZE_T QuotaPagedPoolUsage
;
149 SIZE_T QuotaPeakNonPagedPoolUsage
;
150 SIZE_T QuotaNonPagedPoolUsage
;
151 SIZE_T PagefileUsage
;
152 SIZE_T PeakPagefileUsage
;
154 } VM_COUNTERS_EX
, *PVM_COUNTERS_EX
;
158 // List of Working Sets
160 typedef struct _MEMORY_WORKING_SET_LIST
163 ULONG WorkingSetList
[1];
164 } MEMORY_WORKING_SET_LIST
, *PMEMORY_WORKING_SET_LIST
;
167 // Memory Information Structures for NtQueryVirtualMemory
171 UNICODE_STRING SectionFileName
;
172 WCHAR NameBuffer
[ANYSIZE_ARRAY
];
173 } MEMORY_SECTION_NAME
, *PMEMORY_SECTION_NAME
;
176 // Section Information Structures for NtQuerySection
178 typedef struct _SECTION_BASIC_INFORMATION
183 } SECTION_BASIC_INFORMATION
, *PSECTION_BASIC_INFORMATION
;
185 typedef struct _SECTION_IMAGE_INFORMATION
187 PVOID TransferAddress
;
189 ULONG MaximumStackSize
;
190 ULONG CommittedStackSize
;
192 USHORT SubSystemMinorVersion
;
193 USHORT SubSystemMajorVersion
;
195 USHORT ImageCharacteristics
;
196 USHORT DllChracteristics
;
198 UCHAR ImageContainsCode
;
203 } SECTION_IMAGE_INFORMATION
, *PSECTION_IMAGE_INFORMATION
;
205 #ifndef NTOS_MODE_USER
210 typedef struct _MMPTE
217 MMPTE_PROTOTYPE Proto
;
219 MMPTE_TRANSITION Trans
;
220 MMPTE_SUBSECTION Subsect
;
226 // Section Information structure
228 typedef struct _MI_EXTRA_IMAGE_INFORMATION
231 } MI_EXTRA_IMAGE_INFORMATION
, *PMI_EXTRA_IMAGE_INFORMATION
;
233 typedef struct _MI_SECTION_IMAGE_INFORMATION
235 SECTION_IMAGE_INFORMATION ExportedImageInformation
;
236 MI_EXTRA_IMAGE_INFORMATION InternalImageInformation
;
237 } MI_SECTION_IMAGE_INFORMATION
, *PMI_SECTION_IMAGE_INFORMATION
;
240 // Section Extension Information
242 typedef struct _MMEXTEND_INFO
244 ULONGLONG CommittedSize
;
245 ULONG ReferenceCount
;
246 } MMEXTEND_INFO
, *PMMEXTEND_INFO
;
249 // Segment and Segment Flags
251 typedef struct _SEGMENT_FLAGS
253 ULONG TotalNumberOfPtes4132
:10;
254 ULONG ExtraSharedWowSubsections
:1;
257 } SEGMENT_FLAGS
, *PSEGMENT_FLAGS
;
259 typedef struct _SEGMENT
261 struct _CONTROL_AREA
*ControlArea
;
262 ULONG TotalNumberOfPtes
;
263 ULONG NonExtendedPtes
;
265 ULONGLONG SizeOfSegment
;
266 MMPTE SegmentPteTemplate
;
267 ULONG NumberOfCommittedPages
;
268 PMMEXTEND_INFO ExtendInfo
;
269 SEGMENT_FLAGS SegmentFlags
;
273 ULONG ImageCommitment
;
274 PEPROCESS CreatingProcess
;
278 PMI_SECTION_IMAGE_INFORMATION ImageInformation
;
283 } SEGMENT
, *PSEGMENT
;
286 // Event Counter Structure
288 typedef struct _EVENT_COUNTER
292 LIST_ENTRY ListEntry
;
293 } EVENT_COUNTER
, *PEVENT_COUNTER
;
298 typedef struct _MMSECTION_FLAGS
300 ULONG BeingDeleted
:1;
301 ULONG BeingCreated
:1;
303 ULONG NoModifiedWriting
:1;
310 ULONG PhysicalMemory
:1;
316 ULONG UserReference
:1;
317 ULONG GlobalMemory
:1;
318 ULONG DeleteOnClose
:1;
319 ULONG FilePointerNull
:1;
320 ULONG DebugSymbolsLoaded
:1;
321 ULONG SetMappedFileIoComplete
:1;
322 ULONG CollidedFlush
:1;
325 ULONG ImageMappedInSystemSpace
:1;
326 ULONG UserWritable
:1;
328 ULONG GlobalOnlyPerSession
:1;
330 ULONG WriteCombined
:1;
332 } MMSECTION_FLAGS
, *PMMSECTION_FLAGS
;
334 typedef struct _MMSUBSECTION_FLAGS
338 ULONG SubsectionStatic
:1;
339 ULONG GlobalMemory
:1;
342 ULONG StartingSector4132
:10;
343 ULONG SectorEndOffset
:12;
344 } MMSUBSECTION_FLAGS
, *PMMSUBSECTION_FLAGS
;
347 // Control Area Structures
349 typedef struct _CONTROL_AREA
352 LIST_ENTRY DereferenceList
;
353 ULONG NumberOfSectionReferences
;
354 ULONG NumberOfPfnReferences
;
355 ULONG NumberOfMappedViews
;
356 ULONG NumberOfSystemCacheViews
;
357 ULONG NumberOfUserReferences
;
361 MMSECTION_FLAGS Flags
;
363 PFILE_OBJECT FilePointer
;
364 PEVENT_COUNTER WaitingForDeletion
;
365 USHORT ModifiedWriteCount
;
366 USHORT FlushInProgressCount
;
367 ULONG WritableUserReferences
;
369 } CONTROL_AREA
, *PCONTROL_AREA
;
371 typedef struct _LARGE_CONTROL_AREA
374 LIST_ENTRY DereferenceList
;
375 ULONG NumberOfSectionReferences
;
376 ULONG NumberOfPfnReferences
;
377 ULONG NumberOfMappedViews
;
378 ULONG NumberOfSystemCacheViews
;
379 ULONG NumberOfUserReferences
;
383 MMSECTION_FLAGS Flags
;
385 PFILE_OBJECT FilePointer
;
386 PEVENT_COUNTER WaitingForDeletion
;
387 USHORT ModifiedWriteCount
;
388 USHORT FlushInProgressCount
;
389 ULONG WritableUserReferences
;
392 LIST_ENTRY UserGlobalList
;
394 } LARGE_CONTROL_AREA
, *PLARGE_CONTROL_AREA
;
399 typedef struct _SUBSECTION
401 PCONTROL_AREA ControlArea
;
405 MMSUBSECTION_FLAGS SubsectionFlags
;
407 ULONG StartingSector
;
408 PMMPTE SubsectionBase
;
410 ULONG PtesInSubsection
;
411 struct _SUBSECTION
*NextSubSection
;
412 } SUBSECTION
, *PSUBSECTION
;
417 typedef struct _SEGMENT_OBJECT
420 ULONG TotalNumberOfPtes
;
421 LARGE_INTEGER SizeOfSegment
;
422 ULONG NonExtendedPtes
;
423 ULONG ImageCommitment
;
424 PCONTROL_AREA ControlArea
;
425 PSUBSECTION Subsection
;
426 PLARGE_CONTROL_AREA LargeControlArea
;
427 PMMSECTION_FLAGS MmSectionFlags
;
428 PMMSUBSECTION_FLAGS MmSubSectionFlags
;
429 } SEGMENT_OBJECT
, *PSEGMENT_OBJECT
;
434 typedef struct _SECTION_OBJECT
440 PSEGMENT_OBJECT Segment
;
441 } SECTION_OBJECT
, *PSECTION_OBJECT
;
444 // Generic Address Range Structure
446 typedef struct _ADDRESS_RANGE
453 } ADDRESS_RANGE
, *PADDRESS_RANGE
;
456 // Node in Memory Manager's AVL Table
458 typedef struct _MMADDRESS_NODE
463 struct _MMADDRESS_NODE
*Parent
;
465 struct _MMADDRESS_NODE
*LeftChild
;
466 struct _MMADDRESS_NODE
*RightChild
;
469 } MMADDRESS_NODE
, *PMMADDRESS_NODE
;
472 // Memory Manager AVL Table for VADs and other descriptors
474 typedef struct _MM_AVL_TABLE
476 MMADDRESS_NODE BalancedRoot
;
479 ULONG NumberGenericTableElements
:24;
482 } MM_AVL_TABLE
, *PMM_AVL_TABLE
;
485 // Memory Manager Working Set Structures
487 typedef struct _MMWSLENTRY
491 ULONG LockedInMemory
:1;
496 ULONG VirtualPageNumber
:14;
497 } MMWSLENTRY
, *PMMWSLENTRY
;
499 typedef struct _MMWSLE
503 PVOID VirtualAddress
;
509 typedef struct _MMWSLE_HASH
513 } MMWSLE_HASH
, *PMMWSLE_HASH
;
515 typedef struct _MMWSL
522 ULONG LastInitializedWsle
;
524 PMMWSLE_HASH HashTable
;
526 ULONG NumberOfCommittedPageTables
;
527 PVOID HashTableStart
;
528 PVOID HighestPermittedHashAddress
;
529 ULONG NumberOfImageWaiters
;
531 USHORT UsedPageTableEntries
[768];
532 ULONG CommittedPageTables
[24];
536 // Flags for Memory Support Structure
538 typedef struct _MMSUPPORT_FLAGS
540 ULONG SessionSpace
:1;
541 ULONG BeingTrimmed
:1;
542 ULONG SessionLeader
:1;
544 ULONG WorkingSetHard
:1;
545 ULONG AddressSpaceBeingDeleted
:1;
547 ULONG AllowWorkingSetAdjustment
:8;
548 ULONG MemoryPriority
:8;
549 } MMSUPPORT_FLAGS
, *PMMSUPPORT_FLAGS
;
552 // Per-Process Memory Manager Data
554 typedef struct _MMSUPPORT
556 LARGE_INTEGER LastTrimTime
;
557 MMSUPPORT_FLAGS Flags
;
558 ULONG PageFaultCount
;
559 ULONG PeakWorkingSetSize
;
560 ULONG WorkingSetSize
;
561 ULONG MinimumWorkingSetSize
;
562 ULONG MaximumWorkingSetSize
;
563 PMMWSL MmWorkingSetList
;
564 LIST_ENTRY WorkingSetExpansionLinks
;
566 ULONG NextEstimationSlot
;
568 ULONG EstimatedAvailable
;
569 ULONG GrowthSinceLastEstimate
;
570 } MMSUPPORT
, *PMMSUPPORT
;
573 // Memory Information Types
575 typedef struct _MEMORY_BASIC_INFORMATION
578 PVOID AllocationBase
;
579 ULONG AllocationProtect
;
584 } MEMORY_BASIC_INFORMATION
,*PMEMORY_BASIC_INFORMATION
;
588 // Mm Global Variables
592 // Default heap size values. For user mode, these values are copied to a new
593 // process's PEB by the kernel in MmCreatePeb. In kernel mode, RtlCreateHeap
594 // reads these variables directly.
596 // These variables should be considered "const"; they are written only once,
597 // during MmInitSystem.
599 extern SIZE_T MmHeapSegmentReserve
;
600 extern SIZE_T MmHeapSegmentCommit
;
601 extern SIZE_T MmHeapDeCommitTotalFreeThreshold
;
602 extern SIZE_T MmHeapDeCommitFreeBlockThreshold
;
604 #endif // !NTOS_MODE_USER