MCPcopy Create free account
hub / github.com/HoShiMin/Kernel-Bridge / GetPhysAddressFast4Kb

Function GetPhysAddressFast4Kb

Kernel-Bridge/API/Hypervisor.cpp:138–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136 }
137
138 unsigned long long GetPhysAddressFast4Kb(unsigned long long Cr3, unsigned long long VirtualAddress)
139 {
140 VIRTUAL_ADDRESS Va = { VirtualAddress };
141
142 auto Pml4ePhys = PFN_TO_PAGE(CR3{ Cr3 }.x64.Bitmap.PML4) + Va.x64.NonPageSize.Generic.PageMapLevel4Offset * sizeof(PML4E);
143 const PML4E* Pml4e = reinterpret_cast<const PML4E*>(MmGetVirtualForPhysical(PHYSICAL_ADDRESS{ .QuadPart = static_cast<long long>(Pml4ePhys) }));
144
145 auto PdpePhys = PFN_TO_PAGE(Pml4e->x64.Generic.PDP) + Va.x64.NonPageSize.Generic.PageDirectoryPointerOffset * sizeof(PDPE);
146 const PDPE* Pdpe = reinterpret_cast<const PDPE*>(MmGetVirtualForPhysical(PHYSICAL_ADDRESS{ .QuadPart = static_cast<long long>(PdpePhys) }));
147
148 auto PdePhys = PFN_TO_PAGE(Pdpe->x64.NonPageSize.Generic.PD) + Va.x64.NonPageSize.Generic.PageDirectoryOffset * sizeof(PDE);
149 const PDE* Pde = reinterpret_cast<const PDE*>(MmGetVirtualForPhysical(PHYSICAL_ADDRESS{ .QuadPart = static_cast<long long>(PdePhys) }));
150
151 auto PtePhys = PFN_TO_PAGE(Pde->x64.Page4Kb.PT) + Va.x64.NonPageSize.Page4Kb.PageTableOffset * sizeof(PTE);
152 const PTE* Pte = reinterpret_cast<const PTE*>(MmGetVirtualForPhysical(PHYSICAL_ADDRESS{ .QuadPart = static_cast<long long>(PtePhys) }));
153
154 return PFN_TO_PAGE(Pte->x64.Page4Kb.PhysicalPageFrameNumber) + Va.x64.NonPageSize.Page4Kb.PageOffset;
155 }
156 }
157}
158

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected