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

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?



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

    The docs are pretty clear, I think:

    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 Viscarola

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
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 20 Apr 2020 OSR Seminar Space & ONLINE
Writing WDF Drivers 11 May 2020 OSR Seminar Space & ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA