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/


Diagnosing why driver unload fails

RourkeRourke Member Posts: 49

I have a virtual storport miniport. The HwStorFreeAdapterResources frees everything and there are no inverted calls. devcon is used to install/uninstall. But sometimes uninstalling does not unload the driver and a system restart is required. Other times it works. The outcome seems random and unpredictable. Is there a way to diagnose what is causing driver unload to fail?

Comments

  • MajorTomMajorTom Member - All Emails Posts: 133
    I would try tracking handles and objects your driver is using.
    Driver Verifier on your driver might catch it.
    Also I would try Code Analysis compilation.
    In case those won’t help there are additional ways but this is as tier 1 triage.
  • RourkeRourke Member Posts: 49

    Of course I always run verifier on very stringent settings; detects nothing. I am also pretty sure the driver frees all resources perfectly and consistently as I described. So what I really need to understand is for what reason Windows decided not to unload it. Right now all I have to go in is sometimes it does, sometimes it doesn't. Are there any log files, events, something to trigger on in the debugger, anything like that? I understand this might be more difficult than a typical driver since storport is the one managing the device objects.

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,261

    First thing I would do is check C:\windows\inf\setupapi.dev.log and see if there's anything interesting there.

    -scott
    OSR

  • MajorTomMajorTom Member - All Emails Posts: 133
    It seems that your device reference count is not zero. I would try to make memory bp to track ref count and see what increments and does not decrement. Also on the error case you can try use process explorer look for open handles for your device.
  • RourkeRourke Member Posts: 49
    edited October 2019

    Here is the setupapi.dev.log output:

    ">>> [Delete Device - ROOT\SCSIADAPTER\0001]
    ">>> Section start 2019/10/29 20:24:20.473
    " cmd: devcon remove root\memex
    "! dvi: Setting needs reboot
    "! dvi: Query-and-Remove failed: 0x13: CR_FAILURE.
    "<<< Section end 2019/10/29 20:24:21.348
    "<<< [Exit status: SUCCESS]

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!
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 15 Jun 2020 LIVE ONLINE
Writing WDF Drivers 22 June 2020 LIVE ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA