#include #include #include #include #include void _jove_alloc_untyped_inplace( KernelObjectUntyped *untyped, KernelObjectDirectory *parent, uint8_t membi ) { *untyped = (KernelObjectUntyped) { .typed = (KernelObjectTyped) { .type = KO_MEMORY_UNTYPED, .parent = parent, .membi = membi }, .bytes = 0, .alignment = -1, .children_head = NULL, .sibling = NULL }; parent->children[membi] = (KernelObjectTyped*)untyped; parent->lastmemb = 0; } KernelObjectUntyped* _jove_alloc_untyped(KernelObjectDirectory *parent, uint8_t membi) { if(_jove_alloc == NULL) { jove_errno = EJOVE_NOALLOC; return NULL; } if(parent->children[membi] != NULL) { jove_errno = EJOVE_FULL; } KernelObjectUntyped *untyped = _jove_alloc(sizeof(KernelObjectUntyped)); _jove_alloc_untyped_inplace(untyped, parent, membi); return untyped; } KernelObjectUntyped* jove_object_as_untyped(KernelObjectTyped *typed) { if(typed->type == KO_MEMORY_UNTYPED) return (KernelObjectUntyped*)typed; jove_errno = EJOVE_BADOBJ; return NULL; } int jove_untyped_size(KernelObjectUntyped *untyped) { if(untyped->bytes != 0) return untyped->bytes; int e = _syscall_invoke_untyped_size(untyped, &untyped->bytes); if(e) return jove_error_from_kerror(e); return untyped->bytes; } int jove_untyped_alignment(KernelObjectUntyped *untyped) { if(untyped->alignment >= 0) return untyped->alignment; int e = _syscall_invoke_untyped_alignment(untyped, (size_t*)&untyped->alignment); if(e) return jove_error_from_kerror(e); return untyped->alignment; } KernelObjectUntyped* jove_untyped_split( KernelObjectUntyped *untyped, size_t bytes, KernelObjectDirectory *dest, uint8_t destmemb ) { if(!_jove_alloc) { jove_errno = EJOVE_NOALLOC; return NULL; } KernelObjectUntyped temp; _jove_alloc_untyped_inplace(&temp, dest, destmemb); jove_errno = jove_untyped_split_inplace(untyped, bytes, &temp); if(jove_errno) return NULL; KernelObjectUntyped *newuntyped = _jove_alloc(sizeof(KernelObjectUntyped)); memcpy(newuntyped, &temp, sizeof(KernelObjectUntyped)); dest->children[destmemb] = JOVE_OBJECT_TYPED(newuntyped); return newuntyped; } JoveError jove_untyped_split_inplace( KernelObjectUntyped *untyped, size_t bytes, KernelObjectUntyped *dest) { if(jove_untyped_size(untyped) - sizeof(size_t) <= bytes) { return EJOVE_BADSIZE; } if(bytes < sizeof(size_t)) { return EJOVE_BADSIZE;; } int e = _syscall_invoke_untyped_split(untyped, bytes, dest); if(e) { return jove_error_from_kerror(e); } dest->bytes = bytes; dest->alignment = -1; untyped->bytes -= bytes; return EJOVE_OK; }