From: Tulio A M Mendes Date: Fri, 6 Feb 2026 11:42:02 +0000 (-0300) Subject: sched: make early allocations safe under higher-half/identity constraints X-Git-Url: https://projects.tadryanom.me/?a=commitdiff_plain;h=b17d325f20e759fa8e5b2999b81c689a4fbcd678;p=AdrOS.git sched: make early allocations safe under higher-half/identity constraints --- diff --git a/src/kernel/scheduler.c b/src/kernel/scheduler.c index 5c13a305..742103fb 100644 --- a/src/kernel/scheduler.c +++ b/src/kernel/scheduler.c @@ -29,7 +29,8 @@ static void* pmm_alloc_page_low(void) { for (int tries = 0; tries < 1024; tries++) { void* p = pmm_alloc_page(); if (!p) return 0; - if ((uint32_t)p < 0x00400000) { + // boot.S currently identity-maps a large low window; keep allocations within it. + if ((uint32_t)p < 0x20000000) { return p; } // Not safe to touch yet; put it back. @@ -45,6 +46,11 @@ void process_init(void) { // Initial Kernel Thread (PID 0) - IDLE TASK struct process* kernel_proc = (struct process*)pmm_alloc_page_low(); + if (!kernel_proc) { + spin_unlock_irqrestore(&sched_lock, flags); + uart_print("[SCHED] OOM allocating kernel process struct.\n"); + for(;;) hal_cpu_idle(); + } kernel_proc->pid = 0; kernel_proc->state = PROCESS_RUNNING;