I think you have no need to build an MDL at all. You do not appear to be
using DMA to transfer data to a peripheral device. If you are using a buffer
that some other OS component allocates/deallocates there is NOTHING an MDL
will do for you to prevent the deallocation of that buffer. You have to have
legitimate access to that buffer, through some mechanism that guarantees
that the buffer will not be deallocated before you are finished using it.
(For example, the buffer was handed to you in an IRP that you do not
complete until you are finished doing whatever it is you are doing with the
buffer.) MDLs exist basically to create a list of physical pages associated
with a virtual memory buffer, and to temporarily make that virtual memory
buffer non-pageable so that the physical page list remains invariant over
the life of the MDL.
You *might* use an MDL to make a pageable buffer temporarily non-pageable,
but I rather doubt that this is something you need to do.
Also, your code snippet is rather flawed. Generally you need to wrap
MmProbeAndLockPages in a try/except handler. MmIsAddressValid is not going
to do anything for you. What IRQL is your code running at? If it is <
DISPATCH_LEVEL you don’t need the MDL at all. If it is >= DISPATCH_LEVEL and
pVirtualBuff is pageable, you are going to crash the system. If it is >=
DISPATCH_LEVEL and pVirtualBuff is nonpageable, you don’t need the MDL at
all. I think that pretty much covers all the possible cases 
=====================
Mark Roddy
Hollis Technology Solutions
www.hollistech.com
xxxxx@hollistech.com
-----Original Message-----
From: Michael Alekseev [mailto:xxxxx@nadatel.com]
Sent: Wednesday, June 25, 2003 3:01 AM
To: NT Developers Interest List
Subject: [ntdev] MmProbeAndLockPages question …
Hi all!
Are there any errors, see code below please. Just I’m not sure that this
code is 100% safe, is it so or not? Here, pVirtualBuff - was allocated and
is used by OS, and I need to use it also. I use MDLs and MmXxxx to be sure
that OS will not lock down, free or do smth else with that memory pool, am I
right doing all that stuff?
pMdl = IoAllocateMdl(pVirtualBuff,Length,FALSE,FALSE,NULL);
if( pMdl != NULL ){
MmProbeAndLockPages(pMdl,KernelMode,IoReadAccess);
if( MmIsAddressValid(pVirtualBuff) == TRUE ){
read data from pVirtualBuff here …
}
MmUnlockPages(pMdl);
IoFreeMdl(pMdl);
}
Thanks!
Michael
You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com