IoCallDriver函数与PoCallDriver函数
NTSTATUS
IoCallDriver(
IN PDEVICE_OBJECT DeviceObject,
IN OUT PIRP Irp
);
NTSTATUS
PoCallDriver(
IN PDEVICE_OBJECT DeviceObject,
IN OUT PIRP Irp
);
除了函数名不同之外,其他都一样。参数都是两个,一个是设备对象的指针,另一个是IRP请求对象的指针。返回值也是一样。那么区别到底是什么呢?
我们来看WDK Documentation上的解释:
The IoCallDriver routine sends an IRP to the driver associated with a specified device object.
The PoCallDriver routine passes a power IRP to the next-lower driver in the device stack. (Windows Server 2003, Windows XP, and Windows 2000 only.)
从上面的这两句话中可以看出:IoCallDriver这个函数向DeviceObject设备对象的驱动对象发送一个IRP请求;而PoCallDriver函数向设备栈中的下层设备传递一个主功能号为IRP_MJ_POWER的请求,且限于特定的OS。
而且,调用IoCallDriver之前,主调驱动程序必须要为目标驱动程序建立IRP里的I/O stack location;同时,调用时,IoCallDriver函数还会帮助驱动程序将输入参数的DeviceObject值赋给IO_STACK_LOCATION结构里的DeviceObject成员。