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 #include <extypes.h> 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 // 34 // Page-Rounding Macros 35 // 36 #define PAGE_ROUND_DOWN(x) \ 37 (((ULONG_PTR)(x))&(~(PAGE_SIZE-1))) 38 #define PAGE_ROUND_UP(x) \ 39 ( (((ULONG_PTR)(x)) + PAGE_SIZE-1) & (~(PAGE_SIZE-1)) ) 40 #ifdef NTOS_MODE_USER 41 #define ROUND_TO_PAGES(Size) \ 42 (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)) 43 #endif 44 #define ROUND_TO_ALLOCATION_GRANULARITY(Size) \ 45 (((ULONG_PTR)(Size) + MM_ALLOCATION_GRANULARITY - 1) \ 46 & ~(MM_ALLOCATION_GRANULARITY - 1)) 47 48 // 49 // PFN Identity Uses 50 // 51 #define MMPFNUSE_PROCESSPRIVATE 0 52 #define MMPFNUSE_FILE 1 53 #define MMPFNUSE_PAGEFILEMAPPED 2 54 #define MMPFNUSE_PAGETABLE 3 55 #define MMPFNUSE_PAGEDPOOL 4 56 #define MMPFNUSE_NONPAGEDPOOL 5 57 #define MMPFNUSE_SYSTEMPTE 6 58 #define MMPFNUSE_SESSIONPRIVATE 7 59 #define MMPFNUSE_METAFILE 8 60 #define MMPFNUSE_AWEPAGE 9 61 #define MMPFNUSE_DRIVERLOCKPAGE 10 62 #define MMPFNUSE_KERNELSTACK 11 63 64 // 65 // Lock/Unlock Virtuam Memory Flags 66 // 67 #define MAP_PROCESS 1 68 #define MAP_SYSTEM 2 69 70 // 71 // Flags for ProcessExecutionOptions 72 // 73 #define MEM_EXECUTE_OPTION_DISABLE 0x1 74 #define MEM_EXECUTE_OPTION_ENABLE 0x2 75 #define MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION 0x4 76 #define MEM_EXECUTE_OPTION_PERMANENT 0x8 77 #define MEM_EXECUTE_OPTION_EXECUTE_DISPATCH_ENABLE 0x10 78 #define MEM_EXECUTE_OPTION_IMAGE_DISPATCH_ENABLE 0x20 79 #define MEM_EXECUTE_OPTION_VALID_FLAGS 0x3F 80 81 #ifndef NTOS_MODE_USER 82 83 // 84 // Virtual Memory Flags 85 // 86 #define MEM_WRITE_WATCH 0x200000 87 #define MEM_PHYSICAL 0x400000 88 #define MEM_ROTATE 0x800000 89 #define MEM_IMAGE SEC_IMAGE 90 #define MEM_DOS_LIM 0x40000000 91 92 // 93 // Section Flags for NtCreateSection 94 // 95 #define SEC_NO_CHANGE 0x400000 96 #define SEC_FILE 0x800000 97 #define SEC_IMAGE 0x1000000 98 #define SEC_PROTECTED_IMAGE 0x2000000 99 #define SEC_RESERVE 0x4000000 100 #define SEC_COMMIT 0x8000000 101 #define SEC_NOCACHE 0x10000000 102 #define SEC_WRITECOMBINE 0x40000000 103 #define SEC_LARGE_PAGES 0x80000000 104 105 #else // NTOS_MODE_USER 106 107 #define SEC_BASED 0x200000 108 109 // 110 // Section Inherit Flags for NtMapViewOfSection 111 // 112 typedef enum _SECTION_INHERIT 113 { 114 ViewShare = 1, 115 ViewUnmap = 2 116 } SECTION_INHERIT; 117 118 // 119 // Pool Types 120 // 121 typedef enum _POOL_TYPE 122 { 123 NonPagedPool, 124 PagedPool, 125 NonPagedPoolMustSucceed, 126 DontUseThisType, 127 NonPagedPoolCacheAligned, 128 PagedPoolCacheAligned, 129 NonPagedPoolCacheAlignedMustS, 130 MaxPoolType, 131 132 NonPagedPoolBase = 0, 133 NonPagedPoolBaseMustSucceed = NonPagedPoolBase + 2, 134 NonPagedPoolBaseCacheAligned = NonPagedPoolBase + 4, 135 NonPagedPoolBaseCacheAlignedMustS = NonPagedPoolBase + 6, 136 137 NonPagedPoolSession = 32, 138 PagedPoolSession, 139 NonPagedPoolMustSucceedSession, 140 DontUseThisTypeSession, 141 NonPagedPoolCacheAlignedSession, 142 PagedPoolCacheAlignedSession, 143 NonPagedPoolCacheAlignedMustSSession 144 } POOL_TYPE; 145 146 #endif // NTOS_MODE_USER 147 148 // 149 // Memory Manager Page Lists 150 // 151 typedef enum _MMLISTS 152 { 153 ZeroedPageList = 0, 154 FreePageList = 1, 155 StandbyPageList = 2, 156 ModifiedPageList = 3, 157 ModifiedNoWritePageList = 4, 158 BadPageList = 5, 159 ActiveAndValid = 6, 160 TransitionPage = 7 161 } MMLISTS; 162 163 // 164 // Per Processor Non Paged Lookaside List IDs 165 // 166 typedef enum _PP_NPAGED_LOOKASIDE_NUMBER 167 { 168 LookasideSmallIrpList = 0, 169 LookasideLargeIrpList = 1, 170 LookasideMdlList = 2, 171 LookasideCreateInfoList = 3, 172 LookasideNameBufferList = 4, 173 LookasideTwilightList = 5, 174 LookasideCompletionList = 6, 175 LookasideMaximumList = 7 176 } PP_NPAGED_LOOKASIDE_NUMBER; 177 178 // 179 // Memory Information Classes for NtQueryVirtualMemory 180 // 181 typedef enum _MEMORY_INFORMATION_CLASS 182 { 183 MemoryBasicInformation, 184 MemoryWorkingSetList, 185 MemorySectionName, 186 MemoryBasicVlmInformation, 187 MemoryWorkingSetExList 188 } MEMORY_INFORMATION_CLASS; 189 190 // 191 // Section Information Clasess for NtQuerySection 192 // 193 typedef enum _SECTION_INFORMATION_CLASS 194 { 195 SectionBasicInformation, 196 SectionImageInformation, 197 } SECTION_INFORMATION_CLASS; 198 199 // 200 // Kinds of VADs 201 // 202 typedef enum _MI_VAD_TYPE 203 { 204 VadNone, 205 VadDevicePhysicalMemory, 206 VadImageMap, 207 VadAwe, 208 VadWriteWatch, 209 VadLargePages, 210 VadRotatePhysical, 211 VadLargePageSection 212 } MI_VAD_TYPE, *PMI_VAD_TYPE; 213 214 #ifdef NTOS_MODE_USER 215 // 216 // Virtual Memory Counters 217 // 218 typedef struct _VM_COUNTERS 219 { 220 SIZE_T PeakVirtualSize; 221 SIZE_T VirtualSize; 222 ULONG PageFaultCount; 223 SIZE_T PeakWorkingSetSize; 224 SIZE_T WorkingSetSize; 225 SIZE_T QuotaPeakPagedPoolUsage; 226 SIZE_T QuotaPagedPoolUsage; 227 SIZE_T QuotaPeakNonPagedPoolUsage; 228 SIZE_T QuotaNonPagedPoolUsage; 229 SIZE_T PagefileUsage; 230 SIZE_T PeakPagefileUsage; 231 } VM_COUNTERS, *PVM_COUNTERS; 232 233 typedef struct _VM_COUNTERS_EX 234 { 235 SIZE_T PeakVirtualSize; 236 SIZE_T VirtualSize; 237 ULONG PageFaultCount; 238 SIZE_T PeakWorkingSetSize; 239 SIZE_T WorkingSetSize; 240 SIZE_T QuotaPeakPagedPoolUsage; 241 SIZE_T QuotaPagedPoolUsage; 242 SIZE_T QuotaPeakNonPagedPoolUsage; 243 SIZE_T QuotaNonPagedPoolUsage; 244 SIZE_T PagefileUsage; 245 SIZE_T PeakPagefileUsage; 246 SIZE_T PrivateUsage; 247 } VM_COUNTERS_EX, *PVM_COUNTERS_EX; 248 #endif 249 250 // 251 // Sub-Information Types for PFN Identity 252 // 253 typedef struct _MEMORY_FRAME_INFORMATION 254 { 255 ULONGLONG UseDescription:4; 256 ULONGLONG ListDescription:3; 257 ULONGLONG Reserved0:1; 258 ULONGLONG Pinned:1; 259 ULONGLONG DontUse:48; 260 ULONGLONG Priority:3; 261 ULONGLONG Reserved:4; 262 } MEMORY_FRAME_INFORMATION, *PMEMORY_FRAME_INFORMATION; 263 264 typedef struct _FILEOFFSET_INFORMATION 265 { 266 ULONGLONG DontUse:9; 267 ULONGLONG Offset:48; 268 ULONGLONG Reserved:7; 269 } FILEOFFSET_INFORMATION, *PFILEOFFSET_INFORMATION; 270 271 typedef struct _PAGEDIR_INFORMATION 272 { 273 ULONGLONG DontUse:9; 274 ULONGLONG PageDirectoryBase:48; 275 ULONGLONG Reserved:7; 276 } PAGEDIR_INFORMATION, *PPAGEDIR_INFORMATION; 277 278 typedef struct _UNIQUE_PROCESS_INFORMATION 279 { 280 ULONGLONG DontUse:9; 281 ULONGLONG UniqueProcessKey:48; 282 ULONGLONG Reserved:7; 283 } UNIQUE_PROCESS_INFORMATION, *PUNIQUE_PROCESS_INFORMATION; 284 285 // 286 // PFN Identity Data Structure 287 // 288 typedef struct _MMPFN_IDENTITY 289 { 290 union 291 { 292 MEMORY_FRAME_INFORMATION e1; 293 FILEOFFSET_INFORMATION e2; 294 PAGEDIR_INFORMATION e3; 295 UNIQUE_PROCESS_INFORMATION e4; 296 } u1; 297 SIZE_T PageFrameIndex; 298 union 299 { 300 struct 301 { 302 ULONG Image:1; 303 ULONG Mismatch:1; 304 } e1; 305 PVOID FileObject; 306 PVOID UniqueFileObjectKey; 307 PVOID ProtoPteAddress; 308 PVOID VirtualAddress; 309 } u2; 310 } MMPFN_IDENTITY, *PMMPFN_IDENTITY; 311 312 // 313 // List of Working Sets 314 // 315 typedef struct _MEMORY_WORKING_SET_LIST 316 { 317 ULONG NumberOfPages; 318 ULONG WorkingSetList[1]; 319 } MEMORY_WORKING_SET_LIST, *PMEMORY_WORKING_SET_LIST; 320 321 // 322 // Memory Information Structures for NtQueryVirtualMemory 323 // 324 typedef struct 325 { 326 UNICODE_STRING SectionFileName; 327 } MEMORY_SECTION_NAME, *PMEMORY_SECTION_NAME; 328 329 // 330 // Section Information Structures for NtQuerySection 331 // 332 typedef struct _SECTION_BASIC_INFORMATION 333 { 334 PVOID BaseAddress; 335 ULONG Attributes; 336 LARGE_INTEGER Size; 337 } SECTION_BASIC_INFORMATION, *PSECTION_BASIC_INFORMATION; 338 339 typedef struct _SECTION_IMAGE_INFORMATION 340 { 341 PVOID TransferAddress; 342 ULONG ZeroBits; 343 SIZE_T MaximumStackSize; 344 SIZE_T CommittedStackSize; 345 ULONG SubSystemType; 346 union 347 { 348 struct 349 { 350 USHORT SubSystemMinorVersion; 351 USHORT SubSystemMajorVersion; 352 }; 353 ULONG SubSystemVersion; 354 }; 355 ULONG GpValue; 356 USHORT ImageCharacteristics; 357 USHORT DllCharacteristics; 358 USHORT Machine; 359 BOOLEAN ImageContainsCode; 360 #if (NTDDI_VERSION >= NTDDI_LONGHORN) 361 union 362 { 363 struct 364 { 365 UCHAR ComPlusNativeReady:1; 366 UCHAR ComPlusILOnly:1; 367 UCHAR ImageDynamicallyRelocated:1; 368 UCHAR ImageMappedFlat:1; 369 UCHAR Reserved:4; 370 }; 371 UCHAR ImageFlags; 372 }; 373 #else 374 BOOLEAN Spare1; 375 #endif 376 ULONG LoaderFlags; 377 ULONG ImageFileSize; 378 #if (NTDDI_VERSION >= NTDDI_LONGHORN) 379 ULONG CheckSum; 380 #else 381 ULONG Reserved[1]; 382 #endif 383 } SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION; 384 385 #ifndef NTOS_MODE_USER 386 387 // 388 // Section Extension Information 389 // 390 typedef struct _MMEXTEND_INFO 391 { 392 ULONGLONG CommittedSize; 393 ULONG ReferenceCount; 394 } MMEXTEND_INFO, *PMMEXTEND_INFO; 395 396 // 397 // Segment and Segment Flags 398 // 399 typedef struct _SEGMENT_FLAGS 400 { 401 ULONG TotalNumberOfPtes4132:10; 402 ULONG ExtraSharedWowSubsections:1; 403 ULONG LargePages:1; 404 ULONG Spare:20; 405 } SEGMENT_FLAGS, *PSEGMENT_FLAGS; 406 407 typedef struct _SEGMENT 408 { 409 struct _CONTROL_AREA *ControlArea; 410 ULONG TotalNumberOfPtes; 411 ULONG NonExtendedPtes; 412 ULONG Spare0; 413 ULONGLONG SizeOfSegment; 414 MMPTE SegmentPteTemplate; 415 ULONG NumberOfCommittedPages; 416 PMMEXTEND_INFO ExtendInfo; 417 SEGMENT_FLAGS SegmentFlags; 418 PVOID BasedAddress; 419 union 420 { 421 SIZE_T ImageCommitment; 422 PEPROCESS CreatingProcess; 423 } u1; 424 union 425 { 426 PSECTION_IMAGE_INFORMATION ImageInformation; 427 PVOID FirstMappedVa; 428 } u2; 429 PMMPTE PrototypePte; 430 MMPTE ThePtes[1]; 431 } SEGMENT, *PSEGMENT; 432 433 typedef struct _MAPPED_FILE_SEGMENT 434 { 435 struct _CONTROL_AREA *ControlArea; 436 ULONG TotalNumberOfPtes; 437 ULONG NonExtendedPtes; 438 ULONG Spare0; 439 UINT64 SizeOfSegment; 440 MMPTE SegmentPteTemplate; 441 SIZE_T NumberOfCommittedPages; 442 PMMEXTEND_INFO ExtendInfo; 443 SEGMENT_FLAGS SegmentFlags; 444 PVOID BasedAddress; 445 struct _MSUBSECTION *LastSubsectionHint; 446 } MAPPED_FILE_SEGMENT, *PMAPPED_FILE_SEGMENT; 447 448 // 449 // Event Counter Structure 450 // 451 typedef struct _EVENT_COUNTER 452 { 453 SLIST_ENTRY ListEntry; 454 ULONG RefCount; 455 KEVENT Event; 456 } EVENT_COUNTER, *PEVENT_COUNTER; 457 458 // 459 // Flags 460 // 461 typedef struct _MMSECTION_FLAGS 462 { 463 ULONG BeingDeleted:1; 464 ULONG BeingCreated:1; 465 ULONG BeingPurged:1; 466 ULONG NoModifiedWriting:1; 467 ULONG FailAllIo:1; 468 ULONG Image:1; 469 ULONG Based:1; 470 ULONG File:1; 471 ULONG Networked:1; 472 ULONG NoCache:1; 473 ULONG PhysicalMemory:1; 474 ULONG CopyOnWrite:1; 475 ULONG Reserve:1; 476 ULONG Commit:1; 477 ULONG FloppyMedia:1; 478 ULONG WasPurged:1; 479 ULONG UserReference:1; 480 ULONG GlobalMemory:1; 481 ULONG DeleteOnClose:1; 482 ULONG FilePointerNull:1; 483 ULONG DebugSymbolsLoaded:1; 484 ULONG SetMappedFileIoComplete:1; 485 ULONG CollidedFlush:1; 486 ULONG NoChange:1; 487 ULONG filler0:1; 488 ULONG ImageMappedInSystemSpace:1; 489 ULONG UserWritable:1; 490 ULONG Accessed:1; 491 ULONG GlobalOnlyPerSession:1; 492 ULONG Rom:1; 493 ULONG WriteCombined:1; 494 ULONG filler:1; 495 } MMSECTION_FLAGS, *PMMSECTION_FLAGS; 496 497 typedef struct _MMSUBSECTION_FLAGS 498 { 499 ULONG ReadOnly:1; 500 ULONG ReadWrite:1; 501 ULONG SubsectionStatic:1; 502 ULONG GlobalMemory:1; 503 ULONG Protection:5; 504 ULONG Spare:1; 505 ULONG StartingSector4132:10; 506 ULONG SectorEndOffset:12; 507 } MMSUBSECTION_FLAGS, *PMMSUBSECTION_FLAGS; 508 509 typedef struct _MMSUBSECTION_FLAGS2 510 { 511 ULONG SubsectionAccessed:1; 512 ULONG SubsectionConverted:1; 513 ULONG Reserved:30; 514 } MMSUBSECTION_FLAGS2; 515 516 // 517 // Control Area Structures (8-byte aligned) 518 // 519 typedef struct _CONTROL_AREA 520 { 521 PSEGMENT Segment; 522 LIST_ENTRY DereferenceList; 523 ULONG NumberOfSectionReferences; 524 ULONG NumberOfPfnReferences; 525 ULONG NumberOfMappedViews; 526 ULONG NumberOfSystemCacheViews; 527 ULONG NumberOfUserReferences; 528 union 529 { 530 ULONG LongFlags; 531 MMSECTION_FLAGS Flags; 532 } u; 533 PFILE_OBJECT FilePointer; 534 PEVENT_COUNTER WaitingForDeletion; 535 USHORT ModifiedWriteCount; 536 USHORT FlushInProgressCount; 537 ULONG WritableUserReferences; 538 ULONG QuadwordPad; 539 } CONTROL_AREA, *PCONTROL_AREA; 540 C_ASSERT((sizeof(CONTROL_AREA) % 8) == 0); 541 542 typedef struct _LARGE_CONTROL_AREA 543 { 544 PSEGMENT Segment; 545 LIST_ENTRY DereferenceList; 546 ULONG NumberOfSectionReferences; 547 ULONG NumberOfPfnReferences; 548 ULONG NumberOfMappedViews; 549 ULONG NumberOfSystemCacheViews; 550 ULONG NumberOfUserReferences; 551 union 552 { 553 ULONG LongFlags; 554 MMSECTION_FLAGS Flags; 555 } u; 556 PFILE_OBJECT FilePointer; 557 PEVENT_COUNTER WaitingForDeletion; 558 USHORT ModifiedWriteCount; 559 USHORT FlushInProgressCount; 560 ULONG WritableUserReferences; 561 ULONG QuadwordPad; 562 ULONG StartingFrame; 563 LIST_ENTRY UserGlobalList; 564 ULONG SessionId; 565 } LARGE_CONTROL_AREA, *PLARGE_CONTROL_AREA; 566 C_ASSERT((sizeof(LARGE_CONTROL_AREA) % 8) == 0); 567 568 // 569 // Subsection and Mapped Subsection (8-byte aligned) 570 // 571 typedef struct _SUBSECTION 572 { 573 PCONTROL_AREA ControlArea; 574 union 575 { 576 ULONG LongFlags; 577 MMSUBSECTION_FLAGS SubsectionFlags; 578 } u; 579 ULONG StartingSector; 580 ULONG NumberOfFullSectors; 581 PMMPTE SubsectionBase; 582 ULONG UnusedPtes; 583 ULONG PtesInSubsection; 584 struct _SUBSECTION *NextSubsection; 585 } SUBSECTION, *PSUBSECTION; 586 C_ASSERT((sizeof(SUBSECTION) % 8) == 0); 587 588 typedef struct _MSUBSECTION 589 { 590 PCONTROL_AREA ControlArea; 591 union 592 { 593 ULONG LongFlags; 594 MMSUBSECTION_FLAGS SubsectionFlags; 595 } u; 596 ULONG StartingSector; 597 ULONG NumberOfFullSectors; 598 PMMPTE SubsectionBase; 599 ULONG UnusedPtes; 600 ULONG PtesInSubsection; 601 struct _SUBSECTION *NextSubsection; 602 LIST_ENTRY DereferenceList; 603 ULONG_PTR NumberOfMappedViews; 604 union 605 { 606 ULONG LongFlags2; 607 MMSUBSECTION_FLAGS2 SubsectionFlags2; 608 } u2; 609 } MSUBSECTION, *PMSUBSECTION; 610 C_ASSERT((sizeof(MSUBSECTION) % 8) == 0); 611 612 // 613 // Segment Object 614 // 615 typedef struct _SEGMENT_OBJECT 616 { 617 PVOID BaseAddress; 618 ULONG TotalNumberOfPtes; 619 LARGE_INTEGER SizeOfSegment; 620 ULONG NonExtendedPtes; 621 ULONG ImageCommitment; 622 PCONTROL_AREA ControlArea; 623 PSUBSECTION Subsection; 624 PLARGE_CONTROL_AREA LargeControlArea; 625 PMMSECTION_FLAGS MmSectionFlags; 626 PMMSUBSECTION_FLAGS MmSubSectionFlags; 627 } SEGMENT_OBJECT, *PSEGMENT_OBJECT; 628 629 // 630 // Generic Address Range Structure 631 // 632 typedef struct _ADDRESS_RANGE 633 { 634 ULONG BaseAddrLow; 635 ULONG BaseAddrHigh; 636 ULONG LengthLow; 637 ULONG LengthHigh; 638 ULONG Type; 639 } ADDRESS_RANGE, *PADDRESS_RANGE; 640 641 // 642 // Node in Memory Manager's AVL Table 643 // 644 typedef struct _MMADDRESS_NODE 645 { 646 union 647 { 648 LONG_PTR Balance:2; 649 struct _MMADDRESS_NODE *Parent; 650 } u1; 651 struct _MMADDRESS_NODE *LeftChild; 652 struct _MMADDRESS_NODE *RightChild; 653 ULONG_PTR StartingVpn; 654 ULONG_PTR EndingVpn; 655 } MMADDRESS_NODE, *PMMADDRESS_NODE; 656 657 // 658 // Memory Manager AVL Table for VADs and other descriptors 659 // 660 typedef struct _MM_AVL_TABLE 661 { 662 MMADDRESS_NODE BalancedRoot; 663 ULONG_PTR DepthOfTree:5; 664 ULONG_PTR Unused:3; 665 #ifdef _WIN64 666 ULONG_PTR NumberGenericTableElements:56; 667 #else 668 ULONG_PTR NumberGenericTableElements:24; 669 #endif 670 PVOID NodeHint; 671 PVOID NodeFreeHint; 672 } MM_AVL_TABLE, *PMM_AVL_TABLE; 673 674 // 675 // Virtual Address List used in VADs 676 // 677 typedef struct _MMADDRESS_LIST 678 { 679 ULONG_PTR StartVpn; 680 ULONG_PTR EndVpn; 681 } MMADDRESS_LIST, *PMMADDRESS_LIST; 682 683 // 684 // Flags used in the VAD 685 // 686 typedef struct _MMVAD_FLAGS 687 { 688 #ifdef _WIN64 689 ULONG_PTR CommitCharge:51; 690 #else 691 ULONG_PTR CommitCharge:19; 692 #endif 693 ULONG_PTR NoChange:1; 694 ULONG_PTR VadType:3; 695 ULONG_PTR MemCommit:1; 696 ULONG_PTR Protection:5; 697 ULONG_PTR Spare:2; 698 ULONG_PTR PrivateMemory:1; 699 } MMVAD_FLAGS, *PMMVAD_FLAGS; 700 701 // 702 // Extended flags used in the VAD 703 // 704 typedef struct _MMVAD_FLAGS2 705 { 706 ULONG FileOffset:24; 707 ULONG SecNoChange:1; 708 ULONG OneSecured:1; 709 ULONG MultipleSecured:1; 710 ULONG ReadOnly:1; 711 ULONG LongVad:1; 712 ULONG ExtendableFile:1; 713 ULONG Inherit:1; 714 ULONG CopyOnWrite:1; 715 } MMVAD_FLAGS2, *PMMVAD_FLAGS2; 716 717 // 718 // Virtual Address Descriptor (VAD) Structure 719 // 720 typedef struct _MMVAD 721 { 722 union 723 { 724 LONG_PTR Balance:2; 725 struct _MMVAD *Parent; 726 } u1; 727 struct _MMVAD *LeftChild; 728 struct _MMVAD *RightChild; 729 ULONG_PTR StartingVpn; 730 ULONG_PTR EndingVpn; 731 union 732 { 733 ULONG_PTR LongFlags; 734 MMVAD_FLAGS VadFlags; 735 } u; 736 PCONTROL_AREA ControlArea; 737 PMMPTE FirstPrototypePte; 738 PMMPTE LastContiguousPte; 739 union 740 { 741 ULONG LongFlags2; 742 MMVAD_FLAGS2 VadFlags2; 743 } u2; 744 } MMVAD, *PMMVAD; 745 746 // 747 // Long VAD used in section and private allocations 748 // 749 typedef struct _MMVAD_LONG 750 { 751 union 752 { 753 LONG_PTR Balance:2; 754 PMMVAD Parent; 755 } u1; 756 PMMVAD LeftChild; 757 PMMVAD RightChild; 758 ULONG_PTR StartingVpn; 759 ULONG_PTR EndingVpn; 760 union 761 { 762 ULONG_PTR LongFlags; 763 MMVAD_FLAGS VadFlags; 764 } u; 765 PCONTROL_AREA ControlArea; 766 PMMPTE FirstPrototypePte; 767 PMMPTE LastContiguousPte; 768 union 769 { 770 ULONG LongFlags2; 771 MMVAD_FLAGS2 VadFlags2; 772 } u2; 773 union 774 { 775 LIST_ENTRY List; 776 MMADDRESS_LIST Secured; 777 } u3; 778 union 779 { 780 PVOID Banked; 781 PMMEXTEND_INFO ExtendedInfo; 782 } u4; 783 } MMVAD_LONG, *PMMVAD_LONG; 784 785 // 786 // Short VAD used in virtual memory allocations 787 // 788 typedef struct _MMVAD_SHORT 789 { 790 union 791 { 792 LONG_PTR Balance:2; 793 PMMVAD Parent; 794 } u1; 795 PMMVAD LeftChild; 796 PMMVAD RightChild; 797 ULONG_PTR StartingVpn; 798 ULONG_PTR EndingVpn; 799 union 800 { 801 ULONG_PTR LongFlags; 802 MMVAD_FLAGS VadFlags; 803 } u; 804 } MMVAD_SHORT, *PMMVAD_SHORT; 805 806 // 807 // Actual Section Object 808 // 809 typedef struct _SECTION 810 { 811 MMADDRESS_NODE Address; 812 PSEGMENT Segment; 813 LARGE_INTEGER SizeOfSection; 814 union 815 { 816 ULONG LongFlags; 817 MMSECTION_FLAGS Flags; 818 } u; 819 ULONG InitialPageProtection; 820 } SECTION, *PSECTION; 821 822 // 823 // Memory Manager Working Set Structures 824 // 825 typedef struct _MMWSLENTRY 826 { 827 ULONG_PTR Valid:1; 828 ULONG_PTR LockedInWs:1; 829 ULONG_PTR LockedInMemory:1; 830 ULONG_PTR Protection:5; 831 ULONG_PTR Hashed:1; 832 ULONG_PTR Direct:1; 833 ULONG_PTR Age:2; 834 ULONG_PTR VirtualPageNumber: MM_PAGE_FRAME_NUMBER_SIZE; 835 } MMWSLENTRY, *PMMWSLENTRY; 836 837 typedef struct _MMWSLE_FREE_ENTRY 838 { 839 ULONG MustBeZero:1; 840 #ifdef _WIN64 841 ULONG PreviousFree: 31; 842 LONG NextFree; 843 #define MMWSLE_PREVIOUS_FREE_MASK 0x7FFFFFFF 844 #else 845 ULONG PreviousFree: 11; 846 #define MMWSLE_PREVIOUS_FREE_MASK 0x7FF 847 #define MMWSLE_PREVIOUS_FREE_JUMP 0x800 848 LONG NextFree: 20; 849 #endif 850 } MMWSLE_FREE_ENTRY, *PMMWSLE_FREE_ENTRY; 851 852 typedef struct _MMWSLE 853 { 854 union 855 { 856 PVOID VirtualAddress; 857 ULONG_PTR Long; 858 MMWSLENTRY e1; 859 MMWSLE_FREE_ENTRY Free; 860 } u1; 861 } MMWSLE, *PMMWSLE; 862 863 typedef struct _MMWSLE_HASH 864 { 865 PVOID Key; 866 ULONG Index; 867 } MMWSLE_HASH, *PMMWSLE_HASH; 868 869 typedef struct _MMWSL 870 { 871 ULONG FirstFree; 872 ULONG FirstDynamic; 873 ULONG LastEntry; 874 ULONG NextSlot; 875 PMMWSLE Wsle; 876 ULONG LastInitializedWsle; 877 ULONG NonDirectCount; 878 PMMWSLE_HASH HashTable; 879 ULONG HashTableSize; 880 ULONG NumberOfCommittedPageTables; 881 PVOID HashTableStart; 882 PVOID HighestPermittedHashAddress; 883 ULONG NumberOfImageWaiters; 884 ULONG VadBitMapHint; 885 #ifndef _M_AMD64 886 USHORT UsedPageTableEntries[768]; 887 ULONG CommittedPageTables[24]; 888 #else 889 VOID* HighestUserAddress; 890 ULONG MaximumUserPageTablePages; 891 ULONG MaximumUserPageDirectoryPages; 892 ULONG* CommittedPageTables; 893 ULONG NumberOfCommittedPageDirectories; 894 ULONG* CommittedPageDirectories; 895 ULONG NumberOfCommittedPageDirectoryParents; 896 ULONGLONG CommittedPageDirectoryParents[1]; 897 #endif 898 } MMWSL, *PMMWSL; 899 900 // 901 // Flags for Memory Support Structure 902 // 903 typedef struct _MMSUPPORT_FLAGS 904 { 905 ULONG SessionSpace:1; 906 ULONG BeingTrimmed:1; 907 ULONG SessionLeader:1; 908 ULONG TrimHard:1; 909 ULONG MaximumWorkingSetHard:1; 910 ULONG ForceTrim:1; 911 ULONG MinimumWorkingSetHard:1; 912 ULONG Available0:1; 913 ULONG MemoryPriority:8; 914 ULONG GrowWsleHash:1; 915 ULONG AcquiredUnsafe:1; 916 ULONG Available:14; 917 } MMSUPPORT_FLAGS, *PMMSUPPORT_FLAGS; 918 919 // 920 // Per-Process Memory Manager Data 921 // 922 typedef struct _MMSUPPORT 923 { 924 #if (NTDDI_VERSION >= NTDDI_WS03) 925 LIST_ENTRY WorkingSetExpansionLinks; 926 #endif 927 #if (NTDDI_VERSION >= NTDDI_LONGHORN) 928 USHORT LastTrimpStamp; 929 USHORT NextPageColor; 930 #else 931 LARGE_INTEGER LastTrimTime; 932 #endif 933 MMSUPPORT_FLAGS Flags; 934 ULONG PageFaultCount; 935 ULONG PeakWorkingSetSize; 936 #if (NTDDI_VERSION >= NTDDI_LONGHORN) 937 ULONG Spare0; 938 #else 939 ULONG GrowthSinceLastEstimate; 940 #endif 941 ULONG MinimumWorkingSetSize; 942 ULONG MaximumWorkingSetSize; 943 PMMWSL VmWorkingSetList; 944 #if (NTDDI_VERSION < NTDDI_WS03) 945 LIST_ENTRY WorkingSetExpansionLinks; 946 #endif 947 ULONG Claim; 948 #if (NTDDI_VERSION >= NTDDI_LONGHORN) 949 ULONG Spare; 950 ULONG WorkingSetPrivateSize; 951 ULONG WorkingSetSizeOverhead; 952 #else 953 ULONG NextEstimationSlot; 954 ULONG NextAgingSlot; 955 ULONG EstimatedAvailable; 956 #endif 957 ULONG WorkingSetSize; 958 #if (NTDDI_VERSION >= NTDDI_LONGHORN) 959 PKEVENT ExitEvent; 960 #endif 961 EX_PUSH_LOCK WorkingSetMutex; 962 #if (NTDDI_VERSION >= NTDDI_LONGHORN) 963 PVOID AccessLog; 964 #endif 965 } MMSUPPORT, *PMMSUPPORT; 966 967 // 968 // Memory Information Types 969 // 970 typedef struct _MEMORY_BASIC_INFORMATION 971 { 972 PVOID BaseAddress; 973 PVOID AllocationBase; 974 ULONG AllocationProtect; 975 SIZE_T RegionSize; 976 ULONG State; 977 ULONG Protect; 978 ULONG Type; 979 } MEMORY_BASIC_INFORMATION,*PMEMORY_BASIC_INFORMATION; 980 981 // 982 // Driver Verifier Data 983 // 984 typedef struct _MM_DRIVER_VERIFIER_DATA 985 { 986 ULONG Level; 987 ULONG RaiseIrqls; 988 ULONG AcquireSpinLocks; 989 ULONG SynchronizeExecutions; 990 ULONG AllocationsAttempted; 991 ULONG AllocationsSucceeded; 992 ULONG AllocationsSucceededSpecialPool; 993 ULONG AllocationsWithNoTag; 994 ULONG TrimRequests; 995 ULONG Trims; 996 ULONG AllocationsFailed; 997 ULONG AllocationsFailedDeliberately; 998 ULONG Loads; 999 ULONG Unloads; 1000 ULONG UnTrackedPool; 1001 ULONG UserTrims; 1002 ULONG CurrentPagedPoolAllocations; 1003 ULONG CurrentNonPagedPoolAllocations; 1004 ULONG PeakPagedPoolAllocations; 1005 ULONG PeakNonPagedPoolAllocations; 1006 ULONG PagedBytes; 1007 ULONG NonPagedBytes; 1008 ULONG PeakPagedBytes; 1009 ULONG PeakNonPagedBytes; 1010 ULONG BurstAllocationsFailedDeliberately; 1011 ULONG SessionTrims; 1012 ULONG Reserved[2]; 1013 } MM_DRIVER_VERIFIER_DATA, *PMM_DRIVER_VERIFIER_DATA; 1014 1015 // 1016 // Internal Driver Verifier Table Data 1017 // 1018 typedef struct _DRIVER_SPECIFIED_VERIFIER_THUNKS 1019 { 1020 LIST_ENTRY ListEntry; 1021 struct _LDR_DATA_TABLE_ENTRY *DataTableEntry; 1022 ULONG NumberOfThunks; 1023 } DRIVER_SPECIFIED_VERIFIER_THUNKS, *PDRIVER_SPECIFIED_VERIFIER_THUNKS; 1024 1025 #ifdef __cplusplus 1026 extern "C" { 1027 #endif 1028 1029 // 1030 // Default heap size values. For user mode, these values are copied to a new 1031 // process's PEB by the kernel in MmCreatePeb. In kernel mode, RtlCreateHeap 1032 // reads these variables directly. 1033 // 1034 // These variables should be considered "const"; they are written only once, 1035 // during MmInitSystem. 1036 // 1037 extern SIZE_T MmHeapSegmentReserve; 1038 extern SIZE_T MmHeapSegmentCommit; 1039 extern SIZE_T MmHeapDeCommitTotalFreeThreshold; 1040 extern SIZE_T MmHeapDeCommitFreeBlockThreshold; 1041 1042 // 1043 // Section Object Type 1044 // 1045 extern POBJECT_TYPE NTSYSAPI MmSectionObjectType; 1046 1047 #ifdef __cplusplus 1048 }; // extern "C" 1049 #endif 1050 1051 #endif // !NTOS_MODE_USER 1052 1053 #ifdef __cplusplus 1054 } // extern "C" 1055 #endif 1056 1057 #endif // _MMTYPES_H 1058