I noted a very common pattern/technique in the DDK sample code:
In a dispatch routine for IRPs like IRP_MN_START_DEVICE, you initilize
an event on the stack that the completion routine is supposed to set.
After the call to the lower driver you wait on that event:
status = IoCallDriver(deviceExtension->NextLowerDriver, pIrp);
// MS: Wait for lower drivers to be done with the pIrp.
// Important thing to
// note here is when you allocate memory for an event in the stack
// you must do a KernelMode wait instead of UserMode to prevent
// the stack from getting paged out.
if(status == STATUS_PENDING)
status = pIrp->IoStatus.Status;
You probably have seen this technique.
What I don't understand is what prevents the stack from being paged out
by the time the completion code tries to set the event if that happens
before the KeWait...() is reached. The only resolution I see is if it is
guaranteed that the completion thread is the same thread of the dispatch
routine (but then why bother with events at all...).
What am I missing?