ReactOS 0.4.15-dev-7953-g1f49173
fxirpqueue.hpp
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxIrpQueue.hpp
8
9Abstract:
10
11 This module implements a common queue structure for the
12 driver frameworks built around the Cancel Safe Queues pattern
13
14Author:
15
16
17
18
19
20
21Environment:
22
23 Both kernel and user mode
24
25Revision History:
26
27
28--*/
29
30#ifndef _FXIRPQUEUE_H_
31#define _FXIRPQUEUE_H_
32
33#if (FX_CORE_MODE == FX_CORE_KERNEL_MODE)
34#include "fxirpkm.hpp"
35#else
36#include "fxirpum.hpp"
37#endif
38
39
40//
41// IRP DriverContext[] entry used.
42//
43// We use the same entry that the CSQ package does
44// which is OK since we can't use CSQ if we implement the
45// cancel handler ourselves
46//
47#define FX_IRP_QUEUE_CSQ_CONTEXT_ENTRY 3
48
49//
50// FxIrpQueue entry identifier
51//
52#define FX_IRP_QUEUE_ENTRY_IDENTIFIER 1
53
54#if ((FX_CORE_MODE)==(FX_CORE_KERNEL_MODE))
55#include "fxirpkm.hpp"
56#elif ((FX_CORE_MODE)==(FX_CORE_USER_MODE))
57#include "fxirpum.hpp"
58#endif
59
60
61//
62// This is the cancel function callback for the IrpQueue to its caller/parent
63// This is called holding the lock of the object owning the IrpQueue, and it
64// is responsible for completing the IRP.
65//
66
67extern "C" {
68__drv_functionClass(EVT_IRP_QUEUE_CANCEL)
70typedef
71VOID
72EVT_IRP_QUEUE_CANCEL (
77 );
78
79typedef EVT_IRP_QUEUE_CANCEL *PFN_IRP_QUEUE_CANCEL;
80}
81
83
84 friend VOID GetTriageInfo(VOID);
85
86private:
87
88 //
89 // The Queue
90 //
92
93 //
94 // The object whose lock controls the queue.
95 // Provided by the client object.
96 //
98
99 //
100 // Callers registered cancel callback
101 //
103
104 //
105 // Count of requests in the Queue
106 //
108
109public:
110
112 VOID
113 );
114
116 VOID
117 );
118
119 VOID
123 );
124
129 __in_opt PMdIoCsqIrpContext CsqContext,
130 __out_opt ULONG* pRequestCount
131 );
132
137 __in_opt PMdIoCsqIrpContext CsqContext,
138 __out_opt ULONG* pRequestCount
139 );
140
141 MdIrp
144 );
145
149 __in_opt PMdIoCsqIrpContext TagContext,
151 __out FxRequest** ppOutRequest
152 );
153
157 __in_opt PMdIoCsqIrpContext TagContext,
159 __out FxRequest** ppOutRequest
160 );
161
162 MdIrp
165 );
166
167 //
168 // Return whether the queue is empty
169 // (for optimizing the non-pending case in the caller)
170 //
171 inline
172 BOOLEAN
174
175 if( IsListEmpty(&m_Queue) ) {
176
178
179 return TRUE;
180 }
181 else {
183
184 return FALSE;
185 }
186 }
187
188 //
189 // Return count of queued and driver pending requests.
190 //
191 inline
192 LONG
194 return m_RequestCount;
195 }
196
197 BOOLEAN
200 );
201
202
203private:
204
205 //
206 // Insert an IRP on the cancel list
207 //
213 __in BOOLEAN InsertInHead,
214 __out_opt ULONG* pRequestCount
215 );
216
217 // Do not specify argument names
219 VOID,
220 VerifyRemoveIrpFromQueueByContext,
222 );
223
224 //
225 // Ask to remove an IRP from the cancel list by Context,
226 // and return NULL if its been cancelled
227 //
228 MdIrp
231 );
232
233 //
234 // Remove a request from the head of the queue if PeekContext == NULL,
235 // or the next request after PeekContext if != NULL
236 //
237 MdIrp
241 );
242
243 //
244 // Peek an IRP in the queue
245 //
246 MdIrp
250 );
251
252 //
253 // Unconditionally remove the IRP from the list entry
254 //
255 inline
256 VOID
259 )
260 {
261 PLIST_ENTRY entry = Irp->ListEntry();
266 }
267
268 //
269 // WDM IRP cancel function
270 //
271 static
274
275 //
276 // Lock functions accessed from WDM cancel callback
277 //
278 __inline
279 void
281 __out PKIRQL PreviousIrql
282 )
283 {
284 m_LockObject->Lock(PreviousIrql);
285 }
286
287 __inline
288 void
290 __in KIRQL PreviousIrql
291 )
292 {
293 m_LockObject->Unlock(PreviousIrql);
294 }
295};
296
297#endif // _FXIRPQUEUE_H
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
__inline void LockFromCancel(__out PKIRQL PreviousIrql)
Definition: fxirpqueue.hpp:280
MdIrp RemoveRequest(__in PMdIoCsqIrpContext Context)
Definition: fxirpqueue.cpp:478
VOID RemoveIrpFromListEntry(__inout FxIrp *Irp)
Definition: fxirpqueue.hpp:257
LONG m_RequestCount
Definition: fxirpqueue.hpp:107
_Must_inspect_result_ NTSTATUS InsertHeadRequest(__inout MdIrp Irp, __in_opt PMdIoCsqIrpContext CsqContext, __out_opt ULONG *pRequestCount)
Definition: fxirpqueue.cpp:168
_Must_inspect_result_ NTSTATUS PeekRequest(__in_opt PMdIoCsqIrpContext TagContext, __in_opt MdFileObject FileObject, __out FxRequest **ppOutRequest)
Definition: fxirpqueue.cpp:306
_Must_inspect_result_ NTSTATUS InsertTailRequest(__inout MdIrp Irp, __in_opt PMdIoCsqIrpContext CsqContext, __out_opt ULONG *pRequestCount)
Definition: fxirpqueue.cpp:115
MdIrp RemoveIrpFromQueueByContext(__in PMdIoCsqIrpContext Context)
Definition: fxirpqueue.cpp:671
friend VOID GetTriageInfo(VOID)
FxNonPagedObject * m_LockObject
Definition: fxirpqueue.hpp:97
MdIrp RemoveNextIrpFromQueue(__in_opt PVOID PeekContext, __out_opt PMdIoCsqIrpContext *pCsqContext)
Definition: fxirpqueue.cpp:787
_Must_inspect_result_ NTSTATUS InsertIrpInQueue(__inout MdIrp Irp, __in_opt PMdIoCsqIrpContext Context, __in BOOLEAN InsertInHead, __out_opt ULONG *pRequestCount)
Definition: fxirpqueue.cpp:505
BOOLEAN IsQueueEmpty()
Definition: fxirpqueue.hpp:173
MdIrp PeekNextIrpFromQueue(__in_opt MdIrp Irp, __in_opt PVOID PeekContext)
Definition: fxirpqueue.cpp:724
__inline void UnlockFromCancel(__in KIRQL PreviousIrql)
Definition: fxirpqueue.hpp:289
static MdCancelRoutineType _WdmCancelRoutineInternal
Definition: fxirpqueue.hpp:273
BOOLEAN IsIrpInQueue(__in PMdIoCsqIrpContext Context)
Definition: fxirpqueue.cpp:931
FX_DECLARE_VF_FUNCTION_P1(VOID, VerifyRemoveIrpFromQueueByContext, __in PMdIoCsqIrpContext)
LONG GetRequestCount()
Definition: fxirpqueue.hpp:193
MdIrp GetNextRequest(__out PMdIoCsqIrpContext *pCsqContext)
Definition: fxirpqueue.cpp:219
~FxIrpQueue(VOID)
Definition: fxirpqueue.cpp:55
PFN_IRP_QUEUE_CANCEL m_CancelCallback
Definition: fxirpqueue.hpp:102
LIST_ENTRY m_Queue
Definition: fxirpqueue.hpp:91
Definition: fxirp.hpp:28
__drv_restoresIRQL KIRQL __in BOOLEAN Unlock
Definition: fxobject.hpp:1474
_In_ PIRP Irp
Definition: csq.h:116
_In_opt_ PIRP _In_opt_ PVOID PeekContext
Definition: csq.h:160
#define __out_opt
Definition: dbghelp.h:65
#define __in
Definition: dbghelp.h:35
#define __inout
Definition: dbghelp.h:50
#define __in_opt
Definition: dbghelp.h:38
#define __out
Definition: dbghelp.h:62
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define __drv_requiresIRQL(irql)
Definition: driverspecs.h:321
#define __drv_functionClass(x)
Definition: driverspecs.h:274
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
UCHAR KIRQL
Definition: env_spec_w32.h:591
KIRQL * PKIRQL
Definition: env_spec_w32.h:592
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
__in MdIrp __in PMdIoCsqIrpContext pCsqContext
Definition: fxirpqueue.hpp:75
EVT_IRP_QUEUE_CANCEL * PFN_IRP_QUEUE_CANCEL
Definition: fxirpqueue.hpp:79
__in MdIrp __in PMdIoCsqIrpContext __in KIRQL CallerIrql
Definition: fxirpqueue.hpp:77
uint32_t entry
Definition: isohybrid.c:63
#define ASSERT(a)
Definition: mode.c:44
#define _Must_inspect_result_
Definition: ms_sal.h:558
PFILE_OBJECT MdFileObject
Definition: mxgeneralkm.h:32
IWudfIrp * MdIrp
Definition: mxum.h:103
WUDF_DRIVER_CANCEL MdCancelRoutineType
Definition: mxum.h:143
long LONG
Definition: pedump.c:60
Definition: typedefs.h:120
#define LockObject(Object)
Definition: titypes.h:34
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_ WDFDEVICE _In_ PIRP _In_ WDFQUEUE Queue
Definition: wdfdevice.h:2225
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
static void Initialize()
Definition: xlate.c:212