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

Sept/Oct 2019 Issue of The NT Insider available


Download PDF here: http://insider.osr.com/2019/ntinsider_2019_01.pdf

It’s a particularly BIG issue, too: 40 pages of technical goodness, ranging from WDF to Minifilters. Check it out.
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

[WDM] When should I acquire and release RemoveLock?

BlastoidBlastoid Member Posts: 3

Hi everyone

Looking at drivers code, I found myself confused about when I should acquire/release a RemoveLock.
I know this must be related to PNP and Power management, but I haven't found any useful resource that spill information about that.

I see some drivers provide PNP and POWER dispatch routines and do acquire the RemoveLock during operations which the driver cannot be removed, but I see some other drivers that doesn't implement those and don't need to worry about locking

Can someone help me understand this?

Thanks.

Comments

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

    The docs are pretty clear, I think: https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/using-remove-locks

    The one thing that’s not necessarily clear in the docs is that Remove Locks Remove locks aren’t an architectural part of Windows... they’re just a tool that (works entirely within your driver and) was created to make it easier for WDM drivers to track when their device can be destructed. This was long before KMDF was created.

    So, some drivers use them... some don’t. I’ve never used a Remove Lock in a WDM driver... probably because I started writing WDM drivers before there were Remove Locks. I simply used my own code that accomplishes the same goal.

    So, you need to track when your Device Object can be destructed somehow, but you don’t have to use a Remove Lock to accomplish this.

    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 21 Oct 2019 OSR Seminar Space & ONLINE
Internals & Software Drivers 18 Nov 2019 Dulles, VA
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 27 Apr 2020 OSR Seminar Space & ONLINE