{
NTSTATUS RC = STATUS_SUCCESS;
PMDL PtrMdl = NULL;
ASSERT(PtrIrp);
try
{
// Is a MDL already present in the IRPif( !(PtrIrp->MdlAddress) )
{
// Allocate a MDLif (!(PtrMdl = IoAllocateMdl(PtrIrp->UserBuffer, Length, FALSE, FALSE, PtrIrp)))
{
RC = STATUS_INSUFFICIENT_RESOURCES;
try_return();
}
// Probe and lock the pages described by the MDL// We could encounter an exception doing so, swallow the exception// NOTE: The exception could be due to an unexpected (from our// perspective), invalidation of the virtual addresses that comprise// the passed in buffertry
{
MmProbeAndLockPages(PtrMdl, PtrIrp->RequestorMode, (IsReadOperation ? IoWriteAccess:IoReadAccess));
}
except(EXCEPTION_EXECUTE_HANDLER)
{
RC = STATUS_INVALID_USER_BUFFER;
}
}
try_exit: NOTHING;
}
finally
{
if (!NT_SUCCESS(RC) && PtrMdl)
{
IoFreeMdl(PtrMdl);
// You MUST NULL out the MdlAddress field in the IRP after freeing// the MDL, else the I/O Manager will also attempt to free the MDL// pointed to by that field during I/O completion. Obviously, the// pointer becomes invalid once you free the allocated MDL and hence// you will encounter a system crash during IRP completion.
PtrIrp->MdlAddress = NULL;
}
}
return(RC);
}
Generated on Sun May 27 2012 05:23:38 for ReactOS by
1.7.6.1
ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.