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) \
32 (((ULONG_PTR)x)&(~(PAGE_SIZE-1)))
33 #define PAGE_ROUND_UP(x) \
34 ( (((ULONG_PTR)x)%PAGE_SIZE) ? \
35 ((((ULONG_PTR)x)&(~(PAGE_SIZE-1)))+PAGE_SIZE) : \
38 #define ROUND_TO_PAGES(Size) \
39 (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
41 #define ROUND_TO_ALLOCATION_GRANULARITY(Size) \
42 (((ULONG_PTR)(Size) + MM_ALLOCATION_GRANULARITY - 1) \
43 & ~(MM_ALLOCATION_GRANULARITY - 1))
46 // Macro for generating pool tags
48 #define TAG(A, B, C, D) \
49 (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
51 #ifndef NTOS_MODE_USER
54 // Virtual Memory Flags
56 #define MEM_WRITE_WATCH 0x200000
57 #define MEM_PHYSICAL 0x400000
58 #define MEM_ROTATE 0x800000
59 #define MEM_IMAGE SEC_IMAGE
62 // Section Flags for NtCreateSection
64 #define SEC_NO_CHANGE 0x400000
65 #define SEC_FILE 0x800000
66 #define SEC_IMAGE 0x1000000
67 #define SEC_PROTECTED_IMAGE 0x2000000
68 #define SEC_RESERVE 0x4000000
69 #define SEC_COMMIT 0x8000000
70 #define SEC_NOCACHE 0x10000000
71 #define SEC_WRITECOMBINE 0x40000000
72 #define SEC_LARGE_PAGES 0x80000000
74 #define SEC_BASED 0x200000
77 // Section Inherit Flags for NtCreateSection
79 typedef enum _SECTION_INHERIT
88 typedef enum _POOL_TYPE
92 NonPagedPoolMustSucceed
,
94 NonPagedPoolCacheAligned
,
95 PagedPoolCacheAligned
,
96 NonPagedPoolCacheAlignedMustS
,
98 NonPagedPoolSession
= 32,
100 NonPagedPoolMustSucceedSession
,
101 DontUseThisTypeSession
,
102 NonPagedPoolCacheAlignedSession
,
103 PagedPoolCacheAlignedSession
,
104 NonPagedPoolCacheAlignedMustSSession
109 // Per Processor Non Paged Lookaside List IDs
111 typedef enum _PP_NPAGED_LOOKASIDE_NUMBER
113 LookasideSmallIrpList
= 0,
114 LookasideLargeIrpList
= 1,
115 LookasideMdlList
= 2,
116 LookasideCreateInfoList
= 3,
117 LookasideNameBufferList
= 4,
118 LookasideTwilightList
= 5,
119 LookasideCompletionList
= 6,
120 LookasideMaximumList
= 7
121 } PP_NPAGED_LOOKASIDE_NUMBER
;
124 // Memory Information Classes for NtQueryVirtualMemory
126 typedef enum _MEMORY_INFORMATION_CLASS
128 MemoryBasicInformation
,
129 MemoryWorkingSetList
,
131 MemoryBasicVlmInformation
132 } MEMORY_INFORMATION_CLASS
;
135 // Section Information Clasess for NtQuerySection
137 typedef enum _SECTION_INFORMATION_CLASS
139 SectionBasicInformation
,
140 SectionImageInformation
,
141 } SECTION_INFORMATION_CLASS
;
143 #ifdef NTOS_MODE_USER
146 // Virtual Memory Counters
148 typedef struct _VM_COUNTERS
150 SIZE_T PeakVirtualSize
;
152 ULONG PageFaultCount
;
153 SIZE_T PeakWorkingSetSize
;
154 SIZE_T WorkingSetSize
;
155 SIZE_T QuotaPeakPagedPoolUsage
;
156 SIZE_T QuotaPagedPoolUsage
;
157 SIZE_T QuotaPeakNonPagedPoolUsage
;
158 SIZE_T QuotaNonPagedPoolUsage
;
159 SIZE_T PagefileUsage
;
160 SIZE_T PeakPagefileUsage
;
161 } VM_COUNTERS
, *PVM_COUNTERS
;
163 typedef struct _VM_COUNTERS_EX
165 SIZE_T PeakVirtualSize
;
167 ULONG PageFaultCount
;
168 SIZE_T PeakWorkingSetSize
;
169 SIZE_T WorkingSetSize
;
170 SIZE_T QuotaPeakPagedPoolUsage
;
171 SIZE_T QuotaPagedPoolUsage
;
172 SIZE_T QuotaPeakNonPagedPoolUsage
;
173 SIZE_T QuotaNonPagedPoolUsage
;
174 SIZE_T PagefileUsage
;
175 SIZE_T PeakPagefileUsage
;
177 } VM_COUNTERS_EX
, *PVM_COUNTERS_EX
;
181 // List of Working Sets
183 typedef struct _MEMORY_WORKING_SET_LIST
186 ULONG WorkingSetList
[1];
187 } MEMORY_WORKING_SET_LIST
, *PMEMORY_WORKING_SET_LIST
;
190 // Memory Information Structures for NtQueryVirtualMemory
194 UNICODE_STRING SectionFileName
;
195 WCHAR NameBuffer
[ANYSIZE_ARRAY
];
196 } MEMORY_SECTION_NAME
, *PMEMORY_SECTION_NAME
;
199 // Section Information Structures for NtQuerySection
201 typedef struct _SECTION_BASIC_INFORMATION
206 } SECTION_BASIC_INFORMATION
, *PSECTION_BASIC_INFORMATION
;
208 typedef struct _SECTION_IMAGE_INFORMATION
210 PVOID TransferAddress
;
212 ULONG MaximumStackSize
;
213 ULONG CommittedStackSize
;
215 USHORT SubSystemMinorVersion
;
216 USHORT SubSystemMajorVersion
;
218 USHORT ImageCharacteristics
;
219 USHORT DllChracteristics
;
221 UCHAR ImageContainsCode
;
226 } SECTION_IMAGE_INFORMATION
, *PSECTION_IMAGE_INFORMATION
;
228 #ifndef NTOS_MODE_USER
233 typedef struct _MMPTE
240 MMPTE_PROTOTYPE Proto
;
242 MMPTE_TRANSITION Trans
;
243 MMPTE_SUBSECTION Subsect
;
249 // Section Information structure
251 typedef struct _MI_EXTRA_IMAGE_INFORMATION
254 } MI_EXTRA_IMAGE_INFORMATION
, *PMI_EXTRA_IMAGE_INFORMATION
;
256 typedef struct _MI_SECTION_IMAGE_INFORMATION
258 SECTION_IMAGE_INFORMATION ExportedImageInformation
;
259 MI_EXTRA_IMAGE_INFORMATION InternalImageInformation
;
260 } MI_SECTION_IMAGE_INFORMATION
, *PMI_SECTION_IMAGE_INFORMATION
;
263 // Section Extension Information
265 typedef struct _MMEXTEND_INFO
267 ULONGLONG CommittedSize
;
268 ULONG ReferenceCount
;
269 } MMEXTEND_INFO
, *PMMEXTEND_INFO
;
272 // Segment and Segment Flags
274 typedef struct _SEGMENT_FLAGS
276 ULONG TotalNumberOfPtes4132
:10;
277 ULONG ExtraSharedWowSubsections
:1;
280 } SEGMENT_FLAGS
, *PSEGMENT_FLAGS
;
282 typedef struct _SEGMENT
284 struct _CONTROL_AREA
*ControlArea
;
285 ULONG TotalNumberOfPtes
;
286 ULONG NonExtendedPtes
;
288 ULONGLONG SizeOfSegment
;
289 MMPTE SegmentPteTemplate
;
290 ULONG NumberOfCommittedPages
;
291 PMMEXTEND_INFO ExtendInfo
;
292 SEGMENT_FLAGS SegmentFlags
;
296 ULONG ImageCommitment
;
297 PEPROCESS CreatingProcess
;
301 PMI_SECTION_IMAGE_INFORMATION ImageInformation
;
306 } SEGMENT
, *PSEGMENT
;
309 // Event Counter Structure
311 typedef struct _EVENT_COUNTER
315 LIST_ENTRY ListEntry
;
316 } EVENT_COUNTER
, *PEVENT_COUNTER
;
321 typedef struct _MMSECTION_FLAGS
323 ULONG BeingDeleted
:1;
324 ULONG BeingCreated
:1;
326 ULONG NoModifiedWriting
:1;
333 ULONG PhysicalMemory
:1;
339 ULONG UserReference
:1;
340 ULONG GlobalMemory
:1;
341 ULONG DeleteOnClose
:1;
342 ULONG FilePointerNull
:1;
343 ULONG DebugSymbolsLoaded
:1;
344 ULONG SetMappedFileIoComplete
:1;
345 ULONG CollidedFlush
:1;
348 ULONG ImageMappedInSystemSpace
:1;
349 ULONG UserWritable
:1;
351 ULONG GlobalOnlyPerSession
:1;
353 ULONG WriteCombined
:1;
355 } MMSECTION_FLAGS
, *PMMSECTION_FLAGS
;
357 typedef struct _MMSUBSECTION_FLAGS
361 ULONG SubsectionStatic
:1;
362 ULONG GlobalMemory
:1;
365 ULONG StartingSector4132
:10;
366 ULONG SectorEndOffset
:12;
367 } MMSUBSECTION_FLAGS
, *PMMSUBSECTION_FLAGS
;
370 // Control Area Structures
372 typedef struct _CONTROL_AREA
375 LIST_ENTRY DereferenceList
;
376 ULONG NumberOfSectionReferences
;
377 ULONG NumberOfPfnReferences
;
378 ULONG NumberOfMappedViews
;
379 ULONG NumberOfSystemCacheViews
;
380 ULONG NumberOfUserReferences
;
384 MMSECTION_FLAGS Flags
;
386 PFILE_OBJECT FilePointer
;
387 PEVENT_COUNTER WaitingForDeletion
;
388 USHORT ModifiedWriteCount
;
389 USHORT FlushInProgressCount
;
390 ULONG WritableUserReferences
;
392 } CONTROL_AREA
, *PCONTROL_AREA
;
394 typedef struct _LARGE_CONTROL_AREA
397 LIST_ENTRY DereferenceList
;
398 ULONG NumberOfSectionReferences
;
399 ULONG NumberOfPfnReferences
;
400 ULONG NumberOfMappedViews
;
401 ULONG NumberOfSystemCacheViews
;
402 ULONG NumberOfUserReferences
;
406 MMSECTION_FLAGS Flags
;
408 PFILE_OBJECT FilePointer
;
409 PEVENT_COUNTER WaitingForDeletion
;
410 USHORT ModifiedWriteCount
;
411 USHORT FlushInProgressCount
;
412 ULONG WritableUserReferences
;
415 LIST_ENTRY UserGlobalList
;
417 } LARGE_CONTROL_AREA
, *PLARGE_CONTROL_AREA
;
422 typedef struct _SUBSECTION
424 PCONTROL_AREA ControlArea
;
428 MMSUBSECTION_FLAGS SubsectionFlags
;
430 ULONG StartingSector
;
431 PMMPTE SubsectionBase
;
433 ULONG PtesInSubsection
;
434 struct _SUBSECTION
*NextSubSection
;
435 } SUBSECTION
, *PSUBSECTION
;
440 typedef struct _SEGMENT_OBJECT
443 ULONG TotalNumberOfPtes
;
444 LARGE_INTEGER SizeOfSegment
;
445 ULONG NonExtendedPtes
;
446 ULONG ImageCommitment
;
447 PCONTROL_AREA ControlArea
;
448 PSUBSECTION Subsection
;
449 PLARGE_CONTROL_AREA LargeControlArea
;
450 PMMSECTION_FLAGS MmSectionFlags
;
451 PMMSUBSECTION_FLAGS MmSubSectionFlags
;
452 } SEGMENT_OBJECT
, *PSEGMENT_OBJECT
;
457 typedef struct _SECTION_OBJECT
463 PSEGMENT_OBJECT Segment
;
464 } SECTION_OBJECT
, *PSECTION_OBJECT
;
467 // Generic Address Range Structure
469 typedef struct _ADDRESS_RANGE
476 } ADDRESS_RANGE
, *PADDRESS_RANGE
;
479 // Node in Memory Manager's AVL Table
481 typedef struct _MMADDRESS_NODE
486 struct _MMADDRESS_NODE
*Parent
;
488 struct _MMADDRESS_NODE
*LeftChild
;
489 struct _MMADDRESS_NODE
*RightChild
;
492 } MMADDRESS_NODE
, *PMMADDRESS_NODE
;
495 // Memory Manager AVL Table for VADs and other descriptors
497 typedef struct _MM_AVL_TABLE
499 MMADDRESS_NODE BalancedRoot
;
502 ULONG NumberGenericTableElements
:24;
505 } MM_AVL_TABLE
, *PMM_AVL_TABLE
;
508 // Memory Manager Working Set Structures
510 typedef struct _MMWSLENTRY
514 ULONG LockedInMemory
:1;
519 ULONG VirtualPageNumber
:14;
520 } MMWSLENTRY
, *PMMWSLENTRY
;
522 typedef struct _MMWSLE
526 PVOID VirtualAddress
;
532 typedef struct _MMWSLE_HASH
536 } MMWSLE_HASH
, *PMMWSLE_HASH
;
538 typedef struct _MMWSL
545 ULONG LastInitializedWsle
;
547 PMMWSLE_HASH HashTable
;
549 ULONG NumberOfCommittedPageTables
;
550 PVOID HashTableStart
;
551 PVOID HighestPermittedHashAddress
;
552 ULONG NumberOfImageWaiters
;
554 USHORT UsedPageTableEntries
[768];
555 ULONG CommittedPageTables
[24];
559 // Flags for Memory Support Structure
561 typedef struct _MMSUPPORT_FLAGS
563 ULONG SessionSpace
:1;
564 ULONG BeingTrimmed
:1;
565 ULONG SessionLeader
:1;
567 ULONG WorkingSetHard
:1;
568 ULONG AddressSpaceBeingDeleted
:1;
570 ULONG AllowWorkingSetAdjustment
:8;
571 ULONG MemoryPriority
:8;
572 } MMSUPPORT_FLAGS
, *PMMSUPPORT_FLAGS
;
575 // Per-Process Memory Manager Data
577 typedef struct _MMSUPPORT
579 LARGE_INTEGER LastTrimTime
;
580 MMSUPPORT_FLAGS Flags
;
581 ULONG PageFaultCount
;
582 ULONG PeakWorkingSetSize
;
583 ULONG WorkingSetSize
;
584 ULONG MinimumWorkingSetSize
;
585 ULONG MaximumWorkingSetSize
;
586 PMMWSL MmWorkingSetList
;
587 LIST_ENTRY WorkingSetExpansionLinks
;
589 ULONG NextEstimationSlot
;
591 ULONG EstimatedAvailable
;
592 ULONG GrowthSinceLastEstimate
;
593 } MMSUPPORT
, *PMMSUPPORT
;
596 // Memory Information Types
598 typedef struct _MEMORY_BASIC_INFORMATION
601 PVOID AllocationBase
;
602 ULONG AllocationProtect
;
607 } MEMORY_BASIC_INFORMATION
,*PMEMORY_BASIC_INFORMATION
;
610 // Default heap size values. For user mode, these values are copied to a new
611 // process's PEB by the kernel in MmCreatePeb. In kernel mode, RtlCreateHeap
612 // reads these variables directly.
614 // These variables should be considered "const"; they are written only once,
615 // during MmInitSystem.
617 extern SIZE_T MmHeapSegmentReserve
;
618 extern SIZE_T MmHeapSegmentCommit
;
619 extern SIZE_T MmHeapDeCommitTotalFreeThreshold
;
620 extern SIZE_T MmHeapDeCommitFreeBlockThreshold
;
623 // Section Object Type
625 extern POBJECT_TYPE MmSectionObjectType
;
627 #endif // !NTOS_MODE_USER