Changeset d5bd8d7 in mainline
- Timestamp:
- 2007-03-25T13:02:06Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4638401
- Parents:
- 0f6a3376
- Location:
- kernel/generic/src/mm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/backend_anon.c
r0f6a3376 rd5bd8d7 73 73 * @param access Access mode that caused the fault (i.e. read/write/exec). 74 74 * 75 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced). 75 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. 76 * serviced). 76 77 */ 77 78 int anon_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access) … … 87 88 /* 88 89 * The area is shared, chances are that the mapping can be found 89 * in the pagemap of the address space area share info structure. 90 * in the pagemap of the address space area share info 91 * structure. 90 92 * In the case that the pagemap does not contain the respective 91 93 * mapping, a new frame is allocated and the mapping is created. … … 103 105 */ 104 106 for (i = 0; i < leaf->keys; i++) { 105 if (leaf->key[i] == ALIGN_DOWN(addr, PAGE_SIZE)) { 107 if (leaf->key[i] == 108 ALIGN_DOWN(addr, PAGE_SIZE)) { 106 109 allocate = false; 107 110 break; … … 113 116 114 117 /* 115 * Insert the address of the newly allocated frame to the pagemap. 118 * Insert the address of the newly allocated 119 * frame to the pagemap. 116 120 */ 117 btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, (void *) frame, leaf); 121 btree_insert(&area->sh_info->pagemap, 122 ALIGN_DOWN(addr, PAGE_SIZE) - area->base, 123 (void *) frame, leaf); 118 124 } 119 125 } … … 142 148 /* 143 149 * Map 'page' to 'frame'. 144 * Note that TLB shootdown is not attempted as only new information is being145 * inserted into page tables.150 * Note that TLB shootdown is not attempted as only new information is 151 * being inserted into page tables. 146 152 */ 147 153 page_mapping_insert(AS, addr, frame, as_area_get_flags(area)); … … 185 191 */ 186 192 mutex_lock(&area->sh_info->lock); 187 for (cur = area->used_space.leaf_head.next; cur != &area->used_space.leaf_head; cur = cur->next) { 193 for (cur = area->used_space.leaf_head.next; 194 cur != &area->used_space.leaf_head; cur = cur->next) { 188 195 btree_node_t *node; 189 196 int i; … … 199 206 200 207 page_table_lock(area->as, false); 201 pte = page_mapping_find(area->as, base + j*PAGE_SIZE); 202 ASSERT(pte && PTE_VALID(pte) && PTE_PRESENT(pte)); 203 btree_insert(&area->sh_info->pagemap, (base + j*PAGE_SIZE) - area->base, 204 (void *) PTE_GET_FRAME(pte), NULL); 208 pte = page_mapping_find(area->as, 209 base + j * PAGE_SIZE); 210 ASSERT(pte && PTE_VALID(pte) && 211 PTE_PRESENT(pte)); 212 btree_insert(&area->sh_info->pagemap, 213 (base + j * PAGE_SIZE) - area->base, 214 (void *) PTE_GET_FRAME(pte), NULL); 205 215 page_table_unlock(area->as, false); 206 frame_reference_add(ADDR2PFN(PTE_GET_FRAME(pte))); 216 217 pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(pte)); 218 frame_reference_add(pfn); 207 219 } 208 220 … … 214 226 /** @} 215 227 */ 228 -
kernel/generic/src/mm/backend_elf.c
r0f6a3376 rd5bd8d7 72 72 * @param access Access mode that caused the fault (i.e. read/write/exec). 73 73 * 74 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced). 74 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. 75 * serviced). 75 76 */ 76 77 int elf_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access) … … 85 86 return AS_PF_FAULT; 86 87 87 ASSERT((addr >= entry->p_vaddr) && (addr < entry->p_vaddr + entry->p_memsz)); 88 ASSERT((addr >= entry->p_vaddr) && 89 (addr < entry->p_vaddr + entry->p_memsz)); 88 90 i = (addr - entry->p_vaddr) >> PAGE_WIDTH; 89 91 base = (uintptr_t) (((void *) elf) + entry->p_offset); … … 108 110 109 111 for (i = 0; i < leaf->keys; i++) { 110 if (leaf->key[i] == ALIGN_DOWN(addr, PAGE_SIZE)) { 112 if (leaf->key[i] == 113 ALIGN_DOWN(addr, PAGE_SIZE)) { 111 114 found = true; 112 115 break; … … 116 119 if (frame || found) { 117 120 frame_reference_add(ADDR2PFN(frame)); 118 page_mapping_insert(AS, addr, frame, as_area_get_flags(area)); 119 if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1)) 121 page_mapping_insert(AS, addr, frame, 122 as_area_get_flags(area)); 123 if (!used_space_insert(area, 124 ALIGN_DOWN(addr, PAGE_SIZE), 1)) 120 125 panic("Could not insert used space.\n"); 121 126 mutex_unlock(&area->sh_info->lock); … … 125 130 126 131 /* 127 * The area is either not shared or the pagemap does not contain the mapping. 132 * The area is either not shared or the pagemap does not contain the 133 * mapping. 128 134 */ 129 135 130 if (ALIGN_DOWN(addr, PAGE_SIZE) + PAGE_SIZE < entry->p_vaddr + entry->p_filesz) { 136 if (ALIGN_DOWN(addr, PAGE_SIZE) + PAGE_SIZE < 137 entry->p_vaddr + entry->p_filesz) { 131 138 /* 132 139 * Initialized portion of the segment. The memory is backed … … 139 146 if (entry->p_flags & PF_W) { 140 147 frame = (uintptr_t)frame_alloc(ONE_FRAME, 0); 141 memcpy((void *) PA2KA(frame), (void *) (base + i*FRAME_SIZE), FRAME_SIZE); 148 memcpy((void *) PA2KA(frame), 149 (void *) (base + i * FRAME_SIZE), FRAME_SIZE); 142 150 143 151 if (area->sh_info) { 144 152 frame_reference_add(ADDR2PFN(frame)); 145 btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, 146 (void *) frame, leaf); 153 btree_insert(&area->sh_info->pagemap, 154 ALIGN_DOWN(addr, PAGE_SIZE) - area->base, 155 (void *) frame, leaf); 147 156 } 148 157 … … 150 159 frame = KA2PA(base + i*FRAME_SIZE); 151 160 } 152 } else if (ALIGN_DOWN(addr, PAGE_SIZE) >= ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) { 161 } else if (ALIGN_DOWN(addr, PAGE_SIZE) >= 162 ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) { 153 163 /* 154 164 * This is the uninitialized portion of the segment. … … 162 172 if (area->sh_info) { 163 173 frame_reference_add(ADDR2PFN(frame)); 164 btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, 165 (void *) frame, leaf); 174 btree_insert(&area->sh_info->pagemap, 175 ALIGN_DOWN(addr, PAGE_SIZE) - area->base, 176 (void *) frame, leaf); 166 177 } 167 178 … … 176 187 frame = (uintptr_t)frame_alloc(ONE_FRAME, 0); 177 188 memsetb(PA2KA(frame) + size, FRAME_SIZE - size, 0); 178 memcpy((void *) PA2KA(frame), (void *) (base + i*FRAME_SIZE), size); 189 memcpy((void *) PA2KA(frame), (void *) (base + i * FRAME_SIZE), 190 size); 179 191 180 192 if (area->sh_info) { 181 193 frame_reference_add(ADDR2PFN(frame)); 182 btree_insert(&area->sh_info->pagemap, ALIGN_DOWN(addr, PAGE_SIZE) - area->base, 183 (void *) frame, leaf); 194 btree_insert(&area->sh_info->pagemap, 195 ALIGN_DOWN(addr, PAGE_SIZE) - area->base, 196 (void *) frame, leaf); 184 197 } 185 198 … … 212 225 index_t i; 213 226 214 ASSERT((page >= entry->p_vaddr) && (page < entry->p_vaddr + entry->p_memsz)); 227 ASSERT((page >= entry->p_vaddr) && 228 (page < entry->p_vaddr + entry->p_memsz)); 215 229 i = (page - entry->p_vaddr) >> PAGE_WIDTH; 216 230 base = (uintptr_t) (((void *) elf) + entry->p_offset); 217 231 ASSERT(ALIGN_UP(base, FRAME_SIZE) == base); 218 232 219 if (page + PAGE_SIZE < ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) { 233 if (page + PAGE_SIZE < 234 ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) { 220 235 if (entry->p_flags & PF_W) { 221 236 /* 222 * Free the frame with the copy of writable segment data. 237 * Free the frame with the copy of writable segment 238 * data. 223 239 */ 224 240 frame_free(frame); … … 229 245 } else { 230 246 /* 231 * The frame is either anonymous memory or the mixed case (i.e. lower232 * part is backed by the ELF image and the upper is anonymous).233 * In any case, a frame needs to be freed.247 * The frame is either anonymous memory or the mixed case (i.e. 248 * lower part is backed by the ELF image and the upper is 249 * anonymous). In any case, a frame needs to be freed. 234 250 */ 235 251 frame_free(frame); … … 261 277 */ 262 278 if (area->flags & AS_AREA_WRITE) { 263 node = list_get_instance(area->used_space.leaf_head.next, btree_node_t, leaf_link); 279 node = list_get_instance(area->used_space.leaf_head.next, 280 btree_node_t, leaf_link); 264 281 } else { 265 282 (void) btree_search(&area->sh_info->pagemap, start_anon, &leaf); 266 node = btree_leaf_node_left_neighbour(&area->sh_info->pagemap, leaf); 283 node = btree_leaf_node_left_neighbour(&area->sh_info->pagemap, 284 leaf); 267 285 if (!node) 268 286 node = leaf; … … 273 291 */ 274 292 mutex_lock(&area->sh_info->lock); 275 for (cur = &node->leaf_link; cur != &area->used_space.leaf_head; cur = cur->next) { 293 for (cur = &node->leaf_link; cur != &area->used_space.leaf_head; 294 cur = cur->next) { 276 295 int i; 277 296 … … 295 314 296 315 /* 297 * Skip read-only pages that are backed by the ELF image. 316 * Skip read-only pages that are backed by the 317 * ELF image. 298 318 */ 299 319 if (!(area->flags & AS_AREA_WRITE)) 300 if (base + (j + 1)*PAGE_SIZE <= start_anon) 320 if (base + (j + 1) * PAGE_SIZE <= 321 start_anon) 301 322 continue; 302 323 303 324 page_table_lock(area->as, false); 304 pte = page_mapping_find(area->as, base + j*PAGE_SIZE); 305 ASSERT(pte && PTE_VALID(pte) && PTE_PRESENT(pte)); 306 btree_insert(&area->sh_info->pagemap, (base + j*PAGE_SIZE) - area->base, 325 pte = page_mapping_find(area->as, 326 base + j * PAGE_SIZE); 327 ASSERT(pte && PTE_VALID(pte) && 328 PTE_PRESENT(pte)); 329 btree_insert(&area->sh_info->pagemap, 330 (base + j * PAGE_SIZE) - area->base, 307 331 (void *) PTE_GET_FRAME(pte), NULL); 308 332 page_table_unlock(area->as, false); 309 frame_reference_add(ADDR2PFN(PTE_GET_FRAME(pte))); 333 334 pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(pte)); 335 frame_reference_add(pfn); 310 336 } 311 337 … … 317 343 /** @} 318 344 */ 345 -
kernel/generic/src/mm/backend_phys.c
r0f6a3376 rd5bd8d7 33 33 /** 34 34 * @file 35 * @brief Backend for address space areas backed by continuous physical memory. 35 * @brief Backend for address space areas backed by continuous physical 36 * memory. 36 37 */ 37 38 … … 63 64 * @param access Access mode that caused the fault (i.e. read/write/exec). 64 65 * 65 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. serviced). 66 * @return AS_PF_FAULT on failure (i.e. page fault) or AS_PF_OK on success (i.e. 67 * serviced). 66 68 */ 67 69 int phys_page_fault(as_area_t *area, uintptr_t addr, pf_access_t access) … … 73 75 74 76 ASSERT(addr - area->base < area->backend_data.frames * FRAME_SIZE); 75 page_mapping_insert(AS, addr, base + (addr - area->base), as_area_get_flags(area)); 77 page_mapping_insert(AS, addr, base + (addr - area->base), 78 as_area_get_flags(area)); 76 79 if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1)) 77 80 panic("Could not insert used space.\n");
Note:
See TracChangeset
for help on using the changeset viewer.