[wdmaudiodev] Re: streamclass USB surprise removal problem: help please

  • From: "Philip Lukidis" <pagefault0x0@xxxxxxxxxxx>
  • To: <wdmaudiodev@xxxxxxxxxxxxx>
  • Date: Tue, 15 Apr 2003 09:16:06 -0400

Hi John, thanks for you reply.  I'll tell you what I'm currently doing, and
if you have time and some insight, an answer would much appreciated.

Before I start, I'd just like to say that while MIDI capture is active, I
have received 2-3 IRP_MJ_CREATE calls.  By the time I get
IRP_MN_REMOVE_DEVICE, there is one outstanding IRP_MJ_CLEANUP/CLOSE call.
I'll return to this below.

First of all, I installed my IRP handlers, overriding stream class'.  All
except PnP and IRP_MJ_DEVICE_CONTROL are empty shells.  The
IRP_MJ_DEVICE_CONTROL handler completes all IRPs sent to stream.sys which
target my device with STATUS_DELETE_PENDING (STATUS_DEVICE_REMOVED does not
exist in 98 DDK).

If I do call stream.sys' PnP handler for IRP_MN_REMOVE_DEVICE, then I get
SRB_SURPRISE_REMOVAL.  However, surprise surprise, when I complete all of my
SRBs (following the details you mentioned) the system seems to freeze.  Upon
close inspection the system is not truly frozen.  I am still getting
IRP_MJ_DEVICE_CONTROL IRPs which I complete with STATUS_DELETE_PENDING.
Now, eventually the SRB_SURPRISE_REMOVAL times out, and thereafter I get a
fault in _VWIN32_CloseVxDHandle.  If I set no timeout in this SRB, then the
system freezes indefinitely.  So much for letting stream.sys handle removal.

HOWEVER, if I do NOT call stream.sys' handler for IRP_MN_REMOVE_DEVICE, I
handle the stack tear down myself.  I clean up, and detach myself from the
stack, and delete the class DEVICE_OBJECT.  After I call IoDetachDevice, a
worker thread immediately calls my Unload routine.  Within the Unload
routine, I delete the adapter.  If before deleting the adapter I try to
complete all SRBs, the system seems to freeze.  In reality it is still
sending down IRP_MJ_DEVICE_CONTROL IRPs (which I complete repeatedly with
STATUS_DELETE_PENDING).  If I do NOT complete the SRBs, the driver unloads
(at least according to SoftICE driver command).  However, the shell is
frozen.  I can still move my mouse, but the shell seems extremely lagged.

My theory at this point is that the problem is the outstanding reference to
the class DEVICE_OBJECT. In NT, we would never get IRP_MN_REMOVE_DEVICE if
there was a reference, but in P!S Win9x/(me?) we do...

So, I will construct IRP_MJ_CLEANUP and IRP_MJ_CLOSE IRPs and send them to
sysaudio.sys.  I'll see what happens then, and let you know.

Philip Lukidis

----- Original Message -----
From: "John Brinkman" <john@xxxxxxxxx>
To: <wdmaudiodev@xxxxxxxxxxxxx>
Sent: Monday, April 14, 2003 8:00 PM
Subject: [wdmaudiodev] Re: streamclass USB surprise removal problem: help
please


