Mostly cosmetic renaming to straighten out namespace

This commit is contained in:
Gregory Nutt 2015-12-10 16:56:10 -06:00
parent 8bcf35ff39
commit 251e8395c7
16 changed files with 176 additions and 208 deletions

View File

@ -57,7 +57,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_verifyheader * Name: libmod_verifyheader
* *
* Description: * Description:
* Given the header from a possible ELF executable, verify that it is * Given the header from a possible ELF executable, verify that it is
@ -69,10 +69,10 @@
* *
****************************************************************************/ ****************************************************************************/
int mod_verifyheader(FAR const Elf32_Ehdr *header); int libmod_verifyheader(FAR const Elf32_Ehdr *header);
/**************************************************************************** /****************************************************************************
* Name: mod_read * Name: libmod_read
* *
* Description: * Description:
* Read 'readsize' bytes from the object file at 'offset'. The data is * Read 'readsize' bytes from the object file at 'offset'. The data is
@ -84,11 +84,11 @@ int mod_verifyheader(FAR const Elf32_Ehdr *header);
* *
****************************************************************************/ ****************************************************************************/
int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
size_t readsize, off_t offset); size_t readsize, off_t offset);
/**************************************************************************** /****************************************************************************
* Name: mod_loadshdrs * Name: libmod_loadshdrs
* *
* Description: * Description:
* Loads section headers into memory. * Loads section headers into memory.
@ -99,10 +99,10 @@ int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
* *
****************************************************************************/ ****************************************************************************/
int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo); int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_findsection * Name: libmod_findsection
* *
* Description: * Description:
* A section by its name. * A section by its name.
@ -117,11 +117,11 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo);
* *
****************************************************************************/ ****************************************************************************/
int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, int libmod_findsection(FAR struct libmod_loadinfo_s *loadinfo,
FAR const char *sectname); FAR const char *sectname);
/**************************************************************************** /****************************************************************************
* Name: mod_findsymtab * Name: libmod_findsymtab
* *
* Description: * Description:
* Find the symbol table section. * Find the symbol table section.
@ -132,10 +132,10 @@ int mod_findsection(FAR struct mod_loadinfo_s *loadinfo,
* *
****************************************************************************/ ****************************************************************************/
int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo); int libmod_findsymtab(FAR struct libmod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_readsym * Name: libmod_readsym
* *
* Description: * Description:
* Read the ELFT symbol structure at the specfied index into memory. * Read the ELFT symbol structure at the specfied index into memory.
@ -151,11 +151,11 @@ int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo);
* *
****************************************************************************/ ****************************************************************************/
int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index,
FAR Elf32_Sym *sym); FAR Elf32_Sym *sym);
/**************************************************************************** /****************************************************************************
* Name: mod_symvalue * Name: libmod_symvalue
* *
* Description: * Description:
* Get the value of a symbol. The updated value of the symbol is returned * Get the value of a symbol. The updated value of the symbol is returned
@ -179,11 +179,11 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index,
* *
****************************************************************************/ ****************************************************************************/
int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
FAR const struct symtab_s *exports, int nexports); FAR const struct symtab_s *exports, int nexports);
/**************************************************************************** /****************************************************************************
* Name: mod_freebuffers * Name: libmod_freebuffers
* *
* Description: * Description:
* Release all working buffers. * Release all working buffers.
@ -194,10 +194,10 @@ int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
* *
****************************************************************************/ ****************************************************************************/
int mod_freebuffers(FAR struct mod_loadinfo_s *loadinfo); int libmod_freebuffers(FAR struct libmod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_allocbuffer * Name: libmod_allocbuffer
* *
* Description: * Description:
* Perform the initial allocation of the I/O buffer, if it has not already * Perform the initial allocation of the I/O buffer, if it has not already
@ -209,10 +209,10 @@ int mod_freebuffers(FAR struct mod_loadinfo_s *loadinfo);
* *
****************************************************************************/ ****************************************************************************/
int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo); int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_reallocbuffer * Name: libmod_reallocbuffer
* *
* Description: * Description:
* Increase the size of I/O buffer by the specified buffer increment. * Increase the size of I/O buffer by the specified buffer increment.
@ -223,10 +223,10 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo);
* *
****************************************************************************/ ****************************************************************************/
int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment); int libmod_reallocbuffer(FAR struct libmod_loadinfo_s *loadinfo, size_t increment);
/**************************************************************************** /****************************************************************************
* Name: mod_findctors * Name: libmod_findctors
* *
* Description: * Description:
* Find C++ static constructors. * Find C++ static constructors.
@ -241,11 +241,11 @@ int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_BINFMT_CONSTRUCTORS #ifdef CONFIG_BINFMT_CONSTRUCTORS
int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo); int libmod_loadctors(FAR struct libmod_loadinfo_s *loadinfo);
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: mod_loaddtors * Name: libmod_loaddtors
* *
* Description: * Description:
* Load pointers to static destructors into an in-memory array. * Load pointers to static destructors into an in-memory array.
@ -260,7 +260,7 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo);
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_BINFMT_CONSTRUCTORS #ifdef CONFIG_BINFMT_CONSTRUCTORS
int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo); int libmod_loaddtors(FAR struct libmod_loadinfo_s *loadinfo);
#endif #endif
#endif /* __BINFMT_LIBELF_LIBELF_H */ #endif /* __BINFMT_LIBELF_LIBELF_H */

View File

