From 6a6717b1e4f3f85a09fa48ee11e5421771995493 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 26 Apr 2024 16:38:41 -0400 Subject: kernel: Implement basic loader_unload() Signed-off-by: Ian Moffett --- sys/include/sys/loader.h | 1 + sys/kern/kern_loader.c | 12 ++++++++++++ sys/kern/kern_sched.c | 2 ++ 3 files changed, 15 insertions(+) diff --git a/sys/include/sys/loader.h b/sys/include/sys/loader.h index 297c18d..9b38a55 100644 --- a/sys/include/sys/loader.h +++ b/sys/include/sys/loader.h @@ -62,6 +62,7 @@ struct auxval { #if defined(_KERNEL) +int loader_unload(struct vas vas, struct vm_range *exec_range); int loader_load(struct vas vas, const void *dataptr, struct auxval *auxv, size_t load_base, char **ld_path, struct vm_range *prog_range); diff --git a/sys/kern/kern_loader.c b/sys/kern/kern_loader.c index e62e2b4..a7f15e5 100644 --- a/sys/kern/kern_loader.c +++ b/sys/kern/kern_loader.c @@ -53,6 +53,18 @@ __KERNEL_META("$Hyra$: kern_loader.c, Ian Marco Moffett, " #define PHDR(hdrptr, IDX) \ (void *)((uintptr_t)hdr + (hdrptr)->e_phoff + (hdrptr->e_phentsize*IDX)) +int +loader_unload(struct vas vas, struct vm_range *exec_range) +{ + size_t start, end; + + start = exec_range->start; + end = exec_range->end; + + /* FIXME: Figure out how to free physical memory too */ + return vm_map_destroy(vas, start, (end - start)); +} + int loader_load(struct vas vas, const void *dataptr, struct auxval *auxv, size_t load_base, char **ld_path, struct vm_range *prog_range) { diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 1f302d9..1b4c987 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -308,6 +308,7 @@ static void sched_destroy_td(struct proc *td) { const struct vm_range *stack_range = &td->addr_range[ADDR_RANGE_STACK]; + struct vm_range *exec_range = &td->addr_range[ADDR_RANGE_EXEC]; vm_mapq_t *mapq; processor_free_pcb(td); @@ -334,6 +335,7 @@ sched_destroy_td(struct proc *td) vm_free_mapq(mapq); } + loader_unload(td->addrsp, exec_range); pmap_free_vas(vm_get_ctx(), td->addrsp); dynfree(td); } -- cgit v1.2.3