GEL  0.99
Program Headers

Data Structures

struct  Elf32_Phdr
 
struct  gel_prog_info_t
 
struct  gel_note_t
 

Macros

#define gel_note_name(c)   ((c)->name)
 
#define gel_note_type(c)   ((c)->type)
 
#define gel_note_desc(c)   ((c)->desc)
 
#define gel_note_size(c)   ((c)->desc.size)
 
#define PF_X   (1 << 0)
 
#define PF_W   (1 << 1)
 
#define PF_R   (1 << 2)
 
#define PF_MASKOS   0x0ff00000
 
#define PF_MASKPROC   0xf0000000
 
#define PT_NULL   0
 
#define PT_LOAD   1
 
#define PT_DYNAMIC   2
 
#define PT_INTERP   3
 
#define PT_NOTE   4
 
#define PT_SHLIB   5
 
#define PT_PHDR   6
 
#define PT_LOPROC   0x70000000
 
#define PT_HIPROC   0x7fffffff
 

Typedefs

typedef gel_prog_info_t gel_prog_t
 
typedef struct gel_note_t gel_note_t
 

Functions

int gel_prog2cursor (gel_prog_t *p, gel_cursor_t *c)
 
int gel_note_init (gel_prog_t *phdr, gel_note_t *curs)
 
void gel_note_destroy (gel_note_t *curs)
 
int gel_note_next (gel_note_t *curs)
 
int gel_prog_load (gel_prog_t *p, raddr_t addr)
 
gel_prog_tgel_getprogbyidx (gel_file_t *e, u16_t idx)
 
int gel_prog_infos (gel_prog_t *e, gel_prog_info_t *pi)
 

Detailed Description

This module provides functions to handle program headers. In ELF, the programs headers provide a way to build quickly the memory image of a program. Although there is different types of programs headers, the main type is PT_LOAD that provides information to load code or data from the ELF file to the memory. There is several other types for dynamic linking, compiler notes and so on.

The program headers may be handled using the gel_prog_t pointers and information may be obtained into a gel_prog_info_t structure. A simple way to get a program header is the use of index with the function gel_getprogbyidx().

The PT_NOTE program header may be scanned using the functions: gel_note_init(), gel_note_next(), gel_note_destroy(), gel_note_name(), gel_note_type(), gel_note_size() and gel_note_desc().

Macro Definition Documentation

◆ gel_note_desc

#define gel_note_desc (   c)    ((c)->desc)

Get a cursor on the description of the note.

Parameters
cNote cursor.
Returns
Cursor on the description of the note.

◆ gel_note_name

#define gel_note_name (   c)    ((c)->name)

Get the name of the current note.

Parameters
cNote cursor.
Returns
Name of the note.

◆ gel_note_size

#define gel_note_size (   c)    ((c)->desc.size)

Get the size of the description part of the note.

Parameters
cCursor on the current note.

◆ gel_note_type

#define gel_note_type (   c)    ((c)->type)

Get the type of the current note.

Parameters
cNote cursor.
Returns
Type of the note.

◆ PF_MASKOS

#define PF_MASKOS   0x0ff00000

Program header flag: OS-specific mask.

◆ PF_MASKPROC

#define PF_MASKPROC   0xf0000000

Program header flag: processor specific mask.

◆ PF_R

#define PF_R   (1 << 2)

Program header flag: segment readable.

◆ PF_W

#define PF_W   (1 << 1)

Program header flag: segment writable.

◆ PF_X

#define PF_X   (1 << 0)

Program header flag: segment executable.

◆ PT_DYNAMIC

#define PT_DYNAMIC   2

Program header type: information for dynamic linking.

◆ PT_HIPROC

#define PT_HIPROC   0x7fffffff

Program header type: hig index for processor specific program header.

◆ PT_INTERP

#define PT_INTERP   3

Program header type: information about the program interpreter.

◆ PT_LOAD

#define PT_LOAD   1

Program header type: loadable segment.

◆ PT_LOPROC

#define PT_LOPROC   0x70000000

Program header type: low index for processor specific program header.

◆ PT_NOTE

#define PT_NOTE   4

Program header type: generic note.

◆ PT_NULL

#define PT_NULL   0

Program header type: null.

◆ PT_PHDR

#define PT_PHDR   6

Program header type: position in memory of the program header table.

◆ PT_SHLIB

#define PT_SHLIB   5

Program header type: shared library information.

Typedef Documentation

◆ gel_note_t

typedef struct gel_note_t gel_note_t

Cursor for the content of PT_NOTE program header.

◆ gel_prog_t

Handle for a program header. The program headers may obtained by calling the function gel_getprogbyidx().

Function Documentation

◆ gel_getprogbyidx()

gel_prog_t* gel_getprogbyidx ( gel_file_t e,
u16_t  idx 
)

Get a program header handler from its index. The allocated is automatically managed by the file handler and does not any to be fried by the caller.

Parameters
eFile descriptor.
idxIndex of the required program header.
Returns
Program header handle or null if there is an error.

◆ gel_note_destroy()

void gel_note_destroy ( gel_note_t curs)

Free a note cursor.

Parameters
cursNote cursor.

◆ gel_note_init()

int gel_note_init ( gel_prog_t phdr,
gel_note_t curs 
)

Initialize a note cursor.

Parameters
phdrProgram header to use.
cursUsed cursor.
Returns
0 for success, -1 else.

◆ gel_note_next()

int gel_note_next ( gel_note_t curs)

Get the next note.

Parameters
cursUsed not cursor.
Returns
0 for success. -1 if en is reahced ((gel_errno == 0) or if there is an error (gel_errno != 0).

◆ gel_prog2cursor()

int gel_prog2cursor ( gel_prog_t p,
gel_cursor_t c 
)

Create a cursor on the buffer represented by a program header (loading the program header if needed).

Parameters
pProgram header.
cCursor instance.
Returns
Error code (0 for success, -1 for failure).

◆ gel_prog_infos()

int gel_prog_infos ( gel_prog_t e,
gel_prog_info_t pi 
)

Get public information for the program header handle. Notice that the got information will become inconsistant as soon as the program header is destroyed.

Parameters
eProgram header handle.
piStructure receiving information.
Returns
0 for success, -1 for error.
Deprecated:
Public information are now straight-forward reachable from the handle.

◆ gel_prog_load()

int gel_prog_load ( gel_prog_t p,
raddr_t  addr 
)

Load the rough content of a loadable segment at the given address or, if null, to a memory allocated by GEL.

Parameters
pProgram header handle to load.
addrAddress to load to or null for automatic allocation.
Returns
0 for success, -1 for error.