[wdmaudiodev] Re: About Unload in MSVAD

  • From: Ken Cooper <Ken.Cooper@xxxxxxxxxxxxx>
  • To: "wdmaudiodev@xxxxxxxxxxxxx" <wdmaudiodev@xxxxxxxxxxxxx>
  • Date: Thu, 12 Mar 2009 14:19:43 -0700

In general terms, the information provided on this thread has been correct.  
You can override the portcls IRP dispatchers after calling 
PcInitializeAdapterDriver().  For the DriverUnload routine, you need to save 
the previous one and call it at the end of your unload routine.  For the others 
that you have shown, you can do what you're doing (without saving the old 
values) provided that you pass the IRPs to portcls via PcDispatchIrp().

So what is your application here?  It looks like you're attempting to create a 
child device off of main device object (hence, creating/deleting your own 
device and wanting to intercept the IRPs).  Perhaps there's a simpler way to 
accomplish what you're trying to do.

Best Regards,

Ken

From: wdmaudiodev-bounce@xxxxxxxxxxxxx 
[mailto:wdmaudiodev-bounce@xxxxxxxxxxxxx] On Behalf Of Tim Roberts
Sent: Thursday, March 12, 2009 10:05 AM
To: wdmaudiodev@xxxxxxxxxxxxx
Subject: [wdmaudiodev] Re: About Unload in MSVAD

karthiksharmasg@xxxxxxx<mailto:karthiksharmasg@xxxxxxx> wrote:

     i am working on XP, and i have a pointer to my unload routine defined in 
the DRIVERENTRY like this
...
DriverEntry
{
.....
ntStatus =
        PcInitializeAdapterDriver
..
if (NT_SUCCESS(ntStatus)) // if PcInitializeAdapterDriver is successfull
 {
  pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = MExtender_IoControl;
  pDriverObject->MajorFunction[IRP_MJ_CREATE] = MExtender_Create;
  pDriverObject->MajorFunction[IRP_MJ_WRITE] = MExtender_Write;
  pDriverObject->MajorFunction[IRP_MJ_READ] = MExtender_Read;
  pDriverObject->MajorFunction[IRP_MJ_CLOSE] = MExtender_Close;
  pDriverObject->DriverUnload = MExtender_Unload;
 }
..
VOID
MExtender_Unload
..
RtlInitUnicodeString(&uniDOSString, s_wcMEDOSNameBuffer);
IoDeleteSymbolicLink(&uniDOSString);
IoDeleteDevice(pDriverObject->DeviceObject);
.......
}


i have created an device  in add device like this after the PcAddAdapterDevice

You have created an incredibly tangled and confusing mishmash of different 
driver architectures here.  I'm not at all surprised that it doesn't work.

Think about what PcInitializeAdapterDriver does.  It sets up some state data in 
your driver extension, and then it sets up the dispatch table in the driver 
object so it can process the incoming IRPs, and call your KS callback functions 
to process them.  What's the first thing you do?  You override all of its 
dispatch functions with your own!  As a result, neither the PortClass driver 
nor the KS driver underneath it is ever going to see any IRPs.  None of the KS 
functions or callbacks will work.

Then, you have an AddDevice handler, which makes you a plug-and-play driver, 
but your code shows that you are deleting a device object in the driver 
"unload" handler, which you would only do in a non-PnP driver.  With a PnP 
driver, the driver cannot be unloaded as long as there is a device object 
outstanding.  If you don't delete the device object until the unload function, 
your unload function will never be called.  In a WDM driver, you delete the 
device object during IRP_MN_REMOVE_DEVICE processing, and that deletion 
triggers the unload.  During the unload time, there ARE no device objects left. 
 In a KS driver, however, the KS framework handles this for you.

You really need to take a big step back from the keyboard, spend some time with 
a whiteboard, and figure out what kind of a driver this really is.  You seem to 
be hacking away at something here without really knowing what you are creating.


--

Tim Roberts, timr@xxxxxxxxx<mailto:timr@xxxxxxxxx>

Providenza & Boekelheide, Inc.

Other related posts: