MiniFilter中如何取得IoCallDriver()状态,并继续处理?

在MiniFilter开发中,常会根据IoCallDriver的返回状态确定是否进行下一步处理.
那个状态如何获呢?
 
FltRequestOperationStatusCallback()
这个函数可以解决我们的问题.
它只能在PreOperation中调用,设置一个回调函数,
当IoCallDriver调用完成后会调用它所设置的回调函数.
 
1. Properly synchronized with unload
2.Handles operation being completed by a
  lower minifilter/Legacy filter
3.As in the legacy mode, may be called after the
operation has completed.
 
完成
  KEVENT Event;
  NTSTATUS Status;

  KeInitializeEvent(&Event, NotificationEvent, FALSE);
  IoCopyCurrentIrpStackLocationToNext(Irp);
  IoSetCompletionRoutine(Irp, SfForwardIrpSyncronouslyCompletion, &Event, TRUE, TRUE, TRUE);
  Status = IoCallDriver(DeviceObject, Irp);
  if (STATUS_PENDING == Status)
  {
    KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);

  }
 
NTSTATUS
SfForwardIrpSyncronouslyCompletion (
  IN PDEVICE_OBJECT DeviceObject,
  IN PIRP Irp,
  IN PVOID Context
  )
{
  PKEVENT Event = Context;

  UNREFERENCED_PARAMETER(DeviceObject);

  ASSERT(IS_MY_DEVICE_OBJECT(DeviceObject));

  if (Irp->PendingReturned)
  {
    KeSetEvent(Event, IO_NO_INCREMENT, FALSE);
  }

  return STATUS_MORE_PROCESSING_REQUIRED;
}
 
差不多的功能,等待下层驱动完成之后,根据返回状态进行下一步处理.

你可能感兴趣的:(职场,休闲,minifilter)