Rev 3383 | Rev 3422 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3383 | Rev 3384 | ||
|---|---|---|---|
| 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 874... | Line 882... | ||
| 874 | */ |
882 | */ |
| 875 | area->flags = flags; |
883 | area->flags = flags; |
| 876 | 884 | ||
| 877 | /* |
885 | /* |
| 878 | * 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 |
| 879 | * 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 |
| 880 | * accesed with both the old and the new flags at once. |
888 | * the new flags at once. |
| 881 | */ |
889 | */ |
| 882 | frame_idx = 0; |
890 | frame_idx = 0; |
| 883 | 891 | ||
| 884 | for (cur = area->used_space.leaf_head.next; |
892 | for (cur = area->used_space.leaf_head.next; |
| 885 | cur != &area->used_space.leaf_head; cur = cur->next) { |
893 | cur != &area->used_space.leaf_head; cur = cur->next) { |
| Line 913... | Line 921... | ||
| 913 | } |
921 | } |
| 914 | 922 | ||
| 915 | 923 | ||
| 916 | /** Handle page fault within the current address space. |
924 | /** Handle page fault within the current address space. |
| 917 | * |
925 | * |
| 918 | * 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 |
| 919 | * whether the page fault can be resolved by any backend |
- | |
| 920 | * 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 |
| 921 | * fault. |
928 | * the page fault. |
| 922 | * |
929 | * |
| 923 | * Interrupts are assumed disabled. |
930 | * Interrupts are assumed disabled. |
| 924 | * |
931 | * |
| 925 | * @param page Faulting page. |
932 | * @param page Faulting page. |
| 926 | * @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). |
|
| 927 | * @param istate Pointer to interrupted state. |
935 | * @param istate Pointer to the interrupted state. |
| 928 | * |
936 | * |
| 929 | * @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 |
| 930 | * 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(). |
|
| 931 | */ |
940 | */ |
| 932 | 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) |
| 933 | { |
942 | { |
| 934 | pte_t *pte; |
943 | pte_t *pte; |
| 935 | as_area_t *area; |
944 | as_area_t *area; |
| Line 971... | Line 980... | ||
| 971 | } |
980 | } |
| 972 | 981 | ||
| 973 | page_table_lock(AS, false); |
982 | page_table_lock(AS, false); |
| 974 | 983 | ||
| 975 | /* |
984 | /* |
| 976 | * To avoid race condition between two page faults |
985 | * To avoid race condition between two page faults on the same address, |
| 977 | * on the same address, we need to make sure |
- | |
| 978 | * the mapping has not been already inserted. |
986 | * we need to make sure the mapping has not been already inserted. |
| 979 | */ |
987 | */ |
| 980 | if ((pte = page_mapping_find(AS, page))) { |
988 | if ((pte = page_mapping_find(AS, page))) { |
| 981 | if (PTE_PRESENT(pte)) { |
989 | if (PTE_PRESENT(pte)) { |
| 982 | if (((access == PF_ACCESS_READ) && PTE_READABLE(pte)) || |
990 | if (((access == PF_ACCESS_READ) && PTE_READABLE(pte)) || |
| 983 | (access == PF_ACCESS_WRITE && PTE_WRITABLE(pte)) || |
991 | (access == PF_ACCESS_WRITE && PTE_WRITABLE(pte)) || |
| Line 1027... | Line 1035... | ||
| 1027 | * scheduling. Sleeping here would lead to deadlock on wakeup. Another |
1035 | * scheduling. Sleeping here would lead to deadlock on wakeup. Another |
| 1028 | * 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. |
| 1029 | * |
1037 | * |
| 1030 | * When this function is enetered, no spinlocks may be held. |
1038 | * When this function is enetered, no spinlocks may be held. |
| 1031 | * |
1039 | * |
| 1032 | * @param old Old address space or NULL. |
1040 | * @param old Old address space or NULL. |
| 1033 | * @param new New address space. |
1041 | * @param new New address space. |
| 1034 | */ |
1042 | */ |
| 1035 | void as_switch(as_t *old_as, as_t *new_as) |
1043 | void as_switch(as_t *old_as, as_t *new_as) |
| 1036 | { |
1044 | { |
| 1037 | DEADLOCK_PROBE_INIT(p_asidlock); |
1045 | DEADLOCK_PROBE_INIT(p_asidlock); |
| 1038 | preemption_disable(); |
1046 | preemption_disable(); |
| Line 1099... | Line 1107... | ||
| 1099 | AS = new_as; |
1107 | AS = new_as; |
| 1100 | } |
1108 | } |
| 1101 | 1109 | ||
| 1102 | /** Convert address space area flags to page flags. |
1110 | /** Convert address space area flags to page flags. |
| 1103 | * |
1111 | * |
| 1104 | * @param aflags Flags of some address space area. |
1112 | * @param aflags Flags of some address space area. |
| 1105 | * |
1113 | * |
| 1106 | * @return Flags to be passed to page_mapping_insert(). |
1114 | * @return Flags to be passed to page_mapping_insert(). |
| 1107 | */ |
1115 | */ |
| 1108 | int area_flags_to_page_flags(int aflags) |
1116 | int area_flags_to_page_flags(int aflags) |
| 1109 | { |
1117 | { |
| 1110 | int flags; |
1118 | int flags; |
| 1111 | 1119 | ||
| Line 1129... | Line 1137... | ||
| 1129 | /** Compute flags for virtual address translation subsytem. |
1137 | /** Compute flags for virtual address translation subsytem. |
| 1130 | * |
1138 | * |
| 1131 | * The address space area must be locked. |
1139 | * The address space area must be locked. |
| 1132 | * Interrupts must be disabled. |
1140 | * Interrupts must be disabled. |
| 1133 | * |
1141 | * |
| 1134 | * @param a Address space area. |
1142 | * @param a Address space area. |
| 1135 | * |
1143 | * |
| 1136 | * @return Flags to be used in page_mapping_insert(). |
1144 | * @return Flags to be used in page_mapping_insert(). |
| 1137 | */ |
1145 | */ |
| 1138 | int as_area_get_flags(as_area_t *a) |
1146 | int as_area_get_flags(as_area_t *a) |
| 1139 | { |
1147 | { |
| 1140 | return area_flags_to_page_flags(a->flags); |
1148 | return area_flags_to_page_flags(a->flags); |
| 1141 | } |
1149 | } |
| 1142 | 1150 | ||
| 1143 | /** Create page table. |
1151 | /** Create page table. |
| 1144 | * |
1152 | * |
| 1145 | * Depending on architecture, create either address space |
1153 | * Depending on architecture, create either address space private or global page |
| 1146 | * private or global page table. |
1154 | * table. |
| 1147 | * |
1155 | * |
| 1148 | * @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. |
|
| 1149 | * |
1158 | * |
| 1150 | * @return First entry of the page table. |
1159 | * @return First entry of the page table. |
| 1151 | */ |
1160 | */ |
| 1152 | pte_t *page_table_create(int flags) |
1161 | pte_t *page_table_create(int flags) |
| 1153 | { |
1162 | { |
| 1154 | ASSERT(as_operations); |
1163 | ASSERT(as_operations); |
| 1155 | ASSERT(as_operations->page_table_create); |
1164 | ASSERT(as_operations->page_table_create); |
| Line 1159... | Line 1168... | ||
| 1159 | 1168 | ||
| 1160 | /** Destroy page table. |
1169 | /** Destroy page table. |
| 1161 | * |
1170 | * |
| 1162 | * Destroy page table in architecture specific way. |
1171 | * Destroy page table in architecture specific way. |
| 1163 | * |
1172 | * |
| 1164 | * @param page_table Physical address of PTL0. |
1173 | * @param page_table Physical address of PTL0. |
| 1165 | */ |
1174 | */ |
| 1166 | void page_table_destroy(pte_t *page_table) |
1175 | void page_table_destroy(pte_t *page_table) |
| 1167 | { |
1176 | { |
| 1168 | ASSERT(as_operations); |
1177 | ASSERT(as_operations); |
| 1169 | ASSERT(as_operations->page_table_destroy); |
1178 | ASSERT(as_operations->page_table_destroy); |
| Line 1178... | Line 1187... | ||
| 1178 | * |
1187 | * |
| 1179 | * Locking order is such that address space areas must be locked |
1188 | * Locking order is such that address space areas must be locked |
| 1180 | * 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 |
| 1181 | * call in which case the lock argument is false. |
1190 | * call in which case the lock argument is false. |
| 1182 | * |
1191 | * |
| 1183 | * @param as Address space. |
1192 | * @param as Address space. |
| 1184 | * @param lock If false, do not attempt to lock as->lock. |
1193 | * @param lock If false, do not attempt to lock as->lock. |
| 1185 | */ |
1194 | */ |
| 1186 | void page_table_lock(as_t *as, bool lock) |
1195 | void page_table_lock(as_t *as, bool lock) |
| 1187 | { |
1196 | { |
| 1188 | ASSERT(as_operations); |
1197 | ASSERT(as_operations); |
| 1189 | ASSERT(as_operations->page_table_lock); |
1198 | ASSERT(as_operations->page_table_lock); |
| Line 1191... | Line 1200... | ||
| 1191 | as_operations->page_table_lock(as, lock); |
1200 | as_operations->page_table_lock(as, lock); |
| 1192 | } |
1201 | } |
| 1193 | 1202 | ||
| 1194 | /** Unlock page table. |
1203 | /** Unlock page table. |
| 1195 | * |
1204 | * |
| 1196 | * @param as Address space. |
1205 | * @param as Address space. |
| 1197 | * @param unlock If false, do not attempt to unlock as->lock. |
1206 | * @param unlock If false, do not attempt to unlock as->lock. |
| 1198 | */ |
1207 | */ |
| 1199 | void page_table_unlock(as_t *as, bool unlock) |
1208 | void page_table_unlock(as_t *as, bool unlock) |
| 1200 | { |
1209 | { |
| 1201 | ASSERT(as_operations); |
1210 | ASSERT(as_operations); |
| 1202 | ASSERT(as_operations->page_table_unlock); |
1211 | ASSERT(as_operations->page_table_unlock); |
| Line 1207... | Line 1216... | ||
| 1207 | 1216 | ||
| 1208 | /** Find address space area and lock it. |
1217 | /** Find address space area and lock it. |
| 1209 | * |
1218 | * |
| 1210 | * The address space must be locked and interrupts must be disabled. |
1219 | * The address space must be locked and interrupts must be disabled. |
| 1211 | * |
1220 | * |
| 1212 | * @param as Address space. |
1221 | * @param as Address space. |
| 1213 | * @param va Virtual address. |
1222 | * @param va Virtual address. |
| 1214 | * |
1223 | * |
| 1215 | * @return Locked address space area containing va on success or NULL on |
1224 | * @return Locked address space area containing va on success or |
| 1216 | * failure. |
1225 | * NULL on failure. |
| 1217 | */ |
1226 | */ |
| 1218 | 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) |
| 1219 | { |
1228 | { |
| 1220 | as_area_t *a; |
1229 | as_area_t *a; |
| 1221 | btree_node_t *leaf, *lnode; |
1230 | btree_node_t *leaf, *lnode; |
| Line 1263... | Line 1272... | ||
| 1263 | 1272 | ||
| 1264 | /** Check area conflicts with other areas. |
1273 | /** Check area conflicts with other areas. |
| 1265 | * |
1274 | * |
| 1266 | * The address space must be locked and interrupts must be disabled. |
1275 | * The address space must be locked and interrupts must be disabled. |
| 1267 | * |
1276 | * |
| 1268 | * @param as Address space. |
1277 | * @param as Address space. |
| 1269 | * @param va Starting virtual address of the area being tested. |
1278 | * @param va Starting virtual address of the area being tested. |
| 1270 | * @param size Size of the area being tested. |
1279 | * @param size Size of the area being tested. |
| 1271 | * @param avoid_area Do not touch this area. |
1280 | * @param avoid_area Do not touch this area. |
| 1272 | * |
1281 | * |
| 1273 | * @return True if there is no conflict, false otherwise. |
1282 | * @return True if there is no conflict, false otherwise. |
| 1274 | */ |
1283 | */ |
| - | 1284 | bool |
|
| 1275 | 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) |
| 1276 | as_area_t *avoid_area) |
- | |
| 1277 | { |
1286 | { |
| 1278 | as_area_t *a; |
1287 | as_area_t *a; |
| 1279 | btree_node_t *leaf, *node; |
1288 | btree_node_t *leaf, *node; |
| 1280 | unsigned int i; |
1289 | unsigned int i; |
| 1281 | 1290 | ||
| Line 1360... | Line 1369... | ||
| 1360 | as_area_t *src_area; |
1369 | as_area_t *src_area; |
| 1361 | size_t size; |
1370 | size_t size; |
| 1362 | 1371 | ||
| 1363 | ipl = interrupts_disable(); |
1372 | ipl = interrupts_disable(); |
| 1364 | src_area = find_area_and_lock(AS, base); |
1373 | src_area = find_area_and_lock(AS, base); |
| 1365 | if (src_area){ |
1374 | if (src_area) { |
| 1366 | size = src_area->pages * PAGE_SIZE; |
1375 | size = src_area->pages * PAGE_SIZE; |
| 1367 | mutex_unlock(&src_area->lock); |
1376 | mutex_unlock(&src_area->lock); |
| 1368 | } else { |
1377 | } else { |
| 1369 | size = 0; |
1378 | size = 0; |
| 1370 | } |
1379 | } |
| Line 1374... | Line 1383... | ||
| 1374 | 1383 | ||
| 1375 | /** Mark portion of address space area as used. |
1384 | /** Mark portion of address space area as used. |
| 1376 | * |
1385 | * |
| 1377 | * The address space area must be already locked. |
1386 | * The address space area must be already locked. |
| 1378 | * |
1387 | * |
| 1379 | * @param a Address space area. |
1388 | * @param a Address space area. |
| 1380 | * @param page First page to be marked. |
1389 | * @param page First page to be marked. |
| 1381 | * @param count Number of page to be marked. |
1390 | * @param count Number of page to be marked. |
| 1382 | * |
1391 | * |
| 1383 | * @return 0 on failure and 1 on success. |
1392 | * @return Zero on failure and non-zero on success. |
| 1384 | */ |
1393 | */ |
| 1385 | 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) |
| 1386 | { |
1395 | { |
| 1387 | btree_node_t *leaf, *node; |
1396 | btree_node_t *leaf, *node; |
| 1388 | count_t pages; |
1397 | count_t pages; |
| Line 1648... | Line 1657... | ||
| 1648 | return 1; |
1657 | return 1; |
| 1649 | } |
1658 | } |
| 1650 | } |
1659 | } |
| 1651 | } |
1660 | } |
| 1652 | 1661 | ||
| 1653 | panic("Inconsistency detected while adding %" PRIc " pages of used space at " |
1662 | panic("Inconsistency detected while adding %" PRIc " pages of used " |
| 1654 | "%p.\n", count, page); |
1663 | "space at %p.\n", count, page); |
| 1655 | } |
1664 | } |
| 1656 | 1665 | ||
| 1657 | /** Mark portion of address space area as unused. |
1666 | /** Mark portion of address space area as unused. |
| 1658 | * |
1667 | * |
| 1659 | * The address space area must be already locked. |
1668 | * The address space area must be already locked. |
| 1660 | * |
1669 | * |
| 1661 | * @param a Address space area. |
1670 | * @param a Address space area. |
| 1662 | * @param page First page to be marked. |
1671 | * @param page First page to be marked. |
| 1663 | * @param count Number of page to be marked. |
1672 | * @param count Number of page to be marked. |
| 1664 | * |
1673 | * |
| 1665 | * @return 0 on failure and 1 on success. |
1674 | * @return Zero on failure and non-zero on success. |
| 1666 | */ |
1675 | */ |
| 1667 | 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) |
| 1668 | { |
1677 | { |
| 1669 | btree_node_t *leaf, *node; |
1678 | btree_node_t *leaf, *node; |
| 1670 | count_t pages; |
1679 | count_t pages; |
| Line 1827... | Line 1836... | ||
| 1827 | return 0; |
1836 | return 0; |
| 1828 | } |
1837 | } |
| 1829 | } |
1838 | } |
| 1830 | 1839 | ||
| 1831 | error: |
1840 | error: |
| 1832 | panic("Inconsistency detected while removing %" PRIc " pages of used space " |
1841 | panic("Inconsistency detected while removing %" PRIc " pages of used " |
| 1833 | "from %p.\n", count, page); |
1842 | "space from %p.\n", count, page); |
| 1834 | } |
1843 | } |
| 1835 | 1844 | ||
| 1836 | /** Remove reference to address space area share info. |
1845 | /** Remove reference to address space area share info. |
| 1837 | * |
1846 | * |
| 1838 | * 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. |
| 1839 | * |
1848 | * |
| 1840 | * @param sh_info Pointer to address space area share info. |
1849 | * @param sh_info Pointer to address space area share info. |
| 1841 | */ |
1850 | */ |
| 1842 | void sh_info_remove_reference(share_info_t *sh_info) |
1851 | void sh_info_remove_reference(share_info_t *sh_info) |
| 1843 | { |
1852 | { |
| 1844 | bool dealloc = false; |
1853 | bool dealloc = false; |
| 1845 | 1854 | ||
| Line 1904... | Line 1913... | ||
| 1904 | return (unative_t) as_area_destroy(AS, address); |
1913 | return (unative_t) as_area_destroy(AS, address); |
| 1905 | } |
1914 | } |
| 1906 | 1915 | ||
| 1907 | /** Print out information about address space. |
1916 | /** Print out information about address space. |
| 1908 | * |
1917 | * |
| 1909 | * @param as Address space. |
1918 | * @param as Address space. |
| 1910 | */ |
1919 | */ |
| 1911 | void as_print(as_t *as) |
1920 | void as_print(as_t *as) |
| 1912 | { |
1921 | { |
| 1913 | ipl_t ipl; |
1922 | ipl_t ipl; |
| 1914 | 1923 | ||
| Line 1926... | Line 1935... | ||
| 1926 | unsigned int i; |
1935 | unsigned int i; |
| 1927 | for (i = 0; i < node->keys; i++) { |
1936 | for (i = 0; i < node->keys; i++) { |
| 1928 | as_area_t *area = node->value[i]; |
1937 | as_area_t *area = node->value[i]; |
| 1929 | 1938 | ||
| 1930 | mutex_lock(&area->lock); |
1939 | mutex_lock(&area->lock); |
| 1931 | printf("as_area: %p, base=%p, pages=%" PRIc " (%p - %p)\n", |
1940 | printf("as_area: %p, base=%p, pages=%" PRIc |
| 1932 | area, area->base, area->pages, area->base, |
1941 | " (%p - %p)\n", area, area->base, area->pages, |
| 1933 | area->base + FRAMES2SIZE(area->pages)); |
1942 | area->base, area->base + FRAMES2SIZE(area->pages)); |
| 1934 | mutex_unlock(&area->lock); |
1943 | mutex_unlock(&area->lock); |
| 1935 | } |
1944 | } |
| 1936 | } |
1945 | } |
| 1937 | 1946 | ||
| 1938 | mutex_unlock(&as->lock); |
1947 | mutex_unlock(&as->lock); |