Handling IRPs 8: Propagating the Pending Bit

Propagating the Pending Bit

Any time a driver handling an I/O request returns the response of the next-lower driver, the value of the pending bit in its I/O stack location (SL_PENDING_RETURNED in the Control field of the IO_STACK_LOCATION structure) must be the same as that of the next-lower driver. If the driver does not set an IoCompletion routine, the I/O Manager automatically propagates the value of the bit, freeing the driver of this responsibility. However, if the driver sets an IoCompletion routine, and the next-lower driver returns STATUS_PENDING, the current driver must mark its own I/O stack location as pending. For example:

// Forward request to next driver

IoCopyCurrentIrpStackLocationToNext( Irp );

 

// Send the IRP down

status = IoCallDriver( nextDevice, Irp );

 

// Return the lower driver’s status

return status;

 

Because this example does not set an IoCompletion routine, the driver must not call the IoMarkIrpPending macro. The driver simply returns the same status as the next-lower driver and the I/O Manager copies the value of the pending bit.    

However, if the driver sets an IoCompletion routine, this code is insufficient for situations in which the lower driver returns STATUS_PENDING. In such situations, the driver must call the IoMarkIrpPending macro to set the SL_PENDING_RETURNED bit for its own I/O stack location. The driver must call IoMarkIrpPending from an IoCompletion routine; it must not make this call from its dispatch routine. Thus, the following code is incorrect:

// Forward request to next driver

IoCopyCurrentIrpStackLocationToNext( Irp );

 

// Send the IRP down

status = IoCallDriver( nextDevice, Irp );

 

// The following is an error because this driver

// no longer owns the IRP.

If (status == STATUS_PENDING) {

 

    IoMarkIrpPending( Irp );

}

 

// Return the lower driver’s status

return status;

 

This approach is incorrect because IoMarkIrpPending operates on the current I/O stack location. After IoCallDriver passes the IRP to the next lower driver, the current driver no longer owns the IRP. Thus, when the call to IoMarkIrpPending is executed, there is no current I/O stack location; in fact, if a lower driver completed the IRP, then the pointer is no longer valid. To avoid this problem, the driver must call IoMarkIrpPending from an IoCompletion routine. For example:

NTSTATUS

CompletionRoutine( ... )

{

   if (IrpàPendingReturned) {

 

      // Return the lower driver’s result. If the

      // lower driver marked its stack location pending,

      // so do we.

      IoMarkIrpPending( Irp );

   }

 

… //additional processing in IoCompletion routine

 

   return STATUS_CONTINUE_COMPLETION;

}

 

Drivers should use this code sequence only when returning the same status as the lower driver. If the driver does not set an IoCompletion routine, the I/O Manager automatically propagates the value of the SL_PENDING_RETURNED bit upwards to the next I/O stack location. A driver is not required to use an IoCompletion routine simply to call IoMarkIrpPending; but if a driver does have an IoCompletion routine, and a lower driver returns STATUS_PENDING, the IoCompletion routine must call IoMarkIrpPending.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值