I have a user mode application that keeps an IRP pending until a condition is
satisfied or the device is removed. The driver's remove device routine
completes the IRP with STATUS_CANCELLED. The user mode app then closes the
handle. My expectation was that the driver unload routine would be invoked at
this point, but I'm not seeing that happen. Is this expected behavior or do I
have a bug?

Mike

Re: A Driver Unload Question by Don

Don
Fri Sep 09 14:35:58 CDT 2005

The OS will not call unload if there is an IRP pending.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply



"Yoke" <mdyoke@community.nospam> wrote in message
news:271D9CF1-4655-426E-9836-33C537D9A980@microsoft.com...
>I have a user mode application that keeps an IRP pending until a condition
>is
> satisfied or the device is removed. The driver's remove device routine
> completes the IRP with STATUS_CANCELLED. The user mode app then closes the
> handle. My expectation was that the driver unload routine would be invoked
> at
> this point, but I'm not seeing that happen. Is this expected behavior or
> do I
> have a bug?
>
> Mike



Re: A Driver Unload Question by mdyoke

mdyoke
Fri Sep 09 14:54:01 CDT 2005

Here is a clarification of the scenario I'm interested in, just to make sure
I communicated correctly:

1) User mode app starts.
2) Plug in USB device, driver loads.
3) User mode app sends request to the driver that pends and blocks the app.
4) Detach USB device.
5) Remove Device routine runs and completes IRP with STATUS_CANCELLED and
unblocks the app.
6) App closes handle.

I would have expected the driver unload routine to be invoked following step
6.

"Don Burn" wrote:

> The OS will not call unload if there is an IRP pending.
>
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
>
>
> "Yoke" <mdyoke@community.nospam> wrote in message
> news:271D9CF1-4655-426E-9836-33C537D9A980@microsoft.com...
> >I have a user mode application that keeps an IRP pending until a condition
> >is
> > satisfied or the device is removed. The driver's remove device routine
> > completes the IRP with STATUS_CANCELLED. The user mode app then closes the
> > handle. My expectation was that the driver unload routine would be invoked
> > at
> > this point, but I'm not seeing that happen. Is this expected behavior or
> > do I
> > have a bug?
> >
> > Mike
>
>
>

Re: A Driver Unload Question by Pavel

Pavel
Fri Sep 09 16:31:25 CDT 2005

In your scenario, replace 5) to: driver handles PnP surprise removal
event and cancels (or completes) the IRP .
Then it will be ok.

--PA

"Yoke" <mdyoke@community.nospam> wrote in message news:3C80BC77-30C2-407A-AEE0-4911B23F780F@microsoft.com...
> Here is a clarification of the scenario I'm interested in, just to make sure
> I communicated correctly:
>
> 1) User mode app starts.
> 2) Plug in USB device, driver loads.
> 3) User mode app sends request to the driver that pends and blocks the app.
> 4) Detach USB device.
> 5) Remove Device routine runs and completes IRP with STATUS_CANCELLED and
> unblocks the app.
> 6) App closes handle.
>
> I would have expected the driver unload routine to be invoked following step
> 6.
>
> "Don Burn" wrote:
>
>> The OS will not call unload if there is an IRP pending.
>>
>>
>> --
>> Don Burn (MVP, Windows DDK)
>> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> Remove StopSpam from the email to reply
>>
>>
>>
>> "Yoke" <mdyoke@community.nospam> wrote in message
>> news:271D9CF1-4655-426E-9836-33C537D9A980@microsoft.com...
>> >I have a user mode application that keeps an IRP pending until a condition
>> >is
>> > satisfied or the device is removed. The driver's remove device routine
>> > completes the IRP with STATUS_CANCELLED. The user mode app then closes the
>> > handle. My expectation was that the driver unload routine would be invoked
>> > at
>> > this point, but I'm not seeing that happen. Is this expected behavior or
>> > do I
>> > have a bug?
>> >
>> > Mike
>>
>>
>>



Re: A Driver Unload Question by mdyoke

mdyoke
Sun Sep 11 09:55:01 CDT 2005

My surprise remove handler completes the IRP as well. One other detail I
should probably mention is that my driver creates a singleton device object
that gets destroyed when all of my devices have been removed. This is the
device object that the user mode app targets.

Mike


"Pavel A." wrote:

