The ExInitializeNPagedLookasideList routine initializes a lookaside list for nonpaged entries of the specified size.
void ExInitializeNPagedLookasideList( PNPAGED_LOOKASIDE_LIST Lookaside, PALLOCATE_FUNCTION Allocate, PFREE_FUNCTION Free, ULONG Flags, SIZE_T Size, ULONG Tag, USHORT Depth );
A pointer to the NPAGED_LOOKASIDE_LIST structure to initialize. The caller must use nonpaged system space for the structure. On 64-bit platforms, this structure must be 16-byte aligned.
A pointer to either a caller-supplied function for allocating an entry when the lookaside list is empty, or to NULL. If non-NULL, the pointer is to a function with the prototype:
PVOID XxxAllocate( __in POOL_TYPE PoolType, // NonPagedPool __in SIZE_T NumberOfBytes, // value of Size __in ULONG Tag // value of Tag );
A pointer to either a caller-supplied function for freeing an entry whenever the lookaside list is full, or to NULL. If non-NULL, the pointer is to a function with the prototype:
VOID XxxFree( __in PVOID Buffer );
Starting in Windows 8, this parameter specifies an optional flag value to modify the default behavior of the ExInitializeNPagedLookasideList routine. Compatible flag bits include the following.
|POOL_NX_ALLOCATION||Allocate non-executable memory.|
|POOL_RAISE_IF_ALLOCATION_FAILURE||If the allocation fails, raise an exception.|
Before Windows 8, this parameter is not used and must be zero.
Specifies the size, in bytes, for each nonpaged entry to be allocated subsequently. This parameter must not be less than the required minimum size, LOOKASIDE_MINIMUM_BLOCK_SIZE, which is defined in the Wdm.h header file.
Specifies the pool tag to use when allocating lookaside list entries. For more information about pool tags, see the Tag parameter of ExAllocatePoolWithTag.
Reserved. Must be zero.
After calling ExInitializeNPagedLookasideList, memory blocks of the caller-specified Size can be allocated from and freed to the lookaside list with calls to ExAllocateFromNPagedLookasideList and ExFreeToNPagedLookasideList, respectively. Such dynamically allocated and freed entries can be any data structure or fixed-size buffer that the caller uses while the system is running, particularly if the caller cannot predetermine how many such entries will be in use at any given moment. The layout and contents of each fixed-size entry are caller-determined.
ExInitializeNPagedLookasideList initializes the system state to track usage of the given lookaside list, as follows:
- Zero-initializes the counters to be maintained for entries.
- Stores the entry points of the caller-supplied XxxAllocate and XxxFree routines, if any, or sets these entry points to ExAllocatePoolWithTag and ExFreePool, respectively.
- Initializes a system spin lock to control allocations from and frees to the lookaside list in a multiprocessor-safe manner if necessary.
- Stores the caller-supplied entry Size and list Tag.
- Sets up the system-determined limits (minimum and maximum) on the number of entries to be held in the lookaside list, which can be adjusted subsequently if system-wide demand for entries is higher or lower than anticipated.
- Sets up the system-determined flags, which control the type of memory from which entries will be allocated subsequently.
Drivers must always explicitly free any lookaside lists they create before unloading. To do otherwise is a serious programming error. Use ExDeleteNPagedLookasideList to free the list.
ExInitializeNPagedLookasideList sets up the opaque list head at the caller-supplied location but preallocates no memory for list entries. Subsequently, the initial entries are allocated dynamically as calls to ExAllocateFromNPagedLookasideList occur, and these initial entries are held in the lookaside list as reciprocal calls to ExFreeToNPagedLookasideList occur. Entries collect in the given lookaside list until the system-determined maximum is reached, whereupon any additional entries are returned to nonpaged pool as they are freed. If the list becomes empty, allocate requests are satisfied by the XxxAllocate function specified at list initialization or by ExAllocatePoolWithTag.
It is more efficient to pass NULL pointers for the Allocate and Free parameters of ExInitializeNPagedLookasideList whenever the user of a lookaside list does nothing more than allocate and release fixed-size entries. However, any component that uses a lookaside list might supply these functions to do additional caller-determined processing, such as tracking its own dynamic memory usage by maintaining state about the number of entries it allocates and frees.
If the caller of ExInitializeNPagedLookasideList supplies an XxxAllocate function, that routine must allocate entries for the lookaside list using the given input parameters when it calls ExAllocatePoolWithTag.
Starting with Windows Vista, a similar routine, ExInitializeLookasideListEx, initializes a lookaside list that is described by a LOOKASIDE_LIST_EX structure. Unlike the XxxAllocate and XxxFree routines for a lookaside list that uses an NPAGED_LOOKASIDE_LIST structure, the allocation and deallocation routines for a lookaside list that uses the LOOKASIDE_LIST_EX structure receive a context pointer as an input parameter. These routines can use this context to store private data for the lookaside list. If your driver is intended to run only in Windows Vista and later versions of Windows, consider using ExInitializeLookasideListEx instead of ExInitializeNPagedLookasideList. For more information, see Using Lookaside Lists.
Callers of ExInitializeNPagedLookasideList can be running at IRQL <= DISPATCH_LEVEL, but are typically running at IRQL = PASSIVE_LEVEL.
|Minimum supported client||Available starting with Windows 2000.|
|Header||wdm.h (include Wdm.h, Ntddk.h, Ntifs.h)|
|IRQL||<= DISPATCH_LEVEL (see Remarks section)|