Changes in uspace/lib/c/generic/as.c [56273bb:b93d637] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/as.c
r56273bb rb93d637 35 35 #include <as.h> 36 36 #include <libc.h> 37 #include <errno.h> 37 38 #include <unistd.h> 38 39 #include <align.h> … … 40 41 #include <bitops.h> 41 42 #include <malloc.h> 42 #include "private/libc.h" 43 44 /** Last position allocated by as_get_mappable_page */ 45 static uintptr_t last_allocated = 0; 43 46 44 47 /** Create address space area. … … 51 54 * 52 55 */ 53 void *as_area_create(void *address, size_t size, unsignedint flags)56 void *as_area_create(void *address, size_t size, int flags) 54 57 { 55 58 return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address, … … 67 70 * 68 71 */ 69 int as_area_resize(void *address, size_t size, unsignedint flags)72 int as_area_resize(void *address, size_t size, int flags) 70 73 { 71 74 return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address, … … 95 98 * 96 99 */ 97 int as_area_change_flags(void *address, unsignedint flags)100 int as_area_change_flags(void *address, int flags) 98 101 { 99 102 return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address, … … 101 104 } 102 105 103 /** Return pointer to unmapped address spacearea106 /** Return pointer to some unmapped area, where fits new as_area 104 107 * 105 108 * @param size Requested size of the allocation. 106 109 * 107 * @return Pointer to the beginning of unmapped address space area.110 * @return pointer to the beginning 108 111 * 109 112 */ 110 113 void *as_get_mappable_page(size_t size) 111 114 { 112 return (void *) __SYSCALL2(SYS_AS_GET_UNMAPPED_AREA, 113 (sysarg_t) __entry, (sysarg_t) size); 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; 114 155 } 115 156
Note:
See TracChangeset
for help on using the changeset viewer.