typedef BOOLEAN (*pfnReMapCallBack)(PVOID MapAddress, ULONG MapSize, PVOID MappedAddress, PVOID p1, PVOID p2, PVOID p3, PVOID p4);
BOOLEAN MmReMapSpace(PVOID MapAddress, ULONG MapSize, pfnReMapCallBack lpfn, PVOID p1, PVOID p2, PVOID p3, PVOID p4);
BOOLEAN MmReMapSpace(PVOID MapAddress, ULONG MapSize, pfnReMapCallBack lpfn, PVOID p1, PVOID p2, PVOID p3, PVOID p4)
{
BOOLEAN bRet = FALSE;
PMDL lpMemoryDescriptorList;
PVOID lpMappedAddress;
if (lpMemoryDescriptorList = IoAllocateMdl(MapAddress, MapSize, FALSE, FALSE, NULL))
{
__try
{
MmProbeAndLockPages(lpMemoryDescriptorList, KernelMode, IoReadAccess);
if (lpMappedAddress = MmMapLockedPagesSpecifyCache(lpMemoryDescriptorList, KernelMode, MmNonCached, NULL, FALSE, HighPagePriority))
{
if (NT_SUCCESS(MmProtectMdlSystemAddress(lpMemoryDescriptorList, PAGE_READWRITE)))
{
bRet = lpfn(MapAddress, MapSize, lpMappedAddress, p1, p2, p3, p4);
}
MmUnmapLockedPages(lpMappedAddress, lpMemoryDescriptorList);
}
MmUnlockPages(lpMemoryDescriptorList);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
IoFreeMdl(lpMemoryDescriptorList);
}
return bRet;
}