Hello,
I have an existing driver wrote some years ago where I was getting a B8
BSOD because the driver tried to synchronize access to some internal
structures in a DPC thread during a completion routine.
I changed it so the completion routine now queues an work item using
IoQueueWorkItem
and I do my stuff in a lower IRQL where I am able to synchronize.
Now the B8 BSOD is gone, but I am getting eventually a
MULTIPLE_IRP_COMPLETE_REQUESTS BSOD and I don’t know why.
I am sending below part of the code I changed.
Does anynone can help me?
Thanks,
typedef struct {UCHAR Operation;PIRP Irp;PDEVICE_OBJECT Device;CAttachedDevice *AttachedDevice;} *PNGWORKITEM, NGWORKITEM;VOID ProcessWorkItem(PDEVICE_OBJECT DeviceObject, PVOID Context){LOG_TRACE_ENTERING;PNGWORKITEM ngWorkItem = (PNGWORKITEM)Context;if (ngWorkItem->Irp->PendingReturned) { IoMarkIrpPending(ngWorkItem->Irp); }PIO_STACK_LOCATION stackLocation =IoGetCurrentIrpStackLocation(ngWorkItem->Irp);// Create our IO request structure.IOReq* req = new (NonPagedPool) IOReq(ngWorkItem->Operation == 'R' ? REQ_READ : REQ_WRITE,ngWorkItem->Operation == 'R' ? stackLocation->Parameters.Read.Length :stackLocation->Parameters.Write.Length,(ULONG)ngWorkItem->Irp->IoStatus.Information,ngWorkItem->Irp->AssociatedIrp.SystemBuffer);// If it was possible to allocate an IO request, add it to the list.if (NULL != req) {ngWorkItem->AttachedDevice->New(req);}// Complete the request.IoCompleteRequest(ngWorkItem->Irp,IO_NO_INCREMENT);// Release the memory we allocated.ExFreePool(Context);LOG_TRACE_LEAVING_VOID;}NTSTATUS QueueWorkItem(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN UCHAR Operation,IN CAttachedDevice *CADevice){PIO_WORKITEM workItem = IoAllocateWorkItem(DeviceObject);if (NULL == workItem) {return STATUS_SUCCESS;}PNGWORKITEM ngWorkItem = (PNGWORKITEM)ExAllocatePool(NonPagedPool,sizeof(NGWORKITEM));if (NULL == ngWorkItem) {return STATUS_SUCCESS;}ngWorkItem->Device = DeviceObject;ngWorkItem->AttachedDevice = CADevice;ngWorkItem->Irp = Irp;ngWorkItem->Operation = Operation;IoQueueWorkItem(workItem,ProcessWorkItem,DelayedWorkQueue,ngWorkItem);return STATUS_MORE_PROCESSING_REQUIRED;}NTSTATUS ReadCompletion( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context){return QueueWorkItem(DeviceObject, Irp, 'R', (CAttachedDevice *)Context);}NTSTATUS WriteCompletion(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp,IN PVOID Context){return QueueWorkItem(DeviceObject, Irp, 'W', (CAttachedDevice *)Context);}NTSTATUS CAttachedDevice::Standard( /// I/O request packet identifier. PIRP Irp, /// Completion PIO_COMPLETION_ROUTINE Routine){ LOG_TRACE_ENTERING;// This function forwards the request. PIO_STACK_LOCATION curIRPStack, nextIRPStack;curIRPStack = IoGetCurrentIrpStackLocation(Irp); nextIRPStack = IoGetNextIrpStackLocation(Irp); *nextIRPStack = *curIRPStack;IoSetCompletionRoutine( Irp, (Routine) ? Routine : DefaultCompletion, this, TRUE, TRUE, TRUE);NTSTATUS status = IoCallDriver(OriginalDevice, Irp);LOG_TRACE_LEAVING_STATUS;return status;}
–
-George