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