GEL  0.99
Image Loading

Data Structures

struct  gel_env_s
 

Macros

#define GEL_ENV_CLUSTERISED_MEMORY   0x00000001
 
#define GEL_ENV_NO_STACK   0x00000002
 
#define STACKADDR_OSDEFAULT   0
 
#define STACKSIZE_OSDEFAULT   0
 
#define ENVFLAGS_OSDEFAULT   0
 
#define CLUSTERSIZE_OSDEFAULT   4096
 
#define GEL_IMAGE_CLOSE_EXEC   0x00000001
 
#define GEL_IMAGE_CLOSE_LIBS   0x00000002
 
#define GEL_IMAGE_PLTBLOCK_LAZY   0x00000004
 
#define GEL_IMAGE_PLTBLOCK_NOW   0x00000008
 

Typedefs

typedef struct gel_image_s gel_image_t
 
typedef struct gel_memory_image_s gel_memory_image_t
 
typedef struct gel_memory_cluster_s gel_memory_cluster_t
 
typedef struct gel_memory_cluster_info_t gel_memory_cluster_info_t
 
typedef struct gel_memory_image_info_t gel_memory_image_info_t
 
typedef struct gel_image_info_t gel_image_info_t
 

Functions

int gel_block2cursor (gel_block_t *f, gel_cursor_t *c)
 
gel_env_tgel_default_env (void)
 
int gel_file_load_info (gel_file_t *file, vaddr_t base_vaddr)
 
void gel_image_close (gel_image_t *im)
 
void gel_image_close_only (gel_image_t *im)
 
gel_image_tgel_image_load (gel_file_t *e, gel_env_t *env, int flags)
 
raddr_t gel_vaddr_to_raddr (vaddr_t a, gel_image_t *im)
 
vaddr_t gel_raddr_to_vaddr (raddr_t a, gel_image_t *im)
 
gel_env_tgel_image_env (gel_image_t *i)
 
int gel_image_infos (gel_image_t *i, gel_image_info_t *ii)
 
int gel_memory_image_infos (gel_memory_image_t *mi, gel_memory_image_info_t *mii)
 
int gel_memory_cluster_infos (gel_memory_cluster_t *mc, gel_memory_cluster_info_t *mci)
 

Detailed Description

This module handles the ability to load an execution image from an ELF file.

Macro Definition Documentation

◆ CLUSTERSIZE_OSDEFAULT

#define CLUSTERSIZE_OSDEFAULT   4096

Default memory cluster size as found in the environment.

◆ ENVFLAGS_OSDEFAULT

#define ENVFLAGS_OSDEFAULT   0

Passed in gel_env_t::flags, select the default value for the current OS.

◆ GEL_ENV_CLUSTERISED_MEMORY

#define GEL_ENV_CLUSTERISED_MEMORY   0x00000001

Passed in the gel_env_t flags, activate the use of a clusterized memory scheme.

◆ GEL_ENV_NO_STACK

#define GEL_ENV_NO_STACK   0x00000002

Passed in the gel_env_t flags, disable the allocation of a stack (often used in embedded code).

◆ GEL_IMAGE_CLOSE_EXEC

#define GEL_IMAGE_CLOSE_EXEC   0x00000001

Flag of gel_image_load(). Close the executable file after image building.

◆ GEL_IMAGE_CLOSE_LIBS

#define GEL_IMAGE_CLOSE_LIBS   0x00000002

gel_image_load() flag. Close the library files after image building.

◆ GEL_IMAGE_PLTBLOCK_LAZY

#define GEL_IMAGE_PLTBLOCK_LAZY   0x00000004

gel_image_load() flag. Do not relocate the PLT, use a predefined block instead allowing lazy resolution.

◆ GEL_IMAGE_PLTBLOCK_NOW

#define GEL_IMAGE_PLTBLOCK_NOW   0x00000008

gel_image_load() flag. Replaced the file PLT a new custom one.

◆ STACKADDR_OSDEFAULT

#define STACKADDR_OSDEFAULT   0

Passed in gel_env_t::stackaddr, gives the default stack address for the current OS.

◆ STACKSIZE_OSDEFAULT

#define STACKSIZE_OSDEFAULT   0

Passed in gel_env_t::stacksize, select the default stack size for the current OS.

Typedef Documentation

◆ gel_image_info_t

Public information of an image, extracted from the image descriptor. Provided by the function gel_image_infos().

◆ gel_image_t

