From: uty on
I saw this piece kernel code, possibly from wrk project.

My question is

if (MI_IS_PHYSICAL_ADDRESS(BaseAddress)) {
PhysicalAddress.QuadPart = MI_CONVERT_PHYSICAL_TO_PFN (BaseAddress);
}
------------------------------------------------------------------------------------------
if (MI_PDE_MAPS_LARGE_PAGE (PointerPte)) {
PhysicalAddress.QuadPart = MI_GET_PAGE_FRAME_FROM_PTE
(PointerPte) +
MiGetPteOffset (BaseAddress);
}


These too pieces of code kind do the same work, according to macro
MI_IS_PHYSICAL_ADDRESS and MI_GET_PAGE_FRAME_FROM_PTE, is these necessary?

And how can it be sure during this function BaseAddress will not be paged
out?


Thanks :)

//////////////////////////////////////////////////////////////////////////////////////

if (MI_IS_PHYSICAL_ADDRESS(BaseAddress)) {
PhysicalAddress.QuadPart = MI_CONVERT_PHYSICAL_TO_PFN (BaseAddress);
}
else {

#if (_MI_PAGING_LEVELS>=4)
PointerPte = MiGetPxeAddress (BaseAddress);
if (PointerPte->u.Hard.Valid == 0) {
KdPrint(("MM:MmGetPhysicalAddressFailed base address was %p",
BaseAddress));
ZERO_LARGE (PhysicalAddress);
return PhysicalAddress;
}
#endif

#if (_MI_PAGING_LEVELS>=3)
PointerPte = MiGetPpeAddress (BaseAddress);
if (PointerPte->u.Hard.Valid == 0) {
KdPrint(("MM:MmGetPhysicalAddressFailed base address was %p",
BaseAddress));
ZERO_LARGE (PhysicalAddress);
return PhysicalAddress;
}
#endif

PointerPte = MiGetPdeAddress (BaseAddress);
if (PointerPte->u.Hard.Valid == 0) {
KdPrint(("MM:MmGetPhysicalAddressFailed base address was %p",
BaseAddress));
ZERO_LARGE (PhysicalAddress);
return PhysicalAddress;
}

if (MI_PDE_MAPS_LARGE_PAGE (PointerPte)) {
PhysicalAddress.QuadPart = MI_GET_PAGE_FRAME_FROM_PTE
(PointerPte) +
MiGetPteOffset (BaseAddress);
}
else {
PointerPte = MiGetPteAddress (BaseAddress);

if (PointerPte->u.Hard.Valid == 0) {
KdPrint(("MM:MmGetPhysicalAddressFailed base address was
%p",
BaseAddress));
ZERO_LARGE (PhysicalAddress);
return PhysicalAddress;
}
PhysicalAddress.QuadPart = MI_GET_PAGE_FRAME_FROM_PTE
(PointerPte);
}
}