阅读:3735回复:3
请教TdiBuildInternalDeviceControlIrp的释放问题
请问各位牛兄,TdiBuildInternalDeviceControlIrp() 分配出来的 IRP 该用哪个方法释放呢,
用 IoFreeIrp(query_irp); 还是 IoCompleteRequest(query_irp, IO_NO_INCREMENT); 我是指还没有调用 TdiBuildQueryInformation() 和 IoCallDriver() 之前,如果分配MDL失败,或者出现其它异常,需要手动释放 IRP 的情况下。 非常感谢! |
|
沙发#
发布于:2010-05-23 15:49
也就是这个 IRP 还没有机会完成
|
|
板凳#
发布于:2010-05-23 16:31
自己搜到一些资料:
http://www.codeproject.com/kb/system/driverdev5asp.aspx If you create an IRP using IoBuildDeviceIoControlRequest or IoBuildSynchronousFsdRequest, then you have created a Synchronous IRP. Remember, TdiBuildInternalDeviceControlIrp is a macro and creates a synchronous IRP. These IRPs are owned and managed by the I/O Manager! Do not free them! This is a common mistake I have seen with code on the internet that they call IoFreeIrp on failure! These IRPs MUST be completed using IoCompleteRequest. If you pass this IRP down to IoCallDriver, you do not need to complete it as the driver below will do it for you. If you do intercept the IRP with a completion routine, you will need to call IoCompleteRequest after you are done with it though. 红色那句比较迷惑,个人理解是下层驱动调过 IoCompleteRequest() 才会执行到 completion routine,为什么还要求在 completion routine 内部再去调 IoCompleteRequest() 呢? |
|
地板#
发布于:2011-03-02 10:22
TdiBuildInternalDeviceControlIrp并不需要你来释放
它是一个宏 而内部实际调用滴是:IoBuildDeviceIoControlRequest 只有用IoAllocateIrp申请滴IRP才需要程序员自己释放 |
|