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/sys/proc.h | 3 +++ sys/include/sys/syscall.h | 2 ++ sys/include/vm/map.h | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) (limited to 'sys/include') diff --git a/sys/include/sys/proc.h b/sys/include/sys/proc.h index 09aebf5..f74d1da 100644 --- a/sys/include/sys/proc.h +++ b/sys/include/sys/proc.h @@ -38,6 +38,7 @@ #include #include #include +#include #define PROC_MAX_FDS 256 #define PROC_MAX_ADDR_RANGE 4 @@ -62,6 +63,8 @@ struct proc { uint8_t is_user; uint32_t signal; struct filedesc *fds[PROC_MAX_FDS]; + struct spinlock mapspace_lock; + struct vm_mapspace mapspace; TAILQ_ENTRY(proc) link; }; diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h index 8ebc2da..59b6036 100644 --- a/sys/include/sys/syscall.h +++ b/sys/include/sys/syscall.h @@ -43,6 +43,8 @@ enum { SYS_close, SYS_read, SYS_lseek, + SYS_mmap, + SYS_munmap, __MAX_SYSCALLS }; 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