Changeset 6f4495f5 in mainline for kernel/generic/src/mm/as.c


Ignore:
Timestamp:
2007-01-27T17:32:13Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1ba41c5
Parents:
51baa8a
Message:

Indentaion and formatting changes even Martin will like :-)

File:
1 edited

Legend:

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

    r51baa8a r6f4495f5  
    9494static slab_cache_t *as_slab;
    9595
    96 /** This lock protects inactive_as_with_asid_head list. It must be acquired before as_t mutex. */
     96/**
     97 * This lock protects inactive_as_with_asid_head list. It must be acquired
     98 * before as_t mutex.
     99 */
    97100SPINLOCK_INITIALIZE(inactive_as_with_asid_lock);
    98101
     
    108111static int area_flags_to_page_flags(int aflags);
    109112static as_area_t *find_area_and_lock(as_t *as, uintptr_t va);
    110 static bool check_area_conflicts(as_t *as, uintptr_t va, size_t size, as_area_t *avoid_area);
     113static bool check_area_conflicts(as_t *as, uintptr_t va, size_t size,
     114    as_area_t *avoid_area);
    111115static void sh_info_remove_reference(share_info_t *sh_info);
    112116
     
    137141       
    138142        as_slab = slab_cache_create("as_slab", sizeof(as_t), 0,
    139                 as_constructor, as_destructor, SLAB_CACHE_MAGDEFERRED);
     143            as_constructor, as_destructor, SLAB_CACHE_MAGDEFERRED);
    140144       
    141145        AS_KERNEL = as_create(FLAG_AS_KERNEL);
     
    172176/** Destroy adress space.
    173177 *
    174  * When there are no tasks referencing this address space (i.e. its refcount is zero),
    175  * the address space can be destroyed.
     178 * When there are no tasks referencing this address space (i.e. its refcount is
     179 * zero), the address space can be destroyed.
    176180 */
    177181void as_destroy(as_t *as)
     
    204208
    205209                ASSERT(!list_empty(&as->as_area_btree.leaf_head));
    206                 node = list_get_instance(as->as_area_btree.leaf_head.next, btree_node_t, leaf_link);
     210                node = list_get_instance(as->as_area_btree.leaf_head.next,
     211                    btree_node_t, leaf_link);
    207212
    208213                if ((cond = node->keys)) {
     
    273278                a->backend_data = *backend_data;
    274279        else
    275                 memsetb((uintptr_t) &a->backend_data, sizeof(a->backend_data), 0);
     280                memsetb((uintptr_t) &a->backend_data, sizeof(a->backend_data),
     281                    0);
    276282
    277283        btree_create(&a->used_space);
     
    288294 *
    289295 * @param as Address space.
    290  * @param address Virtual address belonging to the area to be changed. Must be page-aligned.
     296 * @param address Virtual address belonging to the area to be changed. Must be
     297 *     page-aligned.
    291298 * @param size New size of the virtual memory block starting at address.
    292299 * @param flags Flags influencing the remap operation. Currently unused.
     
    357364                 * Start TLB shootdown sequence.
    358365                 */
    359                 tlb_shootdown_start(TLB_INVL_PAGES, AS->asid, area->base + pages*PAGE_SIZE, area->pages - pages);
     366                tlb_shootdown_start(TLB_INVL_PAGES, AS->asid, area->base +
     367                    pages * PAGE_SIZE, area->pages - pages);
    360368
    361369                /*
     
    370378               
    371379                        ASSERT(!list_empty(&area->used_space.leaf_head));
    372                         node = list_get_instance(area->used_space.leaf_head.prev, btree_node_t, leaf_link);
     380                        node =
     381                            list_get_instance(area->used_space.leaf_head.prev,
     382                            btree_node_t, leaf_link);
    373383                        if ((cond = (bool) node->keys)) {
    374384                                uintptr_t b = node->key[node->keys - 1];
    375                                 count_t c = (count_t) node->value[node->keys - 1];
     385                                count_t c =
     386                                    (count_t) node->value[node->keys - 1];
    376387                                int i = 0;
    377388                       
    378                                 if (overlaps(b, c*PAGE_SIZE, area->base, pages*PAGE_SIZE)) {
     389                                if (overlaps(b, c * PAGE_SIZE, area->base,
     390                                    pages*PAGE_SIZE)) {
    379391                                       
    380                                         if (b + c*PAGE_SIZE <= start_free) {
     392                                        if (b + c * PAGE_SIZE <= start_free) {
    381393                                                /*
    382                                                  * The whole interval fits completely
    383                                                  * in the resized address space area.
     394                                                 * The whole interval fits
     395                                                 * completely in the resized
     396                                                 * address space area.
    384397                                                 */
    385398                                                break;
     
    387400               
    388401                                        /*
    389                                          * Part of the interval corresponding to b and c
    390                                          * overlaps with the resized address space area.
     402                                         * Part of the interval corresponding
     403                                         * to b and c overlaps with the resized
     404                                         * address space area.
    391405                                         */
    392406               
    393407                                        cond = false;   /* we are almost done */
    394408                                        i = (start_free - b) >> PAGE_WIDTH;
    395                                         if (!used_space_remove(area, start_free, c - i))
    396                                                 panic("Could not remove used space.\n");
     409                                        if (!used_space_remove(area, start_free,
     410                                            c - i))
     411                                                panic("Could not remove used "
     412                                                    "space.\n");
    397413                                } else {
    398414                                        /*
    399                                          * The interval of used space can be completely removed.
     415                                         * The interval of used space can be
     416                                         * completely removed.
    400417                                         */
    401418                                        if (!used_space_remove(area, b, c))
    402                                                 panic("Could not remove used space.\n");
     419                                                panic("Could not remove used "
     420                                                    "space.\n");
    403421                                }
    404422                       
     
    407425                       
    408426                                        page_table_lock(as, false);
    409                                         pte = page_mapping_find(as, b + i*PAGE_SIZE);
    410                                         ASSERT(pte && PTE_VALID(pte) && PTE_PRESENT(pte));
    411                                         if (area->backend && area->backend->frame_free) {
     427                                        pte = page_mapping_find(as, b +
     428                                            i * PAGE_SIZE);
     429                                        ASSERT(pte && PTE_VALID(pte) &&
     430                                            PTE_PRESENT(pte));
     431                                        if (area->backend &&
     432                                            area->backend->frame_free) {
    412433                                                area->backend->frame_free(area,
    413                                                         b + i*PAGE_SIZE, PTE_GET_FRAME(pte));
     434                                                    b + i * PAGE_SIZE,
     435                                                    PTE_GET_FRAME(pte));
    414436                                        }
    415                                         page_mapping_remove(as, b + i*PAGE_SIZE);
     437                                        page_mapping_remove(as, b +
     438                                            i * PAGE_SIZE);
    416439                                        page_table_unlock(as, false);
    417440                                }
     
    422445                 * Finish TLB shootdown sequence.
    423446                 */
    424                 tlb_invalidate_pages(as->asid, area->base + pages*PAGE_SIZE, area->pages - pages);
     447                tlb_invalidate_pages(as->asid, area->base + pages * PAGE_SIZE,
     448                    area->pages - pages);
    425449                tlb_shootdown_finalize();
    426450               
     
    428452                 * Invalidate software translation caches (e.g. TSB on sparc64).
    429453                 */
    430                 as_invalidate_translation_cache(as, area->base + pages*PAGE_SIZE, area->pages - pages);
     454                as_invalidate_translation_cache(as, area->base +
     455                    pages * PAGE_SIZE, area->pages - pages);
    431456        } else {
    432457                /*
     
    434459                 * Check for overlaps with other address space areas.
    435460                 */
    436                 if (!check_area_conflicts(as, address, pages * PAGE_SIZE, area)) {
     461                if (!check_area_conflicts(as, address, pages * PAGE_SIZE,
     462                    area)) {
    437463                        mutex_unlock(&area->lock);
    438464                        mutex_unlock(&as->lock);               
     
    485511         * Visit only the pages mapped by used_space B+tree.
    486512         */
    487         for (cur = area->used_space.leaf_head.next; cur != &area->used_space.leaf_head; cur = cur->next) {
     513        for (cur = area->used_space.leaf_head.next;
     514            cur != &area->used_space.leaf_head; cur = cur->next) {
    488515                btree_node_t *node;
    489516                int i;
     
    497524                        for (j = 0; j < (count_t) node->value[i]; j++) {
    498525                                page_table_lock(as, false);
    499                                 pte = page_mapping_find(as, b + j*PAGE_SIZE);
    500                                 ASSERT(pte && PTE_VALID(pte) && PTE_PRESENT(pte));
    501                                 if (area->backend && area->backend->frame_free) {
    502                                         area->backend->frame_free(area,
    503                                                 b + j*PAGE_SIZE, PTE_GET_FRAME(pte));
     526                                pte = page_mapping_find(as, b + j * PAGE_SIZE);
     527                                ASSERT(pte && PTE_VALID(pte) &&
     528                                    PTE_PRESENT(pte));
     529                                if (area->backend &&
     530                                    area->backend->frame_free) {
     531                                        area->backend->frame_free(area, b +
     532                                        j * PAGE_SIZE, PTE_GET_FRAME(pte));
    504533                                }
    505                                 page_mapping_remove(as, b + j*PAGE_SIZE);                               
     534                                page_mapping_remove(as, b + j * PAGE_SIZE);                             
    506535                                page_table_unlock(as, false);
    507536                        }
     
    516545       
    517546        /*
    518          * Invalidate potential software translation caches (e.g. TSB on sparc64).
     547         * Invalidate potential software translation caches (e.g. TSB on
     548         * sparc64).
    519549         */
    520550        as_invalidate_translation_cache(as, area->base, area->pages);
     
    606636                dst_flags_mask |= AS_AREA_CACHEABLE;
    607637
    608         if (src_size != acc_size || (src_flags & dst_flags_mask) != dst_flags_mask) {
     638        if (src_size != acc_size ||
     639            (src_flags & dst_flags_mask) != dst_flags_mask) {
    609640                mutex_unlock(&src_area->lock);
    610641                mutex_unlock(&src_as->lock);
     
    659690         */
    660691        dst_area = as_area_create(dst_as, dst_flags_mask, src_size, dst_base,
    661                                   AS_AREA_ATTR_PARTIAL, src_backend, &src_backend_data);
     692            AS_AREA_ATTR_PARTIAL, src_backend, &src_backend_data);
    662693        if (!dst_area) {
    663694                /*
     
    777808                if (PTE_PRESENT(pte)) {
    778809                        if (((access == PF_ACCESS_READ) && PTE_READABLE(pte)) ||
    779                                 (access == PF_ACCESS_WRITE && PTE_WRITABLE(pte)) ||
    780                                 (access == PF_ACCESS_EXEC && PTE_EXECUTABLE(pte))) {
     810                            (access == PF_ACCESS_WRITE && PTE_WRITABLE(pte)) ||
     811                            (access == PF_ACCESS_EXEC && PTE_EXECUTABLE(pte))) {
    781812                                page_table_unlock(AS, false);
    782813                                mutex_unlock(&area->lock);
     
    805836        if (THREAD->in_copy_from_uspace) {
    806837                THREAD->in_copy_from_uspace = false;
    807                 istate_set_retaddr(istate, (uintptr_t) &memcpy_from_uspace_failover_address);
     838                istate_set_retaddr(istate,
     839                    (uintptr_t) &memcpy_from_uspace_failover_address);
    808840        } else if (THREAD->in_copy_to_uspace) {
    809841                THREAD->in_copy_to_uspace = false;
    810                 istate_set_retaddr(istate, (uintptr_t) &memcpy_to_uspace_failover_address);
     842                istate_set_retaddr(istate,
     843                    (uintptr_t) &memcpy_to_uspace_failover_address);
    811844        } else {
    812845                return AS_PF_FAULT;
     
    846879                         */
    847880                         ASSERT(old->asid != ASID_INVALID);
    848                          list_append(&old->inactive_as_with_asid_link, &inactive_as_with_asid_head);
     881                         list_append(&old->inactive_as_with_asid_link,
     882                             &inactive_as_with_asid_head);
    849883                }
    850884                mutex_unlock(&old->lock);
     
    862896        mutex_lock_active(&new->lock);
    863897        if ((new->cpu_refcount++ == 0) && (new != AS_KERNEL)) {
    864                 if (new->asid != ASID_INVALID)
     898                if (new->asid != ASID_INVALID) {
    865899                        list_remove(&new->inactive_as_with_asid_link);
    866                 else
    867                         needs_asid = true;      /* defer call to asid_get() until new->lock is released */
     900                } else {
     901                        /*
     902                         * Defer call to asid_get() until new->lock is released.
     903                         */
     904                        needs_asid = true;
     905                }
    868906        }
    869907        SET_PTL0_ADDRESS(new->page_table);
     
    10071045 * @param va Virtual address.
    10081046 *
    1009  * @return Locked address space area containing va on success or NULL on failure.
     1047 * @return Locked address space area containing va on success or NULL on
     1048 *     failure.
    10101049 */
    10111050as_area_t *find_area_and_lock(as_t *as, uintptr_t va)
     
    10421081         * Because of its position in the B+tree, it must have base < va.
    10431082         */
    1044         if ((lnode = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf))) {
     1083        lnode = btree_leaf_node_left_neighbour(&as->as_area_btree, leaf);
     1084        if (lnode) {
    10451085                a = (as_area_t *) lnode->value[lnode->keys - 1];
    10461086                mutex_lock(&a->lock);
     
    10651105 * @return True if there is no conflict, false otherwise.
    10661106 */
    1067 bool check_area_conflicts(as_t *as, uintptr_t va, size_t size, as_area_t *avoid_area)
     1107bool check_area_conflicts(as_t *as, uintptr_t va, size_t size,
     1108                          as_area_t *avoid_area)
    10681109{
    10691110        as_area_t *a;
     
    11001141                mutex_unlock(&a->lock);
    11011142        }
    1102         if ((node = btree_leaf_node_right_neighbour(&as->as_area_btree, leaf))) {
     1143        node = btree_leaf_node_right_neighbour(&as->as_area_btree, leaf);
     1144        if (node) {
    11031145                a = (as_area_t *) node->value[0];
    11041146                mutex_lock(&a->lock);
     
    11311173        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    11321174                return !overlaps(va, size,
    1133                         KERNEL_ADDRESS_SPACE_START, KERNEL_ADDRESS_SPACE_END-KERNEL_ADDRESS_SPACE_START);
     1175                    KERNEL_ADDRESS_SPACE_START,
     1176                    KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START);
    11341177        }
    11351178
     
    11901233        node = btree_leaf_node_left_neighbour(&a->used_space, leaf);
    11911234        if (node) {
    1192                 uintptr_t left_pg = node->key[node->keys - 1], right_pg = leaf->key[0];
    1193                 count_t left_cnt = (count_t) node->value[node->keys - 1], right_cnt = (count_t) leaf->value[0];
     1235                uintptr_t left_pg = node->key[node->keys - 1];
     1236                uintptr_t right_pg = leaf->key[0];
     1237                count_t left_cnt = (count_t) node->value[node->keys - 1];
     1238                count_t right_cnt = (count_t) leaf->value[0];
    11941239               
    11951240                /*
     
    12011246                if (page >= right_pg) {
    12021247                        /* Do nothing. */
    1203                 } else if (overlaps(page, count*PAGE_SIZE, left_pg, left_cnt*PAGE_SIZE)) {
     1248                } else if (overlaps(page, count * PAGE_SIZE, left_pg,
     1249                    left_cnt * PAGE_SIZE)) {
    12041250                        /* The interval intersects with the left interval. */
    12051251                        return 0;
    1206                 } else if (overlaps(page, count*PAGE_SIZE, right_pg, right_cnt*PAGE_SIZE)) {
     1252                } else if (overlaps(page, count * PAGE_SIZE, right_pg,
     1253                    right_cnt * PAGE_SIZE)) {
    12071254                        /* The interval intersects with the right interval. */
    12081255                        return 0;                       
    1209                 } else if ((page == left_pg + left_cnt*PAGE_SIZE) && (page + count*PAGE_SIZE == right_pg)) {
    1210                         /* The interval can be added by merging the two already present intervals. */
     1256                } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
     1257                    (page + count * PAGE_SIZE == right_pg)) {
     1258                        /*
     1259                         * The interval can be added by merging the two already
     1260                         * present intervals.
     1261                         */
    12111262                        node->value[node->keys - 1] += count + right_cnt;
    12121263                        btree_remove(&a->used_space, right_pg, leaf);
    12131264                        return 1;
    1214                 } else if (page == left_pg + left_cnt*PAGE_SIZE) {
    1215                         /* The interval can be added by simply growing the left interval. */
     1265                } else if (page == left_pg + left_cnt * PAGE_SIZE) {
     1266                        /*
     1267                         * The interval can be added by simply growing the left
     1268                         * interval.
     1269                         */
    12161270                        node->value[node->keys - 1] += count;
    12171271                        return 1;
    1218                 } else if (page + count*PAGE_SIZE == right_pg) {
     1272                } else if (page + count * PAGE_SIZE == right_pg) {
    12191273                        /*
    1220                          * The interval can be addded by simply moving base of the right
    1221                          * interval down and increasing its size accordingly.
     1274                         * The interval can be addded by simply moving base of
     1275                         * the right interval down and increasing its size
     1276                         * accordingly.
    12221277                         */
    12231278                        leaf->value[0] += count;
     
    12291284                         * but cannot be merged with any of them.
    12301285                         */
    1231                         btree_insert(&a->used_space, page, (void *) count, leaf);
     1286                        btree_insert(&a->used_space, page, (void *) count,
     1287                            leaf);
    12321288                        return 1;
    12331289                }
     
    12371293       
    12381294                /*
    1239                  * Investigate the border case in which the left neighbour does not
    1240                  * exist but the interval fits from the left.
     1295                 * Investigate the border case in which the left neighbour does
     1296                 * not exist but the interval fits from the left.
    12411297                 */
    12421298                 
    1243                 if (overlaps(page, count*PAGE_SIZE, right_pg, right_cnt*PAGE_SIZE)) {
     1299                if (overlaps(page, count * PAGE_SIZE, right_pg,
     1300                    right_cnt * PAGE_SIZE)) {
    12441301                        /* The interval intersects with the right interval. */
    12451302                        return 0;
    1246                 } else if (page + count*PAGE_SIZE == right_pg) {
     1303                } else if (page + count * PAGE_SIZE == right_pg) {
    12471304                        /*
    1248                          * The interval can be added by moving the base of the right interval down
    1249                          * and increasing its size accordingly.
     1305                         * The interval can be added by moving the base of the
     1306                         * right interval down and increasing its size
     1307                         * accordingly.
    12501308                         */
    12511309                        leaf->key[0] = page;
     
    12571315                         * It must be added individually.
    12581316                         */
    1259                         btree_insert(&a->used_space, page, (void *) count, leaf);
     1317                        btree_insert(&a->used_space, page, (void *) count,
     1318                            leaf);
    12601319                        return 1;
    12611320                }
     
    12641323        node = btree_leaf_node_right_neighbour(&a->used_space, leaf);
    12651324        if (node) {
    1266                 uintptr_t left_pg = leaf->key[leaf->keys - 1], right_pg = node->key[0];
    1267                 count_t left_cnt = (count_t) leaf->value[leaf->keys - 1], right_cnt = (count_t) node->value[0];
     1325                uintptr_t left_pg = leaf->key[leaf->keys - 1];
     1326                uintptr_t right_pg = node->key[0];
     1327                count_t left_cnt = (count_t) leaf->value[leaf->keys - 1];
     1328                count_t right_cnt = (count_t) node->value[0];
    12681329               
    12691330                /*
     
    12751336                if (page < left_pg) {
    12761337                        /* Do nothing. */
    1277                 } else if (overlaps(page, count*PAGE_SIZE, left_pg, left_cnt*PAGE_SIZE)) {
     1338                } else if (overlaps(page, count * PAGE_SIZE, left_pg,
     1339                    left_cnt * PAGE_SIZE)) {
    12781340                        /* The interval intersects with the left interval. */
    12791341                        return 0;
    1280                 } else if (overlaps(page, count*PAGE_SIZE, right_pg, right_cnt*PAGE_SIZE)) {
     1342                } else if (overlaps(page, count * PAGE_SIZE, right_pg,
     1343                    right_cnt * PAGE_SIZE)) {
    12811344                        /* The interval intersects with the right interval. */
    12821345                        return 0;                       
    1283                 } else if ((page == left_pg + left_cnt*PAGE_SIZE) && (page + count*PAGE_SIZE == right_pg)) {
    1284                         /* The interval can be added by merging the two already present intervals. */
     1346                } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
     1347                    (page + count * PAGE_SIZE == right_pg)) {
     1348                        /*
     1349                         * The interval can be added by merging the two already
     1350                         * present intervals.
     1351                         * */
    12851352                        leaf->value[leaf->keys - 1] += count + right_cnt;
    12861353                        btree_remove(&a->used_space, right_pg, node);
    12871354                        return 1;
    1288                 } else if (page == left_pg + left_cnt*PAGE_SIZE) {
    1289                         /* The interval can be added by simply growing the left interval. */
     1355                } else if (page == left_pg + left_cnt * PAGE_SIZE) {
     1356                        /*
     1357                         * The interval can be added by simply growing the left
     1358                         * interval.
     1359                         * */
    12901360                        leaf->value[leaf->keys - 1] +=  count;
    12911361                        return 1;
    1292                 } else if (page + count*PAGE_SIZE == right_pg) {
     1362                } else if (page + count * PAGE_SIZE == right_pg) {
    12931363                        /*
    1294                          * The interval can be addded by simply moving base of the right
    1295                          * interval down and increasing its size accordingly.
     1364                         * The interval can be addded by simply moving base of
     1365                         * the right interval down and increasing its size
     1366                         * accordingly.
    12961367                         */
    12971368                        node->value[0] += count;
     
    13031374                         * but cannot be merged with any of them.
    13041375                         */
    1305                         btree_insert(&a->used_space, page, (void *) count, leaf);
     1376                        btree_insert(&a->used_space, page, (void *) count,
     1377                            leaf);
    13061378                        return 1;
    13071379                }
     
    13111383       
    13121384                /*
    1313                  * Investigate the border case in which the right neighbour does not
    1314                  * exist but the interval fits from the right.
     1385                 * Investigate the border case in which the right neighbour
     1386                 * does not exist but the interval fits from the right.
    13151387                 */
    13161388                 
    1317                 if (overlaps(page, count*PAGE_SIZE, left_pg, left_cnt*PAGE_SIZE)) {
     1389                if (overlaps(page, count * PAGE_SIZE, left_pg,
     1390                    left_cnt * PAGE_SIZE)) {
    13181391                        /* The interval intersects with the left interval. */
    13191392                        return 0;
    1320                 } else if (left_pg + left_cnt*PAGE_SIZE == page) {
    1321                         /* The interval can be added by growing the left interval. */
     1393                } else if (left_pg + left_cnt * PAGE_SIZE == page) {
     1394                        /*
     1395                         * The interval can be added by growing the left
     1396                         * interval.
     1397                         */
    13221398                        leaf->value[leaf->keys - 1] += count;
    13231399                        return 1;
     
    13271403                         * It must be added individually.
    13281404                         */
    1329                         btree_insert(&a->used_space, page, (void *) count, leaf);
     1405                        btree_insert(&a->used_space, page, (void *) count,
     1406                            leaf);
    13301407                        return 1;
    13311408                }
     
    13331410       
    13341411        /*
    1335          * Note that if the algorithm made it thus far, the interval can fit only
    1336          * between two other intervals of the leaf. The two border cases were already
    1337          * resolved.
     1412         * Note that if the algorithm made it thus far, the interval can fit
     1413         * only between two other intervals of the leaf. The two border cases
     1414         * were already resolved.
    13381415         */
    13391416        for (i = 1; i < leaf->keys; i++) {
    13401417                if (page < leaf->key[i]) {
    1341                         uintptr_t left_pg = leaf->key[i - 1], right_pg = leaf->key[i];
    1342                         count_t left_cnt = (count_t) leaf->value[i - 1], right_cnt = (count_t) leaf->value[i];
     1418                        uintptr_t left_pg = leaf->key[i - 1];
     1419                        uintptr_t right_pg = leaf->key[i];
     1420                        count_t left_cnt = (count_t) leaf->value[i - 1];
     1421                        count_t right_cnt = (count_t) leaf->value[i];
    13431422
    13441423                        /*
     
    13461425                         */
    13471426
    1348                         if (overlaps(page, count*PAGE_SIZE, left_pg, left_cnt*PAGE_SIZE)) {
    1349                                 /* The interval intersects with the left interval. */
     1427                        if (overlaps(page, count * PAGE_SIZE, left_pg,
     1428                            left_cnt * PAGE_SIZE)) {
     1429                                /*
     1430                                 * The interval intersects with the left
     1431                                 * interval.
     1432                                 */
    13501433                                return 0;
    1351                         } else if (overlaps(page, count*PAGE_SIZE, right_pg, right_cnt*PAGE_SIZE)) {
    1352                                 /* The interval intersects with the right interval. */
     1434                        } else if (overlaps(page, count * PAGE_SIZE, right_pg,
     1435                            right_cnt * PAGE_SIZE)) {
     1436                                /*
     1437                                 * The interval intersects with the right
     1438                                 * interval.
     1439                                 */
    13531440                                return 0;                       
    1354                         } else if ((page == left_pg + left_cnt*PAGE_SIZE) && (page + count*PAGE_SIZE == right_pg)) {
    1355                                 /* The interval can be added by merging the two already present intervals. */
     1441                        } else if ((page == left_pg + left_cnt * PAGE_SIZE) &&
     1442                            (page + count * PAGE_SIZE == right_pg)) {
     1443                                /*
     1444                                 * The interval can be added by merging the two
     1445                                 * already present intervals.
     1446                                 */
    13561447                                leaf->value[i - 1] += count + right_cnt;
    13571448                                btree_remove(&a->used_space, right_pg, leaf);
    13581449                                return 1;
    1359                         } else if (page == left_pg + left_cnt*PAGE_SIZE) {
    1360                                 /* The interval can be added by simply growing the left interval. */
     1450                        } else if (page == left_pg + left_cnt * PAGE_SIZE) {
     1451                                /*
     1452                                 * The interval can be added by simply growing
     1453                                 * the left interval.
     1454                                 */
    13611455                                leaf->value[i - 1] += count;
    13621456                                return 1;
    1363                         } else if (page + count*PAGE_SIZE == right_pg) {
     1457                        } else if (page + count * PAGE_SIZE == right_pg) {
    13641458                                /*
    1365                                  * The interval can be addded by simply moving base of the right
    1366                                  * interval down and increasing its size accordingly.
     1459                                 * The interval can be addded by simply moving
     1460                                 * base of the right interval down and
     1461                                 * increasing its size accordingly.
    13671462                                 */
    13681463                                leaf->value[i] += count;
     
    13711466                        } else {
    13721467                                /*
    1373                                  * The interval is between both neigbouring intervals,
    1374                                  * but cannot be merged with any of them.
     1468                                 * The interval is between both neigbouring
     1469                                 * intervals, but cannot be merged with any of
     1470                                 * them.
    13751471                                 */
    1376                                 btree_insert(&a->used_space, page, (void *) count, leaf);
     1472                                btree_insert(&a->used_space, page,
     1473                                    (void *) count, leaf);
    13771474                                return 1;
    13781475                        }
     
    13801477        }
    13811478
    1382         panic("Inconsistency detected while adding %d pages of used space at %p.\n", count, page);
     1479        panic("Inconsistency detected while adding %d pages of used space at "
     1480            "%p.\n", count, page);
    13831481}
    13841482
     
    14191517                        for (i = 0; i < leaf->keys; i++) {
    14201518                                if (leaf->key[i] == page) {
    1421                                         leaf->key[i] += count*PAGE_SIZE;
     1519                                        leaf->key[i] += count * PAGE_SIZE;
    14221520                                        leaf->value[i] -= count;
    14231521                                        return 1;
     
    14331531                count_t left_cnt = (count_t) node->value[node->keys - 1];
    14341532
    1435                 if (overlaps(left_pg, left_cnt*PAGE_SIZE, page, count*PAGE_SIZE)) {
    1436                         if (page + count*PAGE_SIZE == left_pg + left_cnt*PAGE_SIZE) {
     1533                if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
     1534                    count * PAGE_SIZE)) {
     1535                        if (page + count * PAGE_SIZE ==
     1536                            left_pg + left_cnt * PAGE_SIZE) {
    14371537                                /*
    1438                                  * The interval is contained in the rightmost interval
    1439                                  * of the left neighbour and can be removed by
    1440                                  * updating the size of the bigger interval.
     1538                                 * The interval is contained in the rightmost
     1539                                 * interval of the left neighbour and can be
     1540                                 * removed by updating the size of the bigger
     1541                                 * interval.
    14411542                                 */
    14421543                                node->value[node->keys - 1] -= count;
    14431544                                return 1;
    1444                         } else if (page + count*PAGE_SIZE < left_pg + left_cnt*PAGE_SIZE) {
     1545                        } else if (page + count * PAGE_SIZE <
     1546                            left_pg + left_cnt*PAGE_SIZE) {
    14451547                                count_t new_cnt;
    14461548                               
    14471549                                /*
    1448                                  * The interval is contained in the rightmost interval
    1449                                  * of the left neighbour but its removal requires
    1450                                  * both updating the size of the original interval and
    1451                                  * also inserting a new interval.
     1550                                 * The interval is contained in the rightmost
     1551                                 * interval of the left neighbour but its
     1552                                 * removal requires both updating the size of
     1553                                 * the original interval and also inserting a
     1554                                 * new interval.
    14521555                                 */
    1453                                 new_cnt = ((left_pg + left_cnt*PAGE_SIZE) - (page + count*PAGE_SIZE)) >> PAGE_WIDTH;
     1556                                new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
     1557                                    (page + count*PAGE_SIZE)) >> PAGE_WIDTH;
    14541558                                node->value[node->keys - 1] -= count + new_cnt;
    1455                                 btree_insert(&a->used_space, page + count*PAGE_SIZE, (void *) new_cnt, leaf);
     1559                                btree_insert(&a->used_space, page +
     1560                                    count * PAGE_SIZE, (void *) new_cnt, leaf);
    14561561                                return 1;
    14571562                        }
     
    14661571                count_t left_cnt = (count_t) leaf->value[leaf->keys - 1];
    14671572
    1468                 if (overlaps(left_pg, left_cnt*PAGE_SIZE, page, count*PAGE_SIZE)) {
    1469                         if (page + count*PAGE_SIZE == left_pg + left_cnt*PAGE_SIZE) {
     1573                if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
     1574                    count * PAGE_SIZE)) {
     1575                        if (page + count * PAGE_SIZE ==
     1576                            left_pg + left_cnt * PAGE_SIZE) {
    14701577                                /*
    1471                                  * The interval is contained in the rightmost interval
    1472                                  * of the leaf and can be removed by updating the size
    1473                                  * of the bigger interval.
     1578                                 * The interval is contained in the rightmost
     1579                                 * interval of the leaf and can be removed by
     1580                                 * updating the size of the bigger interval.
    14741581                                 */
    14751582                                leaf->value[leaf->keys - 1] -= count;
    14761583                                return 1;
    1477                         } else if (page + count*PAGE_SIZE < left_pg + left_cnt*PAGE_SIZE) {
     1584                        } else if (page + count * PAGE_SIZE < left_pg +
     1585                            left_cnt * PAGE_SIZE) {
    14781586                                count_t new_cnt;
    14791587                               
    14801588                                /*
    1481                                  * The interval is contained in the rightmost interval
    1482                                  * of the leaf but its removal requires both updating
    1483                                  * the size of the original interval and
    1484                                  * also inserting a new interval.
     1589                                 * The interval is contained in the rightmost
     1590                                 * interval of the leaf but its removal
     1591                                 * requires both updating the size of the
     1592                                 * original interval and also inserting a new
     1593                                 * interval.
    14851594                                 */
    1486                                 new_cnt = ((left_pg + left_cnt*PAGE_SIZE) - (page + count*PAGE_SIZE)) >> PAGE_WIDTH;
     1595                                new_cnt = ((left_pg + left_cnt * PAGE_SIZE) -
     1596                                    (page + count * PAGE_SIZE)) >> PAGE_WIDTH;
    14871597                                leaf->value[leaf->keys - 1] -= count + new_cnt;
    1488                                 btree_insert(&a->used_space, page + count*PAGE_SIZE, (void *) new_cnt, leaf);
     1598                                btree_insert(&a->used_space, page +
     1599                                    count * PAGE_SIZE, (void *) new_cnt, leaf);
    14891600                                return 1;
    14901601                        }
     
    15031614
    15041615                        /*
    1505                          * Now the interval is between intervals corresponding to (i - 1) and i.
     1616                         * Now the interval is between intervals corresponding
     1617                         * to (i - 1) and i.
    15061618                         */
    1507                         if (overlaps(left_pg, left_cnt*PAGE_SIZE, page, count*PAGE_SIZE)) {
    1508                                 if (page + count*PAGE_SIZE == left_pg + left_cnt*PAGE_SIZE) {
     1619                        if (overlaps(left_pg, left_cnt * PAGE_SIZE, page,
     1620                            count * PAGE_SIZE)) {
     1621                                if (page + count * PAGE_SIZE ==
     1622                                    left_pg + left_cnt*PAGE_SIZE) {
    15091623                                        /*
    1510                                         * The interval is contained in the interval (i - 1)
    1511                                          * of the leaf and can be removed by updating the size
    1512                                          * of the bigger interval.
     1624                                         * The interval is contained in the
     1625                                         * interval (i - 1) of the leaf and can
     1626                                         * be removed by updating the size of
     1627                                         * the bigger interval.
    15131628                                         */
    15141629                                        leaf->value[i - 1] -= count;
    15151630                                        return 1;
    1516                                 } else if (page + count*PAGE_SIZE < left_pg + left_cnt*PAGE_SIZE) {
     1631                                } else if (page + count * PAGE_SIZE <
     1632                                    left_pg + left_cnt * PAGE_SIZE) {
    15171633                                        count_t new_cnt;
    15181634                               
    15191635                                        /*
    1520                                          * The interval is contained in the interval (i - 1)
    1521                                          * of the leaf but its removal requires both updating
    1522                                          * the size of the original interval and
     1636                                         * The interval is contained in the
     1637                                         * interval (i - 1) of the leaf but its
     1638                                         * removal requires both updating the
     1639                                         * size of the original interval and
    15231640                                         * also inserting a new interval.
    15241641                                         */
    1525                                         new_cnt = ((left_pg + left_cnt*PAGE_SIZE) - (page + count*PAGE_SIZE)) >> PAGE_WIDTH;
     1642                                        new_cnt = ((left_pg +
     1643                                            left_cnt * PAGE_SIZE) -
     1644                                            (page + count * PAGE_SIZE)) >>
     1645                                            PAGE_WIDTH;
    15261646                                        leaf->value[i - 1] -= count + new_cnt;
    1527                                         btree_insert(&a->used_space, page + count*PAGE_SIZE, (void *) new_cnt, leaf);
     1647                                        btree_insert(&a->used_space, page +
     1648                                            count * PAGE_SIZE, (void *) new_cnt,
     1649                                            leaf);
    15281650                                        return 1;
    15291651                                }
     
    15341656
    15351657error:
    1536         panic("Inconsistency detected while removing %d pages of used space from %p.\n", count, page);
     1658        panic("Inconsistency detected while removing %d pages of used space "
     1659            "from %p.\n", count, page);
    15371660}
    15381661
     
    15571680                 * reference from all frames found there.
    15581681                 */
    1559                 for (cur = sh_info->pagemap.leaf_head.next; cur != &sh_info->pagemap.leaf_head; cur = cur->next) {
     1682                for (cur = sh_info->pagemap.leaf_head.next;
     1683                    cur != &sh_info->pagemap.leaf_head; cur = cur->next) {
    15601684                        btree_node_t *node;
    15611685                        int i;
     
    15821706unative_t sys_as_area_create(uintptr_t address, size_t size, int flags)
    15831707{
    1584         if (as_area_create(AS, flags | AS_AREA_CACHEABLE, size, address, AS_AREA_ATTR_NONE, &anon_backend, NULL))
     1708        if (as_area_create(AS, flags | AS_AREA_CACHEABLE, size, address,
     1709            AS_AREA_ATTR_NONE, &anon_backend, NULL))
    15851710                return (unative_t) address;
    15861711        else
     
    16131738        /* print out info about address space areas */
    16141739        link_t *cur;
    1615         for (cur = as->as_area_btree.leaf_head.next; cur != &as->as_area_btree.leaf_head; cur = cur->next) {
    1616                 btree_node_t *node = list_get_instance(cur, btree_node_t, leaf_link);
     1740        for (cur = as->as_area_btree.leaf_head.next;
     1741            cur != &as->as_area_btree.leaf_head; cur = cur->next) {
     1742                btree_node_t *node;
     1743               
     1744                node = list_get_instance(cur, btree_node_t, leaf_link);
    16171745               
    16181746                int i;
     
    16221750                        mutex_lock(&area->lock);
    16231751                        printf("as_area: %p, base=%p, pages=%d (%p - %p)\n",
    1624                                 area, area->base, area->pages, area->base, area->base + area->pages*PAGE_SIZE);
     1752                            area, area->base, area->pages, area->base,
     1753                            area->base + area->pages*PAGE_SIZE);
    16251754                        mutex_unlock(&area->lock);
    16261755                }
Note: See TracChangeset for help on using the changeset viewer.