Subversion Repositories HelenOS

Compare Revisions

No changes between revisions

Ignore whitespace Rev 3773 → Rev 4338

/branches/dynload/uspace/srv/loader/main.c
59,6 → 59,8
#include <elf.h>
#include <elf_load.h>
 
#define DPRINTF(...)
 
void program_run(void *entry, pcb_t *pcb);
 
/** Pathname of the file that will be loaded */
227,7 → 229,7
 
rc = elf_load_file(pathname, 0, 0, &prog_info);
if (rc < 0) {
printf("Failed to load executable '%s'.\n", pathname);
DPRINTF("Failed to load executable '%s'.\n", pathname);
ipc_answer_0(rid, EINVAL);
return 1;
}
247,7 → 249,8
printf("Load ELF interpreter '%s'\n", prog_info.interp);
rc = elf_load_file(prog_info.interp, 0, 0, &interp_info);
if (rc < 0) {
printf("Failed to load interpreter '%s.'\n", prog_info.interp);
DPRINTF("Failed to load interpreter '%s.'\n",
prog_info.interp);
ipc_answer_0(rid, EINVAL);
return 1;
}
274,8 → 277,8
{
if (is_dyn_linked == true) {
/* Dynamically linked program */
printf("run dynamic linker\n");
printf("entry point: 0x%lx\n", interp_info.entry);
DPRINTF("Run ELF interpreter.\n");
DPRINTF("Entry point: 0x%lx\n", interp_info.entry);
close_console();
 
ipc_answer_0(rid, EOK);
332,7 → 335,7
}
if ((callid & IPC_CALLID_NOTIFICATION) == 0 &&
IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) {
printf("responding EINVAL to method %d\n",
DPRINTF("Responding EINVAL to method %d.\n",
IPC_GET_METHOD(call));
ipc_answer_0(callid, EINVAL);
}
/branches/dynload/uspace/srv/loader/elf_load.c
57,6 → 57,8
#include "elf_load.h"
#include "arch.h"
 
#define DPRINTF(...)
 
static char *error_codes[] = {
"no error",
"invalid image",
107,11 → 109,9
int fd;
int rc;
 
// printf("open and read '%s'...\n", file_name);
 
fd = open(file_name, O_RDONLY);
if (fd < 0) {
printf("failed opening file (error %d)\n", fd);
DPRINTF("failed opening file\n");
return -1;
}
 
160,19 → 160,18
 
rc = my_read(elf->fd, header, sizeof(elf_header_t));
if (rc < 0) {
printf("read error\n");
DPRINTF("Read error.\n");
return EE_INVALID;
}
 
elf->header = header;
 
// printf("ELF-load:");
/* Identify ELF */
if (header->e_ident[EI_MAG0] != ELFMAG0 ||
header->e_ident[EI_MAG1] != ELFMAG1 ||
header->e_ident[EI_MAG2] != ELFMAG2 ||
header->e_ident[EI_MAG3] != ELFMAG3) {
printf("invalid header\n");
DPRINTF("Invalid header.\n");
return EE_INVALID;
}
182,18 → 181,18
header->e_ident[EI_VERSION] != EV_CURRENT ||
header->e_version != EV_CURRENT ||
header->e_ident[EI_CLASS] != ELF_CLASS) {
printf("incompatible data/version/class\n");
DPRINTF("Incompatible data/version/class.\n");
return EE_INCOMPATIBLE;
}
 
if (header->e_phentsize != sizeof(elf_segment_header_t)) {
printf("e_phentsize:%d != %d\n", header->e_phentsize,
DPRINTF("e_phentsize:%d != %d\n", header->e_phentsize,
sizeof(elf_segment_header_t));
return EE_INCOMPATIBLE;
}
 
if (header->e_shentsize != sizeof(elf_section_header_t)) {
printf("e_shentsize:%d != %d\n", header->e_shentsize,
DPRINTF("e_shentsize:%d != %d\n", header->e_shentsize,
sizeof(elf_section_header_t));
return EE_INCOMPATIBLE;
}
200,23 → 199,19
 
/* Check if the object type is supported. */
if (header->e_type != ET_EXEC && header->e_type != ET_DYN) {
printf("Object type %d is not supported\n", header->e_type);
DPRINTF("Object type %d is not supported\n", header->e_type);
return EE_UNSUPPORTED;
}
 
/* Shared objects can be loaded with a bias */
// printf("Object type: %d\n", header->e_type);
if (header->e_type == ET_DYN)
elf->bias = so_bias;
else
elf->bias = 0;
 
// printf("Bias set to 0x%x\n", elf->bias);
elf->info->interp = NULL;
elf->info->dynamic = NULL;
 
// printf("parse segments\n");
 
/* Walk through all segment headers and process them. */
for (i = 0; i < header->e_phnum; i++) {
elf_segment_header_t segment_hdr;
228,7 → 223,7
rc = my_read(elf->fd, &segment_hdr,
sizeof(elf_segment_header_t));
if (rc < 0) {
printf("read error\n");
DPRINTF("Read error.\n");
return EE_INVALID;
}
 
237,7 → 232,7
return rc;
}
 
// printf("parse sections\n");
DPRINTF("Parse sections.\n");
 
/* Inspect all section headers and proccess them. */
for (i = 0; i < header->e_shnum; i++) {
250,7 → 245,7
rc = my_read(elf->fd, &section_hdr,
sizeof(elf_section_header_t));
if (rc < 0) {
printf("read error\n");
DPRINTF("Read error.\n");
return EE_INVALID;
}
 
262,7 → 257,7
elf->info->entry =
(entry_point_t)((uint8_t *)header->e_entry + elf->bias);
 
// printf("done\n");
DPRINTF("Done.\n");
 
return EE_OK;
}
303,7 → 298,7
/* Record pointer to dynamic section into info structure */
elf->info->dynamic =
(void *)((uint8_t *)entry->p_vaddr + elf->bias);
printf("dynamic section found at 0x%x\n",
DPRINTF("dynamic section found at 0x%x\n",
(uintptr_t)elf->info->dynamic);
break;
case 0x70000000:
314,7 → 309,7
// case PT_LOPROC:
// case PT_HIPROC:
default:
printf("segment p_type %d unknown\n", entry->p_type);
DPRINTF("Segment p_type %d unknown.\n", entry->p_type);
return EE_UNSUPPORTED;
break;
}
337,8 → 332,8
size_t mem_sz;
int rc;
 
// printf("load segment at addr 0x%x, size 0x%x\n", entry->p_vaddr,
// entry->p_memsz);
DPRINTF("Load segment at addr 0x%x, size 0x%x\n", entry->p_vaddr,
entry->p_memsz);
bias = elf->bias;
 
345,7 → 340,7
if (entry->p_align > 1) {
if ((entry->p_offset % entry->p_align) !=
(entry->p_vaddr % entry->p_align)) {
printf("align check 1 failed offset%%align=%d, "
DPRINTF("Align check 1 failed offset%%align=%d, "
"vaddr%%align=%d\n",
entry->p_offset % entry->p_align,
entry->p_vaddr % entry->p_align
367,8 → 362,8
base = ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE);
mem_sz = entry->p_memsz + (entry->p_vaddr - base);
 
// 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));
DPRINTF("Map to p_vaddr=0x%x-0x%x.\n", entry->p_vaddr + bias,
entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE));
 
/*
* For the course of loading, the area needs to be readable
377,18 → 372,17
a = as_area_create((uint8_t *)base + bias, mem_sz,
AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
if (a == (void *)(-1)) {
printf("memory mapping failed (0x%x, %d)\n",
DPRINTF("memory mapping failed (0x%x, %d)\n",
base+bias, mem_sz);
return EE_MEMORY;
}
 
// printf("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n",
// entry->p_vaddr+bias, entry->p_memsz, flags, (uintptr_t)a);
DPRINTF("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n",
entry->p_vaddr+bias, entry->p_memsz, flags, (uintptr_t)a);
 
/*
* Load segment data
*/
// printf("seek to %d\n", entry->p_offset);
rc = lseek(elf->fd, entry->p_offset, SEEK_SET);
if (rc < 0) {
printf("seek error\n");
395,11 → 389,10
return EE_INVALID;
}
 
// printf("read 0x%x bytes to address 0x%x\n", entry->p_filesz, entry->p_vaddr+bias);
/* rc = read(fd, (void *)(entry->p_vaddr + bias), entry->p_filesz);
if (rc < 0) { printf("read error\n"); return EE_INVALID; }*/
 
/* Long reads are not possible yet. Load segment picewise */
/* Long reads are not possible yet. Load segment piecewise. */
 
unsigned left, now;
uint8_t *dp;
411,12 → 404,10
now = 16384;
if (now > left) now = left;
 
// printf("read %d...", now);
rc = my_read(elf->fd, dp, now);
// printf("->%d\n", rc);
 
if (rc < 0) {
printf("read error\n");
DPRINTF("Read error.\n");
return EE_INVALID;
}
 
433,7 → 424,7
// printf("set area flags to %d\n", flags);
rc = as_area_change_flags((uint8_t *)entry->p_vaddr + bias, flags);
if (rc != 0) {
printf("failed to set memory area flags\n");
DPRINTF("Failed to set memory area flags.\n");
return EE_MEMORY;
}
 
/branches/dynload/uspace/srv/loader/arch/ia64/_link.ld.in
12,15 → 12,10
*(.interp);
} :interp
 
. = 0x00084000 + SIZEOF_HEADERS;
/* On Itanium code sections must be aligned to 16 bytes. */
. = ALIGN(0x800000000 + SIZEOF_HEADERS, 16);
 
.init : {
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
LONG(0);
*(.init);
} : text
.text : {
/branches/dynload/uspace/srv/loader/arch/mips32eb
0,0 → 1,0
link mips32
Property changes:
Added: svn:special
+*
\ No newline at end of property