multiple IoAttachDeviceToDeviceStack => serious machine crash

Hi,
I would like to attach several drivers to my deviceobject in my driver’s
driverentry() function.
the goal here is to decide how to react with the control codes, but this
have nothing about my problem.

My problem here is that because the word “stack” in the
“IoAttachDeviceToDeviceStack” function name,
I expected I could then attach several devices to it.

But on the 2nd call to IoAttachDeviceToDeviceStack(), I get a “nice …”
blue screen and the machine does reboot

Needless to say for both call to IoAttachDeviceToDeviceStack() I retrieves
required parameter with the
IoGetDeviceObjectPointer() function.

Any help, advices?

Thank you for your time, warm regards

PS : Sorry about my awful “english”

Arnaud Maye

Once a device object is attached to a stack via
IoAttachDeviceToDeviceStack, it cannot be attached to another stack. So
for every stack you are attaching to, you need to create a
PDEVICE_OBJECT for each one.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arnaud Maye
Sent: Sunday, December 05, 2004 4:50 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] multiple IoAttachDeviceToDeviceStack => serious machine
crash

Hi,
I would like to attach several drivers to my deviceobject in my driver’s
driverentry() function.
the goal here is to decide how to react with the control codes, but this
have nothing about my problem.

My problem here is that because the word “stack” in the
“IoAttachDeviceToDeviceStack” function name,
I expected I could then attach several devices to it.

But on the 2nd call to IoAttachDeviceToDeviceStack(), I get a “nice …”
blue screen and the machine does reboot

Needless to say for both call to IoAttachDeviceToDeviceStack() I
retrieves
required parameter with the
IoGetDeviceObjectPointer() function.

Any help, advices?

Thank you for your time, warm regards

PS : Sorry about my awful “english”

Arnaud Maye


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

What is the bugcheck? Do you call IoAttachDeviceToDeviceStack with the
same device object each time?

Layering drivers does work. There’s something specific about your
implementation that does not work.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arnaud Maye
Sent: Sunday, December 05, 2004 7:50 PM
To: ntdev redirect
Subject: [ntdev] multiple IoAttachDeviceToDeviceStack => serious machine
crash

Hi,
I would like to attach several drivers to my deviceobject in my driver’s
driverentry() function.
the goal here is to decide how to react with the control codes, but this
have nothing about my problem.

My problem here is that because the word “stack” in the
“IoAttachDeviceToDeviceStack” function name,
I expected I could then attach several devices to it.

But on the 2nd call to IoAttachDeviceToDeviceStack(), I get a “nice …”
blue screen and the machine does reboot

Needless to say for both call to IoAttachDeviceToDeviceStack() I
retrieves
required parameter with the
IoGetDeviceObjectPointer() function.

Any help, advices?

Thank you for your time, warm regards

PS : Sorry about my awful “english”

Arnaud Maye


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@osr.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Hi Doron, Tony and others

here is some code snippets ( cleaned a bit about the msg don’t get too
indigest )

status = IoCreateDevice( … , … , … , … , … , … , &deviceObject);

RtlInitUnicodeString(&drv1up, DRV1_DEVICE_NAME);
status = IoGetDeviceObjectPointer(&drv1up, 1, &drv1fObject, &drv1tDevice);
drv1fdObject = IoAttachDeviceToDeviceStack(deviceObject, drv1tDevice);

RtlInitUnicodeString(&drv2up, DRV2_DEVICE_NAME);
status = IoGetDeviceObjectPointer(&drv2up, 1, &drv2fObject, &drv2tDevice);
drv2fdObject = IoAttachDeviceToDeviceStack(deviceObject, drv2tDevice);

then yes, I do use the same deviceObject for both “devices” I would like to
attach to.
I don’t know much about the bug check, but only thing I can say is that if I
do comment
the latest IoAttachDeviceToDeviceStack() call system don’t crash.

Also I am new in the driver world. I am actualy exercising a bit. Maybe I am
doing something obviously wrong

Best Regards

Arnaud Maye

----- Original Message -----
From: “Tony Mason”
To: “Windows System Software Devs Interest List”
Sent: Friday, December 03, 2004 2:55 AM
Subject: RE: [ntdev] multiple IoAttachDeviceToDeviceStack => serious machine
crash

What is the bugcheck? Do you call IoAttachDeviceToDeviceStack with the
same device object each time?

Layering drivers does work. There’s something specific about your
implementation that does not work.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arnaud Maye
Sent: Sunday, December 05, 2004 7:50 PM
To: ntdev redirect
Subject: [ntdev] multiple IoAttachDeviceToDeviceStack => serious machine
crash

Hi,
I would like to attach several drivers to my deviceobject in my driver’s
driverentry() function.
the goal here is to decide how to react with the control codes, but this
have nothing about my problem.

My problem here is that because the word “stack” in the
“IoAttachDeviceToDeviceStack” function name,
I expected I could then attach several devices to it.

But on the 2nd call to IoAttachDeviceToDeviceStack(), I get a “nice …”
blue screen and the machine does reboot

Needless to say for both call to IoAttachDeviceToDeviceStack() I
retrieves
required parameter with the
IoGetDeviceObjectPointer() function.

Any help, advices?

Thank you for your time, warm regards

PS : Sorry about my awful “english”

Arnaud Maye


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@osr.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

You need to create a seperate device object for each device you are
attaching to. The crash is because you are trying to put the device object
in two stacks, this can’t be done.

Even if you could do this you do not want to. When a request comes into
your driver, it will have the device object you attached as part of the
request, if you had the same object attached to both you wouldn’t know which
to send it to. For your model where you want a request to routed to N
different devices, consider creating N+1 device objects. Create one for
each device you attach to, and then create another for the router function.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

