ReactOS  0.4.15-dev-3287-gfec35dc
fxrequestapium.cpp
Go to the documentation of this file.
1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7  FxRequestApiUm.cpp
8 
9 Abstract:
10 
11  This module implements FxRequest object
12 
13 Author:
14 
15 Environment:
16 
17  User mode only
18 
19 Revision History:
20 
21 
22 --*/
23 #include "coreprivshared.hpp"
24 
25 // Tracing support
26 extern "C" {
27 #include "FxRequestApiUm.tmh"
28 
31 WDFAPI
33 WDFEXPORT(WdfRequestImpersonate)(
34  _In_
36  _In_
37  WDFREQUEST Request,
38  _In_
40  _In_
41  PFN_WDF_REQUEST_IMPERSONATE EvtRequestImpersonate,
42  _In_opt_
44  )
45 
46 /*++
47 
48 Routine Description:
49 
50  The WdfRequestImpersonate method registers the event that the framework
51  should call for impersonation.
52 
53 Arguments:
54 
55  Request : Request object
56 
57  ImpersonationLevel : A SECURITY_IMPERSONATION_LEVEL-typed value that identifies
58  the level of impersonation.
59 
60  EvtRequestImpersonate : A pointer to the IImpersonateCallback interface whose
61  method the framework calls for impersonation.
62 
63 Returns:
64 
65  Impersonate returns STATUS_SUCCESS if the operation succeeds. Otherwise,
66  this method returns one of the error codes that are defined in ntstatus.h.
67 
68 --*/
69 
70 {
74 
75  //
76  // Validate the request handle, and get the FxRequest*
77  //
79  Request,
81  (PVOID*)&pRequest,
83 
87  "ImpersonationLevel is not a valid level, %!STATUS!",
88  status);
90  return status;
91  }
92 
96  "EvtRequestImpersonate must not be NULL, %!STATUS!",
97  status);
99  return status;
100  }
101 
102 
103 #if FX_VERBOSE_TRACE
105  "Enter: WDFREQUEST 0x%p", Request);
106 #endif // FX_VERBOSE_TRACE
107 
110  Context);
111 
112  return status;
113 }
114 
116 WDFAPI
117 ULONG
118 WDFEXPORT(WdfRequestGetRequestorProcessId)(
119  _In_
121  _In_
122  WDFREQUEST Request
123  )
124 /*++
125 
126 Routine Description:
127 
128  This routine returns the identifier of the process that sent the I/O request.
129 
130  The WDM IRP is invalid once WdfRequestComplete is called, regardless
131  of any reference counts on the WDFREQUEST object.
132 
133 Arguments:
134 
135  Request - Handle to the Request object
136 
137 Returns:
138 
139  Process ID
140 
141 --*/
142 {
147 
148  //
149  // Validate the request handle, and get the FxRequest*
150  //
152  Request,
154  (PVOID*)&pRequest,
156 
157 #if FX_VERBOSE_TRACE
159  "Enter: WDFREQUEST 0x%p", Request);
160 #endif // FX_VERBOSE_TRACE
161 
162  status = pRequest->GetIrp(&irp);
163 
166  "WDFREQUEST is already completed 0x%p, %!STATUS!",
167  Request, status);
169  return 0;
170  }
171 
172  return irp->GetRequestorProcessId();
173 }
174 
176 WDFAPI
177 BOOLEAN
178 WDFEXPORT(WdfRequestIsFromUserModeDriver)(
179  _In_
181  _In_
182  WDFREQUEST Request
183  )
184 {
188  MdIrp irp;
189 
190  //
191  // Validate the request handle, and get the FxRequest*
192  //
194  Request,
196  (PVOID*)&pRequest,
198 
199 #if FX_VERBOSE_TRACE
201  "Enter: WDFREQUEST 0x%p", Request);
202 #endif // FX_VERBOSE_TRACE
203 
204  status = pRequest->GetIrp(&irp);
205 
206  if (!NT_SUCCESS(status)) {
208  "WDFREQUEST is already completed 0x%p, %!STATUS!",
209  Request, status);
211  return FALSE;
212  }
213 
214  return (pRequest->GetFxIrp()->GetIoIrp()->IsDriverCreated() ? TRUE : FALSE);
215 }
216 
218 WDFAPI
219 VOID
220 WDFEXPORT(WdfRequestSetUserModeDriverInitiatedIo)(
221  _In_
223  _In_
224  WDFREQUEST Request,
225  _In_
227  )
228 {
232  MdIrp irp;
233 
234  //
235  // Validate the request handle, and get the FxRequest*
236  //
238  Request,
240  (PVOID*)&pRequest,
242 
243 #if FX_VERBOSE_TRACE
245  "Enter: WDFREQUEST 0x%p", Request);
246 #endif // FX_VERBOSE_TRACE
247 
248  status = pRequest->GetIrp(&irp);
249 
250  if (!NT_SUCCESS(status)) {
252  "WDFREQUEST is already completed 0x%p, %!STATUS!",
253  Request, status);
255  return;
256  }
257 
258  pRequest->GetFxIrp()->GetIoIrp()->SetUserModeDriverInitiatedIo(
260  );
261 }
262 
264 WDFAPI
265 BOOLEAN
266 WDFEXPORT(WdfRequestGetUserModeDriverInitiatedIo)(
267  _In_
269  _In_
270  WDFREQUEST Request
271  )
272 {
276  MdIrp irp;
277 
278  //
279  // Validate the request handle, and get the FxRequest*
280  //
282  Request,
284  (PVOID*)&pRequest,
286 
287 #if FX_VERBOSE_TRACE
289  "Enter: WDFREQUEST 0x%p", Request);
290 #endif // FX_VERBOSE_TRACE
291 
292  status = pRequest->GetIrp(&irp);
293 
294  if (!NT_SUCCESS(status)) {
296  "WDFREQUEST is already completed 0x%p, %!STATUS!",
297  Request, status);
299  return FALSE;
300  }
301 
302  return (pRequest->GetFxIrp()->GetIoIrp()->GetUserModeDriverInitiatedIo()
303  ? TRUE : FALSE);
304 }
305 
307 WDFAPI
308 VOID
309 WDFEXPORT(WdfRequestSetActivityId)(
310  _In_
312  _In_
313  WDFREQUEST Request,
314  _In_
316  )
317 {
321  MdIrp irp;
322 
323  //
324  // Validate the request handle, and get the FxRequest*
325  //
327  Request,
329  (PVOID*)&pRequest,
331 
332 #if FX_VERBOSE_TRACE
334  "Enter: WDFREQUEST 0x%p", Request);
335 #endif // FX_VERBOSE_TRACE
336 
337  status = pRequest->GetIrp(&irp);
338 
339  if (!NT_SUCCESS(status)) {
341  "WDFREQUEST is already completed 0x%p, %!STATUS!",
342  Request, status);
344  return;
345  }
346 
347  pRequest->GetFxIrp()->GetIoIrp()->SetActivityId(ActivityId);
348 }
349 
351 WDFAPI
352 NTSTATUS
353 WDFEXPORT(WdfRequestRetrieveActivityId)(
354  _In_
356  _In_
357  WDFREQUEST Request,
358  _Out_
360  )
361 {
365  MdIrp irp;
366 
367  //
368  // Validate the request handle, and get the FxRequest*
369  //
371  Request,
373  (PVOID*)&pRequest,
375 
377 
378 #if FX_VERBOSE_TRACE
380  "Enter: WDFREQUEST 0x%p", Request);
381 #endif // FX_VERBOSE_TRACE
382 
383  status = pRequest->GetIrp(&irp);
384 
385  if (!NT_SUCCESS(status)) {
387  "WDFREQUEST is already completed 0x%p, %!STATUS!",
388  Request, status);
390  return status;
391  }
392 
393  if (pRequest->GetFxIrp()->GetIoIrp()->IsActivityIdSet() == FALSE) {
396  "WDFREQUEST 0x%p Activity ID is not set for the "
397  "request, %!STATUS!", Request, status);
398  return status;
399  }
400 
401  *ActivityId = *(pRequest->GetFxIrp()->GetIoIrp()->GetActivityId());
403 
404  return status;
405 }
406 
408 WDFAPI
410 WDFEXPORT(WdfRequestGetEffectiveIoType)(
411  _In_
413  _In_
414  WDFREQUEST Request
415  )
416 {
420  MdIrp irp;
421 
422  //
423  // Validate the request handle, and get the FxRequest*
424  //
426  Request,
428  (PVOID*)&pRequest,
430 
431 #if FX_VERBOSE_TRACE
433  "Enter: WDFREQUEST 0x%p", Request);
434 #endif // FX_VERBOSE_TRACE
435 
436  status = pRequest->GetIrp(&irp);
437 
438  if (!NT_SUCCESS(status)) {
440  "WDFREQUEST is already completed 0x%p, %!STATUS!",
441  Request, status);
443  return WdfDeviceIoUndefined;
444  }
445 
446  return (WDF_DEVICE_IO_TYPE)(pRequest->GetFxIrp()->GetIoIrp()->GetTransferMode());
447 }
448 
449 } // extern "C" the whole file
MdIrp irp
#define VALID_IMPERSONATION_LEVEL(Level)
Definition: setypes.h:101
#define _In_opt_
Definition: ms_sal.h:309
NTSTATUS status
#define _Out_
Definition: ms_sal.h:345
_Must_inspect_result_ _IRQL_requires_max_(PASSIVE_LEVEL) WDFAPI NTSTATUS WDFEXPORT(WdfRequestImpersonate)(_In_ PWDF_DRIVER_GLOBALS DriverGlobals
Queries information details about a security descriptor.
Definition: Messaging.c:64
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFREQUEST _In_ SECURITY_IMPERSONATION_LEVEL _In_ PFN_WDF_REQUEST_IMPERSONATE EvtRequestImpersonate
LONG NTSTATUS
Definition: precomp.h:26
enum _WDF_DEVICE_IO_TYPE WDF_DEVICE_IO_TYPE
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
FxPointerNotNull(pFxDriverGlobals, ActivityId)
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
DriverGlobals
#define TRACINGREQUEST
Definition: dbgtrace.h:65
#define FALSE
Definition: types.h:117
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals), Request, FX_TYPE_REQUEST,(PVOID *)&pRequest, &pFxDriverGlobals)
#define WDFEXPORT(a)
Definition: fxmacros.hpp:157
#define WDFAPI
Definition: wdftypes.h:53
enum _SECURITY_IMPERSONATION_LEVEL SECURITY_IMPERSONATION_LEVEL
unsigned char BOOLEAN
#define _In_
Definition: ms_sal.h:308
IWudfIrp * MdIrp
Definition: mxum.h:103
_Must_inspect_result_ _In_ WDFREQUEST _In_ SECURITY_IMPERSONATION_LEVEL _In_ PFN_WDF_REQUEST_IMPERSONATE _In_opt_ PVOID Context
PFX_DRIVER_GLOBALS pFxDriverGlobals
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ _In_ WDFREQUEST _In_ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
FxRequest * pRequest
FxIrp * GetFxIrp(VOID)
Definition: fxrequest.hpp:957
IWudfIoIrp * GetIoIrp(VOID)
Definition: fxirpum.cpp:1777
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
_Must_inspect_result_ NTSTATUS Impersonate(_In_ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, _In_ PFN_WDF_REQUEST_IMPERSONATE EvtRequestImpersonate, _In_opt_ PVOID Context)
_In_ WDFREQUEST _In_ BOOLEAN IsUserModeDriverInitiated
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ WDFREQUEST Request
_In_ WDFREQUEST _In_ LPGUID ActivityId
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
__inline PFX_DRIVER_GLOBALS GetFxDriverGlobals(__in PWDF_DRIVER_GLOBALS DriverGlobals)
Definition: fxglobals.h:597
_Must_inspect_result_ NTSTATUS GetIrp(__deref_out MdIrp *ppIrp)
Definition: fxrequest.hpp:975
FxVerifierDbgBreakPoint(pFxDriverGlobals)
Definition: ps.c:97