summaryrefslogtreecommitdiffhomepage
path: root/dev/ddk/src/ddk_alloc.c
blob: 0b428b15d794920d11f7730e39b95d19b1fb0814 (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 <DDKKit/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("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("mm_free_ptr", 1, ptr, 0);
}