diff --git a/binfmt/libmodule/libmodule.h b/binfmt/libmodule/libmodule.h index eeed0498df..fb003a7ac9 100644 --- a/binfmt/libmodule/libmodule.h +++ b/binfmt/libmodule/libmodule.h @@ -57,7 +57,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_verifyheader + * Name: libmod_verifyheader * * Description: * 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: * 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, - size_t readsize, off_t offset); +int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer, + size_t readsize, off_t offset); /**************************************************************************** - * Name: mod_loadshdrs + * Name: libmod_loadshdrs * * Description: * 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: * 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, - FAR const char *sectname); +int libmod_findsection(FAR struct libmod_loadinfo_s *loadinfo, + FAR const char *sectname); /**************************************************************************** - * Name: mod_findsymtab + * Name: libmod_findsymtab * * Description: * 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: * 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, - FAR Elf32_Sym *sym); +int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index, + FAR Elf32_Sym *sym); /**************************************************************************** - * Name: mod_symvalue + * Name: libmod_symvalue * * Description: * 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, - FAR const struct symtab_s *exports, int nexports); +int libmod_symvalue(FAR struct libmod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym, + FAR const struct symtab_s *exports, int nexports); /**************************************************************************** - * Name: mod_freebuffers + * Name: libmod_freebuffers * * Description: * 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: * 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: * 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: * Find C++ static constructors. @@ -241,11 +241,11 @@ int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment); ****************************************************************************/ #ifdef CONFIG_BINFMT_CONSTRUCTORS -int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo); +int libmod_loadctors(FAR struct libmod_loadinfo_s *loadinfo); #endif /**************************************************************************** - * Name: mod_loaddtors + * Name: libmod_loaddtors * * Description: * 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 -int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo); +int libmod_loaddtors(FAR struct libmod_loadinfo_s *loadinfo); #endif #endif /* __BINFMT_LIBELF_LIBELF_H */ diff --git a/binfmt/libmodule/libmodule_bind.c b/binfmt/libmodule/libmodule_bind.c index 8b5b680c8b..199be22faa 100644 --- a/binfmt/libmodule/libmodule_bind.c +++ b/binfmt/libmodule/libmodule_bind.c @@ -68,9 +68,9 @@ #endif #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 -# define mod_dumpbuffer(m,b,n) +# define libmod_dumpbuffer(m,b,n) #endif /**************************************************************************** @@ -86,16 +86,16 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_readrel + * Name: libmod_readrel * * Description: * Read the ELF32_Rel structure into memory. * ****************************************************************************/ -static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo, - FAR const Elf32_Shdr *relsec, - int index, FAR Elf32_Rel *rel) +static inline int libmod_readrel(FAR struct libmod_loadinfo_s *loadinfo, + FAR const Elf32_Shdr *relsec, + int index, FAR Elf32_Rel *rel) { 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 */ - 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: * 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, - FAR const struct symtab_s *exports, int nexports) +static int libmod_relocate(FAR struct libmod_loadinfo_s *loadinfo, int relidx, + FAR const struct symtab_s *exports, int nexports) { 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 */ - ret = mod_readrel(loadinfo, relsec, i, &rel); + ret = libmod_readrel(loadinfo, relsec, i, &rel); if (ret < 0) { 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 */ - ret = mod_readsym(loadinfo, symidx, &sym); + ret = libmod_readsym(loadinfo, symidx, &sym); if (ret < 0) { 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) */ - ret = mod_symvalue(loadinfo, &sym, exports, nexports); + ret = libmod_symvalue(loadinfo, &sym, exports, nexports); if (ret < 0) { /* 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; } -static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx, - FAR const struct symtab_s *exports, int nexports) +static int libmod_relocateadd(FAR struct libmod_loadinfo_s *loadinfo, int relidx, + FAR const struct symtab_s *exports, int nexports) { bdbg("Not implemented\n"); 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: * 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, - FAR const struct symtab_s *exports, int nexports) +int libmod_bind(FAR struct libmod_loadinfo_s *loadinfo, + FAR const struct symtab_s *exports, int nexports) { int ret; int i; /* Find the symbol and string tables */ - ret = mod_findsymtab(loadinfo); + ret = libmod_findsymtab(loadinfo); if (ret < 0) { 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. */ - ret = mod_allocbuffer(loadinfo); + ret = libmod_allocbuffer(loadinfo); if (ret < 0) { - bdbg("mod_allocbuffer failed: %d\n", ret); + bdbg("libmod_allocbuffer failed: %d\n", ret); return -ENOMEM; } @@ -304,11 +304,11 @@ int mod_bind(FAR struct mod_loadinfo_s *loadinfo, 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) { - ret = mod_relocateadd(loadinfo, i, exports, nexports); + ret = libmod_relocateadd(loadinfo, i, exports, nexports); } if (ret < 0) diff --git a/binfmt/libmodule/libmodule_ctors.c b/binfmt/libmodule/libmodule_ctors.c index e89d310fbe..ea79cac7ee 100644 --- a/binfmt/libmodule/libmodule_ctors.c +++ b/binfmt/libmodule/libmodule_ctors.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_loadctors + * Name: libmod_loadctors * * Description: * 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; size_t ctorsize; @@ -97,13 +97,13 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo) DEBUGASSERT(loadinfo->ctors == NULL); /* 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) { - bdbg("mod_allocbuffer failed: %d\n", ret); + bdbg("libmod_allocbuffer failed: %d\n", ret); return -ENOMEM; } @@ -114,14 +114,14 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo) * in either case. */ - ctoridx = mod_findsection(loadinfo, ".ctors"); + ctoridx = libmod_findsection(loadinfo, ".ctors"); if (ctoridx < 0) { /* This may not be a failure. -ENOENT indicates that the file has no * 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; } @@ -174,7 +174,7 @@ int mod_loadctors(FAR struct mod_loadinfo_s *loadinfo) /* 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); if (ret < 0) { diff --git a/binfmt/libmodule/libmodule_dtors.c b/binfmt/libmodule/libmodule_dtors.c index d94c341ed7..9102ceaac0 100644 --- a/binfmt/libmodule/libmodule_dtors.c +++ b/binfmt/libmodule/libmodule_dtors.c @@ -72,7 +72,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_loaddtors + * Name: libmod_loaddtors * * Description: * 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; size_t dtorsize; @@ -97,13 +97,13 @@ int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo) DEBUGASSERT(loadinfo->dtors == NULL); /* 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) { - bdbg("mod_allocbuffer failed: %d\n", ret); + bdbg("libmod_allocbuffer failed: %d\n", ret); return -ENOMEM; } @@ -114,14 +114,14 @@ int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo) * in either case. */ - dtoridx = mod_findsection(loadinfo, ".dtors"); + dtoridx = libmod_findsection(loadinfo, ".dtors"); if (dtoridx < 0) { /* This may not be a failure. -ENOENT indicates that the file has no * 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; } @@ -174,7 +174,7 @@ int mod_loaddtors(FAR struct mod_loadinfo_s *loadinfo) /* 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); if (ret < 0) { diff --git a/binfmt/libmodule/libmodule_init.c b/binfmt/libmodule/libmodule_init.c index a1ba9b0859..c5f737e36f 100644 --- a/binfmt/libmodule/libmodule_init.c +++ b/binfmt/libmodule/libmodule_init.c @@ -65,9 +65,9 @@ #endif #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 -# define mod_dumpbuffer(m,b,n) +# define libmod_dumpbuffer(m,b,n) #endif /**************************************************************************** @@ -79,7 +79,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_filelen + * Name: libmod_filelen * * Description: * Get the size of the ELF file @@ -90,8 +90,8 @@ * ****************************************************************************/ -static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo, - FAR const char *filename) +static inline int libmod_filelen(FAR struct libmod_loadinfo_s *loadinfo, + FAR const char *filename) { struct stat buf; int ret; @@ -129,7 +129,7 @@ static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo, ****************************************************************************/ /**************************************************************************** - * Name: mod_initialize + * Name: libmod_initialize * * Description: * 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; @@ -149,14 +150,14 @@ int mod_initialize(FAR const char *filename, FAR struct mod_loadinfo_s *loadinfo /* 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. */ - ret = mod_filelen(loadinfo, filename); + ret = libmod_filelen(loadinfo, filename); if (ret < 0) { - bdbg("mod_filelen failed: %d\n", ret); + bdbg("libmod_filelen failed: %d\n", 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 */ - 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) { bdbg("Failed to read ELF header: %d\n", 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 */ - ret = mod_verifyheader(&loadinfo->ehdr); + ret = libmod_verifyheader(&loadinfo->ehdr); if (ret < 0) { /* 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 - * 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. */ diff --git a/binfmt/libmodule/libmodule_iobuffer.c b/binfmt/libmodule/libmodule_iobuffer.c index 17f8da4c5c..296c8c2c94 100644 --- a/binfmt/libmodule/libmodule_iobuffer.c +++ b/binfmt/libmodule/libmodule_iobuffer.c @@ -1,5 +1,5 @@ /**************************************************************************** - * binfmt/libmodule/mod_iobuffer.c + * binfmt/libmodule/libmodule_iobuffer.c * * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -64,7 +64,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_allocbuffer + * Name: libmod_allocbuffer * * Description: * 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> */ @@ -98,7 +98,7 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_reallocbuffer + * Name: libmod_reallocbuffer * * Description: * 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; size_t newsize; diff --git a/binfmt/libmodule/libmodule_load.c b/binfmt/libmodule/libmodule_load.c index af89d3ff63..6c55f853de 100644 --- a/binfmt/libmodule/libmodule_load.c +++ b/binfmt/libmodule/libmodule_load.c @@ -79,7 +79,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_elfsize + * Name: libmod_elfsize * * Description: * 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 datasize; @@ -133,7 +133,7 @@ static void mod_elfsize(struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_loadfile + * Name: libmod_loadfile * * Description: * 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 *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 */ - 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) { 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: * 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; #ifdef CONFIG_UCLIBCXX_EXCEPTION @@ -254,16 +254,16 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo) /* Load section headers into memory */ - ret = mod_loadshdrs(loadinfo); + ret = libmod_loadshdrs(loadinfo); if (ret < 0) { - bdbg("ERROR: mod_loadshdrs failed: %d\n", ret); + bdbg("ERROR: libmod_loadshdrs failed: %d\n", ret); goto errout_with_buffers; } /* Determine total size to allocate */ - mod_elfsize(loadinfo); + libmod_elfsize(loadinfo); /* Determine the heapsize to allocate. */ @@ -285,36 +285,36 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo) /* Load ELF section data into memory */ - ret = mod_loadfile(loadinfo); + ret = libmod_loadfile(loadinfo); if (ret < 0) { - bdbg("ERROR: mod_loadfile failed: %d\n", ret); + bdbg("ERROR: libmod_loadfile failed: %d\n", ret); goto errout_with_buffers; } /* Load static constructors and destructors. */ #ifdef CONFIG_BINFMT_CONSTRUCTORS - ret = mod_loadctors(loadinfo); + ret = libmod_loadctors(loadinfo); if (ret < 0) { - bdbg("ERROR: mod_loadctors failed: %d\n", ret); + bdbg("ERROR: libmod_loadctors failed: %d\n", ret); goto errout_with_buffers; } - ret = mod_loaddtors(loadinfo); + ret = libmod_loaddtors(loadinfo); if (ret < 0) { - bdbg("ERROR: mod_loaddtors failed: %d\n", ret); + bdbg("ERROR: libmod_loaddtors failed: %d\n", ret); goto errout_with_buffers; } #endif #ifdef CONFIG_UCLIBCXX_EXCEPTION - exidx = mod_findsection(loadinfo, CONFIG_ELF_EXIDX_SECTNAME); + exidx = libmod_findsection(loadinfo, CONFIG_ELF_EXIDX_SECTNAME); 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 { @@ -327,7 +327,7 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo) /* Error exits */ errout_with_buffers: - mod_unload(loadinfo); + libmod_unload(loadinfo); return ret; } diff --git a/binfmt/libmodule/libmodule_read.c b/binfmt/libmodule/libmodule_read.c index 60f3c37c03..effa0510e0 100644 --- a/binfmt/libmodule/libmodule_read.c +++ b/binfmt/libmodule/libmodule_read.c @@ -64,11 +64,11 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_dumpreaddata + * Name: libmod_dumpreaddata ****************************************************************************/ #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; int i; @@ -86,7 +86,7 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen) } } #else -# define mod_dumpreaddata(b,n) +# define libmod_dumpreaddata(b,n) #endif /**************************************************************************** @@ -94,7 +94,7 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen) ****************************************************************************/ /**************************************************************************** - * Name: mod_read + * Name: libmod_read * * Description: * 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, - size_t readsize, off_t offset) +int libmod_read(FAR struct libmod_loadinfo_s *loadinfo, FAR uint8_t *buffer, + size_t readsize, off_t offset) { ssize_t nbytes; /* Number of bytes read */ 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; } diff --git a/binfmt/libmodule/libmodule_sections.c b/binfmt/libmodule/libmodule_sections.c index 183d014141..699b3e4f75 100644 --- a/binfmt/libmodule/libmodule_sections.c +++ b/binfmt/libmodule/libmodule_sections.c @@ -63,7 +63,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_sectname + * Name: libmod_sectname * * Description: * Get the symbol name in loadinfo->iobuffer[]. @@ -74,8 +74,8 @@ * ****************************************************************************/ -static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, - FAR const Elf32_Shdr *shdr) +static inline int libmod_sectname(FAR struct libmod_loadinfo_s *loadinfo, + FAR const Elf32_Shdr *shdr) { FAR Elf32_Shdr *shstr; 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 */ buffer = &loadinfo->iobuffer[bytesread]; - ret = mod_read(loadinfo, buffer, readlen, offset); + ret = libmod_read(loadinfo, buffer, readlen, offset); if (ret < 0) { 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 */ - ret = mod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); + ret = libmod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); if (ret < 0) { - bdbg("mod_reallocbuffer failed: %d\n", ret); + bdbg("libmod_reallocbuffer failed: %d\n", 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: * 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; int ret; @@ -221,8 +221,8 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) /* Read the section header table into memory */ - ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, - loadinfo->ehdr.e_shoff); + ret = libmod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, + loadinfo->ehdr.e_shoff); if (ret < 0) { 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: * 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, - FAR const char *sectname) +int libmod_findsection(FAR struct libmod_loadinfo_s *loadinfo, + FAR const char *sectname) { FAR const Elf32_Shdr *shdr; int ret; @@ -261,10 +261,10 @@ int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, /* Get the name of this section */ shdr = &loadinfo->shdr[i]; - ret = mod_sectname(loadinfo, shdr); + ret = libmod_sectname(loadinfo, shdr); if (ret < 0) { - bdbg("mod_sectname failed: %d\n", ret); + bdbg("libmod_sectname failed: %d\n", ret); return ret; } diff --git a/binfmt/libmodule/libmodule_symbols.c b/binfmt/libmodule/libmodule_symbols.c index 9e9de001d7..6482e389e1 100644 --- a/binfmt/libmodule/libmodule_symbols.c +++ b/binfmt/libmodule/libmodule_symbols.c @@ -67,7 +67,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_symname + * Name: libmod_symname * * Description: * Get the symbol name in loadinfo->iobuffer[]. @@ -82,8 +82,8 @@ * ****************************************************************************/ -static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, - FAR const Elf32_Sym *sym) +static int libmod_symname(FAR struct libmod_loadinfo_s *loadinfo, + FAR const Elf32_Sym *sym) { FAR uint8_t *buffer; 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 */ buffer = &loadinfo->iobuffer[bytesread]; - ret = mod_read(loadinfo, buffer, readlen, offset); + ret = libmod_read(loadinfo, buffer, readlen, offset); if (ret < 0) { - bdbg("mod_read failed: %d\n", ret); + bdbg("libmod_read failed: %d\n", ret); return ret; } @@ -146,10 +146,10 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, /* No.. then we have to read more */ - ret = mod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); + ret = libmod_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR); if (ret < 0) { - bdbg("mod_reallocbuffer failed: %d\n", ret); + bdbg("libmod_reallocbuffer failed: %d\n", ret); return ret; } } @@ -164,7 +164,7 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, ****************************************************************************/ /**************************************************************************** - * Name: mod_findsymtab + * Name: libmod_findsymtab * * Description: * 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; @@ -203,7 +203,7 @@ int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_readsym + * Name: libmod_readsym * * Description: * 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, - FAR Elf32_Sym *sym) +int libmod_readsym(FAR struct libmod_loadinfo_s *loadinfo, int index, + FAR Elf32_Sym *sym) { FAR Elf32_Shdr *symtab = &loadinfo->shdr[loadinfo->symtabidx]; 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 */ - 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: * 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, - FAR const struct symtab_s *exports, int nexports) +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 *symbol; 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 */ - ret = mod_symname(loadinfo, sym); + ret = libmod_symname(loadinfo, sym); if (ret < 0) { /* There are a few relocations for a few architectures that do diff --git a/binfmt/libmodule/libmodule_uninit.c b/binfmt/libmodule/libmodule_uninit.c index 9ca3684ce3..13932bcc54 100644 --- a/binfmt/libmodule/libmodule_uninit.c +++ b/binfmt/libmodule/libmodule_uninit.c @@ -65,11 +65,11 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_uninit + * Name: libmod_uninitialize * * Description: - * Releases any resources committed by mod_initialize(). This essentially - * undoes the actions of mod_initialize. + * Releases any resources committed by libmod_initialize(). This essentially + * undoes the actions of libmod_initialize. * * Returned Value: * 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 */ - mod_freebuffers(loadinfo); + libmod_freebuffers(loadinfo); /* Close the ELF file */ @@ -94,7 +94,7 @@ int mod_uninit(struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_freebuffers + * Name: libmod_freebuffers * * Description: * 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 */ diff --git a/binfmt/libmodule/libmodule_unload.c b/binfmt/libmodule/libmodule_unload.c index c424a8686b..73822b59c6 100644 --- a/binfmt/libmodule/libmodule_unload.c +++ b/binfmt/libmodule/libmodule_unload.c @@ -64,11 +64,11 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_unload + * Name: libmod_unload * * Description: * 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. * * 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 */ - mod_freebuffers(loadinfo); + libmod_freebuffers(loadinfo); /* Release memory holding the relocated ELF image */ diff --git a/binfmt/libmodule/libmodule_verify.c b/binfmt/libmodule/libmodule_verify.c index 9d207180b3..82ab35ae4d 100644 --- a/binfmt/libmodule/libmodule_verify.c +++ b/binfmt/libmodule/libmodule_verify.c @@ -1,5 +1,5 @@ /**************************************************************************** - * binfmt/libmodule/mod_verify.c + * binfmt/libmodule/libmodule_verify.c * * Copyright (C) 2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -67,7 +67,7 @@ static const char g_modmagic[EI_MAGIC_SIZE] = ****************************************************************************/ /**************************************************************************** - * Name: mod_verifyheader + * Name: libmod_verifyheader * * Description: * 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) { diff --git a/binfmt/module.c b/binfmt/module.c index 79f63df7c7..4f727d4f6f 100644 --- a/binfmt/module.c +++ b/binfmt/module.c @@ -182,34 +182,8 @@ static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo) static void mod_dumpentrypt(FAR struct binary_s *binp, 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, 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 # 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. */ - ret = mod_init(binp->filename, &loadinfo); + ret = libmod_initialize(binp->filename, &loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { @@ -243,7 +217,7 @@ static int mod_loadbinary(FAR struct binary_s *binp) /* Load the program binary */ - ret = mod_load(&loadinfo); + ret = libmod_load(&loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { @@ -253,7 +227,7 @@ static int mod_loadbinary(FAR struct binary_s *binp) /* 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) { 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? */ -#ifdef CONFIG_ARCH_ADDRENV -# warning "REVISIT" -#else binp->alloc[0] = (FAR void *)loadinfo.textalloc; -#endif #ifdef CONFIG_BINFMT_CONSTRUCTORS /* 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; #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_uninit(&loadinfo); + libmod_uninitialize(&loadinfo); return OK; errout_with_load: - mod_unload(&loadinfo); + libmod_unload(&loadinfo); errout_with_init: - mod_uninit(&loadinfo); + libmod_uninitialize(&loadinfo); errout: return ret; } diff --git a/include/nuttx/binfmt/elf.h b/include/nuttx/binfmt/elf.h index 982fc4462d..ba5c31325a 100644 --- a/include/nuttx/binfmt/elf.h +++ b/include/nuttx/binfmt/elf.h @@ -336,6 +336,7 @@ int up_relocateadd(FAR const Elf32_Rela *rel, * Always returns Zero (OK). * ****************************************************************************/ + int up_init_exidx(Elf32_Addr address, Elf32_Word size); #endif diff --git a/include/nuttx/binfmt/module.h b/include/nuttx/binfmt/module.h index 811921f14f..acf26df0dd 100644 --- a/include/nuttx/binfmt/module.h +++ b/include/nuttx/binfmt/module.h @@ -161,7 +161,7 @@ extern "C" ****************************************************************************/ /**************************************************************************** - * Name: mod_init + * Name: libmod_initialize * * Description: * 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: * 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 @@ -336,6 +337,7 @@ int up_relocateadd(FAR const Elf32_Rela *rel, * Always returns Zero (OK). * ****************************************************************************/ + int up_init_exidx(Elf32_Addr address, Elf32_Word size); #endif