@@ -11,8 +11,10 @@ /* arch specific headers */ #ifdef KFenv_posix # include #endif + +#include /* we define all our platform functions here, whether or not * they're for the correct platform - only the ones that are * called by the preprocessed form of the code will actually @@ -20,9 +22,9 @@ extern void* kmem_platform_mmap(void* addr, unsigned long sz, unsigned long prot, unsigned long flags, unsigned long fd, unsigned long off); -void* kmheapa(sz len) { +kmcond kmheapa(void** where, sz len) { /* allocate an object on the heap and return * a pointer, or NULL if the allocation failed. */ union { void* raw; @@ -52,18 +54,36 @@ * the user will receive an adjusted pointer that can * be adjusted to point a field of type size_t that * contains the size of the allocated space.*/ - region.byte = kmem_platform_mmap(null, region_size, - posix_prot_read | posix_prot_write, - posix_flag_anonymous | posix_map_shared, -1, 0); + k_platform_syscall_arg args[] = { + null, region_size, + posix_prot_read | posix_prot_write, + posix_flag_anonymous | posix_map_shared, + -1, 0 + }; + + struct k_platform_syscall_answer r = k_platform_syscall + (k_platform_syscall_mmap, Kmsz(args), args); + + if (r.error == 0) region.byte = (ubyte*)r.ret; else { + switch (r.error) { + case k_platform_error_EAGAIN: return kmcond_bad_lock; + case k_platform_error_EINVAL: return kmcond_bad_size; + case k_platform_error_EMFILE: return kmcond_too_many; + case k_platform_error_ENOMEM: return kmcond_no_room; + default: return kmcond_fail_assert; + } + } + + /* region.byte = kmem_platform_mmap(null, region_size, */ + /* posix_prot_read | posix_prot_write, */ + /* posix_flag_anonymous | posix_map_shared, -1, 0); */ + /* impl note: while per manpage fd is "ignored" * for MAP_ANONYMOUS, "some implementations" require * a value of -1 */ - if (region.raw == (void*) -1) return null; - /* worth retrieving errno? discuss */ - # else Knoimpl(kmheapa,KVos); # error missing implementation # endif @@ -72,6 +92,7 @@ region.header -> kind = kmkind_heap; region.header -> size = len; - return object; + *where = object; + return kmcond_ok; }