Changeset eb522e8 in mainline for uspace/lib/c/generic/as.c
- Timestamp:
- 2011-06-01T08:43:42Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8d6c1f1
- Parents:
- 9e2e715 (diff), e51a514 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/as.c
r9e2e715 reb522e8 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 43 /** Last position allocated by as_get_mappable_page */ 44 static uintptr_t last_allocated = 0; 43 #include "private/libc.h" 45 44 46 45 /** Create address space area. … … 53 52 * 54 53 */ 55 void *as_area_create(void *address, size_t size, int flags)54 void *as_area_create(void *address, size_t size, unsigned int flags) 56 55 { 57 56 return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address, … … 69 68 * 70 69 */ 71 int as_area_resize(void *address, size_t size, int flags)70 int as_area_resize(void *address, size_t size, unsigned int flags) 72 71 { 73 72 return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address, … … 97 96 * 98 97 */ 99 int as_area_change_flags(void *address, int flags)98 int as_area_change_flags(void *address, unsigned int flags) 100 99 { 101 100 return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address, … … 103 102 } 104 103 105 /** Return pointer to some unmapped area, where fits new as_area104 /** Return pointer to unmapped address space area 106 105 * 107 106 * @param size Requested size of the allocation. 108 107 * 109 * @return pointer to the beginning108 * @return Pointer to the beginning of unmapped address space area. 110 109 * 111 110 */ 112 111 void *as_get_mappable_page(size_t size) 113 112 { 114 if (size == 0) 115 return NULL; 113 return (void *) __SYSCALL2(SYS_AS_GET_UNMAPPED_AREA, 114 (sysarg_t) __entry, (sysarg_t) size); 115 } 116 117 /** Find mapping to physical address. 118 * 119 * @param address Virtual address in question (virtual). 120 * @param[out] frame Frame address (physical). 121 * @return Error code. 122 * @retval EOK No error, @p frame holds the translation. 123 * @retval ENOENT Mapping not found. 124 */ 125 int as_get_physical_mapping(void *address, uintptr_t *frame) 126 { 127 uintptr_t tmp_frame; 128 uintptr_t virt = (uintptr_t) address; 116 129 117 size_t sz = 1 << (fnzb(size - 1) + 1); 118 if (last_allocated == 0) 119 last_allocated = get_max_heap_addr(); 130 int rc = (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING, 131 (sysarg_t) virt, (sysarg_t) &tmp_frame); 132 if (rc != EOK) { 133 return rc; 134 } 120 135 121 /* 122 * Make sure we allocate from naturally aligned address. 123 */ 124 uintptr_t res = ALIGN_UP(last_allocated, sz); 125 last_allocated = res + ALIGN_UP(size, PAGE_SIZE); 136 if (frame != NULL) { 137 *frame = tmp_frame; 138 } 126 139 127 return ((void *) res);140 return EOK; 128 141 } 129 142
Note:
See TracChangeset
for help on using the changeset viewer.