Subversion Repositories HelenOS

Rev

Rev 3191 | Rev 4337 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3191 Rev 3403
Line 80... Line 80...
80
 
80
 
81
#ifdef CONFIG_VIRT_IDX_DCACHE
81
#ifdef CONFIG_VIRT_IDX_DCACHE
82
#include <arch/mm/cache.h>
82
#include <arch/mm/cache.h>
83
#endif /* CONFIG_VIRT_IDX_DCACHE */
83
#endif /* CONFIG_VIRT_IDX_DCACHE */
84
 
84
 
85
#ifndef __OBJC__
-
 
86
/**
85
/**
87
 * Each architecture decides what functions will be used to carry out
86
 * Each architecture decides what functions will be used to carry out
88
 * address space operations such as creating or locking page tables.
87
 * address space operations such as creating or locking page tables.
89
 */
88
 */
90
as_operations_t *as_operations = NULL;
89
as_operations_t *as_operations = NULL;
91
 
90
 
92
/**
91
/**
93
 * Slab for as_t objects.
92
 * Slab for as_t objects.
94
 */
93
 */
95
static slab_cache_t *as_slab;
94
static slab_cache_t *as_slab;
96
#endif
-
 
97
 
95
 
98
/**
96
/**
99
 * This lock serializes access to the ASID subsystem.
97
 * This lock serializes access to the ASID subsystem.
100
 * It protects:
98
 * It protects:
101
 * - inactive_as_with_asid_head list
99
 * - inactive_as_with_asid_head list
Line 111... Line 109...
111
LIST_INITIALIZE(inactive_as_with_asid_head);
109
LIST_INITIALIZE(inactive_as_with_asid_head);
112
 
110
 
113
/** Kernel address space. */
111
/** Kernel address space. */
114
as_t *AS_KERNEL = NULL;
112
as_t *AS_KERNEL = NULL;
115
 
113
 
116
static int area_flags_to_page_flags(int aflags);
114
static int area_flags_to_page_flags(int);
117
static as_area_t *find_area_and_lock(as_t *as, uintptr_t va);
115
static as_area_t *find_area_and_lock(as_t *, uintptr_t);
118
static bool check_area_conflicts(as_t *as, uintptr_t va, size_t size,
116
static bool check_area_conflicts(as_t *, uintptr_t, size_t, as_area_t *);
119
    as_area_t *avoid_area);
-
 
120
static void sh_info_remove_reference(share_info_t *sh_info);
117
static void sh_info_remove_reference(share_info_t *);
121
 
118
 
122
#ifndef __OBJC__
-
 
