X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/b0c2a4be2d1f4f93ab01d0858979a12ef0735ec1..a0655e5d30f3cdc73b1aaaa4825d8fae9f92ce4a:/lunaix-os/kernel/mm/kalloc.c diff --git a/lunaix-os/kernel/mm/kalloc.c b/lunaix-os/kernel/mm/kalloc.c index 675a51f..16c1d82 100644 --- a/lunaix-os/kernel/mm/kalloc.c +++ b/lunaix-os/kernel/mm/kalloc.c @@ -14,16 +14,17 @@ #include #include -#include +#include #include -#include +#include #include 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); @@ -82,13 +83,20 @@ lxmalloc(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