Changes in uspace/lib/c/generic/as.c [b93d637:56273bb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/as.c
rb93d637 r56273bb 35 35 #include <as.h> 36 36 #include <libc.h> 37 #include <errno.h>38 37 #include <unistd.h> 39 38 #include <align.h> … … 41 40 #include <bitops.h> 42 41 #include <malloc.h> 43 44 /** Last position allocated by as_get_mappable_page */ 45 static uintptr_t last_allocated = 0; 42 #include "private/libc.h" 46 43 47 44 /** Create address space area. … … 54 51 * 55 52 */ 56 void *as_area_create(void *address, size_t size, int flags)53 void *as_area_create(void *address, size_t size, unsigned int flags) 57 54 { 58 55 return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address, … … 70 67 * 71 68 */ 72 int as_area_resize(void *address, size_t size, int flags)69 int as_area_resize(void *address, size_t size, unsigned int flags) 73 70 { 74 71 return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address, … … 98 95 * 99 96 */ 100 int as_area_change_flags(void *address, int flags)97 int as_area_change_flags(void *address, unsigned int flags) 101 98 { 102 99 return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address, … … 104 101 } 105 102 106 /** Return pointer to some unmapped area, where fits new as_area103 /** Return pointer to unmapped address space area 107 104 * 108 105 * @param size Requested size of the allocation. 109 106 * 110 * @return pointer to the beginning107 * @return Pointer to the beginning of unmapped address space area. 111 108 * 112 109 */ 113 110 void *as_get_mappable_page(size_t size) 114 111 { 115 if (size == 0) 116 return NULL; 117 118 size_t sz = 1 << (fnzb(size - 1) + 1); 119 if (last_allocated == 0) 120 last_allocated = get_max_heap_addr(); 121 122 /* 123 * Make sure we allocate from naturally aligned address. 124 */ 125 uintptr_t res = ALIGN_UP(last_allocated, sz); 126 last_allocated = res + ALIGN_UP(size, PAGE_SIZE); 127 128 return ((void *) res); 129 } 130 131 /** Find mapping to physical address. 132 * 133 * @param address Virtual address in question (virtual). 134 * @param[out] frame Frame address (physical). 135 * @return Error code. 136 * @retval EOK No error, @p frame holds the translation. 137 * @retval ENOENT Mapping not found. 138 */ 139 int as_get_physical_mapping(void *address, uintptr_t *frame) 140 { 141 uintptr_t tmp_frame; 142 uintptr_t virt = (uintptr_t) address; 143 144 int rc = (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING, 145 (sysarg_t) virt, (sysarg_t) &tmp_frame); 146 if (rc != EOK) { 147 return rc; 148 } 149 150 if (frame != NULL) { 151 *frame = tmp_frame; 152 } 153 154 return EOK; 112 return (void *) __SYSCALL2(SYS_AS_GET_UNMAPPED_AREA, 113 (sysarg_t) __entry, (sysarg_t) size); 155 114 } 156 115
Note:
See TracChangeset
for help on using the changeset viewer.