IoDeleteDevice causes BugCheck

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</ntddk.h>

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
>


Mark Roddy</ntddk.h>

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_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;
}------

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</ntddk.h></ntddk.h>

Just a hint: If you had made your file type .CPP, or built your driver with the “compile using CPP” switch, it would have caught this for you.

I suspect PreFAST would also give you some sort of warning here, wouldn’t it? And you can barely avoid running it given the integration of OACR in the kit.

Peter
OSR

PDEVICE_OBJECT deviceobject;

IoCreateDevice(…, &deviceobject);

Please do not ignore compiler warnings.

– pa

“Frank Freud” wrote in message news:xxxxx@ntdev…
> 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_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;
> }------
>
> 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
></ntddk.h></ntddk.h>

Compiler switch: /TP

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: Saturday, July 17, 2010 9:24 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] IoDeleteDevice causes BugCheck

Just a hint: If you had made your file type .CPP, or built your driver with
the “compile using CPP” switch, it would have caught this for you.

I suspect PreFAST would also give you some sort of warning here, wouldn’t
it? And you can barely avoid running it given the integration of OACR in
the kit.

Peter
OSR


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

Integration? How about CRAP ABORTION!

Good morning,

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: Saturday, July 17, 2010 9:24 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] IoDeleteDevice causes BugCheck

Just a hint: If you had made your file type .CPP, or built your driver with
the “compile using CPP” switch, it would have caught this for you.

I suspect PreFAST would also give you some sort of warning here, wouldn’t
it? And you can barely avoid running it given the integration of OACR in
the kit.

Peter
OSR


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

Like Mark said, define deviceobject as PDEVICE_OBJECT. IoCreatDeviceObect
placed a “pointer” to a device object in the first 32 bits or 64 bits of the
global DEVICE_OBJECT that you have defined. Basically, you’ve set yourself
up to fail because the DO structure you defined is NOT filled in as you
think it should be, hence you’re deviceobject.DeviceExtension contains crap.
So no, IoDeleteDevice did not cause a bugcheck. You caused the bug check
because you passed IoDeviceDelete the address of deviceobject instead of
what *(&deviceobject) was pointing too.

Actually your best bet would be to convert this to KMDF.

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 2:56 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] IoDeleteDevice causes BugCheck

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_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;
}

-------------------------------------------

___________________________________________________________
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>

Oh CRAP … my bifocals read that as CPAP and I was wondering how a positive
airway pressure device would have anything to do with IoDeviceDelete.

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 M. M. O’Brien
Sent: Saturday, July 17, 2010 10:30 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IoDeleteDevice causes BugCheck

Integration? How about CRAP ABORTION!

Good morning,

mm

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: Saturday, July 17, 2010 9:24 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] IoDeleteDevice causes BugCheck

Just a hint: If you had made your file type .CPP, or built your driver with
the “compile using CPP” switch, it would have caught this for you.

I suspect PreFAST would also give you some sort of warning here, wouldn’t
it? And you can barely avoid running it given the integration of OACR in
the kit.

Peter
OSR


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


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

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>

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.


DEVICE_OBJECT deviceobject;

NTSTATUS DriverEntry(__in PDRIVER_OBJECT driverobject,
__in PUNICODE_STRING registrypath){

status =
IoCreateDevice(driverobject,sizeof(DEVICE_EXTENSION),NULL,FILE_DEVICE_UNKNOWN,FILE_DEVICE_SECURE_OPEN,FALSE,&deviceobject);

Did that really compile without any warnings? If so, it looks like
you’ve found a compiler bug. If not, why are you wasting time posting
here asking what wrong when the compiler is already telling you?

First of all:
Thank you for your patience, and willingness to help me.
I always read &PDEVICE_OBJECT as a &DEVICE_OBJECT, for some reason, for
it makes no sense to me why I should pass a pointer to a pointer to a
function,what additionally confused me was the fact that IoCreateDevice
was supposed to get a pointer to a pointer and IoDeleteDevice is only
getting the same pointer.
An additional mistake I made(and will never make again) is:seeing a
pointer and an address to an object/variable as equals.
Once again.
Thanks again for your help.
Sincerly

Frank

Am 18.07.2010 01:04, schrieb J. J. Farrell:

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.
>
> …
> DEVICE_OBJECT deviceobject;
> …
> NTSTATUS DriverEntry(__in PDRIVER_OBJECT driverobject,
> __in PUNICODE_STRING registrypath){
> …
> status =
> IoCreateDevice(driverobject,sizeof(DEVICE_EXTENSION),NULL,FILE_DEVICE_UNKNOWN,FILE_DEVICE_SECURE_OPEN,FALSE,&deviceobject);
>
> …

Did that really compile without any warnings? If so, it looks like
you’ve found a compiler bug. If not, why are you wasting time posting
here asking what wrong when the compiler is already telling you?


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


Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de

Never mind.
Came to me outta nowhere.
Call-By-Reference.
sincerly

Frank

Am 18.07.2010 10:09, schrieb Frank Freud:

First of all:
Thank you for your patience, and willingness to help me.
I always read &PDEVICE_OBJECT as a &DEVICE_OBJECT, for some reason, for
it makes no sense to me why I should pass a pointer to a pointer to a
function,what additionally confused me was the fact that IoCreateDevice
was supposed to get a pointer to a pointer and IoDeleteDevice is only
getting the same pointer.
An additional mistake I made(and will never make again) is:seeing a
pointer and an address to an object/variable as equals.
Once again.
Thanks again for your help.
Sincerly

Frank

Am 18.07.2010 01:04, schrieb J. J. Farrell:

> 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.
>>
>> …
>> DEVICE_OBJECT deviceobject;
>> …
>> NTSTATUS DriverEntry(__in PDRIVER_OBJECT driverobject,
>> __in PUNICODE_STRING registrypath){
>> …
>> status =
>> IoCreateDevice(driverobject,sizeof(DEVICE_EXTENSION),NULL,FILE_DEVICE_UNKNOWN,FILE_DEVICE_SECURE_OPEN,FALSE,&deviceobject);
>>
>> …
>>
> Did that really compile without any warnings? If so, it looks like
> you’ve found a compiler bug. If not, why are you wasting time posting
> here asking what wrong when the compiler is already telling you?
>
> —
> 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
>
>


Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.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


Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de

M. M. O’Brien wrote:

Integration? How about CRAP ABORTION!

Now, that’s not fair. PreFAST is a Very Good Thing. OACR is annoying,
unless one is doing nothing but driver development for 8 hours every
day, but I can certainly see where it came from. And it’s not hard to
disable.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.