How can I make a driver wait for another driver or get notified when another driver starts?

Hi folks,

I have two drivers that I could not control the startup orders (one of them is a PNP driver), but one is dependent on another ('s functionalities).
Is there any way I can use to wait for the dependent driver to start or get notified when it starts, so I can let the driver go into working state.

much appreciated.

regards,
Hao

You don’t get to control the load order of PnP drivers. If I were writing this, I would let both drivers load normally, but use a kernel event to have the second driver block if it is asked to perform a function that needs the first driver. The first driver can set the event when it loads.

Why not use a device interface arrival notification to tell you the dependent driver has loaded? Eliminates the need to park a thread and the direct binding between them via the event.

@Tim_Roberts said:
You don’t get to control the load order of PnP drivers. If I were writing this, I would let both drivers load normally, but use a kernel event to have the second driver block if it is asked to perform a function that needs the first driver. The first driver can set the event when it loads.

Thanks very much. I will try to expand what you suggested:

  1. The first driver creates an event when starting by using IoCreateNotificationEvent, and set it to signaled
  2. The second one try to wait for the event to be signaled when starting (by using another thread if I understand correctly)

It seems IoCreateNotificationEvent can be used for both open and create, but it cannot tell the difference. For the 2nd one, it only needs to open an event and wait for it.

How can I address this?

Best regards,
Hao

@Doron_Holan said:
Why not use a device interface arrival notification to tell you the dependent driver has loaded? Eliminates the need to park a thread and the direct binding between them via the event.

Wow, this is something new to me, google didn’t help. Thanks, and I will look into this area.

ps: Could you please shed a light that what names the relevant apis are?

IoRegisterPlugPlayNotification Will let you register the callback to be notified of existing and new interface arrivals.

@Doron_Holan said:
IoRegisterPlugPlayNotification Will let you register the callback to be notified of existing and new interface arrivals.

Thanks again. But isn’t this for PnP device? What I want to check is actually a non-pnp driver.
Simply put:

  1. We have WPD driver whose startup timing is undetermined
  2. But what it depends (for some functionalities) is a non-pnp driver whose startup time may be later than the previous one.

It seems IoRegisterPlugPlayNotification cannot detect a non-pnp driver (or devices created by it using IoCreateDevice)

Thanks
Hao

How do you utilize the second driver? Do you open a handle and send IRPs?

@Tim_Roberts said:
How do you utilize the second driver? Do you open a handle and send IRPs?

It works as a WPD filter, written in WDF, only handle incoming IRPs
But the 1st one is a traditional WDM driver

What I meant was, how does the WPD driver access the other driver? How is it utilizing its services?

And, by the way, WDM vs WDF is totally irrelevant. Do you mean it is a “legacy” driver, one that is installed as a service and started via “net start”?

@Tim_Roberts said:
What I meant was, how does the WPD driver access the other driver? How is it utilizing its services?

And, by the way, WDM vs WDF is totally irrelevant. Do you mean it is a “legacy” driver, one that is installed as a service and started via “net start”?

Sorry for the misunderstanding.
Now in the WPD driver we just use a function pointer (think it as a callback) directly from the other driver (which now I think is an anti-pattern). Yes, the other driver is a legacy one, we use ‘net start’ or ‘sc start’ to control it.

And I have searched OSR forum, and found this discussion https://community.osr.com/discussion/134165/driver-to-driver-communication-in-wdf , which I think is very helpful. I decided to give excreatecallback a try.

What I plan is create two callback objects (maybe one is enough), one for WPD driver, one for the other legacy one. When they start, no matter who is first, will trigger the corresponding callback, to pass or fetch the real function pointer mentioned above. (And also do similar things when either of them stops)

Is this an OK design?

Thank you folks very much

Function pointers are fine, but you have to design for rundown when the driver providing the function pointer is being unloaded.

But how do you get the function pointer? Are you linking to it as a kernel DLL? That’s perfectly fine, but that forces the DLL driver to load, which solves part of your problem.

@Tim_Roberts said:
But how do you get the function pointer? Are you linking to it as a kernel DLL? That’s perfectly fine, but that forces the DLL driver to load, which solves part of your problem.

Currently we are linking to the legacy driver directly from the wpd filter driver, but we need the functionality to start and stop the legacy driver anytime.

What I am trying to implement now is like this:

  1. The legacy driver and the wpd filter driver would create or open a callback object using the same name when they start.
  2. After that they trigger the callback immediately with different parameters. Therefore, no matter what the startup order is, the one that starts first will get called, and it can pass (by the legacy driver) or fetch (by the wpd filter driver) the function pointer. All these happen in DriverEntry and unload.

Sorry for the duplicate posts. When I was editing the first one, it just disappeared… now it shows up again…oh my

> @hayate_lee said: > Sorry for the duplicate posts. When I was editing the first one, it just disappeared… now it shows up again…oh my Welcome to OSR and its spam system that only filters genuine questions and posts

@ThatsBerkan You would be VERY surprised if there were no automated spam system… There are, quite literally, hundreds of spam posts every day. So, basically, STFU unless you know what you’re talking about. And, you know, while you’re at it… contribute something helpful/useful.

@hayate_lee

When I was editing the first one, it just disappeared… now it shows up again

But, of course, you expected this and know what to do in this case, because you read the Announcement at the top of the forum, right?

Peter

@“Peter_Viscarola_(OSR)” said:
@ThatsBerkan You would be VERY surprised if there were no automated spam system… There are, quite literally, hundreds of spam posts every day. So, basically, STFU unless you know what you’re talking about. And, you know, while you’re at it… contribute something helpful/useful.

@hayate_lee

When I was editing the first one, it just disappeared… now it shows up again

But, of course, you expected this and know what to do in this case, because you read the Announcement at the top of the forum, right?

Peter

feel more sorry now~ learned a lesson
But thanks much

Here I have a further question about callback object. If I need two drivers to communicate with each other, I need to create the callback object with obj_permanent flag. But it seems there is no elegant way to remove this callback object when both drivers unload.

But it seems there is no elegant way to remove this callback object when both drivers unload.

Check the docs. You use ObDereferenceObject for that.