Well of course it bug checks, since you still fucked up the pointer to the
device object. You need to look at the definition of IoCreateDevice very
closely. ICD is going to allocate a device object and return you a pointer
to that device object. The way you have defined deviceobject and test
proclaims to the heavens that you have some really serious work to do in
understanding C/C++ syntax and coding. You do NOT need “test” at all. ICD is
expecting in that last parameter, the ADDRESS of a DEVICE_OBJECT POINTER,
and NOT the ADDRESS of the DEVICE_OBJECT structure.
And yes, as Peter said, using either the .CPP extension, or the /TP compile
switch would have caught this for you.
Gary G. Little
H (952) 223-1349
C (952) 454-4629
xxxxx@comcast.net
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Frank Freud
Sent: Saturday, July 17, 2010 8:23 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] IoDeleteDevice causes BugCheck
Doesn’t work.
The following Code produes a bugcheck upon loading.
Putting DEVICE_OBJECT test; within DriverEntry causes a Bugcheck upon
unloading.
sincerly
Frank
Code
#include<ntddk.h>
NTSTATUS DriverEntry( in PDRIVER_OBJECT driverobject,
in PUNICODE_STRING registrypath);
NTSTATUS cleanup(__in PDRIVER_OBJECT driverobject);
PDEVICE_OBJECT deviceobject;
DEVICE_OBJECT test;
typedef struct _extension{
int counter;
PVOID memorypointer;
} DEVICE_EXTENSION,*PDEVICE_EXTENSION;
NTSTATUS DriverEntry(__in PDRIVER_OBJECT driverobject,
__in PUNICODE_STRING registrypath){
UNICODE_STRING devicename;
PDEVICE_EXTENSION pdx;
NTSTATUS status = STATUS_SUCCESS;
deviceobject = &test;
driverobject->DriverUnload = cleanup;
RtlInitUnicodeString(&devicename,L"\Device\Syncdriverexample1");
KdPrint((“Entering the driver”));
KdPrint((“Extensionsize:%d”,sizeof(DEVICE_EXTENSION)));
status =
IoCreateDevice(driverobject,sizeof(DEVICE_EXTENSION),NULL,FILE_DEVICE_UNKNOW
N,FILE_DEVICE_SECURE_OPEN,FALSE,deviceobject);
pdx = (PDEVICE_EXTENSION) deviceobject->DeviceExtension;
pdx->counter = 1;
KdPrint((“Countersize %d”,pdx->counter));
if(!NT_SUCCESS(status)){
KdPrint((“The IoDevice wasn’t created”));
}
return status;
}
NTSTATUS cleanup(__in PDRIVER_OBJECT driverobject){
IoDeleteDevice(deviceobject);//Bugcheck
return STATUS_SUCCESS;
}------
Am 17.07.2010 14:05, schrieb Mark Roddy:
> Your global device object should be a pointer to a device object.
>
> On Saturday, July 17, 2010, Frank Freud wrote:
>
>> Hi!
>> Following Code causes bugcheck upon unloading.
>> It is caused by calling IoDeleteDevice It seems to be something small
>> but I can’t figgure out what is wrong.
>> sincerly
>>
>> Frank
>>
>>
>>
>>
>> Code
>> -------------------------------------------------------------
>>
>> #include<ntddk.h>
>>
>> NTSTATUS DriverEntry( in PDRIVER_OBJECT driverobject,
>> in PUNICODE_STRING registrypath);
>>
>> NTSTATUS cleanup(__in PDRIVER_OBJECT driverobject);
>>
>> //#pragma alloc_text(INIT,DriverEntry) //#pragma
>> alloc_text(PAGE,cleanup)
>>
>> DEVICE_OBJECT deviceobject;
>>
>> typedef struct _extension{
>> int counter;
>> PVOID memorypointer;
>> } DEVICE_EXTENSION,*PDEVICE_EXTENSION;
>>
>> NTSTATUS DriverEntry(__in PDRIVER_OBJECT driverobject,
>> __in PUNICODE_STRING registrypath){
>> UNICODE_STRING devicename;
>> PDEVICE_EXTENSION pdx;
>> NTSTATUS status = STATUS_SUCCESS;
>>
>>
>> driverobject->DriverUnload = cleanup;
>>
>>
>> RtlInitUnicodeString(&devicename,L"\Device\Syncdriverexample1");
>>
>> KdPrint((“Entering the driver”));
>> KdPrint((“Extensionsize:%d”,sizeof(DEVICE_EXTENSION)));
>>
>> status =
>> IoCreateDevice(driverobject,sizeof(DEVICE_EXTENSION),NULL,FILE_DEVICE
>> _UNKNOWN,FILE_DEVICE_SECURE_OPEN,FALSE,&deviceobject);
>>
>> pdx = (PDEVICE_EXTENSION) &deviceobject.DeviceExtension;
>>
>> pdx->counter = 1;
>> KdPrint((“Countersize %d”,pdx->counter));
>>
>> if(!NT_SUCCESS(status)){
>> KdPrint((“The IoDevice wasn’t created”));
>> }
>>
>>
>> return status;
>> }
>>
>> NTSTATUS cleanup(__in PDRIVER_OBJECT driverobject){
>> IoDeleteDevice(&deviceobject);///Bugcheck
>> return STATUS_SUCCESS;
>> }
>>
>> -------------------------------------------
>>
>>
>>
>> Telefonate ohne weitere Kosten vom PC zum PC:
>> http://messenger.yahoo.de
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>>
>
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
—
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer</ntddk.h></ntddk.h>