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/include/vm/map.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'sys/include/vm/map.h') diff --git a/sys/include/vm/map.h b/sys/include/vm/map.h index 078a5e8..f482788 100644 --- a/sys/include/vm/map.h +++ b/sys/include/vm/map.h @@ -32,11 +32,49 @@ #include #include +#include +#include +#include #include +#include + +#define MAP_SHARED 0x0001 +#define MAP_PRIVATE 0x0002 +#define MAP_ANONYMOUS 0x0010 +#define MAP_FAILED ((void *)-1) + +/* Memory map table entry count */ +#define MTAB_ENTRIES 32 + +struct vm_mapping { + TAILQ_ENTRY(vm_mapping) link; + struct vm_range range; + paddr_t physmem_base; + + /* Private */ + size_t vhash; /* Virtual address hash */ +}; + +typedef TAILQ_HEAD(, vm_mapping) vm_mapq_t; + +struct vm_mapspace { + vm_mapq_t mtab[MTAB_ENTRIES]; /* Map table */ + size_t map_count; +}; + int vm_map_create(struct vas vas, vaddr_t va, paddr_t pa, vm_prot_t prot, size_t bytes); int vm_map_destroy(struct vas vas, vaddr_t va, size_t bytes); +uint64_t sys_mmap(struct syscall_args *args); +uint64_t sys_munmap(struct syscall_args *args); + +/* Mapespace operations */ +void vm_mapspace_insert(struct vm_mapspace *ms, struct vm_mapping *mapping); +void vm_mapspace_remove(struct vm_mapspace *ms, struct vm_mapping *mapping); +struct vm_mapping *vm_mapping_fetch(struct vm_mapspace *ms, vaddr_t va); +void vm_free_mapq(vm_mapq_t *mapq); + #endif /* !_VM_MMAP_H_ */ -- cgit v1.2.3