diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-19 23:14:23 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-19 23:22:21 -0400 |
commit | f8411d1f1a4765ce38e63f4b3304d72cbfddad6f (patch) | |
tree | 4fe1f21427e834636f601b3958c88f25464bce49 /src/sys/vm | |
parent | 6b2d1153852a7f0121d6514cb4d7e5dc6baa7e39 (diff) |
kern: vm: Introduce initial mmap() impldev
- Adds kernel mmap() function
- Adds SYS_mmap syscall
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys/vm')
-rw-r--r-- | src/sys/vm/vm_map.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/sys/vm/vm_map.c b/src/sys/vm/vm_map.c index f299b34..1d801af 100644 --- a/src/sys/vm/vm_map.c +++ b/src/sys/vm/vm_map.c @@ -30,12 +30,16 @@ #include <sys/types.h> #include <sys/param.h> #include <sys/errno.h> +#include <sys/param.h> #include <sys/syslog.h> #include <vm/physseg.h> #include <vm/mmu.h> #include <vm/map.h> #include <vm/vm.h> +#define MMAP_START 0x6F3C8E0C0000 +#define MMAP_END 0x6F3C90000000 + /* * Create a virtual to physical memory * mapping @@ -137,3 +141,56 @@ vm_map(struct vm_vas *vas, struct mmu_map *spec, size_t len, int prot) __vm_map(vas, &spec_cpy, DEFAULT_PAGESIZE, 0); return 0; } + +void * +mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) +{ + struct mmu_map spec; + struct vm_vas vas; + paddr_t pa; + int error; + + /* TODO: Support address allocation */ + if (len == 0 || addr == NULL) { + return NULL; + } + + spec.va = (uintptr_t)addr; + spec.pa = 0; + error = mmu_this_vas(&vas); + if (error < 0) { + return NULL; + } + + /* Create the mapping */ + error = vm_map(&vas, &spec, len, prot); + if (error < 0) { + return NULL; + } + + return (void *)spec.va; +} + +/* + * ARG0: Address + * ARG1: Length + * ARG2: Protection flags + * ARG3: Flags + * ARG4: Fildes + * ARG5: Offset + */ +scret_t +sys_mmap(struct syscall_args *scargs) +{ + void *address = SCARG(scargs, void *, 0); + size_t length = SCARG(scargs, size_t, 1); + int prot = SCARG(scargs, int, 2); + + prot |= PROT_USER; + if (address != NULL) { + address = PTR_OFFSET(address, MMAP_START); + } + + /* XXX: Should use rest of the args */ + return (uintptr_t)mmap(address, length, prot, 0, 0, 0); +} |