mirror of
https://github.com/reactos/reactos.git
synced 2025-06-03 16:30:26 +00:00
[CSQ]
Formatting, add annotations, use doxygen style comments, no functional change svn path=/trunk/; revision=57953
This commit is contained in:
parent
a011b6bc32
commit
ed547ad4a5
1 changed files with 289 additions and 255 deletions
|
@ -30,13 +30,13 @@
|
|||
#include <ntifs.h>
|
||||
|
||||
|
||||
static VOID NTAPI IopCsqCancelRoutine(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
/*
|
||||
* FUNCTION: Cancel routine that is installed on any IRP that this library manages
|
||||
* ARGUMENTS:
|
||||
* [Called back by the system]
|
||||
* NOTES:
|
||||
/*!
|
||||
* @brief Cancel routine that is installed on any IRP that this library manages
|
||||
*
|
||||
* @param DeviceObject
|
||||
* @param Irp
|
||||
*
|
||||
* @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
|
||||
|
@ -46,6 +46,13 @@ static VOID NTAPI IopCsqCancelRoutine(PDEVICE_OBJECT DeviceObject,
|
|||
* system
|
||||
* - May be called at high IRQL
|
||||
*/
|
||||
_Function_class_(DRIVER_CANCEL)
|
||||
static
|
||||
VOID
|
||||
NTAPI
|
||||
IopCsqCancelRoutine(
|
||||
_Inout_ PDEVICE_OBJECT DeviceObject,
|
||||
_Inout_ _IRQL_uses_cancel_ PIRP Irp)
|
||||
{
|
||||
PIO_CSQ Csq;
|
||||
KIRQL Irql;
|
||||
|
@ -74,28 +81,33 @@ static VOID NTAPI IopCsqCancelRoutine(PDEVICE_OBJECT DeviceObject,
|
|||
}
|
||||
|
||||
|
||||
NTSTATUS NTAPI IoCsqInitialize(PIO_CSQ Csq,
|
||||
PIO_CSQ_INSERT_IRP CsqInsertIrp,
|
||||
PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
|
||||
PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
|
||||
PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
|
||||
PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
|
||||
PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp)
|
||||
/*
|
||||
* FUNCTION: Set up a CSQ struct to initialize the queue
|
||||
* ARGUMENTS:
|
||||
* 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:
|
||||
/*!
|
||||
* @brief Set up a CSQ struct to initialize the queue
|
||||
*
|
||||
* @param Csq - Caller-allocated non-paged space for our IO_CSQ to be initialized
|
||||
* @param CsqInsertIrp - Insert routine
|
||||
* @param CsqRemoveIrp - Remove routine
|
||||
* @param CsqPeekNextIrp - Routine to paeek at the next IRP in queue
|
||||
* @param CsqAcquireLock - Acquire the queue's lock
|
||||
* @param CsqReleaseLock - Release the queue's lock
|
||||
* @param CsqCompleteCanceledIrp - Routine to complete IRPs when they are canceled
|
||||
*
|
||||
* @return
|
||||
* - STATUS_SUCCESS in all cases
|
||||
* NOTES:
|
||||
*
|
||||
* @note
|
||||
* - Csq must be non-paged, as the queue is manipulated with a held spinlock
|
||||
*/
|
||||
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)
|
||||
{
|
||||
Csq->Type = IO_TYPE_CSQ;
|
||||
Csq->CsqInsertIrp = CsqInsertIrp;
|
||||
|
@ -110,28 +122,32 @@ NTSTATUS NTAPI IoCsqInitialize(PIO_CSQ Csq,
|
|||
}
|
||||
|
||||
|
||||
NTSTATUS NTAPI IoCsqInitializeEx(PIO_CSQ Csq,
|
||||
PIO_CSQ_INSERT_IRP_EX CsqInsertIrpEx,
|
||||
PIO_CSQ_REMOVE_IRP CsqRemoveIrp,
|
||||
PIO_CSQ_PEEK_NEXT_IRP CsqPeekNextIrp,
|
||||
PIO_CSQ_ACQUIRE_LOCK CsqAcquireLock,
|
||||
PIO_CSQ_RELEASE_LOCK CsqReleaseLock,
|
||||
PIO_CSQ_COMPLETE_CANCELED_IRP CsqCompleteCanceledIrp)
|
||||
/*
|
||||
* FUNCTION: Set up a CSQ struct to initialize the queue (extended version)
|
||||
* ARGUMENTS:
|
||||
* 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:
|
||||
/*!
|
||||
* @brief Set up a CSQ struct to initialize the queue (extended version)
|
||||
*
|
||||
* @param Csq - Caller-allocated non-paged space for our IO_CSQ to be initialized
|
||||
* @param CsqInsertIrpEx - Extended insert routine
|
||||
* @param CsqRemoveIrp - Remove routine
|
||||
* @param CsqPeekNextIrp - Routine to paeek at the next IRP in queue
|
||||
* @param CsqAcquireLock - Acquire the queue's lock
|
||||
* @param CsqReleaseLock - Release the queue's lock
|
||||
* @param CsqCompleteCanceledIrp - Routine to complete IRPs when they are canceled
|
||||
*
|
||||
* @return
|
||||
* - STATUS_SUCCESS in all cases
|
||||
* NOTES:
|
||||
* @note
|
||||
* - Csq must be non-paged, as the queue is manipulated with a held spinlock
|
||||
*/
|
||||
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)
|
||||
{
|
||||
Csq->Type = IO_TYPE_CSQ_EX;
|
||||
Csq->CsqInsertIrp = (PIO_CSQ_INSERT_IRP)CsqInsertIrpEx;
|
||||
|
@ -146,35 +162,36 @@ NTSTATUS NTAPI IoCsqInitializeEx(PIO_CSQ Csq,
|
|||
}
|
||||
|
||||
|
||||
VOID NTAPI IoCsqInsertIrp(PIO_CSQ Csq,
|
||||
PIRP Irp,
|
||||
PIO_CSQ_IRP_CONTEXT Context)
|
||||
/*
|
||||
* FUNCTION: Insert an IRP into the CSQ
|
||||
* ARGUMENTS:
|
||||
* Csq: Pointer to the initialized CSQ
|
||||
* Irp: Pointer to the IRP to queue
|
||||
* Context: Context record to track the IRP while queued
|
||||
* NOTES:
|
||||
/*!
|
||||
* @brief Insert an IRP into the CSQ
|
||||
*
|
||||
* @param Csq - Pointer to the initialized CSQ
|
||||
* @param Irp - Pointer to the IRP to queue
|
||||
* @param Context - Context record to track the IRP while queued
|
||||
*
|
||||
* @return
|
||||
* - Just passes through to IoCsqInsertIrpEx, with no InsertContext
|
||||
*/
|
||||
VOID
|
||||
NTAPI
|
||||
IoCsqInsertIrp(
|
||||
_Inout_ PIO_CSQ Csq,
|
||||
_Inout_ PIRP Irp,
|
||||
_Out_opt_ PIO_CSQ_IRP_CONTEXT Context)
|
||||
{
|
||||
IoCsqInsertIrpEx(Csq, Irp, Context, 0);
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS NTAPI IoCsqInsertIrpEx(PIO_CSQ Csq,
|
||||
PIRP Irp,
|
||||
PIO_CSQ_IRP_CONTEXT Context,
|
||||
PVOID InsertContext)
|
||||
/*
|
||||
* FUNCTION: Insert an IRP into the CSQ, with additional tracking context
|
||||
* ARGUMENTS:
|
||||
* 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
|
||||
* NOTES:
|
||||
/*!
|
||||
* @brief Insert an IRP into the CSQ, with additional tracking context
|
||||
*
|
||||
* @param Csq - Pointer to the initialized CSQ
|
||||
* @param Irp - Pointer to the IRP to queue
|
||||
* @param Context - Context record to track the IRP while queued
|
||||
* @param 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
|
||||
|
@ -183,6 +200,13 @@ NTSTATUS NTAPI IoCsqInsertIrpEx(PIO_CSQ Csq,
|
|||
* I'm sure I have gotten the details wrong on a fine point or two, but
|
||||
* basically this works with the MS-supplied samples.
|
||||
*/
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
IoCsqInsertIrpEx(
|
||||
_Inout_ PIO_CSQ Csq,
|
||||
_Inout_ PIRP Irp,
|
||||
_Out_opt_ PIO_CSQ_IRP_CONTEXT Context,
|
||||
_In_opt_ PVOID InsertContext)
|
||||
{
|
||||
NTSTATUS Retval = STATUS_SUCCESS;
|
||||
KIRQL Irql;
|
||||
|
@ -281,19 +305,24 @@ NTSTATUS NTAPI IoCsqInsertIrpEx(PIO_CSQ Csq,
|
|||
}
|
||||
|
||||
|
||||
PIRP NTAPI IoCsqRemoveIrp(PIO_CSQ Csq,
|
||||
PIO_CSQ_IRP_CONTEXT Context)
|
||||
/*
|
||||
* FUNCTION: Remove anb IRP from the queue
|
||||
* ARGUMENTS:
|
||||
* Csq: Queue to remove the IRP from
|
||||
* Context: Context record containing the IRP to be dequeued
|
||||
* RETURNS:
|
||||
/*!
|
||||
* @brief Remove anb IRP from the queue
|
||||
*
|
||||
* @param Csq - Queue to remove the IRP from
|
||||
* @param Context - Context record containing the IRP to be dequeued
|
||||
*
|
||||
* @return
|
||||
* - Pointer to an IRP if we found it
|
||||
* NOTES:
|
||||
*
|
||||
* @note
|
||||
* - Don't forget that we can be canceled any time up to the point
|
||||
* where we unset our cancel routine
|
||||
*/
|
||||
PIRP
|
||||
NTAPI
|
||||
IoCsqRemoveIrp(
|
||||
_Inout_ PIO_CSQ Csq,
|
||||
_Inout_ PIO_CSQ_IRP_CONTEXT Context)
|
||||
{
|
||||
KIRQL Irql;
|
||||
PIRP Irp = NULL;
|
||||
|
@ -334,23 +363,28 @@ PIRP NTAPI IoCsqRemoveIrp(PIO_CSQ Csq,
|
|||
return Irp;
|
||||
}
|
||||
|
||||
PIRP NTAPI IoCsqRemoveNextIrp(PIO_CSQ Csq,
|
||||
PVOID PeekContext)
|
||||
/*
|
||||
* FUNCTION: IoCsqRemoveNextIrp - Removes the next IRP from the queue
|
||||
* ARGUMENTS:
|
||||
* Csq: Queue to remove the IRP from
|
||||
* PeekContext: Identifier of the IRP to be removed
|
||||
* RETURNS:
|
||||
/*!
|
||||
* @brief IoCsqRemoveNextIrp - Removes the next IRP from the queue
|
||||
*
|
||||
* @param Csq - Queue to remove the IRP from
|
||||
* @param PeekContext - Identifier of the IRP to be removed
|
||||
*
|
||||
* @return
|
||||
* Pointer to the IRP that was removed, or NULL if one
|
||||
* could not be found
|
||||
* NOTES:
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
PIRP
|
||||
NTAPI
|
||||
IoCsqRemoveNextIrp(
|
||||
_Inout_ PIO_CSQ Csq,
|
||||
_In_opt_ PVOID PeekContext)
|
||||
{
|
||||
KIRQL Irql;
|
||||
PIRP Irp = NULL;
|
||||
|
|
Loading…
Reference in a new issue