ReactOS  0.4.15-dev-3193-g74513a7
fxiotargetkm.hpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation. All rights reserved.
4 
5 Module Name:
6 
7  FxIoTarget.hpp
8 
9 Abstract:
10 
11  Encapsulation of the target to which FxRequest are sent to. For example,
12  an FxTarget could represent the next device object in the pnp stack.
13  Derivations from this class could include bus specific formatters or device
14  objects outside of the pnp stack of the device.
15 
16 Author:
17 
18 
19 
20 Environment:
21 
22  Kernel mode only
23 
24 Revision History:
25 
26 --*/
27 
28 #ifndef _FXIOTARGETKM_H_
29 #define _FXIOTARGETKM_H_
30 
31 __inline
33  VOID
34  ) :
36  m_MdlToFree(NULL),
37  m_OriginalMdl(NULL),
38  m_BufferToFree(NULL),
39  m_OriginalSystemBuffer(NULL),
40  m_OriginalUserBuffer(NULL),
41  m_OtherMemory(NULL),
42  m_CopyBackToBuffer(FALSE),
43  m_UnlockPages(FALSE),
44  m_RestoreState(FALSE),
45  m_BufferToFreeLength(0),
46  m_MdlToFreeSize(0)
47 {
48 }
49 
50 __inline
52  VOID
53  )
54 {
55  //
56  // Free the buffer allocated for the request, reset m_CopyBackToBuffer
57  // to FALSE.
58  // NOTE: We delay the freeing of the buffer on purpose.
59  //
60  ClearBuffer();
61 
62  //
63  // Free the MDL allocated for the request
64  //
65  if (m_MdlToFree != NULL) {
66  //
67  // Being defensive here, MmUnlockPages should have been done in
68  // ReleaseAndRestore.
69  //
70  if (m_UnlockPages) {
73  }
74 
76  m_MdlToFree = NULL;
77  }
78 }
79 
80 __inline
81 VOID
84  )
85 {
86  FxIrp* irp = NULL;
87 
88  irp = Request->GetSubmitFxIrp();
89 
90  if (m_RestoreState) {
99 
101  }
102 
103  //
104  // If there was a buffer present don't free the buffer here so that
105  // it can be reused for any request with the same size.
106  // Similarly if there was an MDL to be freed unlock the pages but dont free
107  // the Mdl so that it can be reused.
108  //
109  if (m_MdlToFree != NULL) {
110  if (m_UnlockPages) {
113  }
114 
115 
116  m_DriverGlobals = Request->GetDriverGlobals();
117  }
118 
119  //
120  // Release the 2ndary buffer if we have an outstanding reference
121  //
122  if (m_OtherMemory != NULL) {
123  m_OtherMemory->RELEASE(this);
125  }
126 
127  //
128  // Release the other buffer and all __super related fields
129  //
131 }
132 
133 __inline
134 VOID
136  VOID
137  )
138 {
139  if (m_BufferToFree != NULL) {
142  }
143 
146 }
147 
148 __inline
149 VOID
152  )
153 {
154  switch (m_MajorFunction) {
155  case IRP_MJ_WRITE:
158  break;
159 
160  case IRP_MJ_READ:
163  break;
164 
167  m_CompletionParams.Parameters.Ioctl.Output.Length =
169  break;
170 
171  default:
172  ASSERT(FALSE);
173  }
174 
175  if (m_BufferToFree == NULL) {
176  return;
177  }
178 
179  if (m_CopyBackToBuffer) {
180  FxIrp* irp = Request->GetSubmitFxIrp();
181 
182  if (irp->GetUserBuffer() != NULL) {
183  //
184  // UserBuffer contains the caller's original output buffer.
185  // Copy the results back into the original buffer.
186  //
190  }
191 
194  irp->GetInformation());
196  }
197  }
198 }
199 
200 __inline
201 VOID
203  __in FxIrp* Irp
204  )
205 {
207  m_OriginalSystemBuffer = Irp->GetSystemBuffer();
208  m_OriginalUserBuffer = Irp->GetUserBuffer();
209  m_OriginalMdl = Irp->GetMdl();
210  m_OriginalFlags = Irp->GetFlags();
211 }
212 
213 __inline
214 VOID
216  __in PVOID Buffer,
217  __in size_t BufferLength,
218  __in BOOLEAN CopyBackToBuffer
219  )
220 {
221  PVOID pOldBuffer;
222 
223  pOldBuffer = m_BufferToFree;
226  m_CopyBackToBuffer = CopyBackToBuffer;
227 
228  if (pOldBuffer != NULL) {
229  FxPoolFree(pOldBuffer);
230  }
231 }
232 
233 
234 __inline
236 NTSTATUS
239  )
240 {
242 
243  DO_NOTHING();
244 
245  return STATUS_SUCCESS;
246 }
247 
248 __inline
249 BOOLEAN
251  VOID
252  )
253 {
254  return (m_TargetStackSize == 0 ? FALSE : TRUE);
255 }
256 
257 __inline
258 VOID
260  _In_ MdIrp Irp
261  )
262 {
263  //
264  // Ignore the return value because once we have sent the request, we
265  // want all processing to be done in the completion routine.
266  //
268 }
269 
270 #endif // _FXIOTARGETKM_H_
MdDeviceObject m_TargetDevice
Definition: fxiotarget.hpp:910
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3767
PVOID m_OriginalUserBuffer
Definition: fxiotarget.hpp:93
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
BOOLEAN m_RestoreState
Definition: fxiotarget.hpp:113
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
PMDL m_MdlToFree
Definition: fxiotarget.hpp:94
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
Definition: fxirp.hpp:28
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1426
struct _WDF_REQUEST_COMPLETION_PARAMS::@3639::@3642 Ioctl
VOID SetUserBuffer(__in PVOID Value)
Definition: fxirpum.cpp:1341
virtual ~FxIoContext(VOID)
_Must_inspect_result_ NTSTATUS InitModeSpecific(__in CfxDeviceBase *Device)
size_t m_BufferToFreeLength
Definition: fxiotarget.hpp:102
UCHAR m_MajorFunction
Definition: fxiotarget.hpp:114
PMDL m_OriginalMdl
Definition: fxiotarget.hpp:96
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
FxIoContext(VOID)
VOID ClearBuffer(VOID)
PFX_DRIVER_GLOBALS m_DriverGlobals
Definition: fxiotarget.hpp:97
virtual VOID ReleaseAndRestore(__in FxRequestBase *Request)
unsigned char BOOLEAN
#define _In_
Definition: ms_sal.h:308
IWudfIrp * MdIrp
Definition: mxum.h:103
Definition: bufpool.h:45
VOID SetSystemBuffer(__in PVOID Value)
Definition: fxirpum.cpp:1313
VOID SetFlags(__in ULONG Flags)
Definition: fxirpum.cpp:1266
virtual VOID ReleaseAndRestore(__in FxRequestBase *Request)
VOID SetMdlAddress(__in PMDL Value)
Definition: fxirpum.cpp:1330
#define ASSERT(a)
Definition: mode.c:44
ULONG m_OriginalFlags
Definition: fxiotarget.hpp:100
VOID CopyParameters(__in FxRequestBase *Request)
BOOLEAN HasValidStackSize(VOID)
struct _WDF_REQUEST_COMPLETION_PARAMS::@3639::@3641 Read
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
VOID SetBufferAndLength(__in PVOID Buffer, __in size_t BufferLength, __in BOOLEAN CopyBackToBuffer)
BOOLEAN m_UnlockPages
Definition: fxiotarget.hpp:105
VOID __inline FxMdlFree(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PMDL Mdl)
Definition: fxmdl.h:60
PVOID GetUserBuffer()
Definition: fxirpum.cpp:633
#define _Must_inspect_result_
Definition: ms_sal.h:558
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
ULONG_PTR GetInformation()
Definition: fxirpum.cpp:513
PVOID m_BufferToFree
Definition: fxiotarget.hpp:91
CCHAR m_TargetStackSize
Definition: fxiotarget.hpp:941
WDF_REQUEST_COMPLETION_PARAMS m_CompletionParams
struct _WDF_REQUEST_COMPLETION_PARAMS::@3639::@3640 Write
#define NULL
Definition: types.h:112
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MJ_READ
Definition: rdpdr.c:46
IFxMemory * m_OtherMemory
Definition: fxiotarget.hpp:115
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
VOID CaptureState(__in FxIrp *Irp)
#define STATUS_SUCCESS
Definition: shellext.h:65
virtual VOID Send(_In_ MdIrp Irp)
BOOLEAN m_CopyBackToBuffer
Definition: fxiotarget.hpp:104
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
#define __in
Definition: dbghelp.h:35
PVOID m_OriginalSystemBuffer
Definition: fxiotarget.hpp:92
FxIrp * irp
union _WDF_REQUEST_COMPLETION_PARAMS::@3639 Parameters
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define DO_NOTHING()
Definition: mxgeneral.h:32