Changeset 19a1800 in mainline for uspace/lib/c/generic/as.c
- Timestamp:
- 2011-03-01T22:20:56Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e24e7b1
- Parents:
- 976f546 (diff), ac8285d (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
r976f546 r19a1800 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. … … 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.