diff options
Diffstat (limited to 'lib/libjove/arch/x86_64')
-rw-r--r-- | lib/libjove/arch/x86_64/invoke-pagemap.c | 36 | ||||
-rw-r--r-- | lib/libjove/arch/x86_64/object/directory.c | 15 | ||||
-rw-r--r-- | lib/libjove/arch/x86_64/object/pagemap.c | 105 |
3 files changed, 152 insertions, 4 deletions
diff --git a/lib/libjove/arch/x86_64/invoke-pagemap.c b/lib/libjove/arch/x86_64/invoke-pagemap.c index 8357904..e3f3dff 100644 --- a/lib/libjove/arch/x86_64/invoke-pagemap.c +++ b/lib/libjove/arch/x86_64/invoke-pagemap.c @@ -1,3 +1,4 @@ +#include "arch/x86_64/syscall.h" #include <arch/x86_64/object-pagemap.h> #include <kernel/syscall.h> #include <kernel/arch/x86_64/syscall.h> @@ -7,14 +8,41 @@ #include <jove/jove.h> int -_syscall_invoke_mapping_get(KernelObjectPageMapping *mapping, uint16_t pmli, KernelObjectPageMapping *dest) +_syscall_invoke_mapping_exists(KernelObjectPageMap *map, uint8_t depth, uint16_t *path) { uint8_t *syscallData = _syscall_message_ptr; int syscall_at = 0; - SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, mapping); - SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, INVOKE_MAPPING_GET, uint8_t); - SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, pmli, uint16_t); + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, map); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, INVOKE_MAPPING_EXISTS, uint8_t); + SYSCALL_PAYLOAD_PUTPML(syscallData, syscall_at, depth, path); + + return _syscall_invoke(); +} + +int +_syscall_invoke_mapping_map(KernelObjectPageMap *map, uint8_t depth, uint16_t *path, KernelObjectUntyped *untyped) +{ + uint8_t *syscallData = _syscall_message_ptr; + int syscall_at = 0; + + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, map); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, INVOKE_MAPPING_MAP, uint8_t); + SYSCALL_PAYLOAD_PUTPML(syscallData, syscall_at, depth, path); + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, untyped); + + return _syscall_invoke(); +} + +int +_syscall_invoke_mapping_unmap(KernelObjectPageMap *map, uint8_t depth, uint16_t *path, KernelObjectUntyped *dest) +{ + uint8_t *syscallData = _syscall_message_ptr; + int syscall_at = 0; + + SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, map); + SYSCALL_PAYLOAD_PUTL(syscallData, syscall_at, INVOKE_MAPPING_UNMAP, uint8_t); + SYSCALL_PAYLOAD_PUTPML(syscallData, syscall_at, depth, path); SYSCALL_PAYLOAD_PUTOBJ(syscallData, syscall_at, dest); return _syscall_invoke(); diff --git a/lib/libjove/arch/x86_64/object/directory.c b/lib/libjove/arch/x86_64/object/directory.c new file mode 100644 index 0000000..01f57c4 --- /dev/null +++ b/lib/libjove/arch/x86_64/object/directory.c @@ -0,0 +1,15 @@ +#include <object.h> +#include <arch/x86_64/object-pagemap.h> + +JoveError +_jove_objdir_sync_at_arch(KernelObjectDirectory *dir, uint8_t i, obj_type_t type, KernelObjectTyped **memb) +{ + KernelObjectTyped *dirmemb = NULL; + switch(type) { + case KO_MEMORY_MAPPING: + dirmemb = JOVE_OBJECT_TYPED(_jove_alloc_pagemap(dir, i)); + if(memb) *memb = dirmemb; + break; + } + return EJOVE_OK; +} diff --git a/lib/libjove/arch/x86_64/object/pagemap.c b/lib/libjove/arch/x86_64/object/pagemap.c new file mode 100644 index 0000000..c58d7c6 --- /dev/null +++ b/lib/libjove/arch/x86_64/object/pagemap.c @@ -0,0 +1,105 @@ +#include <object.h> +#include <jove.h> +#include <error.h> +#include <kernel/error.h> +#include <string.h> +#include <arch/x86_64/object-pagemap.h> +#include <arch/x86_64/syscall.h> + +KernelObjectPageMap* +jove_object_as_pagemap(KernelObjectTyped *typed) +{ + if(typed->type == KO_MEMORY_MAPPING) return (KernelObjectPageMap*)typed; + jove_errno = EJOVE_BADOBJ; + return NULL; +} + +void +_jove_alloc_pagemap_inplace( + KernelObjectPageMap *pagemap, + KernelObjectDirectory *dir, + uint8_t memb) +{ + *pagemap = (KernelObjectPageMap) { + .typed = (KernelObjectTyped) { + .parent = dir, + .type = KO_MEMORY_MAPPING, + .membi = memb + }, + }; + dir->children[memb] = JOVE_OBJECT_TYPED(pagemap); +} + +KernelObjectPageMap* +_jove_alloc_pagemap( + KernelObjectDirectory *dir, + uint8_t memb) +{ + if(_jove_alloc == NULL) { + jove_errno = EJOVE_NOALLOC; + return NULL; + } + if(dir->children[memb] != NULL) { + jove_errno = EJOVE_FULL; + return NULL; + } + + KernelObjectPageMap *pagemap = _jove_alloc(sizeof(KernelObjectPageMap)); + if(pagemap == NULL) return NULL; + + _jove_alloc_pagemap_inplace(pagemap, dir, memb); + jove_errno = EJOVE_OK; + return pagemap; +} + +int +jove_pagemap_exists( + KernelObjectPageMap *map, + uint8_t depth, + uint16_t *path + ) +{ + if(!_jove_alloc) { + jove_errno = EJOVE_NOALLOC; + return 0; + } + int kerr = _syscall_invoke_mapping_exists(map, depth, path); + if(kerr == KE_DNE) return 0; + + int jerr = jove_error_from_kerror(kerr); + + if(jerr) { + jove_errno = jerr; + return 0; + } + return 1; +} + +JoveError +jove_pagemap_map( + KernelObjectPageMap *map, + uint8_t depth, + uint16_t *path, + KernelObjectUntyped *untyped) +{ + if(jove_untyped_size(untyped) != 0x1000) { + return EJOVE_BADSIZE; + } + + return jove_error_from_kerror(_syscall_invoke_mapping_map(map, depth, path, untyped)); +} + +JoveError +jove_pagemap_unmap( + KernelObjectPageMap *map, + uint8_t depth, + uint16_t *path, + KernelObjectUntyped *untyped) +{ + JoveError err = jove_error_from_kerror(_syscall_invoke_mapping_unmap(map, depth, path, untyped)); + if(err) return err; + + untyped->alignment = 0x1000; + untyped->bytes = 0x1000; + return EJOVE_OK; +} |