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/


Wait for event signalling from Kernel mode to User mode

vikrantwaje96vikrantwaje96 Member Posts: 3
edited September 13 in NTDEV

Hi folks,
I am newbie and currently working on notifying User mode thread from KMDF driver. From what I have read, I need to use Inverted IOCTL mechanism to notify the user mode thread from KMDF.
Following is the sequence that I am following:
1) Create user mode thread with overlapped flag
2) Create an event that will be used in hevent member of overlap structure(manual reset, non signalled).
3) Initialise the overlap structure. Also initialize the hevent flag with event created in step 2.
4) Issue an IOCTL(also pass the overlap structure).
5) Wait for the event to be signalled using GetOverlappedResultEx with timeout parameter to be INFINITE.

My question is , when the IOCTL is completed by the handler using WdfRequestComplete, do I need to explicitly set the event in order to signal the waiting thread, or will the user mode thread be automatically signalled once IOCTL is complete

Post edited by Scott_Noone_(OSR) on

Comments

  • MBond2MBond2 Member Posts: 477

    The first thing to remember is that the inverted call pattern can be used with any UM IO model. That's not quite true, but they are separate concepts.

    Inverted call refers to the idea of having UM components (usually services) open HANDLEs to KM components. Normally, the KM components wait for work to do from UM, but inverted call works the other way where UM waits for work from KM. It usually sends the results back to KM in some fashion

    UM IO models are closely tied to threading models in program design. Theoretically, any of the IO models supported by Windows can work with Inverted call, but in practice some work better than others. OVERLAPPED IO is highly desirable because of the ability to send several requests from UM to KM in advance of there being any work to do. These requests do not complete immediately, but are kept in a pending state until there is work that KM needs UM to do. This helps to avoid the problem that while KM needs UM to do the work, it can't force UM to ask for it and usually can't buffer the work for very long. By using OVERLAPPED IO, UM will pend several requests for work with the hope that in KM, there will always be something to use right away

    One way that a UM program can determine that an OVERLAPPED IO has completed is by including an EVENT object in the OVERLAPPED struct used for the DeviceIoControl, ReadFile, or WriteFile call being used. You can use GetOverlappedResult, HasOverlappedIoCompleted or user mode APCs, but by far the best is IOCP. For new development the thread pool APIs are recommended

    The main point is that your KM component need not concern itself with how the UM component waits for IO completion and you don't need to do anything special whatever method is chosen. on the KM side, the big problem is handling the case where there are no pending calls to complete. Should the data be discarded? buffered in some way? and if so then for how long or how much

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 9,025

    when the IOCTL is completed by the handler using WdfRequestComplete, do I need to explicitly set the event in order to signal the waiting thread, or will the user mode thread be automatically signalled once IOCTL is complete

    The event will automatically be signaled. You do not have to do anything other than completing the I/O Request.

    Peter Viscarola
    OSR
    @OSRDrivers

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

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!
Writing WDF Drivers 12 September 2022 Live, Online
Internals & Software Drivers 23 October 2022 Live, Online
Kernel Debugging 14 November 2022 Live, Online
Developing Minifilters 5 December 2022 Live, Online