#include "api/error.h" #include "arch/x86_64/hal/obj.h" #include "hal/memory.h" #include "hal/obj.h" #include "lib/string.h" #include "jove.h" int objdir_new(jove_owned_obj_t *untyped_obj) { jove_untyped_t *untyped = obj_deref(untyped_obj); if((uintptr_t)untyped & (OBJDIR_SIZE - 1)) return -EALIGN; if(untyped->limit != OBJDIR_SIZE) return -EBADSIZE; memset(untyped, 0, OBJDIR_SIZE); obj_settype(untyped_obj, JOVE_OBJ_OBJDIR); return 0; } jove_obj_t objdir_peeklocal( jove_obj_t *objdir_obj, uint16_t entry) { jove_owned_obj_t *objdir = obj_take(objdir_obj); if(obj_gettype(objdir) != JOVE_OBJ_OBJDIR) { errno = EBADOBJ; obj_release(objdir); return (jove_obj_t) { 0 }; } if(entry >= OBJDIR_ENTRIES) { errno = EBADPATH; obj_release(objdir); return (jove_obj_t) { 0 }; } jove_objdir_t *objtab = obj_deref(objdir); jove_obj_t obj = objtab->entries[entry]; obj_release(objdir); return obj; } jove_owned_obj_t* objdir_getlocal( jove_obj_t *objdir_obj, uint16_t entry) { jove_owned_obj_t *objdir = obj_take(objdir_obj); jove_owned_obj_t *obj = objdir_getlocal_locked(objdir, entry); obj_release(objdir); return obj; } jove_owned_obj_t *objdir_getlocal_locked(jove_owned_obj_t *objdir, objpath_part_t entry) { if(obj_gettype(objdir) != JOVE_OBJ_OBJDIR) { obj_release(objdir); reterr(EBADOBJ); } if(entry >= OBJDIR_ENTRIES) { obj_release(objdir); reterr(EBADPATH); } jove_objdir_t *objtab = obj_deref(objdir); jove_owned_obj_t *obj = obj_take(&objtab->entries[entry]); return obj; } jove_owned_obj_t* objdir_getobj( jove_obj_t *objdir_obj, const uint16_t *path, size_t path_len) { jove_owned_obj_t *objdir = obj_take(objdir_obj); jove_owned_obj_t *obj = objdir_getobj_locked(objdir, path, path_len); obj_release(objdir); return obj; } jove_owned_obj_t *objdir_getobj_locked(jove_owned_obj_t *objdir, const objpath_part_t *path, size_t path_len) { errno = 0; if(path_len == 0) return objdir; jove_owned_obj_t *child_obj = objdir_getlocal_locked(objdir, path[0]); obj_release(objdir); if(child_obj == NULL) return NULL; return objdir_getobj_locked(child_obj, &path[1], path_len - 1); } bool objdir_compare(jove_obj_t *objdir_obj, objpath_part_t entry, jove_obj_t *obj) { jove_obj_t peekobj = objdir_peeklocal(objdir_obj, entry); return obj_compare(&peekobj, obj); } void objdir_swapobj(jove_owned_obj_t *a, jove_owned_obj_t *b) { jove_owned_obj_t buffer_obj = *a; *a = *b; *b = buffer_obj; }