#include <lunaix/mm/kalloc.h>
#include <lunaix/mm/dmm.h>
-#include <lunaix/constants.h>
+#include <lunaix/common.h>
#include <lunaix/spike.h>
-#include <libc/string.h>
+#include <klibc/string.h>
#include <stdint.h>
extern uint8_t __kernel_heap_start;
-heap_context_t __kalloc_kheap;
+// FIXME: This should go to PCB once we're started to support multitasking
+static heap_context_t __kalloc_kheap;
void*
lx_malloc_internal(heap_context_t* heap, size_t size);
}
void*
-lxcalloc(size_t size) {
- void* ptr = lxmalloc(size);
+lxcalloc(size_t n, size_t elem) {
+ size_t pd = n * elem;
+
+ // overflow detection
+ if (pd < elem || pd < n) {
+ return NULL;
+ }
+
+ void* ptr = lxmalloc(pd);
if (!ptr) {
return NULL;
}
- return memset(ptr, 0, size);
+ return memset(ptr, 0, pd);
}
void