#include <ntdef.h>
#include <ntifs.h>
Go to the source code of this file.
|
| _Function_class_ (DRIVER_CANCEL) |
| Cancel routine that is installed on any IRP that this library manages.
|
|
NTSTATUS NTAPI | IoCsqInitialize (_Out_ PIO_CSQ Csq, _In_ PIO_CSQ_INSERT_IRP CsqInsertIrp, _In_ PIO_CSQ_REMOVE_IRP CsqRemoveIrp, _In_ PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp, _In_ PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock, _In_ PIO_CSQ_RELEASE_LOCK CsqReleaseLock, _In_ PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp) |
| Set up a CSQ struct to initialize the queue.
|
|
NTSTATUS NTAPI | IoCsqInitializeEx (_Out_ PIO_CSQ Csq, _In_ PIO_CSQ_INSERT_IRP_EX CsqInsertIrpEx, _In_ PIO_CSQ_REMOVE_IRP CsqRemoveIrp, _In_ PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp, _In_ PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock, _In_ PIO_CSQ_RELEASE_LOCK CsqReleaseLock, _In_ PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp) |
| Set up a CSQ struct to initialize the queue (extended version)
|
|
VOID NTAPI | IoCsqInsertIrp (_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context) |
| Insert an IRP into the CSQ.
|
|
NTSTATUS NTAPI | IoCsqInsertIrpEx (_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context, _In_opt_ PVOID InsertContext) |
| Insert an IRP into the CSQ, with additional tracking context.
|
|
PIRP NTAPI | IoCsqRemoveIrp (_Inout_ PIO_CSQ Csq, _Inout_ PIO_CSQ_IRP_CONTEXT Context) |
| Remove anb IRP from the queue.
|
|
PIRP NTAPI | IoCsqRemoveNextIrp (_Inout_ PIO_CSQ Csq, _In_opt_ PVOID PeekContext) |
| IoCsqRemoveNextIrp - Removes the next IRP from the queue.
|
|
◆ DECLSPEC_IMPORT
Definition at line 29 of file csq.c.
◆ _Function_class_()
_Function_class_ |
( |
DRIVER_CANCEL |
| ) |
|
Cancel routine that is installed on any IRP that this library manages.
- Parameters
-
- Note
- We assume that Irp->Tail.Overlay.DriverContext[3] has either a IO_CSQ or an IO_CSQ_IRP_CONTEXT in it, but we have to figure out which it is
- By the time this routine executes, the I/O Manager has already cleared the cancel routine pointer in the IRP, so it will only be canceled once
- Because of this, we're guaranteed that Irp is valid the whole time
- Don't forget to release the cancel spinlock ASAP --> #1 hot lock in the system
- May be called at high IRQL
Definition at line 49 of file csq.c.
56{
59
60
62
63
65
67 {
70
71
73 }
74
75
79
81}
struct _IO_CSQ_IRP_CONTEXT * PIO_CSQ_IRP_CONTEXT
#define IO_TYPE_CSQ_IRP_CONTEXT
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
PIO_CSQ_RELEASE_LOCK CsqReleaseLock
PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock
PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
PIO_CSQ_REMOVE_IRP CsqRemoveIrp
◆ IoCsqInitialize()
Set up a CSQ struct to initialize the queue.
- Parameters
-
Csq | - Caller-allocated non-paged space for our IO_CSQ to be initialized |
CsqInsertIrp | - Insert routine |
CsqRemoveIrp | - Remove routine |
CsqPeekNextIrp | - Routine to paeek at the next IRP in queue |
CsqAcquireLock | - Acquire the queue's lock |
CsqReleaseLock | - Release the queue's lock |
CsqCompleteCanceledIrp | - Routine to complete IRPs when they are canceled |
- Returns
- STATUS_SUCCESS in all cases
- Note
- Csq must be non-paged, as the queue is manipulated with a held spinlock
Definition at line 103 of file csq.c.
111{
120
122}
PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp
PIO_CSQ_INSERT_IRP CsqInsertIrp
_In_ PIO_CSQ_INSERT_IRP _In_ PIO_CSQ_REMOVE_IRP _In_ PIO_CSQ_PEEK_NEXT_IRP _In_ PIO_CSQ_ACQUIRE_LOCK _In_ PIO_CSQ_RELEASE_LOCK _In_ PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp
_In_ PIO_CSQ_INSERT_IRP CsqInsertIrp
_In_ PIO_CSQ_INSERT_IRP _In_ PIO_CSQ_REMOVE_IRP _In_ PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp
_In_ PIO_CSQ_INSERT_IRP _In_ PIO_CSQ_REMOVE_IRP _In_ PIO_CSQ_PEEK_NEXT_IRP _In_ PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock
_In_ PIO_CSQ_INSERT_IRP _In_ PIO_CSQ_REMOVE_IRP CsqRemoveIrp
_In_ PIO_CSQ_INSERT_IRP _In_ PIO_CSQ_REMOVE_IRP _In_ PIO_CSQ_PEEK_NEXT_IRP _In_ PIO_CSQ_ACQUIRE_LOCK _In_ PIO_CSQ_RELEASE_LOCK CsqReleaseLock
Referenced by DriverEntry(), MsfsCreateMailslot(), and USBPORT_StartDevice().
◆ IoCsqInitializeEx()
Set up a CSQ struct to initialize the queue (extended version)
- Parameters
-
Csq | - Caller-allocated non-paged space for our IO_CSQ to be initialized |
CsqInsertIrpEx | - Extended insert routine |
CsqRemoveIrp | - Remove routine |
CsqPeekNextIrp | - Routine to paeek at the next IRP in queue |
CsqAcquireLock | - Acquire the queue's lock |
CsqReleaseLock | - Release the queue's lock |
CsqCompleteCanceledIrp | - Routine to complete IRPs when they are canceled |
- Returns
- STATUS_SUCCESS in all cases
- Note
- Csq must be non-paged, as the queue is manipulated with a held spinlock
Definition at line 143 of file csq.c.
151{
160
162}
IO_CSQ_INSERT_IRP * PIO_CSQ_INSERT_IRP
NTSTATUS NTAPI CsqInsertIrpEx(PIO_CSQ Csq, PIRP Irp, PVOID InsertContext)
Referenced by FsRtlPrivateLock(), and InitializeMessageWaiterQueue().
◆ IoCsqInsertIrp()
Insert an IRP into the CSQ.
- Parameters
-
Csq | - Pointer to the initialized CSQ |
Irp | - Pointer to the IRP to queue |
Context | - Context record to track the IRP while queued |
- Returns
- Just passes through to IoCsqInsertIrpEx, with no InsertContext
Definition at line 177 of file csq.c.
181{
183}
NTSTATUS NTAPI IoCsqInsertIrpEx(_Inout_ PIO_CSQ Csq, _Inout_ PIRP Irp, _Out_opt_ PIO_CSQ_IRP_CONTEXT Context, _In_opt_ PVOID InsertContext)
Insert an IRP into the CSQ, with additional tracking context.
Referenced by DeviceIoctl(), DispatchReadWrite(), MsfsRead(), ReadWrite(), USBPORT_DoIdleNotificationCallback(), USBPORT_HandleSubmitURB(), and USBPORT_IdleNotification().
◆ IoCsqInsertIrpEx()
Insert an IRP into the CSQ, with additional tracking context.
- Parameters
-
Csq | - Pointer to the initialized CSQ |
Irp | - Pointer to the IRP to queue |
Context | - Context record to track the IRP while queued |
InsertContext | - additional data that is passed through to CsqInsertIrpEx |
- Note
- Passes the additional context through to the driver-supplied callback, which can be used with more sophistocated queues
- Marks the IRP pending in all cases
- Guaranteed to not queue a canceled IRP
- This is complicated logic, and is patterend after the Microsoft library. I'm sure I have gotten the details wrong on a fine point or two, but basically this works with the MS-supplied samples.
Definition at line 205 of file csq.c.
210{
213
215
216 do
217 {
218
220
221
223 {
228 }
229 else
230 Irp->Tail.Overlay.DriverContext[3] =
Csq;
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
271 else
272 {
276 break;
277 }
278
279
281
282
284 break;
285
286
287
288
289
291 break;
292
293
294 Irp->Tail.Overlay.DriverContext[3] = 0;
295
296
299
302 }
303 while(0);
304
306
307 return Retval;
308}
_In_ PIRP _In_ PVOID InsertContext
IO_CSQ_INSERT_IRP_EX * PIO_CSQ_INSERT_IRP_EX
IoSetCancelRoutine(Irp, CancelRoutine)
Referenced by FsRtlFastUnlockSingle(), FsRtlPrivateLock(), and IoCsqInsertIrp().
◆ IoCsqRemoveIrp()
Remove anb IRP from the queue.
- Parameters
-
Csq | - Queue to remove the IRP from |
Context | - Context record containing the IRP to be dequeued |
- Returns
- Pointer to an IRP if we found it
- Note
- Don't forget that we can be canceled any time up to the point where we unset our cancel routine
Definition at line 326 of file csq.c.
329{
332
334
335 do
336 {
337
339
341 break;
342
344
345
347 {
348
349
350
351
353 break;
354 }
355
357
358
360
362
364 {
366
368 }
369
370 Irp->Tail.Overlay.DriverContext[3] = 0;
371 }
372 while(0);
373
375
377}
#define InterlockedExchangePointer(Target, Value)
Referenced by MsfsTimeout().
◆ IoCsqRemoveNextIrp()
IoCsqRemoveNextIrp - Removes the next IRP from the queue.
- Parameters
-
Csq | - Queue to remove the IRP from |
PeekContext | - Identifier of the IRP to be removed |
- Returns
- Pointer to the IRP that was removed, or NULL if one could not be found
- Note
- This function is sensitive to yet another race condition. The basic idea is that we have to return the first IRP that we get that matches the PeekContext >that is not already canceled<. Therefore, we have to do a trick similar to the one done in Insert above.
Definition at line 398 of file csq.c.
401{
405
407
409 {
410
411
412
413
414
415
417 continue;
418
420
421
423
425 {
427
429 }
430
431 Irp->Tail.Overlay.DriverContext[3] = 0;
432
433 break;
434 }
435
437
439}
_In_opt_ PIRP _In_opt_ PVOID PeekContext
Referenced by DispatchCreateCloseCleanup(), DispatchIoctl(), FsRtlFastUnlockSingle(), FsRtlUninitializeFileLock(), MsfsWrite(), QueueThread(), USBPORT_BadRequestFlush(), USBPORT_CompletePendingIdleIrp(), and USBPORT_DoIdleNotificationCallback().