Question about MDL access

Hi all~

I write a filter driver below the ClassPnp to intercept the IRP, and
replace the its IRP->MdlAddress with
I allocated. The way I used is

[0] // Save the information in Irp
oldMDL = Irp->MdlAddress;
oldDataBuffer = Srb->DataBuffer;
oldDataTransferLength = Srb->DataTransferLength;

[1] newDataBuffer = ExAllocatePool(NonPagedPoolCacheAligned, 0x20000);
[2] newMDL = IoAllocateMdl(newDataBuffer,
0x20000,
FALSE,
FALSE,
(PIRP) NULL);

[3] MmBuildMdlForNonPagedPool(newMDL);

[4] //Replace the original Irp->MDL
Irp->MdlAddress = newMDL;
Srb->DataBuffer = newDataBuffer;
Srb->DataTransferLength = 0x20000;

[5] IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine ( Irp,
ReadCompletion, //
Completion Routine…
NULL,
TRUE,
TRUE,
TRUE );
return IoCallDriver (deviceExtension->TargetDeviceObject, Irp);

At the completion routine,
I move data from my allocated buffer to the original buffer, and restore the
necessary with

oldBuffer = MmGetSystemAddressForMdlSafe(oldMDL, HighPagePriority);
newBuffer = MmGetSystemAddressForMdlSafe(newMDL, HighPagePriority);
RtlMoveMemory(oldBuffer, newBuffer, oldDataTransferLength );

// Restore the original…
Irp->MdlAddress = pOldInfo->MDL;
Srb->DataBuffer = pOldInfo ->DataBuffer;
Srb->DataTransferLength = oldDataTransferLength ;
Irp->IoStatus.Information = oldDataTransferLength ;

// Free we allocated MDL…
ExFreePool (newBuffer);
IoFreeMdl (newMDL);

Install the driver and reboot the os, it loads properly until the monitor
turn off and on again.
I can only move the mouse pointer but no other thing be displayed.

Any help would be appreciated.
Thanks

David

I think the typical way of doing this would be to hang the current IRP on a
list, create a new IRP with MDL, copy OldIrp info as needed to NewIrp, and
pass NewIrp to IoCallDriver. Copy what is needed from NewIRP to OldIrp in
the completion routines and complete the IRPs as needed.


Gary G. Little
xxxxx@broadstor.com
xxxxx@inland.net