I/O Manager related query

Hi,
I have a WDM driver on Windows 2000 that exposes 2 device objects. One
is part of the device stack and the other (secondary device object) is for
my application to communicate with my driver directly through symbolic link.

The driver is for a PCMCIA modem.

When I remove the modem from the system, my driver gets a SURPRISE_REMOVAL
IRP. If the primary device object that is part of the device stack has a
pending reference count in the form of an open application handle,
REMOVE_DEVICE IRP is held back till the application closes the handle.

I have two cases.

  1. If I have an open application handle for the secondary device object when
    the device is removed, and I delete both the primary and secondary device
    objects as part of the REMOVE_DEVCICE IRP, the DriverUnLoad routine gets
    called even though the secondary device object has a pending reference count
    in the form of an application handle. Any further requests from the
    application to the secondary driver object crashes my driver (I am not able
    to understand how the I/O Manager is able to pass the requests to the
    secondary device object even after it has called my DriverUnLoad routine).

  2. If I defer the deletion of my secondary device object to the IRP_MJ_CLOSE
    handler so that the open handle is removed, the DriverUnLoad routine doesn’t
    get called at all. If I insert the modem once again, I get an AddDevice call
    directly without the DriverEntry call thereby proving that the DriverUnLoad
    routine didn’t get called in the previous instance. I actually even set a
    break point in the DriverUnLoad routine using softice and verified this
    case.

What could be the reason behind this behaviour?

I guess I have tried to combine the PnP based WDM driver and a Legacy
driver. The Primary device object is following the WDM approach and the
Secondary device object is following a Legacy driver approach.

Doesn’t the I/O Manager check for the reference count of the Device Object
and the Driver Object in the 2nd case? If it had checked the reference count
for the Driver Object in the 2nd case I have described, it should have
called the DriverUnLoad routine when the secondary device object associated
with this driver object is deleted. This is not happening as per this
assumption.

Can anyone clarify why this is happening? Is this approach of having one
device object that doesn’t attach to my device stack correct? Should I
implement this as a filter driver - function driver pair in order to avoid
such problems?

Sorry for the long mail as I had to explain all the cases.

Thanks & Regards,
S.Balaji

***********************************************************************
Disclaimer:
This document is intended for transmission to the named recipient only. If
you are not that person, you should note that legal rights reside in this
document and you are not authorized to access, read, disclose, copy, use or
otherwise deal with it and any such actions are prohibited and may be
unlawful. The views expressed in this document are not necessarily those of
HCL Technologies Ltd. Notice is hereby given that no representation,
contract or other binding obligation shall be created by this e-mail, which
must be interpreted accordingly. Any representations, contractual rights or
obligations shall be separately communicated in writing and signed in the
original by a duly authorized officer of the relevant company.
***********************************************************************


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

“Balaji Swaminathan - CTD, Chennai.” wrote in
message news:xxxxx@ntdev…
>
> What could be the reason behind this behaviour?
>
> I guess I have tried to combine the PnP based WDM driver and a Legacy
> driver. The Primary device object is following the WDM approach and the
> Secondary device object is following a Legacy driver approach.
>

This is really an excellent question, and very well explained. Like you, I
would have assumed that I wouldn’t get an Unload call whilst I had a active
ref to ANY of my device objects. And I’d assume, as you mention, that if
you defer the delete until the close of your “secondary” device object that
you would THEN get the unload call.

Very cool. I bet this is an unforseen case in the I/O Manager…

Anybody have any answer for this?

Please let me know how this turns out,

Peter
OSR


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> Hi,

I have a WDM driver on Windows 2000 that exposes 2 device objects. One
is part of the device stack and the other (secondary device object) is for
my application to communicate with my driver directly through symbolic link.

Why not send your IOCTLs to the first device object instead of creating the second?

Max


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi,

I cannot give you a reason why this is happening but I once solved this
without needing to write full bus-driver (it was quite some time ago so
forgive me, if I get some details wrong), which obviosly would be the
academic answer to this problem. I tried solving this by adding some extra
references to my device-stack device-object and all kind of little things
like that but nothing seemed to work so I came up with this hack.

I once had a device, which is a modem but it also is something totally
different. What happens in Win2000 is that all PCMCIA-modem (I guess this is
true to all modem devices) are lower-filter-drivers for the real
modem-driver (modem.sys), which makes it impossible to get direct
connections to it. Modem.sys gets all IRPs first and it doesn’t allow more
than one connection at the time. This means that only way to bypass this is
to create a secondary device object, which can handle all the non-modem
requests.

