questions about MmGetSystemAddressForMdlSafe

I am using this in the IOCTL handler of my driver to map a user address to
system space.

Irp->MdlAddress

Questions:

  1. The documentation here:
    https://msdn.microsoft.com/en-us/library/windows/hardware/ff554559(v=vs.85).aspx

or atleast my interpretation of it, doesnt seem to clarify whether I need
to free the mapped pages once I am done. So does the driver need to free
the system address mapped? My solution needs to be compatible with XP and
above, yes, we do still need XP support.

  1. The documentation doesnt specify any side effects of
    using HighPagePriority other than the fact that it can also fail. I am
    okay if it fails, but I am concerned, if there are possibilities that the
    system might deadlock under high stress scenarios instead of failing?
    Again, i am seeking answers for all OSs from XP till date.

thanks

Al

>or atleast my interpretation of it, doesnt seem to clarify whether I need to free the mapped pages

once I am done.

Not needed, MDL destruction will do this.

Note that IoFreeMdl does MmPrepareMdlForReuse+free the memory, and MmPrepareMdlForReuse (which is kinda a destructor for MDL, while IoFreeMdl is like “delete Mdl;” operator) will unmap the pages.

  1. The documentation doesnt specify any side effects of using HighPagePriority

I would avoid using it.

Also note: on Win8+, you need to provide non-executable mapping. For Win10+, this is checked by Verifier and HCK.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

  1. The pages are unmapped when the MDL is freed.
  2. The docs don’t allow for a deadlock