ReactOS 0.4.15-dev-7906-g1b85a5f
fxiotargetkm.hpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation. All rights reserved.
4
5Module Name:
6
7 FxIoTarget.hpp
8
9Abstract:
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
16Author:
17
18
19
20Environment:
21
22 Kernel mode only
23
24Revision 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 //
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
77 }
78}
79
80__inline
81VOID
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
134VOID
136 VOID
137 )
138{
139 if (m_BufferToFree != NULL) {
142 }
143
146}
147
148__inline
149VOID
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
196 }
197 }
198}
199
200__inline
201VOID
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
214VOID
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
239 )
240{
242
243 DO_NOTHING();
244
245 return STATUS_SUCCESS;
246}
247
248__inline
251 VOID
252 )
253{
254 return (m_TargetStackSize == 0 ? FALSE : TRUE);
255}
256
257__inline
258VOID
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_
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
MdDeviceObject m_TargetDevice
Definition: fxiotarget.hpp:910
BOOLEAN HasValidStackSize(VOID)
CCHAR m_TargetStackSize
Definition: fxiotarget.hpp:941
virtual VOID Send(_In_ MdIrp Irp)
_Must_inspect_result_ NTSTATUS InitModeSpecific(__in CfxDeviceBase *Device)
Definition: fxirp.hpp:28
VOID SetSystemBuffer(__in PVOID Value)
Definition: fxirpum.cpp:1313
VOID SetUserBuffer(__in PVOID Value)
Definition: fxirpum.cpp:1341
ULONG_PTR GetInformation()
Definition: fxirpum.cpp:513
VOID SetFlags(__in ULONG Flags)
Definition: fxirpum.cpp:1266
PVOID GetUserBuffer()
Definition: fxirpum.cpp:633
VOID SetMdlAddress(__in PMDL Value)
Definition: fxirpum.cpp:1330
_In_ PIRP Irp
Definition: csq.h:116
#define __in
Definition: dbghelp.h:35
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
VOID __inline FxMdlFree(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PMDL Mdl)
Definition: fxmdl.h:60
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
FxIrp * irp
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1435
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _In_
Definition: ms_sal.h:308
#define DO_NOTHING()
Definition: mxgeneral.h:32
IWudfIrp * MdIrp
Definition: mxum.h:103
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define IoCallDriver
Definition: irp.c:1225
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define STATUS_SUCCESS
Definition: shellext.h:65
PVOID m_OriginalSystemBuffer
Definition: fxiotarget.hpp:92
PVOID m_BufferToFree
Definition: fxiotarget.hpp:91
PFX_DRIVER_GLOBALS m_DriverGlobals
Definition: fxiotarget.hpp:97
virtual ~FxIoContext(VOID)
FxIoContext(VOID)
UCHAR m_MajorFunction
Definition: fxiotarget.hpp:114
BOOLEAN m_RestoreState
Definition: fxiotarget.hpp:113
PMDL m_MdlToFree
Definition: fxiotarget.hpp:94
IFxMemory * m_OtherMemory
Definition: fxiotarget.hpp:115
BOOLEAN m_UnlockPages
Definition: fxiotarget.hpp:105
BOOLEAN m_CopyBackToBuffer
Definition: fxiotarget.hpp:104
VOID ClearBuffer(VOID)
PVOID m_OriginalUserBuffer
Definition: fxiotarget.hpp:93
VOID SetBufferAndLength(__in PVOID Buffer, __in size_t BufferLength, __in BOOLEAN CopyBackToBuffer)
ULONG m_OriginalFlags
Definition: fxiotarget.hpp:100
size_t m_BufferToFreeLength
Definition: fxiotarget.hpp:102
VOID CaptureState(__in FxIrp *Irp)
virtual VOID ReleaseAndRestore(__in FxRequestBase *Request)
VOID CopyParameters(__in FxRequestBase *Request)
PMDL m_OriginalMdl
Definition: fxiotarget.hpp:96
virtual VOID ReleaseAndRestore(__in FxRequestBase *Request)
WDF_REQUEST_COMPLETION_PARAMS m_CompletionParams
struct _WDF_REQUEST_COMPLETION_PARAMS::@3887::@3889 Read
struct _WDF_REQUEST_COMPLETION_PARAMS::@3887::@3890 Ioctl
struct _WDF_REQUEST_COMPLETION_PARAMS::@3887::@3888 Write
union _WDF_REQUEST_COMPLETION_PARAMS::@3887 Parameters
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
#define IRP_MJ_INTERNAL_DEVICE_CONTROL