Image descriptor handler. Build by gel_image_load()

◆ gel_memory_cluster_info_t

Public information of an image, got using gel_image_cluster_infos().

◆ gel_memory_cluster_t

Descriptor of a contiguous memory area.

◆ gel_memory_image_info_t

Public information of an image memory. Provided by the function gel_image_memory_infos().

◆ gel_memory_image_t

Image memory descriptor.

Function Documentation

◆ gel_block2cursor()

int gel_block2cursor ( gel_block_t f,
gel_cursor_t c 
)

Create a cursor on a memory block.

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

◆ gel_default_env()

gel_env_t* gel_default_env ( void  )

Return the default environment that is initialized as below :

  • libpath = { "./", "/lib", "/usr/lib", "/usr/local/lib", "/usr/X11R6/lib"}
  • argv = {}
  • envp = {}
  • pltblock = NULL
  • pltblocksize = 0
  • stackaddr = STACKADDR_OSDEFAULT
  • stacksize = STACKSIZE_OSDEFAULT
  • clustersize = CLUSTERSIZE_OSDEFAULT
  • flags = ENVFLAGS_OSDEFAULT
Returns
Environment initialized with default values or NULL if there is no more memory.

◆ gel_file_load_info()

int gel_file_load_info ( gel_file_t file,
vaddr_t  base_vaddr 
)

Get information about loading segments (virtual and physical addresses).

Parameters
fileELF file
base_vaddrcurrent base addresse
Returns
0 for success, -1 else

◆ gel_image_close()

void gel_image_close ( gel_image_t im)

Close the image and unallocated its ressources (including opened execitable file and program headers).

Parameters
imImage to close.

◆ gel_image_close_only()

void gel_image_close_only ( gel_image_t im)

Close only the image data structure, not the opened files. The latter must be closed by hand by the user.

Parameters
imImage to close.

◆ gel_image_env()

gel_env_t* gel_image_env ( gel_image_t i)

Return the execution environment configuration of the current image. The returned information becomes invalid as soon as the image is closed.

Parameters
iImage descriptor.
Returns
Image environment.

◆ gel_image_infos()

int gel_image_infos ( gel_image_t i,
gel_image_info_t ii 
)

Extract public information from the image. Got information becomes invalided as soon as the image is released.

Parameters
iImage descriptor.
iiStructure to get image information.
Returns
0 for sucess, -f for error (code in gel_errno).

◆ gel_image_load()

gel_image_t* gel_image_load ( gel_file_t e,
gel_env_t env,
int  flags 
)

Load the given file used as the executable and build the matching execution image. According the needs of the executable, load also the required libraries. The built image must be released using gel_image_close().

Parameters
eExecutable file to load the image of.
flagsMiscalleneous flags (GEL_IMAGE_CLOSE_EXEC, GEL_IMAGE_CLOSE_LIBS, GEL_IMAGE_PLTBLOCK_LAZY, GEL_IMAGE_PLTBLOCK_NOW).
envUsed environment.
Returns
Built image or NULL if there is an error (code in gel_errno).

◆ gel_memory_cluster_infos()

int gel_memory_cluster_infos ( gel_memory_cluster_t mc,
gel_memory_cluster_info_t mci 
)

Extract public information of an image memory cluster. Got information becomes invalid as soon as the image is closed.

Parameters
mcpointeur vers le descripteur du cluster memoire
mcipointeur vers la structure devant �tre remplie par les infos
Returns
Code d'erreur (0 pour succes, -1 pour erreur)

◆ gel_memory_image_infos()

int gel_memory_image_infos ( gel_memory_image_t mi,
gel_memory_image_info_t mii 
)

Extract public information about the image memory. Got information becomes invalid as soon as the image is released.

Parameters
miImage memory descriptor.
miiStructure to store image memory information in.
Returns
0 for sucess, -1 else (error code in gel_errno).

◆ gel_raddr_to_vaddr()

vaddr_t gel_raddr_to_vaddr ( raddr_t  a,
gel_image_t im 
)

Convert a real address to the matching virtual address.

Parameters
aReal address to convert.
imImage containing the real address.
Returns
Converted virtual address.

◆ gel_vaddr_to_raddr()

raddr_t gel_vaddr_to_raddr ( vaddr_t  a,
gel_image_t im 
)

Convert virtual relocated address to a real address.

Parameters
aVirtual address to convert.
imImage containing the virtual address.
Returns
Converted real address.