diff options
Diffstat (limited to 'lib/libjove')
-rw-r--r-- | lib/libjove/arch/x86_64/pager/ensure.c | 28 | ||||
-rw-r--r-- | lib/libjove/include/arch/x86_64/pager.h | 3 | ||||
-rw-r--r-- | lib/libjove/include/memory.h | 15 | ||||
-rw-r--r-- | lib/libjove/memory.c | 23 |
4 files changed, 66 insertions, 3 deletions
diff --git a/lib/libjove/arch/x86_64/pager/ensure.c b/lib/libjove/arch/x86_64/pager/ensure.c index bfe68ff..874db35 100644 --- a/lib/libjove/arch/x86_64/pager/ensure.c +++ b/lib/libjove/arch/x86_64/pager/ensure.c @@ -18,7 +18,7 @@ pager_write_path(uintptr_t vptr, uint8_t depth) if(depth >= 4) return -1; uint16_t *path = (uint16_t*)&r; - for(uint8_t i = 0; i < depth; i++) path[i] = PMLI_DL(vptr, i); + for(uint8_t i = 0; i < depth + 1; i++) path[i] = PMLI_DL(vptr, i); return r; } @@ -70,10 +70,10 @@ pager_ensure_at_depth(KernelObjectPageMap *map, uint8_t depth, uint16_t *path) JoveError jove_pager_ensure_for(KernelObjectPageMap *map, uintptr_t vptr) { + vptr &= ~0xFFFULL; + uint64_t path = pager_write_path(vptr, 3); if(path == -1) return EJOVE_BADARG; - - vptr &= ~0xFFFULL; uint16_t *path_seg = (uint16_t*)&path; jove_kprintf("%p Alloc %p : %x:%x:%x:%x\n", map, vptr, path_seg[0], path_seg[1], path_seg[2], path_seg[3]); @@ -86,3 +86,25 @@ jove_pager_ensure_for(KernelObjectPageMap *map, uintptr_t vptr) } return EJOVE_OK; } + +#define PAGER_CACHE_EXISTS_DEPTH(map, path_seg, d) \ + if(path_seg[d] != d_cache[d]) { \ + if(!jove_pagemap_exists(map, d, path_seg)) return 0; \ + d_cache[d] = path_seg[d]; \ + } + + +int +jove_pager_exists_for(KernelObjectPageMap *map, uintptr_t vptr) +{ + vptr &= ~0xFFFULL; + + uint64_t path = pager_write_path(vptr, 3); + if(path == -1) return EJOVE_BADARG; + uint16_t *path_seg = (uint16_t*)&path; + + PAGER_CACHE_EXISTS_DEPTH(map, path_seg, 0); + PAGER_CACHE_EXISTS_DEPTH(map, path_seg, 1); + PAGER_CACHE_EXISTS_DEPTH(map, path_seg, 2); + return jove_pagemap_exists(map, 3, path_seg); +} diff --git a/lib/libjove/include/arch/x86_64/pager.h b/lib/libjove/include/arch/x86_64/pager.h index 7e47ed1..2a53a07 100644 --- a/lib/libjove/include/arch/x86_64/pager.h +++ b/lib/libjove/include/arch/x86_64/pager.h @@ -9,4 +9,7 @@ extern KernelObjectPageMap __jove_pagemap; JoveError jove_pager_ensure_for(KernelObjectPageMap *map, uintptr_t vptr); #define jove_pager_ensure(vptr) jove_pager_ensure_for(&__jove_pagemap, vptr) +int jove_pager_exists_for(KernelObjectPageMap *map, uintptr_t vptr); +#define jove_pager_exists(vptr) jove_pager_exists_for(&__jove_pagemap, vptr); + #endif diff --git a/lib/libjove/include/memory.h b/lib/libjove/include/memory.h new file mode 100644 index 0000000..9d4ce1d --- /dev/null +++ b/lib/libjove/include/memory.h @@ -0,0 +1,15 @@ +#ifndef _LIBJOVE_MEMORY_H +#define _LIBJOVE_MEMORY_H 1 + +#include <jove/error.h> + +#ifdef __x86_64__ +#include <jove/arch/x86_64/pager.h> +#define jove_mem_ensure(vptr) jove_pager_ensure(vptr) +#define jove_mem_exists(vptr) jove_pager_exists(vptr) +#endif + +JoveError jove_mem_ensure_range(uintptr_t start, uintptr_t end); +JoveError jove_mem_ensure_w(uintptr_t start, size_t pages); + +#endif diff --git a/lib/libjove/memory.c b/lib/libjove/memory.c new file mode 100644 index 0000000..db76528 --- /dev/null +++ b/lib/libjove/memory.c @@ -0,0 +1,23 @@ +#include <jove/memory.h> + +JoveError +jove_mem_ensure_w(uintptr_t start, size_t pages) +{ + start &= ~0xFFFULL; + for(size_t i = 0; i < pages; i++) { + uintptr_t at = start + (i << 12); + JoveError e = jove_mem_ensure(at); + if(e) return e; + } + return EJOVE_OK; +} + +JoveError +jove_mem_ensure_range(uintptr_t start, uintptr_t end) +{ + start &= ~0xFFFULL; + if(end & 0xFFF) + end += 0x1000 - (end & 0xFFF); + + return jove_mem_ensure_w(start, (end - start) >> 12); +} |