aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-07-17 00:26:09 -0400
committerIan Moffett <ian@osmora.org>2024-07-17 00:41:57 -0400
commite234e602429ebe82836d2f6cae730f2a11dc2fc0 (patch)
tree65f1d837572ef3bba08f06fb25dc40f11c3705d1
parent2be1c778a4dfe2c6ebb371b457c1e1dc9e89c98d (diff)
kernel: exit: Unload thread in exit1()
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/kern/kern_exit.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 04490b0..3f8f17e 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -29,9 +29,43 @@
#include <sys/proc.h>
#include <sys/sched.h>
+#include <sys/syslog.h>
#include <vm/physmem.h>
#include <vm/dynalloc.h>
#include <vm/vm.h>
+#include <vm/map.h>
+#include <machine/pcb.h>
+
+#define pr_trace(fmt, ...) kprintf("exit: " fmt, ##__VA_ARGS__)
+#define pr_error(...) pr_trace(__VA_ARGS__)
+
+static void
+unload_td(struct proc *td)
+{
+ const struct auxval *auxvalp;
+ struct exec_prog *execp;
+ struct exec_range *range;
+ struct pcb *pcbp;
+ size_t len;
+
+ execp = &td->exec;
+ auxvalp = &execp->auxval;
+ pcbp = &td->pcb;
+
+ for (size_t i = 0; i < auxvalp->at_phnum; ++i) {
+ range = &execp->loadmap[i];
+ len = (range->end - range->start);
+
+ /* Attempt to unmap the range */
+ if (vm_unmap(pcbp->addrsp, range->vbase, len) != 0) {
+ pr_error("Failed to unmap %p - %p (pid=%d)\n",
+ range->start, range->end, td->pid);
+ }
+
+ /* Free the physical memory */
+ vm_free_frame(range->start, len / DEFAULT_PAGESIZE);
+ }
+}
/*
* Kill a thread and deallocate its resources.
@@ -63,7 +97,10 @@ exit1(struct proc *td)
stack -= VM_HIGHER_HALF;
}
+ unload_td(td);
+ vm_unmap(pcbp->addrsp, td->stack_base, PROC_STACK_SIZE);
vm_free_frame(stack, PROC_STACK_PAGES);
+
pmap_destroy_vas(pcbp->addrsp);
dynfree(td);