阅读:1474回复:5
天哪,这段代码还是没有看懂
...
IoSetCompletionRoutine(... BulkUsb_IrpCompletionRoutine, &startDeviceEvent, ... ); ntStatus = IoCallDriver(stackDeviceObject, Irp); if (ntStatus == STATUS_PENDING) { waitStatus = KeWaitForSingleObject( &startDeviceEvent, .... ); ... } .... IoCompleteRequest (Irp, IO_NO_INCREMENT ); 各位大哥救命,这是DDK的BulkUSB的bulkpnp.c的一段.我看Walter的书,他说调用IoCallDriver后进入STATUS_PENDING,然后等待startDeviceEvent进入信号态,而startDeviceEvent进入信号态依靠完成例程BulkUsb_IrpCompletionRoutine的设置,而BulkUsb_IrpCompletionRoutine又由IoCompleteRequest调用,但是现在程序正在KeWaitForSingleObject等着,怎么可能运行到下面IoCompletRequest处?我怎么越想越没有想通这个逻辑. 小弟先谢过了. |
|
最新喜欢:![]() |
沙发#
发布于:2001-12-22 17:41
IoCallDriver()会调用下层driver,当下层的driver发现设备没准备好时,会返回status_pending.你的KeWaitForSingleObject()就会等待
随着时间的流逝当下层的driver发现设备准备好时,就会调用IoCompleteRequest();你的completeroutine就会获得调用 |
|
板凳#
发布于:2001-12-24 10:18
(引用masmasm兄)
随着时间的流逝当下层的driver发现设备准备好时,就会调用IoCompleteRequest();你的completeroutine就会获得调用 有劳各位老兄,我就是没有看懂那段代码如何调用IoCompleteRequest,如果从KeWaitSingleObject顺序执行下来倒是可以理解,但是现在KeWaitSingleObject自己还在等着IoCompleteRequest调用完成例程BulkUsb_IrpCompletionRoutine来设置事件startDeviceEvent为信号态啊.不会是设备跳过KeWaitSingleObject自己就直接调用了IoCompleteRequest吧?不好意思,我很菜,再次请教. |
|
地板#
发布于:2001-12-24 17:17
(1) IoCallDriver()调用下层driver,并返回status_pending.
IoCallDriver sends an IRP to the next-lower-level driver after the caller has set up the I/O stack location in the IRP for that driver.IoCallDriver returns the NTSTATUS value that a lower driver set in the I/O status block for the given request or STATUS_PENDING if the request was queued for additional processing. (2)KeWaitForSingleObject()等待。 (3)当下层的driver完成IRP,就会调BulkUsb_IrpCompletionRoutine。 CompletionRoutine - Address of the completion routine that is to be invoked once the next level driver completes the packet. (4)KeWaitForSingleObject受信,运行到下面IoCompletRequest处. KeWaitForSingleObject routine puts the current thread into a wait state until the given dispatcher object is set to a signaled state or (optionally) until the wait times out. |
|
地下室#
发布于:2001-12-24 17:52
多谢两位回帖,但是我还是没有搞懂完成例程是怎么调用的,从unknow兄的帖子来看应该是IRP在下层设备完成后就自动调用了,但是我看Walter的书说
IoCompleteRequest is responsible for calling all of the completion routines that drivers installed in their respective stack locations. ... is this: Something calls IoCompleteRequest to signal the end of processing for the IRP. 但是Unknow的意思是先调用完成例程,然后调用IoCompleteRequest? 不好意思,小弟实在愚笨,再次请教. |
|
5楼#
发布于:2001-12-25 13:59
设备底层的驱动程序完成IRP后,调用IoCompleteRequest,Irp沿设备
栈向上传递,若设有完成列程,就调用完成列程,在完成列程中,若 返回码是STATUS_MORE_PROCESSING_REQUESTED,则避免进一步处理。 否则,继续沿设备栈向上,同理处理,只到返回原始的调用者。 IoCompleteRequest is responsible for calling all of the completion routines(栈中每层都可以设完成列程) that drivers installed in their respective stack locations. ... is this: Something calls IoCompleteRequest to signal the end of processing for the IRP. |
|