Export (0) Print
Expand All

Using the Kernel Stack

The size of the kernel-mode stack is limited to approximately three pages. Therefore, when passing data to internal routines, drivers cannot pass large amounts of data on the kernel stack.

To avoid running out of kernel-mode stack space, use the following design guidelines:

  • Avoid making deeply nested calls from one internal driver routine to another, if each routine passes data on the kernel stack.

  • Make sure that you limit the number of recursive calls that can occur, if you design a driver that has a recursive routine.

In other words, the call-tree structure of a driver should be relatively flat. You can call the IoGetStackLimits and IoGetRemainingStackSize routines to determine the kernel stack space that is available. Note that the size of the kernel-mode stack can vary among different hardware platforms and different versions of the operating system.

Running out of kernel stack space causes a fatal system error. Therefore, it is better for a driver to allocate system-space memory than to run out of kernel stack space. However, nonpaged pool is also a limited system resource.

Drivers of devices that use DMA can buffer data to be transferred, if necessary, either by calling ExAllocatePoolWithTag for a NonPagedPool-type buffer or, for some drivers, by using common-buffer DMA. For more information, see Using Common-Buffer System DMA and Using Common-Buffer Bus-Master DMA.

Generally, the kernel-mode stack cannot be paged; it is guaranteed to be resident in memory. However, Windows occasionally pages the kernel stacks of inactive threads. For help in guaranteeing that these kernel stacks are not paged during a debugging session, see Disable paging of kernel stacks.

 

 

Send comments about this topic to Microsoft

Show:
© 2015 Microsoft