aboutsummaryrefslogtreecommitdiff
path: root/sys/include
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-04-16 20:10:07 -0400
committerIan Moffett <ian@osmora.org>2024-04-16 20:10:07 -0400
commit0d8da6f5436874c1dd987b53d11a3d3aea468f67 (patch)
tree02bcff6e0a18633d8318269cb23780f775d99727 /sys/include
parent9a26f4d453b1742c6249d66a077a175120e23338 (diff)
kernel: vm_map: Add mmap() and munmap()
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/include')
-rw-r--r--sys/include/sys/proc.h3
-rw-r--r--sys/include/sys/syscall.h2
-rw-r--r--sys/include/vm/map.h38
3 files changed, 43 insertions, 0 deletions
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 <machine/frame.h>
#include <machine/pcb.h>
#include <vm/vm.h>
+#include <vm/map.h>
#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 <sys/types.h>
#include <sys/cdefs.h>
+#include <sys/queue.h>
+#include <sys/syscall.h>
+#include <sys/spinlock.h>
#include <vm/pmap.h>
+#include <vm/vm.h>
+
+#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_ */