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

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

When to call FsRtlEnterFileSystem/KeEnterCriticalRegion in minifilter ?

Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 199

Hello !

I am reading MS avscan sample and noticed that they call FsRtlEnterFileSystem/KeEnterCriticalRegion not before ExAcquireResource***Lite. They call FsRtlEnterFileSystem/KeEnterCriticalRegion in context of PostCreate, PreCleanup and InstanceSetupCallback. My understanding was that in general we don’t need to call FsRtlEnterFileSystem/KeEnterCriticalRegion in minifilter. In filesystem we call FsRtlEnterFileSystem before acquiring file resources for thread to not became suspended.

So when should we care about thread suspension in minifilter ?


  • Koby_KahaneKoby_Kahane Member Posts: 11

    Entering a critical region is appropriate whenever suspension of the current thread could lead to deadlocks. In particular, when the current thread obtains a resource that could prevent another thread from making progress indefinitely. In avscan, the AvScan routine enters a critical region before initiating the scan because if the scan initiating thread is suspended, any other thread that tries to access the file being scanned will end up hanging indefinitely waiting for the scan to complete - but it never will.

    Generalizing this, a minifilter should enter a critical region whenever it obtains a resource (in the broad sense, not just an ERESOURCE) that, if it is suspended while holding it, will prevent other threads accessing the object the resource is related to from making progress indefinitely. In the file systems themselves, this applies to the file's main and paging I/O resources. In a minifilter, what this applies to depends on your goals and on your specific design.

  • Sergey_PisarevSergey_Pisarev Member - All Emails Posts: 199
    Thank you very much again Koby !
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 20 Apr 2020 LIVE ONLINE
Writing WDF Drivers 11 May 2020 LIVE ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA