52944.fb2 Sysinternals Freeware - Information for Windows NT and Windows 2000 - Advanced DPCs - читать онлайн бесплатно полную версию книги . Страница 3

Sysinternals Freeware - Information for Windows NT and Windows 2000 - Advanced DPCs - читать онлайн бесплатно полную версию книги . Страница 3

Kernel DPCs

Underneath the I/O Manager functions described above are the Kernel functions that actually implement basic DPC functionality. A driver for a device that accepts multiple simultaneous I/O requests must use the Kernel functions directly, bypassing the I/O Manager convenience routines. There is a strong parallel between the two interfaces, however. Instead of calling IoInitializeDpcRequest, a driver's entry invokes the function KeInitializeDpc to initialize a dpc object. KeInitializeDpc takes a driver-allocated DPC object, a pointer to the deferred function and a context parameter that will be passed to the function. As with most driver-allocated data structures that are handed to the Kernel, the DPC object must be allocated from non-paged memory such as non-paged pool, driver static global non-paged memory, or in a device object extension.

Later, in an ISR, the driver calls KeInsertQueueDpc rather than IoRequestDpc. the parameter list for KeInsertQueueDpc is shorter than for IoRequestDpc – it takes a pointer to the DPC object initialized with KeInitializeDpc and two additional arguments that are simply passed through to the DPC routine. The DPC function receives a pointer to the DPC object, the context parameter that was passed to KeInitializeDpc, and the two system variables from KeInsertQueueDpc.

The I/O Manager's IoInitializeDpcRequest is actually nothing more than a wrapper around KeInitializeDpc.

#define IoInitializeDpcRequest( DeviceObject, DpcRoutine ) (\

 KeInitializeDpc( &(DeviceObject)->Dpc, \

 (PKDEFERRED_ROUTINE) (DpcRoutine), \

 (DeviceObject) ) )

A device object has both a field for an IRP, which would be used for serially-oriented I/O devices, and a field for a DPC, which is the DPC object used in I/O Manager-DPC functions. Similarly, IoRequestDpc is a macro that calls KeInsertQueueDpc.

#define IoRequestDpc( DeviceObject, Irp, Context ) ( \

 KeInsertQueueDpc( &(DeviceObject)->Dpc, (Irp), (Context) ) )

It obtains the DPC object pointer for the call from the device object.