we want to join two or more Irps (byte offsets are in sequence) into one Irp, for this we have to join the mdls of both the Irps following is the code. problem is that the data will be corrupt.
LOOP
if (!finalIrp->MdlAddress){
finalIrp->MdlAddress = partialIrp->MdlAddress;
next = finalIrp->MdlAddress->Next;
}
else{
next = partialIrp->MdlAddress;
next = next->Next;
}
LOOP END
next = NULL;
what is the problem?
Unless MDL describes physical pages that have been allocated by MmAllocatePagesForMd(), MDL gets build for some buffer - it just describes physical pages that correspond to this buffer. Hopefully, at this point you already understand that your question about joining MDLs is essentially “I have multiple buffers, and I want to merge them into one” - unless you have a valid virtual address for the whole buffer , all your tricks are just bound to corrupt the memory…
Anton Bassov
Not all stacks support the IRPs with a MDL chain at Irp->MdlAddress.
–
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
wrote in message news:xxxxx@ntdev…
> we want to join two or more Irps (byte offsets are in sequence) into one Irp,
for this we have to join the mdls of both the Irps following is the code.
problem is that the data will be corrupt.
>
> LOOP
>
> if (!finalIrp->MdlAddress){
> finalIrp->MdlAddress = partialIrp->MdlAddress;
> next = finalIrp->MdlAddress->Next;
> }
> else{
> next = partialIrp->MdlAddress;
> next = next->Next;
> }
> LOOP END
>
> next = NULL;
>
> what is the problem?
>
>
> Not all stacks support the IRPs with a MDL chain at Irp->MdlAddress.
Well, apparently the OP relies upon the direct IO, so that Irp->MdlAddress is valid. I think the problem here is a bit different. IIRC, by the time IRP reaches your driver that relies upon the direct IO, MDL is already locked and mapped into the kernel address space by the IO Manager, i.e. MmGetSystemAddressForMdlSafe() returns MDL-> MappedSystemVa. Under these circumstances
joinging MDLs is, essentially, pretty much like merging multiple buffers into the one, i.e. the result is just memory corruption. You could do it with unmapped MDLs, but doing it with the mapped ones seems to be somehow dodgy…
Anton Bassov
>driver that relies upon the direct IO, MDL is already locked and mapped into
the
kernel address space by the IO Manager, i.e.
IO manager always locks Irp->MdlAddress, but never ever maps it to system
space, this is the task of the driver if it wants so.
–
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com
>> driver that relies upon the direct IO, MDL is already locked and mapped into the
> kernel address space by the IO Manager, i.e.
IO manager always locks Irp->MdlAddress, but never ever maps it to system
space, this is the task of the driver if it wants so.
As it turns out, this is just one more occasion when I had a wrong vision of things. Thank
you for pointing it out …
Anton Bassov