Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


KMDF Verifier Complains About Filtering Create

Tim_RobertsTim_Roberts Member - All Emails Posts: 13,627

Let’s say you are a KMDF filter driver. Let’s say you need to filter IRP_MJ_CREATE calls. Let’s say there are some create calls you don’t really care about, so you just WdfRequestSend with WDF_SEND_OPTIONS_SEND_AND_FORGET. If you do that while the KMDF verifier is on, it will blue screen with an assert, complaining that it must have a completion routine and be post-processed. Why? What disaster is it trying to avoid? What post-processing do they expect me to do??

Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.

Comments

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,088

    Juuuuussst to be sure: You don't that SEND_AND_FORGET to a Local I/O Target, yes? I know you said "filter" but that doesn't necessarily mean you're passing your Create through to the in-stack target. That's the #1 issue I've seen with SEND_AND_FORGET... people trying to use it to send to non-local Targets.

    Aside from that, I can't IMAGINE what it thinks its trying to avoid. Have you looked at the WDF Sources?

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,088

    For the same of completeness, looking at the sources on github, I can't see why this would fail:

    https://github.com/microsoft/Windows-Driver-Frameworks/blob/e56019d083eaecb0b554f0d9246e89241e4a93c0/src/framework/shared/core/fxrequestapi.cpp#L1925

    Very mysterious,

    P

    Peter Viscarola
    OSR
    @OSRDrivers

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,525

    You can blame me :)

    https://github.com/microsoft/Windows-Driver-Frameworks/blob/master/src/framework/shared/core/fxrequest.cpp#L1096

        // You cannot fire and forget a create irp if we created a WDFFILEOBJECT
        // for it since you must post process the status of the create because
        // the create can fail in the driver to which we are sending the irp.
        //
        if ((m_Irp.GetMajorFunction() == IRP_MJ_CREATE)
            &&
            (FxFileObjectClassNormalize(GetDevice()->GetFileObjectClass()) !=
                WdfFileObjectNotRequired)) {
    
            DoTraceLevelMessage(
                FxDriverGlobals, TRACE_LEVEL_ERROR, TRACINGREQUEST,
                "WDFREQUEST %p cannot send and forget a create request which "
                "has a WDFFILEOBJECT created for it, it must have a completion "
                "routine and be post processsed", GetHandle());
    
            FxVerifierDbgBreakPoint(FxDriverGlobals);
        }
    
    d
  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,627

    Yes, I found that in the source, because the text wasn't in the in-flight recorder logs for some reason. I was hoping Doron would respond, because I was pretty sure it came from him. Neither the message nor the comments tells me WHAT post-processing I'm expected to do. I don't see that the framework is doing anything special when calling WdfRequestComplete with IRP_MJ_CREATE and a failure code. Do you remember what prompted this?

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 8,088

    LOL... thanks for "fessing up" Doron. At least we now know who to blame ;-)

    So, the issue here is that WDF might have to "tear down" the WDFFILEOBJECT that it created.

    Surely the code could handle this with its own internal completion routine, no??

    Well, I'm happy to learn something at least. Nice issue. Thanks for posting it, Mr. Roberts.

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,525

    At the time, we didn't want to "steal" the driver's io stack location in the fire and forget case and we didn't want to always allocate an extra io stack location just for the framework (which we had in very early implementations when packages were supposed to be the layering abstraction layering). The documentation is going to be updated to say that when you configure to create WDFFILEOBJECTs you need to complete the request in some fashion. BTW, the existing behavior is tucked away in the docs (emphasis is mine)

    https://docs.microsoft.com/en-us/windows-hardware/drivers/wdf/framework-file-objects

    If a driver forwards a creation request to an I/O target, the driver cannot set the WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET flag if the framework has created a framework file object for the creation request. Therefore, the driver cannot set the WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET flag for a creation request unless it also sets the WdfFileObjectNotRequired flag.

    d
  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,627

    OK, so what I've done is replace the "send-and-forget" with nothing more than a "send-synchronously" and a "WdfRequestComplete(request, WdfRequestGetStatus(request));". That does satisfy the verifier, and from the documentation, that seems like it should be enough.

    I'm glad I asked.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Internals & Software Drivers 25 Jan 2021 LIVE ONLINE
Developing Minifilters 8 March 2021 LIVE ONLINE