diff options
Diffstat (limited to 'src/libDDK/src/KernelAllocator.cpp')
| -rw-r--r-- | src/libDDK/src/KernelAllocator.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libDDK/src/KernelAllocator.cpp b/src/libDDK/src/KernelAllocator.cpp new file mode 100644 index 00000000..f2dd7b45 --- /dev/null +++ b/src/libDDK/src/KernelAllocator.cpp @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (See accompanying +// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0) +// Official repository: https://github.com/ne-foss-org/ne_kernel + +#include <DriverKit/DriverKit.h> + +/** + \brief Allocates a new heap on the Kernel's side. + \param sz the size of the heap block. + \return the newly allocated pointer. +*/ +DDK_EXTERN void* kalloc(size_t sz) { + if (!sz) ++sz; + + void* ptr = ::ke_call_dispatch("mm_alloc_ptr", 1, &sz, sizeof(size_t)); + + return ptr; +} + +/** + \brief Frees a pointer from the heap. + \param ptr the pointer to free. +*/ +DDK_EXTERN void kfree(void* ptr) { + if (!ptr) return; + + ::ke_call_dispatch("mm_free_ptr", 1, ptr, 0); +} |
