44,6 → 44,7 |
#include <as.h> |
#include "elf.h" |
|
#define RTLD_BIAS 0x80000 |
|
static char *error_codes[] = { |
"no error", |
106,7 → 107,7 |
printf("Object type %d is not supported\n", header->e_type); |
return EE_UNSUPPORTED; |
} |
if (header->e_type == ET_DYN) header->e_entry += 0x40000; |
if (header->e_type == ET_DYN) header->e_entry += RTLD_BIAS; |
|
printf("parse segments\n"); |
|
200,14 → 201,13 |
{ |
void *a; |
int flags = 0; |
uintptr_t load_displ; |
uintptr_t bias; |
int rc; |
|
printf("load segment at addr 0x%x, size 0x%x\n", entry->p_vaddr, |
entry->p_memsz); |
|
/*if (elf->e_type == ET_DYN) load_displ = 0x40000; |
else*/ load_displ = 0; |
bias = (elf->e_type == ET_DYN) ? RTLD_BIAS : 0; |
|
if (entry->p_align > 1) { |
if ((entry->p_offset % entry->p_align) != |
241,10 → 241,10 |
return EE_UNSUPPORTED; |
} |
|
printf("map to p_vaddr=0x%x-0x%x...\n", entry->p_vaddr + load_displ, |
entry->p_vaddr + load_displ + ALIGN_UP(entry->p_memsz, PAGE_SIZE)); |
printf("map to p_vaddr=0x%x-0x%x...\n", entry->p_vaddr + bias, |
entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE)); |
|
a = as_area_create((uint8_t *)entry->p_vaddr + load_displ, |
a = as_area_create((uint8_t *)entry->p_vaddr + bias, |
entry->p_memsz, flags); |
if (a == (void *)(-1)) { |
printf("memory mapping failed\n"); |
259,7 → 259,7 |
rc = lseek(fd, entry->p_offset, SEEK_SET); |
if (rc < 0) { printf("seek error\n"); return EE_INVALID; } |
|
rc = read(fd, (void *)entry->p_vaddr, entry->p_filesz); |
rc = read(fd, (void *)(entry->p_vaddr + bias), entry->p_filesz); |
if (rc < 0) { printf("read error\n"); return EE_INVALID; } |
|
return EE_OK; |