1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7     FxMemoryBufferFromLookaside.hpp
8 
9 Abstract:
10 
11 Author:
12 
13 Environment:
14 
15     kernel mode only
16 
17 Revision History:
18 
19 --*/
20 
21 #ifndef _FXMEMORYBUFFERFROMLOOKASIDE_H_
22 #define _FXMEMORYBUFFERFROMLOOKASIDE_H_
23 
24 class FxMemoryBufferFromLookaside : public FxMemoryObject {
25 
26 public:
27     FxMemoryBufferFromLookaside(
28         __in PFX_DRIVER_GLOBALS FxDriverGlobals,
29         __inout FxLookasideList* Lookaside,
30         __in size_t BufferSize
31         );
32 
33     _Must_inspect_result_
34     PVOID
35     operator new(
36         __in size_t Size,
37         __in PFX_DRIVER_GLOBALS FxDriverGlobals,
38         __inout PVOID ValidMemory,
39         __in size_t BufferSize,
40         __in PWDF_OBJECT_ATTRIBUTES Attributes
41         );
42 
43     virtual
44     PVOID
45     GetBuffer(
46         VOID
47         );
48 
49 protected:
50     FxMemoryBufferFromLookaside(
51         __in PFX_DRIVER_GLOBALS FxDriverGlobals,
52         __inout FxLookasideList* Lookaside,
53         __in size_t BufferSize,
54         __in USHORT ObjectSize
55         );
56 
57     ~FxMemoryBufferFromLookaside(
58         );
59 
60     VOID
61     Init(
62         VOID
63         );
64 
65     virtual
66     VOID
67     SelfDestruct(
68         VOID
69         );
70 
71     FxLookasideList* m_pLookaside;
72 };
73 
74 class FxMemoryBufferFromPoolLookaside : public FxMemoryBufferFromLookaside {
75 public:
76     FxMemoryBufferFromPoolLookaside(
77         __in PFX_DRIVER_GLOBALS FxDriverGlobals,
78         __inout FxLookasideList* Lookaside,
79         __in size_t BufferSize,
80         __in_bcount(BufferSize) PVOID Buffer
81         );
82 
83     _Must_inspect_result_
84     PVOID
85     operator new(
86         __in size_t Size,
87         __in PFX_DRIVER_GLOBALS FxDriverGlobals,
88         __inout PVOID ValidMemory,
89         __in PWDF_OBJECT_ATTRIBUTES Attributes
90         );
91 
92     virtual
93     PVOID
GetBuffer(VOID)94     GetBuffer(
95         VOID
96         )
97     {
98         return m_Pool;
99     }
100 
101 protected:
102     FxMemoryBufferFromPoolLookaside(
103         __in PFX_DRIVER_GLOBALS FxDriverGlobals,
104         __inout FxLookasideList* Lookaside,
105         __in size_t BufferSize,
106         __in_bcount(BufferSize) PVOID Buffer,
107         __in USHORT ObjectSize
108         );
109 
110     virtual
111     VOID
112     SelfDestruct(
113         VOID
114         );
115 
116     PVOID m_Pool;
117 };
118 
119 class FxMemoryPagedBufferFromPoolLookaside : public FxMemoryBufferFromPoolLookaside {
120 public:
FxMemoryPagedBufferFromPoolLookaside(__in PFX_DRIVER_GLOBALS FxDriverGlobals,__inout FxLookasideList * Lookaside,__in size_t BufferSize,__in_bcount (BufferSize)PVOID Buffer,__in FxDeviceBase * DeviceBase)121     FxMemoryPagedBufferFromPoolLookaside(
122         __in PFX_DRIVER_GLOBALS FxDriverGlobals,
123         __inout FxLookasideList* Lookaside,
124         __in size_t BufferSize,
125         __in_bcount(BufferSize) PVOID Buffer,
126         __in FxDeviceBase* DeviceBase
127         ) :  FxMemoryBufferFromPoolLookaside(FxDriverGlobals,
128                                              Lookaside,
129                                              BufferSize,
130                                              Buffer,
131                                              sizeof(*this))
132     {
133         SetDeviceBase(DeviceBase);
134     }
135 };
136 #endif // _FXMEMORYBUFFERFROMLOOKASIDE_H_
137