ReactOS 0.4.15-dev-8241-g63935f8
fxiotargetum.cpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxIoTargetUm.cpp
8
9Abstract:
10
11 This module implements the IO Target APIs
12
13Author:
14
15Environment:
16
17 kernel mode only
18
19Revision History:
20
21--*/
22
23
24#include "..\..\FxTargetsShared.hpp"
25
26extern "C" {
27#if defined(EVENT_TRACING)
28#include "FxIoTargetUm.tmh"
29#endif
30}
31
36 )
37{
39
40 //
41 // FxCREvent can fail in UMDF so it is initialized outside of constuctor
42 // for UMDF. It always succeeds for KMDF so it gets initialized in
43 // event's constructor.
44 //
45
47 if (!NT_SUCCESS(status)) {
50 "Could not initialize m_SentIoEvent event for "
51 "WFIOTARGET %p, %!STATUS!",
53 return status;
54 }
55
57 if (!NT_SUCCESS(status)) {
60 "Could not initialize m_DisposeEventUm event for "
61 "WFIOTARGET %p, %!STATUS!",
63 return status;
64 }
65
66 return STATUS_SUCCESS;
67}
68
73 __in UCHAR MajorCode,
74 __in FxRequestBuffer* IoBuffer,
77 )
78{
79 FxIoContext* pContext;
81 ULONG ioLength;
82 FxIrp* irp;
84
86
87 ASSERT(MajorCode == IRP_MJ_WRITE || MajorCode == IRP_MJ_READ);
88
89 status = Request->ValidateTarget(this);
90 if (!NT_SUCCESS(status)) {
91 return status;
92 }
93
94 if (Request->HasContextType(FX_RCT_IO)) {
95 pContext = (FxIoContext*) Request->GetContext();
96 }
97 else {
98 pContext = new(GetDriverGlobals()) FxIoContext();
99 if (pContext == NULL) {
101 "could not allocate context for request");
102
104 }
105
106 //
107 // Since we can error out and return, remember the allocation before
108 // we do anything so we can free it later.
109 //
110 Request->SetContext(pContext);
111 }
112
113 //
114 // Save away any references to IFxMemory pointers that are passed
115 //
116 pContext->StoreAndReferenceMemory(IoBuffer);
117
118 //
119 // Setup irp stack
120 //
121 irp = Request->GetSubmitFxIrp();
123
124 //
125 // copy File object and flags
126 //
128
129 irp->SetMajorFunction(MajorCode);
130 pContext->m_MajorFunction = MajorCode;
131
132 ioLength = IoBuffer->GetBufferLength();
133
134 status = IoBuffer->GetBuffer(&buffer);
135 if (!NT_SUCCESS(status)) {
138 "Could not retrieve i/o buffer, %!STATUS!",
139 status);
140 goto exit;
141 }
142
143 //
144 // Since we don't support buffer transformations (buffered->Direct->Neither)
145 // we are analogous to "Neither" method in KMDF
146 // in which case we just set the Irp buffer to the buffer that is passed in
147 //
148 if (IRP_MJ_READ == MajorCode) {
149 pContext->SwapIrpBuffer(Request,
150 0,
151 NULL,
152 ioLength,
153 buffer);
154
155 irp->GetIoIrp()->SetReadParametersForNextStackLocation(
156 ioLength,
158 0
159 );
160 }
161 else if (IRP_MJ_WRITE == MajorCode) {
162 pContext->SwapIrpBuffer(Request,
163 ioLength,
164 buffer,
165 0,
166 NULL);
167 irp->GetIoIrp()->SetWriteParametersForNextStackLocation(
168 ioLength,
170 0
171 );
172 }
173 /*
174 else if (WdfRequestQueryInformation == RequestType)
175 {
176 pContext->SwapIrpBuffer(pRequest,
177 0,
178 NULL,
179 ioLength,
180 buffer);
181 }
182 else if (WdfRequestSetInformation == RequestType)
183 {
184 pContext->SwapIrpBuffer(pRequest,
185 ioLength,
186 buffer,
187 0,
188 NULL);
189 }
190 */
191 else {
192 pContext->SwapIrpBuffer(Request, 0, NULL, 0, NULL);
193 }
194
195exit:
196
197 if (NT_SUCCESS(status)) {
198 Request->VerifierSetFormatted();
199 }
200 else {
201 Request->ContextReleaseAndRestore();
202 }
203
204 return status;
205}
206
216 )
217{
218 FxIoContext* pContext;
220 ULONG inLength, outLength;
221 FxIrp* irp;
222 PVOID inputBuffer;
223 PVOID outputBuffer;
224
226
227 irp = Request->GetSubmitFxIrp();
228
229 status = Request->ValidateTarget(this);
230 if (!NT_SUCCESS(status)) {
231 return status;
232 }
233
234 if (Request->HasContextType(FX_RCT_IO)) {
235 pContext = (FxIoContext*) Request->GetContext();
236 }
237 else {
238 pContext = new(GetDriverGlobals()) FxIoContext();
239 if (pContext == NULL) {
242 "Could not allocate context for request");
243
245 }
246
247 Request->SetContext(pContext);
248 }
249
250 inLength = InputBuffer->GetBufferLength();
251 outLength = OutputBuffer->GetBufferLength();
252
253 //
254 // Capture irp buffers in context and set driver-provided buffers in the irp
255 //
256 status = InputBuffer->GetBuffer(&inputBuffer);
257 if (!NT_SUCCESS(status)) {
260 "Could not retrieve input buffer, %!STATUS!",
261 status);
262 goto exit;
263 }
264
265 status = OutputBuffer->GetBuffer(&outputBuffer);
266 if (!NT_SUCCESS(status)) {
269 "Could not retrieve output buffer, %!STATUS!",
270 status);
271 goto exit;
272 }
273
274 //
275 // Save away any references to IFxMemory pointers that are passed
276 //
280
281 //
282 // Format next stack location
283 //
286
287 //
288 // copy File object and flags
289 //
291
292 irp->GetIoIrp()->SetDeviceIoControlParametersForNextStackLocation(
293 Ioctl,
294 inLength,
295 outLength
296 );
297
298 pContext->SwapIrpBuffer(Request,
299 InputBuffer->GetBufferLength(),
300 inputBuffer,
301 OutputBuffer->GetBufferLength(),
302 outputBuffer);
303exit:
304
305 if (NT_SUCCESS(status)) {
306 Request->VerifierSetFormatted();
307 }
308 else {
309 Request->ContextReleaseAndRestore();
310 }
311
312 return status;;
313}
314
315
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
__inline VOID CopyFileObjectAndFlags(__in FxRequestBase *Request)
Definition: fxiotarget.hpp:743
FxCREvent m_DisposeEventUm
Definition: fxiotarget.hpp:892
FxCREvent m_SentIoEvent
Definition: fxiotarget.hpp:878
_Must_inspect_result_ NTSTATUS InitModeSpecific(__in CfxDeviceBase *Device)
_Must_inspect_result_ NTSTATUS FormatIoctlRequest(__in FxRequestBase *Request, __in ULONG Ioctl, __in BOOLEAN Internal, __in FxRequestBuffer *InputBuffer, __in FxRequestBuffer *OutputBuffer, __in_opt FxFileObject *FileObject=NULL)
_Must_inspect_result_ NTSTATUS FormatIoRequest(__inout FxRequestBase *Request, __in UCHAR MajorCode, __in FxRequestBuffer *IoBuffer, __in_opt PLONGLONG StartingOffset, __in_opt FxFileObject *FileObject=NULL)
Definition: fxirp.hpp:28
IWudfIoIrp * GetIoIrp(VOID)
Definition: fxirpum.cpp:1777
VOID SetMajorFunction(__in UCHAR MajorFunction)
Definition: fxirpum.cpp:905
VOID ClearNextStackLocation(VOID)
Definition: fxirpum.cpp:1581
__inline PFX_DRIVER_GLOBALS GetDriverGlobals(VOID)
Definition: fxobject.hpp:734
#define __in
Definition: dbghelp.h:35
#define __inout
Definition: dbghelp.h:50
#define __in_opt
Definition: dbghelp.h:38
#define TRACINGIOTARGET
Definition: dbgtrace.h:72
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
return pObject GetObjectHandle()
_Must_inspect_result_ __in WDFIOTARGET __in_opt WDFREQUEST __in ULONG Ioctl
FxIrp * irp
GLuint buffer
Definition: glext.h:5915
@ Internal
Definition: hwresource.cpp:137
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
__GNU_EXTENSION typedef __int64 * PLONGLONG
Definition: ntbasedef.h:382
@ SynchronizationEvent
#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 exit(n)
Definition: config.h:202
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
CHECK_RETURN_IF_USER_MODE NTSTATUS Initialize(__in BOOLEAN InitialState=FALSE)
Definition: fxwaitlock.hpp:51
VOID StoreAndReferenceOtherMemory(__in FxRequestBuffer *Buffer)
Definition: fxiotarget.hpp:44
VOID SwapIrpBuffer(_In_ FxRequestBase *Request, _In_ ULONG NewInputBufferCb, _In_reads_bytes_opt_(NewInputBufferCb) PVOID NewInputBuffer, _In_ ULONG NewOutputBufferCb, _In_reads_bytes_opt_(NewOutputBufferCb) PVOID NewOutputBuffer)
UCHAR m_MajorFunction
Definition: fxiotarget.hpp:114
virtual VOID StoreAndReferenceMemory(__in FxRequestBuffer *Buffer)
Definition: ps.c:97
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG DeviceOffset
Definition: wdfiotarget.h:865
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
unsigned char UCHAR
Definition: xmlstorage.h:181