KallistiOS  2.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Data Structures | Macros | Typedefs | Functions
elf.h File Reference

ELF binary loading support. More...

#include <sys/cdefs.h>
#include <arch/types.h>
#include <sys/queue.h>

Go to the source code of this file.

Data Structures

struct  elf_hdr_t
 ELF file header. More...
struct  elf_shdr_t
 ELF Section header. More...
struct  elf_sym_t
 Symbol table entry. More...
struct  elf_rela_t
 ELF Relocation entry (with explicit addend). More...
struct  elf_rel_t
 ELF Relocation entry (without explicit addend). More...
struct  elf_prog
 Kernel-specific definition of a loaded ELF binary. More...

Macros

#define EM_386   3
 x86 (IA32)
#define EM_ARM   40
 ARM.
#define EM_SH   42
 SuperH.
#define SHT_NULL   0
 Inactive section.
#define SHT_PROGBITS   1
 Program code/data.
#define SHT_SYMTAB   2
 Full symbol table.
#define SHT_STRTAB   3
 String table.
#define SHT_RELA   4
 Relocation table, with addends.
#define SHT_HASH   5
 Symbol hash table.
#define SHT_DYNAMIC   6
 Dynamic linking info.
#define SHT_NOTE   7
 Notes section.
#define SHT_NOBITS   8
 A section that occupies no space in the file.
#define SHT_REL   9
 Relocation table, no addends.
#define SHT_SHLIB   10
 Reserved.
#define SHT_DYNSYM   11
 Dynamic-only sym tab.
#define SHT_LOPROC   0x70000000
 Start of processor specific types.
#define SHT_HIPROC   0x7fffffff
 End of processor specific types.
#define SHT_LOUSER   0x80000000
 Start of program specific types.
#define SHT_HIUSER   0xffffffff
 End of program specific types.
#define SHF_WRITE   1
 Writable data.
#define SHF_ALLOC   2
 Resident.
#define SHF_EXECINSTR   4
 Executable instructions.
#define SHF_MASKPROC   0xf0000000
 Processor specific mask.
#define SHN_UNDEF   0
 Undefined, missing, irrelevant.
#define SHN_ABS   0xfff1
 Absolute values.
#define STB_LOCAL   0
 Local (non-exported) symbol.
#define STB_GLOBAL   1
 Global (exported) symbol.
#define STB_WEAK   2
 Weak-linked symbol.
#define STT_NOTYPE   0
 Symbol has no type.
#define STT_OBJECT   1
 Symbol is an object.
#define STT_FUNC   2
 Symbol is a function.
#define STT_SECTION   3
 Symbol is a section.
#define STT_FILE   4
 Symbol is a file name.
#define ELF32_ST_BIND(info)   ((info) >> 4)
 Retrieve the binding type for a symbol.
#define ELF32_ST_TYPE(info)   ((info) & 0xf)
 Retrieve the symbol type for a symbol.
#define R_SH_DIR32   1
 SuperH: Rel = Symbol + Addend.
#define R_386_32   1
 x86: Rel = Symbol + Addend
#define R_386_PC32   2
 x86: Rel = Symbol + Addend - Value
#define ELF32_R_SYM(i)   ((i) >> 8)
 Retrieve the symbol index from a relocation entry.
#define ELF32_R_TYPE(i)   ((uint8)(i))
 Retrieve the relocation type from a relocation entry.

Typedefs

typedef struct elf_prog elf_prog_t
 Kernel-specific definition of a loaded ELF binary.

Functions

int elf_load (const char *fn, struct klibrary *shell, elf_prog_t *out)
 Load an ELF binary.
void elf_free (elf_prog_t *prog)
 Free a loaded ELF program.

Detailed Description

ELF binary loading support.

This file contains the support functionality for loading ELF binaries in KOS. This includes the various header structures and whatnot that are used in ELF files to store code/data/relocations/etc. This isn't necessarily meant for running multiple processes, but more for loadable library support within KOS.

Author:
Dan Potter

Macro Definition Documentation

#define ELF32_R_SYM (   i)    ((i) >> 8)

Retrieve the symbol index from a relocation entry.

Parameters:
iThe info field of an elf_rel_t or elf_rela_t.
Returns:
The symbol table index from that relocation entry.
#define ELF32_R_TYPE (   i)    ((uint8)(i))

Retrieve the relocation type from a relocation entry.

Parameters:
iThe info field of an elf_rel_t or an elf_rela_t.
Returns:
The relocation type of that relocation.
See also:
ELF relocation types
#define ELF32_ST_BIND (   info)    ((info) >> 4)

Retrieve the binding type for a symbol.

Parameters:
infoThe info field of an elf_sym_t.
Returns:
The binding type of the symbol.
See also:
Symbol binding types.
#define ELF32_ST_TYPE (   info)    ((info) & 0xf)

Retrieve the symbol type for a symbol.

Parameters:
infoThe info field of an elf_sym_t.
Returns:
The symbol type of the symbol.
See also:
Symbol types.

Typedef Documentation

typedef struct elf_prog elf_prog_t

Kernel-specific definition of a loaded ELF binary.

This structure represents the internal representation of a loaded ELF binary in KallistiOS (specifically as a dynamically loaded library).


Function Documentation

void elf_free ( elf_prog_t prog)

Free a loaded ELF program.

This function cleans up an ELF binary that was loaded with elf_load().

Parameters:
progThe loaded binary to clean up.
int elf_load ( const char *  fn,
struct klibrary shell,
elf_prog_t out 
)

Load an ELF binary.

This function loads an ELF binary from the VFS and fills in an elf_prog_t for it.

Parameters:
fnThe filename of the binary on the VFS.
shellUnused?
outStorage for the binary that will be loaded.
Returns:
0 on success, <0 on failure.