Files | |
file | bitops.h |
file | dynamic.h |
file | elf.h |
file | elf.h |
file | elf_dyn.h |
file | elf_load.c |
Userspace ELF loader. | |
file | elf_load.h |
ELF loader structures and public functions. | |
file | printf_core.c |
Printing functions. | |
Data Structures | |
struct | dyn_info_arch_t |
struct | elf32_header |
ELF header. More... | |
struct | elf32_header |
ELF header. More... | |
struct | elf32_section_header |
struct | elf32_section_header |
struct | elf32_segment_header |
struct | elf32_segment_header |
struct | elf32_symbol |
struct | elf32_symbol |
struct | elf64_header |
struct | elf64_header |
struct | elf64_section_header |
struct | elf64_section_header |
struct | elf64_segment_header |
struct | elf64_segment_header |
struct | elf64_symbol |
struct | elf64_symbol |
struct | elf_info_t |
Some data extracted from the headers are stored here. More... | |
struct | elf_ld_t |
Holds information about an ELF binary being loaded. More... | |
Defines | |
#define | __PRINTF_FLAG_BIGCHARS 0x00000080 |
show big characters | |
#define | __PRINTF_FLAG_LEFTALIGNED 0x00000010 |
align to left | |
#define | __PRINTF_FLAG_NEGATIVE 0x00000100 |
number has - sign | |
#define | __PRINTF_FLAG_PREFIX 0x00000001 |
show prefixes 0x or 0 | |
#define | __PRINTF_FLAG_SHOWPLUS 0x00000020 |
always show + sign | |
#define | __PRINTF_FLAG_SIGNED 0x00000002 |
signed / unsigned number | |
#define | __PRINTF_FLAG_SPACESIGN 0x00000040 |
print space instead of plus | |
#define | __PRINTF_FLAG_ZEROPADDED 0x00000004 |
print leading zeroes | |
#define | DPRINTF() |
#define | EE_INCOMPATIBLE 3 |
#define | EE_INCOMPATIBLE 3 |
#define | EE_INVALID 1 |
#define | EE_INVALID 1 |
#define | EE_IRRECOVERABLE 5 |
#define | EE_IRRECOVERABLE 5 |
#define | EE_MEMORY 2 |
#define | EE_MEMORY 2 |
#define | EE_OK 0 |
ELF error return codes. | |
#define | EE_OK 0 |
ELF error return codes. | |
#define | EE_UNSUPPORTED 4 |
#define | EE_UNSUPPORTED 4 |
#define | EI_ABIVERSION 8 |
#define | EI_ABIVERSION 8 |
#define | EI_CLASS 4 |
#define | EI_CLASS 4 |
#define | EI_DATA 5 |
#define | EI_DATA 5 |
#define | EI_MAG0 0 |
ELF identification indexes. | |
#define | EI_MAG0 0 |
ELF identification indexes. | |
#define | EI_MAG1 1 |
#define | EI_MAG1 1 |
#define | EI_MAG2 2 |
#define | EI_MAG2 2 |
#define | EI_MAG3 3 |
#define | EI_MAG3 3 |
#define | EI_NIDENT 16 |
#define | EI_NIDENT 16 |
#define | EI_OSABI 7 |
#define | EI_OSABI 7 |
#define | EI_PAD 9 |
#define | EI_PAD 9 |
#define | EI_VERSION 6 |
#define | EI_VERSION 6 |
#define | ELF_ST_BIND(i) ((i) >> 4) |
Macros for decomposing elf_symbol.st_info into binging and type. | |
#define | ELF_ST_INFO(b, t) (((b) << 4) + ((t) & 0x0f)) |
#define | ELF_ST_TYPE(i) ((i) & 0x0f) |
#define | ELFCLASS32 1 |
#define | ELFCLASS32 1 |
#define | ELFCLASS64 2 |
#define | ELFCLASS64 2 |
#define | ELFCLASSNONE 0 |
ELF file classes. | |
#define | ELFCLASSNONE 0 |
ELF file classes. | |
#define | ELFDATA2LSB 1 |
#define | ELFDATA2LSB 1 |
#define | ELFDATA2MSB 2 |
#define | ELFDATA2MSB 2 |
#define | ELFDATANONE 0 |
ELF data encoding types. | |
#define | ELFDATANONE 0 |
ELF data encoding types. | |
#define | ELFMAG0 0x7f |
ELF magic number. | |
#define | ELFMAG0 0x7f |
ELF magic number. | |
#define | ELFMAG1 'E' |
#define | ELFMAG1 'E' |
#define | ELFMAG2 'L' |
#define | ELFMAG2 'L' |
#define | ELFMAG3 'F' |
#define | ELFMAG3 'F' |
#define | EM_386 3 |
#define | EM_386 3 |
#define | EM_ARM 40 |
#define | EM_ARM 40 |
#define | EM_IA_64 50 |
#define | EM_IA_64 50 |
#define | EM_MIPS 8 |
#define | EM_MIPS 8 |
#define | EM_MIPS_RS3_LE 10 |
#define | EM_MIPS_RS3_LE 10 |
#define | EM_NO 0 |
ELF machine types. | |
#define | EM_NO 0 |
ELF machine types. | |
#define | EM_PPC 20 |
#define | EM_PPC 20 |
#define | EM_PPC64 21 |
#define | EM_PPC64 21 |
#define | EM_SPARC 2 |
#define | EM_SPARC 2 |
#define | EM_SPARCV9 43 |
#define | EM_SPARCV9 43 |
#define | EM_X86_64 62 |
#define | EM_X86_64 62 |
#define | ET_CORE 4 |
#define | ET_CORE 4 |
#define | ET_DYN 3 |
#define | ET_DYN 3 |
#define | ET_EXEC 2 |
#define | ET_EXEC 2 |
#define | ET_HIPROC 0xffff |
#define | ET_HIPROC 0xffff |
#define | ET_LOPROC 0xff00 |
#define | ET_LOPROC 0xff00 |
#define | ET_NONE 0 |
ELF types. | |
#define | ET_NONE 0 |
ELF types. | |
#define | ET_REL 1 |
#define | ET_REL 1 |
#define | EV_CURRENT 1 |
current ELF version | |
#define | EV_CURRENT 1 |
current ELF version | |
#define | PF_R 4 |
#define | PF_R 4 |
#define | PF_W 2 |
#define | PF_W 2 |
#define | PF_X 1 |
Program segment attributes. | |
#define | PF_X 1 |
Program segment attributes. | |
#define | PRINT_NUMBER_BUFFER_SIZE (64 + 5) |
Buffer big enough for 64-bit number printed in base 2, sign, prefix and 0 to terminate string. | |
#define | PT_DYNAMIC 2 |
#define | PT_DYNAMIC 2 |
#define | PT_HIPROC 0x7fffffff |
#define | PT_HIPROC 0x7fffffff |
#define | PT_INTERP 3 |
#define | PT_INTERP 3 |
#define | PT_LOAD 1 |
#define | PT_LOAD 1 |
#define | PT_LOPROC 0x70000000 |
#define | PT_LOPROC 0x70000000 |
#define | PT_NOTE 4 |
#define | PT_NOTE 4 |
#define | PT_NULL 0 |
Program segment types. | |
#define | PT_NULL 0 |
Program segment types. | |
#define | PT_PHDR 6 |
#define | PT_PHDR 6 |
#define | PT_SHLIB 5 |
#define | PT_SHLIB 5 |
#define | R_386_32 1 |
#define | R_386_COPY 5 |
#define | R_386_GLOB_DAT 6 |
#define | R_386_JUMP_SLOT 7 |
#define | R_386_PC32 2 |
#define | R_386_RELATIVE 8 |
#define | R_386_TLS_DTPMOD32 35 |
#define | SHF_ALLOC 0x2 |
#define | SHF_ALLOC 0x2 |
#define | SHF_EXECINSTR 0x4 |
#define | SHF_EXECINSTR 0x4 |
#define | SHF_MASKPROC 0xf0000000 |
#define | SHF_MASKPROC 0xf0000000 |
#define | SHF_TLS 0x400 |
#define | SHF_TLS 0x400 |
#define | SHF_WRITE 0x1 |
ELF section flags. | |
#define | SHF_WRITE 0x1 |
ELF section flags. | |
#define | SHT_DYNAMIC 6 |
#define | SHT_DYNAMIC 6 |
#define | SHT_DYNSYM 11 |
#define | SHT_DYNSYM 11 |
#define | SHT_HASH 5 |
#define | SHT_HASH 5 |
#define | SHT_HIOS 0x6fffffff |
#define | SHT_HIOS 0x6fffffff |
#define | SHT_HIPROC 0x7fffffff |
#define | SHT_HIPROC 0x7fffffff |
#define | SHT_HIUSER 0xffffffff |
#define | SHT_HIUSER 0xffffffff |
#define | SHT_LOOS 0x60000000 |
#define | SHT_LOOS 0x60000000 |
#define | SHT_LOPROC 0x70000000 |
#define | SHT_LOPROC 0x70000000 |
#define | SHT_LOUSER 0x80000000 |
#define | SHT_LOUSER 0x80000000 |
#define | SHT_NOBITS 8 |
#define | SHT_NOBITS 8 |
#define | SHT_NOTE 7 |
#define | SHT_NOTE 7 |
#define | SHT_NULL 0 |
ELF section types. | |
#define | SHT_NULL 0 |
ELF section types. | |
#define | SHT_PROGBITS 1 |
#define | SHT_PROGBITS 1 |
#define | SHT_REL 9 |
#define | SHT_REL 9 |
#define | SHT_RELA 4 |
#define | SHT_RELA 4 |
#define | SHT_SHLIB 10 |
#define | SHT_SHLIB 10 |
#define | SHT_STRTAB 3 |
#define | SHT_STRTAB 3 |
#define | SHT_SYMTAB 2 |
#define | SHT_SYMTAB 2 |
#define | STB_GLOBAL 1 |
#define | STB_GLOBAL 1 |
#define | STB_HIPROC 15 |
#define | STB_HIPROC 15 |
#define | STB_LOCAL 0 |
Symbol binding. | |
#define | STB_LOCAL 0 |
Symbol binding. | |
#define | STB_LOPROC 13 |
#define | STB_LOPROC 13 |
#define | STB_WEAK 2 |
#define | STB_WEAK 2 |
#define | STT_FILE 4 |
#define | STT_FILE 4 |
#define | STT_FUNC 2 |
#define | STT_FUNC 2 |
#define | STT_HIPROC 15 |
#define | STT_HIPROC 15 |
#define | STT_LOPROC 13 |
#define | STT_LOPROC 13 |
#define | STT_NOTYPE 0 |
Symbol types. | |
#define | STT_NOTYPE 0 |
Symbol types. | |
#define | STT_OBJECT 1 |
#define | STT_OBJECT 1 |
#define | STT_SECTION 3 |
#define | STT_SECTION 3 |
Typedefs | |
typedef uint32_t | elf32_addr |
32-bit ELF data types. | |
typedef uint32_t | elf32_addr |
32-bit ELF data types. | |
typedef uint32_t | elf32_off |
typedef uint32_t | elf32_off |
typedef uint64_t | elf64_addr |
64-bit ELF data types. | |
typedef uint64_t | elf64_addr |
64-bit ELF data types. | |
typedef uint64_t | elf64_off |
typedef uint64_t | elf64_off |
typedef uint16_t | elf_half |
typedef uint16_t | elf_half |
typedef int32_t | elf_sword |
typedef int32_t | elf_sword |
typedef int64_t | elf_sxword |
typedef int64_t | elf_sxword |
typedef uint32_t | elf_word |
typedef uint32_t | elf_word |
typedef uint64_t | elf_xword |
ELF data types. | |
typedef uint64_t | elf_xword |
ELF data types. | |
Enumerations | |
enum | eld_flags_t { ELDF_RW = 1 } |
enum | qualifier_t |
Enumeration of possible arguments types. | |
Functions | |
void | elf_create_pcb (elf_info_t *info, pcb_t *pcb) |
Create the program control block (PCB). | |
char * | elf_error (unsigned int rc) |
Print error message according to error code. | |
static unsigned int | elf_load (elf_ld_t *elf, size_t so_bias) |
Load an ELF binary. | |
int | elf_load_file (const char *file_name, size_t so_bias, eld_flags_t flags, elf_info_t *info) |
Load ELF binary from a file. | |
static unsigned int | fnzb (size_t arg) |
static unsigned int | fnzb32 (uint32_t arg) |
Return position of first non-zero bit from left (i.e. | |
static unsigned int | fnzb64 (uint64_t arg) |
static int | load_segment (elf_ld_t *elf, elf_segment_header_t *entry) |
Load segment described by program header entry. | |
static int | my_read (int fd, void *buf, size_t len) |
Read until the buffer is read in its entirety. | |
static int | print_char (const char ch, int width, uint32_t flags, printf_spec_t *ps) |
Print one formatted ASCII character. | |
static int | print_number (uint64_t num, int width, int precision, int base, uint32_t flags, printf_spec_t *ps) |
Print a number in a given base. | |
static int | print_str (char *str, int width, unsigned int precision, uint32_t flags, printf_spec_t *ps) |
Print string. | |
static int | print_wchar (const wchar_t ch, int width, uint32_t flags, printf_spec_t *ps) |
Print one formatted wide character. | |
static int | print_wstr (wchar_t *str, int width, unsigned int precision, uint32_t flags, printf_spec_t *ps) |
Print wide string. | |
int | printf_core (const char *fmt, printf_spec_t *ps, va_list ap) |
Print formatted string. | |
static int | printf_putchar (const char ch, printf_spec_t *ps) |
Print one ASCII character. | |
static int | printf_putnchars (const char *buf, size_t size, printf_spec_t *ps) |
Print one or more characters without adding newline. | |
static int | printf_putstr (const char *str, printf_spec_t *ps) |
Print string without adding a newline. | |
static int | printf_putwchar (const wchar_t ch, printf_spec_t *ps) |
Print one wide character. | |
static int | printf_wputnchars (const wchar_t *buf, size_t size, printf_spec_t *ps) |
Print one or more wide characters without adding newline. | |
static int | section_header (elf_ld_t *elf, elf_section_header_t *entry) |
Process section header. | |
static int | segment_header (elf_ld_t *elf, elf_segment_header_t *entry) |
Process segment header. | |
Variables | |
static const char * | digits_big = "0123456789ABCDEF" |
static const char * | digits_small = "0123456789abcdef" |
static const char * | error_codes [] |
static const char | invalch = U_SPECIAL |
static const char * | nullstr = "(NULL)" |
#define PRINT_NUMBER_BUFFER_SIZE (64 + 5) |
Buffer big enough for 64-bit number printed in base 2, sign, prefix and 0 to terminate string.
.. (last one is only for better testing end of buffer by zero-filling subroutine)
Definition at line 74 of file printf_core.c.
typedef uint32_t elf32_addr |
typedef uint32_t elf32_addr |
typedef uint64_t elf64_addr |
typedef uint64_t elf64_addr |
typedef uint64_t elf_xword |
typedef uint64_t elf_xword |
enum eld_flags_t |
void elf_create_pcb | ( | elf_info_t * | info, | |
pcb_t * | pcb | |||
) |
Create the program control block (PCB).
Fills the program control block pcb with information from info.
info | Program info structure |
Definition at line 138 of file elf_load.c.
const char * elf_error | ( | unsigned int | rc | ) |
Print error message according to error code.
rc | Return code returned by elf_load(). |
Definition at line 272 of file elf_load.c.
Load an ELF binary.
The elf structure contains the loader state, including an open file, from which the binary will be loaded, a pointer to the info
structure etc.
elf | Pointer to loader state buffer. | |
so_bias | Bias to use if the file is a shared object. |
Definition at line 156 of file elf_load.c.
int elf_load_file | ( | const char * | file_name, | |
size_t | so_bias, | |||
eld_flags_t | flags, | |||
elf_info_t * | info | |||
) |
Load ELF binary from a file.
Load an ELF binary from the specified file. If the file is an executable program, it is loaded unbiased. If it is a shared object, it is loaded with the bias so_bias. Some information extracted from the binary is stored in a elf_info_t structure pointed to by info.
file_name | Path to the ELF file. | |
so_bias | Bias to use if the file is a shared object. | |
info | Pointer to a structure for storing information extracted from the binary. |
Definition at line 105 of file elf_load.c.
static unsigned int fnzb32 | ( | uint32_t | arg | ) | [inline, static] |
int load_segment | ( | elf_ld_t * | elf, | |
elf_segment_header_t * | entry | |||
) | [static] |
Load segment described by program header entry.
elf | Loader state. | |
entry | Program header entry describing segment to be loaded. |
Definition at line 327 of file elf_load.c.
static int print_char | ( | const char | ch, | |
int | width, | |||
uint32_t | flags, | |||
printf_spec_t * | ps | |||
) | [static] |
Print one formatted ASCII character.
ch | Character to print. | |
width | Width modifier. | |
flags | Flags that change the way the character is printed. |
Definition at line 182 of file printf_core.c.
static int print_number | ( | uint64_t | num, | |
int | width, | |||
int | precision, | |||
int | base, | |||
uint32_t | flags, | |||
printf_spec_t * | ps | |||
) | [static] |
Print a number in a given base.
Print significant digits of a number in given base.
num | Number to print. | |
width | Width modifier. | |
precision | Precision modifier. | |
base | Base to print the number in (must be between 2 and 16). | |
flags | Flags that modify the way the number is printed. |
Definition at line 357 of file printf_core.c.
static int print_str | ( | char * | str, | |
int | width, | |||
unsigned int | precision, | |||
uint32_t | flags, | |||
printf_spec_t * | ps | |||
) | [static] |
Print string.
str | String to be printed. | |
width | Width modifier. | |
precision | Precision modifier. | |
flags | Flags that modify the way the string is printed. |
Definition at line 258 of file printf_core.c.
static int print_wchar | ( | const wchar_t | ch, | |
int | width, | |||
uint32_t | flags, | |||
printf_spec_t * | ps | |||
) | [static] |
Print one formatted wide character.
ch | Character to print. | |
width | Width modifier. | |
flags | Flags that change the way the character is printed. |
Definition at line 220 of file printf_core.c.
static int print_wstr | ( | wchar_t * | str, | |
int | width, | |||
unsigned int | precision, | |||
uint32_t | flags, | |||
printf_spec_t * | ps | |||
) | [static] |
Print wide string.
str | Wide string to be printed. | |
width | Width modifier. | |
precision | Precision modifier. | |
flags | Flags that modify the way the string is printed. |
Definition at line 306 of file printf_core.c.
int printf_core | ( | const char * | fmt, | |
printf_spec_t * | ps, | |||
va_list | ap | |||
) |
Print formatted string.
Print string formatted according to the fmt parameter and variadic arguments. Each formatting directive must have the following form:
% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION
FLAGS:
WIDTH:
PRECISION:
TYPE:
CONVERSION:
All other characters from fmt except the formatting directives are printed verbatim.
fmt | Format NULL-terminated string. |
Definition at line 599 of file printf_core.c.
static int printf_putchar | ( | const char | ch, | |
printf_spec_t * | ps | |||
) | [static] |
Print one ASCII character.
c | ASCII character to be printed. | |
ps | Output method. |
Definition at line 149 of file printf_core.c.
static int printf_putnchars | ( | const char * | buf, | |
size_t | size, | |||
printf_spec_t * | ps | |||
) | [static] |
Print one or more characters without adding newline.
buf | Buffer holding characters with size of at least size bytes. NULL is not allowed! | |
size | Size of the buffer in bytes. | |
ps | Output method and its data. |
Definition at line 103 of file printf_core.c.
static int printf_putstr | ( | const char * | str, | |
printf_spec_t * | ps | |||
) | [static] |
Print string without adding a newline.
str | String to print. | |
ps | Write function specification and support data. |
Definition at line 133 of file printf_core.c.
static int printf_putwchar | ( | const wchar_t | ch, | |
printf_spec_t * | ps | |||
) | [static] |
Print one wide character.
c | Wide character to be printed. | |
ps | Output method. |
Definition at line 165 of file printf_core.c.
static int printf_wputnchars | ( | const wchar_t * | buf, | |
size_t | size, | |||
printf_spec_t * | ps | |||
) | [static] |
Print one or more wide characters without adding newline.
buf | Buffer holding wide characters with size of at least size bytes. NULL is not allowed! | |
size | Size of the buffer in bytes. | |
ps | Output method and its data. |
Definition at line 119 of file printf_core.c.
static int section_header | ( | elf_ld_t * | elf, | |
elf_section_header_t * | entry | |||
) | [static] |
Process section header.
elf | Loader state. | |
entry | Segment header. |
Definition at line 454 of file elf_load.c.
static int segment_header | ( | elf_ld_t * | elf, | |
elf_segment_header_t * | entry | |||
) | [static] |
Process segment header.
entry | Segment header. |
Definition at line 285 of file elf_load.c.