Sending SRB requests using KMDF APIs

Hello
Is it possible to send SRB requests using KMDF APIs? I’m always getting BSOD for invalid pointer access in storage driver below.
Here are more details…

I have a disk class lower filter driver implemented using KMDF framework. In this driver, at some point I want to read some block on the disk. Since its lower filter, I need to use SRB requests. I follow below steps to do this

  1. Create new wdfmemory for SRB requests and initialize all parameters in it including CDB10 etc. Init memory descriptor for this.
  2. create new WdfRequest for the target
  3. Get IRP pointer for wdfrequest. Set it in srb->OriginalRequest.
  4. Allocate buffer to read data. Get new MDL for the buffer, specify IRP from #3
  5. Send request down using WdfIoTargetSendInternalIoctlOthersSynchronously() with passing memory descriptor in #1 as OtherArg1 and others as NULL.

What I observed is that the KMDF in WdfIoTargetSendInternalIoctlOthersSynchronously() at some point it calls FxRequestContext::ReleaseAndRestore() in which it frees up IRP and MDLs allocated for this request. This is before sending request down/completion. Due to this driver below when try to access IRP or MDL it crashes.
Not sure why it frees up that requests context.

Also, if create IRP and send it WDM way using IoCallDriver(), it can read the data successfully.

Thanks.
Rohan

Any brief or detail information on this?

Thanks
Rohan

What do you have set as the parent of the WDF Objects you create?

Could that be causing the destruction you’re seeing?

Peter

It was DriverObject. But I did not see any code in KMDF that checks for parent object before cleaning up.
Thanks
Rohan