“Arnaud Maye” wrote in message news:xxxxx@ntdev…
> Hi Doron, Tony and others
>
> here is some code snippets ( cleaned a bit about the msg don’t get too
> indigest )
>
>
> status = IoCreateDevice( … , … , … , … , … , … ,
&deviceObject);
>
> …
>
> RtlInitUnicodeString(&drv1up, DRV1_DEVICE_NAME);
> status = IoGetDeviceObjectPointer(&drv1up, 1, &drv1fObject,
&drv1tDevice);
> drv1fdObject = IoAttachDeviceToDeviceStack(deviceObject, drv1tDevice);
>
> …
>
> RtlInitUnicodeString(&drv2up, DRV2_DEVICE_NAME);
> status = IoGetDeviceObjectPointer(&drv2up, 1, &drv2fObject, &drv2tDevice);
> drv2fdObject = IoAttachDeviceToDeviceStack(deviceObject, drv2tDevice);
>
>
> then yes, I do use the same deviceObject for both “devices” I would like
to
> attach to.
> I don’t know much about the bug check, but only thing I can say is that if
I
> do comment
> the latest IoAttachDeviceToDeviceStack() call system don’t crash.
>
> Also I am new in the driver world. I am actualy exercising a bit. Maybe I
am
> doing something obviously wrong
>
> Best Regards
>
> Arnaud Maye

Hi Don adn others,

would you have some templates example of software only drivers that use
several devices?
I understand the principle, but I real need to see a proper manner to do so.
I’v been able to
create two separate device objects with two IoCreateDevice call. Each of
these call use the
same DriverObject pointer ( I guess this is correct ), a different
DeviceObject pointer and a
different device name.

Because I then have two separate device objects, obviously I’ve been able to
attach these
two devices.

I also have slightly modified the DriverUnload() function in a way I
expected it be working
but it does crash in it now…, that’s why I mostly be pleased to see a
“template” made by
some experienced people around!

for reference here is my “Idiotic” DriverUnload fnc(), btw don’t be suprised
about the way I do
accessing the DeviceExtension structure, I was searching pointer in softice,
hehe!
(btw, gdrv1DeviceObject + gdrv2DeviceObject are two global pointers that are
assigned
in the DriverEntry() function ) :
VOID testUnload(
IN PDRIVER_OBJECT DriverObject
)
{
UNICODE_STRING win32Name;
HANDLE *tmpD1 = NULL, *tmpD2 = NULL;
PDEVICE_OBJECT tmpDevice1 = NULL, tmpDevice2 = NULL;

RtlInitUnicodeString(&win32Name, L"\??\testDevice");
IoDeleteSymbolicLink(&win32Name);

tmpD1 = gdrv1DeviceObject->DeviceExtension;
tmpD1 += 6;
tmpDevice1 = *tmpD1;

tmpD2 = gdrv2DeviceObject->DeviceExtension;
tmpD2 += 6;
tmpDevice2 = *tmpD2;

if(tmpDevice1!=0)
{
IoDetachDevice(tmpDevice1);
}

if(tmpDevice2!=0)
{
IoDetachDevice(tmpDevice2);
}

tmpD1 += 1;
tmpDevice1 = *tmpD1;
ObDereferenceObject(tmpDevice1);

tmpD2 += 1;
tmpDevice2 = *tmpD2;
ObDereferenceObject(tmpDevice2);

IoUnregisterShutdownNotification(DriverObject->DeviceObject);
IoDeleteDevice(DriverObject->DeviceObject);

// release memory block allocated for registry path
if (g_Data.RegistryPath.Buffer != NULL)
{
ExFreePool(g_Data.RegistryPath.Buffer);
g_Data.RegistryPath.Buffer = NULL;
}

return;
}

“Don Burn” a écrit dans le message de news:xxxxx@ntdev…
> You need to create a seperate device object for each device you are
> attaching to. The crash is because you are trying to put the device
object
> in two stacks, this can’t be done.
>
> Even if you could do this you do not want to. When a request comes into
> your driver, it will have the device object you attached as part of the
> request, if you had the same object attached to both you wouldn’t know
which
> to send it to. For your model where you want a request to routed to N
> different devices, consider creating N+1 device objects. Create one for
> each device you attach to, and then create another for the router
function.
>
>
> –
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Remove StopSpam from the email to reply
>
> “Arnaud Maye” wrote in message news:xxxxx@ntdev…
> > Hi Doron, Tony and others
> >
> > here is some code snippets ( cleaned a bit about the msg don’t get too
> > indigest )
> >
> >
> > status = IoCreateDevice( … , … , … , … , … , … ,
> &deviceObject);
> >
> > …
> >
> > RtlInitUnicodeString(&drv1up, DRV1_DEVICE_NAME);
> > status = IoGetDeviceObjectPointer(&drv1up, 1, &drv1fObject,
> &drv1tDevice);
> > drv1fdObject = IoAttachDeviceToDeviceStack(deviceObject, drv1tDevice);
> >
> > …
> >
> > RtlInitUnicodeString(&drv2up, DRV2_DEVICE_NAME);
> > status = IoGetDeviceObjectPointer(&drv2up, 1, &drv2fObject,
&drv2tDevice);
> > drv2fdObject = IoAttachDeviceToDeviceStack(deviceObject, drv2tDevice);
> >
> >
> > then yes, I do use the same deviceObject for both “devices” I would like
> to
> > attach to.
> > I don’t know much about the bug check, but only thing I can say is that
if
> I
> > do comment
> > the latest IoAttachDeviceToDeviceStack() call system don’t crash.
> >
> > Also I am new in the driver world. I am actualy exercising a bit. Maybe
I
> am
> > doing something obviously wrong
> >
> > Best Regards
> >
> > Arnaud Maye
>
>
>