From 76d99dc9db5a5782798c1a6b1ae2c01ffb930789 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Mon, 16 Mar 2026 13:54:42 +0100 Subject: [PATCH] Introduce pool allocation and free routines --- xtoskrnl/includes/mm/alloc.hh | 10 +++ xtoskrnl/mm/alloc.cc | 112 ++++++++++++++++++++++++++++++++-- 2 files changed, 116 insertions(+), 6 deletions(-) diff --git a/xtoskrnl/includes/mm/alloc.hh b/xtoskrnl/includes/mm/alloc.hh index 69e34ea..80a4651 100644 --- a/xtoskrnl/includes/mm/alloc.hh +++ b/xtoskrnl/includes/mm/alloc.hh @@ -26,7 +26,17 @@ namespace MM STATIC XTAPI XTSTATUS AllocatePages(IN MMPOOL_TYPE PoolType, IN SIZE_T Bytes, OUT PVOID *Memory); + STATIC XTAPI XTSTATUS AllocatePool(IN MMPOOL_TYPE PoolType, + IN SIZE_T Bytes, + OUT PVOID *Memory); + STATIC XTAPI XTSTATUS AllocatePool(IN MMPOOL_TYPE PoolType, + IN SIZE_T Bytes, + OUT PVOID *Memory, + IN ULONG Tag); STATIC XTAPI XTSTATUS FreePages(IN PVOID VirtualAddress); + STATIC XTAPI XTSTATUS FreePool(IN PVOID VirtualAddress); + STATIC XTAPI XTSTATUS FreePool(IN PVOID VirtualAddress, + IN ULONG Tag); STATIC XTAPI VOID InitializeNonPagedPool(VOID); STATIC XTAPI VOID InitializePagedPool(VOID); diff --git a/xtoskrnl/mm/alloc.cc b/xtoskrnl/mm/alloc.cc index d610a8e..26e6190 100644 --- a/xtoskrnl/mm/alloc.cc +++ b/xtoskrnl/mm/alloc.cc @@ -16,7 +16,7 @@ * Specifies the number of pages to allocate. * * @param Memory - * Supplies a pointer to the allocated pool. + * Supplies a pointer to the allocated pool of pages. * * @return This routine returns a status code. * @@ -189,7 +189,7 @@ MM::Allocator::AllocateNonPagedPoolPages(IN PFN_COUNT Pages, * Specifies the number of pages to allocate. * * @param Memory - * Supplies a pointer to the allocated pool. + * Supplies a pointer to the allocated pool of pages. * * @return This routine returns a status code. * @@ -216,7 +216,7 @@ MM::Allocator::AllocatePagedPoolPages(IN PFN_COUNT Pages, * Specifies the number of bytes to allocate. * * @param Memory - * Supplies a pointer to the allocated pool. + * Supplies a pointer to the allocated pool of pages. * * @return This routine returns a status code. * @@ -258,11 +258,69 @@ MM::Allocator::AllocatePages(IN MMPOOL_TYPE PoolType, return STATUS_INVALID_PARAMETER; } +/** + * Allocates a block of memory from the specified pool type. + * + * @param PoolType + * Specifies the type of pool to allocate from. + * + * @param Bytes + * Specifies the number of bytes to allocate. + * + * @param Memory + * Supplies a pointer to the allocated memory. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +MM::Allocator::AllocatePool(IN MMPOOL_TYPE PoolType, + IN SIZE_T Bytes, + OUT PVOID *Memory) +{ + /* Allocate pool */ + return AllocatePool(PoolType, Bytes, Memory, SIGNATURE32('N', 'o', 'n', 'e')); +} + +/** + * Allocates a block of memory from the specified pool type. + * + * @param PoolType + * Specifies the type of pool to allocate from. + * + * @param Bytes + * Specifies the number of bytes to allocate. + * + * @param Memory + * Supplies a pointer to the allocated memory. + * + * @param Tag + * Specifies the allocation identifying tag. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +MM::Allocator::AllocatePool(IN MMPOOL_TYPE PoolType, + IN SIZE_T Bytes, + OUT PVOID *Memory, + IN ULONG Tag) +{ + UNIMPLEMENTED; + + /* Allocate pages */ + return AllocatePages(PoolType, Bytes, Memory); +} + /** * Frees a previously allocated block of pages from the non-paged pool. * * @param VirtualAddress - * Supplies the base virtual address of the non-paged pool allocation to free. + * Supplies the base virtual address of the non-paged pool pages allocation to free. * * @return This routine returns a status code. * @@ -445,7 +503,7 @@ MM::Allocator::FreeNonPagedPoolPages(IN PVOID VirtualAddress) * Frees a previously allocated block of pages from the paged pool. * * @param VirtualAddress - * Supplies the base virtual address of the paged pool allocation to free. + * Supplies the base virtual address of the paged pool pages allocation to free. * * @return This routine returns a status code. * @@ -465,7 +523,7 @@ MM::Allocator::FreePagedPoolPages(IN PVOID VirtualAddress) * Frees a previously allocated block of pages. * * @param VirtualAddress - * Supplies the base virtual address of the paged pool allocation to free. + * Supplies the base virtual address of the pages allocation to free. * * @return This routine returns a status code. * @@ -493,6 +551,48 @@ MM::Allocator::FreePages(IN PVOID VirtualAddress) } } +/** + * Frees a previously allocated memory pool. + * + * @param VirtualAddress + * Supplies the base virtual address of the pool allocation to free. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +MM::Allocator::FreePool(IN PVOID VirtualAddress) +{ + /* Free pool */ + return FreePool(VirtualAddress, SIGNATURE32('N', 'o', 'n', 'e')); +} + +/** + * Frees a previously allocated memory pool. + * + * @param VirtualAddress + * Supplies the base virtual address of the pool allocation to free. + * + * @param Tag + * Specifies the allocation identifying tag. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +MM::Allocator::FreePool(IN PVOID VirtualAddress, + IN ULONG Tag) +{ + UNIMPLEMENTED; + + /* Free pages */ + return FreePages(VirtualAddress); +} + /** * Initializes the non-paged pool for memory allocator. *