Changeset eb522e8 in mainline for uspace/lib/c/generic/as.c


Ignore:
Timestamp:
2011-06-01T08:43:42Z (14 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8d6c1f1
Parents:
9e2e715 (diff), e51a514 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Huuuuuge merge from development - all the work actually :)

File:
1 edited

Legend:

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

    r9e2e715 reb522e8  
    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 
    43 /** Last position allocated by as_get_mappable_page */
    44 static uintptr_t last_allocated = 0;
     43#include "private/libc.h"
    4544
    4645/** Create address space area.
     
    5352 *
    5453 */
    55 void *as_area_create(void *address, size_t size, int flags)
     54void *as_area_create(void *address, size_t size, unsigned int flags)
    5655{
    5756        return (void *) __SYSCALL3(SYS_AS_AREA_CREATE, (sysarg_t) address,
     
    6968 *
    7069 */
    71 int as_area_resize(void *address, size_t size, int flags)
     70int as_area_resize(void *address, size_t size, unsigned int flags)
    7271{
    7372        return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address,
     
    9796 *
    9897 */
    99 int as_area_change_flags(void *address, int flags)
     98int as_area_change_flags(void *address, unsigned int flags)
    10099{
    101100        return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address,
     
    103102}
    104103
    105 /** Return pointer to some unmapped area, where fits new as_area
     104/** Return pointer to unmapped address space area
    106105 *
    107106 * @param size Requested size of the allocation.
    108107 *
    109  * @return pointer to the beginning
     108 * @return Pointer to the beginning of unmapped address space area.
    110109 *
    111110 */
    112111void *as_get_mappable_page(size_t size)
    113112{
    114         if (size == 0)
    115                 return NULL;
     113        return (void *) __SYSCALL2(SYS_AS_GET_UNMAPPED_AREA,
     114            (sysarg_t) __entry, (sysarg_t) size);
     115}
     116
     117/** Find mapping to physical address.
     118 *
     119 * @param address Virtual address in question (virtual).
     120 * @param[out] frame Frame address (physical).
     121 * @return Error code.
     122 * @retval EOK No error, @p frame holds the translation.
     123 * @retval ENOENT Mapping not found.
     124 */
     125int as_get_physical_mapping(void *address, uintptr_t *frame)
     126{
     127        uintptr_t tmp_frame;
     128        uintptr_t virt = (uintptr_t) address;
    116129       
    117         size_t sz = 1 << (fnzb(size - 1) + 1);
    118         if (last_allocated == 0)
    119                 last_allocated = get_max_heap_addr();
     130        int rc = (int) __SYSCALL2(SYS_PAGE_FIND_MAPPING,
     131            (sysarg_t) virt, (sysarg_t) &tmp_frame);
     132        if (rc != EOK) {
     133                return rc;
     134        }
    120135       
    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);
     136        if (frame != NULL) {
     137                *frame = tmp_frame;
     138        }
    126139       
    127         return ((void *) res);
     140        return EOK;
    128141}
    129142
Note: See TracChangeset for help on using the changeset viewer.