123
static int as_constructor(void *obj, int flags)
119
static int as_constructor(void *obj, int flags)
124
{
120
{
125
    as_t *as = (as_t *) obj;
121
    as_t *as = (as_t *) obj;
126
    int rc;
122
    int rc;
127
 
123
 
Line 137... Line 133...
137
{
133
{
138
    as_t *as = (as_t *) obj;
134
    as_t *as = (as_t *) obj;
139
 
135
 
140
    return as_destructor_arch(as);
136
    return as_destructor_arch(as);
141
}
137
}
142
#endif
-
 
143
 
138
 
144
/** Initialize address space subsystem. */
139
/** Initialize address space subsystem. */
145
void as_init(void)
140
void as_init(void)
146
{
141
{
147
    as_arch_init();
142
    as_arch_init();
148
 
143
 
149
#ifndef __OBJC__
-
 
150
    as_slab = slab_cache_create("as_slab", sizeof(as_t), 0,
144
    as_slab = slab_cache_create("as_slab", sizeof(as_t), 0,
151
        as_constructor, as_destructor, SLAB_CACHE_MAGDEFERRED);
145
        as_constructor, as_destructor, SLAB_CACHE_MAGDEFERRED);
152
#endif
-
 
153
   
146
   
154
    AS_KERNEL = as_create(FLAG_AS_KERNEL);
147
    AS_KERNEL = as_create(FLAG_AS_KERNEL);
155
    if (!AS_KERNEL)
148
    if (!AS_KERNEL)
156
        panic("can't create kernel address space\n");
149
        panic("can't create kernel address space\n");
157
   
150
   
158
}
151
}
159
 
152
 
160
/** Create address space.
153
/** Create address space.
161
 *
154
 *
162
 * @param flags Flags that influence way in wich the address space is created.
155
 * @param flags     Flags that influence the way in wich the address space
-
 
156
 *          is created.
163
 */
157
 */
164
as_t *as_create(int flags)
158
as_t *as_create(int flags)
165
{
159
{
166
    as_t *as;
160
    as_t *as;
167
 
161
 
168
#ifdef __OBJC__
-
 
169
    as = [as_t new];
-
 
170
    link_initialize(&as->inactive_as_with_asid_link);
-
 
171
    mutex_initialize(&as->lock, MUTEX_PASSIVE);
-
 
172
    (void) as_constructor_arch(as, flags);
-
 
173
#else
-
 
174
    as = (as_t *) slab_alloc(as_slab, 0);
162
    as = (as_t *) slab_alloc(as_slab, 0);
175
#endif
-
 
176
    (void) as_create_arch(as, 0);
163
    (void) as_create_arch(as, 0);
177
   
164
   
178
    btree_create(&as->as_area_btree);
165
    btree_create(&as->as_area_btree);
179
   
166
   
180
    if (flags & FLAG_AS_KERNEL)
167
    if (flags & FLAG_AS_KERNEL)
Line 197... Line 184...
197
 *
184
 *
198
 * When there are no tasks referencing this address space (i.e. its refcount is
185
 * When there are no tasks referencing this address space (i.e. its refcount is
199
 * zero), the address space can be destroyed.
186
 * zero), the address space can be destroyed.
200
 *
187
 *
201
 * We know that we don't hold any spinlock.
188
 * We know that we don't hold any spinlock.
-
 
189
 *
-
 
190
 * @param as        Address space to be destroyed.
202
 */
191
 */
203
void as_destroy(as_t *as)
192
void as_destroy(as_t *as)
204
{
193
{
205
    ipl_t ipl;
194
    ipl_t ipl;
206
    bool cond;
195
    bool cond;
Line 261... Line 250...
261
    page_table_destroy(NULL);
250
    page_table_destroy(NULL);
262
#endif
251
#endif
263
 
252
 
264
    interrupts_restore(ipl);
253
    interrupts_restore(ipl);
265
 
254
 
266
#ifdef __OBJC__
-
 
267
    [as free];
-
 
268
#else
-
 
269
    slab_free(as_slab, as);
255
    slab_free(as_slab, as);
270
#endif
-
 
271
}
256
}
272
 
257
 
273
/** Create address space area of common attributes.
258
/** Create address space area of common attributes.
274
 *
259
 *
275
 * The created address space area is added to the target address space.
260
 * The created address space area is added to the target address space.
Line 337... Line 322...
337
}
322
}
338
 
323
 
339
/** Find address space area and change it.
324
/** Find address space area and change it.
340
 *
325
 *
341
 * @param as Address space.
326
 * @param as        Address space.
342
 * @param address Virtual address belonging to the area to be changed. Must be
327
 * @param address   Virtual address belonging to the area to be changed.
343
 *     page-aligned.
328
 *          Must be page-aligned.
344
 * @param size New size of the virtual memory block starting at address.
329
 * @param size      New size of the virtual memory block starting at
-
 
330
 *          address.
345
 * @param flags Flags influencing the remap operation. Currently unused.
331
 * @param flags     Flags influencing the remap operation. Currently unused.
346
 *
332
 *
347
 * @return Zero on success or a value from @ref errno.h otherwise.
333
 * @return      Zero on success or a value from @ref errno.h otherwise.
348
 */
334
 */
349
int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags)
335
int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags)
Line 450... Line 436...
450
                     * address space area.
436
                     * address space area.
451
                     */
437
                     */
452
       
438
       
453
                    cond = false;   /* we are almost done */
439
                    cond = false;   /* we are almost done */
454
                    i = (start_free - b) >> PAGE_WIDTH;
440
                    i = (start_free - b) >> PAGE_WIDTH;
455
                    if (!used_space_remove(area, start_free, c - i))
441
                    if (!used_space_remove(area, start_free,
-
 
442
                        c - i))
456
                        panic("Could not remove used space.\n");
443
                        panic("Could not remove used "
-
 
444
                            "space.\n");
457
                } else {
445
                } else {
458
                    /*
446
                    /*
459
                     * The interval of used space can be
447
                     * The interval of used space can be
460
                     * completely removed.
448
                     * completely removed.
461
                     */
449
                     */
462
                    if (!used_space_remove(area, b, c))
450
                    if (!used_space_remove(area, b, c))
463
                        panic("Could not remove used space.\n");
451
                        panic("Could not remove used "
-
 
452
                            "space.\n");
464
                }
453
                }
