diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-09-11 11:16:36 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-09-11 11:16:36 -0400 |
| commit | bb08472a04127c994d3ea5a2cbc195f7116a03b8 (patch) | |
| tree | c55910449fae5cc2a722c4b6619f4c8dde8d5b56 /sys | |
| parent | 880dc3ee72809e74a5bde2275fc8f419a762b255 (diff) | |
| download | jove-kernel-bb08472a04127c994d3ea5a2cbc195f7116a03b8.tar.gz jove-kernel-bb08472a04127c994d3ea5a2cbc195f7116a03b8.tar.bz2 jove-kernel-bb08472a04127c994d3ea5a2cbc195f7116a03b8.zip | |
preliminary object linking support. needs testing
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/link.c | 52 | ||||
| -rw-r--r-- | sys/link.h | 21 | ||||
| -rw-r--r-- | sys/syscall.c | 29 |
3 files changed, 87 insertions, 15 deletions
diff --git a/sys/link.c b/sys/link.c new file mode 100644 index 0000000..5be9457 --- /dev/null +++ b/sys/link.c @@ -0,0 +1,52 @@ +#include "link.h" +#include "arch/x86_64/hal/obj.h" +#include "hal/memory.h" + +void* +obj_deref_linked(jove_owned_obj_t *obj) +{ + switch(obj_gettype(obj)) { + case JOVE_OBJ_LINK: return obj_deref_linked(link_deref(obj)); + default: return obj_deref(obj); + } +} + +uint8_t +obj_gettype_linked(jove_owned_obj_t *obj) +{ + switch(obj_gettype(obj)) { + case JOVE_OBJ_LINK: return obj_gettype_linked(link_deref(obj)); + default: return obj_gettype(obj); + } +} + +uint64_t +obj_getvalue_linked(jove_owned_obj_t *obj) +{ + switch(obj_gettype(obj)) { + case JOVE_OBJ_LINK: return obj_getvalue_linked(link_deref(obj)); + default: return obj_getvalue(obj); + } +} + +jove_owned_obj_t* +link_deref(jove_owned_obj_t *link) +{ + struct obj_link *linkval = obj_deref(link); + return obj_take(&linkval->obj); +} + +jove_owned_obj_t *link_new(jove_obj_t *tgt, jove_owned_obj_t *dst) +{ + struct obj_link *linkval = obj_deref(dst); + linkval->obj = *tgt; + linkval->refcount = 2; + + { + jove_owned_obj_t *tgt_owned = obj_take(tgt); + obj_settype(tgt_owned, JOVE_OBJ_LINK); + obj_setvalue(tgt_owned, (uintptr_t)linkval); + obj_release(tgt_owned); + } + return dst; +} diff --git a/sys/link.h b/sys/link.h new file mode 100644 index 0000000..37fa1e8 --- /dev/null +++ b/sys/link.h @@ -0,0 +1,21 @@ +#ifndef _JOVE_SYS_LINK_HPP +#define _JOVE_SYS_LINK_HPP 1 + +#include "hal/obj.h" + +struct obj_link +{ + size_t refcount; + jove_obj_t obj; +}; + +void *obj_deref_linked(jove_owned_obj_t *obj); +uint8_t obj_gettype_linked(jove_owned_obj_t *obj); +uint64_t obj_getvalue_linked(jove_owned_obj_t *obj); + +jove_owned_obj_t *link_deref(jove_owned_obj_t *link); +jove_obj_t link_unlink(jove_owned_obj_t *link); + +jove_owned_obj_t *link_new(jove_obj_t *tgt, jove_owned_obj_t *dst); + +#endif diff --git a/sys/syscall.c b/sys/syscall.c index 68a5ae6..9a98030 100644 --- a/sys/syscall.c +++ b/sys/syscall.c @@ -4,6 +4,7 @@ #include "hal/process.h" #include "jove.h" #include "lib/printf.h" +#include "sys/link.h" #include "sys/message.h" int @@ -33,6 +34,7 @@ static const syscall_handle_t s_syscall_handles[128] = { [JOVE_OBJ_FRAMEBUFFER] = _syscall_handle_generic, [JOVE_OBJ_VIRTTERM] = _syscall_handle_vtt, [JOVE_OBJ_MESSAGE] = _syscall_handle_generic, + [JOVE_OBJ_LINK] = _syscall_handle_generic, }; int @@ -55,15 +57,11 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen) return errno; } -#define SYSCALL_MIDWAY_CLEANUP \ - obj_release(message_obj); \ - obj_release(objdir); \ - obj_release(pcb_obj) - - if(obj_gettype(message_obj) != JOVE_OBJ_MESSAGE) { + int sysret = 0; + if(obj_gettype_linked(message_obj) != JOVE_OBJ_MESSAGE) { kprintf("syscall: Process %i tried to call syscall with invalid object: %P\n", pcb_pid(pcb), message_path, message_pathlen); - SYSCALL_MIDWAY_CLEANUP; - return EBADOBJ; + sysret = EBADOBJ; + goto release_return; } size_t messagelen = message_len(message_obj); @@ -75,18 +73,17 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen) if(bytes_left < 0) { //Target path exceeds message length. kprintf("syscall: Process %i tried to call syscall with OOB target path.\n", pcb_pid(pcb)); - SYSCALL_MIDWAY_CLEANUP; - return EBADPATH; + sysret = EBADPATH; + goto release_return; } jove_owned_obj_t *target = objdir_getobj(objdir, header->path, header->pathlen); if(target == 0) { //Could not find payload target in pcb rootdir. kprintf("syscall: Process %i tried to call syscall with bad target path %P\n", pcb_pid(pcb), header->path, header->pathlen); - SYSCALL_MIDWAY_CLEANUP; - return errno; + sysret = errno; + goto release_return; } - int sysret = 0; uint8_t target_type = obj_gettype(target); if(target_type > 0x7F) { @@ -104,8 +101,10 @@ syscall_handler(uintmax_t message_path_raw, uint16_t message_pathlen) pcb_obj, objdir, message_obj, target, header, bytes_left, messagedata + header_bytes); } - obj_release(target); - SYSCALL_MIDWAY_CLEANUP; +release_return: + obj_release(message_obj); + obj_release(objdir); + obj_release(pcb_obj); return sysret; } |
