Changeset 6745592 in mainline for kernel/generic/src/mm/as.c
- Timestamp:
- 2008-09-02T19:00:11Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6d37d27
- Parents:
- ae7f6fb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/as.c
rae7f6fb r6745592 112 112 as_t *AS_KERNEL = NULL; 113 113 114 static int area_flags_to_page_flags(int aflags); 115 static as_area_t *find_area_and_lock(as_t *as, uintptr_t va); 116 static bool check_area_conflicts(as_t *as, uintptr_t va, size_t size, 117 as_area_t *avoid_area); 118 static void sh_info_remove_reference(share_info_t *sh_info); 114 static int area_flags_to_page_flags(int); 115 static as_area_t *find_area_and_lock(as_t *, uintptr_t); 116 static bool check_area_conflicts(as_t *, uintptr_t, size_t, as_area_t *); 117 static void sh_info_remove_reference(share_info_t *); 119 118 120 119 static int as_constructor(void *obj, int flags) … … 154 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 158 as_t *as_create(int flags) … … 187 187 * 188 188 * We know that we don't hold any spinlock. 189 * 190 * @param as Address space to be destroyed. 189 191 */ 190 192 void as_destroy(as_t *as) … … 258 260 * The created address space area is added to the target address space. 259 261 * 260 * @param as 261 * @param flags 262 * @param size 263 * @param base 264 * @param attrs 265 * @param backend 266 * @param backend_data 267 * 268 * @return 262 * @param as Target address space. 263 * @param flags Flags of the area memory. 264 * @param size Size of area. 265 * @param base Base address of area. 266 * @param attrs Attributes of the area. 267 * @param backend Address space area backend. NULL if no backend is used. 268 * @param backend_data NULL or a pointer to an array holding two void *. 269 * 270 * @return Address space area on success or NULL on failure. 269 271 */ 270 272 as_area_t * 271 273 as_area_create(as_t *as, int flags, size_t size, uintptr_t base, int attrs, 272 274 mem_backend_t *backend, mem_backend_data_t *backend_data) 273 275 { 274 276 ipl_t ipl; … … 322 324 /** Find address space area and change it. 323 325 * 324 * @param as Address space. 325 * @param address Virtual address belonging to the area to be changed. Must be 326 * page-aligned. 327 * @param size New size of the virtual memory block starting at address. 328 * @param flags Flags influencing the remap operation. Currently unused. 329 * 330 * @return Zero on success or a value from @ref errno.h otherwise. 326 * @param as Address space. 327 * @param address Virtual address belonging to the area to be changed. 328 * Must be page-aligned. 329 * @param size New size of the virtual memory block starting at 330 * address. 331 * @param flags Flags influencing the remap operation. Currently unused. 332 * 333 * @return Zero on success or a value from @ref errno.h otherwise. 331 334 */ 332 335 int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags) … … 436 439 cond = false; /* we are almost done */ 437 440 i = (start_free - b) >> PAGE_WIDTH; 438 if (!used_space_remove(area, start_free, c - i)) 439 panic("Could not remove used space.\n"); 441 if (!used_space_remove(area, start_free, 442 c - i)) 443 panic("Could not remove used " 444 "space.\n"); 440 445 } else { 441 446 /* … … 444 449 */ 445 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 … … 506 512 /** Destroy address space area. 507 513 * 508 * @param as 509 * @param address Address withingthe area to be deleted.510 * 511 * @return Zero on success or a value from @ref errno.h on failure.514 * @param as Address space. 515 * @param address Address within the area to be deleted. 516 * 517 * @return Zero on success or a value from @ref errno.h on failure. 512 518 */ 513 519 int as_area_destroy(as_t *as, uintptr_t address) … … 606 612 * mapping is done through the backend share function. 607 613 * 608 * @param src_as 609 * @param src_base 610 * @param acc_size 611 * @param dst_as 612 * @param dst_base 614 * @param src_as Pointer to source address space. 615 * @param src_base Base address of the source address space area. 616 * @param acc_size Expected size of the source area. 617 * @param dst_as Pointer to destination address space. 618 * @param dst_base Target base address. 613 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 616 * such address space area, EPERM if there was a problem in accepting the area 617 * or ENOMEM if there was a problem in allocating destination address space 618 * area. ENOTSUP is returned if the address space area backend does not support 619 * sharing. 621 * @return Zero on success or ENOENT if there is no such task or if 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 624 * problem in allocating destination address space area. 625 * ENOTSUP is returned if the address space area backend 626 * does not support sharing. 620 627 */ 621 628 int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size, … … 736 743 * The address space area must be locked prior to this call. 737 744 * 738 * @param area Address space area. 739 * @param access Access mode. 740 * 741 * @return False if access violates area's permissions, true otherwise. 745 * @param area Address space area. 746 * @param access Access mode. 747 * 748 * @return False if access violates area's permissions, true 749 * otherwise. 742 750 */ 743 751 bool as_area_check_access(as_area_t *area, pf_access_t access) … … 755 763 } 756 764 757 /** Change adress area flags.765 /** Change adress space area flags. 758 766 * 759 767 * The idea is to have the same data, but with a different access mode. … … 762 770 * into private anonymous memory (unless it's already there). 763 771 * 764 * @param as 765 * @param flags 766 * @param address 767 * 768 * @return Zero on success or a value from @ref errno.h on failure.772 * @param as Address space. 773 * @param flags Flags of the area memory. 774 * @param address Address withing the area to be changed. 775 * 776 * @return Zero on success or a value from @ref errno.h on failure. 769 777 */ 770 778 int as_area_change_flags(as_t *as, int flags, uintptr_t address) … … 877 885 /* 878 886 * Map pages back in with new flags. This step is kept separate 879 * so that the re's no instant when the memory area could be880 * accesed with both the old andthe new flags at once.887 * so that the memory area could not be accesed with both the old and 888 * the new flags at once. 881 889 */ 882 890 frame_idx = 0; … … 916 924 /** Handle page fault within the current address space. 917 925 * 918 * This is the high-level page fault handler. It decides 919 * whether the page fault can be resolved by any backend 920 * and if so, it invokes the backend to resolve the page 921 * fault. 926 * This is the high-level page fault handler. It decides whether the page fault 927 * can be resolved by any backend and if so, it invokes the backend to resolve 928 * the page fault. 922 929 * 923 930 * Interrupts are assumed disabled. 924 931 * 925 * @param page Faulting page. 926 * @param access Access mode that caused the fault (i.e. read/write/exec). 927 * @param istate Pointer to interrupted state. 928 * 929 * @return AS_PF_FAULT on page fault, AS_PF_OK on success or AS_PF_DEFER if the 930 * fault was caused by copy_to_uspace() or copy_from_uspace(). 932 * @param page Faulting page. 933 * @param access Access mode that caused the page fault (i.e. 934 * read/write/exec). 935 * @param istate Pointer to the interrupted state. 936 * 937 * @return AS_PF_FAULT on page fault, AS_PF_OK on success or 938 * AS_PF_DEFER if the fault was caused by copy_to_uspace() 939 * or copy_from_uspace(). 931 940 */ 932 941 int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate) … … 974 983 975 984 /* 976 * To avoid race condition between two page faults 977 * on the same address, we need to make sure 978 * the mapping has not been already inserted. 985 * To avoid race condition between two page faults on the same address, 986 * we need to make sure the mapping has not been already inserted. 979 987 */ 980 988 if ((pte = page_mapping_find(AS, page))) { … … 1030 1038 * When this function is enetered, no spinlocks may be held. 1031 1039 * 1032 * @param old 1033 * @param new 1040 * @param old Old address space or NULL. 1041 * @param new New address space. 1034 1042 */ 1035 1043 void as_switch(as_t *old_as, as_t *new_as) … … 1102 1110 /** Convert address space area flags to page flags. 1103 1111 * 1104 * @param aflags 1105 * 1106 * @return 1112 * @param aflags Flags of some address space area. 1113 * 1114 * @return Flags to be passed to page_mapping_insert(). 1107 1115 */ 1108 1116 int area_flags_to_page_flags(int aflags) … … 1132 1140 * Interrupts must be disabled. 1133 1141 * 1134 * @param a 1135 * 1136 * @return 1142 * @param a Address space area. 1143 * 1144 * @return Flags to be used in page_mapping_insert(). 1137 1145 */ 1138 1146 int as_area_get_flags(as_area_t *a) … … 1143 1151 /** Create page table. 1144 1152 * 1145 * Depending on architecture, create either address space 1146 * private or global page table. 1147 * 1148 * @param flags Flags saying whether the page table is for kernel address space. 1149 * 1150 * @return First entry of the page table. 1153 * Depending on architecture, create either address space private or global page 1154 * table. 1155 * 1156 * @param flags Flags saying whether the page table is for the kernel 1157 * address space. 1158 * 1159 * @return First entry of the page table. 1151 1160 */ 1152 1161 pte_t *page_table_create(int flags) … … 1162 1171 * Destroy page table in architecture specific way. 1163 1172 * 1164 * @param page_table 1173 * @param page_table Physical address of PTL0. 1165 1174 */ 1166 1175 void page_table_destroy(pte_t *page_table) … … 1181 1190 * call in which case the lock argument is false. 1182 1191 * 1183 * @param as 1184 * @param lock 1192 * @param as Address space. 1193 * @param lock If false, do not attempt to lock as->lock. 1185 1194 */ 1186 1195 void page_table_lock(as_t *as, bool lock) … … 1194 1203 /** Unlock page table. 1195 1204 * 1196 * @param as 1197 * @param unlock 1205 * @param as Address space. 1206 * @param unlock If false, do not attempt to unlock as->lock. 1198 1207 */ 1199 1208 void page_table_unlock(as_t *as, bool unlock) … … 1210 1219 * The address space must be locked and interrupts must be disabled. 1211 1220 * 1212 * @param as 1213 * @param va 1214 * 1215 * @return Locked address space area containing va on success or NULL on1216 * 1221 * @param as Address space. 1222 * @param va Virtual address. 1223 * 1224 * @return Locked address space area containing va on success or 1225 * NULL on failure. 1217 1226 */ 1218 1227 as_area_t *find_area_and_lock(as_t *as, uintptr_t va) … … 1266 1275 * The address space must be locked and interrupts must be disabled. 1267 1276 * 1268 * @param as 1269 * @param va 1270 * @param size 1271 * @param avoid_area 1272 * 1273 * @return 1274 */ 1275 bool check_area_conflicts(as_t *as, uintptr_t va, size_t size,1276 1277 * @param as Address space. 1278 * @param va Starting virtual address of the area being tested. 1279 * @param size Size of the area being tested. 1280 * @param avoid_area Do not touch this area. 1281 * 1282 * @return True if there is no conflict, false otherwise. 1283 */ 1284 bool 1285 check_area_conflicts(as_t *as, uintptr_t va, size_t size, as_area_t *avoid_area) 1277 1286 { 1278 1287 as_area_t *a; … … 1363 1372 ipl = interrupts_disable(); 1364 1373 src_area = find_area_and_lock(AS, base); 1365 if (src_area) {1374 if (src_area) { 1366 1375 size = src_area->pages * PAGE_SIZE; 1367 1376 mutex_unlock(&src_area->lock); … … 1377 1386 * The address space area must be already locked. 1378 1387 * 1379 * @param a 1380 * @param page 1381 * @param count 1382 * 1383 * @return 0 on failure and 1on success.1388 * @param a Address space area. 1389 * @param page First page to be marked. 1390 * @param count Number of page to be marked. 1391 * 1392 * @return Zero on failure and non-zero on success. 1384 1393 */ 1385 1394 int used_space_insert(as_area_t *a, uintptr_t page, count_t count) … … 1651 1660 } 1652 1661 1653 panic("Inconsistency detected while adding %" PRIc " pages of used space at"1654 " %p.\n", count, page);1662 panic("Inconsistency detected while adding %" PRIc " pages of used " 1663 "space at %p.\n", count, page); 1655 1664 } 1656 1665 … … 1659 1668 * The address space area must be already locked. 1660 1669 * 1661 * @param a 1662 * @param page 1663 * @param count 1664 * 1665 * @return 0 on failure and 1on success.1670 * @param a Address space area. 1671 * @param page First page to be marked. 1672 * @param count Number of page to be marked. 1673 * 1674 * @return Zero on failure and non-zero on success. 1666 1675 */ 1667 1676 int used_space_remove(as_area_t *a, uintptr_t page, count_t count) … … 1830 1839 1831 1840 error: 1832 panic("Inconsistency detected while removing %" PRIc " pages of used space"1833 " from %p.\n", count, page);1841 panic("Inconsistency detected while removing %" PRIc " pages of used " 1842 "space from %p.\n", count, page); 1834 1843 } 1835 1844 … … 1838 1847 * If the reference count drops to 0, the sh_info is deallocated. 1839 1848 * 1840 * @param sh_info 1849 * @param sh_info Pointer to address space area share info. 1841 1850 */ 1842 1851 void sh_info_remove_reference(share_info_t *sh_info) … … 1907 1916 /** Print out information about address space. 1908 1917 * 1909 * @param as 1918 * @param as Address space. 1910 1919 */ 1911 1920 void as_print(as_t *as) … … 1929 1938 1930 1939 mutex_lock(&area->lock); 1931 printf("as_area: %p, base=%p, pages=%" PRIc " (%p - %p)\n",1932 area, area->base, area->pages, area->base,1933 area->base + FRAMES2SIZE(area->pages));1940 printf("as_area: %p, base=%p, pages=%" PRIc 1941 " (%p - %p)\n", area, area->base, area->pages, 1942 area->base, area->base + FRAMES2SIZE(area->pages)); 1934 1943 mutex_unlock(&area->lock); 1935 1944 }
Note:
See TracChangeset
for help on using the changeset viewer.