Implement proc_map () and proc_unmap () syscalls
All checks were successful
Build documentation / build-and-deploy (push) Successful in 21s

This commit is contained in:
2026-01-06 23:32:11 +01:00
parent 9f107a1a5e
commit 28aef30f77
15 changed files with 155 additions and 18 deletions

View File

@@ -1,28 +1,63 @@
#include <aux/compiler.h>
#include <libk/std.h>
#include <m/syscall_defs.h>
#include <mm/pmm.h>
#include <proc/proc.h>
#include <sys/debug.h>
#include <sys/mm.h>
#include <syscall/syscall.h>
#define DEFINE_SYSCALL(name) \
int name (struct proc* proc, uintptr_t UNUSED a1, uintptr_t UNUSED a2, uintptr_t UNUSED a3, \
uintptr_t UNUSED a4, uintptr_t UNUSED a5, uintptr_t UNUSED a6)
/* int proc_quit (void) */
DEFINE_SYSCALL (sys_proc_quit) {
proc_kill (proc);
proc_sched ();
return SR_OK;
}
/* int proc_test (void) */
DEFINE_SYSCALL (sys_proc_test) {
DEBUG ("test syscall message!\n");
return SR_OK;
}
/* int proc_map (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;
if (vaddr % PAGE_SIZE != 0)
return -SR_UNALIGNED;
uintptr_t paddr = pmm_alloc (pages);
if (paddr == PMM_ALLOC_ERR)
return -SR_OOM_ERROR;
bool ok = proc_map (proc, paddr, vaddr, pages, flags);
return ok ? SR_OK : -SR_OOM_ERROR;
}
/* int proc_unmap (uintptr_t vaddr, size_t pages) */
DEFINE_SYSCALL (sys_proc_unmap) {
uintptr_t vaddr = a1;
size_t pages = (size_t)a2;
if (vaddr % PAGE_SIZE != 0)
return -SR_UNALIGNED;
bool ok = proc_unmap (proc, vaddr, pages);
return ok ? SR_OK : -SR_OOM_ERROR;
}
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,
};
syscall_handler_func_t syscall_find_handler (int syscall_num) {