NONPAGED KPoolPtrNP MakeSizedPoolPtrNP()

in rtl/inc/kptr.h [88:117]


NONPAGED KPoolPtrNP<THeader> MakeSizedPoolPtrNP(ULONG poolTag, size_t allocationSize)
{
    WIN_ASSERT(allocationSize >= sizeof(THeader));

#if (NTDDI_VERSION >= NTDDI_WIN10_VB) && !defined(KRTL_USE_LEGACY_POOL_API)

    auto allocation = ExAllocatePool2(
        POOL_FLAG_NON_PAGED,
        allocationSize,
        poolTag);
    if (!allocation)
    {
        return nullptr;
    }

#else // (NTDDI_VERSION >= NTDDI_WIN10_VB) && !defined(KRTL_USE_LEGACY_POOL_API)

    auto allocation = ExAllocatePoolWithTag(NonPagedPoolNx, allocationSize, poolTag);
    if (!allocation)
    {
        return nullptr;
    }

    RtlZeroMemory(allocation, allocationSize);

#endif // (NTDDI_VERSION >= NTDDI_WIN10_VB) && !defined(KRTL_USE_LEGACY_POOL_API)

    // Still call the default constructor for the type in case of custom field initializers
    return KPoolPtrNP<THeader>(new (allocation) THeader());
}