Kernel: Add basic fixed width allocator for userspace

We have to move process stacks to the general heap and maybe map
kernel to higher half.
This commit is contained in:
Bananymous
2023-05-06 18:10:38 +03:00
parent 9c07add00f
commit bcfd838131
10 changed files with 267 additions and 9 deletions

View File

@@ -1,8 +1,10 @@
#include <BAN/Assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
extern "C" void _fini();
@@ -55,9 +57,15 @@ char* getenv(const char*)
return nullptr;
}
void* malloc(size_t)
void* malloc(size_t bytes)
{
return nullptr;
long ret = syscall(SYS_ALLOC, bytes);
if (ret < 0)
{
errno = -ret;
return nullptr;
}
return (void*)ret;
}
void* calloc(size_t nmemb, size_t size)

View File

@@ -68,6 +68,12 @@ long syscall(long syscall, ...)
ret = Kernel::syscall(SYS_OPEN, path, oflags);
break;
}
case SYS_ALLOC:
{
size_t bytes = va_arg(args, size_t);
ret = Kernel::syscall(SYS_ALLOC, bytes);
break;
}
default:
puts("LibC: Unhandeled syscall");
}