14.1.2.2 Setting Up Context for a CustomTimerDpc Routine

The DeferredContext passed to KeInitializeDpc points to a context area where other driver routines and the CustomTimerDpc routine can maintain state. This DeferredContext pointer is passed to the DPC routine whenever it is called, as shown by the declaration.

A CustomTimerDpc has no particular associations with a driver-created device object. However, a driver can associate a CustomTimerDpc routine with a driver-created device object by passing a DeferredContext pointer to the device object when it calls KeInitializeDpc.

Such a context area must be in resident memory allocated by the driver. Usually, this context area is in a device extension. It can be in a controller extension if the driver uses a controller object or in nonpaged pool allocated by the driver. The contents of the context area are driver-determined.

If a CustomTimerDpc routine shares context information with the driver's ISR, the CustomTimerDpc routine must call KeSynchronizeExecution with a SynchCritSection routine in order to access the shared context safely.

If the CustomTimerDpc shares the context information with other nonISR driver routine(s), the area at DeferredContext must be protected by an executive spin lock.

For more information about SynchCritSection routines, see Chapter 10. For more information about using executive and interrupt spin locks, see Chapter 16.