[wdmaudiodev] Re: About Unload in MSVAD

  • From: Tim Roberts <timr@xxxxxxxxx>
  • To: wdmaudiodev@xxxxxxxxxxxxx
  • Date: Thu, 12 Mar 2009 10:05:03 -0700

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
Providenza & Boekelheide, Inc.

Other related posts: