diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-09-17 11:11:20 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-09-17 11:11:20 -0400 |
| commit | 13adbc58eb9f5eb5d6f0e4454bd005e9adbb47c8 (patch) | |
| tree | a15e55bc70c60d3faa053db3b7b9a17fe75589bc /arch/x86_64 | |
| parent | a783cc865f1f261c20f6ef55cb37d4839f519865 (diff) | |
| download | jove-kernel-13adbc58eb9f5eb5d6f0e4454bd005e9adbb47c8.tar.gz jove-kernel-13adbc58eb9f5eb5d6f0e4454bd005e9adbb47c8.tar.bz2 jove-kernel-13adbc58eb9f5eb5d6f0e4454bd005e9adbb47c8.zip | |
make syscall use non-locking mutexes
Diffstat (limited to 'arch/x86_64')
| -rw-r--r-- | arch/x86_64/hal/idt.h | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/obj.c | 52 | ||||
| -rw-r--r-- | arch/x86_64/hal/obj.h | 4 | ||||
| -rw-r--r-- | arch/x86_64/hal/process.c | 2 | ||||
| -rw-r--r-- | arch/x86_64/hal/process.h | 2 | ||||
| -rw-r--r-- | arch/x86_64/lock.c | 7 | ||||
| -rw-r--r-- | arch/x86_64/lock.h | 2 | ||||
| -rw-r--r-- | arch/x86_64/main.c | 5 | ||||
| -rw-r--r-- | arch/x86_64/sys/init.c | 1 |
9 files changed, 68 insertions, 9 deletions
diff --git a/arch/x86_64/hal/idt.h b/arch/x86_64/hal/idt.h index 2aa759b..19c9e4c 100644 --- a/arch/x86_64/hal/idt.h +++ b/arch/x86_64/hal/idt.h @@ -66,7 +66,7 @@ struct int_stackframe struct int_user_handle { uintmax_t pid; - void *handle; + int (*handle)(struct int_stackframe*); }; extern struct int_user_handle __int_user_handles[IDT_ENTRIES]; diff --git a/arch/x86_64/hal/obj.c b/arch/x86_64/hal/obj.c index af0491a..cb0e13d 100644 --- a/arch/x86_64/hal/obj.c +++ b/arch/x86_64/hal/obj.c @@ -16,6 +16,18 @@ obj_take(jove_obj_t *obj) return (jove_owned_obj_t*)obj; } +jove_owned_obj_t* +obj_trytake(jove_obj_t *obj) +{ + if((uintptr_t)obj < IDENT_VIRT_BASE) { + reterr(EBADOBJ); + } + if(try_take_mutex(&obj->lock)) { + reterr(EBUSY); + } + return (jove_owned_obj_t*)obj; +} + jove_obj_t* obj_release(jove_owned_obj_t *obj) { @@ -97,16 +109,32 @@ objdir_getlocal( } jove_owned_obj_t* +objdir_trygetlocal( + jove_owned_obj_t *objdir_obj, + uint16_t entry) +{ + if(obj_gettype_linked(objdir_obj) != JOVE_OBJ_OBJDIR) { + reterr(EBADOBJ); + } + if(entry >= JOVE_OBJDIR_ENTRIES) { + reterr(EBADPATH); + } + + jove_objdir_t *objtab = obj_deref_linked(objdir_obj); + return obj_trytake(&objtab->entries[entry]); +} + +jove_owned_obj_t* objdir_getobj( jove_owned_obj_t *objdir_obj, const uint16_t *path, size_t path_len) { + errno = 0; if(path_len == 0) { return objdir_obj; } { - errno = 0; jove_owned_obj_t *child_objdir = objdir_getlocal(objdir_obj, path[0]); if(child_objdir == 0) { reterr(EBADPATH); @@ -118,3 +146,25 @@ objdir_getobj( } } +jove_owned_obj_t* +objdir_trygetobj( + jove_owned_obj_t *objdir_obj, + const uint16_t *path, + size_t path_len) +{ + errno = 0; + if(path_len == 0) { + return objdir_obj; + } + { + jove_owned_obj_t *child_objdir = objdir_trygetlocal(objdir_obj, path[0]); + if(child_objdir == 0) { + return 0; + } + + jove_owned_obj_t *target_obj = objdir_trygetobj(child_objdir, path + 1, path_len - 1); + obj_release(child_objdir); + return target_obj; + } +} + diff --git a/arch/x86_64/hal/obj.h b/arch/x86_64/hal/obj.h index deea2be..4364348 100644 --- a/arch/x86_64/hal/obj.h +++ b/arch/x86_64/hal/obj.h @@ -17,7 +17,7 @@ typedef union jove_obj struct { uint8_t type; atomic_flag lock; - /*Raw value or pointer to a data-structure located in kernel memory.*/ + /*Raw value or pointer to a data-structure located in identity memory.*/ uint64_t value : 48; }; uintmax_t data; @@ -32,7 +32,7 @@ typedef struct jove_locked_obj } jove_owned_obj_t; /*Object directories are always 1 page wide. Since an object inside the directory - * is a pointer width, on x86_64 that is 512 entries per directory.*/ + * in this arch is a pointer width, that is 512 entries per directory.*/ #define JOVE_OBJDIR_SIZE 0x1000 #define JOVE_OBJDIR_ENTRIES (JOVE_OBJDIR_SIZE / sizeof(jove_obj_t)) diff --git a/arch/x86_64/hal/process.c b/arch/x86_64/hal/process.c index 0155919..f30d703 100644 --- a/arch/x86_64/hal/process.c +++ b/arch/x86_64/hal/process.c @@ -37,7 +37,7 @@ pcb_pid(pcb_t *pcb) jove_owned_obj_t* pcb_rootdir(pcb_t *pcb) { - return pcb->rootdir; + return obj_take(pcb->rootdir); } void diff --git a/arch/x86_64/hal/process.h b/arch/x86_64/hal/process.h index c3530bf..f903153 100644 --- a/arch/x86_64/hal/process.h +++ b/arch/x86_64/hal/process.h @@ -7,7 +7,7 @@ typedef struct process_control_block { pid_t pid; - jove_owned_obj_t *rootdir; + jove_obj_t *rootdir; jove_owned_obj_t *iopb; uintptr_t pml4; diff --git a/arch/x86_64/lock.c b/arch/x86_64/lock.c index b010ee6..a34cee6 100644 --- a/arch/x86_64/lock.c +++ b/arch/x86_64/lock.c @@ -11,6 +11,13 @@ take_mutex(atomic_flag *lock) } } +int +try_take_mutex(atomic_flag *lock) +{ + if(_kernel_panic_unlock) return 1; + return atomic_flag_test_and_set(lock); +} + void release_mutex(atomic_flag *lock) { diff --git a/arch/x86_64/lock.h b/arch/x86_64/lock.h index 609ea39..3592ea1 100644 --- a/arch/x86_64/lock.h +++ b/arch/x86_64/lock.h @@ -4,6 +4,8 @@ #include <stdatomic.h> void take_mutex(atomic_flag *lock); +int try_take_mutex(atomic_flag *lock); + void release_mutex(atomic_flag *lock); #endif diff --git a/arch/x86_64/main.c b/arch/x86_64/main.c index 7266155..a35a465 100644 --- a/arch/x86_64/main.c +++ b/arch/x86_64/main.c @@ -1,3 +1,4 @@ +#include "api/init.h" #include "jove.h" #include "init.h" #include "lib/string.h" @@ -19,9 +20,7 @@ int errno = 0; PAGEALIGN jove_objdir_t _rootdir; - -jove_owned_obj_t s_rootdir_obj; -void *_rootdir_obj = &s_rootdir_obj; +void *_rootdir_obj = &_rootdir.entries[ROOTDIR_DIR_I]; static void kernel_process_entry(void); diff --git a/arch/x86_64/sys/init.c b/arch/x86_64/sys/init.c index 8823df2..c55eabe 100644 --- a/arch/x86_64/sys/init.c +++ b/arch/x86_64/sys/init.c @@ -171,6 +171,7 @@ init_setup(void) pcb_t *pcb = obj_deref(pcb_obj); obj_release(pcb_obj); + obj_release(_rootdir_obj); uintptr_t usp = 0x00007FFFFFFFFFF8; uintptr_t uip = init_ehdr->e_entry; |
