驱动牛犊
|
阅读:3322回复:5
发生系统错误 1058
一个HelloWorld的驱动,用net start 服务名启动时提示:
发生系统错误 1058。 无法启动服务,原因可能是已被禁用或与其相关联的设备没有启动。 百思不得其解。从DbgView可以看出,DriverEntry确实执行了。 注册表信息如下: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UnicodeStr] "Type"=dword:00000001 "Start"=dword:00000003 "ErrorControl"=dword:00000001 "ImagePath"=hex(2):\??\T:\WAVMOQ\objchk\i386\UnicodeStr.sys "DisplayName"="UnicodeStr测试程序" "Description"="测试UnicodeStr" [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\UnicodeStr\Enum] "0"="Root\\LEGACY_UNICODESTR\\0000" "Count"=dword:00000001 "NextInstance"=dword:00000001 代码如下: NTSTATUS Pnp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { PDEVICE_EXTENSION dx = (PDEVICE_EXTENSION)(DeviceObject->DeviceExtension); PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp); ULONG MinorFunction = IrpStack->MinorFunction; NTSTATUS ntStatus = STATUS_SUCCESS; DbgPrint("> Pnp"); IoSkipCurrentIrpStackLocation(Irp); ntStatus = IoCallDriver(dx->NextStackDevice, Irp); if(MinorFunction == IRP_MN_REMOVE_DEVICE) { IoSetDeviceInterfaceState(&dx->SymLinkName, FALSE); RtlFreeUnicodeString(&dx->SymLinkName); if(dx->NextStackDevice) { IoDetachDevice(dx->NextStackDevice); IoDeleteDevice(DeviceObject); } } DbgPrint("< Pnp"); return ntStatus; } NTSTATUS Add(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject) { NTSTATUS ntStatus = STATUS_SUCCESS; PDEVICE_OBJECT fdo; PDEVICE_EXTENSION dx = NULL; DbgPrint("> Add"); ntStatus = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &fdo); dx = (PDEVICE_EXTENSION)fdo->DeviceExtension; dx->fdo = fdo; dx->NextStackDevice = IoAttachDeviceToDeviceStack(fdo, DeviceObject); fdo->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE; fdo->Flags &= ~DO_DEVICE_INITIALIZING; DbgPrint("< Add"); return STATUS_SUCCESS; } NTSTATUS DeviceControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { DbgPrint("> DeviceControl"); DbgPrint("< DeviceControl"); return STATUS_SUCCESS; } NTSTATUS Create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { DbgPrint("> Create"); DbgPrint("< Create"); return STATUS_SUCCESS; } NTSTATUS Close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { DbgPrint("> Close"); DbgPrint("< Close"); return STATUS_SUCCESS; } NTSTATUS Unload(IN PDRIVER_OBJECT DeviceObject) { DbgPrint("> Unload"); DbgPrint("< Unload"); return STATUS_SUCCESS; } NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { NTSTATUS ntStatus = STATUS_SUCCESS; UNICODE_STRING str = RTL_CONSTANT_STRING(L"Xu zhen is a hao ren"); DbgPrint("%wZ", &str); DriverObject->MajorFunction[IRP_MJ_CREATE] = Create; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DeviceControl; DriverObject->MajorFunction[IRP_MJ_CLOSE] = Close; DriverObject->DriverExtension->AddDevice = Add; DriverObject->MajorFunction[IRP_MJ_PNP] = Pnp; DriverObject->DriverUnload = Unload; return ntStatus; } |
|
驱动牛犊
|
沙发#
发布于:2009-08-07 19:34
我自己顶下。
|
|
板凳#
发布于:2009-08-13 10:55
你这个驱动只有通过服务堆叠才能用,比如总线枚举出来一个物体,通过读注册表找到堆叠你这个驱动才能掉用到你的AddDevice,这个时候才有用。不知道我说的是不是你想要回答的问题。
|
|
地板#
发布于:2009-08-13 10:57
同上,如果你在driverEntry里面造这个物体的话这个时候生成的DriverObject才会有实在的DeviceObject,当跑到DriverEntry的时候你一定要看看有没有跑到你的AddDevice,因为这样才表示底层有物体需要堆叠,否则的话你这个是不能用的。
|
|
地下室#
发布于:2010-07-04 19:48
引用第3楼voidinit于2009-08-13 10:57发表的 : 能说的详细点么,具体该怎么做呢 |
|
驱动牛犊
|
5楼#
发布于:2010-07-06 09:15
问题解决了。其实就是在驱动中按照规范调用IoCreateDevice创建设备对象即可。
|
|