Rev 4419 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4419 | Rev 4668 | ||
---|---|---|---|
Line 72... | Line 72... | ||
72 | static int segment_header(elf_ld_t *elf, elf_segment_header_t *entry); |
72 | static int segment_header(elf_ld_t *elf, elf_segment_header_t *entry); |
73 | static int section_header(elf_ld_t *elf, elf_section_header_t *entry); |
73 | static int section_header(elf_ld_t *elf, elf_section_header_t *entry); |
74 | static int load_segment(elf_ld_t *elf, elf_segment_header_t *entry); |
74 | static int load_segment(elf_ld_t *elf, elf_segment_header_t *entry); |
75 | 75 | ||
76 | /** Read until the buffer is read in its entirety. */ |
76 | /** Read until the buffer is read in its entirety. */ |
77 | static int my_read(int fd, char *buf, size_t len) |
77 | static int my_read(int fd, void *buf, size_t len) |
78 | { |
78 | { |
79 | int cnt = 0; |
79 | int cnt = 0; |
80 | do { |
80 | do { |
81 | buf += cnt; |
81 | buf += cnt; |
82 | len -= cnt; |
82 | len -= cnt; |
Line 329... | Line 329... | ||
329 | { |
329 | { |
330 | void *a; |
330 | void *a; |
331 | int flags = 0; |
331 | int flags = 0; |
332 | uintptr_t bias; |
332 | uintptr_t bias; |
333 | uintptr_t base; |
333 | uintptr_t base; |
- | 334 | void *seg_ptr; |
|
- | 335 | uintptr_t seg_addr; |
|
334 | size_t mem_sz; |
336 | size_t mem_sz; |
335 | int rc; |
337 | int rc; |
336 | 338 | ||
337 | DPRINTF("Load segment at addr 0x%x, size 0x%x\n", entry->p_vaddr, |
- | |
338 | entry->p_memsz); |
- | |
339 | - | ||
340 | bias = elf->bias; |
339 | bias = elf->bias; |
341 | 340 | ||
- | 341 | seg_addr = entry->p_vaddr + bias; |
|
- | 342 | seg_ptr = (void *) seg_addr; |
|
- | 343 | ||
- | 344 | DPRINTF("Load segment at addr 0x%x, size 0x%x\n", seg_addr, |
|
- | 345 | entry->p_memsz); |
|
- | 346 | ||
342 | if (entry->p_align > 1) { |
347 | if (entry->p_align > 1) { |
343 | if ((entry->p_offset % entry->p_align) != |
348 | if ((entry->p_offset % entry->p_align) != |
344 | (entry->p_vaddr % entry->p_align)) { |
349 | (seg_addr % entry->p_align)) { |
345 | DPRINTF("Align check 1 failed offset%%align=%d, " |
350 | DPRINTF("Align check 1 failed offset%%align=%d, " |
346 | "vaddr%%align=%d\n", |
351 | "vaddr%%align=%d\n", |
347 | entry->p_offset % entry->p_align, |
352 | entry->p_offset % entry->p_align, |
348 | entry->p_vaddr % entry->p_align |
353 | seg_addr % entry->p_align |
349 | ); |
354 | ); |
350 | return EE_INVALID; |
355 | return EE_INVALID; |
351 | } |
356 | } |
352 | } |
357 | } |
353 | 358 | ||
Line 362... | Line 367... | ||
362 | flags |= AS_AREA_CACHEABLE; |
367 | flags |= AS_AREA_CACHEABLE; |
363 | 368 | ||
364 | base = ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE); |
369 | base = ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE); |
365 | mem_sz = entry->p_memsz + (entry->p_vaddr - base); |
370 | mem_sz = entry->p_memsz + (entry->p_vaddr - base); |
366 | 371 | ||
367 | DPRINTF("Map to p_vaddr=0x%x-0x%x.\n", entry->p_vaddr + bias, |
372 | DPRINTF("Map to seg_addr=0x%x-0x%x.\n", seg_addr, |
368 | entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE)); |
373 | entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE)); |
369 | 374 | ||
370 | /* |
375 | /* |
371 | * For the course of loading, the area needs to be readable |
376 | * For the course of loading, the area needs to be readable |
372 | * and writeable. |
377 | * and writeable. |
Line 377... | Line 382... | ||
377 | DPRINTF("Memory mapping failed.\n"); |
382 | DPRINTF("Memory mapping failed.\n"); |
378 | return EE_MEMORY; |
383 | return EE_MEMORY; |
379 | } |
384 | } |
380 | 385 | ||
381 | DPRINTF("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n", |
386 | DPRINTF("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n", |
382 | entry->p_vaddr+bias, entry->p_memsz, flags, (uintptr_t)a); |
387 | base + bias, mem_sz, flags, (uintptr_t)a); |
383 | 388 | ||
384 | /* |
389 | /* |
385 | * Load segment data |
390 | * Load segment data |
386 | */ |
391 | */ |
387 | rc = lseek(elf->fd, entry->p_offset, SEEK_SET); |
392 | rc = lseek(elf->fd, entry->p_offset, SEEK_SET); |
Line 397... | Line 402... | ||
397 | 402 | ||
398 | unsigned left, now; |
403 | unsigned left, now; |
399 | uint8_t *dp; |
404 | uint8_t *dp; |
400 | 405 | ||
401 | left = entry->p_filesz; |
406 | left = entry->p_filesz; |
402 | dp = (uint8_t *)(entry->p_vaddr + bias); |
407 | dp = seg_ptr; |
403 | 408 | ||
404 | while (left > 0) { |
409 | while (left > 0) { |
405 | now = 16384; |
410 | now = 16384; |
406 | if (now > left) now = left; |
411 | if (now > left) now = left; |
407 | 412 | ||
Line 414... | Line 419... | ||
414 | 419 | ||
415 | left -= now; |
420 | left -= now; |
416 | dp += now; |
421 | dp += now; |
417 | } |
422 | } |
418 | 423 | ||
419 | rc = as_area_change_flags((uint8_t *)entry->p_vaddr + bias, flags); |
424 | rc = as_area_change_flags(seg_ptr, flags); |
420 | if (rc != 0) { |
425 | if (rc != 0) { |
421 | DPRINTF("Failed to set memory area flags.\n"); |
426 | DPRINTF("Failed to set memory area flags.\n"); |
422 | return EE_MEMORY; |
427 | return EE_MEMORY; |
423 | } |
428 | } |
424 | 429 | ||
425 | if (flags & AS_AREA_EXEC) { |
430 | if (flags & AS_AREA_EXEC) { |
426 | /* Enforce SMC coherence for the segment */ |
431 | /* Enforce SMC coherence for the segment */ |
427 | if (smc_coherence(entry->p_vaddr + bias, entry->p_filesz)) |
432 | if (smc_coherence(seg_ptr, entry->p_filesz)) |
428 | return EE_MEMORY; |
433 | return EE_MEMORY; |
429 | } |
434 | } |
430 | 435 | ||
431 | return EE_OK; |
436 | return EE_OK; |
432 | } |
437 | } |