[XDK] Introduce ExAllocate*Zero and ExAllocate*Uninitialized functions

These has been first added to DDK 10.0.19041.0 and made backwards-compatible
with all Windows versions since Windows 2000.
Our implementation does not use POOL_ZERO_ALLOCATION flag because it's not
supported by ReactOS yet, and thus erases the memory unconditionally.
This commit is contained in:
Victor Perevertkin 2020-07-26 14:10:52 +03:00
parent 92520463d8
commit 380cd27cf3
No known key found for this signature in database
GPG key ID: C750B7222E9C7830
2 changed files with 163 additions and 3 deletions

View file

@ -574,6 +574,164 @@ ExAllocatePoolWithTagPriority(
_In_ ULONG Tag,
_In_ __drv_strictTypeMatch(__drv_typeExpr) EX_POOL_PRIORITY Priority);
FORCEINLINE
__drv_allocatesMem(Mem)
_When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
_When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
_When_((PoolType & NonPagedPoolMustSucceed) != 0,
__drv_reportError("Must succeed pool allocations are forbidden. "
"Allocation failures cause a system crash"))
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
_Post_maybenull_ _Must_inspect_result_)
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
_Post_notnull_)
_Post_writable_byte_size_(NumberOfBytes)
PVOID
NTAPI
ExAllocatePoolZero(
_In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
_In_ SIZE_T NumberOfBytes,
_In_ ULONG Tag)
{
PVOID Allocation;
Allocation = ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
if (Allocation != NULL) {
RtlZeroMemory(Allocation, NumberOfBytes);
}
return Allocation;
}
FORCEINLINE
__drv_allocatesMem(Mem)
_When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
_When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
_When_((PoolType & NonPagedPoolMustSucceed) != 0,
__drv_reportError("Must succeed pool allocations are forbidden. "
"Allocation failures cause a system crash"))
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
_Post_maybenull_ _Must_inspect_result_)
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
_Post_notnull_)
_Post_writable_byte_size_(NumberOfBytes)
PVOID
NTAPI
ExAllocatePoolUninitialized(
_In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
_In_ SIZE_T NumberOfBytes,
_In_ ULONG Tag)
{
return ExAllocatePoolWithTag(PoolType, NumberOfBytes, Tag);
}
FORCEINLINE
__drv_allocatesMem(Mem)
_When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
_When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
_When_((PoolType & NonPagedPoolMustSucceed) != 0,
__drv_reportError("Must succeed pool allocations are forbidden. "
"Allocation failures cause a system crash"))
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
_Post_maybenull_ _Must_inspect_result_)
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
_Post_notnull_)
_Post_writable_byte_size_(NumberOfBytes)
PVOID
NTAPI
ExAllocatePoolQuotaZero (
_In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
_In_ SIZE_T NumberOfBytes,
_In_ ULONG Tag)
{
PVOID Allocation;
Allocation = ExAllocatePoolWithQuotaTag(PoolType, NumberOfBytes, Tag);
if (Allocation != NULL) {
RtlZeroMemory(Allocation, NumberOfBytes);
}
return Allocation;
}
FORCEINLINE
__drv_allocatesMem(Mem)
_When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
_When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
_When_((PoolType & NonPagedPoolMustSucceed) != 0,
__drv_reportError("Must succeed pool allocations are forbidden. "
"Allocation failures cause a system crash"))
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
_Post_maybenull_ _Must_inspect_result_)
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
_Post_notnull_)
_Post_writable_byte_size_(NumberOfBytes)
PVOID
NTAPI
ExAllocatePoolQuotaUninitialized(
_In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
_In_ SIZE_T NumberOfBytes,
_In_ ULONG Tag)
{
return ExAllocatePoolWithQuotaTag(PoolType, NumberOfBytes, Tag);
}
FORCEINLINE
__drv_allocatesMem(Mem)
_When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
_When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
_When_((PoolType & NonPagedPoolMustSucceed) != 0,
__drv_reportError("Must succeed pool allocations are forbidden. "
"Allocation failures cause a system crash"))
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
_Post_maybenull_ _Must_inspect_result_)
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
_Post_notnull_)
_Post_writable_byte_size_(NumberOfBytes)
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(PoolType, NumberOfBytes, Tag, Priority);
if (Allocation != NULL) {
RtlZeroMemory(Allocation, NumberOfBytes);
}
return Allocation;
}
FORCEINLINE
__drv_allocatesMem(Mem)
_When_((PoolType & PagedPool) != 0, _IRQL_requires_max_(APC_LEVEL))
_When_((PoolType & PagedPool) == 0, _IRQL_requires_max_(DISPATCH_LEVEL))
_When_((PoolType & NonPagedPoolMustSucceed) != 0,
__drv_reportError("Must succeed pool allocations are forbidden. "
"Allocation failures cause a system crash"))
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) == 0,
_Post_maybenull_ _Must_inspect_result_)
_When_((PoolType & (NonPagedPoolMustSucceed | POOL_RAISE_IF_ALLOCATION_FAILURE)) != 0,
_Post_notnull_)
_Post_writable_byte_size_(NumberOfBytes)
PVOID
NTAPI
ExAllocatePoolPriorityUninitialized(
_In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
_In_ SIZE_T NumberOfBytes,
_In_ ULONG Tag,
_In_ EX_POOL_PRIORITY Priority)
{
return ExAllocatePoolWithTagPriority(PoolType, NumberOfBytes, Tag, Priority);
}
_IRQL_requires_max_(DISPATCH_LEVEL)
NTKERNELAPI
VOID

View file

@ -14,9 +14,11 @@ $if (_WDMDDK_)
#define CONNECT_FULLY_SPECIFIED_GROUP 0x4
#define CONNECT_CURRENT_VERSION 0x4
#define POOL_COLD_ALLOCATION 256
#define POOL_QUOTA_FAIL_INSTEAD_OF_RAISE 8
#define POOL_RAISE_IF_ALLOCATION_FAILURE 16
#define POOL_QUOTA_FAIL_INSTEAD_OF_RAISE 0x8
#define POOL_RAISE_IF_ALLOCATION_FAILURE 0x10
#define POOL_COLD_ALLOCATION 0x100
#define POOL_NX_ALLOCATION 0x200
#define POOL_ZERO_ALLOCATION 0x400
#define IO_TYPE_ADAPTER 1
#define IO_TYPE_CONTROLLER 2