465
           
454
           
466
                for (; i < c; i++) {
455
                for (; i < c; i++) {
467
                    pte_t *pte;
456
                    pte_t *pte;
468
           
457
           
Line 521... Line 510...
521
}
510
}
522
 
511
 
523
/** Destroy address space area.
512
/** Destroy address space area.
524
 *
513
 *
525
 * @param as Address space.
514
 * @param as        Address space.
526
 * @param address Address withing the area to be deleted.
515
 * @param address   Address within the area to be deleted.
527
 *
516
 *
528
 * @return Zero on success or a value from @ref errno.h on failure.
517
 * @return      Zero on success or a value from @ref errno.h on failure.
529
 */
518
 */
530
int as_area_destroy(as_t *as, uintptr_t address)
519
int as_area_destroy(as_t *as, uintptr_t address)
531
{
520
{
Line 627... Line 616...
627
 * @param acc_size Expected size of the source area.
616
 * @param acc_size  Expected size of the source area.
628
 * @param dst_as Pointer to destination address space.
617
 * @param dst_as    Pointer to destination address space.
629
 * @param dst_base Target base address.
618
 * @param dst_base  Target base address.
630
 * @param dst_flags_mask Destination address space area flags mask.
619
 * @param dst_flags_mask Destination address space area flags mask.
631
 *
620
 *
632
 * @return Zero on success or ENOENT if there is no such task or if there is no
621
 * @return      Zero on success or ENOENT if there is no such task or if
633
 * such address space area, EPERM if there was a problem in accepting the area
622
 *          there is no such address space area, EPERM if there was
-
 
623
 *          a problem in accepting the area or ENOMEM if there was a
634
 * or ENOMEM if there was a problem in allocating destination address space
624
 *          problem in allocating destination address space area.
635
 * area. ENOTSUP is returned if the address space area backend does not support
625
 *          ENOTSUP is returned if the address space area backend
636
 * sharing.
626
 *          does not support sharing.
637
 */
627
 */
638
int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size,
628
int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size,
639
    as_t *dst_as, uintptr_t dst_base, int dst_flags_mask)
629
    as_t *dst_as, uintptr_t dst_base, int dst_flags_mask)
