From 1142699c4811061972bfaeb08cfff7a7820b0d15 Mon Sep 17 00:00:00 2001 From: xamidev Date: Sun, 10 May 2026 19:36:01 +0200 Subject: [PATCH] Alloc extra pages for raw binary --- include/config.h | 2 ++ src/mem/vmm.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/config.h b/include/config.h index 11c6fe9..55d9c6f 100644 --- a/include/config.h +++ b/include/config.h @@ -44,6 +44,8 @@ #define USER_STACK_TOP 0x80000000 #define USER_STACK_PAGES 16 // 16*4096 = 64kb #define USER_CODE_START 0x400000 // like linux +#define USER_RAW_EXTRA_PAGES 8192 // Extra writable pages after raw image for .bss/heap + // TODO: throw this away and make an ELF loader instead bruh /* paging */ #define PAGING_MAX_PHYS 0x200000000 diff --git a/src/mem/vmm.c b/src/mem/vmm.c index 2c851de..6ad0af9 100644 --- a/src/mem/vmm.c +++ b/src/mem/vmm.c @@ -18,6 +18,7 @@ compared to the PMM which allocs/frees 4kb frames ("physical pages"). #include #include #include +#include #include extern uint64_t *kernel_pml4; @@ -116,6 +117,8 @@ void* vmm_map(uint64_t* pml4, uint64_t virt, uint64_t flags) panic(NULL, "VMM/PMM out of memory!"); } + memset(PHYS_TO_VIRT(phys), 0, PAGE_SIZE); + paging_map_page(pml4, virt, phys, flags | PTE_PRESENT); return (void*)virt; } @@ -255,8 +258,9 @@ uintptr_t vmm_alloc_user_code(uint64_t* pml4, void* code_addr, uint64_t code_siz // Round code_size up to next page boundary uint64_t code_size_aligned = (code_size + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1); + uint64_t mapped_size = code_size_aligned + ((uint64_t)USER_RAW_EXTRA_PAGES * PAGE_SIZE); - for (uint64_t i=code_start; i