From 1bf901c803bff3393d0cc9dfe76fc9f025cecb1c Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 12 Sep 2021 14:59:47 +0200 Subject: barebones `memflag()` implementation - letting the user allocate pages --- src/kernel/syscalls.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/kernel') diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 21c1b72..1180197 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -221,6 +222,25 @@ int _syscall_fs_wait(handle_t back, char __user *buf, int __user *len) { } } +int _syscall_memflag(void __user *addr, size_t len, int flags) { + userptr_t goal = addr + len; + struct pagedir *pages = process_current->pages; + if (flags != MEMFLAG_PRESENT) panic(); // currently only allocation is implemented + + addr = (userptr_t)((int)addr & ~PAGE_MASK); // align to page boundary + for (; addr < goal; addr += PAGE_SIZE) { + if (pagedir_virt2phys(pages, addr, false, false)) { + // allocated page, currently a no-op + // if you'll be changing this - remember to check if the pages are owned by the kernel! + } else { + // allocate the new pages + pagedir_map(pages, addr, page_alloc(1), true, true); + } + } + + return -1; +} + int syscall_handler(int num, int a, int b, int c) { switch (num) { case _SYSCALL_EXIT: @@ -243,6 +263,8 @@ int syscall_handler(int num, int a, int b, int c) { return _syscall_fs_create((userptr_t)a); case _SYSCALL_FS_WAIT: return _syscall_fs_wait(a, (userptr_t)b, (userptr_t)c); + case _SYSCALL_MEMFLAG: + return _syscall_memflag((userptr_t)a, b, c); default: tty_const("unknown syscall "); panic(); -- cgit v1.2.3