640
{
630
{
641
    ipl_t ipl;
631
    ipl_t ipl;
Line 753... Line 743...
753
 * The address space area must be locked prior to this call.
743
 * The address space area must be locked prior to this call.
754
 *
744
 *
755
 * @param area Address space area.
745
 * @param area      Address space area.
756
 * @param access Access mode.
746
 * @param access    Access mode.
757
 *
747
 *
758
 * @return False if access violates area's permissions, true otherwise.
748
 * @return      False if access violates area's permissions, true
-
 
749
 *          otherwise.
759
 */
750
 */
760
bool as_area_check_access(as_area_t *area, pf_access_t access)
751
bool as_area_check_access(as_area_t *area, pf_access_t access)
761
{
752
{
762
    int flagmap[] = {
753
    int flagmap[] = {
763
        [PF_ACCESS_READ] = AS_AREA_READ,
754
        [PF_ACCESS_READ] = AS_AREA_READ,
Line 769... Line 760...
769
        return false;
760
        return false;
770
   
761
   
771
    return true;
762
    return true;
772
}
763
}
773
 
764
 
774
/** Change adress area flags.
765
/** Change adress space area flags.
775
 *
766
 *
776
 * The idea is to have the same data, but with a different access mode.
767
 * The idea is to have the same data, but with a different access mode.
777
 * This is needed e.g. for writing code into memory and then executing it.
768
 * This is needed e.g. for writing code into memory and then executing it.
778
 * In order for this to work properly, this may copy the data
769
 * In order for this to work properly, this may copy the data
779
 * into private anonymous memory (unless it's already there).
770
 * into private anonymous memory (unless it's already there).
Line 885... Line 876...
885
     */
876
     */
886
    as_invalidate_translation_cache(as, area->base, area->pages);
877
    as_invalidate_translation_cache(as, area->base, area->pages);
887
    tlb_shootdown_finalize();
878
    tlb_shootdown_finalize();
888
 
879
 
889
    /*
880
    /*
-
 
881
     * Set the new flags.
-
 
882
     */
-
 
883
    area->flags = flags;
-
 
884
 
-
 
885
    /*
890
     * Map pages back in with new flags. This step is kept separate
886
     * Map pages back in with new flags. This step is kept separate
891
     * so that there's no instant when the memory area could be
887
     * so that the memory area could not be accesed with both the old and
892
     * accesed with both the old and the new flags at once.
888
     * the new flags at once.
893
     */
889
     */
894
    frame_idx = 0;
890
    frame_idx = 0;
895
 
891
 
896
    for (cur = area->used_space.leaf_head.next;
892
    for (cur = area->used_space.leaf_head.next;
897
        cur != &area->used_space.leaf_head; cur = cur->next) {
893
        cur != &area->used_space.leaf_head; cur = cur->next) {
Line 925... Line 921...
925
}
921
}
926
 
922
 
927
 
923
 
928
/** Handle page fault within the current address space.
924
/** Handle page fault within the current address space.
929
 *
925
 *
930
 * This is the high-level page fault handler. It decides
926
 * This is the high-level page fault handler. It decides whether the page fault
931
 * whether the page fault can be resolved by any backend
-
 
932
 * and if so, it invokes the backend to resolve the page
927
 * can be resolved by any backend and if so, it invokes the backend to resolve
933
 * fault.
928
 * the page fault.
934
 *
929
 *
935
 * Interrupts are assumed disabled.
930
 * Interrupts are assumed disabled.
936
 *
931
 *
937
 * @param page Faulting page.
932
 * @param page      Faulting page.
938
 * @param access Access mode that caused the fault (i.e. read/write/exec).
933
 * @param access    Access mode that caused the page fault (i.e.
-
 
934
 *          read/write/exec).
939
 * @param istate Pointer to interrupted state.
935
 * @param istate    Pointer to the interrupted state.
940
 *
936
 *
941
 * @return AS_PF_FAULT on page fault, AS_PF_OK on success or AS_PF_DEFER if the
937
 * @return      AS_PF_FAULT on page fault, AS_PF_OK on success or
942
 *     fault was caused by copy_to_uspace() or copy_from_uspace().
938
 *          AS_PF_DEFER if the fault was caused by copy_to_uspace()
-
 
939
 *          or copy_from_uspace().
943
 */
940
 */
944
int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate)
941
int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate)
945
{
942
{
946
    pte_t *pte;
943
    pte_t *pte;
947
    as_area_t *area;
944
    as_area_t *area;
Line 983... Line 980...
983
    }
980
    }
984
 
981
 
985
    page_table_lock(AS, false);
982
    page_table_lock(AS, false);
986
   
983
   
987
    /*
984
    /*
988
     * To avoid race condition between two page faults
985
     * To avoid race condition between two page faults on the same address,
989
     * on the same address, we need to make sure
-
 
990
     * the mapping has not been already inserted.
986
     * we need to make sure the mapping has not been already inserted.
991
     */
987
     */
992
    if ((pte = page_mapping_find(AS, page))) {
988
    if ((pte = page_mapping_find(AS, page))) {
993
        if (PTE_PRESENT(pte)) {
989
        if (PTE_PRESENT(pte)) {
994
            if (((access == PF_ACCESS_READ) && PTE_READABLE(pte)) ||
990
            if (((access == PF_ACCESS_READ) && PTE_READABLE(pte)) ||
995
                (access == PF_ACCESS_WRITE && PTE_WRITABLE(pte)) ||
991
                (access == PF_ACCESS_WRITE && PTE_WRITABLE(pte)) ||
Line 1152... Line 1148...
1152
    return area_flags_to_page_flags(a->flags);
1148
    return area_flags_to_page_flags(a->flags);
1153
}
1149
}
1154
 
1150
 
1155
/** Create page table.
1151
/** Create page table.
1156
 *
1152
 *
1157
 * Depending on architecture, create either address space
1153
 * Depending on architecture, create either address space private or global page
1158
 * private or global page table.
1154
 * table.
1159
 *
1155
 *
1160
 * @param flags Flags saying whether the page table is for kernel address space.
1156
 * @param flags     Flags saying whether the page table is for the kernel
-
 
1157
 *          address space.
1161
 *
1158
 *
1162
 * @return First entry of the page table.
1159
 * @return      First entry of the page table.
1163
 */
1160
 */
1164
pte_t *page_table_create(int flags)
1161
pte_t *page_table_create(int flags)
1165
{
1162
{
1166
#ifdef __OBJC__
-
 
1167
    return [as_t page_table_create: flags];
-
 
1168
#else
-
 
1169
    ASSERT(as_operations);
1163
    ASSERT(as_operations);
1170
    ASSERT(as_operations->page_table_create);
1164
    ASSERT(as_operations->page_table_create);
1171
   
1165
   
1172
    return as_operations->page_table_create(flags);
1166
    return as_operations->page_table_create(flags);
1173
#endif
-
 
1174
}
1167
}
1175
 
1168
 
1176
/** Destroy page table.
1169
/** Destroy page table.
1177
 *
1170
 *
1178
 * Destroy page table in architecture specific way.
1171
 * Destroy page table in architecture specific way.
1179
 *
1172
 *
1180
 * @param page_table Physical address of PTL0.
1173
 * @param page_table    Physical address of PTL0.
1181
 */
1174
 */
1182
void page_table_destroy(pte_t *page_table)
1175
void page_table_destroy(pte_t *page_table)
1183
{
1176
{
1184
#ifdef __OBJC__
-
 
1185
    return [as_t page_table_destroy: page_table];
-
 
1186
#else
-
 
1187
    ASSERT(as_operations);
1177
    ASSERT(as_operations);
1188
    ASSERT(as_operations->page_table_destroy);
1178
    ASSERT(as_operations->page_table_destroy);
1189
   
1179
   
1190
    as_operations->page_table_destroy(page_table);
1180
    as_operations->page_table_destroy(page_table);
1191
#endif
-
 
1192
}
1181
}
1193
 
1182
 
1194
/** Lock page table.
1183
/** Lock page table.
1195
 *
1184
 *
1196
 * This function should be called before any page_mapping_insert(),
1185
 * This function should be called before any page_mapping_insert(),
Line 1203... Line 1192...
1203
 * @param as Address space.
1192
 * @param as        Address space.
1204
 * @param lock If false, do not attempt to lock as->lock.
1193
 * @param lock      If false, do not attempt to lock as->lock.
1205
 */
1194
 */
1206
void page_table_lock(as_t *as, bool lock)
1195
void page_table_lock(as_t *as, bool lock)
1207
{
1196
{
1208
#ifdef __OBJC__
-
 
1209
    [as page_table_lock: lock];
-
 
1210
#else
-
 
1211
    ASSERT(as_operations);
1197
    ASSERT(as_operations);
1212
    ASSERT(as_operations->page_table_lock);
1198
    ASSERT(as_operations->page_table_lock);
1213
   
1199
   
1214
    as_operations->page_table_lock(as, lock);
1200
    as_operations->page_table_lock(as, lock);
1215
#endif
-
 
1216
}
1201
}
1217
 
1202
 
1218
/** Unlock page table.
1203
/** Unlock page table.
1219
 *
1204
 *
1220
 * @param as Address space.
1205
 * @param as        Address space.
1221
 * @param unlock If false, do not attempt to unlock as->lock.
1206
 * @param unlock    If false, do not attempt to unlock as->lock.
1222
 */
1207
 */
1223
void page_table_unlock(as_t *as, bool unlock)
1208
void page_table_unlock(as_t *as, bool unlock)
1224
{
1209
{
1225
#ifdef __OBJC__
-
 
1226
    [as page_table_unlock: unlock];
-
 
1227
#else
-
 
1228
    ASSERT(as_operations);
1210
    ASSERT(as_operations);
1229
    ASSERT(as_operations->page_table_unlock);
1211
    ASSERT(as_operations->page_table_unlock);
1230
   
1212
   
1231
    as_operations->page_table_unlock(as, unlock);
1213
    as_operations->page_table_unlock(as, unlock);
1232
#endif
-
 
1233
}
1214
}
1234
 
1215
 
1235
 
1216
 
1236
/** Find address space area and lock it.
1217
/** Find address space area and lock it.
1237
 *
1218
 *
1238
 * The address space must be locked and interrupts must be disabled.
1219
 * The address space must be locked and interrupts must be disabled.
1239
 *
1220
 *
1240
 * @param as Address space.
1221
 * @param as        Address space.
1241
 * @param va Virtual address.
1222
 * @param va        Virtual address.
1242
 *
1223
 *
1243
 * @return Locked address space area containing va on success or NULL on
1224
 * @return      Locked address space area containing va on success or
1244
 *     failure.
1225
 *          NULL on failure.
1245
 */
1226
 */
1246
as_area_t *find_area_and_lock(as_t *as, uintptr_t va)
1227
as_area_t *find_area_and_lock(as_t *as, uintptr_t va)
1247
{
1228
{
1248
    as_area_t *a;
1229
    as_area_t *a;
1249
    btree_node_t *leaf, *lnode;
1230
    btree_node_t *leaf, *lnode;
Line 1298... Line 1279...
1298
 * @param size Size of the area being tested.
1279
 * @param size      Size of the area being tested.
1299
 * @param avoid_area Do not touch this area.
1280
 * @param avoid_area    Do not touch this area.
1300
 *
1281
 *
1301
 * @return True if there is no conflict, false otherwise.
1282
 * @return      True if there is no conflict, false otherwise.
1302
 */
1283
 */
-
 
1284
bool
1303
bool check_area_conflicts(as_t *as, uintptr_t va, size_t size,
1285
check_area_conflicts(as_t *as, uintptr_t va, size_t size, as_area_t *avoid_area)
1304
              as_area_t *avoid_area)
-
 
1305
{
1286
{
1306
    as_area_t *a;
1287
    as_area_t *a;
1307
    btree_node_t *leaf, *node;
1288
    btree_node_t *leaf, *node;
1308
    unsigned int i;
1289
    unsigned int i;
1309
   
1290
   
Line 1406... Line 1387...
1406
 *
1387
 *
1407
 * @param a Address space area.
1388
 * @param a     Address space area.
1408
 * @param page First page to be marked.
1389
 * @param page      First page to be marked.
1409
 * @param count Number of page to be marked.
1390
 * @param count     Number of page to be marked.
1410
 *
1391
 *
1411
 * @return 0 on failure and 1 on success.
1392
 * @return      Zero on failure and non-zero on success.
1412
 */
1393
 */
1413
int used_space_insert(as_area_t *a, uintptr_t page, count_t count)
1394
int used_space_insert(as_area_t *a, uintptr_t page, count_t count)
1414
{
1395
{
1415
    btree_node_t *leaf, *node;
1396
    btree_node_t *leaf, *node;
1416
    count_t pages;
1397
    count_t pages;
Line 1676... Line 1657...
1676
                return 1;
1657
                return 1;
1677
            }
1658
            }
1678
        }
1659
        }
1679
    }
1660
    }
1680
 
1661
 
1681
    panic("Inconsistency detected while adding %" PRIc " pages of used space at "
1662
    panic("Inconsistency detected while adding %" PRIc " pages of used "
1682
        "%p.\n", count, page);
1663
        "space at %p.\n", count, page);
1683
}
1664
}
1684
 
1665
 
1685
/** Mark portion of address space area as unused.
1666
/** Mark portion of address space area as unused.
1686
 *
1667
 *
1687
 * The address space area must be already locked.
1668
 * The address space area must be already locked.
1688
 *
1669
 *
1689
 * @param a Address space area.
1670
 * @param a     Address space area.
1690
 * @param page First page to be marked.
1671
 * @param page      First page to be marked.
1691
 * @param count Number of page to be marked.
1672
 * @param count     Number of page to be marked.
1692
 *
1673
 *
1693
 * @return 0 on failure and 1 on success.
1674
 * @return      Zero on failure and non-zero on success.
1694
 */
1675
 */
1695
int used_space_remove(as_area_t *a, uintptr_t page, count_t count)
1676
int used_space_remove(as_area_t *a, uintptr_t page, count_t count)
1696
{
1677
{
1697
    btree_node_t *leaf, *node;
1678
    btree_node_t *leaf, *node;
1698
    count_t pages;
1679
    count_t pages;
Line 1855... Line 1836...
1855
            return 0;
1836
            return 0;
1856
        }
1837
        }
1857
    }
1838
    }
1858
 
1839
 
1859
error:
1840
error:
1860
    panic("Inconsistency detected while removing %" PRIc " pages of used space "
1841
    panic("Inconsistency detected while removing %" PRIc " pages of used "
1861
        "from %p.\n", count, page);
1842
        "space from %p.\n", count, page);
1862
}
1843
}
1863
 
