Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/as.c

    r30718cc2 rfc47885  
    7171#include <memstr.h>
    7272#include <macros.h>
    73 #include <bitops.h>
    7473#include <arch.h>
    7574#include <errno.h>
     
    289288/** Check area conflicts with other areas.
    290289 *
    291  * @param as    Address space.
    292  * @param addr  Starting virtual address of the area being tested.
    293  * @param count Number of pages in the area being tested.
    294  * @param avoid Do not touch this area.
     290 * @param as         Address space.
     291 * @param va         Starting virtual address of the area being tested.
     292 * @param size       Size of the area being tested.
     293 * @param avoid_area Do not touch this area.
    295294 *
    296295 * @return True if there is no conflict, false otherwise.
    297296 *
    298297 */
    299 NO_TRACE static bool check_area_conflicts(as_t *as, uintptr_t addr,
    300     size_t count, as_area_t *avoid)
    301 {
    302         ASSERT((addr % PAGE_SIZE) == 0);
     298NO_TRACE static bool check_area_conflicts(as_t *as, uintptr_t va, size_t size,
     299    as_area_t *avoid_area)
     300{
    303301        ASSERT(mutex_locked(&as->lock));
    304302       
     
    306304         * We don't want any area to have conflicts with NULL page.
    307305         */
    308         if (overlaps(addr, count << PAGE_WIDTH, (uintptr_t) NULL, PAGE_SIZE))
     306        if (overlaps(va, size, (uintptr_t) NULL, PAGE_SIZE))
    309307                return false;
    310308       
     
    318316        btree_node_t *leaf;
    319317        as_area_t *area =
    320             (as_area_t *) btree_search(&as->as_area_btree, addr, &leaf);
     318            (as_area_t *) btree_search(&as->as_area_btree, va, &leaf);
    321319        if (area) {
    322                 if (area != avoid)
     320                if (area != avoid_area)
    323321                        return false;
    324322        }
     
    330328                area = (as_area_t *) node->value[node->keys - 1];
    331329               
    332                 if (area != avoid) {
    333                         mutex_lock(&area->lock);
    334                        
    335                         if (overlaps(addr, count << PAGE_WIDTH,
    336                             area->base, area->pages << PAGE_WIDTH)) {
    337                                 mutex_unlock(&area->lock);
    338                                 return false;
    339                         }
    340                        
     330                mutex_lock(&area->lock);
     331               
     332                if (overlaps(va, size, area->base, area->pages * PAGE_SIZE)) {
    341333                        mutex_unlock(&area->lock);
    342                 }
     334                        return false;
     335                }
     336               
     337                mutex_unlock(&area->lock);
    343338        }
    344339       
     
    347342                area = (as_area_t *) node->value[0];
    348343               
    349                 if (area != avoid) {
    350                         mutex_lock(&area->lock);
    351                        
    352                         if (overlaps(addr, count << PAGE_WIDTH,
    353                             area->base, area->pages << PAGE_WIDTH)) {
    354                                 mutex_unlock(&area->lock);
    355                                 return false;
    356                         }
    357                        
     344                mutex_lock(&area->lock);
     345               
     346                if (overlaps(va, size, area->base, area->pages * PAGE_SIZE)) {
    358347                        mutex_unlock(&area->lock);
    359                 }
     348                        return false;
     349                }
     350               
     351                mutex_unlock(&area->lock);
    360352        }
    361353       
     
    365357                area = (as_area_t *) leaf->value[i];
    366358               
    367                 if (area == avoid)
     359                if (area == avoid_area)
    368360                        continue;
    369361               
    370362                mutex_lock(&area->lock);
    371363               
    372                 if (overlaps(addr, count << PAGE_WIDTH,
    373                     area->base, area->pages << PAGE_WIDTH)) {
     364                if (overlaps(va, size, area->base, area->pages * PAGE_SIZE)) {
    374365                        mutex_unlock(&area->lock);
    375366                        return false;
     
    384375         */
    385376        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    386                 return !overlaps(addr, count << PAGE_WIDTH,
     377                return !overlaps(va, size,
    387378                    KERNEL_ADDRESS_SPACE_START,
    388379                    KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START);
     
    411402    mem_backend_data_t *backend_data)
    412403{
    413         if ((base % PAGE_SIZE) != 0)
     404        if (base % PAGE_SIZE)
    414405                return NULL;
    415406       
    416         if (size == 0)
     407        if (!size)
    417408                return NULL;
    418        
    419         size_t pages = SIZE2FRAMES(size);
    420409       
    421410        /* Writeable executable areas are not supported. */
     
    425414        mutex_lock(&as->lock);
    426415       
    427         if (!check_area_conflicts(as, base, pages, NULL)) {
     416        if (!check_area_conflicts(as, base, size, NULL)) {
    428417                mutex_unlock(&as->lock);
    429418                return NULL;
     
    437426        area->flags = flags;
    438427        area->attributes = attrs;
    439         area->pages = pages;
     428        area->pages = SIZE2FRAMES(size);
    440429        area->resident = 0;
    441430        area->base = base;
     
    491480                mutex_lock(&area->lock);
    492481               
    493                 if ((area->base <= va) &&
    494                     (va < area->base + (area->pages << PAGE_WIDTH)))
     482                if ((area->base <= va) && (va < area->base + area->pages * PAGE_SIZE))
    495483                        return area;
    496484               
     
    508496                mutex_lock(&area->lock);
    509497               
    510                 if (va < area->base + (area->pages << PAGE_WIDTH))
     498                if (va < area->base + area->pages * PAGE_SIZE)
    511499                        return area;
    512500               
     
    573561       
    574562        if (pages < area->pages) {
    575                 uintptr_t start_free = area->base + (pages << PAGE_WIDTH);
     563                uintptr_t start_free = area->base + pages * PAGE_SIZE;
    576564               
    577565                /*
     
    586574                 */
    587575                ipl_t ipl = tlb_shootdown_start(TLB_INVL_PAGES, as->asid,
    588                     area->base + (pages << PAGE_WIDTH), area->pages - pages);
     576                    area->base + pages * PAGE_SIZE, area->pages - pages);
    589577               
    590578                /*
     
    609597                                size_t i = 0;
    610598                               
    611                                 if (overlaps(ptr, size << PAGE_WIDTH, area->base,
    612                                     pages << PAGE_WIDTH)) {
     599                                if (overlaps(ptr, size * PAGE_SIZE, area->base,
     600                                    pages * PAGE_SIZE)) {
    613601                                       
    614                                         if (ptr + (size << PAGE_WIDTH) <= start_free) {
     602                                        if (ptr + size * PAGE_SIZE <= start_free) {
    615603                                                /*
    616604                                                 * The whole interval fits
     
    644632                                for (; i < size; i++) {
    645633                                        pte_t *pte = page_mapping_find(as, ptr +
    646                                             (i << PAGE_WIDTH));
     634                                            i * PAGE_SIZE);
    647635                                       
    648636                                        ASSERT(pte);
     
    653641                                            (area->backend->frame_free)) {
    654642                                                area->backend->frame_free(area,
    655                                                     ptr + (i << PAGE_WIDTH),
     643                                                    ptr + i * PAGE_SIZE,
    656644                                                    PTE_GET_FRAME(pte));
    657645                                        }
    658646                                       
    659647                                        page_mapping_remove(as, ptr +
    660                                             (i << PAGE_WIDTH));
     648                                            i * PAGE_SIZE);
    661649                                }
    662650                        }
     
    667655                 */
    668656               
    669                 tlb_invalidate_pages(as->asid, area->base + (pages << PAGE_WIDTH),
     657                tlb_invalidate_pages(as->asid, area->base + pages * PAGE_SIZE,
    670658                    area->pages - pages);
    671659               
     
    674662                 */
    675663                as_invalidate_translation_cache(as, area->base +
    676                     (pages << PAGE_WIDTH), area->pages - pages);
     664                    pages * PAGE_SIZE, area->pages - pages);
    677665                tlb_shootdown_finalize(ipl);
    678666               
     
    683671                 * Check for overlaps with other address space areas.
    684672                 */
    685                 if (!check_area_conflicts(as, address, pages, area)) {
     673                if (!check_area_conflicts(as, address, pages * PAGE_SIZE,
     674                    area)) {
    686675                        mutex_unlock(&area->lock);
    687676                        mutex_unlock(&as->lock);
     
    782771                       
    783772                        for (size = 0; size < (size_t) node->value[i]; size++) {
    784                                 pte_t *pte =
    785                                     page_mapping_find(as, ptr + (size << PAGE_WIDTH));
     773                                pte_t *pte = page_mapping_find(as, ptr + size * PAGE_SIZE);
    786774                               
    787775                                ASSERT(pte);
     
    792780                                    (area->backend->frame_free)) {
    793781                                        area->backend->frame_free(area,
    794                                             ptr + (size << PAGE_WIDTH), PTE_GET_FRAME(pte));
     782                                            ptr + size * PAGE_SIZE, PTE_GET_FRAME(pte));
    795783                                }
    796784                               
    797                                 page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
     785                                page_mapping_remove(as, ptr + size * PAGE_SIZE);
    798786                        }
    799787                }
     
    882870        }
    883871       
    884         size_t src_size = src_area->pages << PAGE_WIDTH;
     872        size_t src_size = src_area->pages * PAGE_SIZE;
    885873        unsigned int src_flags = src_area->flags;
    886874        mem_backend_t *src_backend = src_area->backend;
     
    10881076                       
    10891077                        for (size = 0; size < (size_t) node->value[i]; size++) {
    1090                                 pte_t *pte =
    1091                                     page_mapping_find(as, ptr + (size << PAGE_WIDTH));
     1078                                pte_t *pte = page_mapping_find(as, ptr + size * PAGE_SIZE);
    10921079                               
    10931080                                ASSERT(pte);
     
    10981085                               
    10991086                                /* Remove old mapping */
    1100                                 page_mapping_remove(as, ptr + (size << PAGE_WIDTH));
     1087                                page_mapping_remove(as, ptr + size * PAGE_SIZE);
    11011088                        }
    11021089                }
     
    11441131                               
    11451132                                /* Insert the new mapping */
    1146                                 page_mapping_insert(as, ptr + (size << PAGE_WIDTH),
     1133                                page_mapping_insert(as, ptr + size * PAGE_SIZE,
    11471134                                    old_frame[frame_idx++], page_flags);
    11481135                               
     
    14661453       
    14671454        if (src_area) {
    1468                 size = src_area->pages << PAGE_WIDTH;
     1455                size = src_area->pages * PAGE_SIZE;
    14691456                mutex_unlock(&src_area->lock);
    14701457        } else
     
    15211508                if (page >= right_pg) {
    15221509                        /* Do nothing. */
    1523                 } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1524                     left_cnt << PAGE_WIDTH)) {
     1510                } else if (overlaps(page, count * PAGE_SIZE, left_pg,
     1511                    left_cnt * PAGE_SIZE)) {
    15251512                        /* The interval intersects with the left interval. */
    15261513                        return false;
    1527                 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1528                     right_cnt << PAGE_WIDTH)) {
     1514                } else if (overlaps(page, count * PAGE_SIZE, right_pg,
     1515                    right_cnt * PAGE_SIZE)) {
    15291516                        /* The interval intersects with the right interval. */
    15301517                        return false;
    1531                 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
    1532                     (page + (count << PAGE_WIDTH) == right_pg)) {
     1518                } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
     1519                    (page + count * PAGE_SIZE == right_pg)) {
    15331520                        /*
    15341521                         * The interval can be added by merging the two already
     
    15381525                        btree_remove(&area->used_space, right_pg, leaf);
    15391526                        goto success;
    1540                 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
     1527                } else if (page == left_pg + left_cnt * PAGE_SIZE) {
    15411528                        /*
    15421529                         * The interval can be added by simply growing the left
     
    15451532                        node->value[node->keys - 1] += count;
    15461533                        goto success;
    1547                 } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1534                } else if (page + count * PAGE_SIZE == right_pg) {
    15481535                        /*
    15491536                         * The interval can be addded by simply moving base of
     
    15721559                 */
    15731560               
    1574                 if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1575                     right_cnt << PAGE_WIDTH)) {
     1561                if (overlaps(page, count * PAGE_SIZE, right_pg,
     1562                    right_cnt * PAGE_SIZE)) {
    15761563                        /* The interval intersects with the right interval. */
    15771564                        return false;
    1578                 } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1565                } else if (page + count * PAGE_SIZE == right_pg) {
    15791566                        /*
    15801567                         * The interval can be added by moving the base of the
     
    16111598                if (page < left_pg) {
    16121599                        /* Do nothing. */
    1613                 } else if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1614                     left_cnt << PAGE_WIDTH)) {
     1600                } else if (overlaps(page, count * PAGE_SIZE, left_pg,
     1601                    left_cnt * PAGE_SIZE)) {
    16151602                        /* The interval intersects with the left interval. */
    16161603                        return false;
    1617                 } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1618                     right_cnt << PAGE_WIDTH)) {
     1604                } else if (overlaps(page, count * PAGE_SIZE, right_pg,
     1605                    right_cnt * PAGE_SIZE)) {
    16191606                        /* The interval intersects with the right interval. */
    16201607                        return false;
    1621                 } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
    1622                     (page + (count << PAGE_WIDTH) == right_pg)) {
     1608                } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
     1609                    (page + count * PAGE_SIZE == right_pg)) {
    16231610                        /*
    16241611                         * The interval can be added by merging the two already
     
    16281615                        btree_remove(&area->used_space, right_pg, node);
    16291616                        goto success;
    1630                 } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
     1617                } else if (page == left_pg + left_cnt * PAGE_SIZE) {
    16311618                        /*
    16321619                         * The interval can be added by simply growing the left
     
    16351622                        leaf->value[leaf->keys - 1] += count;
    16361623                        goto success;
    1637                 } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1624                } else if (page + count * PAGE_SIZE == right_pg) {
    16381625                        /*
    16391626                         * The interval can be addded by simply moving base of
     
    16621649                 */
    16631650               
    1664                 if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1665                     left_cnt << PAGE_WIDTH)) {
     1651                if (overlaps(page, count * PAGE_SIZE, left_pg,
     1652                    left_cnt * PAGE_SIZE)) {
    16661653                        /* The interval intersects with the left interval. */
    16671654                        return false;
    1668                 } else if (left_pg + (left_cnt << PAGE_WIDTH) == page) {
     1655                } else if (left_pg + left_cnt * PAGE_SIZE == page) {
    16691656                        /*
    16701657                         * The interval can be added by growing the left
     
    17011688                         */
    17021689                       
    1703                         if (overlaps(page, count << PAGE_WIDTH, left_pg,
    1704                             left_cnt << PAGE_WIDTH)) {
     1690                        if (overlaps(page, count * PAGE_SIZE, left_pg,
     1691                            left_cnt * PAGE_SIZE)) {
    17051692                                /*
    17061693                                 * The interval intersects with the left
     
    17081695                                 */
    17091696                                return false;
    1710                         } else if (overlaps(page, count << PAGE_WIDTH, right_pg,
    1711                             right_cnt << PAGE_WIDTH)) {
     1697                        } else if (overlaps(page, count * PAGE_SIZE, right_pg,
     1698                            right_cnt * PAGE_SIZE)) {
    17121699                                /*
    17131700                                 * The interval intersects with the right
     
    17151702                                 */
    17161703                                return false;
    1717                         } else if ((page == left_pg + (left_cnt << PAGE_WIDTH)) &&
    1718                             (page + (count << PAGE_WIDTH) == right_pg)) {
     1704                        } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
     1705                            (page + count * PAGE_SIZE == right_pg)) {
    17191706                                /*
    17201707                                 * The interval can be added by merging the two
     
    17241711                                btree_remove(&area->used_space, right_pg, leaf);
    17251712                                goto success;
    1726                         } else if (page == left_pg + (left_cnt << PAGE_WIDTH)) {
     1713                        } else if (page == left_pg + left_cnt * PAGE_SIZE) {
    17271714                                /*
    17281715                                 * The interval can be added by simply growing
     
    17311718                                leaf->value[i - 1] += count;
    17321719                                goto success;
    1733                         } else if (page + (count << PAGE_WIDTH) == right_pg) {
     1720                        } else if (page + count * PAGE_SIZE == right_pg) {
    17341721                                /*
    17351722                                 * The interval can be addded by simply moving
     
    17971784                        for (i = 0; i < leaf->keys; i++) {
    17981785                                if (leaf->key[i] == page) {
    1799                                         leaf->key[i] += count << PAGE_WIDTH;
     1786                                        leaf->key[i] += count * PAGE_SIZE;
    18001787                                        leaf->value[i] -= count;
    18011788                                        goto success;
     
    18121799                size_t left_cnt = (size_t) node->value[node->keys - 1];
    18131800               
    1814                 if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
    1815                     count << PAGE_WIDTH)) {
    1816                         if (page + (count << PAGE_WIDTH) ==
    1817                             left_pg + (left_cnt << PAGE_WIDTH)) {
     1801                if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
     1802                    count * PAGE_SIZE)) {
     1803                        if (page + count * PAGE_SIZE ==
     1804                            left_pg + left_cnt * PAGE_SIZE) {
    18181805                                /*
    18191806                                 * The interval is contained in the rightmost
     
    18241811                                node->value[node->keys - 1] -= count;
    18251812                                goto success;
    1826                         } else if (page + (count << PAGE_WIDTH) <
    1827                             left_pg + (left_cnt << PAGE_WIDTH)) {
     1813                        } else if (page + count * PAGE_SIZE <
     1814                            left_pg + left_cnt*PAGE_SIZE) {
    18281815                                /*
    18291816                                 * The interval is contained in the rightmost
     
    18331820                                 * new interval.
    18341821                                 */
    1835                                 size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
    1836                                     (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
     1822                                size_t new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
     1823                                    (page + count*PAGE_SIZE)) >> PAGE_WIDTH;
    18371824                                node->value[node->keys - 1] -= count + new_cnt;
    18381825                                btree_insert(&area->used_space, page +
    1839                                     (count << PAGE_WIDTH), (void *) new_cnt, leaf);
     1826                                    count * PAGE_SIZE, (void *) new_cnt, leaf);
    18401827                                goto success;
    18411828                        }
     
    18501837                size_t left_cnt = (size_t) leaf->value[leaf->keys - 1];
    18511838               
    1852                 if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
    1853                     count << PAGE_WIDTH)) {
    1854                         if (page + (count << PAGE_WIDTH) ==
    1855                             left_pg + (left_cnt << PAGE_WIDTH)) {
     1839                if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
     1840                    count * PAGE_SIZE)) {
     1841                        if (page + count * PAGE_SIZE ==
     1842                            left_pg + left_cnt * PAGE_SIZE) {
    18561843                                /*
    18571844                                 * The interval is contained in the rightmost
     
    18611848                                leaf->value[leaf->keys - 1] -= count;
    18621849                                goto success;
    1863                         } else if (page + (count << PAGE_WIDTH) < left_pg +
    1864                             (left_cnt << PAGE_WIDTH)) {
     1850                        } else if (page + count * PAGE_SIZE < left_pg +
     1851                            left_cnt * PAGE_SIZE) {
    18651852                                /*
    18661853                                 * The interval is contained in the rightmost
     
    18701857                                 * interval.
    18711858                                 */
    1872                                 size_t new_cnt = ((left_pg + (left_cnt << PAGE_WIDTH)) -
    1873                                     (page + (count << PAGE_WIDTH))) >> PAGE_WIDTH;
     1859                                size_t new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
     1860                                    (page + count * PAGE_SIZE)) >> PAGE_WIDTH;
    18741861                                leaf->value[leaf->keys - 1] -= count + new_cnt;
    18751862                                btree_insert(&area->used_space, page +
    1876                                     (count << PAGE_WIDTH), (void *) new_cnt, leaf);
     1863                                    count * PAGE_SIZE, (void *) new_cnt, leaf);
    18771864                                goto success;
    18781865                        }
     
    18961883                         * to (i - 1) and i.
    18971884                         */
    1898                         if (overlaps(left_pg, left_cnt << PAGE_WIDTH, page,
    1899                             count << PAGE_WIDTH)) {
    1900                                 if (page + (count << PAGE_WIDTH) ==
    1901                                     left_pg + (left_cnt << PAGE_WIDTH)) {
     1885                        if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
     1886                            count * PAGE_SIZE)) {
     1887                                if (page + count * PAGE_SIZE ==
     1888                                    left_pg + left_cnt*PAGE_SIZE) {
    19021889                                        /*
    19031890                                         * The interval is contained in the
     
    19081895                                        leaf->value[i - 1] -= count;
    19091896                                        goto success;
    1910                                 } else if (page + (count << PAGE_WIDTH) <
    1911                                     left_pg + (left_cnt << PAGE_WIDTH)) {
     1897                                } else if (page + count * PAGE_SIZE <
     1898                                    left_pg + left_cnt * PAGE_SIZE) {
    19121899                                        /*
    19131900                                         * The interval is contained in the
     
    19181905                                         */
    19191906                                        size_t new_cnt = ((left_pg +
    1920                                             (left_cnt << PAGE_WIDTH)) -
    1921                                             (page + (count << PAGE_WIDTH))) >>
     1907                                            left_cnt * PAGE_SIZE) -
     1908                                            (page + count * PAGE_SIZE)) >>
    19221909                                            PAGE_WIDTH;
    19231910                                        leaf->value[i - 1] -= count + new_cnt;
    19241911                                        btree_insert(&area->used_space, page +
    1925                                             (count << PAGE_WIDTH), (void *) new_cnt,
     1912                                            count * PAGE_SIZE, (void *) new_cnt,
    19261913                                            leaf);
    19271914                                        goto success;
     
    19491936sysarg_t sys_as_area_create(uintptr_t address, size_t size, unsigned int flags)
    19501937{
    1951         if (as_area_create(AS, flags, size, address,
     1938        if (as_area_create(AS, flags | AS_AREA_CACHEABLE, size, address,
    19521939            AS_AREA_ATTR_NONE, &anon_backend, NULL))
    19531940                return (sysarg_t) address;
     
    19721959{
    19731960        return (sysarg_t) as_area_destroy(AS, address);
    1974 }
    1975 
    1976 /** Return pointer to unmapped address space area
    1977  *
    1978  * @param base Lowest address bound.
    1979  * @param size Requested size of the allocation.
    1980  *
    1981  * @return Pointer to the beginning of unmapped address space area.
    1982  *
    1983  */
    1984 sysarg_t sys_as_get_unmapped_area(uintptr_t base, size_t size)
    1985 {
    1986         if (size == 0)
    1987                 return 0;
    1988        
    1989         /*
    1990          * Make sure we allocate from page-aligned
    1991          * address. Check for possible overflow in
    1992          * each step.
    1993          */
    1994        
    1995         size_t pages = SIZE2FRAMES(size);
    1996         uintptr_t ret = 0;
    1997        
    1998         /*
    1999          * Find the lowest unmapped address aligned on the sz
    2000          * boundary, not smaller than base and of the required size.
    2001          */
    2002        
    2003         mutex_lock(&AS->lock);
    2004        
    2005         /* First check the base address itself */
    2006         uintptr_t addr = ALIGN_UP(base, PAGE_SIZE);
    2007         if ((addr >= base) &&
    2008             (check_area_conflicts(AS, addr, pages, NULL)))
    2009                 ret = addr;
    2010        
    2011         /* Eventually check the addresses behind each area */
    2012         link_t *cur;
    2013         for (cur = AS->as_area_btree.leaf_head.next;
    2014             (ret == 0) && (cur != &AS->as_area_btree.leaf_head);
    2015             cur = cur->next) {
    2016                 btree_node_t *node =
    2017                     list_get_instance(cur, btree_node_t, leaf_link);
    2018                
    2019                 btree_key_t i;
    2020                 for (i = 0; (ret == 0) && (i < node->keys); i++) {
    2021                         as_area_t *area = (as_area_t *) node->value[i];
    2022                        
    2023                         mutex_lock(&area->lock);
    2024                        
    2025                         uintptr_t addr =
    2026                             ALIGN_UP(area->base + (area->pages << PAGE_WIDTH),
    2027                             PAGE_SIZE);
    2028                        
    2029                         if ((addr >= base) && (addr >= area->base) &&
    2030                             (check_area_conflicts(AS, addr, pages, area)))
    2031                                 ret = addr;
    2032                        
    2033                         mutex_unlock(&area->lock);
    2034                 }
    2035         }
    2036        
    2037         mutex_unlock(&AS->lock);
    2038        
    2039         return (sysarg_t) ret;
    20401961}
    20411962
     
    21062027        mutex_lock(&as->lock);
    21072028       
    2108         /* Print out info about address space areas */
     2029        /* print out info about address space areas */
    21092030        link_t *cur;
    21102031        for (cur = as->as_area_btree.leaf_head.next;
Note: See TracChangeset for help on using the changeset viewer.