From 0d8da6f5436874c1dd987b53d11a3d3aea468f67 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 16 Apr 2024 20:10:07 -0400 Subject: kernel: vm_map: Add mmap() and munmap() Signed-off-by: Ian Moffett --- sys/kern/kern_sched.c | 10 ++++++++++ sys/kern/kern_syscall.c | 3 +++ 2 files changed, 13 insertions(+) (limited to 'sys/kern') diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 877c55d..214032a 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -265,6 +265,10 @@ sched_create_td(uintptr_t rip, char *argvp[], char *envp[], struct auxval auxv, td->tf = tf; td->addrsp = vas; td->is_user = is_user; + for (size_t i = 0; i < MTAB_ENTRIES; ++i) { + /* Init the memory mapping table */ + TAILQ_INIT(&td->mapspace.mtab[i]); + } if (prog_range != NULL) { memcpy(exec_range, prog_range, sizeof(struct vm_range)); } @@ -288,6 +292,7 @@ static void sched_destroy_td(struct proc *td) { const struct vm_range *stack_range = &td->addr_range[ADDR_RANGE_STACK]; + vm_mapq_t *mapq; processor_free_pcb(td); @@ -308,6 +313,11 @@ sched_destroy_td(struct proc *td) fd_close_fdnum(td, i); } + for (size_t i = 0; i < MTAB_ENTRIES; ++i) { + mapq = &td->mapspace.mtab[i]; + vm_free_mapq(mapq); + } + pmap_free_vas(vm_get_ctx(), td->addrsp); dynfree(td); } diff --git a/sys/kern/kern_syscall.c b/sys/kern/kern_syscall.c index a630195..b4a86f3 100644 --- a/sys/kern/kern_syscall.c +++ b/sys/kern/kern_syscall.c @@ -32,6 +32,7 @@ #include #include #include +#include __noreturn static uint64_t sys_exit(struct syscall_args *args) @@ -47,4 +48,6 @@ uint64_t(*g_syscall_table[__MAX_SYSCALLS])(struct syscall_args *args) = { sys_close, sys_read, sys_lseek, + sys_mmap, + sys_munmap }; -- cgit v1.2.3