Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3787 → Rev 3786

/trunk/uspace/srv/loader/main.c
59,8 → 59,6
#include <elf.h>
#include <elf_load.h>
 
#define DPRINTF(...)
 
/** Pathname of the file that will be loaded */
static char *pathname = NULL;
 
227,7 → 225,7
 
rc = elf_load_file(pathname, 0, &prog_info);
if (rc < 0) {
DPRINTF("Failed to load executable '%s'.\n", pathname);
printf("Failed to load executable '%s'.\n", pathname);
ipc_answer_0(rid, EINVAL);
return 1;
}
246,8 → 244,7
 
rc = elf_load_file(prog_info.interp, 0, &interp_info);
if (rc < 0) {
DPRINTF("Failed to load interpreter '%s.'\n",
prog_info.interp);
printf("Failed to load interpreter '%s.'\n", prog_info.interp);
ipc_answer_0(rid, EINVAL);
return 1;
}
269,8 → 266,8
{
if (is_dyn_linked == true) {
/* Dynamically linked program */
DPRINTF("Run ELF interpreter.\n");
DPRINTF("Entry point: 0x%lx\n", interp_info.entry);
printf("run dynamic linker\n");
printf("entry point: 0x%lx\n", interp_info.entry);
close_console();
 
ipc_answer_0(rid, EOK);
327,7 → 324,7
}
if ((callid & IPC_CALLID_NOTIFICATION) == 0 &&
IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) {
DPRINTF("Responding EINVAL to method %d.\n",
printf("responding EINVAL to method %d\n",
IPC_GET_METHOD(call));
ipc_answer_0(callid, EINVAL);
}
/trunk/uspace/srv/loader/elf_load.c
57,8 → 57,6
#include "elf_load.h"
#include "arch.h"
 
#define DPRINTF(...)
 
static char *error_codes[] = {
"no error",
"invalid image",
108,9 → 106,11
int fd;
int rc;
 
// printf("open and read '%s'...\n", file_name);
 
fd = open(file_name, O_RDONLY);
if (fd < 0) {
DPRINTF("failed opening file\n");
printf("failed opening file\n");
return -1;
}
 
171,18 → 171,19
 
rc = my_read(elf->fd, header, sizeof(elf_header_t));
if (rc < 0) {
DPRINTF("Read error.\n");
printf("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) {
DPRINTF("Invalid header.\n");
printf("invalid header\n");
return EE_INVALID;
}
192,18 → 193,18
header->e_ident[EI_VERSION] != EV_CURRENT ||
header->e_version != EV_CURRENT ||
header->e_ident[EI_CLASS] != ELF_CLASS) {
DPRINTF("Incompatible data/version/class.\n");
printf("incompatible data/version/class\n");
return EE_INCOMPATIBLE;
}
 
if (header->e_phentsize != sizeof(elf_segment_header_t)) {
DPRINTF("e_phentsize:%d != %d\n", header->e_phentsize,
printf("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)) {
DPRINTF("e_shentsize:%d != %d\n", header->e_shentsize,
printf("e_shentsize:%d != %d\n", header->e_shentsize,
sizeof(elf_section_header_t));
return EE_INCOMPATIBLE;
}
210,19 → 211,23
 
/* Check if the object type is supported. */
if (header->e_type != ET_EXEC && header->e_type != ET_DYN) {
DPRINTF("Object type %d is not supported\n", header->e_type);
printf("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;
234,7 → 239,7
rc = my_read(elf->fd, &segment_hdr,
sizeof(elf_segment_header_t));
if (rc < 0) {
DPRINTF("Read error.\n");
printf("read error\n");
return EE_INVALID;
}
 
243,7 → 248,7
return rc;
}
 
DPRINTF("Parse sections.\n");
// printf("parse sections\n");
 
/* Inspect all section headers and proccess them. */
for (i = 0; i < header->e_shnum; i++) {
256,7 → 261,7
rc = my_read(elf->fd, &section_hdr,
sizeof(elf_section_header_t));
if (rc < 0) {
DPRINTF("Read error.\n");
printf("read error\n");
return EE_INVALID;
}
 
268,7 → 273,7
elf->info->entry =
(entry_point_t)((uint8_t *)header->e_entry + elf->bias);
 
DPRINTF("Done.\n");
// printf("done\n");
 
return EE_OK;
}
311,7 → 316,7
case PT_LOPROC:
case PT_HIPROC:
default:
DPRINTF("Segment p_type %d unknown.\n", entry->p_type);
printf("segment p_type %d unknown\n", entry->p_type);
return EE_UNSUPPORTED;
break;
}
334,8 → 339,8
size_t mem_sz;
int rc;
 
DPRINTF("Load segment at addr 0x%x, size 0x%x\n", entry->p_vaddr,
entry->p_memsz);
// printf("load segment at addr 0x%x, size 0x%x\n", entry->p_vaddr,
// entry->p_memsz);
bias = elf->bias;
 
342,7 → 347,7
if (entry->p_align > 1) {
if ((entry->p_offset % entry->p_align) !=
(entry->p_vaddr % entry->p_align)) {
DPRINTF("Align check 1 failed offset%%align=%d, "
printf("align check 1 failed offset%%align=%d, "
"vaddr%%align=%d\n",
entry->p_offset % entry->p_align,
entry->p_vaddr % entry->p_align
364,8 → 369,8
base = ALIGN_DOWN(entry->p_vaddr, PAGE_SIZE);
mem_sz = entry->p_memsz + (entry->p_vaddr - base);
 
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));
// 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));
 
/*
* For the course of loading, the area needs to be readable
374,16 → 379,17
a = as_area_create((uint8_t *)base + bias, mem_sz,
AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
if (a == (void *)(-1)) {
DPRINTF("Memory mapping failed.\n");
printf("memory mapping failed\n");
return EE_MEMORY;
}
 
DPRINTF("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n",
entry->p_vaddr+bias, entry->p_memsz, flags, (uintptr_t)a);
// printf("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");
390,10 → 396,11
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 piecewise. */
/* Long reads are not possible yet. Load segment picewise */
 
unsigned left, now;
uint8_t *dp;
405,10 → 412,12
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) {
DPRINTF("Read error.\n");
printf("read error\n");
return EE_INVALID;
}
 
416,9 → 425,10
dp += now;
}
 
// printf("set area flags to %d\n", flags);
rc = as_area_change_flags((uint8_t *)entry->p_vaddr + bias, flags);
if (rc != 0) {
DPRINTF("Failed to set memory area flags.\n");
printf("failed to set memory area flags\n");
return EE_MEMORY;
}
 
455,7 → 465,7
/* Record pointer to dynamic section into info structure */
elf->info->dynamic =
(void *)((uint8_t *)entry->sh_addr + elf->bias);
DPRINTF("Dynamic section found at 0x%x.\n",
printf("dynamic section found at 0x%x\n",
(uintptr_t)elf->info->dynamic);
break;
default: