ReactOS  0.4.15-dev-5487-ge7bbbf0
fxrequestsystembuffer.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxRequestSystemBuffer.cpp
8 
9 Abstract:
10 
11  This module implements class representing the system buffer in an FxRequest
12 
13 Author:
14 
15 
16 
17 
18 Environment:
19 
20  Both kernel and user mode
21 
22 Revision History:
23 
24 
25 
26 
27 --*/
28 
29 #include "coreprivshared.hpp"
30 
31 // Tracing support
32 extern "C" {
33 // #include "FxRequestSystemBuffer.tmh"
34 }
35 
36 size_t
38  VOID
39  )
40 /*++
41 
42 Routine Description:
43  Returns the size of the buffer returned by GetBuffer()
44 
45 Arguments:
46  None
47 
48 Return Value:
49  Buffer length or 0 on error
50 
51  --*/
52 {
53  FxIrp* irp = GetRequest()->GetFxIrp();
54 
55  switch (irp->GetMajorFunction()) {
56  case IRP_MJ_READ:
57  return irp->GetParameterReadLength();
58 
59  case IRP_MJ_WRITE:
60  return irp->GetParameterWriteLength();
61 
65 
66  default:
67  // should not get here
68  ASSERT(FALSE);
69  return 0;
70  }
71 }
72 
74 PMDL
76  VOID
77  )
78 /*++
79 
80 Routine Description:
81  Returns the PMDL from the irp if one exists, otherwise NULL
82 
83 Arguments:
84  None
85 
86 Return Value:
87  a valid PMDL or NULL (not an error condition)
88 
89  --*/
90 {
92  FxIrp* irp = GetRequest()->GetFxIrp();
93 
94  switch (irp->GetMajorFunction()) {
95  case IRP_MJ_READ:
96  case IRP_MJ_WRITE:
98 
100  return m_Mdl;
101  }
102  // || || Fall through || ||
103  // \/ \/ \/ \/
104 
107  //
108  // For IOCLs, the outbuffer will return the PMDL
109  //
110  // || || Fall through || ||
111  // \/ \/ \/ \/
112 
113  default:
114  return NULL;
115  }
116 }
117 
118 WDFMEMORY
120  VOID
121  )
122 /*++
123 
124 Routine Description:
125  Returns the handle that will represent this object to the driver writer.
126 
127 Arguments:
128  None
129 
130 Return Value:
131  Valid WDF handle
132 
133  --*/
134 {
135  return GetRequest()->GetMemoryHandle(
136  FIELD_OFFSET(FxRequest, m_SystemBufferOffset));
137 }
138 
139 USHORT
141  VOID
142  )
143 /*++
144 
145 Routine Description:
146  Returns the flags associated with this buffer. This currently only includes
147  whether the buffer is read only or not
148 
149 Arguments:
150  None
151 
152 Return Value:
153  flags from IFxMemoryFlags
154 
155  --*/
156 {
157  FxIrp* irp = GetRequest()->GetFxIrp();
158 
159  switch (irp->GetMajorFunction()) {
163  case METHOD_BUFFERED:
164  case METHOD_NEITHER:
165  return 0;
166 
167  case METHOD_IN_DIRECT:
168  case METHOD_OUT_DIRECT:
169  return IFxMemoryFlagReadOnly;
170  }
171 
172  case IRP_MJ_READ:
173  return 0;
174 
175  case IRP_MJ_WRITE:
176  return IFxMemoryFlagReadOnly;
177 
178  default:
179  ASSERT(FALSE);
180  return 0;
181  }
182 }
183 
186  VOID
187  )
188 /*++
189 
190 Routine Description:
191  Returns the driver globals
192 
193 Arguments:
194  none
195 
196 Return Value:
197  Driver globals pointer
198 
199  --*/
200 {
201  return GetRequest()->GetDriverGlobals();
202 }
203 
204 ULONG
206  __in PVOID Tag,
207  __in LONG Line,
209  )
210 /*++
211 
212 Routine Description:
213  Adds an irp reference to the owning FxRequest. This object does not maintain
214  its own reference count. A request cannot be completed with outstanding
215  irp references.
216 
217 Arguments:
218  Tag - the tag to use to track the reference
219 
220  Line - The line number of the caller
221 
222  File - the file name of the caller
223 
224 Return Value:
225  current reference count
226 
227  --*/
228 {
232 
234 
235  //
236  // This value should never be used by the caller
237  //
238  return 2;
239 }
240 
241 ULONG
243  __in PVOID Tag,
244  __in LONG Line,
246  )
247 /*++
248 
249 Routine Description:
250  Removes an irp reference to the owning FxRequest. This object does not maintain
251  its own reference count. A request cannot be completed with outstanding
252  irp references.
253 
254 Arguments:
255  Tag - the tag to use to track the release
256 
257  Line - The line number of the caller
258 
259  File - the file name of the caller
260 
261 Return Value:
262  current reference count
263 
264  --*/
265 {
269 
271 
272  return 1;
273 }
274 
275 FxRequest*
277  VOID
278  )
279 /*++
280 
281 Routine Description:
282  Return the owning FxRequest based on this object's address
283 
284 Arguments:
285  None
286 
287 Return Value:
288  owning FxRequest
289 
290  --*/
291 {
292  return CONTAINING_RECORD(this, FxRequest, m_SystemBuffer);
293 }
294 
295 VOID
297  VOID
298  )
299 /*++
300 
301 Routine Description:
302  Attempt to delete this interface. Since this is an embedded object, it
303  cannot be deleted. Since this function is only called internally, the
304  internal caller knows if the IFxMemory is deletable because the internal
305  caller allocated the IFxMemory to begin with.
306 
307 Arguments:
308  None
309 
310 Return Value:
311  None
312 
313  --*/
314 {
315  // this function should never be called
316  ASSERT(FALSE);
317 }
VOID AddIrpReference(VOID)
Definition: fxrequest.cpp:2470
ULONG GetParameterReadLength(VOID)
Definition: fxirpum.cpp:1589
MdDeviceObject GetDeviceObject(VOID)
Definition: fxirpum.cpp:1352
__inline WDF_DEVICE_IO_TYPE GetIoType(VOID)
Definition: fxdevice.hpp:1084
#define __in_opt
Definition: dbghelp.h:38
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
static FxDevice * GetFxDevice(__in MdDeviceObject DeviceObject)
Definition: fxdeviceum.cpp:60
Definition: fxirp.hpp:28
virtual _Must_inspect_result_ PMDL GetMdl(VOID)
#define METHOD_IN_DIRECT
Definition: nt_native.h:595
WDFMEMORY GetMemoryHandle(__in USHORT Offset)
Definition: fxrequest.hpp:658
virtual PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
#define METHOD_NEITHER
Definition: nt_native.h:597
#define FALSE
Definition: types.h:117
ULONG GetParameterIoctlInputBufferLength(VOID)
Definition: fxirpum.cpp:1518
virtual USHORT GetFlags(VOID)
long LONG
Definition: pedump.c:60
virtual WDFMEMORY GetHandle(VOID)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
FxDevice * pDevice
#define METHOD_OUT_DIRECT
Definition: nt_native.h:596
#define ASSERT(a)
Definition: mode.c:44
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
Definition: ncftp.h:79
FxIrp * GetFxIrp(VOID)
Definition: fxrequest.hpp:957
#define _Must_inspect_result_
Definition: ms_sal.h:558
ULONG GetParameterWriteLength(VOID)
Definition: fxirpum.cpp:1601
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4061
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
virtual ULONG Release(__in PVOID Tag, __in LONG Line, __in_opt PSTR File)
VOID ReleaseIrpReference(VOID)
Definition: fxrequest.cpp:2512
unsigned short USHORT
Definition: pedump.c:61
#define METHOD_BUFFERED
Definition: nt_native.h:594
signed char * PSTR
Definition: retypes.h:7
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
ULONG GetParameterIoctlCodeBufferMethod(VOID)
Definition: fxirpum.cpp:1490
#define NULL
Definition: types.h:112
#define IRP_MJ_READ
Definition: rdpdr.c:46
unsigned int ULONG
Definition: retypes.h:1
virtual ULONG AddRef(__in PVOID Tag, __in LONG Line, __in_opt PSTR File)
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
Definition: File.h:15
virtual size_t GetBufferSize(VOID)
UCHAR GetMajorFunction(VOID)
Definition: fxirpum.cpp:217
#define __in
Definition: dbghelp.h:35
FxIrp * irp
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52