From 50e1b103669a334d31bb27d7d858400c7a12e29e Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 19 Sep 2025 23:29:18 -0400 Subject: kern: proc: Keep track of mapped areas with ranges This commit adds a virtual memory range queue to the process descriptor in order to keep track of mapped pages and free their respective frames upon program exit. Signed-off-by: Ian Moffett --- src/sys/include/sys/proc.h | 18 ++++++++++++++++++ src/sys/include/vm/vm.h | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'src/sys/include') diff --git a/src/sys/include/sys/proc.h b/src/sys/include/sys/proc.h index 200d5ce..cf00850 100644 --- a/src/sys/include/sys/proc.h +++ b/src/sys/include/sys/proc.h @@ -35,6 +35,7 @@ #include #include #include +#include #include /* standard */ /* @@ -52,6 +53,7 @@ * @flags: State flags (see PROC_*) * @pcb: Process control block * @scdom: Syscall domain + * @maplist: List of mapped regions * @link: TAILQ link */ struct proc { @@ -59,6 +61,7 @@ struct proc { uint32_t flags; struct md_pcb pcb; struct syscall_domain scdom; + TAILQ_HEAD(, vm_range) maplist; TAILQ_ENTRY(proc) link; }; @@ -82,6 +85,21 @@ int proc_init(struct proc *procp, int flags); */ struct proc *proc_self(void); +/* + * Allocate a range descriptor and add it to the + * process's range tracking list for cleanup upon + * exit. + * + * @procp: Process to initialize the range of + * @va: Virtual address to use + * @pa: Physical address to use + * @len: Length to use + * + * Returns zero on success, otherwise a less than + * zero value upon error. + */ +int proc_add_range(struct proc *procp, vaddr_t va, paddr_t pa, size_t len); + /* * Kill a process with a specific status code * diff --git a/src/sys/include/vm/vm.h b/src/sys/include/vm/vm.h index 790fe0b..f5f7b16 100644 --- a/src/sys/include/vm/vm.h +++ b/src/sys/include/vm/vm.h @@ -31,6 +31,7 @@ #define _VM_H_ 1 #include +#include #include #define VM_HIGHER_HALF (get_kernel_base()) @@ -42,6 +43,21 @@ typedef uintptr_t vaddr_t; typedef uintptr_t paddr_t; +/* + * Describes a virtual memory range + * + * @pa_base: Physical memory base + * @va_base: Virtual memory base + * @len: Length of region + * @link: Queue link + */ +struct vm_range { + paddr_t pa_base; + vaddr_t va_base; + size_t len; + TAILQ_ENTRY(vm_range) link; +}; + void vm_init(void); #endif /* !_VM_H_ */ -- cgit v1.2.3