From c1d3ac750b8483c9a942d2fb5d5b7245d014e905 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 13 Jul 2024 23:37:37 +0200 Subject: kernel/malloc: limit the maximum allocation size to under a page This will likely be changed back, but for the time being it will let me implement a better allocator without too much effort. --- src/kernel/malloc.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/kernel/malloc.c') diff --git a/src/kernel/malloc.c b/src/kernel/malloc.c index 8ba00dc..ba1ab42 100644 --- a/src/kernel/malloc.c +++ b/src/kernel/malloc.c @@ -116,6 +116,7 @@ mem_debugprint(void) void *page_alloc(size_t pages) { + assert(pages == 1); /* not using that assertion... yet */ /* i do realize how painfully slow this is */ size_t streak = 0; for (size_t i = pbitmap_firstfree; i < pbitmap_len * 8; i++) { @@ -177,7 +178,11 @@ void Allocation *hdr; void *addr; + if (KMALLOC_MAX < len) { + panic_invalid_state(); + } len += sizeof(Allocation); + assert(len <= PAGE_SIZE); hdr = page_alloc(page_amt(len)); hdr->magic = MALLOC_MAGIC; hdr->len = len; -- cgit v1.2.3