⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cancel.c

📁 driver wdk
💻 C
字号:
//++
// File Name:
//		cancel.c
//
// Contents:
//		Support for IRP cancellation
//
//--
#include "ave2k.h"
#include "channel2.h"

//++
// Function:
//		Ave2kCancelIrp
//
// Description:
//		This function gets called to cancel
//		an IRP that's somewhere between the
//		Device Queue and the beginning
//		of processing in the Start I/O routine.
//
// Arguments:
//		Pointer to the Device object
//		Pointer to the target IRP
//
// Return Value:
//		(None)
//
// Synchronization:
//		This routine is called at DISPATCH_LEVEL
//		IRQL, holding the Cancel spin lock.
//
//--
VOID
Ave2kCancelIrp(
	IN PDEVICE_OBJECT DeviceObject,
	IN PIRP Irp
	)
{
	PDEVICE_EXTENSION DeviceExtension =
				DeviceObject->DeviceExtension;

	KdPrint(( "Ave2kCancelIrp: IRP %8x\n", Irp ));

	//
	// If IRP is already in the CurrentIrp slot,
	// but not yet started, we can cancel it.
	//
	if( Irp == DeviceObject->CurrentIrp )
	{
		KdPrint(( "\tIRP is current\n" ));

		//
		// Release the Cancel spin lock
		// *BEFORE* calling IoCompleteRequest
		//
		IoReleaseCancelSpinLock( Irp->CancelIrql );

		Irp->IoStatus.Status = STATUS_CANCELLED;
		Irp->IoStatus.Information = 0;

		IoCompleteRequest( Irp, IO_NO_INCREMENT );
		IoStartNextPacket( DeviceObject, TRUE );
	}
	//
	// IRP is not the current IRP. It must still 
	// be sitting in the Device Queue.
	//
	else
	{
		KdPrint(( "\tIRP is in Device Queue; removing and cancelling.\n" ));
		KeRemoveEntryDeviceQueue( 
			&DeviceObject->DeviceQueue,
			&Irp->Tail.Overlay.DeviceQueueEntry );

		IoReleaseCancelSpinLock( Irp->CancelIrql );

		Irp->IoStatus.Status = STATUS_CANCELLED;
		Irp->IoStatus.Information = 0;

		//
		// Complete this IRP, but don't start the
		// next one.
		//
		IoCompleteRequest( Irp, IO_NO_INCREMENT );
	}
		
}

//++
// Function:
//		Ave2kCancelChannel2Irp
//
// Description:
//		This function gets called to cancel
//		an IRP of Channel2
//
// Arguments:
//		Pointer to the Device object
//		Pointer to the target IRP
//
// Return Value:
//		(None)
//
// Synchronization:
//		This routine is called at DISPATCH_LEVEL
//		IRQL, holding the Cancel spin lock.
//
//--
VOID
Ave2kCancelChannel2Irp(
	IN PDEVICE_OBJECT DeviceObject,
	IN PIRP Irp
	)
{
	PDEVICE_EXTENSION DeviceExtension =
				DeviceObject->DeviceExtension;

	KdPrint(( "Ave2kCancelChannel2Irp: IRP %8x\n", Irp ));

	//
	// If IRP is already in the CurrentIrp slot,
	// but not yet started, we can cancel it.
	//
	if( Irp == DeviceExtension->CurrentAlternateIrp )
	{
		KdPrint(( "\tIRP is current\n" ));

		//
		// Release the Cancel spin lock
		// *BEFORE* calling IoCompleteRequest
		//
		IoReleaseCancelSpinLock( Irp->CancelIrql );

		Irp->IoStatus.Status = STATUS_CANCELLED;
		Irp->IoStatus.Information = 0;

		IoCompleteRequest( Irp, IO_NO_INCREMENT );
		Ave2kChannel2StartNextPacket( DeviceObject, TRUE );
	}
	//
	// IRP is not the current IRP. It must still 
	// be sitting in the Device Queue.
	//
	else
	{
		KdPrint(( "\tIRP is in Device Queue; removing and cancelling.\n" ));
		KeRemoveEntryDeviceQueue( 
			&DeviceExtension->AlternateIrpQueue,
			&Irp->Tail.Overlay.DeviceQueueEntry );

		IoReleaseCancelSpinLock( Irp->CancelIrql );

		Irp->IoStatus.Status = STATUS_CANCELLED;
		Irp->IoStatus.Information = 0;

		//
		// Complete this IRP, but don't start the
		// next one.
		//
		IoCompleteRequest( Irp, IO_NO_INCREMENT );
	}
		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -