https://git.reactos.org/?p=reactos.git;a=commitdiff;h=380cd27cf3dc2286d994d…
commit 380cd27cf3dc2286d994d905556e15f2884b9746
Author: Victor Perevertkin <victor.perevertkin(a)reactos.org>
AuthorDate: Sun Jul 26 14:10:52 2020 +0300
Commit: Victor Perevertkin <victor.perevertkin(a)reactos.org>
CommitDate: Sun Jul 26 14:10:52 2020 +0300
[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.
---
sdk/include/xdk/exfuncs.h | 158 ++++++++++++++++++++++++++++++++++++++++++++++
sdk/include/xdk/iotypes.h | 8 ++-
2 files changed, 163 insertions(+), 3 deletions(-)
diff --git a/sdk/include/xdk/exfuncs.h b/sdk/include/xdk/exfuncs.h
index 5dc7ba9fd9c..1f9a1ad6a97 100644
--- a/sdk/include/xdk/exfuncs.h
+++ b/sdk/include/xdk/exfuncs.h
@@ -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
diff --git a/sdk/include/xdk/iotypes.h b/sdk/include/xdk/iotypes.h
index 2ae56a60e47..5a40a71f6a5 100644
--- a/sdk/include/xdk/iotypes.h
+++ b/sdk/include/xdk/iotypes.h
@@ -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