RE: Strange MDL behavior
- From: Carsten Schmidt <CarstenSchmidt@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 5 Sep 2009 02:26:01 -0700
Thanks for your reply. It was much appreciated, but I'm afraid it didn't help
me much. Since I am in an IRP_MJ_READ request I am expected to write to the
buffer. Furthermore, the MDL_MAPPED_TO_SYSTEM_VA flag is not set, i.e., the
memory is not mapped to virtual memory yet, so no other thread can write to
the memory simultaneously.
However, after I posted this question I think I have come across a
explanation to what is happening. The memory manager has mapped some MDL
pages to a dummy page (http://www.microsoft.com/whdc/driver/tips/mdl.mspx).
"Carsten Schmidt" wrote:
Hi,.
Sometimes I experience strange behavior when writing to the irp->MdlAddress
buffer of a disk filter driver I am writing.
In my IRP_MJ_READ routine I need to return the contents of an internal
buffer in stead of passing the request on to the disk driver.
If I enter the code below in the IRP_MJ_READ dispatch routine the assertion
occasionally fails, i.e., the RtlCopyMemory command did not copy correctly.
if (irp->MdlAddress) {
void* mdlBuffer = MmGetSystemAddressForMdlSafe(irp->MdlAddress,
NormalPagePriority);
ULONG length = IoGetCurrentIrpStackLocation(irp)->Parameters.Read.Length;
RtlCopyMemory(mdlBuffer, buffer, length);
ASSERT(RtlEqualMemory(mdlBuffer, buffer, length )); // <- This assertion
occasionally fails
}
Typically irp->MdlAddress->MdlFlags is (MDL_IO_PAGE_READ | MDL_PAGES_LOCKED)
before the MmGetSystemAddressForMdlSafe() call and (MDL_IO_PAGE_READ |
MDL_PAGES_LOCKED | MDL_MAPPED_TO_SYSTEM_VA) afterwards.
What really puzzles me is that after one ore more attempts the test code
below succeeds. It looks like the MDL is not fully ready yet on the first
attempt and that a separate thread is building it simultaneously.
do {
differs = FALSE;
RtlFillMemory(mdlBuffer, length, 'X');
for (i = 0; i < length; ++i) {
if (buffer[i] != 'X') {
differs = TRUE;
KdPrint( ("Byte %d of %d differs.\n", i, length) );
}
}
} while (differs);
Can anybody please tell me what is going on.
Thanks
- Follow-Ups:
- Re: Strange MDL behavior
- From: Alexander Grigoriev
- Re: Strange MDL behavior
- References:
- Strange MDL behavior
- From: Carsten Schmidt
- Strange MDL behavior
- Prev by Date: Re: Strange MDL behavior
- Next by Date: Re: Strange MDL behavior
- Previous by thread: Re: Strange MDL behavior
- Next by thread: Re: Strange MDL behavior
- Index(es):
Relevant Pages
|