> In your scenario, replace 5) to: driver handles PnP surprise removal
> event and cancels (or completes) the IRP .
> Then it will be ok.
>
> --PA
>
> "Yoke" <mdyoke@community.nospam> wrote in message news:3C80BC77-30C2-407A-AEE0-4911B23F780F@microsoft.com...
> > Here is a clarification of the scenario I'm interested in, just to make sure
> > I communicated correctly:
> >
> > 1) User mode app starts.
> > 2) Plug in USB device, driver loads.
> > 3) User mode app sends request to the driver that pends and blocks the app.
> > 4) Detach USB device.
> > 5) Remove Device routine runs and completes IRP with STATUS_CANCELLED and
> > unblocks the app.
> > 6) App closes handle.
> >
> > I would have expected the driver unload routine to be invoked following step
> > 6.
> >
> > "Don Burn" wrote:
> >
> >> The OS will not call unload if there is an IRP pending.
> >>
> >>
> >> --
> >> Don Burn (MVP, Windows DDK)
> >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> >> Remove StopSpam from the email to reply
> >>
> >>
> >>
> >> "Yoke" <mdyoke@community.nospam> wrote in message
> >> news:271D9CF1-4655-426E-9836-33C537D9A980@microsoft.com...
> >> >I have a user mode application that keeps an IRP pending until a condition
> >> >is
> >> > satisfied or the device is removed. The driver's remove device routine
> >> > completes the IRP with STATUS_CANCELLED. The user mode app then closes the
> >> > handle. My expectation was that the driver unload routine would be invoked
> >> > at
> >> > this point, but I'm not seeing that happen. Is this expected behavior or
> >> > do I
> >> > have a bug?
> >> >
> >> > Mike
> >>
> >>
> >>
>
>
>

Re: A Driver Unload Question by Eliyas

Eliyas
Sun Sep 11 11:46:00 CDT 2005

http://groups.google.com/group/microsoft.public.development.device.drivers/browse_thread/thread/c0d59eb3f1c7057a/3df9934d68cdaa0f?lnk=st&q=NdisMRegisterDevice+NDIS+Eliyas+NetVmini&rnum=1#3df9934d68cdaa0f

--
--
-Eliyas
This posting is provided "AS IS" with no warranties, and confers no rights.
http://www.microsoft.com/whdc/driver/default.mspx
http://www.microsoft.com/whdc/driver/kernel/KB-drv.mspx



"Yoke" <mdyoke@community.nospam> wrote in message
news:BAC50F7D-F522-4AE7-A6EC-EF9A25CF5188@microsoft.com...
> My surprise remove handler completes the IRP as well. One other detail I
> should probably mention is that my driver creates a singleton device
> object
> that gets destroyed when all of my devices have been removed. This is the
> device object that the user mode app targets.
>
> Mike
>
>
> "Pavel A." wrote:
>
>> In your scenario, replace 5) to: driver handles PnP surprise removal
>> event and cancels (or completes) the IRP .
>> Then it will be ok.
>>
>> --PA
>>
>> "Yoke" <mdyoke@community.nospam> wrote in message
>> news:3C80BC77-30C2-407A-AEE0-4911B23F780F@microsoft.com...
>> > Here is a clarification of the scenario I'm interested in, just to make
>> > sure
>> > I communicated correctly:
>> >
>> > 1) User mode app starts.
>> > 2) Plug in USB device, driver loads.
>> > 3) User mode app sends request to the driver that pends and blocks the
>> > app.
>> > 4) Detach USB device.
>> > 5) Remove Device routine runs and completes IRP with STATUS_CANCELLED
>> > and
>> > unblocks the app.
>> > 6) App closes handle.
>> >
>> > I would have expected the driver unload routine to be invoked following
>> > step
>> > 6.
>> >
>> > "Don Burn" wrote:
>> >
>> >> The OS will not call unload if there is an IRP pending.
>> >>
>> >>
>> >> --
>> >> Don Burn (MVP, Windows DDK)
>> >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
>> >> Remove StopSpam from the email to reply
>> >>
>> >>
>> >>
>> >> "Yoke" <mdyoke@community.nospam> wrote in message
>> >> news:271D9CF1-4655-426E-9836-33C537D9A980@microsoft.com...
>> >> >I have a user mode application that keeps an IRP pending until a
>> >> >condition
>> >> >is
>> >> > satisfied or the device is removed. The driver's remove device
>> >> > routine
>> >> > completes the IRP with STATUS_CANCELLED. The user mode app then
>> >> > closes the
>> >> > handle. My expectation was that the driver unload routine would be
>> >> > invoked
>> >> > at
>> >> > this point, but I'm not seeing that happen. Is this expected
>> >> > behavior or
>> >> > do I
>> >> > have a bug?
>> >> >
>> >> > Mike
>> >>
>> >>
>> >>
>>
>>
>>



Re: A Driver Unload Question by pavel_a

pavel_a
Sun Sep 11 14:44:01 CDT 2005

"Yoke" wrote:
> My surprise remove handler completes the IRP as well. One other detail I
> should probably mention is that my driver creates a singleton device object
> that gets destroyed when all of my devices have been removed. This is the
> device object that the user mode app targets.

But then, does 6) occur? That is, the app should detect unnormal
completion of the IRP (due to removal) and close the handle.
--PA

