Changeset f8ddd17 in mainline for uspace/libc/generic/as.c
- Timestamp:
- 2006-12-09T20:20:50Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b82a13c
- Parents:
- 9ab9c2ec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/libc/generic/as.c
r9ab9c2ec rf8ddd17 38 38 #include <align.h> 39 39 #include <types.h> 40 #include <bitops.h> 40 41 41 42 /** … … 54 55 void *as_area_create(void *address, size_t size, int flags) 55 56 { 56 return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t ) address, (sysarg_t) size, (sysarg_t) flags); 57 return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t ) address, 58 (sysarg_t) size, (sysarg_t) flags); 57 59 } 58 60 59 61 /** Resize address space area. 60 62 * 61 * @param address Virtual address pointing into already existing address space area. 63 * @param address Virtual address pointing into already existing address space 64 * area. 62 65 * @param size New requested size of the area. 63 66 * @param flags Currently unused. … … 67 70 int as_area_resize(void *address, size_t size, int flags) 68 71 { 69 return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t ) address, (sysarg_t) size, (sysarg_t) flags); 72 return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t ) address, (sysarg_t) 73 size, (sysarg_t) flags); 70 74 } 71 75 72 76 /** Destroy address space area. 73 77 * 74 * @param address Virtual address pointing into the address space area being destroyed. 78 * @param address Virtual address pointing into the address space area being 79 * destroyed. 75 80 * 76 81 * @return Zero on success or a code from @ref errno.h on failure. … … 134 139 /* Return pointer to area not managed by sbrk */ 135 140 return ((void *) &_heap + maxheapsize); 136 137 141 } 138 142 139 143 /** Return pointer to some unmapped area, where fits new as_area 140 144 * 145 * @param sz Requested size of the allocation. 146 * @param color Requested virtual color of the allocation. 147 * 148 * @return Pointer to the beginning 149 * 141 150 * TODO: make some first_fit/... algorithm, we are now just incrementing 142 151 * the pointer to last area 143 152 */ 144 void * as_get_mappable_page(size_t sz) 153 #include <stdio.h> 154 void *as_get_mappable_page(size_t sz, int color) 145 155 { 146 156 void *res; 157 uint64_t asz; 158 int i; 159 160 if (!sz) 161 return NULL; 162 163 asz = 1 << (fnzb64(sz - 1) + 1); 147 164 148 165 /* Set heapsize to some meaningful value */ … … 150 167 set_maxheapsize(MAX_HEAP_SIZE); 151 168 152 if (!last_allocated) 153 last_allocated = (void *) ALIGN_UP((void *) &_heap + maxheapsize, PAGE_SIZE); 154 155 sz = ALIGN_UP(sz, PAGE_SIZE); 169 /* 170 * Make sure we allocate from naturally aligned address and a page of 171 * appropriate color. 172 */ 173 i = 0; 174 do { 175 if (!last_allocated) { 176 last_allocated = (void *) ALIGN_UP((void *) &_heap + 177 maxheapsize, asz); 178 } else { 179 last_allocated = (void *) ALIGN_UP(((uintptr_t) 180 last_allocated) + (int) (i > 0), asz); 181 } 182 } while ((asz < (1 << (PAGE_COLOR_BITS + PAGE_WIDTH))) && 183 (PAGE_COLOR((uintptr_t) last_allocated) != color) && 184 (++i < (1 << PAGE_COLOR_BITS))); 185 156 186 res = last_allocated; 157 last_allocated += sz;187 last_allocated += ALIGN_UP(sz, PAGE_SIZE); 158 188 159 189 return res;
Note:
See TracChangeset
for help on using the changeset viewer.