I am generating an IRP to send to the next lower driver using IoBuildDeviceIoControlRequest with the following code:
KSPROPERTY* pProp;
pProp = (KSPROPERTY*)ExAllocatePoolWithTag(NonPagedPool, sizeof(KSPROPERTY), ‘prIl’);
pProp->Set = KSPROPSETID_Topology;
pProp->Id = KSPROPERTY_TOPOLOGY_NODES;
pProp->Flags = KSPROPERTY_TYPE_GET;
// Allocate output buffer
ULONG uOutBufSize = 2000;
BYTE* pOutBuf = (BYTE*)ExAllocatePoolWithTag(NonPagedPool, uOutBufSize, ‘prIl’);
// Event we must supply and wait on if the lower driver returns a pending status
KEVENT ev;
KeInitializeEvent(&ev, NotificationEvent, FALSE);
IO_STATUS_BLOCK iosb;
// Build the Irp
PIRP pRequest = IoBuildDeviceIoControlRequest(
IOCTL_KS_PROPERTY
, pLowerDevice
, (PVOID)pProp
, sizeof(KSPROPERTY)
, (PVOID)pOutBuf
, uOutBufSize
, FALSE
, &ev
, &iosb);
// Set the target FileObject to the filter we are querying
PIO_STACK_LOCATION pStack = IoGetNextIrpStackLocation(pRequest);
pStack->FileObject = pFileObject;
// Pass the request to the next lowest device
NTSTATUS status = IoCallDriver(pLowerDevice, pRequest);
if (status == STATUS_PENDING) {
KeWaitForSingleObject(&ev, Executive, KernelMode, FALSE, NULL);
}
— some trivial logic concerning the output buffer —
IoCompleteRequest(pRequest, IO_NO_INCREMENT);
When I complete the request as per the documentation for IoBuildDeviceIoControlRequest I get a bugcheck:
PAGE_FAULT_IN_FREED_SPECIAL_POOL (cc)
Stepping through with windbg I see that the IRP I have created becomes invalid memory immediately after the call to IoCallDriver. This is why I am assuming that the call to IoCompleteRequest is crashing. But is this expected? I thought it was my responsibility to complete the IRP?
Cheers,
BJW