>
> Hi Philip,
>
> I'm not an expert and I can't specifically answer any of your questions,
so
> I will simply explain how I handle a removal IRP and with any luck I wont
> mislead you or waste your time.
>
> When my stream class driver receives a surprise removal IRP, and one of my
> MIDI pins is open I will:
>
> 1) Any new control or stream requests are completed with
> STATUS_DEVICED_REMOVED.
>
> 2) I force my open pins back to KSSTATE_STOP performing any cleanup work
> that is done when translating from RUN to STOP under normal conditions.  I
> force the KStream base class back to KSSTATE_STOP by accessing its member
> m_eState (KStream::m_eState = KSSTATE_STOP) and then I complete any
pending
> SRBs in my queues with STATUS_CANCELLED.  I also "religiously" (because I
> don't remember why) set both the
Srb->CommandData.DataBufferArray->DataUsed
> and Irp->IoStatus.Information fields to zero.
>
> Once all that is done I complete the removal IRP with STATUS_SUCCESS.
>
> Good luck,
> -John
>
> ----- Original Message -----
> From: "pagefault 0x0" <pagefault0x0@xxxxxxxxxxx>
> To: <wdmaudiodev@xxxxxxxxxxxxx>
> Sent: Sunday, April 13, 2003 10:44 AM
> Subject: [wdmaudiodev] streamclass USB surprise removal problem: help
please
>
>
> >
> >
> > Hello!
> >
> > I know that this is Win98SE question, and that this is an NT based list,
> but
> > my USB stream class MIDI driver is WDM, so I hope I'm not too far off
> topic.
> > While this driver has been made with DriverWorks (not by me- I'm the
lucky
> > debugger), I have been reading about stream class in the DDK, and take
> > nothing for granted in the DriverWorks libraries (seen some questionable
> > things in there!).  So let's forget about DriveWorks, and talk in plain
> old
> > WDM/streamclass language.  I'm away from my source and the DDK headers,
so
> > apologies if I have mispelled some DDK/streamclass constants.  As
stated,
> > this question concerns Win98SE, and it also has the WDM audio QFE
> installed.
> > The driver is MIDI in/out USB bulk driver.
> >
> > My problem is this: my stream class MIDI driver freezes the system, or
> BSODs
> > in _VWIN32_CloseVxDHandle on surprise removal.  Here's the mystery: it
> does
> > not do this with each MIDI app (but all except MIDIOX), AND it works
fine
> > with for surprise removal with ALL apps under WinXP SP1 (except that
> stream
> > class BSODs under driver verifier when it completes some IRPs with
> > STATUS_PENDING!).  In Win98SE, I do get a SRB_SURPRISE_REMOVAL
associated
> > with IRP_MN_REMOVE_DEVICE (naturally).  I do wait for all my own created
> > IRPsto my device to come back up and I free them (I created them with
> > IoCreate Irp).  This is done in accordance to Walter Oney's cancel
> examples
> > in his 2ed book (Great book!  Can't survive without it!).  Then I
complete
> > all my queued SRBs with STATUS_CANCELLED.  Then, sometimes I get
> > SRB_CLOSE_STREAM, but NEVER SRB_UNINITIALIZE_DEVICE.  I have noted two
> > things:
> >
> > a) I have my IRP stream class interception handlers which allow me to
> check
> > what is going on before forwarding them to stream class.  I know, this
is
> > notfor production driver, only for debugging. I have seen that I
although
> I
> > get 3 IRP_MJ_CREATE to stream class, I *never* get 3
> > IRP_MJ_CLEANUP/IRP_MJ_CLOSE, but only 2.  Why  is this?  Can I send
these
> > IRPs myself to ks.sys?  If so, how can I find its DEVICE_OBJECT?  Why do
I
> > even get IRP_MN_REMOVE_DEVICE in this circumstance, with references on
my
> > class DEVICE_OBJECT??
> >
> > Sometimes, even though I received IRP_MN_REMOVE_DEVICE, I continue to
find
> > IRP_MJ_DEVICE_CONTROL IRPs being sent to stream.sys!!  If I have
received
> > remove IRP, I complete them with STATUS_DELETE_PENDING, but they keep on
> > coming!  Why?
> >
> > b) As I said, I do get SRB_SURPRISE_REMOVAL.  While I am stepping
through
> > this handler in SoftICE, I frequently get a freeze *before* I complete
the
> > SRB.  Later my timeout routine for this SRB is called, which confirms
that
> I
> > was never able to complete the SRB with the default timeout.  When I
> specify
> > NO timeout, the system freezes.  So I reasoned I am
preempted/interrupted.
> > So in my surprise removal handler, I did _asm cli, and balanced this
with
> > _asm sti after I completed the SRB (I know, never in a production
> > driver...).  This time I *always* complete the SRB, but later freeze or
> BSOD
> > in _VWIN32_CloseVxDHandle.  What would cause this?  Is this my interrupt
> on
> > my device?  When in my IRP interception functions, should I send the
> > IRP_MN_REMOVE_DEVICE right away down to the bus driver?  Any ideas on
> this??
> >
> >
> > Can anyone help me somewhat with my woes?  Thanks in advance.
> >
> > Philip Lukidis
> >
>
> --------------------------------------------------------------------------
> --
> > Add photos to your e-mail with MSN 8. [1]Get 2 months FREE*.
> >
> > --- Links ---
> >    1 http://g.msn.com/8HMRENCA/2746
> > ******************
> >
> > WDMAUDIODEV addresses:
> > Post message: mailto:wdmaudiodev@xxxxxxxxxxxxx
> > Subscribe:    mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=subscribe
> > Unsubscribe:
mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=unsubscribe
> > Moderator:    mailto:wdmaudiodev-moderators@xxxxxxxxxxxxx
> >
> > URL to WDMAUDIODEV page:
> > http://www.wdmaudiodev.de/
> >
> >
>
> ******************
>
> WDMAUDIODEV addresses:
> Post message: mailto:wdmaudiodev@xxxxxxxxxxxxx
> Subscribe:    mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=subscribe
> Unsubscribe:  mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=unsubscribe
> Moderator:    mailto:wdmaudiodev-moderators@xxxxxxxxxxxxx
>
> URL to WDMAUDIODEV page:
> http://www.wdmaudiodev.de/
>
>
******************

WDMAUDIODEV addresses:
Post message: mailto:wdmaudiodev@xxxxxxxxxxxxx
Subscribe:    mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=subscribe
Unsubscribe:  mailto:wdmaudiodev-request@xxxxxxxxxxxxx?subject=unsubscribe
Moderator:    mailto:wdmaudiodev-moderators@xxxxxxxxxxxxx

URL to WDMAUDIODEV page:
http://www.wdmaudiodev.de/

Other related posts: