PAGED KPoolPtr MakeSizedPoolPtr()

in rtl/inc/kptr.h [53:84]


PAGED KPoolPtr<THeader> MakeSizedPoolPtr(ULONG poolTag, size_t allocationSize)
{
    PAGED_CODE();

    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 KPoolPtr<THeader>(new (allocation) THeader());
}