16.4.2 Using the Kernel Stack

While an NT driver can pass data to its internal routines, the NT kernel-mode stack size is around two pages. Consequently, NT drivers cannot pass large amounts of data on the kernel stack.

    NT driver writers should take care not to run out of kernel-mode stack space by following these design guidelines:

In other words, the call-tree structure of an NT driver should be relatively flat. While nonpaged pool is also a limited system resource, it is better for an NT driver to allocate a system-space buffer, as described in Section 16.4.1.3, than to run out of kernel stack space.

The NT kernel-mode stack is in cached memory. Consequently, NT drivers cannot transfer data on the stack using DMA.

    NT driver writers should avoid DMA data alignment and/or data integrity problems by following this design guideline:

Never attempt to transfer data on the kernel stack using DMA.

Drivers of devices that use DMA can buffer data to be transferred, if necessary, either by calling ExAllocatePool or ExAllocatePoolWithTag for a NonPagedPoolCacheAligned-type buffer or, for some drivers, by using common-buffer DMA, as described in the section on adapter objects in Chapter 3.