From 8dae807a20913aa7210ed1dc2927c1f85187dbb2 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 8 Jun 2025 23:56:36 -0400 Subject: kernel: exit: Handle stack VA/PA in proc_reap() User stacks are identity mapped and kernel stacks are not. Handle this properly or else suffer the consequences. Signed-off-by: Ian Moffett --- sys/kern/kern_exit.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 58d4506..0f90365 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -82,23 +82,26 @@ void proc_reap(struct proc *td) { struct pcb *pcbp; - uintptr_t stack; + vaddr_t stack_va; + paddr_t stack_pa; pcbp = &td->pcb; - stack = td->stack_base; + unload_td(td); /* - * If this is on the higher half, it is kernel - * mapped and we need to convert it to a physical - * address. + * User space stacks are identity mapped and + * kernel space stacks are not. */ - if (stack >= VM_HIGHER_HALF) { - stack -= VM_HIGHER_HALF; + if (ISSET(td->flags, PROC_KTD)) { + stack_va = td->stack_base; + stack_pa = td->stack_base - VM_HIGHER_HALF; + } else { + stack_va = td->stack_base; + stack_pa = td->stack_base; + vm_unmap(pcbp->addrsp, stack_va, PROC_STACK_SIZE); } - unload_td(td); - vm_unmap(pcbp->addrsp, td->stack_base, PROC_STACK_SIZE); - vm_free_frame(stack, PROC_STACK_PAGES); + vm_free_frame(stack_pa, PROC_STACK_PAGES); pmap_destroy_vas(pcbp->addrsp); } -- cgit v1.2.3