阅读:1752回复:3
ZwClose()会导致线程挂起?
各位高手请教一下:
nStatus=ZwClose(hDisk); if(NT_SUCCESS(nStatus)) { KdPrint(("Close Success\n")); } else { KdPrint(("Close Failed nStatus=%X\n",nStatus)); } 我的驱动执行到这里 nStatus=ZwClose(hDisk); 就挂住了,不再往下执行了,这是为什么? |
|
沙发#
发布于:2008-10-30 14:23
我的完整程序如下:
BOOLEAN HideFileGetDiskType(IN PUNICODE_STRING puStrLinkName) { OBJECT_ATTRIBUTES ObjAtr; HANDLE hDisk; IO_STATUS_BLOCK IoStatus; BOOLEAN bIsRemovable=FALSE; NTSTATUS nStatus; KdPrint(("===>HideFileGetDiskType")); InitializeObjectAttributes( &ObjAtr, puStrLinkName, OBJ_CASE_INSENSITIVE, NULL, NULL); nStatus=ZwCreateFile( &hDisk, GENERIC_ALL, &ObjAtr, &IoStatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_OPEN, FILE_WRITE_THROUGH,//FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0); if(NT_SUCCESS(nStatus)) { GET_MEDIA_TYPES mty; IO_STATUS_BLOCK IoStatus; mty.DeviceType=FILE_DEVICE_DISK; nStatus=ZwDeviceIoControlFile( hDisk, NULL, NULL, NULL, &IoStatus, IOCTL_STORAGE_GET_MEDIA_TYPES_EX, NULL, 0, &mty, sizeof(mty)); KdPrint(("ZwDeviceIoControlFile: nStatus=%X\n",IoStatus.Status)); if(!NT_SUCCESS(nStatus)) { KdPrint(("DevIOCTL Failed nStatus=%X\n",nStatus)); } else { if(mty.MediaInfo[0].DeviceSpecific.DiskInfo.MediaType==RemovableMedia) { bIsRemovable=TRUE; KdPrint(("Is Removable\n")); } else { KdPrint(("Is Fixed\n")); } } nStatus=ZwClose(hDisk); if(NT_SUCCESS(nStatus)) { KdPrint(("Close Success\n")); } else { KdPrint(("Close Failed nStatus=%X\n",nStatus)); } } else { KdPrint(("Faile to get dev nStatus=%X\n",nStatus)); } KdPrint(("<===HideFileGetDiskType")); return bIsRemovable; } 运行结果: 00000030 30.09598541 LinkName=\??\STORAGE#RemovableMedia#7&25842618&0&RM#{53f5630d-b6bf-11d0-94f2-00a0c91efb8b} 00000031 30.09601212 ===>HideFileGetDiskType 00000032 38.23619080 ZwDeviceIoControlFile: nStatus=0 00000033 38.23622131 Is Removable |
|
板凳#
发布于:2008-10-30 17:07
我跟踪了他的汇编代码,是在等待一个信号量,所以挂起的,不知是为什么?
|
|
地板#
发布于:2008-11-03 10:29
这样看来应该是他的驱动里处理IRP_MJ_CLOSE的问题,不是你的驱动的问题。
|
|
|