Hello,
I erroneously posted this to microsoft.public.win32.programmer.kernel, I
thought I were in this group here, so please excuse if you get multiple
copies of this.
In Walter Oney's book, chapter 6, Walter shows a HandleQueryStop()
function which can be used by the PNP management stuff
(IRP_MN_QUERY_STOP_DEVICE). This can be found on page 323 (2nd edition)
or 241 (1st edition).
I hope I can give the code here:
(1) if (pdx->state != WORKING)
(2) return DefaultPnpHandler(fdo, Irp);
(3) if (!OkayToStop(pdx))
(4) return CompleteRequest(Irq, STATUS_UNSUCCESSFUL, 0);
(5) StallRequests(&pqx->dqReadWrite);
(6) WaitForCurrentIrp(&pdx->dqReadWrite);
(7) pdx->state = PENDINGSTOP;
(8) return DefaultPnpHandler(fdo, Irq);
I ask myself why (5) does not need to be issued before (3), and undone
if (4) is executed? An OkayToStop() function might return an Ok which is
not true anymore when 5 is executed, can't it?
I think about a scenario with two CPUs where one CPU has justed picked
an IRP to execute at the point of time when (3) is executed on the other
CPU. Before (5) can be executed, the 2nd CPU has begun executing the IRP
which results in putting the driver in a state where it cannot be
stopped afterwards (for example, a REWIND operation for a tape), where
another IRP has to be executed to undo this effect.
Am I missing something important here, or this this a bug in the code?
Kind regards,
Spiro.
--
Spiro R. Trikaliotis
http://www.trikaliotis.net/