PVOID
ExInterlockedAllocateFromZone(
IN PZONE_HEADER Zone,
IN PKSPIN_LOCK Lock
);
ExInterlockedAllocateFromZone removes an entry from a given zone and returns a pointer to the entry.
Parameters
Zone
Points to the zone header that controls the storage for the entry.
Lock
Points to a caller-supplied spin lock. This spin lock is released before returning to the caller.
Return Value
The routine returns a pointer to a zone entry.
Comments
Consider using a lookaside list instead of a zone. Lookaside lists are more efficient and are easier to manage.
Support routines that do interlocked operations are assumed to be incapable of causing a page fault. That is, neither their code nor any of the data they touch can cause a page fault without bringing down the system. They use spin locks to achieve atomicity in SMP machines. The caller must provide resident storage for the Lock, which must be initialized with KeInitializeSpinLock before the initial call to an ExInterlockedXxx.
The removal process is performed with the given Lock held to update the links in a multiprocessor-safe way. Always call ExIsFullZone immediately preceding the call to ExInterlockedAllocateFromZone and allocate additional temporary memory with ExAllocatePool if necessary. Otherwise, a call to ExInterlockedAllocateFromZone can tie up a processor trying to acquire the Lock for a zone that has no free entries.
Any of the Ex..InterlockedXxx can be called at DIRQL from a device driver’s ISR or SynchCritSection routine, provided that other driver routines do not make calls to the ExInterlockedXxx while running at < DIRQL with the same spin lock. Otherwise, callers of ExInterlockedAllocateFromZone must be running at IRQL <= DISPATCH_LEVEL.
See Also
ExInterlockedFreeToZone, ExInitializeNPagedLookasideList, ExInitializePagedLookasideList, ExInitializeZone, ExIsFullZone