summaryrefslogtreecommitdiffhomepage
path: root/dev/libDDK/src/ddk_alloc.c
blob: 09f3034f29b273a1583d19c01be2dfed75b06d33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* ========================================

  Copyright Amlal El Mahrouss.

  Purpose: DDK allocator.

======================================== */

#include <DriverKit/ddk.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);
}