From 6fb77c70559782a9928432af5cc6f83906a530c1 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 24 Jan 2026 23:24:45 +0200 Subject: make physical memory request a capability + Seems obvious, not sure why I hadn't done it already --- include/kmi/syscalls.h | 5 ++++- src/proc.c | 4 +--- src/uapi/mem.c | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/kmi/syscalls.h b/include/kmi/syscalls.h index a4d2c52..30e46be 100644 --- a/include/kmi/syscalls.h +++ b/include/kmi/syscalls.h @@ -291,7 +291,10 @@ enum sys_cap { CAP_SIGNAL = (1 << 6), /** Thread is allowed to request shared memory */ - CAP_SHARED = (1 << 7) + CAP_SHARED = (1 << 7), + + /** Thread is allowed to request physical memory */ + CAP_PHYSICAL = (1 << 8), }; /** diff --git a/src/proc.c b/src/proc.c index 090ae20..0283117 100644 --- a/src/proc.c +++ b/src/proc.c @@ -46,9 +46,7 @@ stat_t init_proc(void *fdt, vm_t *proc_fdt, vm_t *proc_initrd) t->notify_id = t->tid; /* init process has all capabilities */ - set_caps(t->caps, - CAP_CAPS | CAP_PROC | CAP_SIGNAL | CAP_POWER | CAP_NOTIFY | - CAP_SHARED); + set_caps(t->caps, ~0); /* we shall try to map the fdt and initrd into the new address space, so * save them here before we switch */ diff --git a/src/uapi/mem.c b/src/uapi/mem.c index 5c18797..561b5eb 100644 --- a/src/uapi/mem.c +++ b/src/uapi/mem.c @@ -100,6 +100,9 @@ SYSCALL_DEFINE3(req_pmem)(struct tcb *t, sys_arg_t paddr, sys_arg_t size, * that keeps track of used regions outside of RAM. We'll see. */ struct tcb *r = get_cproc(t); + if (!has_cap(r->caps, CAP_PHYSICAL)) + return_args1(t, ERR_PERM); + flags = sanitize_uvflags(flags); vm_t start = alloc_devmem(r, paddr, size, flags); if (ERR_CODE(start)) -- cgit v1.3