What I basically did was:

  • In AddDevice I created the two device object, one for the real device
    stack and one for non-modem stuff. Also event needs to be created so that
    you can synchronize the removal of the device (I should be signaled in the
    beginning)

  • When non-modem user-mode service-starts and opens handle to my device, the
    removal event should be cleared (you can see who is openning your device by
    comparing the device-objects that are being used).

  • If the card is removed while non-modem service has handle to the device,
    the device driver should wait in KeWaitForSingleObject at the
    IRP_MN_REMOVE_DEVICE or/and IRP_MN_SURPRISE_REMOVAL (in Win2000 you will get
    the IRP_MN_REMOVE_DEVICE after this so I guess waiting in this is optional)
    for the signalling the removal event. You might need to come up with some
    way to signal the your user-mode application to close its handle, when the
    device is removed. You need to have some propriatery way to do this because
    your device won’t get any of the ordinary device removal events as this
    device-object is not part of the legimate device-stack.

This worked pretty well for my own “do it in my own time just for fun
R&D-project” but I wouldn’t introduce this trick in any real production
driver (and I never did). Having said that, my driver passes the driver
verifier tests and has survived a couple service packs so it cannot be that
bad hack :slight_smile:

The best way, of course, is to ask your hw-guys to come-up with real
multi-functional PCMCIA-card and make two separate drivers for it. The next
best option is to write bus-driver for your device and two device drivers
that are attached to it (you need to have one of these options if you want
to pass WHQL but this might take a couple extra weeks to do).

I hope this made some sense to some of you and hopefully gave some ideas how
to overcome these kind of problems.

Best Regards, Mikko

Mikko Jaakkola
Nokia Mobile Phones / Special Products
Tel: +358(0)50 5816945 Fax: +358(0)3 3183690
Email: xxxxx@nokia.com

-----Original Message-----
From: ext Balaji Swaminathan - CTD, Chennai.
[mailto:xxxxx@ctd.hcltech.com]
Sent: 1. marraskuuta 2001 16:41
To: NT Developers Interest List
Subject: [ntdev] I/O Manager related query

Hi,
I have a WDM driver on Windows 2000 that exposes 2 device objects. One
is part of the device stack and the other (secondary device object) is for
my application to communicate with my driver directly through symbolic link.

The driver is for a PCMCIA modem.

When I remove the modem from the system, my driver gets a SURPRISE_REMOVAL
IRP. If the primary device object that is part of the device stack has a
pending reference count in the form of an open application handle,
REMOVE_DEVICE IRP is held back till the application closes the handle.

I have two cases.

  1. If I have an open application handle for the secondary device object when
    the device is removed, and I delete both the primary and secondary device
    objects as part of the REMOVE_DEVCICE IRP, the DriverUnLoad routine gets
    called even though the secondary device object has a pending reference count
    in the form of an application handle. Any further requests from the
    application to the secondary driver object crashes my driver (I am not able
    to understand how the I/O Manager is able to pass the requests to the
    secondary device object even after it has called my DriverUnLoad routine).

  2. If I defer the deletion of my secondary device object to the IRP_MJ_CLOSE
    handler so that the open handle is removed, the DriverUnLoad routine doesn’t
    get called at all. If I insert the modem once again, I get an AddDevice call
    directly without the DriverEntry call thereby proving that the DriverUnLoad
    routine didn’t get called in the previous instance. I actually even set a
    break point in the DriverUnLoad routine using softice and verified this
    case.

What could be the reason behind this behaviour?

I guess I have tried to combine the PnP based WDM driver and a Legacy
driver. The Primary device object is following the WDM approach and the
Secondary device object is following a Legacy driver approach.

Doesn’t the I/O Manager check for the reference count of the Device Object
and the Driver Object in the 2nd case? If it had checked the reference count
for the Driver Object in the 2nd case I have described, it should have
called the DriverUnLoad routine when the secondary device object associated
with this driver object is deleted. This is not happening as per this
assumption.

Can anyone clarify why this is happening? Is this approach of having one
device object that doesn’t attach to my device stack correct? Should I
implement this as a filter driver - function driver pair in order to avoid
such problems?

Sorry for the long mail as I had to explain all the cases.

Thanks & Regards,
S.Balaji

***********************************************************************
Disclaimer:
This document is intended for transmission to the named recipient only. If
you are not that person, you should note that legal rights reside in this
document and you are not authorized to access, read, disclose, copy, use or
otherwise deal with it and any such actions are prohibited and may be
unlawful. The views expressed in this document are not necessarily those of
HCL Technologies Ltd. Notice is hereby given that no representation,
contract or other binding obligation shall be created by this e-mail, which
must be interpreted accordingly. Any representations, contractual rights or
obligations shall be separately communicated in writing and signed in the
original by a duly authorized officer of the relevant company.
***********************************************************************


You are currently subscribed to ntdev as: xxxxx@nokia.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com