In Windows XP you need to use the one you didn’t list -
IoAttachDeviceToDeviceStackSafe.
This fixes a problem in the filter driver where it calls something like:
MyDeviceExtension->DeviceObjectToCall =
IoAttachDeviceToDeviceStack(MyDeviceExtension->FSDeviceObject,
MyFilterDeviceObject);
And an IRP arrives *in the filter* after the attachment is made but before
the function has returned (a narrow window, but one sufficient to cause the
system to crash if the filter is written not to expect this).
Of course, there are ways that you can protect against this in versions
prior to Windows XP (essentially, you need a condition variable of some
sort) so you’d have something like:
If (NULL == MyDeviceExtension->DeviceObjecToCall) {
KeWaitForSingleObject(MyDeviceExtension->AttachmentComplete);
}
down any path where you might be trying to use DeviceObjectToCall and then
you would set the event after IoAttachDeviceToDeviceStack returns
successfully.
Serialization is a wonderful thing!
At any rate, the new call has a different prototype:
NTSTATUS
IoAttachDeviceToDeviceStackSafe(
IN PDEVICE_OBJECT SourceDevice,
IN PDEVICE_OBJECT TargetDevice,
OUT PDEVICE_OBJECT *AttachedToDeviceObject
);
And it guarantees that the AttachedToDeviceObject is set in a fashion that
is atomic with respect to the attachment. In other words, it does the
serialization for you.
Regards,
Tony
Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com
Hope to see you at the next OSR file systems class October 7, 2002!
-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Wednesday, April 10, 2002 8:32 AM
To: File Systems Developers
Subject: [ntfsd] Re: Attach filter driver
Could anybody tell me the different IoAttachDeviceByPointer,
IoAttachDeviceToDeviceStack, IoAttachDevice function?
Use the second. The first one is obsolete long ago, and the last one seems
to provide no benefits over a second one.
Max
You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to %%email.unsub%%