我再练习另外一个1709的WIN10系统.加深印象:
1: kd> uf nt!MmGetVirtualForPhysical
nt!MmGetVirtualForPhysical:
fffff803`be81be60 488bc1 mov rax,rcx
fffff803`be81be63 48c1e80c shr rax,0Ch
fffff803`be81be67 488d1440 lea rdx,[rax+rax*2]
fffff803`be81be6b 4803d2 add rdx,rdx
fffff803`be81be6e 48b8080000008097ffff mov rax,0FFFF978000000008h
fffff803`be81be78 488b04d0 mov rax,qword ptr [rax+rdx*8]
fffff803`be81be7c 48c1e019 shl rax,19h
fffff803`be81be80 48ba0000000000edffff mov rdx,0FFFFED0000000000h ;PTE_BASE
fffff803`be81be8a 48c1e219 shl rdx,19h
fffff803`be81be8e 81e1ff0f0000 and ecx,0FFFh
fffff803`be81be94 482bc2 sub rax,rdx
fffff803`be81be97 48c1f810 sar rax,10h
fffff803`be81be9b 4803c1 add rax,rcx
fffff803`be81be9e c3 ret
PTE_BASE所在的VA处无效:
1: kd> db FFFFED0000000000
ffffed00`00000000 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000010 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000020 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000030 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000040 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000050 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000060 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000070 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
观察PTE_BASE(第1个PTE)信息:
描述的是NULL地址处的PTE,PDE,PPE, PXE信息
1: kd> !pte FFFFED0000000000
VA 0000000000000000
PXE at FFFFED76BB5DA000 PPE at FFFFED76BB400000 PDE at FFFFED7680000000 PTE at FFFFED0000000000
contains 0A0000000E974867 contains 0000000000000000
pfn e974 ---DA--UWEV contains 0000000000000000
not valid
PTE=(((VA&0x0000FFFFFFFFFFFF)>>12)<<3)+PTE_BASE
当VA=0时:
PTE=(((0&0x0000FFFFFFFFFFFF)>>12)<<3)+PTE_BASE
=PTE_BASE
所以VA为NULL处的1页的PTE(就是PTE_BASE的第1项,也就是PTE_BASE)是无效的。
1: kd> db FFFFED0000000000
ffffed00`00000000 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000010 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000020 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000030 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000040 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000050 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000060 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed00`00000070 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
(1)描述PTE_BASE的PTE(PDE_BASE)
PTE_BASE为FFFFED0000000000
PDE_BASE=(((PTE_BASE&0x0000FFFFFFFFFFFF)>>12)<<3)+PTE_BASE
=(((FFFFED0000000000&0x0000FFFFFFFFFFFF)>>12)<<3)+0xFFFFED0000000000
=0xFFFFED7680000000
PDE_BASE是无效的:
1: kd> db FFFFED7680000000
ffffed76`80000000 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000010 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000020 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000030 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000040 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000050 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000060 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000070 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
(2)描述PDE_BASE的PTE(PPE_BASE)
PPE_BASE=(((PDE_BASE&0x0000FFFFFFFFFFFF)>>12)<<3)+PTE_BASE
=(((FFFFED7680000000&0x0000FFFFFFFFFFFF)>>12)<<3)+0xFFFFED0000000000
=0xFFFFED76BB400000
观察PPE_BASE:
1: kd> db FFFFED76BB400000
ffffed76`bb400000 00 00 00 00 00 00 00 00-67 58 27 65 00 00 00 0a ........gX'e....
ffffed76`bb400010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
描述PDE_BASE的PTE(PPE_BASE)所在的内存是可读取的,其内容为:
*PPE_BASE=0x0000000000000000
通过用PPE_BASE及PDE_BASE计算得到到的PDE_BASE物理地址:
PHY_ADDR=((*PPE_BASE)&0x0000FFFFFFFFF000)+(PDE_BASE&0x0000000000000FFF)
=(0x0000000000000000&0x0000FFFFFFFFF000)+(FFFFED7680000000&0000000000000FFF)
=0
观察通过PPE_BASE及PDE_BASE计算到的PDE_BASE物理地址内容(验证PPE_BASE描述有效性):
1: kd> !db 0
# 0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# 10 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# 20 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# 30 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# 40 07 00 00 c0 00 00 00 00-00 00 00 00 00 00 00 00 ................
# 50 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# 60 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# 70 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
与
PDE_BASE本身所在VA处
1: kd> db FFFFED7680000000 ;PDE_BASE VA
ffffed76`80000000 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000010 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000020 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000030 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000040 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000050 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000060 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
ffffed76`80000070 ?? ?? ?? ?? ?? ?? ?? ??-?? ?? ?? ?? ?? ?? ?? ?? ????????????????
并不吻合,说明: PPE_BASE(描述PDE_BASE的PTE)所描述的PTE信息实际上是不正确的,只是PPE_BASE所在内存本身可读而已, 从前面也可以看出: PDE_BASE本身所在的页是无效的。
(3)描述PPE_BASE的PTE(PXE_BASE)
PXE_BASE=(((PPE_BASE&0x0000FFFFFFFFFFFF)>>12)<<3)+PTE_BASE
=(((FFFFED76BB400000&0x0000FFFFFFFFFFFF)>>12)<<3)+0xFFFFED0000000000
=0xFFFFED76BB5DA000
观察PXE_BASE
1: kd> db FFFFED76BB5DA000
ffffed76`bb5da000 67 48 97 0e 00 00 00 0a-00 00 00 00 00 00 00 00 gH..............
ffffed76`bb5da010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb5da020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb5da030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb5da040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb5da050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb5da060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb5da070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
PXE_BASE所在的内存是可读的,其内容为:
*PXE_BASE=0x0a0000000e974867
采用PXE_BASE及PPE_BASE计算到的PPE_BASE的物理地址为:
PHY_ADDR=((*PXE_BASE)&0x0000FFFFFFFFF000)+(PPE_BASE&0x0000000000000FFF)
=(0x0a0000000e974867&0x0000FFFFFFFFF000)+(0xFFFFED76BB400000&0x0000000000000FFF)
=0x00000e974000
观察通过PXE_BASE及PPE_BASE计算到的PPE_BASE物理地址内容(验证PXE_BASE描述有效性):
1: kd> !db 00000e974000
# e974000 00 00 00 00 00 00 00 00-67 58 27 65 00 00 00 0a ........gX'e....
# e974010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# e974020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# e974030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# e974040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# e974050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# e974060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
# e974070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
与
1: kd> db FFFFED76BB400000 ;PPE_BASE VA
ffffed76`bb400000 00 00 00 00 00 00 00 00-67 58 27 65 00 00 00 0a ........gX'e....
ffffed76`bb400010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400030 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400040 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400050 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400060 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
ffffed76`bb400070 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
相吻合
PXE_BASE(描述PPE_BASE的PTE)所描述的PTE信息是有效的,描述的就是PPE_BASE,从前面也可以看出: PPE_BASE本身所在的内存页也是可读的。
(4)综上所述: 系统启动后, 对于VA为NULL的1页对应的PTE(PTE_BASE的第1项==PTE_BASE)是无效的
PXE_BASE(描述PPE_BASE的PTE)->PPE_BASE(描述PDE_BASE的PTE)->PDE_BASE(描述PTE_BASE的PTE)->PTE_BASE(页表基址)
PDE_BASE,PPE_BASE,PXE_BASE本质上都是PTE
如果PTE描述的目标内存页无效,则原PTE就无效,要么是PTE本身就不可读取, 要么是PTE本身可读取但描述信息不正确。
太麻烦了,假如再多几级页表,脑袋都要搅晕了。
感谢楼主的提问!让我自学到了一些有关页表方面的知识!获益匪浅!
最后于 2021-2-4 12:35
被低调putchar编辑
,原因: