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
;
355 typedef struct _MMSUBSECTION_FLAGS2
357 ULONG SubsectionAccessed
:1;
358 ULONG SubsectionConverted
:1;
360 } MMSUBSECTION_FLAGS2
;
363 // Control Area Structures
365 typedef struct _CONTROL_AREA
368 LIST_ENTRY DereferenceList
;
369 ULONG NumberOfSectionReferences
;
370 ULONG NumberOfPfnReferences
;
371 ULONG NumberOfMappedViews
;
372 ULONG NumberOfSystemCacheViews
;
373 ULONG NumberOfUserReferences
;
377 MMSECTION_FLAGS Flags
;
379 PFILE_OBJECT FilePointer
;
380 PEVENT_COUNTER WaitingForDeletion
;
381 USHORT ModifiedWriteCount
;
382 USHORT FlushInProgressCount
;
383 ULONG WritableUserReferences
;
385 } CONTROL_AREA
, *PCONTROL_AREA
;
387 typedef struct _LARGE_CONTROL_AREA
390 LIST_ENTRY DereferenceList
;
391 ULONG NumberOfSectionReferences
;
392 ULONG NumberOfPfnReferences
;
393 ULONG NumberOfMappedViews
;
394 ULONG NumberOfSystemCacheViews
;
395 ULONG NumberOfUserReferences
;
399 MMSECTION_FLAGS Flags
;
401 PFILE_OBJECT FilePointer
;
402 PEVENT_COUNTER WaitingForDeletion
;
403 USHORT ModifiedWriteCount
;
404 USHORT FlushInProgressCount
;
405 ULONG WritableUserReferences
;
408 LIST_ENTRY UserGlobalList
;
410 } LARGE_CONTROL_AREA
, *PLARGE_CONTROL_AREA
;
413 // Subsection and Mapped Subsection
415 typedef struct _SUBSECTION
417 PCONTROL_AREA ControlArea
;
421 MMSUBSECTION_FLAGS SubsectionFlags
;
423 ULONG StartingSector
;
424 ULONG NumberOfFullSectors
;
425 PMMPTE SubsectionBase
;
427 ULONG PtesInSubsection
;
428 struct _SUBSECTION
*NextSubsection
;
429 } SUBSECTION
, *PSUBSECTION
;
431 typedef struct _MSUBSECTION
433 PCONTROL_AREA ControlArea
;
437 MMSUBSECTION_FLAGS SubsectionFlags
;
439 ULONG StartingSector
;
440 ULONG NumberOfFullSectors
;
441 PMMPTE SubsectionBase
;
443 ULONG PtesInSubsection
;
444 struct _SUBSECTION
*NextSubsection
;
445 LIST_ENTRY DereferenceList
;
446 ULONG_PTR NumberOfMappedViews
;
450 MMSUBSECTION_FLAGS2 SubsectionFlags2
;
452 } MSUBSECTION
, *PMSUBSECTION
;
457 typedef struct _SEGMENT_OBJECT
460 ULONG TotalNumberOfPtes
;
461 LARGE_INTEGER SizeOfSegment
;
462 ULONG NonExtendedPtes
;
463 ULONG ImageCommitment
;
464 PCONTROL_AREA ControlArea
;
465 PSUBSECTION Subsection
;
466 PLARGE_CONTROL_AREA LargeControlArea
;
467 PMMSECTION_FLAGS MmSectionFlags
;
468 PMMSUBSECTION_FLAGS MmSubSectionFlags
;
469 } SEGMENT_OBJECT
, *PSEGMENT_OBJECT
;
474 typedef struct _SECTION_OBJECT
480 PSEGMENT_OBJECT Segment
;
481 } SECTION_OBJECT
, *PSECTION_OBJECT
;
484 // Generic Address Range Structure
486 typedef struct _ADDRESS_RANGE
493 } ADDRESS_RANGE
, *PADDRESS_RANGE
;
496 // Node in Memory Manager's AVL Table
498 typedef struct _MMADDRESS_NODE
503 struct _MMADDRESS_NODE
*Parent
;
505 struct _MMADDRESS_NODE
*LeftChild
;
506 struct _MMADDRESS_NODE
*RightChild
;
509 } MMADDRESS_NODE
, *PMMADDRESS_NODE
;
512 // Memory Manager AVL Table for VADs and other descriptors
514 typedef struct _MM_AVL_TABLE
516 MMADDRESS_NODE BalancedRoot
;
519 ULONG NumberGenericTableElements
:24;
522 } MM_AVL_TABLE
, *PMM_AVL_TABLE
;
525 // Actual Section Object
527 typedef struct _SECTION
529 MMADDRESS_NODE Address
;
531 LARGE_INTEGER SizeOfSection
;
535 MMSECTION_FLAGS Flags
;
537 ULONG InitialPageProtection
;
538 } SECTION
, *PSECTION
;
541 // Memory Manager Working Set Structures
543 typedef struct _MMWSLENTRY
547 ULONG LockedInMemory
:1;
552 ULONG VirtualPageNumber
:14;
553 } MMWSLENTRY
, *PMMWSLENTRY
;
555 typedef struct _MMWSLE
559 PVOID VirtualAddress
;
565 typedef struct _MMWSLE_HASH
569 } MMWSLE_HASH
, *PMMWSLE_HASH
;
571 typedef struct _MMWSL
578 ULONG LastInitializedWsle
;
579 ULONG NonDirectCount
;
580 PMMWSLE_HASH HashTable
;
582 ULONG NumberOfCommittedPageTables
;
583 PVOID HashTableStart
;
584 PVOID HighestPermittedHashAddress
;
585 ULONG NumberOfImageWaiters
;
587 USHORT UsedPageTableEntries
[768];
588 ULONG CommittedPageTables
[24];
592 // Flags for Memory Support Structure
594 typedef struct _MMSUPPORT_FLAGS
596 ULONG SessionSpace
:1;
597 ULONG BeingTrimmed
:1;
598 ULONG SessionLeader
:1;
600 ULONG MaximumWorkingSetHard
:1;
602 ULONG MinimumworkingSetHard
:1;
604 ULONG MemoryPriority
:8;
605 ULONG GrowWsleHash
:1;
606 ULONG AcquiredUnsafe
:1;
608 } MMSUPPORT_FLAGS
, *PMMSUPPORT_FLAGS
;
611 // Per-Process Memory Manager Data
613 typedef struct _MMSUPPORT
615 #if (NTDDI_VERSION >= NTDDI_WS03)
616 LIST_ENTRY WorkingSetExpansionLinks
;
618 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
619 USHORT LastTrimpStamp
;
620 USHORT NextPageColor
;
622 LARGE_INTEGER LastTrimTime
;
624 MMSUPPORT_FLAGS Flags
;
625 ULONG PageFaultCount
;
626 ULONG PeakWorkingSetSize
;
627 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
630 ULONG GrowthSinceLastEstimate
;
632 ULONG MinimumWorkingSetSize
;
633 ULONG MaximumWorkingSetSize
;
634 PMMWSL VmWorkingSetList
;
635 #if (NTDDI_VERSION < NTDDI_WS03)
636 LIST_ENTRY WorkingSetExpansionLinks
;
639 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
641 ULONG WorkingSetPrivateSize
;
642 ULONG WorkingSetSizeOverhead
;
644 ULONG NextEstimationSlot
;
646 ULONG EstimatedAvailable
;
648 ULONG WorkingSetSize
;
649 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
652 EX_PUSH_LOCK WorkingSetMutex
;
653 #if (NTDDI_VERSION >= NTDDI_LONGHORN)
656 } MMSUPPORT
, *PMMSUPPORT
;
659 // Memory Information Types
661 typedef struct _MEMORY_BASIC_INFORMATION
664 PVOID AllocationBase
;
665 ULONG AllocationProtect
;
670 } MEMORY_BASIC_INFORMATION
,*PMEMORY_BASIC_INFORMATION
;
673 // Driver Verifier Data
675 typedef struct _MM_DRIVER_VERIFIER_DATA
679 ULONG AcquireSpinLocks
;
680 ULONG SynchronizeExecutions
;
681 ULONG AllocationsAttempted
;
682 ULONG AllocationsSucceeded
;
683 ULONG AllocationsSucceededSpecialPool
;
684 ULONG AllocationsWithNoTag
;
687 ULONG AllocationsFailed
;
688 ULONG AllocationsFailedDeliberately
;
693 ULONG CurrentPagedPoolAllocations
;
694 ULONG CurrentNonPagedPoolAllocations
;
695 ULONG PeakPagedPoolAllocations
;
696 ULONG PeakNonPagedPoolAllocations
;
699 ULONG PeakPagedBytes
;
700 ULONG PeakNonPagedBytes
;
701 ULONG BurstAllocationsFailedDeliberately
;
704 } MM_DRIVER_VERIFIER_DATA
, *PMM_DRIVER_VERIFIER_DATA
;
707 // Internal Driver Verifier Table Data
709 typedef struct _DRIVER_SPECIFIED_VERIFIER_THUNKS
711 LIST_ENTRY ListEntry
;
712 struct _LDR_DATA_TABLE_ENTRY
*DataTableEntry
;
713 ULONG NumberOfThunks
;
714 } DRIVER_SPECIFIED_VERIFIER_THUNKS
, *PDRIVER_SPECIFIED_VERIFIER_THUNKS
;
717 // Default heap size values. For user mode, these values are copied to a new
718 // process's PEB by the kernel in MmCreatePeb. In kernel mode, RtlCreateHeap
719 // reads these variables directly.
721 // These variables should be considered "const"; they are written only once,
722 // during MmInitSystem.
724 extern SIZE_T MmHeapSegmentReserve
;
725 extern SIZE_T MmHeapSegmentCommit
;
726 extern SIZE_T MmHeapDeCommitTotalFreeThreshold
;
727 extern SIZE_T MmHeapDeCommitFreeBlockThreshold
;
730 // Section Object Type
732 extern POBJECT_TYPE MmSectionObjectType
;
734 #endif // !NTOS_MODE_USER