> "Pavel A." wrote:
>
> > In your scenario, replace 5) to: driver handles PnP surprise removal
> > event and cancels (or completes) the IRP .
> > Then it will be ok.
> >
> > --PA
> >
> > "Yoke" <mdyoke@community.nospam> wrote in message news:3C80BC77-30C2-407A-AEE0-4911B23F780F@microsoft.com...
> > > Here is a clarification of the scenario I'm interested in, just to make sure
> > > I communicated correctly:
> > >
> > > 1) User mode app starts.
> > > 2) Plug in USB device, driver loads.
> > > 3) User mode app sends request to the driver that pends and blocks the app.
> > > 4) Detach USB device.
> > > 5) Remove Device routine runs and completes IRP with STATUS_CANCELLED and
> > > unblocks the app.
> > > 6) App closes handle.
> > >
> > > I would have expected the driver unload routine to be invoked following step
> > > 6.
> > >
> > > "Don Burn" wrote:
> > >
> > >> The OS will not call unload if there is an IRP pending.
> > >>
> > >>
> > >> --
> > >> Don Burn (MVP, Windows DDK)
> > >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > >> Remove StopSpam from the email to reply
> > >>
> > >>
> > >>
> > >> "Yoke" <mdyoke@community.nospam> wrote in message
> > >> news:271D9CF1-4655-426E-9836-33C537D9A980@microsoft.com...
> > >> >I have a user mode application that keeps an IRP pending until a condition
> > >> >is
> > >> > satisfied or the device is removed. The driver's remove device routine
> > >> > completes the IRP with STATUS_CANCELLED. The user mode app then closes the
> > >> > handle. My expectation was that the driver unload routine would be invoked
> > >> > at
> > >> > this point, but I'm not seeing that happen. Is this expected behavior or
> > >> > do I
> > >> > have a bug?
> > >> >
> > >> > Mike
> > >>
> > >>
> > >>
> >
> >
> >

Re: A Driver Unload Question by mdyoke

mdyoke
Sun Sep 11 16:00:02 CDT 2005

Yes, the IRP gets cancelled by the driver, the app resumes and closes the
handle. I see the IRP_MJ_CLOSE occur in the driver but the unload routine is
never invoked.

Mike

"Pavel A." wrote:

> "Yoke" wrote:
> > My surprise remove handler completes the IRP as well. One other detail I
> > should probably mention is that my driver creates a singleton device object
> > that gets destroyed when all of my devices have been removed. This is the
> > device object that the user mode app targets.
>
> But then, does 6) occur? That is, the app should detect unnormal
> completion of the IRP (due to removal) and close the handle.
> --PA
>
> > "Pavel A." wrote:
> >
> > > In your scenario, replace 5) to: driver handles PnP surprise removal
> > > event and cancels (or completes) the IRP .
> > > Then it will be ok.
> > >
> > > --PA
> > >
> > > "Yoke" <mdyoke@community.nospam> wrote in message news:3C80BC77-30C2-407A-AEE0-4911B23F780F@microsoft.com...
> > > > Here is a clarification of the scenario I'm interested in, just to make sure
> > > > I communicated correctly:
> > > >
> > > > 1) User mode app starts.
> > > > 2) Plug in USB device, driver loads.
> > > > 3) User mode app sends request to the driver that pends and blocks the app.
> > > > 4) Detach USB device.
> > > > 5) Remove Device routine runs and completes IRP with STATUS_CANCELLED and
> > > > unblocks the app.
> > > > 6) App closes handle.
> > > >
> > > > I would have expected the driver unload routine to be invoked following step
> > > > 6.
> > > >
> > > > "Don Burn" wrote:
> > > >
> > > >> The OS will not call unload if there is an IRP pending.
> > > >>
> > > >>
> > > >> --
> > > >> Don Burn (MVP, Windows DDK)
> > > >> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> > > >> Remove StopSpam from the email to reply
> > > >>
> > > >>
> > > >>
> > > >> "Yoke" <mdyoke@community.nospam> wrote in message
> > > >> news:271D9CF1-4655-426E-9836-33C537D9A980@microsoft.com...
> > > >> >I have a user mode application that keeps an IRP pending until a condition
> > > >> >is
> > > >> > satisfied or the device is removed. The driver's remove device routine
> > > >> > completes the IRP with STATUS_CANCELLED. The user mode app then closes the
> > > >> > handle. My expectation was that the driver unload routine would be invoked
> > > >> > at
> > > >> > this point, but I'm not seeing that happen. Is this expected behavior or
> > > >> > do I
> > > >> > have a bug?
> > > >> >
> > > >> > Mike
> > > >>
> > > >>
> > > >>
> > >
> > >
> > >

Re: A Driver Unload Question by Alexander

Alexander
Sun Sep 11 18:22:33 CDT 2005

The driver doesn't get REMOVE_DEVICE request until the handle is closed and
probably all FILE_OBJECTs are closed, too, which means all IRPs are
completed.

You need to handle WM_DEVICECHANGE/DBT_DEVTYP_HANDLE in your application.

"Yoke" <mdyoke@community.nospam> wrote in message
news:271D9CF1-4655-426E-9836-33C537D9A980@microsoft.com...
>I have a user mode application that keeps an IRP pending until a condition
>is
> satisfied or the device is removed. The driver's remove device routine
> completes the IRP with STATUS_CANCELLED. The user mode app then closes the
> handle. My expectation was that the driver unload routine would be invoked
> at
> this point, but I'm not seeing that happen. Is this expected behavior or
> do I
> have a bug?
>
> Mike