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>
30 // Page-Rounding Macros
32 #define PAGE_ROUND_DOWN(x) \
33 (((ULONG_PTR)(x))&(~(PAGE_SIZE-1)))
34 #define PAGE_ROUND_UP(x) \
35 ( (((ULONG_PTR)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1)) )
37 #define ROUND_TO_PAGES(Size) \
38 (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
40 #define ROUND_TO_ALLOCATION_GRANULARITY(Size) \
41 (((ULONG_PTR)(Size) + MM_ALLOCATION_GRANULARITY - 1) \
42 & ~(MM_ALLOCATION_GRANULARITY - 1))
45 // Macro for generating pool tags
47 #define TAG(A, B, C, D) \
48 (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
50 #ifndef NTOS_MODE_USER
53 // Virtual Memory Flags
55 #define MEM_WRITE_WATCH 0x200000
56 #define MEM_PHYSICAL 0x400000
57 #define MEM_ROTATE 0x800000
58 #define MEM_IMAGE SEC_IMAGE
59 #define MEM_DOS_LIM 0x40000000
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 Extension Information
251 typedef struct _MMEXTEND_INFO
253 ULONGLONG CommittedSize
;
254 ULONG ReferenceCount
;
255 } MMEXTEND_INFO
, *PMMEXTEND_INFO
;
258 // Segment and Segment Flags
260 typedef struct _SEGMENT_FLAGS
262 ULONG TotalNumberOfPtes4132
:10;
263 ULONG ExtraSharedWowSubsections
:1;
266 } SEGMENT_FLAGS
, *PSEGMENT_FLAGS
;
268 typedef struct _SEGMENT
270 struct _CONTROL_AREA
*ControlArea
;
271 ULONG TotalNumberOfPtes
;
272 ULONG NonExtendedPtes
;
274 ULONGLONG SizeOfSegment
;
275 MMPTE SegmentPteTemplate
;
276 ULONG NumberOfCommittedPages
;
277 PMMEXTEND_INFO ExtendInfo
;
278 SEGMENT_FLAGS SegmentFlags
;
282 SIZE_T ImageCommitment
;
283 PEPROCESS CreatingProcess
;
287 PSECTION_IMAGE_INFORMATION ImageInformation
;
292 } SEGMENT
, *PSEGMENT
;
295 // Event Counter Structure
297 typedef struct _EVENT_COUNTER
301 LIST_ENTRY ListEntry
;
302 } EVENT_COUNTER
, *PEVENT_COUNTER
;
307 typedef struct _MMSECTION_FLAGS
309 ULONG BeingDeleted
:1;
310 ULONG BeingCreated
:1;
312 ULONG NoModifiedWriting
:1;
319 ULONG PhysicalMemory
:1;
325 ULONG UserReference
:1;
326 ULONG GlobalMemory
:1;
327 ULONG DeleteOnClose
:1;
328 ULONG FilePointerNull
:1;
329 ULONG DebugSymbolsLoaded
:1;
330 ULONG SetMappedFileIoComplete
:1;
331 ULONG CollidedFlush
:1;
334 ULONG ImageMappedInSystemSpace
:1;
335 ULONG UserWritable
:1;
337 ULONG GlobalOnlyPerSession
:1;
339 ULONG WriteCombined
:1;
341 } MMSECTION_FLAGS
, *PMMSECTION_FLAGS
;
343 typedef struct _MMSUBSECTION_FLAGS
347 ULONG SubsectionStatic
:1;
348 ULONG GlobalMemory
:1;
351 ULONG StartingSector4132
:10;
352 ULONG SectorEndOffset
:12;
353 } MMSUBSECTION_FLAGS
, *PMMSUBSECTION_FLAGS
;
356 // Control Area Structures
358 typedef struct _CONTROL_AREA
361 LIST_ENTRY DereferenceList
;
362 ULONG NumberOfSectionReferences
;
363 ULONG NumberOfPfnReferences
;
364 ULONG NumberOfMappedViews
;
365 ULONG NumberOfSystemCacheViews
;
366 ULONG NumberOfUserReferences
;
370 MMSECTION_FLAGS Flags
;
372 PFILE_OBJECT FilePointer
;
373 PEVENT_COUNTER WaitingForDeletion
;
374 USHORT ModifiedWriteCount
;
375 USHORT FlushInProgressCount
;
376 ULONG WritableUserReferences
;
378 } CONTROL_AREA
, *PCONTROL_AREA
;
380 typedef struct _LARGE_CONTROL_AREA
383 LIST_ENTRY DereferenceList
;
384 ULONG NumberOfSectionReferences
;
385 ULONG NumberOfPfnReferences
;
386 ULONG NumberOfMappedViews
;
387 ULONG NumberOfSystemCacheViews
;
388 ULONG NumberOfUserReferences
;
392 MMSECTION_FLAGS Flags
;
394 PFILE_OBJECT FilePointer
;
395 PEVENT_COUNTER WaitingForDeletion
;
396 USHORT ModifiedWriteCount
;
397 USHORT FlushInProgressCount
;
398 ULONG WritableUserReferences
;
401 LIST_ENTRY UserGlobalList
;
403 } LARGE_CONTROL_AREA
, *PLARGE_CONTROL_AREA
;
408 typedef struct _SUBSECTION
410 PCONTROL_AREA ControlArea
;
414 MMSUBSECTION_FLAGS SubsectionFlags
;
416 ULONG StartingSector
;
417 ULONG NumberOfFullSectors
;
418 PMMPTE SubsectionBase
;
420 ULONG PtesInSubsection
;
421 struct _SUBSECTION
*NextSubSection
;
422 } SUBSECTION
, *PSUBSECTION
;
427 typedef struct _SEGMENT_OBJECT
430 ULONG TotalNumberOfPtes
;
431 LARGE_INTEGER SizeOfSegment
;
432 ULONG NonExtendedPtes
;
433 ULONG ImageCommitment
;
434 PCONTROL_AREA ControlArea
;
435 PSUBSECTION Subsection
;
436 PLARGE_CONTROL_AREA LargeControlArea
;
437 PMMSECTION_FLAGS MmSectionFlags
;
438 PMMSUBSECTION_FLAGS MmSubSectionFlags
;
439 } SEGMENT_OBJECT
, *PSEGMENT_OBJECT
;
444 typedef struct _SECTION_OBJECT
450 PSEGMENT_OBJECT Segment
;
451 } SECTION_OBJECT
, *PSECTION_OBJECT
;
454 // Generic Address Range Structure
456 typedef struct _ADDRESS_RANGE
463 } ADDRESS_RANGE
, *PADDRESS_RANGE
;
466 // Node in Memory Manager's AVL Table
468 typedef struct _MMADDRESS_NODE
473 struct _MMADDRESS_NODE
*Parent
;
475 struct _MMADDRESS_NODE
*LeftChild
;
476 struct _MMADDRESS_NODE
*RightChild
;
479 } MMADDRESS_NODE
, *PMMADDRESS_NODE
;
482 // Memory Manager AVL Table for VADs and other descriptors
484 typedef struct _MM_AVL_TABLE
486 MMADDRESS_NODE BalancedRoot
;
489 ULONG NumberGenericTableElements
:24;
492 } MM_AVL_TABLE
, *PMM_AVL_TABLE
;
495 // Actual Section Object
497 typedef struct _SECTION
499 MMADDRESS_NODE Address
;
501 LARGE_INTEGER SizeOfSection
;
505 MMSECTION_FLAGS Flags
;
507 ULONG InitialPageProtection
;
508 } SECTION
, *PSECTION
;
511 // Memory Manager Working Set Structures
513 typedef struct _MMWSLENTRY
517 ULONG LockedInMemory
:1;
522 ULONG VirtualPageNumber
:14;
523 } MMWSLENTRY
, *PMMWSLENTRY
;
525 typedef struct _MMWSLE
529 PVOID VirtualAddress
;
535 typedef struct _MMWSLE_HASH
539 } MMWSLE_HASH
, *PMMWSLE_HASH
;
541 typedef struct _MMWSL
548 ULONG LastInitializedWsle
;
549 ULONG NonDirectCount
;
550 PMMWSLE_HASH HashTable
;
552 ULONG NumberOfCommittedPageTables
;
553 PVOID HashTableStart
;
554 PVOID HighestPermittedHashAddress
;
555 ULONG NumberOfImageWaiters
;
557 USHORT UsedPageTableEntries
[768];
558 ULONG CommittedPageTables
[24];
562 // Flags for Memory Support Structure
564 typedef struct _MMSUPPORT_FLAGS
566 ULONG SessionSpace
:1;
567 ULONG BeingTrimmed
:1;
568 ULONG SessionLeader
:1;
570 ULONG MaximumWorkingSetHard
:1;
572 ULONG MinimumworkingSetHard
:1;
574 ULONG MemoryPriority
:8;
575 ULONG GrowWsleHash
:1;
576 ULONG AcquiredUnsafe
:1;
578 } MMSUPPORT_FLAGS
, *PMMSUPPORT_FLAGS
;
581 // Per-Process Memory Manager Data
583 typedef struct _MMSUPPORT
585 #if (NTDDI_VERSION >= NTDDI_WS03)
586 LIST_ENTRY WorkingSetExpansionLinks
;
588 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
589 USHORT LastTrimpStamp
;
590 USHORT NextPageColor
;
592 LARGE_INTEGER LastTrimTime
;
594 MMSUPPORT_FLAGS Flags
;
595 ULONG PageFaultCount
;
596 ULONG PeakWorkingSetSize
;
597 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
600 ULONG GrowthSinceLastEstimate
;
602 ULONG MinimumWorkingSetSize
;
603 ULONG MaximumWorkingSetSize
;
604 PMMWSL VmWorkingSetList
;
605 #if (NTDDI_VERSION < NTDDI_WS03)
606 LIST_ENTRY WorkingSetExpansionLinks
;
609 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
611 ULONG WorkingSetPrivateSize
;
612 ULONG WorkingSetSizeOverhead
;
614 ULONG NextEstimationSlot
;
616 ULONG EstimatedAvailable
;
618 ULONG WorkingSetSize
;
619 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
622 EX_PUSH_LOCK WorkingSetMutex
;
623 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
626 } MMSUPPORT
, *PMMSUPPORT
;
629 // Memory Information Types
631 typedef struct _MEMORY_BASIC_INFORMATION
634 PVOID AllocationBase
;
635 ULONG AllocationProtect
;
640 } MEMORY_BASIC_INFORMATION
,*PMEMORY_BASIC_INFORMATION
;
643 // Driver Verifier Data
645 typedef struct _MM_DRIVER_VERIFIER_DATA
649 ULONG AcquireSpinLocks
;
650 ULONG SynchronizeExecutions
;
651 ULONG AllocationsAttempted
;
652 ULONG AllocationsSucceeded
;
653 ULONG AllocationsSucceededSpecialPool
;
654 ULONG AllocationsWithNoTag
;
657 ULONG AllocationsFailed
;
658 ULONG AllocationsFailedDeliberately
;
663 ULONG CurrentPagedPoolAllocations
;
664 ULONG CurrentNonPagedPoolAllocations
;
665 ULONG PeakPagedPoolAllocations
;
666 ULONG PeakNonPagedPoolAllocations
;
669 ULONG PeakPagedBytes
;
670 ULONG PeakNonPagedBytes
;
671 ULONG BurstAllocationsFailedDeliberately
;
674 } MM_DRIVER_VERIFIER_DATA
, *PMM_DRIVER_VERIFIER_DATA
;
677 // Internal Driver Verifier Table Data
679 typedef struct _DRIVER_SPECIFIED_VERIFIER_THUNKS
681 LIST_ENTRY ListEntry
;
682 struct _LDR_DATA_TABLE_ENTRY
*DataTableEntry
;
683 ULONG NumberOfThunks
;
684 } DRIVER_SPECIFIED_VERIFIER_THUNKS
, *PDRIVER_SPECIFIED_VERIFIER_THUNKS
;
687 // Default heap size values. For user mode, these values are copied to a new
688 // process's PEB by the kernel in MmCreatePeb. In kernel mode, RtlCreateHeap
689 // reads these variables directly.
691 // These variables should be considered "const"; they are written only once,
692 // during MmInitSystem.
694 extern SIZE_T MmHeapSegmentReserve
;
695 extern SIZE_T MmHeapSegmentCommit
;
696 extern SIZE_T MmHeapDeCommitTotalFreeThreshold
;
697 extern SIZE_T MmHeapDeCommitFreeBlockThreshold
;
700 // Section Object Type
702 extern POBJECT_TYPE MmSectionObjectType
;
704 #endif // !NTOS_MODE_USER