Ignore:
File:
1 edited

Legend:

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

    r56273bb rb93d637  
    3535#include <as.h>
    3636#include <libc.h>
     37#include <errno.h>
    3738#include <unistd.h>
    3839#include <align.h>
     
    4041#include <bitops.h>
    4142#include <malloc.h>
    42 #include "private/libc.h"
     43
     44/** Last position allocated by as_get_mappable_page */
     45static uintptr_t last_allocated = 0;
    4346
    4447/** Create address space area.
     
    5154 *
    5255 */
    53 void *as_area_create(void *address, size_t size, unsigned int flags)
     56void *as_area_create(void *address, size_t size, int flags)
    5457{
    5558        return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address,
     
    6770 *
    6871 */
    69 int as_area_resize(void *address, size_t size, unsigned int flags)
     72int as_area_resize(void *address, size_t size, int flags)
    7073{
    7174        return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address,
     
    9598 *
    9699 */
    97 int as_area_change_flags(void *address, unsigned int flags)
     100int as_area_change_flags(void *address, int flags)
    98101{
    99102        return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address,
     
    101104}
    102105
    103 /** Return pointer to unmapped address space area
     106/** Return pointer to some unmapped area, where fits new as_area
    104107 *
    105108 * @param size Requested size of the allocation.
    106109 *
    107  * @return Pointer to the beginning of unmapped address space area.
     110 * @return pointer to the beginning
    108111 *
    109112 */
    110113void *as_get_mappable_page(size_t size)
    111114{
    112         return (void *) __SYSCALL2(SYS_AS_GET_UNMAPPED_AREA,
    113             (sysarg_t) __entry, (sysarg_t) size);
     115        if (size == 0)
     116                return NULL;
     117       
     118        size_t sz = 1 << (fnzb(size - 1) + 1);
     119        if (last_allocated == 0)
     120                last_allocated = get_max_heap_addr();
     121       
     122        /*
     123         * Make sure we allocate from naturally aligned address.
     124         */
     125        uintptr_t res = ALIGN_UP(last_allocated, sz);
     126        last_allocated = res + ALIGN_UP(size, PAGE_SIZE);
     127       
     128        return ((void *) res);
     129}
     130
     131/** Find mapping to physical address.
     132 *
     133 * @param address Virtual address in question (virtual).
     134 * @param[out] frame Frame address (physical).
     135 * @return Error code.
     136 * @retval EOK No error, @p frame holds the translation.
     137 * @retval ENOENT Mapping not found.
     138 */
     139int as_get_physical_mapping(void *address, uintptr_t *frame)
     140{
     141        uintptr_t tmp_frame;
     142        uintptr_t virt = (uintptr_t) address;
     143       
     144        int rc = (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING,
     145            (sysarg_t) virt, (sysarg_t) &tmp_frame);
     146        if (rc != EOK) {
     147                return rc;
     148        }
     149       
     150        if (frame != NULL) {
     151                *frame = tmp_frame;
     152        }
     153       
     154        return EOK;
    114155}
    115156
Note: See TracChangeset for help on using the changeset viewer.