3ff541be0d53d162fd56e922e176ed18a39548a1
[reactos.git] / reactos / include / ndk / mmtypes.h
1 /*++ NDK Version: 0098
2
3 Copyright (c) Alex Ionescu. All rights reserved.
4
5 Header Name:
6
7 mmtypes.h
8
9 Abstract:
10
11 Type definitions for the Memory Manager
12
13 Author:
14
15 Alex Ionescu (alexi@tinykrnl.org) - Updated - 27-Feb-2006
16
17 --*/
18
19 #ifndef _MMTYPES_H
20 #define _MMTYPES_H
21
22 //
23 // Dependencies
24 //
25 #include <umtypes.h>
26 #include <arch/mmtypes.h>
27
28 //
29 // Page-Rounding Macros
30 //
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) )
34 #ifdef NTOS_MODE_USER
35 #define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
36 #endif
37 #define ROUND_TO_ALLOCATION_GRANULARITY(Size) (((ULONG_PTR)(Size) + MM_ALLOCATION_GRANULARITY - 1) \
38 & ~(MM_ALLOCATION_GRANULARITY - 1))
39
40 //
41 // Macro for generating pool tags
42 //
43 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
44
45 #ifdef NTOS_MODE_USER
46
47 //
48 // Section Flags for NtCreateSection
49 //
50 #define SEC_BASED 0x00200000
51 #define SEC_NO_CHANGE 0x00400000
52
53 //
54 // Section Inherit Flags for NtCreateSection
55 //
56 typedef enum _SECTION_INHERIT
57 {
58 ViewShare = 1,
59 ViewUnmap = 2
60 } SECTION_INHERIT;
61
62 //
63 // Pool Types
64 //
65 typedef enum _POOL_TYPE
66 {
67 NonPagedPool,
68 PagedPool,
69 NonPagedPoolMustSucceed,
70 DontUseThisType,
71 NonPagedPoolCacheAligned,
72 PagedPoolCacheAligned,
73 NonPagedPoolCacheAlignedMustS,
74 MaxPoolType,
75 NonPagedPoolSession = 32,
76 PagedPoolSession,
77 NonPagedPoolMustSucceedSession,
78 DontUseThisTypeSession,
79 NonPagedPoolCacheAlignedSession,
80 PagedPoolCacheAlignedSession,
81 NonPagedPoolCacheAlignedMustSSession
82 } POOL_TYPE;
83 #endif
84
85 //
86 // Per Processor Non Paged Lookaside List IDs
87 //
88 typedef enum _PP_NPAGED_LOOKASIDE_NUMBER
89 {
90 LookasideSmallIrpList = 0,
91 LookasideLargeIrpList = 1,
92 LookasideMdlList = 2,
93 LookasideCreateInfoList = 3,
94 LookasideNameBufferList = 4,
95 LookasideTwilightList = 5,
96 LookasideCompletionList = 6,
97 LookasideMaximumList = 7
98 } PP_NPAGED_LOOKASIDE_NUMBER;
99
100 //
101 // Memory Information Classes for NtQueryVirtualMemory
102 //
103 typedef enum _MEMORY_INFORMATION_CLASS
104 {
105 MemoryBasicInformation,
106 MemoryWorkingSetList,
107 MemorySectionName,
108 MemoryBasicVlmInformation
109 } MEMORY_INFORMATION_CLASS;
110
111 //
112 // Section Information Clasess for NtQuerySection
113 //
114 typedef enum _SECTION_INFORMATION_CLASS
115 {
116 SectionBasicInformation,
117 SectionImageInformation,
118 } SECTION_INFORMATION_CLASS;
119
120 #ifdef NTOS_MODE_USER
121
122 //
123 // Virtual Memory Counters
124 //
125 typedef struct _VM_COUNTERS
126 {
127 SIZE_T PeakVirtualSize;
128 SIZE_T VirtualSize;
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;
139
140 typedef struct _VM_COUNTERS_EX
141 {
142 SIZE_T PeakVirtualSize;
143 SIZE_T VirtualSize;
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;
153 SIZE_T PrivateUsage;
154 } VM_COUNTERS_EX, *PVM_COUNTERS_EX;
155 #endif
156
157 //
158 // List of Working Sets
159 //
160 typedef struct _MEMORY_WORKING_SET_LIST
161 {
162 ULONG NumberOfPages;
163 ULONG WorkingSetList[1];
164 } MEMORY_WORKING_SET_LIST, *PMEMORY_WORKING_SET_LIST;
165
166 //
167 // Memory Information Structures for NtQueryVirtualMemory
168 //
169 typedef struct
170 {
171 UNICODE_STRING SectionFileName;
172 WCHAR NameBuffer[ANYSIZE_ARRAY];
173 } MEMORY_SECTION_NAME, *PMEMORY_SECTION_NAME;
174
175 //
176 // Section Information Structures for NtQuerySection
177 //
178 typedef struct _SECTION_BASIC_INFORMATION
179 {
180 PVOID BaseAddress;
181 ULONG Attributes;
182 LARGE_INTEGER Size;
183 } SECTION_BASIC_INFORMATION, *PSECTION_BASIC_INFORMATION;
184
185 typedef struct _SECTION_IMAGE_INFORMATION
186 {
187 PVOID TransferAddress;
188 ULONG ZeroBits;
189 ULONG MaximumStackSize;
190 ULONG CommittedStackSize;
191 ULONG SubsystemType;
192 USHORT SubSystemMinorVersion;
193 USHORT SubSystemMajorVersion;
194 ULONG GpValue;
195 USHORT ImageCharacteristics;
196 USHORT DllChracteristics;
197 USHORT Machine;
198 UCHAR ImageContainsCode;
199 UCHAR Spare1;
200 ULONG LoaderFlags;
201 ULONG ImageFileSIze;
202 ULONG Reserved[1];
203 } SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION;
204
205 #ifndef NTOS_MODE_USER
206
207 //
208 // PTE Structures
209 //
210 typedef struct _MMPTE
211 {
212 union
213 {
214 ULONG Long;
215 HARDWARE_PTE Flush;
216 MMPTE_HARDWARE Hard;
217 MMPTE_PROTOTYPE Proto;
218 MMPTE_SOFTWARE Soft;
219 MMPTE_TRANSITION Trans;
220 MMPTE_SUBSECTION Subsect;
221 MMPTE_LIST List;
222 };
223 } MMPTE, *PMMPTE;
224
225 //
226 // Section Information structure
227 //
228 typedef struct _MI_EXTRA_IMAGE_INFORMATION
229 {
230 ULONG SizeOfHeaders;
231 } MI_EXTRA_IMAGE_INFORMATION, *PMI_EXTRA_IMAGE_INFORMATION;
232
233 typedef struct _MI_SECTION_IMAGE_INFORMATION
234 {
235 SECTION_IMAGE_INFORMATION ExportedImageInformation;
236 MI_EXTRA_IMAGE_INFORMATION InternalImageInformation;
237 } MI_SECTION_IMAGE_INFORMATION, *PMI_SECTION_IMAGE_INFORMATION;
238
239 //
240 // Section Extension Information
241 //
242 typedef struct _MMEXTEND_INFO
243 {
244 ULONGLONG CommittedSize;
245 ULONG ReferenceCount;
246 } MMEXTEND_INFO, *PMMEXTEND_INFO;
247
248 //
249 // Segment and Segment Flags
250 //
251 typedef struct _SEGMENT_FLAGS
252 {
253 ULONG TotalNumberOfPtes4132:10;
254 ULONG ExtraSharedWowSubsections:1;
255 ULONG LargePages:1;
256 ULONG Spare:20;
257 } SEGMENT_FLAGS, *PSEGMENT_FLAGS;
258
259 typedef struct _SEGMENT
260 {
261 struct _CONTROL_AREA *ControlArea;
262 ULONG TotalNumberOfPtes;
263 ULONG NonExtendedPtes;
264 ULONG Spare0;
265 ULONGLONG SizeOfSegment;
266 MMPTE SegmentPteTemplate;
267 ULONG NumberOfCommittedPages;
268 PMMEXTEND_INFO ExtendInfo;
269 SEGMENT_FLAGS SegmentFlags;
270 PVOID BaseAddress;
271 union
272 {
273 ULONG ImageCommitment;
274 PEPROCESS CreatingProcess;
275 } u1;
276 union
277 {
278 PMI_SECTION_IMAGE_INFORMATION ImageInformation;
279 PVOID FirstMappedVa;
280 } u2;
281 PMMPTE PrototypePte;
282 MMPTE ThePtes[1];
283 } SEGMENT, *PSEGMENT;
284
285 //
286 // Event Counter Structure
287 //
288 typedef struct _EVENT_COUNTER
289 {
290 ULONG RefCount;
291 KEVENT Event;
292 LIST_ENTRY ListEntry;
293 } EVENT_COUNTER, *PEVENT_COUNTER;
294
295 //
296 // Flags
297 //
298 typedef struct _MMSECTION_FLAGS
299 {
300 ULONG BeingDeleted:1;
301 ULONG BeingCreated:1;
302 ULONG BeingPurged:1;
303 ULONG NoModifiedWriting:1;
304 ULONG FailAllIo:1;
305 ULONG Image:1;
306 ULONG Based:1;
307 ULONG File:1;
308 ULONG Networked:1;
309 ULONG NoCache:1;
310 ULONG PhysicalMemory:1;
311 ULONG CopyOnWrite:1;
312 ULONG Reserve:1;
313 ULONG Commit:1;
314 ULONG FloppyMedia:1;
315 ULONG WasPurged: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;
323 ULONG NoChange:1;
324 ULONG filler0:1;
325 ULONG ImageMappedInSystemSpace:1;
326 ULONG UserWritable:1;
327 ULONG Accessed:1;
328 ULONG GlobalOnlyPerSession:1;
329 ULONG Rom:1;
330 ULONG WriteCombined:1;
331 ULONG filler:1;
332 } MMSECTION_FLAGS, *PMMSECTION_FLAGS;
333
334 typedef struct _MMSUBSECTION_FLAGS
335 {
336 ULONG ReadOnly:1;
337 ULONG ReadWrite:1;
338 ULONG SubsectionStatic:1;
339 ULONG GlobalMemory:1;
340 ULONG Protection:5;
341 ULONG Spare:1;
342 ULONG StartingSector4132:10;
343 ULONG SectorEndOffset:12;
344 } MMSUBSECTION_FLAGS, *PMMSUBSECTION_FLAGS;
345
346 //
347 // Control Area Structures
348 //
349 typedef struct _CONTROL_AREA
350 {
351 PSEGMENT Segment;
352 LIST_ENTRY DereferenceList;
353 ULONG NumberOfSectionReferences;
354 ULONG NumberOfPfnReferences;
355 ULONG NumberOfMappedViews;
356 ULONG NumberOfSystemCacheViews;
357 ULONG NumberOfUserReferences;
358 union
359 {
360 ULONG LongFlags;
361 MMSECTION_FLAGS Flags;
362 } u;
363 PFILE_OBJECT FilePointer;
364 PEVENT_COUNTER WaitingForDeletion;
365 USHORT ModifiedWriteCount;
366 USHORT FlushInProgressCount;
367 ULONG WritableUserReferences;
368 ULONG QuadwordPad;
369 } CONTROL_AREA, *PCONTROL_AREA;
370
371 typedef struct _LARGE_CONTROL_AREA
372 {
373 PSEGMENT Segment;
374 LIST_ENTRY DereferenceList;
375 ULONG NumberOfSectionReferences;
376 ULONG NumberOfPfnReferences;
377 ULONG NumberOfMappedViews;
378 ULONG NumberOfSystemCacheViews;
379 ULONG NumberOfUserReferences;
380 union
381 {
382 ULONG LongFlags;
383 MMSECTION_FLAGS Flags;
384 } u;
385 PFILE_OBJECT FilePointer;
386 PEVENT_COUNTER WaitingForDeletion;
387 USHORT ModifiedWriteCount;
388 USHORT FlushInProgressCount;
389 ULONG WritableUserReferences;
390 ULONG QuadwordPad;
391 ULONG StartingFrame;
392 LIST_ENTRY UserGlobalList;
393 ULONG SessionId;
394 } LARGE_CONTROL_AREA, *PLARGE_CONTROL_AREA;
395
396 //
397 // Subsection
398 //
399 typedef struct _SUBSECTION
400 {
401 PCONTROL_AREA ControlArea;
402 union
403 {
404 ULONG LongFlags;
405 MMSUBSECTION_FLAGS SubsectionFlags;
406 } u;
407 ULONG StartingSector;
408 PMMPTE SubsectionBase;
409 ULONG UnusedPtes;
410 ULONG PtesInSubsection;
411 struct _SUBSECTION *NextSubSection;
412 } SUBSECTION, *PSUBSECTION;
413
414 //
415 // Segment Object
416 //
417 typedef struct _SEGMENT_OBJECT
418 {
419 PVOID BaseAddress;
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;
430
431 //
432 // Section Object
433 //
434 typedef struct _SECTION_OBJECT
435 {
436 PVOID StartingVa;
437 PVOID EndingVa;
438 PVOID LeftChild;
439 PVOID RightChild;
440 PSEGMENT_OBJECT Segment;
441 } SECTION_OBJECT, *PSECTION_OBJECT;
442
443 //
444 // Generic Address Range Structure
445 //
446 typedef struct _ADDRESS_RANGE
447 {
448 ULONG BaseAddrLow;
449 ULONG BaseAddrHigh;
450 ULONG LengthLow;
451 ULONG LengthHigh;
452 ULONG Type;
453 } ADDRESS_RANGE, *PADDRESS_RANGE;
454
455 //
456 // Node in Memory Manager's AVL Table
457 //
458 typedef struct _MMADDRESS_NODE
459 {
460 union
461 {
462 ULONG Balance:2;
463 struct _MMADDRESS_NODE *Parent;
464 } u1;
465 struct _MMADDRESS_NODE *LeftChild;
466 struct _MMADDRESS_NODE *RightChild;
467 ULONG StartingVpn;
468 ULONG EndingVpn;
469 } MMADDRESS_NODE, *PMMADDRESS_NODE;
470
471 //
472 // Memory Manager AVL Table for VADs and other descriptors
473 //
474 typedef struct _MM_AVL_TABLE
475 {
476 MMADDRESS_NODE BalancedRoot;
477 ULONG DepthOfTree:5;
478 ULONG Unused:3;
479 ULONG NumberGenericTableElements:24;
480 PVOID NodeHint;
481 PVOID NodeFreeHint;
482 } MM_AVL_TABLE, *PMM_AVL_TABLE;
483
484 //
485 // Memory Manager Working Set Structures
486 //
487 typedef struct _MMWSLENTRY
488 {
489 ULONG Valid:1;
490 ULONG LockedInWs:1;
491 ULONG LockedInMemory:1;
492 ULONG Protection:5;
493 ULONG Hashed:1;
494 ULONG Direct:1;
495 ULONG Age:2;
496 ULONG VirtualPageNumber:14;
497 } MMWSLENTRY, *PMMWSLENTRY;
498
499 typedef struct _MMWSLE
500 {
501 union
502 {
503 PVOID VirtualAddress;
504 ULONG Long;
505 MMWSLENTRY e1;
506 };
507 } MMWSLE, *PMMWSLE;
508
509 typedef struct _MMWSLE_HASH
510 {
511 PVOID Key;
512 ULONG Index;
513 } MMWSLE_HASH, *PMMWSLE_HASH;
514
515 typedef struct _MMWSL
516 {
517 ULONG FirstFree;
518 ULONG FirstDynamic;
519 ULONG LastEntry;
520 ULONG NextSlot;
521 PMMWSLE Wsle;
522 ULONG LastInitializedWsle;
523 ULONG NonDirectcout;
524 PMMWSLE_HASH HashTable;
525 ULONG HashTableSize;
526 ULONG NumberOfCommittedPageTables;
527 PVOID HashTableStart;
528 PVOID HighestPermittedHashAddress;
529 ULONG NumberOfImageWaiters;
530 ULONG VadBitMapHint;
531 USHORT UsedPageTableEntries[768];
532 ULONG CommittedPageTables[24];
533 } MMWSL, *PMMWSL;
534
535 //
536 // Flags for Memory Support Structure
537 //
538 typedef struct _MMSUPPORT_FLAGS
539 {
540 ULONG SessionSpace:1;
541 ULONG BeingTrimmed:1;
542 ULONG SessionLeader:1;
543 ULONG TrimHard:1;
544 ULONG WorkingSetHard:1;
545 ULONG AddressSpaceBeingDeleted :1;
546 ULONG Available:10;
547 ULONG AllowWorkingSetAdjustment:8;
548 ULONG MemoryPriority:8;
549 } MMSUPPORT_FLAGS, *PMMSUPPORT_FLAGS;
550
551 //
552 // Per-Process Memory Manager Data
553 //
554 typedef struct _MMSUPPORT
555 {
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;
565 ULONG Claim;
566 ULONG NextEstimationSlot;
567 ULONG NextAgingSlot;
568 ULONG EstimatedAvailable;
569 ULONG GrowthSinceLastEstimate;
570 } MMSUPPORT, *PMMSUPPORT;
571
572 //
573 // Memory Information Types
574 //
575 typedef struct _MEMORY_BASIC_INFORMATION
576 {
577 PVOID BaseAddress;
578 PVOID AllocationBase;
579 ULONG AllocationProtect;
580 ULONG RegionSize;
581 ULONG State;
582 ULONG Protect;
583 ULONG Type;
584 } MEMORY_BASIC_INFORMATION,*PMEMORY_BASIC_INFORMATION;
585
586
587 //
588 // Mm Global Variables
589 //
590
591 //
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.
595 //
596 // These variables should be considered "const"; they are written only once,
597 // during MmInitSystem.
598 //
599 extern SIZE_T MmHeapSegmentReserve;
600 extern SIZE_T MmHeapSegmentCommit;
601 extern SIZE_T MmHeapDeCommitTotalFreeThreshold;
602 extern SIZE_T MmHeapDeCommitFreeBlockThreshold;
603
604 #endif // !NTOS_MODE_USER
605
606 #endif // _MMTYPES_H