In my filesystem filter driver, I Used IoAllocateMdl and MmProbeAndLockPages for Irp->UserBuffer, do I need to MmUnlockPages and IoFreeMdl? If it is needed, where to use them at? I try to use them after IoCompleteRequest, but it result in BSOD;
Humm…
I don’t quite understand what you are doing…
You allocate an IRP, memory, etc and then generally you call some OTHER driver. Then you wait for the IRP to complete. Once it is complete you can free the IRP and memory, etc.
You do NOT call IoCompleteRequest yourself. Instead, the “other driver” (mentioned above) is the one that interprets the IRP and memory, does something with it and eventually calls IoCompleteRequest. Then the “other driver” calls IoCompleteRequest you (the caller who is waiting for the request to complete) will find out that the request has finally completed.
Hope this makes sense.
Thomas F. Divine
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-293377-
xxxxx@lists.osr.com] On Behalf Of liyuncheng@163.com
Sent: Wednesday, July 11, 2007 11:05 PM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] When used Mmprobeandlockpages for Irp->Userbuffer, do
I need to MmUnlockPages?In my filesystem filter driver, I Used IoAllocateMdl and
MmProbeAndLockPages for Irp->UserBuffer, do I need to MmUnlockPages and
IoFreeMdl? If it is needed, where to use them at? I try to use them
after IoCompleteRequest, but it result in BSOD;
Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17You are currently subscribed to ntfsd as: xxxxx@pcausa.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
In certain scenario, I need to replace the Irp->UserBuffer in IRP_MJ_READ with something in another file, so I have to MmProbeAndLockPages the Irp->UserBuffer, else it would page fault sometimes. So the question raised!
Concerning your specific question, please read the WDK documentation for MmProbeAndLockPages. It answers your question:
"MmProbeAndLockPages can be called multiple times for the same page. Each successful call to MmProbeAndLockPages for an MDL must be matched by a call to MmUnlockPages for the same MDL.
Calls to MmProbeAndLockPages must be enclosed in a try/except block…"
Read first, then ask on the newsgroup.
Good luck!
Thomas F. Divine
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-293380-
xxxxx@lists.osr.com] On Behalf Of liyuncheng@163.com
Sent: Wednesday, July 11, 2007 11:41 PM
To: Windows File Systems Devs Interest List
Subject: RE:[ntfsd] When used Mmprobeandlockpages for Irp->Userbuffer,
do I need to MmUnlockPages?In certain scenario, I need to replace the Irp->UserBuffer in
IRP_MJ_READ with something in another file, so I have to
MmProbeAndLockPages the Irp->UserBuffer, else it would page fault
sometimes. So the question raised!
Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17You are currently subscribed to ntfsd as: xxxxx@pcausa.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
As I have to MmUnlockPages, where to unlock the pages and free the mdl?
in your scenario, you can set the complete routine which is responsible for
calling MmUnlockPages and IoFreeMdl,and remeber to set irp->MdlAddress to
NULL after MmUnlockPages and IoFreeMdl . or you can choose the simple way,
you don’t explicitly call MmUnlockPages and IoFreeMdl,let io manager to do
such thing .
danny
> In certain scenario, I need to replace the Irp->UserBuffer in IRP_MJ_READ
with something in another file,
The best solution for this is to unlock pages and free the MDL in your
CompletionRoutine and then restore the original MDL and User buffer
pointers, because the original MDL should also be unlocked and freed either
by IO Manager( during IRP completion ) or by the IRP creator.
If you replace Irp->UserBuffer then you should replace Irp->MdlAddress( if
it is not NULL ). Also, there is scenario when UserBuffer is NULL but
Irp->MdlAddress is valid - this is a request from Memory Manager.
–
Slava Imameyev, xxxxx@hotmail.com
wrote in message news:xxxxx@ntfsd…
> In certain scenario, I need to replace the Irp->UserBuffer in IRP_MJ_READ
> with something in another file, so I have to MmProbeAndLockPages the
> Irp->UserBuffer, else it would page fault sometimes. So the question
> raised!
>