ReactOS 0.4.15-dev-8419-g7f0e8a3
fxrequestmemory.cpp
Go to the documentation of this file.
1
2/*++
3
4Copyright (c) Microsoft. All rights reserved.
5
6Module Name:
7
8 FxRequestMemory.hpp
9
10Abstract:
11
12 This is the memory object for FxRequest that is sized, and
13 allows checking for read/write access.
14
15 Its lifetime reference is tied with IRP completion in
16 FxRequest.
17
18Author:
19
20
21
22Environment:
23
24 Both kernel and user mode
25
26Revision History:
27
28--*/
29
30#include "coreprivshared.hpp"
31
32//
33// FxRequestMemory can be an embedded object inside of FxRequest,
34// in which it represents the standard WDM IRP buffers.
35//
36// In addition, FxRequestMemory may be allocated by the device
37// driver by probing and locking pages for dealing with direct
38// and method_neither I/O types.
39//
40// In both cases, the lifetime of a WDFMEMORY handle returned from
41// FxRequestMemory becomes invalid once FxRequest::Complete is called.
42//
43// Code exists to assist FxRequest in verifying there are no out
44// standing references on the WDFMEMORY handles when a request is
45// completed.
46//
47// Rundown and disposing of FxRequestMemory occur during FxRequest::Complete,
48// and not when FxRequest is actually destroyed. This is because they represent
49// system buffers and MDLs which must be released before the IRP inside
50// the FxRequest is completed. Otherwise an I/O manager bugcheck will occur.
51//
52
58 )
59
60/*++
61
62Routine Description:
63
64 Class Factory for FxRequestMemory
65
66--*/
67
68{
70
71 // Build an FxRequestMemory object now
73
74 if (pMemory == NULL) {
76 }
77
78 *Object = pMemory;
79
80 return STATUS_SUCCESS;
81}
82
84 __in PFX_DRIVER_GLOBALS FxDriverGlobals
85 ) :
86 FxMemoryBufferPreallocated(sizeof(*this), FxDriverGlobals)
87/*++
88
89Routine Description:
90
91 Default constructor for this object.
92
93 --*/
94{
95
96 //
97 // Our constructor chain:
98 //
99 // FxRequestMemory(ObjectSize, PFX_DRIVER_GLOBALS),
100 // : FxMemoryBufferPreallocated(ObjectSize, PFX_DRIVER_GLOBALS),
101 // : FxMemoryObject(PFX_DRIVER_GLOBALS, ObjectSize, ObjectSize),
102 // : FxObject(FX_TYPE_MEMORY, ObjectSize, PFX_DRIVER_GLOBALS)
103 //
104 m_Request = NULL;
105
106 m_Mdl = NULL;
107
108 m_Flags = 0;
109}
110
111
113 VOID
114 )
115/*++
116
117Routine Description:
118 Destructor for this object. Does nothing with the client memory since
119 the client owns it.
120
121Arguments:
122 None
123
124Return Value:
125 None
126
127 --*/
128{
129 //
130 // Non-embedded case releases resources in the destructor
131 // rather than Dispose to ensure all outstanding device driver
132 // references are gone.
133 //
134#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
135 if( m_Mdl != NULL ) {
138 m_Mdl = NULL;
139 }
140#endif
141
142 if( m_Request != NULL ) {
144 m_Request = NULL;
145 }
146}
147
152 )
153{
154 if (Params->Type == FX_TYPE_REQUEST_MEMORY) {
155 *Params->Object = (FxRequestMemory*) this;
156 return STATUS_SUCCESS;
157 }
158 else {
160 }
161}
162
163PVOID
165 VOID
166 )
167/*++
168
169Routine Description:
170 GetBuffer overload.
171
172 Returns pointer into buffer memory.
173
174Arguments:
175 None
176
177Return Value:
178 Client supplied buffer from the constructor
179
180 --*/
181{
182 return m_pBuffer;
183}
184
186PMDL
188 VOID
189 )
190/*++
191
192Routine Description:
193 GetMdl overload. Returns the embedded MDL
194
195Arguments:
196 None
197
198Return Value:
199 valid MDL or NULL
200
201 --*/
202{
203 return m_Mdl;
204}
205
206VOID
210 _In_ PMDL BackingMdl,
211 _In_ size_t BufferSize,
213 )
214/*++
215
216Routine Description:
217 Updates the internal pointer to a new value.
218
219
220Arguments:
221 Request - new Request.
222
223 Buffer - new buffer
224
225 BackingMdl - associated MDL.
226
227 BufferSize - length of Buffer in bytes
228
229 ReadOnly - TRUE if read only buffer.
230
231Return Value:
232 None.
233
234 --*/
235
236{
239 ASSERT(m_Mdl == NULL);
240
241 ASSERT(Request != NULL);
242
244 m_Mdl = BackingMdl;
246
248
249 //
250 // A single FxRequest IRP reference
251 // is outstanding until destroy
252 //
254
255 // Set access checking if its a readonly buffer
256 if (ReadOnly) {
258 }
259}
260
261VOID
264 __in PMDL Mdl,
265 __in PVOID MdlBuffer,
266 __in size_t BufferSize,
268 )
269/*++
270
271Routine Description:
272
273 Sets an MDL on the WDFMEMORY object.
274
275 It can't already have a buffer set.
276
277 We are expected to free the MDL when Disposed.
278
279 This is not used by embedded WDFMEMORY objects whose
280 MDL comes from the IRP.
281
282Arguments:
283 Request - new Request.
284
285 Mdl - new MDL.
286
287 MdlBuffer - associated buffer
288
289 BufferSize - length of Buffer in bytes
290
291 ReadOnly - TRUE if read only buffer.
292
293Return Value:
294 None.
295
296 --*/
297
298{
299
301 ASSERT(m_Mdl == NULL);
303 ASSERT(Request != NULL);
304
305 m_Mdl = Mdl;
306 m_pBuffer = MdlBuffer;
308
310
311 //
312 // A single FxRequest IRP reference is outstanding until destroy
313 //
315
316 // Set access checking if it's a readonly buffer
317 if (ReadOnly) {
319 }
320
321 return;
322}
323
324
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
_Must_inspect_result_ NTSTATUS QueryInterface(__inout FxQueryInterfaceParams *Params)
virtual PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
FxRequestMemory(__in PFX_DRIVER_GLOBALS Globals)
static NTSTATUS Create(__in PFX_DRIVER_GLOBALS DriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out FxRequestMemory **Object)
VOID SetMdl(__in FxRequest *Request, __in PMDL Mdl, __in PVOID MdlBuffer, __in size_t BufferSize, __in BOOLEAN ReadOnly)
VOID SetFlags(__in USHORT Flags)
virtual PVOID GetBuffer(VOID)
VOID SetBuffer(_In_ FxRequest *Request, _Pre_notnull_ _Pre_writable_byte_size_(BufferSize) PVOID Buffer, _In_ PMDL BackingMdl, _In_ size_t BufferSize, _In_ BOOLEAN ReadOnly)
_Must_inspect_result_ NTSTATUS QueryInterface(__in FxQueryInterfaceParams *Params)
FxRequest * m_Request
virtual _Must_inspect_result_ PMDL GetMdl(VOID)
VOID ReleaseIrpReference(VOID)
Definition: fxrequest.cpp:2512
VOID AddIrpReference(VOID)
Definition: fxrequest.cpp:2470
static __inline VOID MxUnlockPages(__in PMDL Mdl)
Definition: mxgeneralkm.h:357
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define BufferSize
Definition: mmc.h:75
#define NULL
Definition: types.h:112
DriverGlobals
FxMemoryObject * pMemory
VOID __inline FxMdlFree(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PMDL Mdl)
Definition: fxmdl.h:60
@ FX_TYPE_REQUEST_MEMORY
Definition: fxtypes.h:85
@ IFxMemoryFlagReadOnly
Definition: ifxmemory.hpp:35
#define ASSERT(a)
Definition: mode.c:44
#define _Pre_writable_byte_size_(size)
Definition: ms_sal.h:647
#define _Pre_notnull_
Definition: ms_sal.h:680
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _In_
Definition: ms_sal.h:308
@ ReadOnly
Definition: arc.h:80
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:308
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList