From 465cba0c00bfc5d89bf10ce353b0adf40bdc098d Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Sat, 3 Oct 2026 21:32:29 -0400 Subject: unmap message object used for syscalls --- sys/syscall.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'sys/syscall.c') diff --git a/sys/syscall.c b/sys/syscall.c index 1c9af45..7207708 100644 --- a/sys/syscall.c +++ b/sys/syscall.c @@ -1,5 +1,6 @@ #include "sys/syscall.h" #include "arch/x86_64/hal/obj.h" +#include "hal/memory.h" #include "hal/smp.h" #include "proc/process.h" #include "jove.h" @@ -27,7 +28,7 @@ int _syscall_handle_generic(syscall_context_t *ctx) { pcb_t *pcb = obj_deref(ctx->pcb); - klogf("Process %i encountered stub syscall on object %P\n", pcb_pid(pcb), ctx->header->path, ctx->header->pathlen); + klogf("Process %i encountered stub syscall on object %P\n", pcb_getpid(pcb), ctx->header->path, ctx->header->pathlen); return -EBADOBJ; } @@ -92,35 +93,38 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen) if(ctx.message.obj == NULL) { klogf("Process %i failed to get message %P : %s\n", - pcb_pid(pcb), message_path, message_pathlen, errstr(errno)); + pcb_getpid(pcb), message_path, message_pathlen, errstr(errno)); sysret = -errno; goto release_return; } if(obj_gettype(ctx.message.obj) != JOVE_OBJ_MESSAGE) { klogf("Process %i tried to call syscall with invalid object %P\n", - pcb_pid(pcb), message_path, message_pathlen); + pcb_getpid(pcb), message_path, message_pathlen); sysret = -EBADOBJ; goto release_return; } if((ctx.message.permissions & JOVE_PERM_READ) == 0) { klogf("Process %i tried to call syscall with message object %P without read permissions\n", - pcb_pid(pcb), message_path, message_pathlen); + pcb_getpid(pcb), message_path, message_pathlen); sysret = -EPERM; goto release_return; } - size_t messagelen = message_len(ctx.message.obj); - void *messagedata = message_data(ctx.message.obj); + uintptr_t message_vptr = message_unmap(ctx.message.obj, + (jove_owned_obj_t*)pcb_pagedir(pcb)); + + size_t messagelen = 0x1000; + void *messagedata = (void*)message_getdata(ctx.message.obj); struct syscall_header *header = messagedata; size_t bytes_needed = sizeof(struct syscall_header) + header->pathlen * 2; if(bytes_needed > messagelen) { //Target path exceeds message length. - klogf("Process %i tried to call syscall with target path too big for message.\n", pcb_pid(pcb)); + klogf("Process %i tried to call syscall with target path too big for message.\n", pcb_getpid(pcb)); sysret = -ETOOSMALL; - goto release_return; + goto remap_return; } ctx.header = header; @@ -128,17 +132,29 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen) ctx.payload = (void*)((uintptr_t)header + bytes_needed); ctx.target = link_try_traverse_objdir( - ctx.objdir, &ctx.lockstack, ctx.header->pathlen, ctx.header->path); - - if(ctx.target.obj == 0) { - //Could not find payload target in pcb rootdir. - klogf("Process %i tried to call syscall with bad target path %P : %s\n", - pcb_pid(pcb), header->path, header->pathlen, errstr(errno)); - sysret = -errno; - goto release_return; + ctx.objdir, &ctx.lockstack, ctx.header->pathlen, ctx.header->path); + + if(ctx.target.obj != 0) { + sysret = _syscall_handle_switch(&ctx); + }else{ + //Check if we're trying to reference the PCB. If we are, we should set it as the target + //regardless of lock. + if(ctx.header->pathlen == 1 && + objdir_peeklocal(ctx.objdir, ctx.header->path[0]).data == ctx.pcb->locked.data) + { + ctx.target = (jove_perm_obj_t) { .permissions = 0xFF, .obj = ctx.pcb }; + sysret = _syscall_handle_switch(&ctx); + + }else{ + //Could not find payload target in pcb rootdir. + klogf("Process %i tried to call syscall with bad target path %P : %s\n", + pcb_getpid(pcb), header->path, header->pathlen, errstr(errno)); + sysret = -errno; + } } - sysret = _syscall_handle_switch(&ctx); +remap_return: + message_remap(ctx.message.obj, (jove_owned_obj_t*)pcb_pagedir(pcb), message_vptr); release_return: lockstack_popall(&ctx.lockstack); -- cgit v1.2.3