1 /*++
2 
3   Copyright (c) Microsoft Corporation
4 
5   Module Name:
6 
7   FxRequestBaseKm.hpp
8 
9   Abstract:
10 
11   This module implements km specific functions for FxRequestBase.
12 
13   Author:
14 
15 
16 
17   Environment:
18 
19   Kernel mode only
20 
21   Revision History:
22 
23   --*/
24 
25 #ifndef _FXREQUESTBASEKM_HPP_
26 #define _FXREQUESTBASEKM_HPP_
27 
28 
29 VOID
30 __inline
31 FxRequestBase::FreeMdls(
32     VOID
33     )
34 {
35     PMDL pMdl, pNext;
36 
37     if (IsAllocatedFromIo() || IsCanComplete()) {
38       return;
39     }
40 
41     pMdl = m_Irp.GetIrp()->MdlAddress;
42 
43     //
44     // Free any PMDLs that the lower layer allocated.  Since we are going
45     // to free the PIRP ourself and not call IoCompleteRequest, we must mimic
46     // the behavior in IoCompleteRequest which does the same thing.
47     //
48     while (pMdl != NULL) {
49       pNext = pMdl->Next;
50 
51       if (pMdl->MdlFlags & MDL_PAGES_LOCKED) {
52         MmUnlockPages(pMdl);
53       }
54       else if (GetDriverGlobals()->FxVerifierOn) {
55         DbgPrint("pMdl %p, Flags 0x%x in PIRP %p should be locked",
56             pMdl, pMdl->MdlFlags, m_Irp.GetIrp());
57 
58         FxVerifierDbgBreakPoint(GetDriverGlobals());
59       }
60 
61       FxIrpMdlFree(pMdl);
62       pMdl = pNext;
63     }
64 
65     m_Irp.GetIrp()->MdlAddress = NULL;
66 }
67 
68 #endif // _FXREQUESTBASEKM_HPP
69