00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 #define _MM64_ 1
00196
00197 #define _MIALT4K_ 1
00198
00199
00200
00201
00202
00203
00204 #define MM_EMPTY_LIST ((ULONG)0xFFFFFFFF) //
00205 #define MM_EMPTY_PTE_LIST ((ULONG)0xFFFFFFFF) // N.B. tied to MMPTE definition
00206
00207 #define MI_PTE_BASE_FOR_LOWEST_KERNEL_ADDRESS ((PMMPTE)PTE_KBASE)
00208
00209
00210
00211
00212
00213 #define MASK_43 0x7FFFFFFFFFFUI64 //
00214
00215
00216
00217
00218
00219 #define MASK_44 0xFFFFFFFFFFFUI64
00220
00221 #define MM_PAGES_IN_KSEG0 ((ULONG)((KSEG2_BASE - KSEG0_BASE) >> PAGE_SHIFT))
00222
00223 extern ULONG_PTR
MmKseg2Frame;
00224 extern ULONGLONG
MmPageSizeInfo;
00225
00226 #define MM_USER_ADDRESS_RANGE_LIMIT (0xFFFFFFFFFFFFFFFFUI64) // user address range limit
00227 #define MM_MAXIMUM_ZERO_BITS 53 // maximum number of zero bits
00228
00229
00230
00231
00232
00233
00234 #define MM_VIRTUAL_PAGE_FILLER (PAGE_SHIFT - 12)
00235 #define MM_VIRTUAL_PAGE_SIZE (64-PAGE_SHIFT)
00236
00237
00238
00239
00240
00241 #define CODE_START KSEG0_BASE
00242
00243 #define CODE_END KSEG2_BASE
00244
00245 #define MM_SYSTEM_SPACE_START (KADDRESS_BASE + 0x400000000UI64)
00246
00247 #define MM_SYSTEM_SPACE_END (KADDRESS_BASE + 0x60000000000UI64)
00248
00249 #define PDE_TOP PDE_UTOP
00250
00251
00252
00253
00254
00255 #define ALT4KB_PERMISSION_TABLE_START (UADDRESS_BASE + 0x40000000000)
00256
00257 #define ALT4KB_PERMISSION_TABLE_END (UADDRESS_BASE + 0x40000400000)
00258
00259
00260
00261
00262
00263 #define HYPER_SPACE ((PVOID)(UADDRESS_BASE + 0x40000800000))
00264
00265 #define HYPER_SPACE_END (UADDRESS_BASE + 0x401FFFFFFFF)
00266
00267
00268
00269
00270
00271 #define MM_SYSTEM_VIEW_START (KADDRESS_BASE + 0xA0000000)
00272
00273 #define MM_SYSTEM_VIEW_SIZE (48*1024*1024)
00274
00275 #define MM_SESSION_SPACE_DEFAULT (0x2000000000000000UI64) // make it the region 1 space
00276
00277 #define MM_SYSTEM_VIEW_START_IF_HYDRA MM_SYSTEM_VIEW_START
00278
00279 #define MM_SYSTEM_VIEW_SIZE_IF_HYDRA MM_SYSTEM_VIEW_SIZE
00280
00281
00282
00283
00284
00285
00286 #define MM_SYSTEM_CACHE_WORKING_SET (KADDRESS_BASE + 0x400000000UI64)
00287
00288 #define MM_SYSTEM_CACHE_START (KADDRESS_BASE + 0x600000000UI64)
00289
00290 #define MM_SYSTEM_CACHE_END (KADDRESS_BASE + 0x1005FFFFFFFFUI64)
00291
00292 #define MM_MAXIMUM_SYSTEM_CACHE_SIZE \
00293
(((ULONG_PTR)MM_SYSTEM_CACHE_END - (ULONG_PTR)MM_SYSTEM_CACHE_START) >> PAGE_SHIFT)
00294
00295 #define MM_PAGED_POOL_START ((PVOID)(KADDRESS_BASE + 0x10600000000UI64))
00296
00297 #define MM_LOWEST_NONPAGED_SYSTEM_START ((PVOID)(KADDRESS_BASE + 0x12600000000UI64))
00298
00299 #define MmProtopte_Base (KADDRESS_BASE)
00300
00301 #define MM_NONPAGED_POOL_END ((PVOID)(KADDRESS_BASE + 0x16600000000UI64 - (16 * PAGE_SIZE)))
00302
00303 #define MM_CRASH_DUMP_VA ((PVOID)(KADDRESS_BASE + 0xFF800000))
00304
00305
00306
00307 #define MM_DEBUG_VA ((PVOID)(KADDRESS_BASE + 0xFF900000))
00308
00309 #define NON_PAGED_SYSTEM_END (KADDRESS_BASE + 0x16600000000UI64) //quadword aligned.
00310
00311 #define MM_PFN_DATABASE_START (KADDRESS_BASE + 0x40000000000UI64)
00312
00313 #define MM_PFN_DATABASE_END (KADDRESS_BASE + 0x60000000000UI64)
00314
00315 extern ULONG
MiMaximumSystemCacheSize;
00316
00317
00318
00319
00320
00321 #define MM_MINIMUM_SYSTEM_PTES 7000
00322
00323 #define MM_MAXIMUM_SYSTEM_PTES 50000
00324
00325 #define MM_DEFAULT_SYSTEM_PTES 11000
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 #define MM_MAX_INITIAL_NONPAGED_POOL ((SIZE_T)(128 * 1024 * 1024))
00336
00337
00338
00339
00340
00341 #define MM_MAX_ADDITIONAL_NONPAGED_POOL (((SIZE_T)128 * 1024 * 1024 * 1024) - 16)
00342
00343
00344
00345
00346
00347 #define MM_MAX_PAGED_POOL ((SIZE_T)128 * 1024 * 1024 * 1024)
00348
00349
00350
00351
00352
00353 #define MM_MAX_DEFAULT_NONPAGED_POOL ((SIZE_T)8 * 1024 * 1024 * 1024)
00354
00355
00356
00357
00358
00359
00360 #define MM_PROTO_PTE_ALIGNMENT ((ULONG)PAGE_SIZE)
00361
00362
00363
00364
00365
00366
00367
00368
00369 #define PAGE_DIRECTORY1_MASK (((ULONG_PTR)1 << PDI1_SHIFT) - 1)
00370 #define PAGE_DIRECTORY2_MASK (((ULONG_PTR)1 << PDI_SHIFT) -1)
00371
00372 #define MM_VA_MAPPED_BY_PDE ((ULONG_PTR)1 << PDI_SHIFT)
00373
00374 #define LOWEST_IO_ADDRESS 0xa0000
00375
00376
00377
00378
00379
00380 #define PHYSICAL_ADDRESS_BITS 44
00381
00382 #define MM_MAXIMUM_NUMBER_OF_COLORS (1)
00383
00384
00385
00386
00387
00388 #define MM_NUMBER_OF_COLORS (1)
00389
00390
00391
00392
00393
00394 #define MM_COLOR_MASK (0)
00395
00396
00397
00398
00399
00400 #define MM_COLOR_ALIGNMENT (0)
00401
00402
00403
00404
00405
00406 #define MM_COLOR_MASK_VIRTUAL (0)
00407
00408
00409
00410
00411
00412 #define MM_SECONDARY_COLORS_DEFAULT (64)
00413
00414 #define MM_SECONDARY_COLORS_MIN (2)
00415
00416 #define MM_SECONDARY_COLORS_MAX (1024)
00417
00418
00419
00420
00421
00422 extern ULONG
MmSecondaryColorMask;
00423
00424
00425
00426
00427
00428 #define MAX_PAGE_FILES 16
00429
00430
00431
00432
00433
00434
00435 #define FIRST_MAPPING_PTE ((PMMPTE)HYPER_SPACE)
00436
00437 #define NUMBER_OF_MAPPING_PTES 255
00438 #define LAST_MAPPING_PTE \
00439
((ULONG_PTR)((ULONG_PTR)FIRST_MAPPING_PTE + (NUMBER_OF_MAPPING_PTES * PAGE_SIZE)))
00440
00441 #define IMAGE_MAPPING_PTE ((PMMPTE)((ULONG_PTR)LAST_MAPPING_PTE + PAGE_SIZE))
00442
00443 #define ZEROING_PAGE_PTE ((PMMPTE)((ULONG_PTR)IMAGE_MAPPING_PTE + PAGE_SIZE))
00444
00445 #define WORKING_SET_LIST ((PVOID)((ULONG_PTR)ZEROING_PAGE_PTE + PAGE_SIZE))
00446
00447 #define MM_MAXIMUM_WORKING_SET \
00448
((ULONG)((ULONG)2*1024*1024*1024 - 64*1024*1024) >> PAGE_SHIFT) //2Gb-64Mb
00449
00450 #define MM_WORKING_SET_END (UADDRESS_BASE + 0x3FFFFFFFFFFUI64)
00451
00452
00453
00454
00455
00456 #define MM_PTE_TB_MA_WB (0x0 << 2) // cacheable, write-back
00457 #define MM_PTE_TB_MA_UC (0x4 << 2) // uncheable
00458 #define MM_PTE_TB_MA_UCE (0x5 << 2) // uncheable, exporting fetchadd
00459 #define MM_PTE_TB_MA_WC (0x6 << 2) // uncheable, coalesing
00460 #define MM_PTE_TB_MA_NATPAGE (0x7 << 2) // Nat Page
00461
00462
00463
00464
00465
00466 #define MM_PTE_CACHE_ENABLED 0 // WB
00467 #define MM_PTE_CACHE_DISABLED 4 // UC
00468 #define MM_PTE_CACHE_DISPLAY 6 // WC
00469 #define MM_PTE_CACHE_RESERVED 1 // special encoding to cause a TLB miss
00470
00471
00472
00473
00474
00475 #define MM_PTE_OWNER_MASK 0x0180
00476 #define MM_PTE_VALID_MASK 1
00477 #define MM_PTE_CACHE_DISABLE_MASK MM_PTE_TB_MA_UC
00478 #define MM_PTE_ACCESS_MASK 0x0020
00479 #define MM_PTE_DIRTY_MASK 0x0040
00480 #define MM_PTE_EXECUTE_MASK 0x0200
00481 #define MM_PTE_WRITE_MASK 0x0400
00482 #define MM_PTE_LARGE_PAGE_MASK 0
00483 #define MM_PTE_COPY_ON_WRITE_MASK ((ULONG)1 << (PAGE_SHIFT-1))
00484
00485 #define MM_PTE_PROTOTYPE_MASK 0x0002
00486 #define MM_PTE_TRANSITION_MASK 0x0080
00487
00488
00489
00490
00491
00492
00493 #define MM_PTE_NOACCESS 0x0
00494 #define MM_PTE_READONLY 0x0
00495 #define MM_PTE_READWRITE MM_PTE_WRITE_MASK
00496 #define MM_PTE_WRITECOPY MM_PTE_COPY_ON_WRITE_MASK
00497 #define MM_PTE_EXECUTE MM_PTE_EXECUTE_MASK
00498 #define MM_PTE_EXECUTE_READ MM_PTE_EXECUTE_MASK
00499 #define MM_PTE_EXECUTE_READWRITE MM_PTE_EXECUTE_MASK | MM_PTE_WRITE_MASK
00500 #define MM_PTE_EXECUTE_WRITECOPY MM_PTE_EXECUTE_MASK | MM_PTE_COPY_ON_WRITE_MASK
00501 #define MM_PTE_GUARD 0x0
00502 #define MM_PTE_CACHE MM_PTE_TB_MA_WB
00503 #define MM_PTE_NOCACHE MM_PTE_CACHE // PAGE_NOCACHE is cached
00504 #define MM_PTE_EXC_DEFER 0x10000000000000 // defer exception
00505
00506
00507 #define MM_PROTECT_FIELD_SHIFT 2
00508
00509
00510
00511
00512
00513 #define MM_PTE_TB_VALID 0x0001
00514 #define MM_PTE_TB_ACCESSED 0x0020
00515 #define MM_PTE_TB_MODIFIED 0x0040
00516 #define MM_PTE_TB_WRITE 0x0400
00517 #define MM_PTE_TB_EXECUTE 0x0200 // read/execute on EM
00518 #define MM_PTE_TB_EXC_DEFER 0x10000000000000 // defer exception
00519
00520
00521
00522
00523
00524 #define MM_PTE_1MB_PAGE 20
00525 #define MM_PTE_2MB_PAGE 21
00526 #define MM_PTE_4MB_PAGE 22
00527 #define MM_PTE_16MB_PAGE 24
00528 #define MM_PTE_64MB_PAGE 26
00529 #define MM_PTE_256MB_PAGE 28
00530
00531
00532
00533
00534
00535 #define MM_VHPT_PAGES 32
00536
00537
00538
00539
00540
00541 #define MI_MAXIMUM_PTE_WORKING_SET_INDEX (1 << _HARDWARE_PTE_WORKING_SET_BITS)
00542
00543
00544
00545
00546
00547 #define MM_ZERO_PTE 0
00548
00549
00550
00551
00552
00553 #define MM_ZERO_KERNEL_PTE 0
00554
00555
00556
00557
00558
00559 #define MM_DEMAND_ZERO_WRITE_PTE ((ULONGLONG)MM_READWRITE << MM_PROTECT_FIELD_SHIFT)
00560
00561
00562
00563
00564
00565
00566 #define MM_KERNEL_DEMAND_ZERO_PTE ((ULONGLONG)MM_READWRITE << MM_PROTECT_FIELD_SHIFT)
00567
00568
00569
00570
00571
00572 #define MM_KERNEL_NOACCESS_PTE ((ULONGLONG)MM_NOACCESS << MM_PROTECT_FIELD_SHIFT)
00573
00574 extern ULONG_PTR
MmPteGlobal;
00575
00576
00577
00578
00579
00580 #define MM_STACK_ALIGNMENT 0x0
00581
00582 #define MM_STACK_OFFSET 0x0
00583
00584
00585
00586
00587
00588 #define PDE_PER_PAGE ((ULONG)(PAGE_SIZE/(1 << PTE_SHIFT)))
00589
00590 #define PTE_PER_PAGE ((ULONG)(PAGE_SIZE/(1 << PTE_SHIFT)))
00591
00592 #define PTE_PER_PAGE_BITS 11 // This handles the case where the page is full
00593
00594
#if PTE_PER_PAGE_BITS > 32
00595
error - too many bits to fit into
MMPTE_SOFTWARE or
MMPFN.u1
00596
#endif
00597
00598
00599
00600
00601
00602 #define MM_USER_PAGE_TABLE_PAGES PTE_PER_PAGE
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
#if !defined(_MIALT4K_)
00637
00638
#define MI_MAKE_VALID_PTE(OUTPTE,FRAME,PMASK,PPTE) \
00639
(OUTPTE).u.Long = 0; \
00640
(OUTPTE).u.Hard.Valid = 1; \
00641
(OUTPTE).u.Hard.Cache = MM_PTE_CACHE_ENABLED; \
00642
(OUTPTE).u.Hard.Accessed = 1; \
00643
(OUTPTE).u.Hard.Exception = 1; \
00644
(OUTPTE).u.Hard.PageFrameNumber = FRAME; \
00645
(OUTPTE).u.Hard.Owner = MI_DETERMINE_OWNER(PPTE); \
00646
(OUTPTE).u.Long |= (MmProtectToPteMask[PMASK]);
00647
00648
#endif
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674 #define MI_MAKE_VALID_PTE_TRANSITION(OUTPTE,PROTECT) \
00675
(OUTPTE).u.Soft.Transition = 1; \
00676
(OUTPTE).u.Soft.Valid = 0; \
00677
(OUTPTE).u.Soft.Prototype = 0; \
00678
(OUTPTE).u.Soft.Protection = PROTECT;
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710 #define MI_MAKE_TRANSITION_PTE(OUTPTE,PAGE,PROTECT,PPTE) \
00711
(OUTPTE).u.Long = 0; \
00712
(OUTPTE).u.Trans.PageFrameNumber = PAGE; \
00713
(OUTPTE).u.Trans.Transition = 1; \
00714
(OUTPTE).u.Trans.Protection = PROTECT;
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
#if !defined(_MIALT4K_)
00742
00743
#define MI_MAKE_TRANSITION_PTE_VALID(OUTPTE,PPTE) \
00744
ASSERT (((PPTE)->u.Hard.Valid == 0) && \
00745
((PPTE)->u.Trans.Prototype == 0) && \
00746
((PPTE)->u.Trans.Transition == 1)); \
00747
(OUTPTE).u.Long = (PPTE)->u.Long & 0x1FFFFFFFE000; \
00748
(OUTPTE).u.Hard.Valid = 1; \
00749
(OUTPTE).u.Hard.Cache = MM_PTE_CACHE_ENABLED; \
00750
(OUTPTE).u.Hard.Accessed = 1; \
00751
(OUTPTE).u.Hard.Exception = 1; \
00752
(OUTPTE).u.Hard.Owner = MI_DETERMINE_OWNER(PPTE); \
00753
(OUTPTE).u.Long |= (MmProtectToPteMask[(PPTE)->u.Trans.Protection]);
00754
#endif
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783 #define MI_SET_PTE_IN_WORKING_SET(PTE, WSINDEX) { \
00784
MMPTE _TempPte; \
00785
_TempPte = *(PTE); \
00786
_TempPte.u.Hard.SoftwareWsIndex = (WSINDEX); \
00787
*(PTE) = _TempPte; \
00788
}
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810 #define MI_GET_WORKING_SET_FROM_PTE(PTE) (ULONG)(PTE)->u.Hard.SoftwareWsIndex
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832 #define MI_SET_PTE_WRITE_COMBINE(PTE) \
00833
((PTE).u.Hard.Cache = MM_PTE_CACHE_DISABLED)
00834
00835 #define MI_SET_PTE_WRITE_COMBINE2(PTE) \
00836
((PTE).u.Hard.Cache = MM_PTE_CACHE_DISPLAY)
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859 #define MI_SET_PTE_DIRTY(PTE) (PTE).u.Hard.Dirty = 1
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882 #define MI_SET_PTE_CLEAN(PTE) (PTE).u.Hard.Dirty = 0
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906 #define MI_IS_PTE_DIRTY(PTE) ((PTE).u.Hard.Dirty != 0)
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934 #define MI_SET_GLOBAL_BIT_IF_SYSTEM(OUTPTE,PPTE)
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961 #define MI_SET_GLOBAL_STATE(PTE,STATE)
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986 #define MI_ENABLE_CACHING(PTE) ((PTE).u.Hard.Cache = MM_PTE_CACHE_ENABLED)
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011 #define MI_DISABLE_CACHING(PTE) ((PTE).u.Hard.Cache = MM_PTE_CACHE_DISABLED)
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037 #define MI_IS_CACHING_DISABLED(PPTE) \
01038
((PPTE)->u.Hard.Cache == MM_PTE_CACHE_DISABLED)
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063 #define MI_SET_PFN_DELETED(PPFN) (((PPFN)->PteAddress = (PMMPTE)((INT_PTR)(LONG)0xFFFFFFFF)))
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089 #define MI_IS_PFN_DELETED(PPFN) \
01090
((PPFN)->PteAddress == (PMMPTE)((INT_PTR)(LONG)0xFFFFFFFF))
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120 #define MI_CHECK_PAGE_ALIGNMENT(PAGE,PPTE)
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148 #define MI_INITIALIZE_HYPERSPACE_MAP(INDEX)
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172 #define MI_GET_PAGE_COLOR_FROM_PTE(PTEADDRESS) \
01173
((ULONG)((MmSystemPageColor++) & MmSecondaryColorMask))
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199 #define MI_GET_PAGE_COLOR_FROM_VA(ADDRESS) \
01200
((ULONG)((MmSystemPageColor++) & MmSecondaryColorMask))
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225 #define MI_GET_PAGE_COLOR_FROM_SESSION(_SessionSpace) \
01226
((ULONG)((_SessionSpace->Color++) & MmSecondaryColorMask))
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251 #define MI_PAGE_COLOR_PTE_PROCESS(PTE,COLOR) \
01252
(ULONG)((ULONG_PTR)((*(COLOR))++) & MmSecondaryColorMask)
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278 #define MI_PAGE_COLOR_VA_PROCESS(ADDRESS,COLOR) \
01279
((ULONG)((*(COLOR))++) & MmSecondaryColorMask)
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303 #define MI_GET_NEXT_COLOR(COLOR) ((COLOR + 1) & MM_COLOR_MASK)
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326 #define MI_GET_PREVIOUS_COLOR(COLOR) (0)
01327
01328
01329 #define MI_GET_SECONDARY_COLOR(PAGE,PFN) ((ULONG)(PAGE & MmSecondaryColorMask))
01330
01331
01332 #define MI_GET_COLOR_FROM_SECONDARY(SECONDARY_COLOR) (0)
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361 #define MI_GET_MODIFIED_PAGE_BY_COLOR(PAGE,COLOR) \
01362
PAGE = MmModifiedPageListByColor[COLOR].Flink
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393 #define MI_GET_MODIFIED_PAGE_ANY_COLOR(PAGE,COLOR) \
01394
{ \
01395
if (MmTotalPagesForPagingFile == 0) { \
01396
PAGE = MM_EMPTY_LIST; \
01397
} else { \
01398
PAGE = MmModifiedPageListByColor[COLOR].Flink; \
01399
} \
01400
}
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426 #define MI_MAKE_VALID_PTE_WRITE_COPY(PPTE) \
01427
if ((PPTE)->u.Hard.Write == 1) { \
01428
(PPTE)->u.Hard.CopyOnWrite = 1; \
01429
(PPTE)->u.Hard.Write = 0; \
01430
}
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
#if defined(_MIALT4K_)
01455
01456 #define MI_DETERMINE_OWNER(PPTE) \
01457
((((((PPTE) >= (PMMPTE)PTE_UBASE) && ((PPTE) <= MiHighestUserPte))) || \
01458
(MI_IS_ALT_PAGE_TABLE_ADDRESS(PPTE))) ? 3 : 0)
01459
01460
#else
01461
01462
#define MI_DETERMINE_OWNER(PPTE) \
01463
((((PPTE) >= (PMMPTE)PTE_UBASE) && \
01464
((PPTE) <= MiHighestUserPte)) ? 3 : 0)
01465
#endif
01466
01467
01468
01469
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488 #define MI_SET_ACCESSED_IN_PTE(PPTE,ACCESSED)
01489
01490
01491
01492
01493
01494
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512 #define MI_GET_ACCESSED_IN_PTE(PPTE) 0
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537 #define MI_SET_OWNER_IN_PTE(PPTE,OWNER)
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562 #define MI_GET_OWNER_IN_PTE(PPTE) KernelMode
01563
01564
01565
01566
01567
01568
01569
01570 #define CLEAR_FOR_PROTO_PTE_ADDRESS ((ULONG)0x701)
01571
01572
01573
01574
01575
01576 #define CLEAR_FOR_PAGE_FILE 0x000003E0
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609 #define MI_SET_PAGING_FILE_INFO(OUTPTE,PTE,FILEINFO,OFFSET) \
01610
(OUTPTE).u.Long = (((PTE).u.Soft.Protection << MM_PROTECT_FIELD_SHIFT) | \
01611
((ULONGLONG)(FILEINFO) << _MM_PAGING_FILE_LOW_SHIFT) | \
01612
((ULONGLONG)(OFFSET) << _MM_PAGING_FILE_HIGH_SHIFT));
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642
01643
01644
01645 #define MiPteToProto(lpte) \
01646
((PMMPTE) ((ULONG_PTR)((lpte)->u.Proto.ProtoAddress) + MmProtopte_Base))
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669
01670
01671
01672 #define MiProtoAddressForPte(proto_va) \
01673
(( (ULONGLONG)((ULONG_PTR)proto_va - MmProtopte_Base) << \
01674
(_MM_PROTO_ADDRESS_SHIFT)) | MM_PTE_PROTOTYPE_MASK)
01675
01676 #define MISetProtoAddressForPte(PTE, proto_va) \
01677
(PTE).u.Long = 0; \
01678
(PTE).u.Proto.Prototype = 1; \
01679
(PTE).u.Proto.ProtoAddress = (ULONG_PTR)proto_va - MmProtopte_Base;
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711 #define MiProtoAddressForKernelPte(proto_va) MiProtoAddressForPte(proto_va)
01712
01713
01714 #define MM_SUBSECTION_MAP (128*1024*1024)
01715
01716
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742 #define MiGetSubsectionAddress(lpte) \
01743
(((lpte)->u.Subsect.WhichPool == 1) ? \
01744
((PSUBSECTION)((ULONG_PTR)MmSubsectionBase + \
01745
((ULONG_PTR)(lpte)->u.Subsect.SubsectionAddress))) \
01746
: \
01747
((PSUBSECTION)((ULONG_PTR)MM_NONPAGED_POOL_END - \
01748
((ULONG_PTR)(lpte)->u.Subsect.SubsectionAddress))))
01749
01750
01751
01752
01753
01754
01755
01756
01757
01758
01759
01760
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774 #define MiGetSubsectionAddressForPte(VA) \
01775
( ((ULONG_PTR)(VA) < (ULONG_PTR)KSEG2_BASE) ? \
01776
( ((ULONGLONG)((ULONG_PTR)VA - (ULONG_PTR)MmSubsectionBase) \
01777
<< (_MM_PTE_SUBSECTION_ADDRESS_SHIFT)) | 0x80) \
01778
: \
01779
((ULONGLONG)((ULONG_PTR)MM_NONPAGED_POOL_END - (ULONG_PTR)VA) \
01780
<< (_MM_PTE_SUBSECTION_ADDRESS_SHIFT)) )
01781
01782 #define MiSetSubsectionAddressForPte(PTE, VA) \
01783
(PTE).u.Long = 0; \
01784
if ((ULONG_PTR)(VA) < (ULONG_PTR)KSEG2_BASE) { \
01785
(PTE).u.Subsect.SubsectionAddress = (ULONG_PTR)VA - (ULONG_PTR)MmSubsectionBase; \
01786
(PTE).u.Subsect.WhichPool = 1; \
01787
} else { \
01788
(PTE).u.Subsect.SubsectionAddress = (ULONG_PTR)MM_NONPAGED_POOL_END - (ULONG_PTR)VA; \
01789
}
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814 #define MiGetPpeOffset(va) ((ULONG)(((ULONG_PTR)(va) >> PDI1_SHIFT) & PDI_MASK))
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837 #define MiGetPdeOffset(va) ((ULONG) (((ULONG_PTR)(va) >> PDI_SHIFT) & PDI_MASK))
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853
01854
01855
01856
01857
01858
01859
01860
01861
01862
01863 #define MiGetPpePdeOffset(va) ((ULONG) ((ULONG_PTR)(va) >> PDI_SHIFT))
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886 #define MiGetPteOffset(va) ((ULONG) (((ULONG_PTR)(va) >> PTI_SHIFT) & PDI_MASK))
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911 #define MiGetVirtualAddressMappedByPpe(PPE) \
01912
MiGetVirtualAddressMappedByPte(MiGetVirtualAddressMappedByPde(PPE))
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935 #define MiGetVirtualAddressMappedByPde(Pde) \
01936
MiGetVirtualAddressMappedByPte(MiGetVirtualAddressMappedByPte(Pde))
01937
01938
01939
01940
01941
01942
01943
01944
01945
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
#ifdef _WIN64
01960
01961
#define MiGetVirtualAddressMappedByPte(PTE) \
01962
(((ULONG_PTR)(PTE) & PTA_SIGN) ? \
01963
(PVOID)(((ULONG_PTR)(PTE) & VRN_MASK) | VA_FILL | \
01964
(((ULONG_PTR)(PTE)-PTE_BASE) << (PAGE_SHIFT - PTE_SHIFT))) : \
01965
(PVOID)(((ULONG_PTR)(PTE) & VRN_MASK) | (((ULONG_PTR)(PTE)-PTE_BASE) << (PAGE_SHIFT - PTE_SHIFT))))
01966
01967
#else
01968
01969 #define MiGetVirtualAddressMappedByPte(PTE) ((PVOID)((ULONG_PTR)(PTE) << (PAGE_SHIFT - PTE_SHIFT)))
01970
01971
#endif
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995 #define MiIsVirtualAddressOnPpeBoundary(VA) (((ULONG_PTR)(VA) & PAGE_DIRECTORY1_MASK) == 0)
01996
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017
02018
02019 #define MiIsVirtualAddressOnPdeBoundary(VA) (((ULONG_PTR)(VA) & PAGE_DIRECTORY2_MASK) == 0)
02020
02021
02022
02023
02024
02025
02026
02027
02028
02029
02030
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042
02043 #define MiIsPteOnPpeBoundary(PTE) (((ULONG_PTR)(PTE) & (MM_VA_MAPPED_BY_PDE - 1)) == 0)
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063
02064
02065
02066
02067
02068 #define MiIsPteOnPdeBoundary(PTE) (((ULONG_PTR)(PTE) & (PAGE_SIZE - 1)) == 0)
02069
02070
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090
02091 #define GET_PAGING_FILE_NUMBER(PTE) ((ULONG) (PTE).u.Soft.PageFileLow)
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115 #define GET_PAGING_FILE_OFFSET(PTE) ((ULONG) (PTE).u.Soft.PageFileHigh)
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140 #define IS_PTE_NOT_DEMAND_ZERO(PTE) \
02141
((PTE).u.Long & ((ULONG_PTR)0xFFFFFFFFFFFFF000 | \
02142
MM_PTE_VALID_MASK | \
02143
MM_PTE_PROTOTYPE_MASK | \
02144
MM_PTE_TRANSITION_MASK))
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166
02167
02168 #define MI_MAKING_VALID_PTE_INVALID(SYSTEM_WIDE)
02169
02170
02171
02172
02173
02174
02175
02176
02177
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187
02188
02189
02190
02191
02192 #define MI_MAKING_MULTIPLE_PTES_INVALID(SYSTEM_WIDE)
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216 #define MI_MAKE_PROTECT_WRITE_COPY(PTE) \
02217
if ((PTE).u.Soft.Protection & MM_PROTECTION_WRITE_MASK) { \
02218
(PTE).u.Long |= MM_PROTECTION_COPY_MASK << MM_PROTECT_FIELD_SHIFT; \
02219
}
02220
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242
02243
02244
02245
02246
02247
02248
02249
02250 #define MI_SET_PAGE_DIRTY(PPTE,VA,PFNHELD) \
02251
if ((PPTE)->u.Hard.Dirty == 1) { \
02252
MiSetDirtyBit ((VA),(PPTE),(PFNHELD)); \
02253
}
02254
02255
02256
02257
02258
02259
02260
02261
02262
02263
02264
02265
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284
02285
02286 #define MI_NO_FAULT_FOUND(TEMP,PPTE,VA,PFNHELD) \
02287
if (StoreInstruction && ((PPTE)->u.Hard.Dirty == 0)) { \
02288
MiSetDirtyBit ((VA),(PPTE),(PFNHELD)); \
02289
}
02290
02291
02292
02293
02294
02295
02296
02297
02298
02299
02300
02301
02302
02303
02304
02305
02306
02307
02308
02309
02310
02311
02312
02313
02314
02315
02316
02317
02318
02319
02320 #define MI_CAPTURE_DIRTY_BIT_TO_PFN(PPTE,PPFN) \
02321
ASSERT (KeGetCurrentIrql() > APC_LEVEL); \
02322
if (((PPFN)->u3.e1.Modified == 0) && \
02323
((PPTE)->u.Hard.Dirty != 0)) { \
02324
(PPFN)->u3.e1.Modified = 1; \
02325
if (((PPFN)->OriginalPte.u.Soft.Prototype == 0) && \
02326
((PPFN)->u3.e1.WriteInProgress == 0)) { \
02327
MiReleasePageFileSpace ((PPFN)->OriginalPte); \
02328
(PPFN)->OriginalPte.u.Soft.PageFileHigh = 0; \
02329
} \
02330
}
02331
02332
02333
02334
02335
02336
02337
02338
02339
02340
02341
02342
02343
02344
02345
02346
02347
02348
02349
02350
02351
02352
02353
02354
02355 #define MI_IS_PHYSICAL_ADDRESS(Va) \
02356
((((ULONG_PTR)(Va) >= KSEG3_BASE) && ((ULONG_PTR)(Va) < KSEG3_LIMIT)) || \
02357
(((ULONG_PTR)Va >= KSEG0_BASE) && ((ULONG_PTR)Va < KSEG2_BASE)))
02358
02359
02360
02361
02362
02363
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381 PVOID
KiGetPhysicalAddress(
02382 IN PVOID VirtualAddress
02383 );
02384
02385 #define MI_CONVERT_PHYSICAL_TO_PFN(Va) \
02386
(((ULONG_PTR)(Va) < KSEG0_BASE) ? \
02387
((PFN_NUMBER)(((ULONG_PTR)(Va) - KSEG3_BASE) >> PAGE_SHIFT)) : \
02388
((PFN_NUMBER)(((ULONG_PTR)KiGetPhysicalAddress(Va)) >> PAGE_SHIFT)))
02389
02390
02391
typedef struct _MMCOLOR_TABLES {
02392 PFN_NUMBER
Flink;
02393 PVOID
Blink;
02394 }
MMCOLOR_TABLES, *
PMMCOLOR_TABLES;
02395
02396
typedef struct _MMPRIMARY_COLOR_TABLES {
02397 LIST_ENTRY ListHead;
02398 }
MMPRIMARY_COLOR_TABLES, *
PMMPRIMARY_COLOR_TABLES;
02399
02400
02401
#if MM_MAXIMUM_NUMBER_OF_COLORS > 1
02402
extern MMPFNLIST MmFreePagesByPrimaryColor[2][
MM_MAXIMUM_NUMBER_OF_COLORS];
02403
#endif
02404
02405 extern PMMCOLOR_TABLES MmFreePagesByColor[2];
02406
02407 extern ULONG
MmTotalPagesForPagingFile;
02408
02409
02410
02411
02412
02413
02414 #define _MM_PAGING_FILE_LOW_SHIFT 28
02415 #define _MM_PAGING_FILE_HIGH_SHIFT 32
02416
02417 #define MI_PTE_LOOKUP_NEEDED ((ULONG64)0xffffffff)
02418
02419
typedef struct _MMPTE_SOFTWARE {
02420 ULONGLONG
Valid : 1;
02421 ULONGLONG
Prototype : 1;
02422 ULONGLONG
Protection : 5;
02423 ULONGLONG
Transition : 1;
02424 ULONGLONG
UsedPageTableEntries :
PTE_PER_PAGE_BITS;
02425 ULONGLONG
Reserved : 20 -
PTE_PER_PAGE_BITS;
02426 ULONGLONG
PageFileLow: 4;
02427 ULONGLONG
PageFileHigh : 32;
02428 }
MMPTE_SOFTWARE;
02429
02430
typedef struct _MMPTE_TRANSITION {
02431 ULONGLONG
Valid : 1;
02432 ULONGLONG
Prototype : 1;
02433 ULONGLONG
Protection : 5;
02434 ULONGLONG
Transition : 1;
02435 ULONGLONG
Rsvd0 :
PAGE_SHIFT - 8;
02436 ULONGLONG
PageFrameNumber : 50 -
PAGE_SHIFT;
02437 ULONGLONG
Rsvd1 : 14;
02438 }
MMPTE_TRANSITION;
02439
02440
02441 #define _MM_PROTO_ADDRESS_SHIFT 12
02442
02443
typedef struct _MMPTE_PROTOTYPE {
02444 ULONGLONG
Valid : 1;
02445 ULONGLONG
Prototype : 1;
02446 ULONGLONG
ReadOnly : 1;
02447 ULONGLONG
Rsvd : 9;
02448 ULONGLONG
ProtoAddress : 52;
02449 }
MMPTE_PROTOTYPE;
02450
02451
02452 #define _MM_PTE_SUBSECTION_ADDRESS_SHIFT 12
02453
02454
typedef struct _MMPTE_SUBSECTION {
02455 ULONGLONG
Valid : 1;
02456 ULONGLONG
Prototype : 1;
02457 ULONGLONG
Protection : 5;
02458 ULONGLONG
WhichPool : 1;
02459 ULONGLONG
Rsvd : 4;
02460 ULONGLONG
SubsectionAddress : 52;
02461 }
MMPTE_SUBSECTION;
02462
02463
typedef struct _MMPTE_LIST {
02464 ULONGLONG
Valid : 1;
02465 ULONGLONG
OneEntry : 1;
02466 ULONGLONG
filler10 : 10;
02467 ULONGLONG
NextEntry : 32;
02468 ULONGLONG
Rsvd : 20;
02469 }
MMPTE_LIST;
02470
02471
02472
02473
02474
02475
02476 #define _HARDWARE_PTE_WORKING_SET_BITS 11
02477
02478
typedef struct _MMPTE_HARDWARE {
02479 ULONGLONG
Valid : 1;
02480 ULONGLONG
Rsvd0 : 1;
02481 ULONGLONG
Cache : 3;
02482 ULONGLONG
Accessed : 1;
02483 ULONGLONG
Dirty : 1;
02484 ULONGLONG
Owner : 2;
02485 ULONGLONG
Execute : 1;
02486 ULONGLONG
Write : 1;
02487 ULONGLONG
Rsvd1 :
PAGE_SHIFT - 12;
02488 ULONGLONG
CopyOnWrite : 1;
02489 ULONGLONG
PageFrameNumber : 50 -
PAGE_SHIFT;
02490 ULONGLONG
Rsvd2 : 2;
02491 ULONGLONG
Exception : 1;
02492 ULONGLONG
SoftwareWsIndex :
_HARDWARE_PTE_WORKING_SET_BITS;
02493 }
MMPTE_HARDWARE, *
PMMPTE_HARDWARE;
02494
02495 typedef struct _MMPTE_LARGEPAGE {
02496 ULONGLONG
Valid : 1;
02497 ULONGLONG
Rsvd0 : 1;
02498 ULONGLONG
Cache : 3;
02499 ULONGLONG
Accessed : 1;
02500 ULONGLONG
Dirty : 1;
02501 ULONGLONG
Owner : 2;
02502 ULONGLONG
Execute : 1;
02503 ULONGLONG
Write : 1;
02504 ULONGLONG
Rsvd1 :
PAGE_SHIFT - 12;
02505 ULONGLONG
CopyOnWrite : 1;
02506 ULONGLONG
PageFrameNumber : 50 -
PAGE_SHIFT;
02507 ULONGLONG
Rsvd2 : 2;
02508 ULONGLONG
Exception : 1;
02509 ULONGLONG
Rsvd3 : 1;
02510 ULONGLONG
LargePage : 1;
02511 ULONGLONG
PageSize : 6;
02512 ULONGLONG
Rsvd4 : 3;
02513 }
MMPTE_LARGEPAGE, *
PMMPTE_LARGEPAGE;
02514
02515 typedef struct _ALT_4KPTE {
02516 ULONGLONG
Commit : 1;
02517 ULONGLONG
Rsvd0 : 1;
02518 ULONGLONG
Cache : 3;
02519 ULONGLONG
Accessed : 1;
02520 ULONGLONG
Dirty : 1;
02521 ULONGLONG
Owner : 2;
02522 ULONGLONG
Execute : 1;
02523 ULONGLONG
Write : 1;
02524 ULONGLONG
Rsvd1 : 1;
02525 ULONGLONG
PteOffset : 32;
02526 ULONGLONG
Rsvd2 : 8;
02527 ULONGLONG
Exception : 1;
02528 ULONGLONG
Protection : 5;
02529 ULONGLONG
Lock : 1;
02530 ULONGLONG
FillZero : 1;
02531 ULONGLONG
NoAccess : 1;
02532 ULONGLONG
CopyOnWrite : 1;
02533 ULONGLONG
PteIndirect : 1;
02534 ULONGLONG
Private : 1;
02535 }
ALT_4KPTE, *
PALT_4KPTE;
02536
02537 #define MI_GET_PAGE_FRAME_FROM_PTE(PTE) ((ULONG)((PTE)->u.Hard.PageFrameNumber))
02538 #define MI_GET_PAGE_FRAME_FROM_TRANSITION_PTE(PTE) ((ULONG)((PTE)->u.Trans.PageFrameNumber))
02539 #define MI_GET_PROTECTION_FROM_SOFT_PTE(PTE) ((ULONG)((PTE)->u.Soft.Protection))
02540 #define MI_GET_PROTECTION_FROM_TRANSITION_PTE(PTE) ((ULONG)((PTE)->u.Trans.Protection))
02541
02542
02543
typedef struct _MMPTE {
02544
union {
02545 ULONGLONG
Long;
02546 MMPTE_HARDWARE Hard;
02547 MMPTE_LARGEPAGE Large;
02548 HARDWARE_PTE
Flush;
02549
MMPTE_PROTOTYPE Proto;
02550
MMPTE_SOFTWARE Soft;
02551
MMPTE_TRANSITION Trans;
02552
MMPTE_SUBSECTION Subsect;
02553
MMPTE_LIST List;
02554 ALT_4KPTE Alt;
02555 } u;
02556 }
MMPTE;
02557
02558 typedef MMPTE *
PMMPTE;
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584 #define MI_WRITE_VALID_PTE(_PointerPte, _PteContents) \
02585
(*(_PointerPte) = (_PteContents))
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611 #define MI_WRITE_INVALID_PTE(_PointerPte, _PteContents) \
02612
(*(_PointerPte) = (_PteContents))
02613
02614
02615
02616
02617
02618
02619
02620
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638 #define MI_WRITE_VALID_PTE_NEW_PROTECTION(_PointerPte, _PteContents) \
02639
(*(_PointerPte) = (_PteContents))
02640
02641
02642
02643
02644
02645
extern PVOID
02646
MiCreatePebOrTeb (
02647 IN
PEPROCESS TargetProcess,
02648 IN ULONG Size
02649 );
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679 #define MiFillMemoryPte(Destination, Length, Pattern) \
02680
RtlFillMemoryUlonglong ((Destination), (Length), (Pattern))
02681
02682
02683 #define KiWbInvalidateCache
02684
02685
02686
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
#if defined(_MIALT4K_)
02708 #define MI_IS_PAGE_TABLE_ADDRESS(VA) \
02709
((((ULONG_PTR)VA >= PTE_UBASE) && ((ULONG_PTR)VA <= (PDE_UTBASE + PAGE_SIZE))) || \
02710
(((ULONG_PTR)VA >= PTE_KBASE) && ((ULONG_PTR)VA <= (PDE_KTBASE + PAGE_SIZE))) || \
02711
(((ULONG_PTR)VA >= PTE_SBASE) && ((ULONG_PTR)VA <= (PDE_STBASE + PAGE_SIZE))) || \
02712
(((ULONG_PTR)VA >= ALT4KB_PERMISSION_TABLE_START) && \
02713
((ULONG_PTR)VA <= ALT4KB_PERMISSION_TABLE_END)))
02714
#else
02715
#define MI_IS_PAGE_TABLE_ADDRESS(VA) \
02716
((((ULONG_PTR)VA >= PTE_UBASE) && ((ULONG_PTR)VA <= (PDE_UTBASE + PAGE_SIZE))) || \
02717
(((ULONG_PTR)VA >= PTE_KBASE) && ((ULONG_PTR)VA <= (PDE_KTBASE + PAGE_SIZE))) || \
02718
(((ULONG_PTR)VA >= PTE_SBASE) && ((ULONG_PTR)VA <= (PDE_STBASE + PAGE_SIZE))))
02719
#endif
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742 #define MI_IS_HYPER_SPACE_ADDRESS(VA) \
02743
(((ULONG_PTR)VA >= (ULONG_PTR)HYPER_SPACE) && ((ULONG_PTR)VA <= HYPER_SPACE_END))
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766 #define MI_IS_PTE_ADDRESS(PTE) \
02767
(((PTE >= (PMMPTE)PTE_UBASE) && (PTE <= (PMMPTE)PTE_UTOP)) || \
02768
((PTE >= (PMMPTE)PTE_KBASE) && (PTE <= (PMMPTE)PTE_KTOP)) || \
02769
((PTE >= (PMMPTE)PTE_SBASE) && (PTE <= (PMMPTE)PTE_STOP)))
02770
02771
02772 #define MI_IS_PPE_ADDRESS(PTE) \
02773
(((PTE >= (PMMPTE)PDE_UTBASE) && (PTE <= (PMMPTE)(PDE_UTBASE + PAGE_SIZE))) || \
02774
((PTE >= (PMMPTE)PDE_KTBASE) && (PTE <= (PMMPTE)(PDE_KTBASE + PAGE_SIZE))) || \
02775
((PTE >= (PMMPTE)PDE_STBASE) && (PTE <= (PMMPTE)(PDE_STBASE + PAGE_SIZE))))
02776
02777
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789
02790
02791
02792
02793
02794
02795
02796
02797
02798 #define MI_IS_KERNEL_PTE_ADDRESS(PTE) \
02799
(((PMMPTE)PTE >= (PMMPTE)PTE_KBASE) && ((PMMPTE)PTE <= (PMMPTE)PTE_KTOP))
02800
02801
02802
02803
02804
02805
02806
02807
02808
02809
02810
02811
02812
02813
02814
02815
02816
02817
02818
02819
02820
02821
02822
02823 #define MI_IS_USER_PTE_ADDRESS(PTE) \
02824
((PTE >= (PMMPTE)PTE_UBASE) && (PTE <= (PMMPTE)PTE_UTOP))
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834
02835
02836
02837
02838
02839
02840
02841
02842
02843
02844
02845
02846
02847
02848 #define MI_IS_PAGE_DIRECTORY_ADDRESS(PDE) \
02849
(((PDE >= (PMMPTE)PDE_UBASE) && (PDE <= (PMMPTE)PDE_UTOP)) || \
02850
((PDE >= (PMMPTE)PDE_KBASE) && (PDE <= (PMMPTE)PDE_KTOP)) || \
02851
((PDE >= (PMMPTE)PDE_SBASE) && (PDE <= (PMMPTE)PDE_STOP)))
02852
02853
02854
02855
02856
02857
02858
02859
02860
02861
02862
02863
02864
02865
02866
02867
02868
02869
02870
02871
02872
02873
02874 #define MI_IS_USER_PDE_ADDRESS(PDE) \
02875
((PDE >= (PMMPTE)PDE_UBASE) && (PDE <= (PMMPTE)PDE_UTOP))
02876
02877
02878
02879
02880
02881
02882
02883
02884
02885
02886
02887
02888
02889
02890
02891
02892
02893
02894
02895
02896
02897
02898
02899 #define MI_IS_KERNEL_PDE_ADDRESS(PDE) \
02900
((PDE >= (PMMPTE)PDE_KBASE) && (PDE <= (PMMPTE)PDE_KTOP))
02901
02902
02903
02904
02905
02906
02907
02908
02909
02910
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924 #define MI_IS_PROCESS_SPACE_ADDRESS(VA) (((ULONG_PTR)VA >> 61) == UREGION_INDEX)
02925
02926
02927
02928
02929
02930
02931
02932
02933
02934
02935
02936
02937
02938
02939
02940
02941
02942
02943
02944
02945
02946
02947 #define MI_IS_SYSTEM_ADDRESS(VA) (((ULONG_PTR)VA >> 61) == KREGION_INDEX)
02948
02949
02950
02951
02952
02953
02954
02955
02956
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969
02970
02971
02972
02973
02974
02975
02976
02977
02978
02979
02980
02981
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992
02993
02994
02995
02996
02997
02998
02999
03000
03001
03002
03003
03004
03005
03006 #define KSEG0_ADDRESS(PAGE) \
03007
(PVOID)(KSEG0_BASE | ((PAGE) << PAGE_SHIFT))
03008
03009
03010 extern MMPTE ValidPpePte;
03011
03012 extern PFN_NUMBER
MmSystemParentTablePage;
03013
03014
03015
03016
03017
03018
03019
03020
03021
03022
03023
03024
03025
03026
03027
03028
03029
03030
03031
03032
03033
03034
03035
03036
#if PTE_THASH
03037
03038 __inline
03039
PMMPTE
03040 MiGetPpeAddress_XX(
03041 IN PVOID Va
03042 )
03043 {
03044
if (((ULONG_PTR)(Va) & PTE_BASE) == PTE_BASE) {
03045
03046
return ((
PMMPTE)(((ULONG_PTR)Va & VRN_MASK) | (PDE_TBASE +
PAGE_SIZE -
sizeof(
MMPTE))));
03047
03048 }
else {
03049
03050
return ((
PMMPTE)(__thash(__thash(__thash((ULONG_PTR)Va)))));
03051
03052 }
03053 }
03054
03055
#define MiGetPpeAddress(va) MiGetPpeAddress_XX((PVOID)(va))
03056
03057
#else
03058
03059 #define MiGetPpeAddress(Va) \
03060
(((((ULONG_PTR)(Va)) & PTE_BASE) == PTE_BASE) ? \
03061
((PMMPTE)((((ULONG_PTR)(Va)) & VRN_MASK) | (PDE_TBASE + PAGE_SIZE - sizeof(MMPTE)))) :\
03062
((PMMPTE)(((((ULONG_PTR)(Va)) & VRN_MASK)) | \
03063
((((((ULONG_PTR)(Va)) >> PDI1_SHIFT) << PTE_SHIFT) & \
03064
(~(PDE_TBASE|VRN_MASK)) ) + PDE_TBASE))))
03065
03066
#endif
03067
03068
03069
03070
03071
03072
03073
03074
03075
03076
03077
03078
03079
03080
03081
03082
03083
03084
03085
03086
03087
#if PTE_THASH
03088
03089 __inline
03090
PMMPTE
03091 MiGetPdeAddress_XX(
03092 IN PVOID Va
03093 )
03094 {
03095
if (((ULONG_PTR)(Va) & PDE_BASE) == PDE_BASE) {
03096
03097
return ((
PMMPTE)(((ULONG_PTR)Va & VRN_MASK) | (PDE_TBASE +
PAGE_SIZE -
sizeof(
MMPTE))));
03098
03099 }
else {
03100
03101
return ((
PMMPTE)(__thash(__thash((ULONG_PTR)(Va)))));
03102 }
03103 }
03104
03105
#define MiGetPdeAddress(va) MiGetPdeAddress_XX((PVOID)(va))
03106
03107
#else
03108
03109 #define MiGetPdeAddress(Va) \
03110
(((((ULONG_PTR)(Va)) & PDE_BASE) == PDE_BASE) ? \
03111
((PMMPTE)((((ULONG_PTR)(Va)) & VRN_MASK) | (PDE_TBASE + PAGE_SIZE - sizeof(MMPTE)))) :\
03112
((PMMPTE)(((((ULONG_PTR)(Va)) & VRN_MASK)) | \
03113
((((((ULONG_PTR)(Va)) >> PDI_SHIFT) << PTE_SHIFT) & (~(PDE_BASE|VRN_MASK))) + PDE_BASE))))
03114
03115
#endif
03116
03117
03118
03119
03120
03121
03122
03123
03124
03125
03126
03127
03128
03129
03130
03131
03132
03133
03134
03135
03136
03137
03138
03139
#if PTE_THASH
03140
03141 __inline
03142
PMMPTE
03143 MiGetPteAddress_XX(
03144 IN PVOID Va
03145 )
03146 {
03147
if (((ULONG_PTR)(Va) & PDE_TBASE) == PDE_TBASE) {
03148
03149
return ((
PMMPTE)(((ULONG_PTR)Va & VRN_MASK) | (PDE_TBASE +
PAGE_SIZE -
sizeof(
MMPTE))));
03150
03151 }
else {
03152
03153
return ((
PMMPTE)(__thash((ULONG_PTR)(Va))));
03154
03155 }
03156 }
03157
03158
#define MiGetPteAddress(va) MiGetPteAddress_XX((PVOID)(va))
03159
03160
#else
03161
03162 #define MiGetPteAddress(Va) \
03163
(((((ULONG_PTR)(Va)) & PDE_TBASE) == PDE_TBASE) ? \
03164
((PMMPTE)((((ULONG_PTR)(Va)) & VRN_MASK) | (PDE_TBASE + PAGE_SIZE - sizeof(MMPTE)))) :\
03165
((PMMPTE)(((((ULONG_PTR)(Va)) & VRN_MASK)) | \
03166
((((((ULONG_PTR)(Va)) >> PTI_SHIFT) << PTE_SHIFT) & (~(PTE_BASE|VRN_MASK))) + PTE_BASE))))
03167
03168
#endif
03169
03170
03171 #define MI_IS_PTE_PROTOTYPE(PointerPte) (!MI_IS_USER_PTE_ADDRESS (PointerPte))
03172
03173
03174
03175
03176
03177
03178
03179
03180
03181
03182
03183
03184
03185
03186
03187
03188
03189
03190
03191
03192
03193
03194 #define MI_IS_SYSTEM_CACHE_ADDRESS(VA) \
03195
(((PVOID)(VA) >= (PVOID)MmSystemCacheStart && \
03196
(PVOID)(VA) <= (PVOID)MmSystemCacheEnd))
03197
03198
03199
#if defined(_MIALT4K_)
03200
03201
03202
03203
03204
03205
03206
03207
03208 #define PAGE_4K 4096
03209 #define PAGE_4K_SHIFT 12
03210 #define PAGE_4K_MASK (PAGE_4K - 1)
03211 #define PAGE_4K_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_4K - 1)))
03212 #define ROUND_TO_4K_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_4K - 1) & ~(PAGE_4K - 1))
03213
03214 #define PAGE_NEXT_ALIGN(Va) ((PVOID)(PAGE_ALIGN((ULONG_PTR)Va + PAGE_SIZE - 1)))
03215
03216 #define BYTES_TO_4K_PAGES(Size) ((ULONG)((ULONG_PTR)(Size) >> PAGE_4K_SHIFT) + \
03217
(((ULONG)(Size) & (PAGE_4K - 1)) != 0))
03218
03219
03220
03221
03222
03223 #define SPLITS_PER_PAGE (PAGE_SIZE / PAGE_4K)
03224 #define PAGE_SHIFT_DIFF (PAGE_SHIFT - PAGE_4K_SHIFT)
03225
03226 #define ALT_PTE_SHIFT 3
03227
03228 #define ALT_PROTECTION_MASK (MM_PTE_EXECUTE_MASK|MM_PTE_WRITE_MASK)
03229
03230 #define MiGetAltPteAddress(VA) \
03231
((PMMPTE) (ALT4KB_PERMISSION_TABLE_START + \
03232
((((ULONG_PTR) (VA)) >> PAGE_4K_SHIFT) << ALT_PTE_SHIFT)))
03233
03234
03235
03236
03237
03238 #define MI_ALTFLG_FLUSH2G 0x0000000000000001
03239
03240
03241
03242
03243
03244 #define ALT_ALLOCATE 1
03245 #define ALT_COMMIT 2
03246 #define ALT_CHANGE 4
03247
03248
03249
03250
03251
03252 #define MM_ATE_COMMIT 0x0000000000000001
03253 #define MM_ATE_ACCESS 0x0000000000000020
03254
03255 #define MM_ATE_READONLY 0x0000000000000200
03256 #define MM_ATE_EXECUTE 0x0400000000000200
03257 #define MM_ATE_EXECUTE_READ 0x0400000000000200
03258 #define MM_ATE_READWRITE 0x0000000000000600
03259 #define MM_ATE_WRITECOPY 0x0020000000000200
03260 #define MM_ATE_EXECUTE_READWRITE 0x0400000000000600
03261 #define MM_ATE_EXECUTE_WRITECOPY 0x0420000000000400
03262
03263 #define MM_ATE_ZEROFILL 0x0800000000000000
03264 #define MM_ATE_NOACCESS 0x1000000000000000
03265 #define MM_ATE_COPY_ON_WRITE 0x2000000000000000
03266 #define MM_ATE_PRIVATE 0x8000000000000000
03267 #define MM_ATE_PROTO_MASK 0x0000000000000621
03268
03269
03270
03271
03272
03273
03274 #define _MAX_WOW64_ADDRESS (0x00000000080000000UI64)
03275
03276
MmX86Fault (
03277 IN BOOLEAN StoreInstruction,
03278 IN PVOID VirtualAddress,
03279 IN KPROCESSOR_MODE PreviousMode,
03280 IN PVOID TrapInformation
03281 );
03282
03283
VOID
03284
MiProtectFor4kPage(
03285 IN PVOID Base,
03286 IN SIZE_T Size,
03287 IN ULONG NewProtect,
03288 IN ULONG Flags,
03289 IN
PEPROCESS Process
03290 );
03291
03292
VOID
03293
MiProtectMapFileFor4kPage(
03294 IN PVOID Base,
03295 IN SIZE_T Size,
03296 IN ULONG NewProtect,
03297 IN PMMPTE PointerPte,
03298 IN
PEPROCESS Process
03299 );
03300
03301
VOID
03302
MiProtectImageFileFor4kPage(
03303 IN PVOID Base,
03304 IN SIZE_T Size,
03305 IN PMMPTE PointerPte,
03306 IN
PEPROCESS Process
03307 );
03308
03309
VOID
03310
MiReleaseFor4kPage(
03311 IN PVOID StartVirtual,
03312 IN PVOID EndVirtual,
03313 IN
PEPROCESS Process
03314 );
03315
03316
VOID
03317
MiDecommitFor4kPage(
03318 IN PVOID StartVirtual,
03319 IN PVOID EndVirtual,
03320 IN
PEPROCESS Process
03321 );
03322
03323
VOID
03324
MiDeleteFor4kPage(
03325 IN PVOID StartVirtual,
03326 IN PVOID EndVirtual,
03327 IN
PEPROCESS Process
03328 );
03329
03330
VOID
03331
MiQueryRegionFor4kPage(
03332 IN PVOID BaseAddress,
03333 IN PVOID EndAddress,
03334 IN OUT PSIZE_T RegionSize,
03335 IN OUT PULONG RegionState,
03336 IN OUT PULONG RegionProtect,
03337 IN
PEPROCESS Process
03338 );
03339
03340 ULONG
03341
MiQueryProtectionFor4kPage (
03342 IN PVOID BaseAddress,
03343 IN
PEPROCESS Process
03344 );
03345
03346
NTSTATUS
03347
MiInitializeAlternateTable(
03348
PEPROCESS Process
03349 );
03350
03351
VOID
03352
MiDeleteAlternateTable(
03353
PEPROCESS Process
03354 );
03355
03356
VOID
03357
MiLockFor4kPage(
03358 PVOID CapturedBase,
03359 SIZE_T CapturedRegionSize,
03360
PEPROCESS Process
03361 );
03362
03363
NTSTATUS
03364
MiUnlockFor4kPage(
03365 PVOID CapturedBase,
03366 SIZE_T CapturedRegionSize,
03367
PEPROCESS Process
03368 );
03369
03370 BOOLEAN
03371
MiShouldBeUnlockedFor4kPage(
03372 PVOID VirtualAddress,
03373
PEPROCESS Process
03374 );
03375
03376
VOID
03377
MiMarkSplitPages(
03378 IN PVOID StartVirtual,
03379 IN PVOID EndVirtual,
03380 IN PULONG Bitmap,
03381 IN BOOLEAN SetBit
03382 );
03383
03384 ULONG
03385
MiMakeProtectForNativePage(
03386 IN PVOID VirtualAddress,
03387 IN ULONG NewProtect,
03388 IN
PEPROCESS Process
03389 );
03390
03391
03392 extern ULONG
MmProtectToPteMaskForIA32[32];
03393 extern ULONG
MmProtectToPteMaskForSplit[32];
03394 extern ULONGLONG
MmProtectToAteMask[32];
03395
03396
03397 #define MiMakeProtectionAteMask(NewProtect) MmProtectToAteMask[NewProtect]
03398
03399
03400 #define _ALTPERM_BITMAP_MASK ((_MAX_WOW64_ADDRESS - 1) >> PTI_SHIFT)
03401
03402
#if 1
03403 #define MI_MAKE_VALID_PTE(OUTPTE,FRAME,PMASK,PPTE) \
03404
(OUTPTE).u.Long = 0; \
03405
(OUTPTE).u.Hard.Valid = 1; \
03406
(OUTPTE).u.Hard.Cache = MM_PTE_CACHE_ENABLED; \
03407
(OUTPTE).u.Hard.Exception = 1; \
03408
(OUTPTE).u.Hard.PageFrameNumber = FRAME; \
03409
(OUTPTE).u.Hard.Owner = MI_DETERMINE_OWNER(PPTE); \
03410
{ \
03411
PWOW64_PROCESS _Wow64Process = PsGetCurrentProcess()->Wow64Process; \
03412
if ((_Wow64Process != NULL) && \
03413
((PPTE >= (PMMPTE)PTE_UBASE) && \
03414
(PPTE < MiGetPteAddress(_MAX_WOW64_ADDRESS)))) { \
03415
if (MI_CHECK_BIT(_Wow64Process->AltPermBitmap, \
03416
((ULONG_PTR)PPTE >> PTE_SHIFT) & _ALTPERM_BITMAP_MASK) != 0) { \
03417
(OUTPTE).u.Long |= (MmProtectToPteMaskForSplit[PMASK]); \
03418
} else { \
03419
(OUTPTE).u.Long |= (MmProtectToPteMaskForIA32[PMASK]); \
03420
(OUTPTE).u.Hard.Accessed = 1; \
03421
} \
03422
} else { \
03423
(OUTPTE).u.Hard.Accessed = 1; \
03424
(OUTPTE).u.Long |= (MmProtectToPteMask[PMASK]);\
03425
}\
03426
}
03427
03428
03429 #define MI_MAKE_TRANSITION_PTE_VALID(OUTPTE,PPTE) \
03430
ASSERT (((PPTE)->u.Hard.Valid == 0) && \
03431
((PPTE)->u.Trans.Prototype == 0) && \
03432
((PPTE)->u.Trans.Transition == 1)); \
03433
(OUTPTE).u.Long = (PPTE)->u.Long & 0x1FFFFFFFE000; \
03434
(OUTPTE).u.Hard.Valid = 1; \
03435
(OUTPTE).u.Hard.Cache = MM_PTE_CACHE_ENABLED; \
03436
(OUTPTE).u.Hard.Exception = 1; \
03437
(OUTPTE).u.Hard.Owner = MI_DETERMINE_OWNER(PPTE); \
03438
{ \
03439
PWOW64_PROCESS _Wow64Process = PsGetCurrentProcess()->Wow64Process; \
03440
if ((_Wow64Process != NULL) && \
03441
((PPTE >= (PMMPTE)PTE_UBASE) && \
03442
(PPTE < MiGetPteAddress(_MAX_WOW64_ADDRESS)))) { \
03443
if (MI_CHECK_BIT(_Wow64Process->AltPermBitmap, \
03444
((ULONG_PTR)PPTE >> PTE_SHIFT) & _ALTPERM_BITMAP_MASK) != 0) { \
03445
(OUTPTE).u.Long |= (MmProtectToPteMaskForSplit[(PPTE)->u.Trans.Protection]); \
03446
} else { \
03447
(OUTPTE).u.Long |= (MmProtectToPteMaskForIA32[(PPTE)->u.Trans.Protection]); \
03448
(OUTPTE).u.Hard.Accessed = 1; \
03449
} \
03450
} else { \
03451
(OUTPTE).u.Hard.Accessed = 1; \
03452
(OUTPTE).u.Long |=(MmProtectToPteMask[(PPTE)->u.Trans.Protection]);\
03453
}\
03454
}
03455
#else
03456
#define MI_MAKE_VALID_PTE(OUTPTE,FRAME,PMASK,PPTE) \
03457
(OUTPTE).u.Long = 0; \
03458
(OUTPTE).u.Hard.Valid = 1; \
03459
(OUTPTE).u.Hard.Cache = MM_PTE_CACHE_ENABLED; \
03460
(OUTPTE).u.Hard.Exception = 1; \
03461
(OUTPTE).u.Hard.PageFrameNumber = FRAME; \
03462
(OUTPTE).u.Hard.Owner = MI_DETERMINE_OWNER(PPTE); \
03463
{ \
03464
PWOW64_PROCESS _Wow64Process = PsGetCurrentProcess()->Wow64Process; \
03465
if ((_Wow64Process != NULL) && \
03466
((PPTE >= (PMMPTE)PTE_UBASE) && \
03467
(PPTE < MiGetPteAddress(_MAX_WOW64_ADDRESS)))) { \
03468
(OUTPTE).u.Long |= MM_PTE_READONLY; \
03469
} else { \
03470
(OUTPTE).u.Hard.Accessed = 1; \
03471
(OUTPTE).u.Long |= (MmProtectToPteMask[PMASK]);\
03472
}\
03473
}
03474
03475
03476
#define MI_MAKE_TRANSITION_PTE_VALID(OUTPTE,PPTE) \
03477
ASSERT (((PPTE)->u.Hard.Valid == 0) && \
03478
((PPTE)->u.Trans.Prototype == 0) && \
03479
((PPTE)->u.Trans.Transition == 1)); \
03480
(OUTPTE).u.Long = (PPTE)->u.Long & 0x1FFFFFFFE000; \
03481
(OUTPTE).u.Hard.Valid = 1; \
03482
(OUTPTE).u.Hard.Cache = MM_PTE_CACHE_ENABLED; \
03483
(OUTPTE).u.Hard.Exception = 1; \
03484
(OUTPTE).u.Hard.Owner = MI_DETERMINE_OWNER(PPTE); \
03485
{ \
03486
PWOW64_PROCESS _Wow64Process = PsGetCurrentProcess()->Wow64Process; \
03487
if ((_Wow64Process != NULL) && \
03488
((PPTE >= (PMMPTE)PTE_UBASE) && \
03489
(PPTE < MiGetPteAddress(_MAX_WOW64_ADDRESS)))) { \
03490
(OUTPTE).u.Long |= MM_PTE_READONLY; \
03491
} else { \
03492
(OUTPTE).u.Hard.Accessed = 1; \
03493
(OUTPTE).u.Long |=(MmProtectToPteMask[(PPTE)->u.Trans.Protection]);\
03494
}\
03495
}
03496
#endif
03497
03498 #define LOCK_ALTERNATE_TABLE(PWOW64) \
03499
ExAcquireFastMutex( &(PWOW64)->AlternateTableLock)
03500
03501 #define UNLOCK_ALTERNATE_TABLE(PWOW64) \
03502
ExReleaseFastMutex(&(PWOW64)->AlternateTableLock)
03503
03504 #define MI_IS_ALT_PAGE_TABLE_ADDRESS(PPTE) \
03505
(((PPTE) >= (PMMPTE)ALT4KB_PERMISSION_TABLE_START) && \
03506
((PPTE) < (PMMPTE)ALT4KB_PERMISSION_TABLE_END))
03507
03508
#endif
03509
03510
03511
03512
03513
03514
03515
03516
03517
03518
03519
03520
03521
03522
03523
03524
03525
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535
03536
03537
03538
03539
03540
03541
03542
03543
03544
03545
03546
03547
03548
03549
03550
03551
03552
03553
03554 #define MI_BARRIER_SYNCHRONIZE(TimeStamp)
03555
03556
03557
03558
03559
03560
03561
03562
03563
03564
03565
03566
03567
03568
03569
03570
03571
03572
03573
03574
03575
03576
03577
03578
03579
03580
03581 #define MI_BARRIER_STAMP_ZEROED_PAGE(PointerTimeStamp)
03582
03583
03584
03585
03586
03587
03588
03589
03590
03591
03592
03593
03594
03595
03596
03597
03598
03599
03600
03601
03602
03603
03604
03605
03606
03607
03608
03609
03610
03611
03612
03613
03614
03615
03616
03617
03618
03619
03620
03621
03622 #define MI_FLUSH_SINGLE_SESSION_TB(Virtual, Invalid, AllProcessors, PtePointer, PteValue, PreviousPte) \
03623
PreviousPte.u.Flush = *PtePointer; \
03624
*PtePointer = PteValue; \
03625
KeFlushEntireTb (TRUE, TRUE);
03626
03627
03628
03629
03630
03631
03632
03633
03634
03635
03636
03637
03638
03639
03640
03641
03642
03643
03644
03645
03646
03647
03648
03649
03650
03651 #define MI_FLUSH_ENTIRE_SESSION_TB(Invalid, AllProcessors) \
03652
KeFlushEntireTb (Invalid, AllProcessors);
03653
03654
VOID
03655
MiSweepCacheMachineDependent(
03656 IN PVOID VirtualAddress,
03657 IN SIZE_T Size,
03658 IN MEMORY_CACHING_TYPE CacheType
03659 );
03660
03661 #define MI_IS_PCR_PAGE(Va) (((PVOID)PCR <= Va) && (Va < (PVOID)(PCR+PAGE_SIZE)))
03662
03663
03664
03665
03666
03667
03668
03669
03670
03671
03672
03673
03674
03675
03676
03677
03678
03679
03680
03681
03682
03683
03684
03685 #define MI_IS_ADDRESS_VALID_FOR_KD(VirtualAddress) \
03686
((VirtualAddress <= (PVOID)(HYPER_SPACE_END)) || \
03687
(MI_IS_PTE_ADDRESS((PMMPTE)VirtualAddress)) || \
03688
(MI_IS_PAGE_DIRECTORY_ADDRESS((PMMPTE)VirtualAddress)) || \
03689
(MI_IS_PPE_ADDRESS((PMMPTE)VirtualAddress)) || \
03690
((VirtualAddress >= MM_SYSTEM_RANGE_START) && \
03691
(VirtualAddress < (PVOID)MM_SYSTEM_SPACE_END)) || \
03692
(MI_IS_SESSION_ADDRESS(VirtualAddress)) || \
03693
(MI_IS_PHYSICAL_ADDRESS(VirtualAddress)) || \
03694
(MI_IS_PCR_PAGE(VirtualAddress)))