看流星社区

 找回密码
 注册账号
查看: 1882|回复: 0

再次深入理解IRP

[复制链接]

该用户从未签到

发表于 2017-6-1 13:33:10 | 显示全部楼层 |阅读模式
过滤驱动与IRP处理方式
我们关系这个IRP的处理结果 就用这个
a.Pending完成例程
IoCopyCurrentIrpStackLocationToNext +完成例程
Pending完成例程
KEVENT event;
KeInitializeEvent(&event, NotificationEvent, FALSE);
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(Irp,
CompRoutine,
&event,
TRUE,
TRUE,
TRUE
);
status = IoCallDriver(DeviceObject, Irp);
if (status == STATUS_PENDING)
{
        status = KeWaitForSingleObject(&event,
Executive,
KernelMode,
FALSE,
NULL
);
ASSERT(NT_SUCCESS(status));
status = Irp->IoStatus.Status;
}
[/code]
回调例程
NTSTATUS
CompRoutine(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp,
    IN PVOID Context
    )
{
    PKEVENT event = Context;
    Irp->UserIosb->Status = Irp->IoStatus.Status;
    Irp->UserIosb->Information = Irp->IoStatus.Information;


    KeSetEvent(event ,
        IO_NO_INCREMENT, FALSE);


    //IoFreeIrp(Irp);


    return STATUS_MORE_PROCESSING_REQUIRED;
}
[/code]

b.忽略直接下发
IoSkipCurrentIrpStackLocation,下层设备拿到的IO_STACKLOCATION 和当前的一样


对IRP没有任何改动的时候,比如放行:
PDEVICE_EXTENSION   deviceExtension;
IoSkipCurrentIrpStackLocation(Irp);[/code]
//拿到保存在设备扩展里的下层设备
deviceExtension =
        (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
//下发
return IoCallDriver(
                deviceExtension->TargetDeviceObject,
                Irp);
[/code]

c.结束IRP不下发
PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation (Irp);
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest( Irp, IO_NO_INCREMENT );[/code]
d.手动构建IRP
IoAllocateIrp
IoGetNextIrpStackLocation


IoAllocateIrp /IoBuildDeviceIoControlRequest
IoGetNextIrpStackLocation
//例子:
//强制删除文件
//Sfilter里查询文件名字[/code]
错误的下发:
下发后就没有访问这个IRP的权限了 必须等待 和设置完成例程 例程中必须返回STATUS_MORE_PROCESSING_REQUIRED
// 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 );//错误,无权操作Irp了
}
// Return the lower driver’s status
return status;
[/code]
点击按钮快速添加回复内容: 支持 高兴 激动 给力 加油 苦寻 生气 回帖 路过 感恩
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

小黑屋|手机版|Archiver|看流星社区 |网站地图

GMT+8, 2024-3-19 17:43

Powered by Kanliuxing X3.4

© 2010-2019 kanliuxing.com

快速回复 返回顶部 返回列表