Changeset bf9afa07 in mainline for libc/generic/as.c


Ignore:
Timestamp:
2006-06-02T11:35:05Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2d22049
Parents:
49d072e
Message:

Allocation function for allocating free areas for mmap, map_physmem etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libc/generic/as.c

    r49d072e rbf9afa07  
    2727 */
    2828
     29#include <stdlib.h>
     30#include <unistd.h>
     31#include <string.h>
     32#include <ddi.h>
     33#include <sysinfo.h>
     34#include <align.h>
     35#include <as.h>
     36#include <ipc/fb.h>
     37#include <ipc/ipc.h>
     38#include <ipc/ns.h>
     39#include <ipc/services.h>
     40#include <kernel/errno.h>
     41
     42
    2943#include <as.h>
    3044#include <libc.h>
    3145#include <unistd.h>
    32 #include <task.h>
     46#include <align.h>
    3347
    3448/** Create address space area.
     
    7185static size_t heapsize = 0;
    7286static size_t maxheapsize = (size_t)(-1);
     87
     88static void * last_allocated = 0;
     89
    7390/* Start of heap linker symbol */
    7491extern char _heap;
     
    108125}
    109126
     127/** Set maximum heap size and return pointer just after the heap */
    110128void *set_maxheapsize(size_t mhs)
    111129{
     
    115133
    116134}
     135
     136/** Return pointer to some unmapped area, where fits new as_area
     137 *
     138 * TODO: make some first_fit/... algorithm, we are now just incrementing
     139 *       the pointer to last area
     140 */
     141void * as_get_mappable_page(size_t sz)
     142{
     143        void *res;
     144
     145        /* Set heapsize to some meaningful value */
     146        if (maxheapsize == -1)
     147                set_maxheapsize(ALIGN_UP(USER_ADDRESS_SPACE_SIZE_ARCH>>1,PAGE_SIZE));
     148        if (!last_allocated)
     149                last_allocated = ALIGN_UP((void *)&_heap + maxheapsize, PAGE_SIZE);
     150       
     151        sz = ALIGN_UP(sz, PAGE_SIZE);
     152        res = last_allocated;
     153        last_allocated += sz;
     154
     155        return res;
     156}
Note: See TracChangeset for help on using the changeset viewer.