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

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

Microsoft WDM Cancel Logic Document

Erik_DabrowskyErik_Dabrowsky Member - All Emails Posts: 11

I had to update a WDM driver recently and in doing so decided to review all the code.
(Yes it should be ported to WDF, but that's a task for another day...)

In reviewing the code, I found that the cancellation logic and cancel routine were improperly implemented.

The following document from Microsoft was very useful to me.
The section "Cancel Logic with a Driver-Supplied Lock" was most helpful.
It helped me better understand the possible race conditions that can happen and the proper way to deal with them.
download.microsoft.com/download/5/7/7/577a5684-8a83-43ae-9272-ff260a9c20e2/cancel_logic.doc

I expect most people are probably using WDF and may not have to deal with this, but I thought I would share it with the community just in case.

Comments

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 12,854
    via Email
    Erik_Dabrowsky wrote:
    > In reviewing the code, I found that the cancellation logic and cancel routine were improperly implemented.

    I'm not sure there are ANY WDM drivers to which that sentence does not
    apply.

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

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,058

    15 year old paper, at least. It’s so old I can’t even remember who wrote it.

    The primary thing it’s missing is what cancel means... and when you need to cancel it. But in terms of telling yuppi how to write your code, it seems fine.

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • anton_bassovanton_bassov Member Posts: 4,901

    In reviewing the code, I found that the cancellation logic and cancel routine were improperly implemented.

    I'm not sure there are ANY WDM drivers to which that sentence does not apply.

    Well, this is most definitely an overstatement and a gross exaggeration, and I am pretty sure you know it yourself. Just think of numerous in-box drivers that had been written in WDM quite a while ago.

    You know, when one starts blowing things, no matter how reasonable they may be, out of proportion,they generally tend to turn into something nonsensical and absurd....

    Anton Bassov

  • Don_BurnDon_Burn Member - All Emails Posts: 1,648
    via Email
    Actually, the statement was not necessarily an exaggeration. When Microsoft started presenting their efforts on KMDF at first it was to a limited group under NDA. During those sessions Redmond indicated they went through every driver they had looking at the code, and found none that dealt with PnP/Power or cancelation correctly.


    Don Burn
    Windows Driver Consulting
    Website: http://www.windrvr.com
  • anton_bassovanton_bassov Member Posts: 4,901

    During those sessions Redmond indicated they went through every driver they had looking at the code, and found none
    that dealt with PnP/Power or cancelation correctly.

    Well, I guess it depends on what the word "correctly" may mean in the particular context.....

    If you introduce some new requirements there is, indeed, always a good chance that none of your existing drivers yet conforms to them. Otherwise, the above statement is very obviously ridiculous. Just think about the whole thing carefully, and you are hopefully) going to realise it within a split-second - we are speaking about the system with overall installation base expressed in terms of at least 9-10-digit numbers at the moment, and, once in a sudden, it turns out that, out of few dozens of its in-box drivers,
    NOT A SINGLE ONE works correctly by the design...

    Anton Bassov

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,427
    via Email
    Basically, yes. All of the many, many various race conditions and timing around cancel were not understood for years after NT
    d
  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,058

    found none that dealt with PnP/Power or cancelation correctly

    PnP/Power was always much harder than cancel... but for a very long time problems in canel was one of the top two causes of driver crashes.

    All praise WDF, for making these problems largely a thing of the past (though, cancel in WDF could definitely be easier than it is now).

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

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
Writing WDF Drivers 25 Feb 2019 OSR Seminar Space
Developing Minifilters 8 April 2019 OSR Seminar Space