summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-06-08 23:56:36 -0400
committerIan Moffett <ian@osmora.org>2025-06-08 23:59:09 -0400
commit8dae807a20913aa7210ed1dc2927c1f85187dbb2 (patch)
tree3637d7b6c7892e6de074ca617b55e63a9b16f59c /sys/kern
parentadd9905af1b34d6592903c591177f37cc23e4f0d (diff)
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 <ian@osmora.org>
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_exit.c23
1 files 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);
}