1844
 
1864
/** Remove reference to address space area share info.
1845
/** Remove reference to address space area share info.
1865
 *
1846
 *
1866
 * If the reference count drops to 0, the sh_info is deallocated.
1847
 * If the reference count drops to 0, the sh_info is deallocated.
Line 1954... Line 1935...
1954
        unsigned int i;
1935
        unsigned int i;
1955
        for (i = 0; i < node->keys; i++) {
1936
        for (i = 0; i < node->keys; i++) {
1956
            as_area_t *area = node->value[i];
1937
            as_area_t *area = node->value[i];
1957
       
1938
       
1958
            mutex_lock(&area->lock);
1939
            mutex_lock(&area->lock);
1959
            printf("as_area: %p, base=%p, pages=%" PRIc " (%p - %p)\n",
1940
            printf("as_area: %p, base=%p, pages=%" PRIc
1960
                area, area->base, area->pages, area->base,
1941
                " (%p - %p)\n", area, area->base, area->pages,
1961
                area->base + FRAMES2SIZE(area->pages));
1942
                area->base, area->base + FRAMES2SIZE(area->pages));
1962
            mutex_unlock(&area->lock);
1943
            mutex_unlock(&area->lock);
1963
        }
1944
        }
1964
    }
1945
    }
1965
   
1946
   
1966
    mutex_unlock(&as->lock);
1947
    mutex_unlock(&as->lock);