From 95e33f7f9362aadd9c6169b41437ca478aa3be14 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 31 Jul 2021 14:36:56 +0200 Subject: kmalloc() and kfree() stubs --- src/kernel/mem.c | 10 ++++++++++ src/kernel/mem.h | 3 +++ src/kernel/proc.c | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/kernel/mem.c b/src/kernel/mem.c index 5684bb7..19a10a9 100644 --- a/src/kernel/mem.c +++ b/src/kernel/mem.c @@ -25,3 +25,13 @@ void *page_alloc(size_t pages) { void page_free(void *first, size_t pages) { // not implemented } + + +void *kmalloc(size_t len) { + // extremely inefficient, but this is only temporary anyways + return page_alloc(len / PAGE_SIZE + 1); +} + +void kfree(void *ptr) { + // unimplemented +} diff --git a/src/kernel/mem.h b/src/kernel/mem.h index f608bb8..b17ba30 100644 --- a/src/kernel/mem.h +++ b/src/kernel/mem.h @@ -9,3 +9,6 @@ void *page_alloc(size_t pages); // frees `pages` consecutive pages starting from *first void page_free(void *first, size_t pages); + +void *kmalloc(size_t len); +void kfree(void *ptr); diff --git a/src/kernel/proc.c b/src/kernel/proc.c index 8a80754..b705324 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -8,7 +8,7 @@ struct process *process_first; struct process *process_current; struct process *process_seed() { - struct process *proc = page_alloc(1); // TODO kmalloc + struct process *proc = kmalloc(sizeof(struct process)); proc->pages = pagedir_new(); proc->state = PS_RUNNING; proc->next = NULL; @@ -30,7 +30,7 @@ struct process *process_seed() { } struct process *process_clone(struct process *orig) { - struct process *clone = page_alloc(1); + struct process *clone = kmalloc(sizeof(struct process)); memcpy(clone, orig, sizeof(struct process)); clone->pages = pagedir_copy(orig->pages); orig->next = clone; -- cgit v1.2.3