Subversion Repositories HelenOS

Rev

Rev 3343 | Rev 3742 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3343 Rev 3397
Line 109... Line 109...
109
LIST_INITIALIZE(inactive_as_with_asid_head);
109
LIST_INITIALIZE(inactive_as_with_asid_head);
110
 
110
 
111
/** Kernel address space. */
111
/** Kernel address space. */
112
as_t *AS_KERNEL = NULL;
112
as_t *AS_KERNEL = NULL;
113
 
113
 
114
static int area_flags_to_page_flags(int aflags);
114
static int area_flags_to_page_flags(int);
115
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);
116
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 *);
117
    as_area_t *avoid_area);
-
 
118
static void sh_info_remove_reference(share_info_t *sh_info);
117
static void sh_info_remove_reference(share_info_t *);
119
 
118
 
120
static int as_constructor(void *obj, int flags)
119
static int as_constructor(void *obj, int flags)
121
{
120
{
122
    as_t *as = (as_t *) obj;
121
    as_t *as = (as_t *) obj;
123
    int rc;
122
    int rc;
Line 151... Line 150...
151
   
150
   
152
}
151
}
153
 
152
 
154
/** Create address space.
153
/** Create address space.
155
 *
154
 *
156
 * @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.
157
 */
157
 */
158
as_t *as_create(int flags)
158
as_t *as_create(int flags)
159
{
159
{
160
    as_t *as;
160
    as_t *as;
161
 
161
 
Line 184... Line 184...
184
 *
184
 *
185
 * 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
186
 * zero), the address space can be destroyed.
186
 * zero), the address space can be destroyed.
187
 *
187
 *
188
 * 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.
189
 */
191
 */
