lib/aos/paging.c
errval_t paging_map_fixed_attr(struct paging_state *st, lvaddr_t vaddr,
        struct capref frame, size_t bytes, int flags)
{
    errval_t err;
    size_t mapped_bytes = 0;
    if(slab_freecount(&st->slab_alloc) == 0) {
        struct capref slabframe;
        st->slot_alloc->alloc(st->slot_alloc,&slabframe);
        slab_refill_no_pagefault(&st->slab_alloc,slabframe,BASE_PAGE_SIZE);
    }
    struct paging_allocated_node *used_node = (struct paging_allocated_node *)slab_alloc(&st->slab_alloc);

    used_node->addr = vaddr;
    used_node->size = bytes;
    used_node->next = st->used_node_list;
    st->used_node_list = used_node;

    while(bytes > 0) {
        struct capref l2_pt;
        if (st->l2_page_tables[ARM_L1_OFFSET(vaddr)].init) {
            l2_pt = st->l2_page_tables[ARM_L1_OFFSET(vaddr)].cap;
        } else {
            err = arml2_alloc(st, &l2_pt);
            struct capref l2_map;
            err = st->slot_alloc->alloc(st->slot_alloc, &l2_map);
 
            err = vnode_map(st->l1_page_table, l2_pt, ARM_L1_OFFSET(vaddr), VREGION_FLAGS_READ_WRITE, 0, 1, l2_map);
 
            st->l2_page_tables[ARM_L1_OFFSET(vaddr)].cap = l2_pt;
            st->l2_page_tables[ARM_L1_OFFSET(vaddr)].init = true;
 
        }
 
        size_t leftover = MIN(bytes, (ARM_L2_MAX_ENTRIES - ARM_L2_OFFSET(vaddr)) * BASE_PAGE_SIZE);
 
        struct capref l2_frame;
        err = st->slot_alloc->alloc(st->slot_alloc, &l2_frame);
        err = vnode_map(l2_pt, frame, ARM_L2_OFFSET(vaddr), flags, mapped_bytes, leftover/BASE_PAGE_SIZE, l2_frame);
 
        mapped_bytes += leftover;
        bytes -= leftover;
        vaddr += leftover;
        
    }
    return SYS_ERR_OK;
}
/**
 * \brief map a user provided frame at user provided VA.
 */
\brief map a user provided frame at user provided VA.
\ brief map a user provided frame at user provided VA .
errval_t paging_map_fixed_attr(struct paging_state *st, lvaddr_t vaddr,
        struct capref frame, size_t bytes, int flags)
{
    errval_t err;
    size_t mapped_bytes = 0;
    if(slab_freecount(&st->slab_alloc) == 0) {
        struct capref slabframe;
        st->slot_alloc->alloc(st->slot_alloc,&slabframe);
        slab_refill_no_pagefault(&st->slab_alloc,slabframe,BASE_PAGE_SIZE);
    }
    struct paging_allocated_node *used_node = (struct paging_allocated_node *)slab_alloc(&st->slab_alloc);
    used_node->addr = vaddr;
    used_node->size = bytes;
    used_node->next = st->used_node_list;
    st->used_node_list = used_node;
    while(bytes > 0) {
        struct capref l2_pt;
        if (st->l2_page_tables[ARM_L1_OFFSET(vaddr)].init) {
            l2_pt = st->l2_page_tables[ARM_L1_OFFSET(vaddr)].cap;
        } else {
            err = arml2_alloc(st, &l2_pt);
            struct capref l2_map;
            err = st->slot_alloc->alloc(st->slot_alloc, &l2_map);
            err = vnode_map(st->l1_page_table, l2_pt, ARM_L1_OFFSET(vaddr), VREGION_FLAGS_READ_WRITE, 0, 1, l2_map);
            st->l2_page_tables[ARM_L1_OFFSET(vaddr)].cap = l2_pt;
            st->l2_page_tables[ARM_L1_OFFSET(vaddr)].init = true;
        }
        size_t leftover = MIN(bytes, (ARM_L2_MAX_ENTRIES - ARM_L2_OFFSET(vaddr)) * BASE_PAGE_SIZE);
        struct capref l2_frame;
        err = st->slot_alloc->alloc(st->slot_alloc, &l2_frame);
        err = vnode_map(l2_pt, frame, ARM_L2_OFFSET(vaddr), flags, mapped_bytes, leftover/BASE_PAGE_SIZE, l2_frame);
        mapped_bytes += leftover;
        bytes -= leftover;
        vaddr += leftover;
    }
    return SYS_ERR_OK;
}
errval_t paging_map_fixed_attr ( struct paging_state * st , lvaddr_t vaddr , struct capref frame , size_t bytes , int flags ) { errval_t err ; size_t mapped_bytes = 0 ; if ( slab_freecount ( & st -> slab_alloc ) == 0 ) { struct capref slabframe ; st -> slot_alloc -> alloc ( st -> slot_alloc , & slabframe ) ; slab_refill_no_pagefault ( & st -> slab_alloc , slabframe , BASE_PAGE_SIZE ) ; } struct paging_allocated_node * used_node = ( struct paging_allocated_node * ) slab_alloc ( & st -> slab_alloc ) ; used_node -> addr = vaddr ; used_node -> size = bytes ; used_node -> next = st -> used_node_list ; st -> used_node_list = used_node ; while ( bytes > 0 ) { struct capref l2_pt ; if ( st -> l2_page_tables [ ARM_L1_OFFSET ( vaddr ) ] . init ) { l2_pt = st -> l2_page_tables [ ARM_L1_OFFSET ( vaddr ) ] . cap ; } else { err = arml2_alloc ( st , & l2_pt ) ; struct capref l2_map ; err = st -> slot_alloc -> alloc ( st -> slot_alloc , & l2_map ) ; err = vnode_map ( st -> l1_page_table , l2_pt , ARM_L1_OFFSET ( vaddr ) , VREGION_FLAGS_READ_WRITE , 0 , 1 , l2_map ) ; st -> l2_page_tables [ ARM_L1_OFFSET ( vaddr ) ] . cap = l2_pt ; st -> l2_page_tables [ ARM_L1_OFFSET ( vaddr ) ] . init = true ; } size_t leftover = MIN ( bytes , ( ARM_L2_MAX_ENTRIES - ARM_L2_OFFSET ( vaddr ) ) * BASE_PAGE_SIZE ) ; struct capref l2_frame ; err = st -> slot_alloc -> alloc ( st -> slot_alloc , & l2_frame ) ; err = vnode_map ( l2_pt , frame , ARM_L2_OFFSET ( vaddr ) , flags , mapped_bytes , leftover / BASE_PAGE_SIZE , l2_frame ) ; mapped_bytes += leftover ; bytes -= leftover ; vaddr += leftover ; } return SYS_ERR_OK ; }
\brief map a user provided frame at user provided VA.
\ brief map a user provided frame at user provided VA .