Introduce concept of Process Resources (PR_MEM), implement necessary syscalls
All checks were successful
Build documentation / build-and-deploy (push) Successful in 42s

This commit is contained in:
2026-01-07 22:47:30 +01:00
parent 28aef30f77
commit d7b734306f
16 changed files with 451 additions and 50 deletions

View File

@@ -1,5 +1,6 @@
#include <aux/compiler.h>
#include <libk/std.h>
#include <limine/requests.h>
#include <m/syscall_defs.h>
#include <mm/pmm.h>
#include <proc/proc.h>
@@ -24,18 +25,18 @@ DEFINE_SYSCALL (sys_proc_test) {
return SR_OK;
}
/* int proc_map (uintptr_t vaddr, size_t pages, uint32_t flags) */
/* int proc_map (uintptr_t paddr, uintptr_t vaddr, size_t pages, uint32_t flags) */
DEFINE_SYSCALL (sys_proc_map) {
uintptr_t vaddr = a1;
size_t pages = (size_t)a2;
uint32_t flags = (uint32_t)a3;
uintptr_t paddr = a1;
uintptr_t vaddr = a2;
size_t pages = (size_t)a3;
uint32_t flags = (uint32_t)a4;
if (vaddr % PAGE_SIZE != 0)
return -SR_UNALIGNED;
uintptr_t paddr = pmm_alloc (pages);
if (paddr == PMM_ALLOC_ERR)
return -SR_OOM_ERROR;
if (paddr % PAGE_SIZE != 0)
return -SR_UNALIGNED;
bool ok = proc_map (proc, paddr, vaddr, pages, flags);
return ok ? SR_OK : -SR_OOM_ERROR;
@@ -53,11 +54,64 @@ DEFINE_SYSCALL (sys_proc_unmap) {
return ok ? SR_OK : -SR_OOM_ERROR;
}
/* int proc_create_resource_mem (size_t pages, int vis, uintptr_t* out_paddr) */
DEFINE_SYSCALL (sys_proc_create_resource_mem) {
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
size_t pages = (size_t)a1;
int vis = (int)a2;
uintptr_t* out_paddr_buf = (uintptr_t*)a3;
spin_lock (&proc->pd.lock);
uintptr_t out_paddr_buf_paddr = mm_v2p (&proc->pd, (uintptr_t)out_paddr_buf, 0);
if (!mm_validate_buffer (&proc->pd, (uintptr_t)out_paddr_buf, sizeof (uintptr_t), 0)) {
spin_unlock (&proc->pd.lock);
return -SR_BAD_ADDRESS_SPACE;
}
spin_unlock (&proc->pd.lock);
uintptr_t* out_paddr_buf_vaddr = (uintptr_t*)((uintptr_t)hhdm->offset + out_paddr_buf_paddr);
int rid = atomic_fetch_add (&proc->rids, 1);
struct proc_resource_mem_init mem_init = {.pages = pages};
struct proc_resource* r = proc_create_resource (proc, rid, PR_MEM, vis, &mem_init);
if (r != NULL) {
*out_paddr_buf_vaddr = r->u.mem.paddr;
return r->rid;
} else {
return -SR_OOM_ERROR;
}
}
/* int proc_drop_resource (int rid) */
DEFINE_SYSCALL (sys_proc_drop_resource) {
int rid = (int)a1;
struct proc_resource* resource;
spin_lock (&proc->lock);
rbtree_find (struct proc_resource, &proc->resource_tree, rid, resource, proc_resource_tree_link,
rid);
spin_unlock (&proc->lock);
if (resource == NULL)
return -SR_NOT_FOUND;
proc_drop_resource (proc, resource);
return SR_OK;
}
static syscall_handler_func_t handler_table[] = {
[SYS_PROC_QUIT] = &sys_proc_quit,
[SYS_PROC_TEST] = &sys_proc_test,
[SYS_PROC_MAP] = &sys_proc_map,
[SYS_PROC_UNMAP] = &sys_proc_unmap,
[SYS_PROC_CREATE_RESOURCE_MEM] = &sys_proc_create_resource_mem,
[SYS_PROC_DROP_RESOURCE] = &sys_proc_drop_resource,
};
syscall_handler_func_t syscall_find_handler (int syscall_num) {