Rev 2131 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2131 | Rev 2292 | ||
---|---|---|---|
Line 53... | Line 53... | ||
53 | * @return address on success, (void *) -1 otherwise. |
53 | * @return address on success, (void *) -1 otherwise. |
54 | */ |
54 | */ |
55 | void *as_area_create(void *address, size_t size, int flags) |
55 | void *as_area_create(void *address, size_t size, int flags) |
56 | { |
56 | { |
57 | return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t ) address, |
57 | return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t ) address, |
58 | (sysarg_t) size, (sysarg_t) flags); |
58 | (sysarg_t) size, (sysarg_t) flags); |
59 | } |
59 | } |
60 | 60 | ||
61 | /** Resize address space area. |
61 | /** Resize address space area. |
62 | * |
62 | * |
63 | * @param address Virtual address pointing into already existing address space |
63 | * @param address Virtual address pointing into already existing address space |
Line 67... | Line 67... | ||
67 | * |
67 | * |
68 | * @return Zero on success or a code from @ref errno.h on failure. |
68 | * @return Zero on success or a code from @ref errno.h on failure. |
69 | */ |
69 | */ |
70 | int as_area_resize(void *address, size_t size, int flags) |
70 | int as_area_resize(void *address, size_t size, int flags) |
71 | { |
71 | { |
72 | return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t ) address, (sysarg_t) |
72 | return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t ) address, |
73 | size, (sysarg_t) flags); |
73 | (sysarg_t) size, (sysarg_t) flags); |
74 | } |
74 | } |
75 | 75 | ||
76 | /** Destroy address space area. |
76 | /** Destroy address space area. |
77 | * |
77 | * |
78 | * @param address Virtual address pointing into the address space area being |
78 | * @param address Virtual address pointing into the address space area being |
Line 141... | Line 141... | ||
141 | } |
141 | } |
142 | 142 | ||
143 | /** Return pointer to some unmapped area, where fits new as_area |
143 | /** Return pointer to some unmapped area, where fits new as_area |
144 | * |
144 | * |
145 | * @param sz Requested size of the allocation. |
145 | * @param sz Requested size of the allocation. |
146 | * @param color Requested virtual color of the allocation. |
- | |
147 | * |
146 | * |
148 | * @return Pointer to the beginning |
147 | * @return Pointer to the beginning |
149 | * |
148 | * |
150 | * TODO: make some first_fit/... algorithm, we are now just incrementing |
149 | * TODO: make some first_fit/... algorithm, we are now just incrementing |
151 | * the pointer to last area |
150 | * the pointer to last area |
152 | */ |
151 | */ |
153 | void *as_get_mappable_page(size_t sz, int color) |
152 | void *as_get_mappable_page(size_t sz) |
154 | { |
153 | { |
155 | void *res; |
154 | void *res; |
156 | uint64_t asz; |
155 | uint64_t asz; |
157 | int i; |
156 | int i; |
158 | 157 | ||
Line 164... | Line 163... | ||
164 | /* Set heapsize to some meaningful value */ |
163 | /* Set heapsize to some meaningful value */ |
165 | if (maxheapsize == -1) |
164 | if (maxheapsize == -1) |
166 | set_maxheapsize(MAX_HEAP_SIZE); |
165 | set_maxheapsize(MAX_HEAP_SIZE); |
167 | 166 | ||
168 | /* |
167 | /* |
169 | * Make sure we allocate from naturally aligned address and a page of |
168 | * Make sure we allocate from naturally aligned address. |
170 | * appropriate color. |
- | |
171 | */ |
169 | */ |
172 | i = 0; |
170 | i = 0; |
173 | do { |
- | |
174 | if (!last_allocated) { |
171 | if (!last_allocated) { |
175 | last_allocated = (void *) ALIGN_UP((void *) &_heap + |
172 | last_allocated = (void *) ALIGN_UP((void *) &_heap + |
176 | maxheapsize, asz); |
173 | maxheapsize, asz); |
177 | } else { |
174 | } else { |
178 | last_allocated = (void *) ALIGN_UP(((uintptr_t) |
175 | last_allocated = (void *) ALIGN_UP(((uintptr_t) |
179 | last_allocated) + (int) (i > 0), asz); |
176 | last_allocated) + (int) (i > 0), asz); |
180 | } |
177 | } |
181 | } while ((asz < (1 << (PAGE_COLOR_BITS + PAGE_WIDTH))) && |
- | |
182 | (PAGE_COLOR((uintptr_t) last_allocated) != color) && |
- | |
183 | (++i < (1 << PAGE_COLOR_BITS))); |
- | |
184 | 178 | ||
185 | res = last_allocated; |
179 | res = last_allocated; |
186 | last_allocated += ALIGN_UP(sz, PAGE_SIZE); |
180 | last_allocated += ALIGN_UP(sz, PAGE_SIZE); |
187 | 181 | ||
188 | return res; |
182 | return res; |