diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/include/compat/unix/syscall.h | 4 | ||||
-rw-r--r-- | src/sys/include/sys/mman.h | 5 | ||||
-rw-r--r-- | src/sys/include/sys/syscall.h | 1 | ||||
-rw-r--r-- | src/sys/include/vm/map.h | 6 | ||||
-rw-r--r-- | src/sys/vm/vm_map.c | 57 |
5 files changed, 72 insertions, 1 deletions
diff --git a/src/sys/include/compat/unix/syscall.h b/src/sys/include/compat/unix/syscall.h index 9b76139..5df3c51 100644 --- a/src/sys/include/compat/unix/syscall.h +++ b/src/sys/include/compat/unix/syscall.h @@ -39,6 +39,7 @@ #include <os/iotap.h> #include <os/reboot.h> #include <dms/dms.h> +#include <vm/map.h> /* * Exit the current process - exit(2) syscall @@ -100,7 +101,8 @@ scret_t(*g_unix_sctab[])(struct syscall_args *) = { [SYS_lseek] = sys_lseek, [SYS_socket] = sys_socket, [SYS_listen] = sys_listen, - [SYS_seteuid] = sys_seteuid + [SYS_seteuid] = sys_seteuid, + [SYS_mmap] = sys_mmap }; #endif /* !_NEED_UNIX_SCTAB */ diff --git a/src/sys/include/sys/mman.h b/src/sys/include/sys/mman.h index 7ae1ed2..b688fdd 100644 --- a/src/sys/include/sys/mman.h +++ b/src/sys/include/sys/mman.h @@ -39,4 +39,9 @@ #define PROT_USER BIT(3) #endif /* _KERNEL */ +/* + * Map memory pages + */ +void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off); + #endif /* !_SYS_MMAN_H_ */ diff --git a/src/sys/include/sys/syscall.h b/src/sys/include/sys/syscall.h index d148405..ee6ef48 100644 --- a/src/sys/include/sys/syscall.h +++ b/src/sys/include/sys/syscall.h @@ -62,6 +62,7 @@ #define SYS_socket 0x11 /* get a socket fd */ #define SYS_listen 0x12 /* listen on a socket */ #define SYS_seteuid 0x13 /* set effective UID */ +#define SYS_mmap 0x14 /* map a virtual address */ typedef __ssize_t scret_t; typedef __ssize_t scarg_t; diff --git a/src/sys/include/vm/map.h b/src/sys/include/vm/map.h index 69d7d73..8183b62 100644 --- a/src/sys/include/vm/map.h +++ b/src/sys/include/vm/map.h @@ -31,6 +31,7 @@ #define _VM_MAP_H_ 1 #include <sys/types.h> +#include <sys/syscall.h> #include <sys/mman.h> #include <machine/vas.h> /* standard */ #include <vm/mmu.h> @@ -52,4 +53,9 @@ */ int vm_map(struct vm_vas *vas, struct mmu_map *spec, size_t len, int prot); +/* + * POSIX mmap syscall + */ +scret_t sys_mmap(struct syscall_args *scargs); + #endif /* !_VM_MAP_H_ */ 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); +} |