-
-
[求助]关于win驱动中StartIo历程的问题
-
发表于: 2017-4-11 11:11 2028
-
最近在读windows驱动开发技术时,发现了一个小问题,请各位帮忙看一下。
在StartIo历程的例子中,作者给出irp的取消历程为:
VOID OnCancelIRP( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { KdPrint(("Enter CancelReadIRP\n")); if (Irp==DeviceObject->CurrentIrp) { KIRQL oldirql = Irp->CancelIrql; IoReleaseCancelSpinLock(Irp->CancelIrql); IoStartNextPacket(DeviceObject,TRUE); KeLowerIrql(oldirql); }else { KeRemoveEntryDeviceQueue(&DeviceObject->DeviceQueue,&Irp->Tail.Overlay.DeviceQueueEntry); IoReleaseCancelSpinLock(Irp->CancelIrql); } Irp->IoStatus.Status = STATUS_CANCELLED; Irp->IoStatus.Information = 0; // bytes xfered IoCompleteRequest( Irp, IO_NO_INCREMENT ); KdPrint(("Leave CancelReadIRP\n")); }
StartIo历程为:
VOID HelloDDKStartIO( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { KIRQL oldirql; KdPrint(("Enter HelloDDKStartIO\n")); IoAcquireCancelSpinLock(&oldirql); if (Irp!=DeviceObject->CurrentIrp||Irp->Cancel) { IoReleaseCancelSpinLock(oldirql); KdPrint(("Leave HelloDDKStartIO\n")); return; }else { IoSetCancelRoutine(Irp,NULL); IoReleaseCancelSpinLock(oldirql); } KEVENT event; KeInitializeEvent(&event,NotificationEvent,FALSE); LARGE_INTEGER timeout; timeout.QuadPart = -3*1000*1000*10; KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,&timeout); Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Information = 0; // no bytes xfered IoCompleteRequest(Irp,IO_NO_INCREMENT); IoStartNextPacket(DeviceObject,TRUE); KdPrint(("Leave HelloDDKStartIO\n")); }
如上,在取消历程的if为真的语句块中,并没有直接使用return语句返回,另一方面StartIo历程会对当前的irp进行complete,而在取消历程的if语句结束后也会对当前的irp进行complete,两次对同一个irp进行complete,会不会出错?
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
赞赏
看原图
赞赏
雪币:
留言: