I’m trying to better my understanding of what I see as a bit of a discrepancy with these two functions. If you refer to the SwapBuffers example, IoAllocateMdl is called in certain situations but the only time IoFreeMdl is called is during a failure in PreOp. No where in PostOp is IoFreeMdl called.
Looking at the documentation, IoAllocateMdl makes no mention of having to call IoFreeMdl (unlike some other allocation functions where it explicitly states about the freeing) however, the IoFreeMdl page says “If a driver allocates an MDL to describe a buffer, it must explicitly release the MDL when operations on the buffer are done.”
So I guess my question that will help clear this up a bit is what happens between pre and post ops that makes calling IoFreeMdl not necessary?
MDL address is saved in Irp->MdlAddress and freed on IRP completion.
The exceptions to this rule are paging IO and STATUS_MORE_PROCESSING_REQUIRED returned from a completion routine without a following call to IoCompleteRequest.
Take a look at https://msdn.microsoft.com/en-us/library/windows/hardware/ff565421(v=vs.85).
aspx you will see that if you specify the IRP for IoAllocateMdl then the
freeing of the IRP takes care of freeing the MDL. If you just allocate a
MDL and don’t associate it with an IRP, then it your drivers responsibility
to free it.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Saturday, April 15, 2017 10:54 AM
To: Windows System Software Devs Interest List Subject: [ntdev] IoAllocateMdl / IoFreeMdl
I’m trying to better my understanding of what I see as a bit of a discrepancy with these two functions. If you refer to the SwapBuffers example, IoAllocateMdl is called in certain situations but the only time IoFreeMdl is called is during a failure in PreOp. No where in PostOp is IoFreeMdl called.
Looking at the documentation, IoAllocateMdl makes no mention of having to call IoFreeMdl (unlike some other allocation functions where it explicitly states about the freeing) however, the IoFreeMdl page says “If a driver allocates an MDL to describe a buffer, it must explicitly release the MDL when operations on the buffer are done.”
So I guess my question that will help clear this up a bit is what happens between pre and post ops that makes calling IoFreeMdl not necessary?
There is no way that by reading the doc page for IoAllocateMdl or the
non-minifiter documentation for mdl handling, that one could understand
what the rules are for minifilters. Nor does the swap buffer sample bother
to explain what it is doing.
Mark Roddy
On Sat, Apr 15, 2017 at 2:43 PM, wrote:
> Thanks Slava and Don. That helped clear things up. > > — > NTDEV is sponsored by OSR > > Visit the list online at: http:> showlists.cfm?list=ntdev> > > MONTHLY seminars on crash dump analysis, WDF, Windows internals and > software drivers! > Details at http: > > To unsubscribe, visit the List Server section of OSR Online at < > http://www.osronline.com/page.cfm?name=ListServer> ></http:></http:>
They could put the whole os source code up on github and it wouldn’t hurt
their bottom line.
Mark Roddy
On Sun, Apr 16, 2017 at 1:29 PM, wrote:
>
> > I wonder when MS management will get the idea that opening the Filter > Manager source code is not going to hurt MS bottom line. > > — > NTDEV is sponsored by OSR > > Visit the list online at: http:> showlists.cfm?list=ntdev> > > MONTHLY seminars on crash dump analysis, WDF, Windows internals and > software drivers! > Details at http: > > To unsubscribe, visit the List Server section of OSR Online at < > http://www.osronline.com/page.cfm?name=ListServer> ></http:></http:>