[c98e6ee] | 1 | /*
|
---|
[e16e2ba4] | 2 | * Copyright (c) 2006 Sergey Bondari
|
---|
[c98e6ee] | 3 | * Copyright (c) 2008 Jiri Svoboda
|
---|
| 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[a000878c] | 30 | /** @addtogroup generic
|
---|
[c98e6ee] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | * @brief ELF loader structures and public functions.
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #ifndef ELF_LOAD_H_
|
---|
| 38 | #define ELF_LOAD_H_
|
---|
| 39 |
|
---|
| 40 | #include <arch/elf.h>
|
---|
[90b8d58] | 41 | #include <elf/elf.h>
|
---|
[c98e6ee] | 42 | #include <sys/types.h>
|
---|
| 43 | #include <loader/pcb.h>
|
---|
| 44 |
|
---|
[e16e2ba4] | 45 | /**
|
---|
| 46 | * ELF error return codes
|
---|
| 47 | */
|
---|
| 48 | #define EE_OK 0 /* No error */
|
---|
| 49 | #define EE_INVALID 1 /* Invalid ELF image */
|
---|
| 50 | #define EE_MEMORY 2 /* Cannot allocate address space */
|
---|
| 51 | #define EE_INCOMPATIBLE 3 /* ELF image is not compatible with current architecture */
|
---|
| 52 | #define EE_UNSUPPORTED 4 /* Non-supported ELF (e.g. dynamic ELFs) */
|
---|
| 53 | #define EE_LOADER 5 /* The image is actually a program loader. */
|
---|
| 54 | #define EE_IRRECOVERABLE 6
|
---|
[c98e6ee] | 55 |
|
---|
[1ea99cc] | 56 | typedef enum {
|
---|
| 57 | /** Leave all segments in RW access mode. */
|
---|
| 58 | ELDF_RW = 1
|
---|
| 59 | } eld_flags_t;
|
---|
| 60 |
|
---|
[c98e6ee] | 61 | /**
|
---|
| 62 | * Some data extracted from the headers are stored here
|
---|
| 63 | */
|
---|
| 64 | typedef struct {
|
---|
| 65 | /** Entry point */
|
---|
| 66 | entry_point_t entry;
|
---|
| 67 |
|
---|
| 68 | /** ELF interpreter name or NULL if statically-linked */
|
---|
[a000878c] | 69 | const char *interp;
|
---|
[c98e6ee] | 70 |
|
---|
| 71 | /** Pointer to the dynamic section */
|
---|
| 72 | void *dynamic;
|
---|
| 73 | } elf_info_t;
|
---|
| 74 |
|
---|
| 75 | /**
|
---|
| 76 | * Holds information about an ELF binary being loaded.
|
---|
| 77 | */
|
---|
| 78 | typedef struct {
|
---|
| 79 | /** Filedescriptor of the file from which we are loading */
|
---|
| 80 | int fd;
|
---|
| 81 |
|
---|
| 82 | /** Difference between run-time addresses and link-time addresses */
|
---|
| 83 | uintptr_t bias;
|
---|
| 84 |
|
---|
[1ea99cc] | 85 | /** Flags passed to the ELF loader. */
|
---|
| 86 | eld_flags_t flags;
|
---|
| 87 |
|
---|
[c98e6ee] | 88 | /** A copy of the ELF file header */
|
---|
| 89 | elf_header_t *header;
|
---|
| 90 |
|
---|
| 91 | /** Store extracted info here */
|
---|
| 92 | elf_info_t *info;
|
---|
| 93 | } elf_ld_t;
|
---|
| 94 |
|
---|
[90b8d58] | 95 | extern const char *elf_error(unsigned int);
|
---|
| 96 | extern int elf_load_file(const char *, size_t, eld_flags_t, elf_info_t *);
|
---|
| 97 | extern void elf_create_pcb(elf_info_t *, pcb_t *);
|
---|
[c98e6ee] | 98 |
|
---|
| 99 | #endif
|
---|
| 100 |
|
---|
| 101 | /** @}
|
---|
| 102 | */
|
---|