阅读:1384回复:1
版主大神,请帮忙看一下,谢谢了
问题如下,我手动创建的IRP去调用另一个驱动程序,总是蓝屏。用同步去调用就没有问题,异步就有问题。目的驱动是没有问题的。
部分代码如下: NTSTATUS ntStatus = STATUS_SUCCESS; UNICODE_STRING DeviceName; RtlInitUnicodeString( &DeviceName, L"\\Device\\MyDDKDeviceA" ); PDEVICE_OBJECT DeviceObject = NULL; PFILE_OBJECT FileObject = NULL; //得到设备对象指针 ntStatus = IoGetDeviceObjectPointer(&DeviceName,FILE_ALL_ACCESS,&FileObject,&DeviceObject); KdPrint(("DriverB:FileObject:%x\n",FileObject)); KdPrint(("DriverB:DeviceObject:%x\n",DeviceObject)); if (!NT_SUCCESS(ntStatus)) { KdPrint(("DriverB:IoGetDeviceObjectPointer() 0x%x\n", ntStatus )); ntStatus = STATUS_UNSUCCESSFUL; // 完成IRP pIrp->IoStatus.Status = ntStatus; pIrp->IoStatus.Information = 0; // bytes xfered IoCompleteRequest( pIrp, IO_NO_INCREMENT ); KdPrint(("DriverB:Leave B HelloDDKRead\n")); return ntStatus; } KEVENT event; KeInitializeEvent(&event,NotificationEvent,FALSE); IO_STATUS_BLOCK status_block; LARGE_INTEGER offsert = RtlConvertLongToLargeInteger(0); //创建异步IRP PIRP pNewIrp = IoBuildAsynchronousFsdRequest(IRP_MJ_READ, DeviceObject, NULL,0, &offsert,&status_block); KdPrint(("pNewIrp->UserEvent :%x\n",pNewIrp->UserEvent)); //设置pNewIrp->UserEvent,这样在IRP完成后可以通知该事件 pNewIrp->UserEvent = &event; KdPrint(("DriverB:pNewIrp:%x\n",pNewIrp)); PIO_STACK_LOCATION stack = IoGetNextIrpStackLocation(pNewIrp); stack->FileObject = FileObject; NTSTATUS status = IoCallDriver(DeviceObject,pNewIrp); if (status == STATUS_PENDING) { status = KeWaitForSingleObject( &event, Executive, KernelMode, FALSE, // Not alertable NULL); status = status_block.Status; } ZwClose(FileObject); |
|
沙发#
发布于:2013-04-19 10:59
看一下寒江独钓的例子
|
|
|