Port liballoc to userspace

This commit is contained in:
2026-01-16 18:50:40 +01:00
parent 9fc8521e63
commit a054257336
9 changed files with 522 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
#include <alloc/liballoc.h>
#include <limits.h>
#include <m/proc.h>
#include <m/status.h>
#include <stddef.h>
#include <stdint.h>
#include <string/string.h>
@@ -16,17 +18,14 @@ void mythread (void) {
}
}
void make_thread (void* fn) {
size_t stack_pages = 256;
size_t stack_size = PAGE_SIZE * stack_pages;
int make_thread (void (*fn) (void)) {
size_t stack_size = 256 * PAGE_SIZE;
void* stack = malloc (stack_size);
if (stack == NULL)
return -SR_OOM_ERROR;
uintptr_t out_paddr;
int mem_rid = proc_create_resource_mem (100, stack_pages, RV_PRIVATE, &out_paddr);
proc_map (out_paddr, PROC_MAP_BASE, stack_pages, PM_PRESENT | PM_RW | PM_USER);
memset ((void*)PROC_MAP_BASE, 0, stack_size);
uintptr_t vstack_top = PROC_MAP_BASE + stack_size;
proc_spawn_thread (vstack_top, stack_size, fn);
uintptr_t stack_top = (uintptr_t)stack + stack_size;
return proc_spawn_thread (stack_top, stack_size, (void*)fn);
}
void app_main (void) {