2 * \file bootstrap/server/src/exec.c
6 * \author Frank Mehnert <fm3@os.inf.tu-dresden.de>,
7 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de> */
10 * (c) 2005-2009 Author(s)
11 * economic rights: Technische Universität Dresden (Germany)
13 * This file is part of TUD:OS and distributed under the terms of the
14 * GNU General Public License 2.
15 * Please see the COPYING-GPL-2 file for details.
23 #include <l4/util/elf.h>
28 exec_load_elf(exec_handler_func_t *handler,
29 void *handle, const char **error_msg, l4_addr_t *entry)
31 exec_task_t *t = handle;
32 ElfW(Ehdr) *x = t->mod_start;
33 ElfW(Phdr) *phdr, *ph;
36 /* Read the ELF header. */
38 if (!l4util_elf_check_magic(x))
39 return *error_msg="no ELF executable", -1;
41 /* Make sure the file is of the right architecture. */
42 if (!l4util_elf_check_arch(x))
43 return *error_msg="wrong ELF architecture", -1;
45 *entry = (l4_addr_t) x->e_entry;
47 phdr = l4util_elf_phdr(x);
49 for (i = 0; i < x->e_phnum; i++)
51 ph = (ElfW(Phdr)*)((l4_addr_t)phdr + i * x->e_phentsize);
52 if (ph->p_type == PT_LOAD)
54 exec_sectype_t type = EXEC_SECTYPE_ALLOC |
56 if (ph->p_flags & PF_R) type |= EXEC_SECTYPE_READ;
57 if (ph->p_flags & PF_W) type |= EXEC_SECTYPE_WRITE;
58 if (ph->p_flags & PF_X) type |= EXEC_SECTYPE_EXECUTE;
60 ph->p_offset, ph->p_filesz,
61 ph->p_paddr, ph->p_vaddr, ph->p_memsz, type);
65 return *error_msg="", 0;