Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/as.c

    r56273bb r63f8966  
    4040#include <bitops.h>
    4141#include <malloc.h>
    42 #include "private/libc.h"
     42
     43/** Last position allocated by as_get_mappable_page */
     44static uintptr_t last_allocated = 0;
    4345
    4446/** Create address space area.
     
    5153 *
    5254 */
    53 void *as_area_create(void *address, size_t size, unsigned int flags)
     55void *as_area_create(void *address, size_t size, int flags)
    5456{
    5557        return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address,
     
    6769 *
    6870 */
    69 int as_area_resize(void *address, size_t size, unsigned int flags)
     71int as_area_resize(void *address, size_t size, int flags)
    7072{
    7173        return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address,
     
    9597 *
    9698 */
    97 int as_area_change_flags(void *address, unsigned int flags)
     99int as_area_change_flags(void *address, int flags)
    98100{
    99101        return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address,
     
    101103}
    102104
    103 /** Return pointer to unmapped address space area
     105/** Return pointer to some unmapped area, where fits new as_area
    104106 *
    105107 * @param size Requested size of the allocation.
    106108 *
    107  * @return Pointer to the beginning of unmapped address space area.
     109 * @return pointer to the beginning
    108110 *
    109111 */
    110112void *as_get_mappable_page(size_t size)
    111113{
    112         return (void *) __SYSCALL2(SYS_AS_GET_UNMAPPED_AREA,
    113             (sysarg_t) __entry, (sysarg_t) size);
     114        if (size == 0)
     115                return NULL;
     116       
     117        size_t sz = 1 << (fnzb(size - 1) + 1);
     118        if (last_allocated == 0)
     119                last_allocated = get_max_heap_addr();
     120       
     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);
     126       
     127        return ((void *) res);
    114128}
    115129
Note: See TracChangeset for help on using the changeset viewer.