阅读:1367回复:4
请高手们看看我的这段代码,帮忙指出他的致命错误在哪
我最近刚开始学驱动设计,写了一个小程序,编译没有错误,装载到系统之后系统马上会蓝屏(winxp),提示beginning dump of physicy memory,错误信息是 0x0000007e(0xc0000005,0x805b639c,0xf9e78864,0xf9e78560) 其他例如驱动装入基值没有告诉,代码如下:
/**************** wmd.c ******************/ #define INITGUID #include \"wdm.h\" #include \"mywdm.h\" /*包含了扩展对象的定义*/ #include \"guid.h\" NTSTATUS MyWdmAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT pdo); void MyWdmUnload(IN PDRIVER_OBJECT DriverObject); NTSTATUS MyWdmCreate(IN PDEVICE_OBJECT fdo, IN PIRP irp); NTSTATUS MyWdmClose(IN PDEVICE_OBJECT fdo, IN PIRP irp); NTSTATUS MyWdmWrite(IN PDEVICE_OBJECT fdo, IN PIRP irp); NTSTATUS MyWdmRead(IN PDEVICE_OBJECT fdo, IN PIRP irp); #pragma code_seg(\"INIT\") NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegPath) { NTSTATUS status=STATUS_SUCCESS; DriverObject->DriverExtension>AddDevice=MyWdmAddDevice; DriverObject->DriverUnload=MyWdmUnload; DriverObject->MajorFunction[IRP_MJ_CREATE]=MyWdmCreate; DriverObject->MajorFunction[IRP_MJ_CLOSE]=MyWdmClose; DriverObject->MajorFunction[IRP_MJ_WRITE]=MyWdmWrite; DriverObject->MajorFunction[IRP_MJ_READ]=MyWdmRead; return(status); } #pragma code_seg() #pragma code_seg(\"PAGE\") NTSTATUS MyWdmAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT pdo) { NTSTATUS status=STATUS_SUCCESS; PDEVICE_OBJECT fdo; PMyDeviceExtension dx; status=IoCreateDevice(DriverObject, sizeof(MyDeviceExtension), NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &fdo); if (!NT_SUCCESS(status)) { IoDeleteDevice(fdo); return(status); } dx=(MyDeviceExtension *)fdo->DeviceExtension; status=IoRegisterDeviceInterface(pdo, &MYGUID, NULL, dx->ifSysLinkName); if (!NT_SUCCESS(status)) { IoDeleteDevice(fdo); return(status); } status=IoSetDeviceInterfaceState(dx->ifSysLinkName, TRUE); if (!NT_SUCCESS(status)) { IoDeleteDevice(fdo); return(status); } dx->NextStackDevice=IoAttachDeviceToDeviceStack(fdo, pdo); fdo->Flags&=~DO_DEVICE_INITIALIZING ; fdo->Flags|=DO_BUFFERED_IO ; return(status); } void MyWdmUnload(IN PDRIVER_OBJECT DriverObject) { PMyDeviceExtension dx; dx=(PMyDeviceExtension)DriverObject->DeviceObject->DeviceExtension; RtlFreeUnicodeString(dx->ifSysLinkName); IoDetachDevice(dx->NextStackDevice); } NTSTATUS MyWdmCreate(IN PDEVICE_OBJECT fdo, IN PIRP irp) { NTSTATUS status=STATUS_SUCCESS; PMyDeviceExtension dx; dx=(PMyDeviceExtension)fdo->DeviceExtension; dx->data=0; IoCompleteRequest(irp, IO_NO_INCREMENT); return(status); } NTSTATUS MyWdmClose(IN PDEVICE_OBJECT fdo, IN PIRP irp) { NTSTATUS status=STATUS_SUCCESS; IoCompleteRequest(irp, IO_NO_INCREMENT); return(status); } NTSTATUS MyWdmWrite(IN PDEVICE_OBJECT fdo, IN PIRP irp) { NTSTATUS status=STATUS_SUCCESS; int * buffer; PMyDeviceExtension dx=(PMyDeviceExtension)fdo->DeviceExtension; buffer=(int *)irp->AssociatedIrp.SystemBuffer; dx->data+=(* buffer); if (dx->data >= 10000) { dx->data=0; } IoCompleteRequest(irp, IO_NO_INCREMENT); return(status); } NTSTATUS MyWdmRead(IN PDEVICE_OBJECT fdo, IN PIRP irp) { NTSTATUS status=STATUS_SUCCESS; PMyDeviceExtension dx; int * buffer; dx=(PMyDeviceExtension)fdo->DeviceExtension; buffer=(int *)irp->AssociatedIrp.SystemBuffer; (* buffer)=dx->data; IoCompleteRequest(irp, IO_NO_INCREMENT); return(status); } #pragma code_seg() |
|
沙发#
发布于:2005-04-08 23:05
你有什么调试工具吗?softice之类的
|
|
板凳#
发布于:2005-04-09 00:17
我有阿,我安装了driverStudio,有softice
|
|
地板#
发布于:2005-04-09 02:22
试这个如没问题,再加上自己所写的,一步步找就知错误在哪 !
#include <ntddk.h> |
|
地下室#
发布于:2005-04-09 09:51
试这个如没问题,再加上自己所写的,一步步找就知错误在哪 ![/quote] KMK大虾所言极是,一口吃个胖子就是这滋味 |
|
|