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/


Increment reference count on WDF REQUEST

ajitabhsajitabhs Member Posts: 100
edited October 2023 in NTDEV
Hi All,
I need to increment the ref count on wdf request in cancellation routine. Once the reference count is incremented, I would queue a work item and pass this wdf request to it.
In workitem I would check if the request is still pending with hardware if so then I cancel the request else if the request is completed/cancelled I just decrement the reference count and return.

How can I increment the reference count on wdfrequest ?


Thanks
Aj

Comments

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,828
    WdfObjectReference will keep the object alive until dereferenced but does not protect the object’s state.
    d
  • Tim_RobertsTim_Roberts Member - All Emails Posts: 14,831

    Right. Remember that the IRP that is being wrapped by the WDFREQUEST goes invalid once the request is completed, and KMDF can't prevent that. What are you planning to do that needs this?

    Tim Roberts, [email protected]
    Software Wizard Emeritus

  • ajitabhsajitabhs Member Posts: 100

    Hi Tim,
    Thanks for your response.

    Here is what I am planning to do.

    1. I have setup a extension part in each WDF request (RequestExtension). This extension part holds some state about the request.

    2. When I get a cancel routine, I am planning to increment the ref count on the WDF request and schedule a WorkItem.

    3. In the workitem which is at passive level, I am reclaiming the commands from the hardware and completing (cancelling) them to the OS. This abort is really a hammer and would like to perform this abort only when the hardware is not responsive.

    4. When I receive the wdfrequest in the workitem, I look at the extension part of the request and see if the request gets completed or not. If the request gets completed I avoid the abort hardware operations. If the request does not get completed, I perform the abort. The only thing I need is the extension part of the WDFREQUEST. I do not not modify the wdfrequest in anyway and I just access the extension part.

    Any thoughts are appreciated.
    -Thanks
    Aj.

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 9,159

    You don't need a reference count for this, do you? Don't you just need a COUNTER that you decrement in each location where you could ultimately complete the Request, and when this counter goes to zero that's when you complete the Request?

    That's the classic way of handling cancel in WDF. Or, at least, the classic way I handle cancel in WDF ;-)

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • ajitabhsajitabhs Member Posts: 100

    @Peter_Viscarola_(OSR)
    But where does that counter reside? the logical place is the request extension, then I will have to make sure that the request extension lives long enough so that I can access it in my abort. There is a delay between when the Cancel is called and my abort gets called. in that time the request could be completed and then the extension part will get destroyed. Instead of a counter I have a state but that does not really matter. I need to keep my extension alive.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

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!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 20-24 May 2024 Live, Online