Kernel/LibC: add mmap for private anonymous mappings

This will be used by the userspace to get more memory. Currently
kernel handles all allocations, which is not preferable.
This commit is contained in:
Bananymous
2023-09-22 15:41:05 +03:00
parent b9c779ff7e
commit af4af1cae9
7 changed files with 117 additions and 0 deletions

23
libc/sys/mman.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include <sys/mman.h>
#include <sys/syscall.h>
#include <unistd.h>
void* mmap(void* addr, size_t len, int prot, int flags, int fildes, off_t off)
{
sys_mmap_t args {
.addr = addr,
.len = len,
.prot = prot,
.flags = flags,
.off = off
};
long ret = syscall(SYS_MMAP, &args);
if (ret == -1)
return nullptr;
return (void*)ret;
}
int munmap(void* addr, size_t len)
{
return syscall(SYS_MUNMAP, addr, len);
}