summaryrefslogtreecommitdiff
path: root/src/kernel/mem/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/mem/alloc.c')
-rw-r--r--src/kernel/mem/alloc.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/kernel/mem/alloc.c b/src/kernel/mem/alloc.c
index 42a2f3b..51576bb 100644
--- a/src/kernel/mem/alloc.c
+++ b/src/kernel/mem/alloc.c
@@ -4,6 +4,7 @@
#include <stdint.h>
static void *highest_page;
+static int malloc_balance = 0;
void mem_init(struct kmain_info *info) {
// finds the highest used page, and starts allocating pages above it
@@ -16,6 +17,12 @@ void mem_init(struct kmain_info *info) {
highest_page = (void*)(((uintptr_t)highest + PAGE_MASK) & ~PAGE_MASK);
}
+void mem_debugprint(void) {
+ tty_const("malloc balance: ");
+ _tty_var(malloc_balance);
+ tty_const(" ");
+}
+
void *page_alloc(size_t pages) {
void *bottom = highest_page;
highest_page += pages * PAGE_SIZE;
@@ -29,10 +36,12 @@ void page_free(void *first, size_t pages) {
void *kmalloc(size_t len) {
+ malloc_balance++;
// extremely inefficient, but this is only temporary anyways
return page_alloc(len / PAGE_SIZE + 1);
}
void kfree(void *ptr) {
- // unimplemented
+ if (ptr == NULL) return;
+ malloc_balance--;
}