1 //
2 //    Copyright (C) Microsoft.  All rights reserved.
3 //
4 #ifndef __FXMDL_H__
5 #define __FXMDL_H__
6 
7 PMDL
8 FxMdlAllocateDebug(
9     __in PFX_DRIVER_GLOBALS FxDriverGlobals,
10     __in FxObject* Owner,
11     __in PVOID VirtualAddress,
12     __in ULONG Length,
13     __in BOOLEAN SecondaryBuffer,
14     __in BOOLEAN ChargeQuota,
15     __in PVOID CallersAddress
16     );
17 
18 VOID
19 FxMdlFreeDebug(
20     __in  PFX_DRIVER_GLOBALS FxDriverGlobals,
21     __in PMDL Mdl
22     );
23 
24 VOID
25 FxMdlDump(
26     __in PFX_DRIVER_GLOBALS FxDriverGlobals
27     );
28 
29 PMDL
30 FORCEINLINE
31 FxMdlAllocate(
32     __in PFX_DRIVER_GLOBALS FxDriverGlobals,
33     __in FxObject* Owner,
34     __in PVOID VirtualAddress,
35     __in ULONG Length,
36     __in BOOLEAN SecondaryBuffer,
37     __in BOOLEAN ChargeQuota
38     )
39 {
40     if (FxDriverGlobals->FxVerifierOn)  {
41         return FxMdlAllocateDebug(FxDriverGlobals,
42                                   Owner,
43                                   VirtualAddress,
44                                   Length,
45                                   SecondaryBuffer,
46                                   ChargeQuota,
47                                   _ReturnAddress());
48     }
49     else {
50         return IoAllocateMdl(VirtualAddress,
51                              Length,
52                              SecondaryBuffer,
53                              ChargeQuota,
54                              NULL);
55     }
56 }
57 
58 VOID
59 __inline
60 FxMdlFree(
61     __in PFX_DRIVER_GLOBALS FxDriverGlobals,
62     __in PMDL Mdl
63     )
64 {
65     if (FxDriverGlobals->FxVerifierOn) {
66         FxMdlFreeDebug(FxDriverGlobals, Mdl);
67     }
68     else {
69         IoFreeMdl(Mdl);
70     }
71 }
72 
73 VOID
74 __inline
75 FxIrpMdlFree(
76     __in PMDL Mdl
77     )
78 {
79     IoFreeMdl(Mdl);
80 }
81 
82 // Do not allow accidental usage by redefining these DDIs to uncompilable names.
83 // Do this after we define our own functions so that our own functions use
84 // the correct DDI.
85 #undef IoAllocateMdl
86 #undef IoFreeMdl
87 
88 #define IoAllocateMdl use_FxMdlAllocate_instead
89 #define IoFreeMdl use_FxMdlFree_instead
90 
91 #endif // __FXMDL_H__
92