@ -68,9 +68,9 @@
#endif #endif
#ifdef CONFIG_ELF_DUMPBUFFER #ifdef CONFIG_ELF_DUMPBUFFER
# define mod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) # define libmod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
#else #else
# define mod_dumpbuffer(m,b,n) # define libmod_dumpbuffer(m,b,n)
#endif #endif
/**************************************************************************** /****************************************************************************
@ -86,16 +86,16 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_readrel * Name: libmod_readrel
* *
* Description: * Description:
* Read the ELF32_Rel structure into memory. * Read the ELF32_Rel structure into memory.
* *
****************************************************************************/ ****************************************************************************/
static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo, static inline int libmod_readrel(FAR struct libmod_loadinfo_s *loadinfo,
FAR const Elf32_Shdr *relsec, FAR const Elf32_Shdr *relsec,
int index, FAR Elf32_Rel *rel) int index, FAR Elf32_Rel *rel)
{ {
off_t offset; off_t offset;
@ -113,11 +113,11 @@ static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo,
/* And, finally, read the symbol table entry into memory */ /* And, finally, read the symbol table entry into memory */
return mod_read(loadinfo, (FAR uint8_t *)rel, sizeof(Elf32_Rel), offset); return libmod_read(loadinfo, (FAR uint8_t *)rel, sizeof(Elf32_Rel), offset);
} }
/**************************************************************************** /****************************************************************************
* Name: mod_relocate and mod_relocateadd * Name: libmod_relocate and libmod_relocateadd
* *
* Description: * Description:
* Perform all relocations associated with a section. * Perform all relocations associated with a section.
@ -128,8 +128,8 @@ static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo,
* *
****************************************************************************/ ****************************************************************************/
static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx, static int libmod_relocate(FAR struct libmod_loadinfo_s *loadinfo, int relidx,
FAR const struct symtab_s *exports, int nexports) FAR const struct symtab_s *exports, int nexports)
{ {
FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx]; FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx];
@ -153,7 +153,7 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx,
/* Read the relocation entry into memory */ /* Read the relocation entry into memory */
ret = mod_readrel(loadinfo, relsec, i, &rel); ret = libmod_readrel(loadinfo, relsec, i, &rel);
if (ret < 0) if (ret < 0)
{ {
bdbg("Section %d reloc %d: Failed to read relocation entry: %d\n", bdbg("Section %d reloc %d: Failed to read relocation entry: %d\n",
@ -169,7 +169,7 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx,
/* Read the symbol table entry into memory */ /* Read the symbol table entry into memory */
ret = mod_readsym(loadinfo, symidx, &sym); ret = libmod_readsym(loadinfo, symidx, &sym);
if (ret < 0) if (ret < 0)
{ {
bdbg("Section %d reloc %d: Failed to read symbol[%d]: %d\n", bdbg("Section %d reloc %d: Failed to read symbol[%d]: %d\n",
@ -179,7 +179,7 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx,
/* Get the value of the symbol (in sym.st_value) */ /* Get the value of the symbol (in sym.st_value) */
ret = mod_symvalue(loadinfo, &sym, exports, nexports); ret = libmod_symvalue(loadinfo, &sym, exports, nexports);
if (ret < 0) if (ret < 0)
{ {
/* The special error -ESRCH is returned only in one condition: The /* The special error -ESRCH is returned only in one condition: The
@ -230,8 +230,8 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx,
return OK; return OK;
} }
static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx, static int libmod_relocateadd(FAR struct libmod_loadinfo_s *loadinfo, int relidx,
FAR const struct symtab_s *exports, int nexports) FAR const struct symtab_s *exports, int nexports)
{ {
bdbg("Not implemented\n"); bdbg("Not implemented\n");
return -ENOSYS; return -ENOSYS;
@ -242,7 +242,7 @@ static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx,
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_bind * Name: libmod_bind
* *
* Description: * Description:
* Bind the imported symbol names in the loaded module described by * Bind the imported symbol names in the loaded module described by
@ -254,28 +254,28 @@ static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx,
* *
****************************************************************************/ ****************************************************************************/
int mod_bind(FAR struct mod_loadinfo_s *loadinfo, int libmod_bind(FAR struct libmod_loadinfo_s *loadinfo,
FAR const struct symtab_s *exports, int nexports) FAR const struct symtab_s *exports, int nexports)
{ {
int ret; int ret;
int i; int i;
/* Find the symbol and string tables */ /* Find the symbol and string tables */
ret = mod_findsymtab(loadinfo); ret = libmod_findsymtab(loadinfo);
if (ret < 0) if (ret < 0)
{ {
return ret; return ret;
} }
/* Allocate an I/O buffer. This buffer is used by mod_symname() to /* Allocate an I/O buffer. This buffer is used by libmod_symname() to
* accumulate the variable length symbol name. * accumulate the variable length symbol name.
*/ */
ret = mod_allocbuffer(loadinfo); ret = libmod_allocbuffer(loadinfo);
if (ret < 0) if (ret < 0)
{ {
bdbg("mod_allocbuffer failed: %d\n", ret); bdbg("libmod_allocbuffer failed: %d\n", ret);
return -ENOMEM; return -ENOMEM;
} }
@ -304,11 +304,11 @@ int mod_bind(FAR struct mod_loadinfo_s *loadinfo,
if (loadinfo->shdr[i].sh_type == SHT_REL) if (loadinfo->shdr[i].sh_type == SHT_REL)
{ {
ret = mod_relocate(loadinfo, i, exports, nexports); ret = libmod_relocate(loadinfo, i, exports, nexports);
} }
else if (loadinfo->shdr[i].sh_type == SHT_RELA) else if (loadinfo->shdr[i].sh_type == SHT_RELA)
{ {
ret = mod_relocateadd(loadinfo, i, exports, nexports); ret = libmod_relocateadd(loadinfo, i, exports, nexports);
} }
if (ret < 0) if (ret < 0)

View File

@ -72,7 +72,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_loadctors * Name: libmod_loadctors
* *
* Description: * Description:
* Load pointers to static constructors into an in-memory array. * Load pointers to static constructors into an in-memory array.
@ -86,7 +86,7 @@
* *
****************************************************************************/ ****************************************************************************/
int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo) int libmod_loadctors(FAR struct libmod_loadinfo_s *loadinfo)
{ {
FAR Elf32_Shdr *shdr; FAR Elf32_Shdr *shdr;
size_t ctorsize; size_t ctorsize;
@ -97,13 +97,13 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo)
DEBUGASSERT(loadinfo->ctors == NULL); DEBUGASSERT(loadinfo->ctors == NULL);
/* Allocate an I/O buffer if necessary. This buffer is used by /* Allocate an I/O buffer if necessary. This buffer is used by
* mod_sectname() to accumulate the variable length symbol name. * libmod_sectname() to accumulate the variable length symbol name.
*/ */
ret = mod_allocbuffer(loadinfo); ret = libmod_allocbuffer(loadinfo);
if (ret < 0) if (ret < 0)
{ {
bdbg("mod_allocbuffer failed: %d\n", ret); bdbg("libmod_allocbuffer failed: %d\n", ret);
return -ENOMEM; return -ENOMEM;
} }
@ -114,14 +114,14 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo)
* in either case. * in either case.
*/ */
ctoridx = mod_findsection(loadinfo, ".ctors"); ctoridx = libmod_findsection(loadinfo, ".ctors");
if (ctoridx < 0) if (ctoridx < 0)
{ {
/* This may not be a failure. -ENOENT indicates that the file has no /* This may not be a failure. -ENOENT indicates that the file has no
* static constructor section. * static constructor section.
*/ */
bvdbg("mod_findsection .ctors section failed: %d\n", ctoridx); bvdbg("libmod_findsection .ctors section failed: %d\n", ctoridx);
return ret == -ENOENT ? OK : ret; return ret == -ENOENT ? OK : ret;
} }
@ -174,7 +174,7 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo)
/* Read the section header table into memory */ /* Read the section header table into memory */
ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->ctors, ctorsize, ret = libmod_read(loadinfo, (FAR uint8_t *)loadinfo->ctors, ctorsize,
shdr->sh_offset); shdr->sh_offset);
if (ret < 0) if (ret < 0)
{ {

View File

@ -72,7 +72,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_loaddtors * Name: libmod_loaddtors
* *
* Description: * Description:
* Load pointers to static destructors into an in-memory array. * Load pointers to static destructors into an in-memory array.
@ -86,7 +86,7 @@
* *
****************************************************************************/ ****************************************************************************/
int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo) int libmod_loaddtors(FAR struct libmod_loadinfo_s *loadinfo)
{ {
FAR Elf32_Shdr *shdr; FAR Elf32_Shdr *shdr;
size_t dtorsize; size_t dtorsize;
@ -97,13 +97,13 @@ int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo)
DEBUGASSERT(loadinfo->dtors == NULL); DEBUGASSERT(loadinfo->dtors == NULL);
/* Allocate an I/O buffer if necessary. This buffer is used by /* Allocate an I/O buffer if necessary. This buffer is used by
* mod_sectname() to accumulate the variable length symbol name. * libmod_sectname() to accumulate the variable length symbol name.
*/ */
ret = mod_allocbuffer(loadinfo); ret = libmod_allocbuffer(loadinfo);
if (ret < 0) if (ret < 0)
{ {
bdbg("mod_allocbuffer failed: %d\n", ret); bdbg("libmod_allocbuffer failed: %d\n", ret);
return -ENOMEM; return -ENOMEM;
} }
@ -114,14 +114,14 @@ int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo)
* in either case. * in either case.
*/ */
dtoridx = mod_findsection(loadinfo, ".dtors"); dtoridx = libmod_findsection(loadinfo, ".dtors");
if (dtoridx < 0) if (dtoridx < 0)
{ {
/* This may not be a failure. -ENOENT indicates that the file has no /* This may not be a failure. -ENOENT indicates that the file has no
* static destructor section. * static destructor section.
*/ */
bvdbg("mod_findsection .dtors section failed: %d\n", dtoridx); bvdbg("libmod_findsection .dtors section failed: %d\n", dtoridx);
return ret == -ENOENT ? OK : ret; return ret == -ENOENT ? OK : ret;
} }
@ -174,7 +174,7 @@ int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo)
/* Read the section header table into memory */ /* Read the section header table into memory */
ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->dtors, dtorsize, ret = libmod_read(loadinfo, (FAR uint8_t *)loadinfo->dtors, dtorsize,
shdr->sh_offset); shdr->sh_offset);
if (ret < 0) if (ret < 0)
{ {

View File

@ -65,9 +65,9 @@
#endif #endif
#ifdef CONFIG_ELF_DUMPBUFFER #ifdef CONFIG_ELF_DUMPBUFFER
# define mod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n) # define libmod_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
#else #else
# define mod_dumpbuffer(m,b,n) # define libmod_dumpbuffer(m,b,n)
#endif #endif
/**************************************************************************** /****************************************************************************
@ -79,7 +79,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_filelen * Name: libmod_filelen
* *
* Description: * Description:
* Get the size of the ELF file * Get the size of the ELF file
@ -90,8 +90,8 @@
* *
****************************************************************************/ ****************************************************************************/
static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo, static inline int libmod_filelen(FAR struct libmod_loadinfo_s *loadinfo,
FAR const char *filename) FAR const char *filename)
{ {
struct stat buf; struct stat buf;
int ret; int ret;
@ -129,7 +129,7 @@ static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo,
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_initialize * Name: libmod_initialize
* *
* Description: * Description:
* This function is called to configure the library to process an ELF * This function is called to configure the library to process an ELF
@ -141,7 +141,8 @@ static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo,
* *
****************************************************************************/ ****************************************************************************/
int mod_initialize(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo) int libmod_initialize(FAR const char *filename,
FAR struct libmod_loadinfo_s *loadinfo)
{ {
int ret; int ret;
@ -149,14 +150,14 @@ int mod_initialize(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo
/* Clear the load info structure */ /* Clear the load info structure */
memset(loadinfo, 0, sizeof(struct mod_loadinfo_s)); memset(loadinfo, 0, sizeof(struct libmod_loadinfo_s));
/* Get the length of the file. */ /* Get the length of the file. */
ret = mod_filelen(loadinfo, filename); ret = libmod_filelen(loadinfo, filename);
if (ret < 0) if (ret < 0)
{ {
bdbg("mod_filelen failed: %d\n", ret); bdbg("libmod_filelen failed: %d\n", ret);
return ret; return ret;
} }
@ -172,24 +173,26 @@ int mod_initialize(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo
/* Read the ELF ehdr from offset 0 */ /* Read the ELF ehdr from offset 0 */
ret = mod_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr), 0); ret = libmod_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr,
sizeof(Elf32_Ehdr), 0);
if (ret < 0) if (ret < 0)
{ {
bdbg("Failed to read ELF header: %d\n", ret); bdbg("Failed to read ELF header: %d\n", ret);
return ret; return ret;
} }
mod_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr)); libmod_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr,
sizeof(Elf32_Ehdr));
/* Verify the ELF header */ /* Verify the ELF header */
ret = mod_verifyheader(&loadinfo->ehdr); ret = libmod_verifyheader(&loadinfo->ehdr);
if (ret < 0) if (ret < 0)
{ {
/* This may not be an error because we will be called to attempt loading /* This may not be an error because we will be called to attempt loading
* EVERY binary. If mod_verifyheader() does not recognize the ELF header, * EVERY binary. If libmod_verifyheader() does not recognize the ELF header,
* it will -ENOEXEC whcih simply informs the system that the file is not an * it will -ENOEXEC whcih simply informs the system that the file is not an
* ELF file. mod_verifyheader() will return other errors if the ELF header * ELF file. libmod_verifyheader() will return other errors if the ELF header
* is not correctly formed. * is not correctly formed.
*/ */

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* binfmt/libmodule/mod_iobuffer.c * binfmt/libmodule/libmodule_iobuffer.c
* *
* Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
@ -64,7 +64,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_allocbuffer * Name: libmod_allocbuffer
* *
* Description: * Description:
* Perform the initial allocation of the I/O buffer, if it has not already * Perform the initial allocation of the I/O buffer, if it has not already
@ -76,7 +76,7 @@
* *
****************************************************************************/ ****************************************************************************/
int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) int libmod_allocbuffer(FAR struct libmod_loadinfo_s *loadinfo)
{ {
/* Has a buffer been allocated> */ /* Has a buffer been allocated> */
@ -98,7 +98,7 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_reallocbuffer * Name: libmod_reallocbuffer
* *
* Description: * Description:
* Increase the size of I/O buffer by the specified buffer increment. * Increase the size of I/O buffer by the specified buffer increment.
@ -109,7 +109,7 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo)
* *
****************************************************************************/ ****************************************************************************/
int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment) int libmod_reallocbuffer(FAR struct libmod_loadinfo_s *loadinfo, size_t increment)
{ {
FAR void *buffer; FAR void *buffer;
size_t newsize; size_t newsize;

View File

@ -79,7 +79,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_elfsize * Name: libmod_elfsize
* *
* Description: * Description:
* Calculate total memory allocation for the ELF file. * Calculate total memory allocation for the ELF file.
@ -90,7 +90,7 @@
* *
****************************************************************************/ ****************************************************************************/
static void mod_elfsize(struct mod_loadinfo_s *loadinfo) static void libmod_elfsize(struct libmod_loadinfo_s *loadinfo)
{ {
size_t textsize; size_t textsize;
size_t datasize; size_t datasize;
@ -133,7 +133,7 @@ static void mod_elfsize(struct mod_loadinfo_s *loadinfo)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_loadfile * Name: libmod_loadfile
* *
* Description: * Description:
* Read the section data into memory. Section addresses in the shdr[] are * Read the section data into memory. Section addresses in the shdr[] are
@ -145,7 +145,7 @@ static void mod_elfsize(struct mod_loadinfo_s *loadinfo)
* *
****************************************************************************/ ****************************************************************************/
static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo) static inline int libmod_loadfile(FAR struct libmod_loadinfo_s *loadinfo)
{ {
FAR uint8_t *text; FAR uint8_t *text;
FAR uint8_t *data; FAR uint8_t *data;
@ -192,7 +192,7 @@ static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo)
{ {
/* Read the section data from sh_offset to the memory region */ /* Read the section data from sh_offset to the memory region */
ret = mod_read(loadinfo, *pptr, shdr->sh_size, shdr->sh_offset); ret = libmod_read(loadinfo, *pptr, shdr->sh_size, shdr->sh_offset);
if (ret < 0) if (ret < 0)
{ {
bdbg("ERROR: Failed to read section %d: %d\n", i, ret); bdbg("ERROR: Failed to read section %d: %d\n", i, ret);
@ -229,7 +229,7 @@ static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_load * Name: libmod_load
* *
* Description: * Description:
* Loads the binary into memory, allocating memory, performing relocations * Loads the binary into memory, allocating memory, performing relocations
@ -241,7 +241,7 @@ static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo)
* *
****************************************************************************/ ****************************************************************************/
int mod_load(FAR struct mod_loadinfo_s *loadinfo) int libmod_load(FAR struct libmod_loadinfo_s *loadinfo)
{ {
size_t heapsize; size_t heapsize;
#ifdef CONFIG_UCLIBCXX_EXCEPTION #ifdef CONFIG_UCLIBCXX_EXCEPTION
@ -254,16 +254,16 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo)
/* Load section headers into memory */ /* Load section headers into memory */
ret = mod_loadshdrs(loadinfo); ret = libmod_loadshdrs(loadinfo);
if (ret < 0) if (ret < 0)
{ {
bdbg("ERROR: mod_loadshdrs failed: %d\n", ret); bdbg("ERROR: libmod_loadshdrs failed: %d\n", ret);
goto errout_with_buffers; goto errout_with_buffers;
} }
/* Determine total size to allocate */ /* Determine total size to allocate */
mod_elfsize(loadinfo); libmod_elfsize(loadinfo);
/* Determine the heapsize to allocate. */ /* Determine the heapsize to allocate. */
@ -285,36 +285,36 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo)
/* Load ELF section data into memory */ /* Load ELF section data into memory */
ret = mod_loadfile(loadinfo); ret = libmod_loadfile(loadinfo);
if (ret < 0) if (ret < 0)
{ {
bdbg("ERROR: mod_loadfile failed: %d\n", ret); bdbg("ERROR: libmod_loadfile failed: %d\n", ret);
goto errout_with_buffers; goto errout_with_buffers;
} }
/* Load static constructors and destructors. */ /* Load static constructors and destructors. */
#ifdef CONFIG_BINFMT_CONSTRUCTORS #ifdef CONFIG_BINFMT_CONSTRUCTORS
ret = mod_loadctors(loadinfo); ret = libmod_loadctors(loadinfo);
if (ret < 0) if (ret < 0)
{ {
bdbg("ERROR: mod_loadctors failed: %d\n", ret); bdbg("ERROR: libmod_loadctors failed: %d\n", ret);
goto errout_with_buffers; goto errout_with_buffers;
} }
ret = mod_loaddtors(loadinfo); ret = libmod_loaddtors(loadinfo);
if (ret < 0) if (ret < 0)
{ {
bdbg("ERROR: mod_loaddtors failed: %d\n", ret); bdbg("ERROR: libmod_loaddtors failed: %d\n", ret);
goto errout_with_buffers; goto errout_with_buffers;
} }
#endif #endif
#ifdef CONFIG_UCLIBCXX_EXCEPTION #ifdef CONFIG_UCLIBCXX_EXCEPTION
exidx = mod_findsection(loadinfo, CONFIG_ELF_EXIDX_SECTNAME); exidx = libmod_findsection(loadinfo, CONFIG_ELF_EXIDX_SECTNAME);
if (exidx < 0) if (exidx < 0)
{ {
bvdbg("mod_findsection: Exception Index section not found: %d\n", exidx); bvdbg("libmod_findsection: Exception Index section not found: %d\n", exidx);
} }
else else
{ {
@ -327,7 +327,7 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo)
/* Error exits */ /* Error exits */
errout_with_buffers: errout_with_buffers:
mod_unload(loadinfo); libmod_unload(loadinfo);
return ret; return ret;
} }

View File

@ -64,11 +64,11 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_dumpreaddata * Name: libmod_dumpreaddata
****************************************************************************/ ****************************************************************************/
#if defined(ELF_DUMP_READDATA) #if defined(ELF_DUMP_READDATA)
static inline void mod_dumpreaddata(FAR char *buffer, int buflen) static inline void libmod_dumpreaddata(FAR char *buffer, int buflen)
{ {
FAR uint32_t *buf32 = (FAR uint32_t *)buffer; FAR uint32_t *buf32 = (FAR uint32_t *)buffer;
int i; int i;
@ -86,7 +86,7 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen)
} }
} }
#else #else
# define mod_dumpreaddata(b,n) # define libmod_dumpreaddata(b,n)
#endif #endif
/**************************************************************************** /****************************************************************************
@ -94,7 +94,7 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_read * Name: libmod_read
* *
* Description: * Description:
* Read 'readsize' bytes from the object file at 'offset'. The data is * Read 'readsize' bytes from the object file at 'offset'. The data is
@ -106,8 +106,8 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen)
* *
****************************************************************************/ ****************************************************************************/
int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
size_t readsize, off_t offset) size_t readsize, off_t offset)
{ {
ssize_t nbytes; /* Number of bytes read */ ssize_t nbytes; /* Number of bytes read */
off_t rpos; /* Position returned by lseek */ off_t rpos; /* Position returned by lseek */
@ -158,6 +158,6 @@ int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
} }
} }
mod_dumpreaddata(buffer, readsize); libmod_dumpreaddata(buffer, readsize);
return OK; return OK;
} }

View File

@ -63,7 +63,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_sectname * Name: libmod_sectname
* *
* Description: * Description:
* Get the symbol name in loadinfo->iobuffer[]. * Get the symbol name in loadinfo->iobuffer[].
@ -74,8 +74,8 @@
* *
****************************************************************************/ ****************************************************************************/
static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo,
FAR const Elf32_Shdr *shdr) FAR const Elf32_Shdr *shdr)
{ {
FAR Elf32_Shdr *shstr; FAR Elf32_Shdr *shstr;
FAR uint8_t *buffer; FAR uint8_t *buffer;
@ -136,7 +136,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo,
/* Read that number of bytes into the array */ /* Read that number of bytes into the array */
buffer = &loadinfo->iobuffer[bytesread]; buffer = &loadinfo->iobuffer[bytesread];
ret = mod_read(loadinfo, buffer, readlen, offset); ret = libmod_read(loadinfo, buffer, readlen, offset);
if (ret < 0) if (ret < 0)
{ {
bdbg("Failed to read section name\n"); bdbg("Failed to read section name\n");
@ -156,10 +156,10 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo,
/* No.. then we have to read more */ /* No.. then we have to read more */
ret = mod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); ret = libmod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR);
if (ret < 0) if (ret < 0)
{ {
bdbg("mod_reallocbuffer failed: %d\n", ret); bdbg("libmod_reallocbuffer failed: %d\n", ret);
return ret; return ret;
} }
} }
@ -174,7 +174,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo,
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_loadshdrs * Name: libmod_loadshdrs
* *
* Description: * Description:
* Loads section headers into memory. * Loads section headers into memory.
@ -185,7 +185,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo,
* *
****************************************************************************/ ****************************************************************************/
int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) int libmod_loadshdrs(FAR struct libmod_loadinfo_s *loadinfo)
{ {
size_t shdrsize; size_t shdrsize;
int ret; int ret;
@ -221,8 +221,8 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo)
/* Read the section header table into memory */ /* Read the section header table into memory */
ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, ret = libmod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize,
loadinfo->ehdr.e_shoff); loadinfo->ehdr.e_shoff);
if (ret < 0) if (ret < 0)
{ {
bdbg("Failed to read section header table: %d\n", ret); bdbg("Failed to read section header table: %d\n", ret);
@ -232,7 +232,7 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_findsection * Name: libmod_findsection
* *
* Description: * Description:
* A section by its name. * A section by its name.
@ -247,8 +247,8 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo)
* *
****************************************************************************/ ****************************************************************************/
int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, int libmod_findsection(FAR struct libmod_loadinfo_s *loadinfo,
FAR const char *sectname) FAR const char *sectname)
{ {
FAR const Elf32_Shdr *shdr; FAR const Elf32_Shdr *shdr;
int ret; int ret;
@ -261,10 +261,10 @@ int mod_findsection(FAR struct mod_loadinfo_s *loadinfo,
/* Get the name of this section */ /* Get the name of this section */
shdr = &loadinfo->shdr[i]; shdr = &loadinfo->shdr[i];
ret = mod_sectname(loadinfo, shdr); ret = libmod_sectname(loadinfo, shdr);
if (ret < 0) if (ret < 0)
{ {
bdbg("mod_sectname failed: %d\n", ret); bdbg("libmod_sectname failed: %d\n", ret);
return ret; return ret;
} }

View File

@ -67,7 +67,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_symname * Name: libmod_symname
* *
* Description: * Description:
* Get the symbol name in loadinfo->iobuffer[]. * Get the symbol name in loadinfo->iobuffer[].
@ -82,8 +82,8 @@
* *
****************************************************************************/ ****************************************************************************/
static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo,
FAR const Elf32_Sym *sym) FAR const Elf32_Sym *sym)
{ {
FAR uint8_t *buffer; FAR uint8_t *buffer;
off_t offset; off_t offset;
@ -126,10 +126,10 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo,
/* Read that number of bytes into the array */ /* Read that number of bytes into the array */
buffer = &loadinfo->iobuffer[bytesread]; buffer = &loadinfo->iobuffer[bytesread];
ret = mod_read(loadinfo, buffer, readlen, offset); ret = libmod_read(loadinfo, buffer, readlen, offset);
if (ret < 0) if (ret < 0)
{ {
bdbg("mod_read failed: %d\n", ret); bdbg("libmod_read failed: %d\n", ret);
return ret; return ret;
} }
@ -146,10 +146,10 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo,
/* No.. then we have to read more */ /* No.. then we have to read more */
ret = mod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); ret = libmod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR);
if (ret < 0) if (ret < 0)
{ {
bdbg("mod_reallocbuffer failed: %d\n", ret); bdbg("libmod_reallocbuffer failed: %d\n", ret);
return ret; return ret;
} }
} }
@ -164,7 +164,7 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo,
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_findsymtab * Name: libmod_findsymtab
* *
* Description: * Description:
* Find the symbol table section. * Find the symbol table section.
@ -175,7 +175,7 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo,
* *
****************************************************************************/ ****************************************************************************/
int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo) int libmod_findsymtab(FAR struct libmod_loadinfo_s *loadinfo)
{ {
int i; int i;
@ -203,7 +203,7 @@ int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_readsym * Name: libmod_readsym
* *
* Description: * Description:
* Read the ELFT symbol structure at the specfied index into memory. * Read the ELFT symbol structure at the specfied index into memory.
@ -219,8 +219,8 @@ int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo)
* *
****************************************************************************/ ****************************************************************************/
int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index,
FAR Elf32_Sym *sym) FAR Elf32_Sym *sym)
{ {
FAR Elf32_Shdr *symtab = &loadinfo->shdr[loadinfo->symtabidx]; FAR Elf32_Shdr *symtab = &loadinfo->shdr[loadinfo->symtabidx];
off_t offset; off_t offset;
@ -239,11 +239,11 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index,
/* And, finally, read the symbol table entry into memory */ /* And, finally, read the symbol table entry into memory */
return mod_read(loadinfo, (FAR uint8_t *)sym, sizeof(Elf32_Sym), offset); return libmod_read(loadinfo, (FAR uint8_t *)sym, sizeof(Elf32_Sym), offset);
} }
/**************************************************************************** /****************************************************************************
* Name: mod_symvalue * Name: libmod_symvalue
* *
* Description: * Description:
* Get the value of a symbol. The updated value of the symbol is returned * Get the value of a symbol. The updated value of the symbol is returned
@ -265,8 +265,8 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index,
* *
****************************************************************************/ ****************************************************************************/
int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
FAR const struct symtab_s *exports, int nexports) FAR const struct symtab_s *exports, int nexports)
{ {
FAR const struct symtab_s *symbol; FAR const struct symtab_s *symbol;
uintptr_t secbase; uintptr_t secbase;
@ -294,7 +294,7 @@ int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
{ {
/* Get the name of the undefined symbol */ /* Get the name of the undefined symbol */
ret = mod_symname(loadinfo, sym); ret = libmod_symname(loadinfo, sym);
if (ret < 0) if (ret < 0)
{ {
/* There are a few relocations for a few architectures that do /* There are a few relocations for a few architectures that do

View File

@ -65,11 +65,11 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_uninit * Name: libmod_uninitialize
* *
* Description: * Description:
* Releases any resources committed by mod_initialize(). This essentially * Releases any resources committed by libmod_initialize(). This essentially
* undoes the actions of mod_initialize. * undoes the actions of libmod_initialize.
* *
* Returned Value: * Returned Value:
* 0 (OK) is returned on success and a negated errno is returned on * 0 (OK) is returned on success and a negated errno is returned on
@ -77,11 +77,11 @@
* *
****************************************************************************/ ****************************************************************************/
int mod_uninit(struct mod_loadinfo_s *loadinfo) int libmod_uninitialize(struct libmod_loadinfo_s *loadinfo)
{ {
/* Free all working buffers */ /* Free all working buffers */
mod_freebuffers(loadinfo); libmod_freebuffers(loadinfo);
/* Close the ELF file */ /* Close the ELF file */
@ -94,7 +94,7 @@ int mod_uninit(struct mod_loadinfo_s *loadinfo)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_freebuffers * Name: libmod_freebuffers
* *
* Description: * Description:
* Release all working buffers. * Release all working buffers.
@ -105,7 +105,7 @@ int mod_uninit(struct mod_loadinfo_s *loadinfo)
* *
****************************************************************************/ ****************************************************************************/
int mod_freebuffers(struct mod_loadinfo_s *loadinfo) int libmod_freebuffers(struct libmod_loadinfo_s *loadinfo)
{ {
/* Release all working allocations */ /* Release all working allocations */

View File

@ -64,11 +64,11 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_unload * Name: libmod_unload
* *
* Description: * Description:
* This function unloads the object from memory. This essentially undoes * This function unloads the object from memory. This essentially undoes
* the actions of mod_load. It is called only under certain error * the actions of libmod_load. It is called only under certain error
* conditions after the module has been loaded but not yet started. * conditions after the module has been loaded but not yet started.
* *
* Returned Value: * Returned Value:
@ -77,11 +77,11 @@
* *
****************************************************************************/ ****************************************************************************/
int mod_unload(struct mod_loadinfo_s *loadinfo) int libmod_unload(struct libmod_loadinfo_s *loadinfo)
{ {
/* Free all working buffers */ /* Free all working buffers */
mod_freebuffers(loadinfo); libmod_freebuffers(loadinfo);
/* Release memory holding the relocated ELF image */ /* Release memory holding the relocated ELF image */

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* binfmt/libmodule/mod_verify.c * binfmt/libmodule/libmodule_verify.c
* *
* Copyright (C) 2012 Gregory Nutt. All rights reserved. * Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
@ -67,7 +67,7 @@ static const char g_modmagic[EI_MAGIC_SIZE] =
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_verifyheader * Name: libmod_verifyheader
* *
* Description: * Description:
* Given the header from a possible ELF executable, verify that it * Given the header from a possible ELF executable, verify that it
@ -83,7 +83,7 @@ static const char g_modmagic[EI_MAGIC_SIZE] =
* *
****************************************************************************/ ****************************************************************************/
int mod_verifyheader(FAR const Elf32_Ehdr *ehdr) int libmod_verifyheader(FAR const Elf32_Ehdr *ehdr)
{ {
if (!ehdr) if (!ehdr)
{ {

View File

@ -182,34 +182,8 @@ static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo)
static void mod_dumpentrypt(FAR struct binary_s *binp, static void mod_dumpentrypt(FAR struct binary_s *binp,
FAR struct mod_loadinfo_s *loadinfo) FAR struct mod_loadinfo_s *loadinfo)
{ {
#ifdef CONFIG_ARCH_ADDRENV
int ret;
/* If CONFIG_ARCH_ADDRENV=y, then the loaded ELF lies in a virtual address
* space that may not be in place now. mod_addrenv_select() will
* temporarily instantiate that address space.
*/
ret = mod_addrenv_select(loadinfo);
if (ret < 0)
{
bdbg("ERROR: mod_addrenv_select() failed: %d\n", ret);
return;
}
#endif
mod_dumpbuffer("Entry code", (FAR const uint8_t *)binp->entrypt, mod_dumpbuffer("Entry code", (FAR const uint8_t *)binp->entrypt,
MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512)); MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512));
#ifdef CONFIG_ARCH_ADDRENV
/* Restore the original address environment */
ret = mod_addrenv_restore(loadinfo);
if (ret < 0)
{
bdbg("ERROR: mod_addrenv_restore() failed: %d\n", ret);
}
#endif
} }
#else #else
# define mod_dumpentrypt(b,l) # define mod_dumpentrypt(b,l)
@ -233,7 +207,7 @@ static int mod_loadbinary(FAR struct binary_s *binp)
/* Initialize the ELF library to load the program binary. */ /* Initialize the ELF library to load the program binary. */
ret = mod_init(binp->filename, &loadinfo); ret = libmod_initialize(binp->filename, &loadinfo);
mod_dumploadinfo(&loadinfo); mod_dumploadinfo(&loadinfo);
if (ret != 0) if (ret != 0)
{ {
@ -243,7 +217,7 @@ static int mod_loadbinary(FAR struct binary_s *binp)
/* Load the program binary */ /* Load the program binary */
ret = mod_load(&loadinfo); ret = libmod_load(&loadinfo);
mod_dumploadinfo(&loadinfo); mod_dumploadinfo(&loadinfo);
if (ret != 0) if (ret != 0)
{ {
@ -253,7 +227,7 @@ static int mod_loadbinary(FAR struct binary_s *binp)
/* Bind the program to the exported symbol table */ /* Bind the program to the exported symbol table */
ret = mod_bind(&loadinfo, binp->exports, binp->nexports); ret = libmod_bind(&loadinfo, binp->exports, binp->nexports);
if (ret != 0) if (ret != 0)
{ {
bdbg("Failed to bind symbols program binary: %d\n", ret); bdbg("Failed to bind symbols program binary: %d\n", ret);
@ -273,11 +247,7 @@ static int mod_loadbinary(FAR struct binary_s *binp)
* a memory leak? * a memory leak?
*/ */
#ifdef CONFIG_ARCH_ADDRENV
# warning "REVISIT"
#else
binp->alloc[0] = (FAR void *)loadinfo.textalloc; binp->alloc[0] = (FAR void *)loadinfo.textalloc;
#endif
#ifdef CONFIG_BINFMT_CONSTRUCTORS #ifdef CONFIG_BINFMT_CONSTRUCTORS
/* Save information about constructors. NOTE: destructors are not /* Save information about constructors. NOTE: destructors are not
@ -293,22 +263,14 @@ static int mod_loadbinary(FAR struct binary_s *binp)
binp->ndtors = loadinfo.ndtors; binp->ndtors = loadinfo.ndtors;
#endif #endif
#ifdef CONFIG_ARCH_ADDRENV
/* Save the address environment in the binfmt structure. This will be
* needed when the module is executed.
*/
up_addrenv_clone(&loadinfo.addrenv, &binp->addrenv);
#endif
mod_dumpentrypt(binp, &loadinfo); mod_dumpentrypt(binp, &loadinfo);
mod_uninit(&loadinfo); libmod_uninitialize(&loadinfo);
return OK; return OK;
errout_with_load: errout_with_load:
mod_unload(&loadinfo); libmod_unload(&loadinfo);
errout_with_init: errout_with_init:
mod_uninit(&loadinfo); libmod_uninitialize(&loadinfo);
errout: errout:
return ret; return ret;
} }

View File

@ -336,6 +336,7 @@ int up_relocateadd(FAR const Elf32_Rela *rel,
* Always returns Zero (OK). * Always returns Zero (OK).
* *
****************************************************************************/ ****************************************************************************/
int up_init_exidx(Elf32_Addr address, Elf32_Word size); int up_init_exidx(Elf32_Addr address, Elf32_Word size);
#endif #endif

View File

@ -161,7 +161,7 @@ extern "C"
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_init * Name: libmod_initialize
* *
* Description: * Description:
* This function is called to configure the library to process an kernel * This function is called to configure the library to process an kernel
@ -173,10 +173,11 @@ extern "C"
* *
****************************************************************************/ ****************************************************************************/
int mod_init(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo); int libmod_initalize(FAR const char *filename,
FAR struct mod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_uninit * Name: libmod_uninitialize
* *
* Description: * Description:
* Releases any resources committed by mod_init(). This essentially * Releases any resources committed by mod_init(). This essentially
@ -188,7 +189,7 @@ int mod_init(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo);
* *
****************************************************************************/ ****************************************************************************/
int mod_uninit(FAR struct mod_loadinfo_s *loadinfo); int libmod_uninitialize(FAR struct mod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_load * Name: mod_load
@ -336,6 +337,7 @@ int up_relocateadd(FAR const Elf32_Rela *rel,
* Always returns Zero (OK). * Always returns Zero (OK).
* *
****************************************************************************/ ****************************************************************************/
int up_init_exidx(Elf32_Addr address, Elf32_Word size); int up_init_exidx(Elf32_Addr address, Elf32_Word size);
#endif #endif