我是初学者,正在学习异步读写设备,发现执行到KdPrint(("Other Diapatch!\n"))时,系统就会崩溃,windbug提示A fatal system error has occurred.
Debugger entered on first try; Bugcheck callbacks have not been invoked.经多次测试发现是由于派遣函数HelloDDKCleanUp中的ULONG ulReadOffset = (ULONG)stack->Parameters.Read.ByteOffset.QuadPart;语句引起的,删除这句话就没事,搞不清什么原因,猜测可能是非法访问造成的。烦请各位大牛帮忙看看,非常感谢.程序结构很简单,就是先将read、write的irp保存到设备扩展中,集中到设备关闭时异步处理.
NTSTATUS HelloDDKDispatchRoutine(IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp)
{
KdPrint(("Other Diapatch!\n")); NTSTATUS status = STATUS_SUCCESS;
pIrp->IoStatus.Status = status;
pIrp->IoStatus.Information = 0;
IoCompleteRequest(pIrp,IO_NO_INCREMENT);
KdPrint(("Leave HelloDDKDispatchRoutine\n"));
return status;
}
NTSTATUS HelloDDKCleanUp(IN PDEVICE_OBJECT pDevObj,
IN PIRP pIrp)
{
KdPrint(("Enter HelloDDKCleanUp\n"));
PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION)
pDevObj->DeviceExtension;
//(1)将存在队列中的IRP逐个出队列,并处理
PMY_IRP_ENTRY my_irp_entry;
while(!IsListEmpty(pDevExt->pIRPLinkListHead))
{
PLIST_ENTRY pEntry = RemoveHeadList(pDevExt->pIRPLinkListHead);
my_irp_entry = CONTAINING_RECORD(pEntry,
MY_IRP_ENTRY,
ListEntry);
PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(my_irp_entry->pIRP);
if (stack->MajorFunction == IRP_MJ_READ)
{
KdPrint(("Complete HelloDDKRead\n"));
PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION)pDevObj->DeviceExtension;
NTSTATUS status = STATUS_SUCCESS;
ULONG ulReadLength = stack->Parameters.Read.Length;
ULONG ulReadOffset = (ULONG)stack->Parameters.Read.ByteOffset.QuadPart;
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!