ReactOS  0.4.15-dev-2701-g34593d9
fxrequestmemory.cpp
Go to the documentation of this file.
1 
2 /*++
3 
4 Copyright (c) Microsoft. All rights reserved.
5 
6 Module Name:
7 
8  FxRequestMemory.hpp
9 
10 Abstract:
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 
18 Author:
19 
20 
21 
22 Environment:
23 
24  Both kernel and user mode
25 
26 Revision 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 
62 Routine 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 
89 Routine 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 
117 Routine Description:
118  Destructor for this object. Does nothing with the client memory since
119  the client owns it.
120 
121 Arguments:
122  None
123 
124 Return 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 
149 NTSTATUS
152  )
153 {
154  if (Params->Type == FX_TYPE_REQUEST_MEMORY) {
155  *Params->Object = (FxRequestMemory*) this;
156  return STATUS_SUCCESS;
157  }
158  else {
159  return FxMemoryBufferPreallocated::QueryInterface(Params); // __super call
160  }
161 }
162 
163 PVOID
165  VOID
166  )
167 /*++
168 
169 Routine Description:
170  GetBuffer overload.
171 
172  Returns pointer into buffer memory.
173 
174 Arguments:
175  None
176 
177 Return Value:
178  Client supplied buffer from the constructor
179 
180  --*/
181 {
182  return m_pBuffer;
183 }
184 
186 PMDL
188  VOID
189  )
190 /*++
191 
192 Routine Description:
193  GetMdl overload. Returns the embedded MDL
194 
195 Arguments:
196  None
197 
198 Return Value:
199  valid MDL or NULL
200 
201  --*/
202 {
203  return m_Mdl;
204 }
205 
206 VOID
210  _In_ PMDL BackingMdl,
211  _In_ size_t BufferSize,
213  )
214 /*++
215 
216 Routine Description:
217  Updates the internal pointer to a new value.
218 
219 
220 Arguments:
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 
231 Return Value:
232  None.
233 
234  --*/
235 
236 {
237  ASSERT(m_pBuffer == NULL);
238  ASSERT(m_Request == NULL);
239  ASSERT(m_Mdl == NULL);
240 
241  ASSERT(Request != NULL);
242 
243  m_pBuffer = Buffer;
244  m_Mdl = BackingMdl;
246 
247  m_Request = Request;
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 
261 VOID
264  __in PMDL Mdl,
265  __in PVOID MdlBuffer,
266  __in size_t BufferSize,
268  )
269 /*++
270 
271 Routine 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 
282 Arguments:
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 
293 Return Value:
294  None.
295 
296  --*/
297 
298 {
299 
300  ASSERT(m_pBuffer == NULL);
301  ASSERT(m_Mdl == NULL);
302  ASSERT(m_Request == NULL);
303  ASSERT(Request != NULL);
304 
305  m_Mdl = Mdl;
306  m_pBuffer = MdlBuffer;
308 
309  m_Request = Request;
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 
VOID AddIrpReference(VOID)
Definition: fxrequest.cpp:2470
#define _Must_inspect_result_
Definition: no_sal2.h:62
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFIOTARGET _In_ PWDF_REQUEST_COMPLETION_PARAMS Params
Definition: wdfrequest.h:306
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
static NTSTATUS Create(__in PFX_DRIVER_GLOBALS DriverGlobals, __in_opt PWDF_OBJECT_ATTRIBUTES Attributes, __out FxRequestMemory **Object)
#define __in_opt
Definition: dbghelp.h:38
Definition: arc.h:80
LONG NTSTATUS
Definition: precomp.h:26
FxMemoryObject * pMemory
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
DriverGlobals
VOID SetFlags(__in USHORT Flags)
FxRequest * m_Request
#define __out
Definition: dbghelp.h:62
unsigned char BOOLEAN
Definition: bufpool.h:45
virtual PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
#define ASSERT(a)
Definition: mode.c:44
VOID SetMdl(__in FxRequest *Request, __in PMDL Mdl, __in PVOID MdlBuffer, __in size_t BufferSize, __in BOOLEAN ReadOnly)
FxRequestMemory(__in PFX_DRIVER_GLOBALS Globals)
VOID __inline FxMdlFree(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PMDL Mdl)
Definition: fxmdl.h:60
#define _Pre_notnull_
Definition: no_sal2.h:516
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_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
#define _In_
Definition: no_sal2.h:158
virtual PVOID GetBuffer(VOID)
static __inline VOID MxUnlockPages(__in PMDL Mdl)
Definition: mxgeneralkm.h:357
VOID ReleaseIrpReference(VOID)
Definition: fxrequest.cpp:2512
_Must_inspect_result_ NTSTATUS QueryInterface(__in FxQueryInterfaceParams *Params)
#define NULL
Definition: types.h:112
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
virtual _Must_inspect_result_ PMDL GetMdl(VOID)
_Must_inspect_result_ NTSTATUS QueryInterface(__inout FxQueryInterfaceParams *Params)
#define _Pre_writable_byte_size_(s)
Definition: no_sal2.h:534
#define STATUS_SUCCESS
Definition: shellext.h:65
#define __in
Definition: dbghelp.h:35
#define BufferSize
Definition: mmc.h:75
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes