NT4 driver programming model

I am investigating a problem with an NT4 legacy driver running
on XPSP2. While looking at the code, i began wondering what the
correct way of handling DMA adapters was in that driver model.

During DriverEntry the driver allocates two adapters per device
by calling HalGetAdapter, since the device supports two DMA
transfers simultaneously. As far as i know this is standard
processing.
But i could not find any information on what a driver is supposed
to do with those adapters during Unload. How are the adapters to be
freed? The driver i am analyzing does a ObDereferenceObject on the
adapters. Is that OK???

Kind regards,
poltrone

poltrone wrote:

During DriverEntry the driver allocates two adapters per device
by calling HalGetAdapter, since the device supports two DMA
transfers simultaneously. As far as i know this is standard
processing.

Yes, it’s good practice.

But i could not find any information on what a driver is supposed
to do with those adapters during Unload. How are the adapters to be
freed? The driver i am analyzing does a ObDereferenceObject on the
adapters. Is that OK???

You don’t actually say if this driver is running on NT V4 or a later
system. I’ll assume it’s running on NT V4.

There is no need to “free” the adapters. The “get” in this case just
returns you a pointer to the adapter objects for your device. It
doesn’t NECESSARILY allocate anything that needs to be returned by your
driver.

Deref’ing the ADAPTER_OBJECT by calling ObDereferenceObject is entirely
undocumented, and was only discussed in the following thread, as far as
I know:

http://www.osronline.com/lists_archive/ntdev/thread1705.html

It never was documented. I agree with Mr. Roddy who notes in that
thread that not all DMA Adapter Objects can, or should, be dereferenced.

The fact of the matter is, from NT V3.1 through NT V4.0 there was no way
to return ADAPTER_OBJECTs to the system, and there was never a
practice of calling ObDereferenceObject on them. Thus, you should NOT
deref them. Just leave them alone.

In Win2K, a new function named HalPutAdapter was introduced. This
probably works when used in combination with HalGetAdapter in Win2K and
later.

Peter
OSR

> The fact of the matter is, from NT V3.1 through NT V4.0 there was no way

to return ADAPTER_OBJECTs to the system, and there was never a
practice of calling ObDereferenceObject on them. Thus, you should NOT
deref them. Just leave them alone.

IIRC in NT4 the adapter objects were pre-allocated inside HAL, and
HalGetDmaAdapter was just returning the pointer without allocating any
resources. Thus no need in freeing them.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Hi Peter,

You don’t actually say if this driver is running on NT V4 or a later system.

I did mention that im running the driver on XP SP2.

Deref’ing the ADAPTER_OBJECT by calling ObDereferenceObject is entirely undocumented, and was only discussed in the following thread, as far as I know:

http://www.osronline.com/lists_archive/ntdev/thread1705.html

Thank you for that link to this very enlightening thread. Just once more
this proves that you should search the archives before asking a question :wink:

Thus, you should NOT deref them. Just leave them alone.

I tried that and the problem i had in the Unload path went away :slight_smile:

Kind regards,
poltrone