From 2dfecbfa898c7db2f5039c81c23a8475966ecfef Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 26 May 2022 21:45:34 +0200 Subject: syscalls/memflag: FINDFREE flag --- src/kernel/arch/i386/pagedir.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/kernel/arch/i386/pagedir.c') diff --git a/src/kernel/arch/i386/pagedir.c b/src/kernel/arch/i386/pagedir.c index 28608dc..e607cc7 100644 --- a/src/kernel/arch/i386/pagedir.c +++ b/src/kernel/arch/i386/pagedir.c @@ -184,3 +184,23 @@ void *pagedir_virt2phys(struct pagedir *dir, const void __user *virt, phys |= ((uintptr_t)virt) & 0xFFF; return (void*)phys; } + +void __user *pagedir_findfree(struct pagedir *dir, char __user *start, size_t len) { + struct pagetable_entry *page; + char __user *iter; + start = (userptr_t)(((uintptr_t __force)start + PAGE_MASK) & ~PAGE_MASK); // round up to next page + iter = start; + + while (iter < (char __user *)0xFFF00000) { // TODO better boundary + page = get_entry(dir, iter); + if (page && page->present) { + start = iter + PAGE_SIZE; + } else { + if ((size_t)(iter + PAGE_SIZE - start) >= len) + return start; + } + iter += PAGE_SIZE; + } + + return NULL; +} -- cgit v1.2.3