summaryrefslogtreecommitdiffhomepage
path: root/DDKit/KernelAlloc.c
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-07-30 08:49:23 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-07-30 08:49:23 +0200
commitbf642edd6c77d405637f0695452460640b8e540d (patch)
treee8e78f658e5eac62790a0fb8129a491183db92d5 /DDKit/KernelAlloc.c
parent60902ec5fc462128d264f63f279c7fc362a72e1d (diff)
[Refactor] SCIKit and DDKit.
[IMP} Prevent DDK from being included when we aren't in kernel mode. Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'DDKit/KernelAlloc.c')
-rw-r--r--DDKit/KernelAlloc.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/DDKit/KernelAlloc.c b/DDKit/KernelAlloc.c
new file mode 100644
index 00000000..f1044324
--- /dev/null
+++ b/DDKit/KernelAlloc.c
@@ -0,0 +1,34 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies
+
+ Purpose: DDK allocator.
+
+------------------------------------------- */
+
+#include <DDKit/KernelStd.h>
+
+/**
+ \brief Allocates a new heap on the kernel's side.
+ \param sz the size of the heap block.
+ \return the newly allocated pointer.
+*/
+DK_EXTERN void* kernelAlloc(size_t sz)
+{
+ if (!sz) ++sz;
+
+ void* ptr = kernelCall("NewHeap", 1, &sz, sizeof(size_t));
+
+ return ptr;
+}
+
+/**
+ \brief Frees a pointer from the heap.
+ \param ptr the pointer to free.
+*/
+DK_EXTERN void kernelFree(void* ptr)
+{
+ if (!ptr) return;
+
+ kernelCall("DeleteHeap", 1, ptr, 0);
+}