190
void as_destroy(as_t *as)
192
void as_destroy(as_t *as)
191
{
193
{
192
    ipl_t ipl;
194
    ipl_t ipl;
193
    bool cond;
195
    bool cond;
Line 255... Line 257...
255
 
257
 
256
/** Create address space area of common attributes.
258
/** Create address space area of common attributes.
257
 *
259
 *
258
 * 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.
259
 *
261
 *
260
 * @param as Target address space.
262
 * @param as        Target address space.
261
 * @param flags Flags of the area memory.
263
 * @param flags     Flags of the area memory.
262
 * @param size Size of area.
264
 * @param size      Size of area.
263
 * @param base Base address of area.
265
 * @param base      Base address of area.
264
 * @param attrs Attributes of the area.
266
 * @param attrs     Attributes of the area.
265
 * @param backend Address space area backend. NULL if no backend is used.
267
 * @param backend   Address space area backend. NULL if no backend is used.
266
 * @param backend_data NULL or a pointer to an array holding two void *.
268
 * @param backend_data  NULL or a pointer to an array holding two void *.
267
 *
269
 *
268
 * @return Address space area on success or NULL on failure.
270
 * @return      Address space area on success or NULL on failure.
269
 */
271
 */
270
as_area_t *
272
as_area_t *
271
as_area_create(as_t *as, int flags, size_t size, uintptr_t base, int attrs,
273
as_area_create(as_t *as, int flags, size_t size, uintptr_t base, int attrs,
272
           mem_backend_t *backend, mem_backend_data_t *backend_data)
274
    mem_backend_t *backend, mem_backend_data_t *backend_data)
273
{
275
{
274
    ipl_t ipl;
276
    ipl_t ipl;
275
    as_area_t *a;
277
    as_area_t *a;
276
   
278
   
277
    if (base % PAGE_SIZE)
279
    if (base % PAGE_SIZE)
Line 319... Line 321...
319
    return a;
321
    return a;
320
}
322
}
321
 
323
 
322
/** Find address space area and change it.
324
/** Find address space area and change it.
323
 *
325
 *
324
 * @param as Address space.
326
 * @param as        Address space.
325
 * @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.
326
 *     page-aligned.
328
 *          Must be page-aligned.
327
 * @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.
328
 * @param flags Flags influencing the remap operation. Currently unused.
331
 * @param flags     Flags influencing the remap operation. Currently unused.
329
 *
332
 *
330
 * @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.
331
 */
334
 */
332
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)
333
{
336
{
334
    as_area_t *area;
337
    as_area_t *area;
335
    ipl_t ipl;
338
    ipl_t ipl;
Line 433... Line 436...
433
                     * address space area.
436
                     * address space area.
434
                     */
437
                     */
435
       
438
       
436
                    cond = false;   /* we are almost done */
439
                    cond = false;   /* we are almost done */
437
                    i = (start_free - b) >> PAGE_WIDTH;
440
                    i = (start_free - b) >> PAGE_WIDTH;
438
                    if (!used_space_remove(area, start_free, c - i))
441
                    if (!used_space_remove(area, start_free,
-
 
442
                        c - i))
439
                        panic("Could not remove used space.\n");
443
                        panic("Could not remove used "
-
 
444
                            "space.\n");
440
                } else {
445
                } else {
441
                    /*
446
                    /*
442
                     * The interval of used space can be
447
                     * The interval of used space can be
443
                     * completely removed.
448
                     * completely removed.
444
                     */
449
                     */
445
                    if (!used_space_remove(area, b, c))
450
                    if (!used_space_remove(area, b, c))
446
                        panic("Could not remove used space.\n");
451
                        panic("Could not remove used "
-
 
452
                            "space.\n");
447
                }
453
                }
448
           
454
           
449
                for (; i < c; i++) {
455
                for (; i < c; i++) {
450
                    pte_t *pte;
456
                    pte_t *pte;
451
           
457
           
Line 503... Line 509...
503
    return 0;
509
    return 0;
504
}
510
}
505
 
511
 
506
/** Destroy address space area.
512
/** Destroy address space area.
507
 *
513
 *
508
 * @param as Address space.
514
 * @param as        Address space.
509
 * @param address Address withing the area to be deleted.
515
 * @param address   Address within the area to be deleted.
510
 *
516
 *
511
 * @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.
512
 */
518
 */
513
int as_area_destroy(as_t *as, uintptr_t address)
519
int as_area_destroy(as_t *as, uintptr_t address)
514
{
520
{
515
    as_area_t *area;
521
    as_area_t *area;
516
    uintptr_t base;
522
    uintptr_t base;
Line 603... Line 609...
603
 * If the source address space area has not been shared so far,
609
 * If the source address space area has not been shared so far,
604
 * a new sh_info is created. The new address space area simply gets the
610
 * a new sh_info is created. The new address space area simply gets the
605
 * sh_info of the source area. The process of duplicating the
611
 * sh_info of the source area. The process of duplicating the
606
 * mapping is done through the backend share function.
612
 * mapping is done through the backend share function.
607
 *
613
 *
608
 * @param src_as Pointer to source address space.
614
 * @param src_as    Pointer to source address space.
609
 * @param src_base Base address of the source address space area.
615
 * @param src_base  Base address of the source address space area.
610
 * @param acc_size Expected size of the source area.
616
 * @param acc_size  Expected size of the source area.
611
 * @param dst_as Pointer to destination address space.
617
 * @param dst_as    Pointer to destination address space.
612
 * @param dst_base Target base address.
618
 * @param dst_base  Target base address.
613
 * @param dst_flags_mask Destination address space area flags mask.
619
 * @param dst_flags_mask Destination address space area flags mask.
614
 *
620
 *
615
 * @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
616
 * 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
617
 * or ENOMEM if there was a problem in allocating destination address space
624
 *          problem in allocating destination address space area.
618
 * area. ENOTSUP is returned if the address space area backend does not support
625
 *          ENOTSUP is returned if the address space area backend
619
 * sharing.
626
 *          does not support sharing.
620
 */
627
 */
621
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,
622
    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)
623
{
630
{
624
    ipl_t ipl;
631
    ipl_t ipl;
Line 733... Line 740...
733
 
740
 
734
/** Check access mode for address space area.
741
/** Check access mode for address space area.
735
 *
742
 *
736
 * The address space area must be locked prior to this call.
743
 * The address space area must be locked prior to this call.
737
 *
744
 *
738
 * @param area Address space area.
745
 * @param area      Address space area.
739
 * @param access Access mode.
746
 * @param access    Access mode.
740
 *
747
 *
741
 * @return False if access violates area's permissions, true otherwise.
748
 * @return      False if access violates area's permissions, true
-
 
749
 *          otherwise.
742
 */
750
 */
743
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)
744
{
752
{
745
    int flagmap[] = {
753
    int flagmap[] = {
746
        [PF_ACCESS_READ] = AS_AREA_READ,
754
        [PF_ACCESS_READ] = AS_AREA_READ,
Line 752... Line 760...
752
        return false;
760
        return false;
753
   
761
   
754
    return true;
762
    return true;
755
}
763
}
756
 
764
 
757
/** Change adress area flags.
765
/** Change adress space area flags.
758
 *
766
 *
759
 * 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.
760
 * 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.
761
 * 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
762
 * into private anonymous memory (unless it's already there).
770
 * into private anonymous memory (unless it's already there).
763
 *
771
 *
764
 * @param as Address space.
772
 * @param as        Address space.
765
 * @param flags Flags of the area memory.
773
 * @param flags     Flags of the area memory.
766
 * @param address Address withing the area to be changed.
774
 * @param address   Address withing the area to be changed.
767
 *
775
 *
768
 * @return Zero on success or a value from @ref errno.h on failure.
776
 * @return      Zero on success or a value from @ref errno.h on failure.
769
 */
777
 */
770
int as_area_change_flags(as_t *as, int flags, uintptr_t address)
778
int as_area_change_flags(as_t *as, int flags, uintptr_t address)
771
{
779
{
772
    as_area_t *area;
780
    as_area_t *area;
773
    uintptr_t base;
781
    uintptr_t base;
Line 868... Line 876...
868
     */
876
     */
869
    as_invalidate_translation_cache(as, area->base, area->pages);
877
    as_invalidate_translation_cache(as, area->base, area->pages);
870
    tlb_shootdown_finalize();
878
    tlb_shootdown_finalize();
871
 
879
 
872
    /*
880
    /*
-
 
881
     * Set the new flags.
-
 
882
     */
-
 
883
    area->flags = flags;
-
 
884
 
-
 
885
    /*
873
     * 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
874
     * 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
875
     * accesed with both the old and the new flags at once.
888
     * the new flags at once.
876
     */
889
     */
877
    frame_idx = 0;
890
    frame_idx = 0;
878
 
891
 
879
    for (cur = area->used_space.leaf_head.next;
892
    for (cur = area->used_space.leaf_head.next;
880
        cur != &area->used_space.leaf_head; cur = cur->next) {
893
        cur != &area->used_space.leaf_head; cur = cur->next) {
Line 908... Line 921...
908
}
921
}
909
 
922
 
910
 
923
 
911
/** Handle page fault within the current address space.
924
/** Handle page fault within the current address space.
912
 *
925
 *
913
 * 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
914
 * whether the page fault can be resolved by any backend
-
 
915
 * 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
916
 * fault.
928
 * the page fault.
917
 *
929
 *
918
 * Interrupts are assumed disabled.
930
 * Interrupts are assumed disabled.
919
 *
931
 *
920
 * @param page Faulting page.
932
 * @param page      Faulting page.
921
 * @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).
922
 * @param istate Pointer to interrupted state.
935
 * @param istate    Pointer to the interrupted state.
923
 *
936
 *
924
 * @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
925
 *     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().
926
 */
940
 */
927
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)
928
{
942
{
929
    pte_t *pte;
943
    pte_t *pte;
930
    as_area_t *area;
944
    as_area_t *area;
Line 966... Line 980...
966
    }
980
    }
967
 
981
 
968
    page_table_lock(AS, false);
982
    page_table_lock(AS, false);
969
   
983
   
970
    /*
984
    /*
971
     * To avoid race condition between two page faults
985
     * To avoid race condition between two page faults on the same address,
972
     * on the same address, we need to make sure
-
 
973
     * the mapping has not been already inserted.
986
     * we need to make sure the mapping has not been already inserted.
974
     */
987
     */
975
    if ((pte = page_mapping_find(AS, page))) {
988
    if ((pte = page_mapping_find(AS, page))) {
976
        if (PTE_PRESENT(pte)) {
989
        if (PTE_PRESENT(pte)) {
977
            if (((access == PF_ACCESS_READ) && PTE_READABLE(pte)) ||
990
            if (((access == PF_ACCESS_READ) && PTE_READABLE(pte)) ||
978
                (access == PF_ACCESS_WRITE && PTE_WRITABLE(pte)) ||
991
                (access == PF_ACCESS_WRITE && PTE_WRITABLE(pte)) ||
Line 1022... Line 1035...
1022
 * scheduling. Sleeping here would lead to deadlock on wakeup. Another
1035
 * scheduling. Sleeping here would lead to deadlock on wakeup. Another
1023
 * thing which is forbidden in this context is locking the address space.
1036
 * thing which is forbidden in this context is locking the address space.
1024
 *
1037
 *
1025
 * When this function is enetered, no spinlocks may be held.
1038
 * When this function is enetered, no spinlocks may be held.
1026
 *
1039
 *
1027
 * @param old Old address space or NULL.
1040
 * @param old       Old address space or NULL.
1028
 * @param new New address space.
1041
 * @param new       New address space.
1029
 */
1042
 */
1030
void as_switch(as_t *old_as, as_t *new_as)
1043
void as_switch(as_t *old_as, as_t *new_as)
1031
{
1044
{
1032
    DEADLOCK_PROBE_INIT(p_asidlock);
1045
    DEADLOCK_PROBE_INIT(p_asidlock);
1033
    preemption_disable();
1046
    preemption_disable();
Line 1094... Line 1107...
1094
    AS = new_as;
1107
    AS = new_as;
1095
}
1108
}
1096
 
1109
 
1097
/** Convert address space area flags to page flags.
1110
/** Convert address space area flags to page flags.
1098
 *
1111
 *
1099
 * @param aflags Flags of some address space area.
1112
 * @param aflags    Flags of some address space area.
1100
 *
1113
 *
1101
 * @return Flags to be passed to page_mapping_insert().
1114
 * @return      Flags to be passed to page_mapping_insert().
1102
 */
1115
 */
1103
int area_flags_to_page_flags(int aflags)
1116
int area_flags_to_page_flags(int aflags)
1104
{
1117
{
1105
    int flags;
1118
    int flags;
1106
 
1119
 
Line 1124... Line 1137...
1124
/** Compute flags for virtual address translation subsytem.
1137
/** Compute flags for virtual address translation subsytem.
1125
 *
1138
 *
1126
 * The address space area must be locked.
1139
 * The address space area must be locked.
1127
 * Interrupts must be disabled.
1140
 * Interrupts must be disabled.
1128
 *
1141
 *
1129
 * @param a Address space area.
1142
 * @param a     Address space area.
1130
 *
1143
 *
1131
 * @return Flags to be used in page_mapping_insert().
1144
 * @return      Flags to be used in page_mapping_insert().
1132
 */
1145
 */
1133
int as_area_get_flags(as_area_t *a)
1146
int as_area_get_flags(as_area_t *a)
1134
{
1147
{
1135
    return area_flags_to_page_flags(a->flags);
1148
    return area_flags_to_page_flags(a->flags);
1136
}
1149
}
1137
 
1150
 
1138
/** Create page table.
1151
/** Create page table.
1139
 *
1152
 *
1140
 * Depending on architecture, create either address space
1153
 * Depending on architecture, create either address space private or global page
1141
 * private or global page table.
1154
 * table.
1142
 *
1155
 *
1143
 * @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.
1144
 *
1158
 *
1145
 * @return First entry of the page table.
1159
 * @return      First entry of the page table.
1146
 */
1160
 */
1147
pte_t *page_table_create(int flags)
1161
pte_t *page_table_create(int flags)
1148
{
1162
{
1149
    ASSERT(as_operations);
1163
    ASSERT(as_operations);
1150
    ASSERT(as_operations->page_table_create);
1164
    ASSERT(as_operations->page_table_create);
Line 1154... Line 1168...
1154
 
1168
 
1155
/** Destroy page table.
1169
/** Destroy page table.
1156
 *
1170
 *
1157
 * Destroy page table in architecture specific way.
1171
 * Destroy page table in architecture specific way.
1158
 *
1172
 *
1159
 * @param page_table Physical address of PTL0.
1173
 * @param page_table    Physical address of PTL0.
1160
 */
1174
 */
1161
void page_table_destroy(pte_t *page_table)
1175
void page_table_destroy(pte_t *page_table)
1162
{
1176
{
1163
    ASSERT(as_operations);
1177
    ASSERT(as_operations);
1164
    ASSERT(as_operations->page_table_destroy);
1178
    ASSERT(as_operations->page_table_destroy);
Line 1173... Line 1187...
1173
 *
1187
 *
1174
 * Locking order is such that address space areas must be locked
1188
 * Locking order is such that address space areas must be locked
1175
 * prior to this call. Address space can be locked prior to this
1189
 * prior to this call. Address space can be locked prior to this
1176
 * call in which case the lock argument is false.
1190
 * call in which case the lock argument is false.
1177
 *
1191
 *
1178
 * @param as Address space.
1192
 * @param as        Address space.
1179
 * @param lock If false, do not attempt to lock as->lock.
1193
 * @param lock      If false, do not attempt to lock as->lock.
1180
 */
1194
 */
1181
void page_table_lock(as_t *as, bool lock)
1195
void page_table_lock(as_t *as, bool lock)
1182
{
1196
{
1183
    ASSERT(as_operations);
1197
    ASSERT(as_operations);
1184
    ASSERT(as_operations->page_table_lock);
1198
    ASSERT(as_operations->page_table_lock);
Line 1186... Line 1200...
1186
    as_operations->page_table_lock(as, lock);
1200
    as_operations->page_table_lock(as, lock);
1187
}
1201
}
1188
 
1202
 
1189
/** Unlock page table.
1203
/** Unlock page table.
1190
 *
1204
 *
1191
 * @param as Address space.
1205
 * @param as        Address space.
1192
 * @param unlock If false, do not attempt to unlock as->lock.
1206
 * @param unlock    If false, do not attempt to unlock as->lock.
1193
 */
1207
 */
1194
void page_table_unlock(as_t *as, bool unlock)
1208
void page_table_unlock(as_t *as, bool unlock)
1195
{
1209
{
1196
    ASSERT(as_operations);
1210
    ASSERT(as_operations);
1197
    ASSERT(as_operations->page_table_unlock);
1211
    ASSERT(as_operations->page_table_unlock);
Line 1202... Line 1216...
1202
 
1216
 
1203
/** Find address space area and lock it.
1217
/** Find address space area and lock it.
1204
 *
1218
 *
1205
 * The address space must be locked and interrupts must be disabled.
1219
 * The address space must be locked and interrupts must be disabled.
1206
 *
1220
 *
1207
 * @param as Address space.
1221
 * @param as        Address space.
1208
 * @param va Virtual address.
1222
 * @param va        Virtual address.
1209
 *
1223
 *
1210
 * @return Locked address space area containing va on success or NULL on
1224
 * @return      Locked address space area containing va on success or
1211
 *     failure.
1225
 *          NULL on failure.
1212
 */
1226
 */
1213
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)
1214
{
1228
{
1215
    as_area_t *a;
1229
    as_area_t *a;
1216
    btree_node_t *leaf, *lnode;
1230
    btree_node_t *leaf, *lnode;
Line 1258... Line 1272...
1258
 
1272
 
1259
/** Check area conflicts with other areas.
1273
/** Check area conflicts with other areas.
1260
 *
1274
 *
1261
 * The address space must be locked and interrupts must be disabled.
1275
 * The address space must be locked and interrupts must be disabled.
1262
 *
1276
 *
1263
 * @param as Address space.
1277
 * @param as        Address space.
1264
 * @param va Starting virtual address of the area being tested.
1278
 * @param va        Starting virtual address of the area being tested.
1265
 * @param size Size of the area being tested.
1279
 * @param size      Size of the area being tested.
1266
 * @param avoid_area Do not touch this area.
1280
 * @param avoid_area    Do not touch this area.
1267
 *
1281
 *
1268
 * @return True if there is no conflict, false otherwise.
1282
 * @return      True if there is no conflict, false otherwise.
1269
 */
1283
 */
-
 
1284
bool
1270
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)
1271
              as_area_t *avoid_area)
-
 
1272
{
1286
{
1273
    as_area_t *a;
1287
    as_area_t *a;
1274
    btree_node_t *leaf, *node;
1288
    btree_node_t *leaf, *node;
1275
    unsigned int i;
1289
    unsigned int i;
1276
   
1290
   
Line 1355... Line 1369...
1355
    as_area_t *src_area;
1369
    as_area_t *src_area;
1356
    size_t size;
1370
    size_t size;
1357
 
1371
 
1358
    ipl = interrupts_disable();
1372
    ipl = interrupts_disable();
1359
    src_area = find_area_and_lock(AS, base);
1373
    src_area = find_area_and_lock(AS, base);
1360
    if (src_area){
1374
    if (src_area) {
1361
        size = src_area->pages * PAGE_SIZE;
1375
        size = src_area->pages * PAGE_SIZE;
1362
        mutex_unlock(&src_area->lock);
1376
        mutex_unlock(&src_area->lock);
1363
    } else {
1377
    } else {
1364
        size = 0;
1378
        size = 0;
1365
    }
1379
    }
Line 1369... Line 1383...
1369
 
1383
 
1370
/** Mark portion of address space area as used.
1384
/** Mark portion of address space area as used.
1371
 *
1385
 *
1372
 * The address space area must be already locked.
1386
 * The address space area must be already locked.
1373
 *
1387
 *
1374
 * @param a Address space area.
1388
 * @param a     Address space area.
1375
 * @param page First page to be marked.
1389
 * @param page      First page to be marked.
1376
 * @param count Number of page to be marked.
1390
 * @param count     Number of page to be marked.
1377
 *
1391
 *
1378
 * @return 0 on failure and 1 on success.
1392
 * @return      Zero on failure and non-zero on success.
1379
 */
1393
 */
1380
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)
1381
{
1395
{
1382
    btree_node_t *leaf, *node;
1396
    btree_node_t *leaf, *node;
1383
    count_t pages;
1397
    count_t pages;
Line 1643... Line 1657...
1643
                return 1;
1657
                return 1;
1644
            }
1658
            }
1645
        }
1659
        }
1646
    }
1660
    }
1647
 
1661
 
1648
    panic("Inconsistency detected while adding %" PRIc " pages of used space at "
1662
    panic("Inconsistency detected while adding %" PRIc " pages of used "
1649
        "%p.\n", count, page);
1663
        "space at %p.\n", count, page);
1650
}
1664
}
1651
 
1665
 
1652
/** Mark portion of address space area as unused.
1666
/** Mark portion of address space area as unused.
1653
 *
1667
 *
1654
 * The address space area must be already locked.
1668
 * The address space area must be already locked.
1655
 *
1669
 *
1656
 * @param a Address space area.
1670
 * @param a     Address space area.
1657
 * @param page First page to be marked.
1671
 * @param page      First page to be marked.
1658
 * @param count Number of page to be marked.
1672
 * @param count     Number of page to be marked.
1659
 *
1673
 *
1660
 * @return 0 on failure and 1 on success.
1674
 * @return      Zero on failure and non-zero on success.
1661
 */
1675
 */
1662
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)
1663
{
1677
{
1664
    btree_node_t *leaf, *node;
1678
    btree_node_t *leaf, *node;
1665
    count_t pages;
1679
    count_t pages;
Line 1822... Line 1836...
1822
            return 0;
1836
            return 0;
1823
        }
1837
        }
1824
    }
1838
    }
1825
 
1839
 
1826
error:
1840
error:
1827
    panic("Inconsistency detected while removing %" PRIc " pages of used space "
1841
    panic("Inconsistency detected while removing %" PRIc " pages of used "
1828
        "from %p.\n", count, page);
1842
        "space from %p.\n", count, page);
1829
}
1843
}
1830
 
1844
 
1831
/** Remove reference to address space area share info.
1845
/** Remove reference to address space area share info.
1832
 *
1846
 *
1833
 * 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.
1834
 *
1848
 *
1835
 * @param sh_info Pointer to address space area share info.
1849
 * @param sh_info   Pointer to address space area share info.
1836
 */
1850
 */
1837
void sh_info_remove_reference(share_info_t *sh_info)
1851
void sh_info_remove_reference(share_info_t *sh_info)
1838
{
1852
{
1839
    bool dealloc = false;
1853
    bool dealloc = false;
1840
 
1854
 
Line 1899... Line 1913...
1899
    return (unative_t) as_area_destroy(AS, address);
1913
    return (unative_t) as_area_destroy(AS, address);
1900
}
1914
}
1901
 
1915
 
1902
/** Print out information about address space.
1916
/** Print out information about address space.
1903
 *
1917
 *
1904
 * @param as Address space.
1918
 * @param as        Address space.
1905
 */
1919
 */
1906
void as_print(as_t *as)
1920
void as_print(as_t *as)
1907
{
1921
{
1908
    ipl_t ipl;
1922
    ipl_t ipl;
1909
   
1923
   
Line 1921... Line 1935...
1921
        unsigned int i;
1935
        unsigned int i;
1922
        for (i = 0; i < node->keys; i++) {
1936
        for (i = 0; i < node->keys; i++) {
1923
            as_area_t *area = node->value[i];
1937
            as_area_t *area = node->value[i];
1924
       
1938
       
1925
            mutex_lock(&area->lock);
1939
            mutex_lock(&area->lock);
1926
            printf("as_area: %p, base=%p, pages=%" PRIc " (%p - %p)\n",
1940
            printf("as_area: %p, base=%p, pages=%" PRIc
1927
                area, area->base, area->pages, area->base,
1941
                " (%p - %p)\n", area, area->base, area->pages,
1928
                area->base + FRAMES2SIZE(area->pages));
1942
                area->base, area->base + FRAMES2SIZE(area->pages));
1929
            mutex_unlock(&area->lock);
1943
            mutex_unlock(&area->lock);
1930
        }
1944
        }
1931
    }
1945
    }
1932
   
1946
   
1933
    mutex_unlock(&as->lock);
1947
    mutex_unlock(&as->lock);