Changeset 1cc2974 in mainline
- Timestamp:
- 2008-05-26T18:56:34Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5a55ae6
- Parents:
- fa832eb
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/lib/elf.c
rfa832eb r1cc2974 101 101 return EE_UNSUPPORTED; 102 102 103 /* Check if the ELF image starts on a page boundary */ 104 if (ALIGN_UP((uintptr_t)header, PAGE_SIZE) != (uintptr_t)header) 105 return EE_UNSUPPORTED; 106 103 107 /* Walk through all segment headers and process them. */ 104 108 for (i = 0; i < header->e_phnum; i++) { … … 183 187 int flags = 0; 184 188 mem_backend_data_t backend_data; 189 uintptr_t base; 190 size_t mem_sz; 185 191 186 192 backend_data.elf = elf; … … 202 208 flags |= AS_AREA_CACHEABLE; 203 209 204 /* 205 * Check if the virtual address starts on page boundary. 210 /* 211 * Align vaddr down, inserting a little "gap" at the beginning. 212 * Adjust area size, so that its end remains in place. 206 213 */ 207 if (ALIGN_UP(entry->p_vaddr, PAGE_SIZE) != entry->p_vaddr)208 return EE_UNSUPPORTED;209 210 a = as_area_create(as, flags, entry->p_memsz, entry->p_vaddr,214 base = ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE); 215 mem_sz = entry->p_memsz + (entry->p_vaddr - base); 216 217 a = as_area_create(as, flags, mem_sz, base, 211 218 AS_AREA_ATTR_NONE, &elf_backend, &backend_data); 212 219 if (!a) -
kernel/generic/src/mm/backend_elf.c
rfa832eb r1cc2974 80 80 elf_segment_header_t *entry = area->backend_data.segment; 81 81 btree_node_t *leaf; 82 uintptr_t base, frame ;82 uintptr_t base, frame, page, start_anon; 83 83 index_t i; 84 84 bool dirty = false; … … 87 87 return AS_PF_FAULT; 88 88 89 ASSERT((addr >= entry->p_vaddr) &&89 ASSERT((addr >= ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE)) && 90 90 (addr < entry->p_vaddr + entry->p_memsz)); 91 i = (addr - entry->p_vaddr) >> PAGE_WIDTH; 92 base = (uintptr_t) (((void *) elf) + entry->p_offset); 93 ASSERT(ALIGN_UP(base, FRAME_SIZE) == base); 91 i = (addr - ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE)) >> PAGE_WIDTH; 92 base = (uintptr_t) 93 (((void *) elf) + ALIGN_DOWN(entry->p_offset, PAGE_SIZE)); 94 95 /* Virtual address of faulting page*/ 96 page = ALIGN_DOWN(addr, PAGE_SIZE); 97 98 /* Virtual address of the end of initialized part of segment */ 99 start_anon = entry->p_vaddr + entry->p_filesz; 94 100 95 101 if (area->sh_info) { … … 99 105 * The address space area is shared. 100 106 */ 101 107 102 108 mutex_lock(&area->sh_info->lock); 103 109 frame = (uintptr_t) btree_search(&area->sh_info->pagemap, 104 ALIGN_DOWN(addr, PAGE_SIZE)- area->base, &leaf);110 page - area->base, &leaf); 105 111 if (!frame) { 106 112 unsigned int i; … … 111 117 112 118 for (i = 0; i < leaf->keys; i++) { 113 if (leaf->key[i] == 114 ALIGN_DOWN(addr, PAGE_SIZE)) { 119 if (leaf->key[i] == page) { 115 120 found = true; 116 121 break; … … 122 127 page_mapping_insert(AS, addr, frame, 123 128 as_area_get_flags(area)); 124 if (!used_space_insert(area, 125 ALIGN_DOWN(addr, PAGE_SIZE), 1)) 129 if (!used_space_insert(area, page, 1)) 126 130 panic("Could not insert used space.\n"); 127 131 mutex_unlock(&area->sh_info->lock); … … 129 133 } 130 134 } 131 135 132 136 /* 133 137 * The area is either not shared or the pagemap does not contain the 134 138 * mapping. 135 139 */ 136 137 if (ALIGN_DOWN(addr, PAGE_SIZE) + PAGE_SIZE < 138 entry->p_vaddr + entry->p_filesz) { 140 if (page >= entry->p_vaddr && page + PAGE_SIZE <= start_anon) { 139 141 /* 140 142 * Initialized portion of the segment. The memory is backed … … 150 152 (void *) (base + i * FRAME_SIZE), FRAME_SIZE); 151 153 dirty = true; 152 153 if (area->sh_info) {154 frame_reference_add(ADDR2PFN(frame));155 btree_insert(&area->sh_info->pagemap,156 ALIGN_DOWN(addr, PAGE_SIZE) - area->base,157 (void *) frame, leaf);158 }159 160 154 } else { 161 frame = KA2PA(base + i *FRAME_SIZE);155 frame = KA2PA(base + i * FRAME_SIZE); 162 156 } 163 } else if (ALIGN_DOWN(addr, PAGE_SIZE) >= 164 ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) { 157 } else if (page >= start_anon) { 165 158 /* 166 159 * This is the uninitialized portion of the segment. … … 172 165 memsetb(PA2KA(frame), FRAME_SIZE, 0); 173 166 dirty = true; 174 175 if (area->sh_info) {176 frame_reference_add(ADDR2PFN(frame));177 btree_insert(&area->sh_info->pagemap,178 ALIGN_DOWN(addr, PAGE_SIZE) - area->base,179 (void *) frame, leaf);180 }181 182 167 } else { 183 size_t size;168 size_t pad_lo, pad_hi; 184 169 /* 185 170 * The mixed case. 186 * The lower part is backed by the ELF image and 187 * the upper part is anonymous memory. 171 * 172 * The middle part is backed by the ELF image and 173 * the lower and upper parts are anonymous memory. 174 * (The segment can be and often is shorter than 1 page). 188 175 */ 189 size = entry->p_filesz - (i<<PAGE_WIDTH); 176 if (page < entry->p_vaddr) 177 pad_lo = entry->p_vaddr - page; 178 else 179 pad_lo = 0; 180 181 if (start_anon < page + PAGE_SIZE) 182 pad_hi = page + PAGE_SIZE - start_anon; 183 else 184 pad_hi = 0; 185 190 186 frame = (uintptr_t)frame_alloc(ONE_FRAME, 0); 191 memsetb(PA2KA(frame) + size, FRAME_SIZE - size, 0); 192 memcpy((void *) PA2KA(frame), (void *) (base + i * FRAME_SIZE), 193 size); 187 memcpy((void *) (PA2KA(frame) + pad_lo), 188 (void *) (base + i * FRAME_SIZE + pad_lo), 189 FRAME_SIZE - pad_lo - pad_hi); 190 memsetb(PA2KA(frame), pad_lo, 0); 191 memsetb(PA2KA(frame) + FRAME_SIZE - pad_hi, pad_hi, 0); 194 192 dirty = true; 195 196 if (area->sh_info) { 197 frame_reference_add(ADDR2PFN(frame)); 198 btree_insert(&area->sh_info->pagemap, 199 ALIGN_DOWN(addr, PAGE_SIZE) - area->base, 200 (void *) frame, leaf); 201 } 202 203 } 204 193 } 194 195 if (dirty && area->sh_info) { 196 frame_reference_add(ADDR2PFN(frame)); 197 btree_insert(&area->sh_info->pagemap, page - area->base, 198 (void *) frame, leaf); 199 } 200 205 201 if (area->sh_info) 206 202 mutex_unlock(&area->sh_info->lock); 207 203 208 204 page_mapping_insert(AS, addr, frame, as_area_get_flags(area)); 209 if (!used_space_insert(area, ALIGN_DOWN(addr, PAGE_SIZE), 1))205 if (!used_space_insert(area, page, 1)) 210 206 panic("Could not insert used space.\n"); 211 207 … … 226 222 elf_header_t *elf = area->backend_data.elf; 227 223 elf_segment_header_t *entry = area->backend_data.segment; 228 uintptr_t base ;224 uintptr_t base, start_anon; 229 225 index_t i; 230 231 ASSERT((page >= entry->p_vaddr) &&226 227 ASSERT((page >= ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE)) && 232 228 (page < entry->p_vaddr + entry->p_memsz)); 233 i = (page - entry->p_vaddr) >> PAGE_WIDTH;234 base = (uintptr_t) (((void *) elf) + entry->p_offset);235 ASSERT(ALIGN_UP(base, FRAME_SIZE) == base);236 237 if (page + PAGE_SIZE < 238 ALIGN_UP(entry->p_vaddr + entry->p_filesz, PAGE_SIZE)) {229 i = (page - ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE)) >> PAGE_WIDTH; 230 base = (uintptr_t) (((void *) elf) + 231 ALIGN_DOWN(entry->p_offset, FRAME_SIZE)); 232 start_anon = entry->p_vaddr + entry->p_filesz; 233 234 if (page >= entry->p_vaddr && page + PAGE_SIZE <= start_anon) { 239 235 if (entry->p_flags & PF_W) { 240 236 /* … … 305 301 */ 306 302 if (!(area->flags & AS_AREA_WRITE)) 307 if (base + count * PAGE_SIZE <= start_anon) 303 if (base >= entry->p_vaddr && 304 base + count * PAGE_SIZE <= start_anon) 308 305 continue; 309 306 … … 316 313 */ 317 314 if (!(area->flags & AS_AREA_WRITE)) 318 if (base + (j + 1) * PAGE_SIZE <= 315 if (base >= entry->p_vaddr && 316 base + (j + 1) * PAGE_SIZE <= 319 317 start_anon) 320 318 continue; -
uspace/lib/libc/arch/amd64/_link.ld.in
rfa832eb r1cc2974 8 8 9 9 SECTIONS { 10 . = 0x1000 ;10 . = 0x1000 + SIZEOF_HEADERS; 11 11 12 .init ALIGN(0x1000) : SUBALIGN(0x1000){12 .init : { 13 13 *(.init); 14 14 } :text … … 17 17 *(.rodata*); 18 18 } :text 19 20 .data ALIGN(0x1000) : SUBALIGN(0x1000) { 19 20 . = . + 0x1000; 21 22 .data : { 21 23 *(.data); 22 24 } :data -
uspace/lib/libc/arch/arm32/_link.ld.in
rfa832eb r1cc2974 8 8 9 9 SECTIONS { 10 . = 0x1000 ;10 . = 0x1000 + SIZEOF_HEADERS; 11 11 12 .init ALIGN(0x1000): SUBALIGN(0x1000){12 .init : { 13 13 *(.init); 14 14 } : text … … 17 17 *(.rodata*); 18 18 } :text 19 20 .data ALIGN(0x1000) : SUBALIGN(0x1000) { 19 20 . = . + 0x1000; 21 22 .data : { 21 23 *(.opd); 22 24 *(.data .data.*); -
uspace/lib/libc/arch/ia32/_link.ld.in
rfa832eb r1cc2974 8 8 9 9 SECTIONS { 10 . = 0x1000 ;10 . = 0x1000 + SIZEOF_HEADERS; 11 11 12 .init ALIGN(0x1000) : SUBALIGN(0x1000){12 .init : { 13 13 *(.init); 14 14 } :text … … 17 17 *(.rodata*); 18 18 } :text 19 20 .data ALIGN(0x1000) : SUBALIGN(0x1000) { 19 20 . = . + 0x1000; 21 22 .data : { 21 23 *(.data); 22 24 } :data -
uspace/lib/libc/arch/ia64/_link.ld.in
rfa832eb r1cc2974 8 8 9 9 SECTIONS { 10 . = 0x4000 ;10 . = 0x4000 + SIZEOF_HEADERS; 11 11 12 .init ALIGN(0x4000): SUBALIGN(0x4000){12 .init : { 13 13 *(.init); 14 14 } : text … … 18 18 } :text 19 19 20 .got ALIGN(0x4000) : SUBALIGN(0x4000) { 20 . = . + 0x4000; 21 22 .got : { 21 23 _gp = .; 22 24 *(.got*); -
uspace/lib/libc/arch/mips32/_link.ld.in
rfa832eb r1cc2974 8 8 9 9 SECTIONS { 10 . = 0x4000 ;10 . = 0x4000 + SIZEOF_HEADERS; 11 11 12 .init ALIGN(0x4000) : SUBALIGN(0x4000){12 .init : { 13 13 *(.init); 14 14 } :text … … 17 17 *(.rodata*); 18 18 } :text 19 20 . = . + 0x4000; 19 21 20 22 .data : { -
uspace/lib/libc/arch/ppc32/_link.ld.in
rfa832eb r1cc2974 8 8 9 9 SECTIONS { 10 . = 0x1000 ;10 . = 0x1000 + SIZEOF_HEADERS; 11 11 12 .init ALIGN(0x1000) : SUBALIGN(0x1000){12 .init : { 13 13 *(.init); 14 14 } :text … … 17 17 *(.rodata*); 18 18 } :text 19 20 .data ALIGN(0x1000) : SUBALIGN(0x1000) { 19 20 . = . + 0x1000; 21 22 .data : { 21 23 *(.data); 22 24 *(.sdata); -
uspace/lib/libc/arch/ppc64/_link.ld.in
rfa832eb r1cc2974 8 8 9 9 SECTIONS { 10 . = 0x1000 ;10 . = 0x1000 + SIZEOF_HEADERS; 11 11 12 .init ALIGN(0x1000) : SUBALIGN(0x1000){12 .init : { 13 13 *(.init); 14 14 } :text … … 18 18 *(.rodata*); 19 19 } :text 20 21 .data ALIGN(0x1000) : SUBALIGN(0x1000) { 20 21 . = . + 0x1000; 22 23 .data : { 22 24 *(.opd); 23 25 *(.data*); -
uspace/lib/libc/arch/sparc64/_link.ld.in
rfa832eb r1cc2974 8 8 9 9 SECTIONS { 10 . = 0x4000 ;10 . = 0x4000 + SIZEOF_HEADERS; 11 11 12 .init ALIGN(0x4000) : SUBALIGN(0x4000){12 .init : { 13 13 *(.init); 14 14 } :text … … 17 17 *(.rodata*); 18 18 } :text 19 20 .got ALIGN(0x4000) : SUBALIGN(0x4000) { 19 20 . = . + 0x4000; 21 22 .got : { 21 23 _gp = .; 22 24 *(.got*); 23 25 } :data 24 .data ALIGN(0x4000) : SUBALIGN(0x4000){26 .data : { 25 27 *(.data); 26 28 *(.sdata);
Note:
See TracChangeset
for help on using the changeset viewer.