Changes in kernel/generic/src/mm/backend_elf.c [d91488d:2fc3b2d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/backend_elf.c
rd91488d r2fc3b2d 153 153 { 154 154 elf_segment_header_t *entry = area->backend_data.segment; 155 link_t *cur;156 btree_node_t *leaf, *node;155 used_space_ival_t *start; 156 used_space_ival_t *cur; 157 157 uintptr_t start_anon = entry->p_vaddr + entry->p_filesz; 158 158 … … 164 164 */ 165 165 if (area->flags & AS_AREA_WRITE) { 166 node = list_get_instance(list_first(&area->used_space.leaf_list), 167 btree_node_t, leaf_link); 166 start = used_space_first(&area->used_space); 168 167 } else { 169 (void) btree_search(&area->used_space, start_anon, &leaf); 170 node = btree_leaf_node_left_neighbour(&area->used_space, leaf); 171 if (!node) 172 node = leaf; 168 /* Find first interval containing addresses >= start_anon */ 169 start = used_space_find_gteq(&area->used_space, start_anon); 173 170 } 174 171 … … 177 174 */ 178 175 mutex_lock(&area->sh_info->lock); 179 for (cur = &node->leaf_link; cur != &area->used_space.leaf_list.head; 180 cur = cur->next) { 176 cur = start; 177 while (cur != NULL) { 178 uintptr_t base = cur->page; 179 size_t count = cur->count; 181 180 unsigned int i; 182 181 183 node = list_get_instance(cur, btree_node_t, leaf_link); 184 185 for (i = 0; i < node->keys; i++) { 186 uintptr_t base = node->key[i]; 187 size_t count = (size_t) node->value[i]; 188 unsigned int j; 182 /* 183 * Skip read-only areas of used space that are backed 184 * by the ELF image. 185 */ 186 if (!(area->flags & AS_AREA_WRITE)) 187 if (base >= entry->p_vaddr && 188 base + P2SZ(count) <= start_anon) 189 continue; 190 191 for (i = 0; i < count; i++) { 192 pte_t pte; 193 bool found; 189 194 190 195 /* 191 * Skip read-only areas of used space that are backed192 * by theELF image.196 * Skip read-only pages that are backed by the 197 * ELF image. 193 198 */ 194 199 if (!(area->flags & AS_AREA_WRITE)) 195 200 if (base >= entry->p_vaddr && 196 base + P2SZ( count) <= start_anon)201 base + P2SZ(i + 1) <= start_anon) 197 202 continue; 198 203 199 for (j = 0; j < count; j++) { 200 pte_t pte; 201 bool found; 202 203 /* 204 * Skip read-only pages that are backed by the 205 * ELF image. 206 */ 207 if (!(area->flags & AS_AREA_WRITE)) 208 if (base >= entry->p_vaddr && 209 base + P2SZ(j + 1) <= start_anon) 210 continue; 211 212 page_table_lock(area->as, false); 213 found = page_mapping_find(area->as, 214 base + P2SZ(j), false, &pte); 215 216 (void) found; 217 assert(found); 218 assert(PTE_VALID(&pte)); 219 assert(PTE_PRESENT(&pte)); 220 221 btree_insert(&area->sh_info->pagemap, 222 (base + P2SZ(j)) - area->base, 223 (void *) PTE_GET_FRAME(&pte), NULL); 224 page_table_unlock(area->as, false); 225 226 pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(&pte)); 227 frame_reference_add(pfn); 228 } 229 204 page_table_lock(area->as, false); 205 found = page_mapping_find(area->as, 206 base + P2SZ(i), false, &pte); 207 208 (void) found; 209 assert(found); 210 assert(PTE_VALID(&pte)); 211 assert(PTE_PRESENT(&pte)); 212 213 as_pagemap_insert(&area->sh_info->pagemap, 214 (base + P2SZ(i)) - area->base, 215 PTE_GET_FRAME(&pte)); 216 page_table_unlock(area->as, false); 217 218 pfn_t pfn = ADDR2PFN(PTE_GET_FRAME(&pte)); 219 frame_reference_add(pfn); 230 220 } 231 } 221 222 cur = used_space_next(cur); 223 } 224 232 225 mutex_unlock(&area->sh_info->lock); 233 226 } … … 267 260 elf_header_t *elf = area->backend_data.elf; 268 261 elf_segment_header_t *entry = area->backend_data.segment; 269 btree_node_t *leaf;270 262 uintptr_t base; 271 263 uintptr_t frame; … … 301 293 mutex_lock(&area->sh_info->lock); 302 294 if (area->sh_info->shared) { 303 bool found = false;304 305 295 /* 306 296 * The address space area is shared. 307 297 */ 308 298 309 frame = (uintptr_t) btree_search(&area->sh_info->pagemap, 310 upage - area->base, &leaf); 311 if (!frame) { 312 unsigned int i; 313 314 /* 315 * Workaround for valid NULL address. 316 */ 317 318 for (i = 0; i < leaf->keys; i++) { 319 if (leaf->key[i] == upage - area->base) { 320 found = true; 321 break; 322 } 323 } 324 } 325 if (frame || found) { 299 errno_t rc = as_pagemap_find(&area->sh_info->pagemap, 300 upage - area->base, &frame); 301 if (rc == EOK) { 326 302 frame_reference_add(ADDR2PFN(frame)); 327 303 page_mapping_insert(AS, upage, frame, 328 304 as_area_get_flags(area)); 329 if (!used_space_insert( area, upage, 1))305 if (!used_space_insert(&area->used_space, upage, 1)) 330 306 panic("Cannot insert used space."); 331 307 mutex_unlock(&area->sh_info->lock); … … 415 391 if (dirty && area->sh_info->shared) { 416 392 frame_reference_add(ADDR2PFN(frame)); 417 btree_insert(&area->sh_info->pagemap, upage - area->base,418 (void *) frame, leaf);393 as_pagemap_insert(&area->sh_info->pagemap, upage - area->base, 394 frame); 419 395 } 420 396 … … 422 398 423 399 page_mapping_insert(AS, upage, frame, as_area_get_flags(area)); 424 if (!used_space_insert( area, upage, 1))400 if (!used_space_insert(&area->used_space, upage, 1)) 425 401 panic("Cannot insert used space."); 426 402
Note:
See TracChangeset
for help on using the changeset viewer.