How to allocate pool correctly?

The problem: Old pool allocation functions ExAllocatePoolWithTagPriority(), ExAllocatePoolWithTag() are deprecated in Windows 10, version 2004 and has been replaced by ExAllocatePool2, ExAllocatePool3.

But for ExAllocatePool2 and ExAllocatePool3 Minimum supported client is Windows 10, version 2004.

Question: I need support all Windows 10 versions, before 2004 too.
Which APIs may be used for it?

Attempt to keep ExAllocatePoolWithTagPriority(0 was cached by Driver verifier: :frowning:

04 VerifierExt!ExAllocatePoolWithTagPriority_internal_wrapper
05 nt!VerifierExAllocatePoolWithTagPriority

This is discussed here [https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/updating-deprecated-exallocatepool-calls], in my drivers I will call RtlVerifyVersionInfo for buildnumber and ver_platformid to see what I’m running on and then adjust the calls accordingly …

It should also be noted that this is for KMDF, WDM and miniport drivers … UMDF v2 drivers don’t have support for the ExInitializeDriverRuntime() function [???] (although I can still use ExAllocateXXX functions in a UMDF v2 driver, meh …)

Better still, following in the pattern established by our old friend POOL_NX_OPTIN, the auto-zeroing allocation functions can be made to do the right thing down-level as well. All you need to do is:

  1. Define the symbol POOL_ZERO_DOWN_LEVEL_SUPPORT when you build your driver
  2. Call ExInitializeDriverRuntime right at the start of DriverEntry

See the blog post here.

Peter

Peter,
thanks for replay.
And I had read this recommendation.

The problem that VerifierExAllocatePoolWithTagPriority was catched by Driver Verifier with following stack:

00 nt!KeBugCheckEx
01 nt!VerifierBugCheckIfAppropriate
02 nt!ExAllocatePoolSanityChecks
03 nt!VeAllocatePoolWithTagPriority
04 VerifierExt!ExAllocatePoolWithTagPriority_internal_wrapper
05 nt!VerifierExAllocatePoolWithTagPriority

I guess using POOL_ZERO_DOWN_LEVEL_SUPPORT and ExInitializeDriverRuntime does not change situation.
I see how to realized ExAllocatePoolZero() which really is ExAllocatePoolWithTagPriority():

PVOID NTAPI ExAllocatePoolPriorityZero (
In __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
In SIZE_T NumberOfBytes,
In ULONG Tag,
In EX_POOL_PRIORITY Priority
)
{
PVOID Allocation;

Allocation = ExAllocatePoolWithTagPriority((POOL_TYPE) (PoolType | POOL_ZERO_ALLOCATION),
                                           NumberOfBytes,
                                           Tag,
                                           Priority);

(#)if defined(POOL_ZERO_DOWN_LEVEL_SUPPORT)

if ((!ExPoolZeroingNativelySupported) && (Allocation != NULL)) {
    RtlZeroMemory(Allocation, NumberOfBytes);
}

(#)endif

return Allocation;

}