binfmt/elf: Fix the minor style issue

and remove the unused macros and unnecessary cast

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-07-03 00:11:02 +08:00 committed by Alan Carvalho de Assis
parent 98bb66998b
commit cb8df39207
48 changed files with 254 additions and 309 deletions

View File

@ -88,7 +88,7 @@ static void exec_ctors(FAR void *arg)
for (i = 0; i < binp->nctors; i++)
{
binfo("Calling ctor %d at %p\n", i, (FAR void *)ctor);
binfo("Calling ctor %d at %p\n", i, ctor);
(*ctor)();
ctor++;
@ -272,7 +272,7 @@ int exec_module(FAR struct binary_s *binp,
if (binp->nctors > 0)
{
nxtask_starthook(tcb, exec_ctors, (FAR void *)binp);
nxtask_starthook(tcb, exec_ctors, binp);
}
#endif

View File

@ -24,7 +24,7 @@
#include <nuttx/config.h>
#include <nuttx/binfmt/binfmt.h>
#include "binfmt.h"
#ifndef CONFIG_BINFMT_DISABLE

View File

@ -69,7 +69,7 @@ static inline int exec_dtors(FAR struct binary_s *binp)
/* Instantiate the address environment containing the destructors */
#ifdef CONFIG_ARCH_ADDRENV
ret = addrenv_select(&binp->addrenv);
ret = addrenv_select(binp->addrenv, &binp->oldenv);
if (ret < 0)
{
berr("ERROR: addrenv_select() failed: %d\n", ret);
@ -81,7 +81,7 @@ static inline int exec_dtors(FAR struct binary_s *binp)
for (i = 0; i < binp->ndtors; i++)
{
binfo("Calling dtor %d at %p\n", i, (FAR void *)dtor);
binfo("Calling dtor %d at %p\n", i, dtor);
(*dtor)();
dtor++;
@ -90,7 +90,7 @@ static inline int exec_dtors(FAR struct binary_s *binp)
/* Restore the address environment */
#ifdef CONFIG_ARCH_ADDRENV
return addrenv_restore();
return addrenv_restore(binp->oldenv);
#else
return OK;
#endif
@ -169,12 +169,12 @@ int unload_module(FAR struct binary_s *binp)
#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
if (i == 0)
{
up_textheap_free((FAR void *)binp->alloc[i]);
up_textheap_free(binp->alloc[i]);
}
else
#endif
{
kumm_free((FAR void *)binp->alloc[i]);
kumm_free(binp->alloc[i]);
}
}
}

View File

@ -96,7 +96,7 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
* the priority. That is a bug and needs to be fixed.
*/
builtin = builtin_for_index(index);
builtin = builtin_for_index(index);
if (builtin == NULL)
{
berr("ERROR: %s is not a builtin application\n", filename);

View File

@ -47,7 +47,7 @@
* have to be defined or CONFIG_ELF_DUMPBUFFER does nothing.
*/
#if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_DEBUG_BINFMT)
#if !defined(CONFIG_DEBUG_INFO) || !defined(CONFIG_DEBUG_BINFMT)
# undef CONFIG_ELF_DUMPBUFFER
#endif
@ -300,22 +300,22 @@ static int elf_loadbinary(FAR struct binary_s *binp,
binp->addrenv = loadinfo.addrenv;
#else
binp->alloc[0] = (FAR void *)loadinfo.textalloc;
binp->alloc[1] = (FAR void *)loadinfo.dataalloc;
#ifdef CONFIG_BINFMT_CONSTRUCTORS
binp->alloc[2] = loadinfo.ctoralloc;
binp->alloc[3] = loadinfo.dtoralloc;
#endif
binp->alloc[0] = (FAR void *)loadinfo.textalloc;
binp->alloc[1] = (FAR void *)loadinfo.dataalloc;
# ifdef CONFIG_BINFMT_CONSTRUCTORS
binp->alloc[2] = loadinfo.ctoralloc;
binp->alloc[3] = loadinfo.dtoralloc;
# endif
#endif
#ifdef CONFIG_BINFMT_CONSTRUCTORS
/* Save information about constructors and destructors. */
binp->ctors = loadinfo.ctors;
binp->nctors = loadinfo.nctors;
binp->ctors = loadinfo.ctors;
binp->nctors = loadinfo.nctors;
binp->dtors = loadinfo.dtors;
binp->ndtors = loadinfo.ndtors;
binp->dtors = loadinfo.dtors;
binp->ndtors = loadinfo.ndtors;
#endif
#ifdef CONFIG_SCHED_USER_IDENTITY

View File

@ -25,11 +25,6 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/binfmt/elf.h>
/****************************************************************************
@ -253,7 +248,7 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo);
* Allocate memory for the ELF image (textalloc and dataalloc).
* If CONFIG_ARCH_ADDRENV=n, textalloc will be allocated using kmm_zalloc()
* and dataalloc will be a offset from textalloc.
* If CONFIG_ARCH_ADDRENV-y, then textalloc and dataalloc will be allocated
* If CONFIG_ARCH_ADDRENV=y, then textalloc and dataalloc will be allocated
* using up_addrenv_create().
* In either case, there will be a unique instance of textalloc and
* dataalloc (and stack) for each instance of a process.

View File

@ -40,7 +40,7 @@
****************************************************************************/
#define ELF_TEXT_WRE (PROT_READ | PROT_WRITE | PROT_EXEC)
#define ELF_TEXT_WRD (PROT_READ | PROT_EXEC)
#define ELF_TEXT_RE (PROT_READ | PROT_EXEC)
/****************************************************************************
* Private Constant Data
@ -144,14 +144,13 @@ errout_with_addrenv:
/* Allocate memory to hold the ELF image */
#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
# if defined(CONFIG_ARCH_USE_TEXT_HEAP)
loadinfo->textalloc = (uintptr_t)
up_textheap_memalign(loadinfo->textalign,
textsize);
#else
loadinfo->textalloc = (uintptr_t)kumm_memalign(loadinfo->textalign,
textsize);
#endif
up_textheap_memalign(loadinfo->textalign, textsize);
# else
loadinfo->textalloc = (uintptr_t)
kumm_memalign(loadinfo->textalign, textsize);
# endif
if (!loadinfo->textalloc)
{
@ -160,8 +159,8 @@ errout_with_addrenv:
if (loadinfo->datasize > 0)
{
loadinfo->dataalloc = (uintptr_t)kumm_memalign(loadinfo->dataalign,
datasize);
loadinfo->dataalloc = (uintptr_t)
kumm_memalign(loadinfo->dataalign, datasize);
if (!loadinfo->dataalloc)
{
return -ENOMEM;
@ -236,7 +235,7 @@ int elf_addrenv_restore(FAR struct elf_loadinfo_s *loadinfo)
/* Remove write access to .text */
ret = up_addrenv_mprot(&loadinfo->addrenv->addrenv, loadinfo->textalloc,
loadinfo->textsize, ELF_TEXT_WRD);
loadinfo->textsize, ELF_TEXT_RE);
if (ret < 0)
{
berr("ERROR: up_addrenv_text_disable_write failed: %d\n", ret);
@ -261,7 +260,7 @@ int elf_addrenv_restore(FAR struct elf_loadinfo_s *loadinfo)
*
* Description:
* Release the address environment previously created by
* elf_addrenv_alloc(). This function is called only under certain error
* elf_addrenv_alloc(). This function is called only under certain error
* conditions after the module has been loaded but not yet started.
* After the module has been started, the address environment will
* automatically be freed when the module exits.
@ -285,18 +284,17 @@ void elf_addrenv_free(FAR struct elf_loadinfo_s *loadinfo)
if (loadinfo->textalloc != 0)
{
#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
# if defined(CONFIG_ARCH_USE_TEXT_HEAP)
up_textheap_free((FAR void *)loadinfo->textalloc);
#else
# else
kumm_free((FAR void *)loadinfo->textalloc);
#endif
# endif
}
if (loadinfo->dataalloc != 0)
{
kumm_free((FAR void *)loadinfo->dataalloc);
}
#endif
/* Clear out all indications of the allocated address environment */

View File

@ -113,7 +113,7 @@ int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo)
ctorsize = shdr->sh_size;
loadinfo->nctors = ctorsize / sizeof(binfmt_ctor_t);
binfo("ctoridx=%d ctorsize=%d sizeof(binfmt_ctor_t)=%d nctors=%d\n",
binfo("ctoridx=%d ctorsize=%zd sizeof(binfmt_ctor_t)=%zd nctors=%d\n",
ctoridx, ctorsize, sizeof(binfmt_ctor_t), loadinfo->nctors);
/* Check if there are any constructors. It is not an error if there
@ -168,9 +168,8 @@ int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo)
((FAR void *)(&loadinfo->ctors)[i]);
binfo("ctor %d: "
"%08" PRIxPTR " + %08" PRIxPTR " = %08" PRIxPTR "\n",
i, *ptr, (uintptr_t)loadinfo->textalloc,
(uintptr_t)(*ptr + loadinfo->textalloc));
"%08" PRIxPTR " + %08" PRIxPTR " = %08" PRIxPTR "\n", i,
*ptr, loadinfo->textalloc, (*ptr + loadinfo->textalloc));
*ptr += loadinfo->textalloc;
}

View File

@ -115,7 +115,7 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo)
loadinfo->ndtors = dtorsize / sizeof(binfmt_dtor_t);
binfo("dtoridx=%d dtorsize=%d sizeof(binfmt_dtor_t)=%d ndtors=%d\n",
dtoridx, dtorsize, sizeof(binfmt_dtor_t), loadinfo->ndtors);
dtoridx, dtorsize, sizeof(binfmt_dtor_t), loadinfo->ndtors);
/* Check if there are any destructors. It is not an error if there
* are none.
@ -169,9 +169,8 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo)
((FAR void *)(&loadinfo->dtors)[i]);
binfo("dtor %d: "
"%08" PRIxPTR " + %08" PRIxPTR " = %08" PRIxPTR "\n",
i, *ptr, (uintptr_t)loadinfo->textalloc,
(uintptr_t)(*ptr + loadinfo->textalloc));
"%08" PRIxPTR " + %08" PRIxPTR " = %08" PRIxPTR "\n", i,
*ptr, loadinfo->textalloc, (*ptr + loadinfo->textalloc));
*ptr += loadinfo->textalloc;
}

View File

@ -45,7 +45,7 @@
* be defined or CONFIG_ELF_DUMPBUFFER does nothing.
*/
#if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_DEBUG_BINFMT)
#if !defined(CONFIG_DEBUG_INFO) || !defined(CONFIG_DEBUG_BINFMT)
# undef CONFIG_ELF_DUMPBUFFER
#endif

View File

@ -63,7 +63,7 @@
int elf_allocbuffer(FAR struct elf_loadinfo_s *loadinfo)
{
/* Has a buffer been allocated> */
/* Has a buffer been allocated? */
if (!loadinfo->iobuffer)
{
@ -105,7 +105,7 @@ int elf_reallocbuffer(FAR struct elf_loadinfo_s *loadinfo, size_t increment)
/* And perform the reallocation */
buffer = kmm_realloc((FAR void *)loadinfo->iobuffer, newsize);
buffer = kmm_realloc(loadinfo->iobuffer, newsize);
if (!buffer)
{
berr("Failed to reallocate the I/O buffer\n");

View File

@ -52,7 +52,7 @@
/* _ALIGN_UP: 'a' is assumed to be a power of two */
#define _ALIGN_UP(v, a) (((v) + ((a) - 1)) & ~((a) - 1))
#define _ALIGN_UP(v, a) (((v) + ((a) - 1)) & ~((a) - 1))
/****************************************************************************
* Private Constant Data
@ -74,17 +74,14 @@
*
****************************************************************************/
static void elf_elfsize(struct elf_loadinfo_s *loadinfo)
static void elf_elfsize(FAR struct elf_loadinfo_s *loadinfo)
{
size_t textsize;
size_t datasize;
size_t textsize = 0;
size_t datasize = 0;
int i;
/* Accumulate the size each section into memory that is marked SHF_ALLOC */
textsize = 0;
datasize = 0;
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
{
FAR Elf_Shdr *shdr = &loadinfo->shdr[i];
@ -141,8 +138,8 @@ static void elf_elfsize(struct elf_loadinfo_s *loadinfo)
static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
{
FAR uint8_t *text;
FAR uint8_t *data;
FAR uint8_t *text = (FAR uint8_t *)loadinfo->textalloc;
FAR uint8_t *data = (FAR uint8_t *)loadinfo->dataalloc;
FAR uint8_t **pptr;
int ret;
int i;
@ -150,8 +147,6 @@ static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
/* Read each section into memory that is marked SHF_ALLOC + SHT_NOBITS */
binfo("Loaded sections:\n");
text = (FAR uint8_t *)loadinfo->textalloc;
data = (FAR uint8_t *)loadinfo->dataalloc;
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
{
@ -267,7 +262,20 @@ static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
int elf_load(FAR struct elf_loadinfo_s *loadinfo)
{
size_t heapsize;
/* Determine the heapsize to allocate. heapsize is ignored if there is
* no address environment because the heap is a shared resource in that
* case. If there is no dynamic stack then heapsize must at least as big
* as the fixed stack size since the stack will be allocated from the heap
* in that case.
*/
#if !defined(CONFIG_ARCH_ADDRENV)
size_t heapsize = 0;
#elif defined(CONFIG_ARCH_STACK_DYNAMIC)
size_t heapsize = ARCH_HEAP_SIZE;
#else
size_t heapsize = MAX(ARCH_HEAP_SIZE, CONFIG_ELF_STACKSIZE);
#endif
#ifdef CONFIG_ELF_EXIDX_SECTNAME
int exidx;
#endif
@ -289,21 +297,6 @@ int elf_load(FAR struct elf_loadinfo_s *loadinfo)
elf_elfsize(loadinfo);
/* Determine the heapsize to allocate. heapsize is ignored if there is
* no address environment because the heap is a shared resource in that
* case. If there is no dynamic stack then heapsize must at least as big
* as the fixed stack size since the stack will be allocated from the heap
* in that case.
*/
#if !defined(CONFIG_ARCH_ADDRENV)
heapsize = 0;
#elif defined(CONFIG_ARCH_STACK_DYNAMIC)
heapsize = ARCH_HEAP_SIZE;
#else
heapsize = MAX(ARCH_HEAP_SIZE, CONFIG_ELF_STACKSIZE);
#endif
/* Allocate (and zero) memory for the ELF file. */
ret = elf_addrenv_alloc(loadinfo, loadinfo->textsize, loadinfo->datasize,

View File

@ -25,6 +25,7 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <inttypes.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
@ -52,19 +53,19 @@
* Name: elf_dumpreaddata
****************************************************************************/
#if defined(ELF_DUMP_READDATA)
static inline void elf_dumpreaddata(FAR char *buffer, int buflen)
#ifdef ELF_DUMP_READDATA
static inline void elf_dumpreaddata(FAR char *buffer, size_t buflen)
{
FAR uint32_t *buf32 = (FAR uint32_t *)buffer;
int i;
int j;
size_t i;
size_t j;
for (i = 0; i < buflen; i += 32)
{
syslog(LOG_DEBUG, "%04x:", i);
syslog(LOG_DEBUG, "%04zx:", i);
for (j = 0; j < 32; j += sizeof(uint32_t))
{
syslog(LOG_DEBUG, " %08x", *buf32++);
syslog(LOG_DEBUG, " %08" PRIx32, *buf32++);
}
syslog(LOG_DEBUG, "\n");
@ -97,10 +98,11 @@ static inline void elf_dumpreaddata(FAR char *buffer, int buflen)
int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
size_t readsize, off_t offset)
{
size_t nsize = readsize;
ssize_t nbytes; /* Number of bytes read */
off_t rpos; /* Position returned by lseek */
binfo("Read %ld bytes from offset %ld\n", (long)readsize, (long)offset);
binfo("Read %zu bytes from offset %" PRIdOFF "\n", readsize, offset);
/* Loop until all of the requested data has been read. */
@ -111,22 +113,23 @@ int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
rpos = file_seek(&loadinfo->file, offset, SEEK_SET);
if (rpos != offset)
{
berr("Failed to seek to position %lu: %d\n",
(unsigned long)offset, (int)rpos);
berr("Failed to seek to position %" PRIdOFF ": %" PRIdOFF "\n",
offset, rpos);
return rpos;
}
/* Read the file data at offset into the user buffer */
nbytes = file_read(&loadinfo->file, buffer, readsize);
nbytes = file_read(&loadinfo->file,
buffer + nsize - readsize, readsize);
if (nbytes < 0)
{
/* EINTR just means that we received a signal */
if (nbytes != -EINTR)
{
berr("Read from offset %lu failed: %d\n",
(unsigned long)offset, (int)nbytes);
berr("Read from offset %" PRIdOFF " failed: %zd\n",
offset, nbytes);
return nbytes;
}
}
@ -138,11 +141,10 @@ int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
else
{
readsize -= nbytes;
buffer += nbytes;
offset += nbytes;
}
}
elf_dumpreaddata(buffer, readsize);
elf_dumpreaddata(buffer, nsize);
return OK;
}

View File

@ -63,10 +63,8 @@ static inline int elf_sectname(FAR struct elf_loadinfo_s *loadinfo,
FAR const Elf_Shdr *shdr)
{
FAR Elf_Shdr *shstr;
FAR uint8_t *buffer;
off_t offset;
size_t readlen;
size_t bytesread;
size_t bytesread = 0;
int shstrndx;
int ret;
@ -110,13 +108,13 @@ static inline int elf_sectname(FAR struct elf_loadinfo_s *loadinfo,
/* Loop until we get the entire section name into memory */
bytesread = 0;
for (; ; )
{
FAR uint8_t *buffer = &loadinfo->iobuffer[bytesread];
size_t readlen = loadinfo->buflen - bytesread;
/* Get the number of bytes to read */
readlen = loadinfo->buflen - bytesread;
if (offset + readlen > loadinfo->filelen)
{
if (loadinfo->filelen <= offset)
@ -130,7 +128,6 @@ static inline int elf_sectname(FAR struct elf_loadinfo_s *loadinfo,
/* Read that number of bytes into the array */
buffer = &loadinfo->iobuffer[bytesread];
ret = elf_read(loadinfo, buffer, readlen, offset + bytesread);
if (ret < 0)
{
@ -210,8 +207,8 @@ int elf_loadshdrs(FAR struct elf_loadinfo_s *loadinfo)
loadinfo->shdr = (FAR FAR Elf_Shdr *)kmm_malloc(shdrsize);
if (!loadinfo->shdr)
{
berr("Failed to allocate the section header table. Size: %ld\n",
(long)shdrsize);
berr("Failed to allocate the section header table. Size: %zu\n",
shdrsize);
return -ENOMEM;
}
@ -246,8 +243,6 @@ int elf_loadshdrs(FAR struct elf_loadinfo_s *loadinfo)
int elf_findsection(FAR struct elf_loadinfo_s *loadinfo,
FAR const char *sectname)
{
FAR const Elf_Shdr *shdr;
int ret;
int i;
/* Search through the shdr[] array in loadinfo for a section named
@ -256,10 +251,11 @@ int elf_findsection(FAR struct elf_loadinfo_s *loadinfo,
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
{
FAR const Elf_Shdr *shdr = &loadinfo->shdr[i];
/* Get the name of this section */
shdr = &loadinfo->shdr[i];
ret = elf_sectname(loadinfo, shdr);
int ret = elf_sectname(loadinfo, shdr);
if (ret < 0)
{
berr("elf_sectname failed: %d\n", ret);

View File

@ -66,10 +66,8 @@
static int elf_symname(FAR struct elf_loadinfo_s *loadinfo,
FAR const Elf_Sym *sym)
{
FAR uint8_t *buffer;
off_t offset;
size_t readlen;
size_t bytesread;
size_t bytesread = 0;
int ret;
/* Get the file offset to the string that is the name of the symbol. The
@ -97,13 +95,13 @@ static int elf_symname(FAR struct elf_loadinfo_s *loadinfo,
/* Loop until we get the entire symbol name into memory */
bytesread = 0;
for (; ; )
{
FAR uint8_t *buffer = &loadinfo->iobuffer[bytesread];
size_t readlen = loadinfo->buflen - bytesread;
/* Get the number of bytes to read */
readlen = loadinfo->buflen - bytesread;
if (offset + readlen > loadinfo->filelen)
{
if (loadinfo->filelen <= offset)
@ -117,7 +115,6 @@ static int elf_symname(FAR struct elf_loadinfo_s *loadinfo,
/* Read that number of bytes into the array */
buffer = &loadinfo->iobuffer[bytesread];
ret = elf_read(loadinfo, buffer, readlen, offset + bytesread);
if (ret < 0)
{
@ -320,7 +317,7 @@ int elf_symvalue(FAR struct elf_loadinfo_s *loadinfo, FAR Elf_Sym *sym,
(uintptr_t)symbol->sym_value,
(uintptr_t)(sym->st_value + (uintptr_t)symbol->sym_value));
sym->st_value += ((uintptr_t)symbol->sym_value);
sym->st_value += (uintptr_t)symbol->sym_value;
}
break;

View File

@ -90,21 +90,21 @@ int elf_uninit(struct elf_loadinfo_s *loadinfo)
*
****************************************************************************/
int elf_freebuffers(struct elf_loadinfo_s *loadinfo)
int elf_freebuffers(FAR struct elf_loadinfo_s *loadinfo)
{
/* Release all working allocations */
if (loadinfo->shdr)
{
kmm_free((FAR void *)loadinfo->shdr);
loadinfo->shdr = NULL;
kmm_free(loadinfo->shdr);
loadinfo->shdr = NULL;
}
if (loadinfo->iobuffer)
{
kmm_free((FAR void *)loadinfo->iobuffer);
loadinfo->iobuffer = NULL;
loadinfo->buflen = 0;
kmm_free(loadinfo->iobuffer);
loadinfo->iobuffer = NULL;
loadinfo->buflen = 0;
}
return OK;

View File

@ -62,7 +62,7 @@
*
****************************************************************************/
int elf_unload(struct elf_loadinfo_s *loadinfo)
int elf_unload(FAR struct elf_loadinfo_s *loadinfo)
{
/* Free all working buffers */
@ -75,7 +75,7 @@ int elf_unload(struct elf_loadinfo_s *loadinfo)
/* Release memory used to hold static constructors and destructors */
#ifdef CONFIG_BINFMT_CONSTRUCTORS
#ifndef CONFIG_ARCH_ADDRENV
# ifndef CONFIG_ARCH_ADDRENV
if (loadinfo->ctoralloc != 0)
{
kumm_free(loadinfo->ctoralloc);
@ -85,7 +85,7 @@ int elf_unload(struct elf_loadinfo_s *loadinfo)
{
kumm_free(loadinfo->dtoralloc);
}
#endif
# endif
loadinfo->ctoralloc = NULL;
loadinfo->ctors = NULL;

View File

@ -86,7 +86,7 @@ int elf_verifyheader(FAR const Elf_Ehdr *ehdr)
/* Verify that this is a relocatable file */
if ((ehdr->e_type != ET_REL) && (ehdr->e_type != ET_EXEC))
if (ehdr->e_type != ET_REL && ehdr->e_type != ET_EXEC)
{
berr("Not a relocatable or executable file: e_type=%d\n",
ehdr->e_type);

View File

@ -25,11 +25,6 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/binfmt/nxflat.h>
/****************************************************************************
@ -37,9 +32,24 @@
****************************************************************************/
/****************************************************************************
* Public Types
* Public Function Definitions
****************************************************************************/
/****************************************************************************
* Name: nxflat_verifyheader
*
* Description:
* Given the header from a possible NXFLAT executable, verify that it is
* an NXFLAT executable.
*
* Returned Value:
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
****************************************************************************/
int nxflat_verifyheader(FAR const struct nxflat_hdr_s *header);
/****************************************************************************
* Name: nxflat_addrenv_alloc
*

View File

@ -36,6 +36,8 @@
#include <nuttx/fs/fs.h>
#include <nuttx/binfmt/nxflat.h>
#include "libnxflat.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

View File

@ -48,7 +48,7 @@
* have to be defined or CONFIG_NXFLAT_DUMPBUFFER does nothing.
*/
#if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_DEBUG_BINFMT)
#if !defined(CONFIG_DEBUG_INFO) || !defined(CONFIG_DEBUG_BINFMT)
# undef CONFIG_NXFLAT_DUMPBUFFER
#endif

View File

@ -28,10 +28,8 @@
#include <nuttx/config.h>
#include <spawn.h>
#include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/sched.h>
#include <nuttx/streams.h>
@ -47,8 +45,8 @@
/* The type of one C++ constructor or destructor */
typedef FAR void (*binfmt_ctor_t)(void);
typedef FAR void (*binfmt_dtor_t)(void);
typedef CODE void (*binfmt_ctor_t)(void);
typedef CODE void (*binfmt_dtor_t)(void);
/* This describes the file to be loaded.
*
@ -141,7 +139,7 @@ struct binfmt_s
CODE int (*unload)(FAR struct binary_s *bin);
/* Unload module callback */
/* Coredump callback */
CODE int (*coredump)(FAR struct memory_region_s *regions,
FAR struct lib_outstream_s *stream,

View File

@ -56,17 +56,6 @@
# define CONFIG_ELF_BUFFERINCR 32
#endif
/* Allocation array size and indices */
#define LIBELF_ELF_ALLOC 0
#ifdef CONFIG_BINFMT_CONSTRUCTORS
# define LIBELF_CTORS_ALLOC 1
# define LIBELF_CTPRS_ALLOC 2
# define LIBELF_NALLOC 3
#else
# define LIBELF_NALLOC 1
#endif
/****************************************************************************
* Public Types
****************************************************************************/
@ -82,7 +71,7 @@ struct elf_loadinfo_s
*
* If CONFIG_ARCH_ADDRENV=n, elfalloc will be allocated using kmm_malloc()
* (or kmm_zalloc()).
* If CONFIG_ARCH_ADDRENV-y, then elfalloc will be allocated using
* If CONFIG_ARCH_ADDRENV=y, then elfalloc will be allocated using
* up_addrenv_create(). In either case, there will be a unique instance
* of elfalloc (and stack) for each instance of a process.
*
@ -235,7 +224,7 @@ int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
*
****************************************************************************/
int elf_unload(struct elf_loadinfo_s *loadinfo);
int elf_unload(FAR struct elf_loadinfo_s *loadinfo);
/****************************************************************************
* Name: elf_coredump

View File

@ -112,21 +112,6 @@ extern "C"
#define EXTERN extern
#endif
/****************************************************************************
* Name: nxflat_verifyheader
*
* Description:
* Given the header from a possible NXFLAT executable, verify that it is
* an NXFLAT executable.
*
* Returned Value:
* 0 (OK) is returned on success and a negated errno is returned on
* failure.
*
****************************************************************************/
int nxflat_verifyheader(const struct nxflat_hdr_s *header);
/****************************************************************************
* Name: nxflat_init
*

View File

@ -52,11 +52,11 @@
# define CONFIG_MODLIB_BUFFERINCR 32
#endif
/* CONFIG_DEBUG_INFO, and CONFIG_DEBUG_BINFMT have to be defined or
/* CONFIG_DEBUG_INFO, and CONFIG_LIBC_MODLIB have to be defined or
* CONFIG_MODLIB_DUMPBUFFER does nothing.
*/
#if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_DEBUG_BINFMT)
#if !defined(CONFIG_DEBUG_INFO) || !defined(CONFIG_LIBC_MODLIB)
# undef CONFIG_MODLIB_DUMPBUFFER
#endif
@ -77,7 +77,7 @@
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
# define HAVE_MODLIB_NAMES
# define MODLIB_NAMEMAX 16
# define MODLIB_NAMEMAX NAME_MAX
#endif
/****************************************************************************

View File

@ -129,7 +129,11 @@ static inline int dlremove(FAR void *handle)
{
/* Free the module memory */
lib_free((FAR void *)modp->textalloc);
#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
up_textheap_free(modp->textalloc);
#else
lib_free(modp->textalloc);
#endif
/* Nullify so that the memory cannot be freed again */
@ -143,7 +147,7 @@ static inline int dlremove(FAR void *handle)
{
/* Free the module memory */
lib_free((FAR void *)modp->dataalloc);
lib_free(modp->dataalloc);
/* Nullify so that the memory cannot be freed again */

View File

@ -55,5 +55,5 @@
FAR char *dlerror(void)
{
return (FAR char *)strerror(get_errno());
return strerror(get_errno());
}

View File

@ -32,6 +32,7 @@
#include <debug.h>
#include <errno.h>
#include <unistd.h>
#include <sys/param.h>
#include <nuttx/envpath.h>
#include <nuttx/module.h>
@ -49,7 +50,7 @@
****************************************************************************/
#ifdef CONFIG_BUILD_PROTECTED
#if defined(CONFIG_DEBUG_INFO) && defined(CONFIG_DEBUG_BINFMT)
# if defined(CONFIG_DEBUG_INFO) && defined(CONFIG_DEBUG_BINFMT)
static void dldump_loadinfo(FAR struct mod_loadinfo_s *loadinfo)
{
int i;
@ -118,18 +119,16 @@ static void dldump_loadinfo(FAR struct mod_loadinfo_s *loadinfo)
}
}
}
#else
# define dldump_loadinfo(i)
#endif
# else
# define dldump_loadinfo(i)
# endif
#endif
/****************************************************************************
* Name: dldump_initializer
****************************************************************************/
#ifdef CONFIG_BUILD_PROTECTED
#ifdef CONFIG_MODLIB_DUMPBUFFER
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MODLIB_DUMPBUFFER)
static void dldump_initializer(mod_initializer_t initializer,
FAR struct mod_loadinfo_s *loadinfo)
{
@ -139,7 +138,6 @@ static void dldump_initializer(mod_initializer_t initializer,
#else
# define dldump_initializer(b,l)
#endif
#endif
/****************************************************************************
* Public Functions
@ -204,14 +202,13 @@ static inline FAR void *dlinsert(FAR const char *filename)
/* Allocate a module registry entry to hold the module data */
modp = (FAR struct module_s *)lib_zalloc(sizeof(struct module_s));
if (ret != 0)
if (modp == NULL)
{
ret = -ENOMEM;
binfo("Failed to initialize for load of ELF program: %d\n", ret);
goto errout_with_loadinfo;
}
memset(modp, 0, sizeof(*modp));
/* Load the program binary */
ret = modlib_load(&loadinfo);
@ -233,11 +230,11 @@ static inline FAR void *dlinsert(FAR const char *filename)
/* Save the load information */
modp->textalloc = (FAR void *)loadinfo.textalloc;
modp->dataalloc = (FAR void *)loadinfo.datastart;
modp->textalloc = (FAR void *)loadinfo.textalloc;
modp->dataalloc = (FAR void *)loadinfo.datastart;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
modp->textsize = loadinfo.textsize;
modp->datasize = loadinfo.datasize;
modp->textsize = loadinfo.textsize;
modp->datasize = loadinfo.datasize;
#endif
/* Get the module initializer entry point */
@ -290,7 +287,7 @@ static inline FAR void *dlinsert(FAR const char *filename)
modlib_uninitialize(&loadinfo);
modlib_registry_unlock();
return (FAR void *)modp;
return modp;
errout_with_load:
modlib_unload(&loadinfo);

View File

@ -27,7 +27,6 @@
#include <dlfcn.h>
#include <errno.h>
#include <nuttx/module.h>
#include <nuttx/lib/modlib.h>
/****************************************************************************

View File

@ -23,10 +23,9 @@ ifeq ($(CONFIG_LIBC_MODLIB),y)
# Add the nuttx/lib/modlib.h files to the build
CSRCS += modlib_bind.c modlib_depend.c modlib_init.c modlib_iobuffer.c
CSRCS += modlib_load.c modlib_loadhdrs.c
CSRCS += modlib_load.c modlib_loadhdrs.c modlib_verify.c
CSRCS += modlib_read.c modlib_registry.c modlib_sections.c
CSRCS += modlib_symbols.c modlib_symtab.c modlib_uninit.c modlib_unload.c
CSRCS += modlib_verify.c
# Add the modlib directory to the build

View File

@ -25,11 +25,6 @@
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/lib/modlib.h>
/****************************************************************************

View File

@ -593,26 +593,26 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
switch (dyn[i].d_tag)
{
case DT_REL :
reldata.reloff[I_REL] = dyn[i].d_un.d_val;
break;
reldata.reloff[I_REL] = dyn[i].d_un.d_val;
break;
case DT_RELSZ :
reldata.relsz[I_REL] = dyn[i].d_un.d_val;
break;
reldata.relsz[I_REL] = dyn[i].d_un.d_val;
break;
case DT_RELENT :
reldata.relentsz = dyn[i].d_un.d_val;
break;
reldata.relentsz = dyn[i].d_un.d_val;
break;
case DT_SYMTAB :
reldata.symoff = dyn[i].d_un.d_val;
break;
reldata.symoff = dyn[i].d_un.d_val;
break;
case DT_STRTAB :
reldata.stroff = dyn[i].d_un.d_val;
break;
reldata.stroff = dyn[i].d_un.d_val;
break;
case DT_JMPREL :
reldata.reloff[I_PLT] = dyn[i].d_un.d_val;
break;
reldata.reloff[I_PLT] = dyn[i].d_un.d_val;
break;
case DT_PLTRELSZ :
reldata.relsz[I_PLT] = dyn[i].d_un.d_val;
break;
reldata.relsz[I_PLT] = dyn[i].d_un.d_val;
break;
}
}
@ -626,7 +626,7 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
return -ENOMEM;
}
ret = modlib_read(loadinfo, (uint8_t *) sym, symhdr->sh_size,
ret = modlib_read(loadinfo, (FAR uint8_t *)sym, symhdr->sh_size,
symhdr->sh_offset);
if (ret < 0)
{
@ -666,7 +666,7 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
relsize = reldata.relsz[idx_rel];
}
ret = modlib_read(loadinfo, (FAR uint8_t *) rels,
ret = modlib_read(loadinfo, (FAR uint8_t *)rels,
relsize,
reldata.reloff[idx_rel] +
i * sizeof(Elf_Rel));
@ -717,7 +717,7 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
}
addr = rel->r_offset + loadinfo->textalloc;
*(uintptr_t *)addr = (uintptr_t)ep;
*(FAR uintptr_t *)addr = (uintptr_t)ep;
}
}
else
@ -726,10 +726,11 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
addr = rel->r_offset - loadinfo->datasec + loadinfo->datastart;
if ((*(uint32_t *) addr) < loadinfo->datasec)
dynsym.st_value = *(uint32_t *) addr + loadinfo->textalloc;
if ((*(FAR uint32_t *)addr) < loadinfo->datasec)
dynsym.st_value = *(FAR uint32_t *)addr +
loadinfo->textalloc;
else
dynsym.st_value = *(uint32_t *) addr -
dynsym.st_value = *(FAR uint32_t *)addr -
loadinfo->datasec + loadinfo->datastart;
ret = up_relocate(rel, &dynsym, addr);
}
@ -872,11 +873,11 @@ int modlib_bind(FAR struct module_s *modp,
switch (loadinfo->shdr[i].sh_type)
{
case SHT_REL :
ret = modlib_relocate(modp, loadinfo, i);
break;
ret = modlib_relocate(modp, loadinfo, i);
break;
case SHT_RELA :
ret = modlib_relocateadd(modp, loadinfo, i);
break;
ret = modlib_relocateadd(modp, loadinfo, i);
break;
}
}

View File

@ -56,7 +56,7 @@ int modlib_depend(FAR struct module_s *importer,
FAR struct module_s *exporter)
{
#if CONFIG_MODLIB_MAXDEPEND > 0
int freendx;
int freendx = -1;
int i;
DEBUGASSERT(importer != NULL && exporter != NULL);
@ -71,7 +71,7 @@ int modlib_depend(FAR struct module_s *importer,
* is small. Otherwise, a more dynamic data structure would be in order.
*/
for (i = 0, freendx = -1; i < CONFIG_MODLIB_MAXDEPEND; i++)
for (i = 0; i < CONFIG_MODLIB_MAXDEPEND; i++)
{
FAR const struct module_s *modp;

View File

@ -45,7 +45,7 @@
* have to be defined or CONFIG_MODLIB_DUMPBUFFER does nothing.
*/
#if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_MODLIB_DUMPBUFFER)
#if !defined(CONFIG_DEBUG_INFO) || !defined(CONFIG_MODLIB_DUMPBUFFER)
# undef CONFIG_MODLIB_DUMPBUFFER
#endif
@ -127,7 +127,6 @@ int modlib_initialize(FAR const char *filename,
/* Clear the load info structure */
memset(loadinfo, 0, sizeof(struct mod_loadinfo_s));
loadinfo->filfd = -1;
/* Open the binary file for reading (only) */

View File

@ -95,7 +95,7 @@ int modlib_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo,
/* And perform the reallocation */
buffer = lib_realloc((FAR void *)loadinfo->iobuffer, newsize);
buffer = lib_realloc(loadinfo->iobuffer, newsize);
if (!buffer)
{
berr("ERROR: Failed to reallocate the I/O buffer\n");

View File

@ -50,7 +50,7 @@
/* _ALIGN_UP: 'a' is assumed to be a power of two */
#define _ALIGN_UP(v, a) (((v) + ((a) - 1)) & ~((a) - 1))
#define _ALIGN_UP(v, a) (((v) + ((a) - 1)) & ~((a) - 1))
/****************************************************************************
* Private Functions
@ -68,17 +68,14 @@
*
****************************************************************************/
static void modlib_elfsize(struct mod_loadinfo_s *loadinfo)
static void modlib_elfsize(FAR struct mod_loadinfo_s *loadinfo)
{
size_t textsize;
size_t datasize;
size_t textsize = 0;
size_t datasize = 0;
int i;
/* Accumulate the size each section into memory that is marked SHF_ALLOC */
textsize = 0;
datasize = 0;
if (loadinfo->ehdr.e_phnum > 0)
{
for (i = 0; i < loadinfo->ehdr.e_phnum; i++)
@ -91,14 +88,14 @@ static void modlib_elfsize(struct mod_loadinfo_s *loadinfo)
if (phdr->p_flags & PF_X)
{
textsize += phdr->p_memsz;
textaddr = (void *) phdr->p_vaddr;
textaddr = (FAR void *)phdr->p_vaddr;
}
else
{
datasize += phdr->p_memsz;
loadinfo->datasec = phdr->p_vaddr;
loadinfo->segpad = phdr->p_vaddr -
((uintptr_t) textaddr + textsize);
((uintptr_t)textaddr + textsize);
}
}
}
@ -162,19 +159,16 @@ static void modlib_elfsize(struct mod_loadinfo_s *loadinfo)
static inline int modlib_loadfile(FAR struct mod_loadinfo_s *loadinfo)
{
FAR uint8_t *text;
FAR uint8_t *data;
FAR uint8_t *text = (FAR uint8_t *)loadinfo->textalloc;
FAR uint8_t *data = (FAR uint8_t *)loadinfo->datastart;
FAR uint8_t **pptr;
int ret;
int i;
/* Read each PT_LOAD area into memory */
binfo("Loading sections - text: %p.%x data: %p.%x\n",
(void *)loadinfo->textalloc, (int) loadinfo->textsize,
(void *)loadinfo->datastart, (int) loadinfo->datasize);
text = (FAR uint8_t *)loadinfo->textalloc;
data = (FAR uint8_t *)loadinfo->datastart;
binfo("Loading sections - text: %p.%zx data: %p.%zx\n",
text, loadinfo->textsize, data, loadinfo->datasize);
if (loadinfo->ehdr.e_phnum > 0)
{
@ -191,11 +185,10 @@ static inline int modlib_loadfile(FAR struct mod_loadinfo_s *loadinfo)
}
else
{
int bsssize = phdr->p_memsz - phdr->p_filesz;
size_t bsssize = phdr->p_memsz - phdr->p_filesz;
ret = modlib_read(loadinfo, data, phdr->p_filesz,
phdr->p_offset);
memset((FAR void *)((uintptr_t) data + phdr->p_filesz), 0,
bsssize);
memset(data + phdr->p_filesz, 0, bsssize);
}
if (ret < 0)
@ -235,7 +228,7 @@ static inline int modlib_loadfile(FAR struct mod_loadinfo_s *loadinfo)
}
*pptr = (FAR uint8_t *)_ALIGN_UP((uintptr_t)*pptr,
shdr->sh_addralign);
shdr->sh_addralign);
/* SHT_NOBITS indicates that there is no data in the file for the
* section.

View File

@ -85,8 +85,8 @@ int modlib_loadhdrs(FAR struct mod_loadinfo_s *loadinfo)
loadinfo->shdr = (FAR Elf_Shdr *)lib_malloc(shdrsize);
if (!loadinfo->shdr)
{
berr("ERROR: Failed to allocate the section header table. Size: %ld\n",
(long)shdrsize);
berr("ERROR: Failed to allocate the section header table. Size: %zu\n",
shdrsize);
return -ENOMEM;
}
@ -116,9 +116,9 @@ int modlib_loadhdrs(FAR struct mod_loadinfo_s *loadinfo)
loadinfo->phdr = (FAR Elf_Phdr *)lib_malloc(phdrsize);
if (!loadinfo->phdr)
{
lib_free((FAR void *)loadinfo->shdr);
lib_free(loadinfo->shdr);
berr("ERROR: Failed to allocate the program header table."
"Size: %ld\n", (long)phdrsize);
"Size: %zu\n", phdrsize);
return -ENOMEM;
}
@ -129,8 +129,8 @@ int modlib_loadhdrs(FAR struct mod_loadinfo_s *loadinfo)
if (ret < 0)
{
berr("ERROR: Failed to read program header table: %d\n", ret);
lib_free((FAR void *)loadinfo->phdr);
lib_free((FAR void *)loadinfo->shdr);
lib_free(loadinfo->phdr);
lib_free(loadinfo->shdr);
}
}
else

View File

@ -25,6 +25,7 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <inttypes.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
@ -48,19 +49,19 @@
* Name: modlib_dumpreaddata
****************************************************************************/
#if defined(ELF_DUMP_READDATA)
static inline void modlib_dumpreaddata(FAR char *buffer, int buflen)
#ifdef ELF_DUMP_READDATA
static inline void modlib_dumpreaddata(FAR char *buffer, size_t buflen)
{
FAR uint32_t *buf32 = (FAR uint32_t *)buffer;
int i;
int j;
size_t i;
size_t j;
for (i = 0; i < buflen; i += 32)
{
syslog(LOG_DEBUG, "%04x:", i);
syslog(LOG_DEBUG, "%04zx:", i);
for (j = 0; j < 32; j += sizeof(uint32_t))
{
syslog(LOG_DEBUG, " %08x", *buf32++);
syslog(LOG_DEBUG, " %08" PRIx32, *buf32++);
}
syslog(LOG_DEBUG, "\n");
@ -90,10 +91,11 @@ static inline void modlib_dumpreaddata(FAR char *buffer, int buflen)
int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
size_t readsize, off_t offset)
{
size_t nsize = readsize;
ssize_t nbytes; /* Number of bytes read */
off_t rpos; /* Position returned by lseek */
binfo("Read %ld bytes from offset %ld\n", (long)readsize, (long)offset);
binfo("Read %zu bytes from offset %" PRIdOFF "\n", readsize, offset);
/* Loop until all of the requested data has been read. */
@ -105,14 +107,15 @@ int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
if (rpos != offset)
{
int errval = _NX_GETERRNO(rpos);
berr("ERROR: Failed to seek to position %lu: %d\n",
(unsigned long)offset, errval);
berr("ERROR: Failed to seek to position %" PRIdOFF ": %d\n",
offset, errval);
return -errval;
}
/* Read the file data at offset into the user buffer */
nbytes = _NX_READ(loadinfo->filfd, buffer, readsize);
nbytes = _NX_READ(loadinfo->filfd,
buffer + nsize - readsize, readsize);
if (nbytes < 0)
{
int errval = _NX_GETERRNO(nbytes);
@ -121,8 +124,8 @@ int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
if (errval != EINTR)
{
berr("ERROR: Read from offset %lu failed: %d\n",
(unsigned long)offset, errval);
berr("ERROR: Read from offset %" PRIdOFF " failed: %d\n",
offset, errval);
return -errval;
}
}
@ -134,11 +137,10 @@ int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
else
{
readsize -= nbytes;
buffer += nbytes;
offset += nbytes;
}
}
modlib_dumpreaddata(buffer, readsize);
modlib_dumpreaddata(buffer, nsize);
return OK;
}

View File

@ -45,7 +45,6 @@
****************************************************************************/
static rmutex_t g_modlock = NXRMUTEX_INITIALIZER;
static FAR struct module_s *g_mod_registry;
/****************************************************************************

View File

@ -29,8 +29,6 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/lib/modlib.h>
#include "libc.h"
#include "modlib/modlib.h"
@ -54,10 +52,8 @@ static inline int modlib_sectname(FAR struct mod_loadinfo_s *loadinfo,
FAR const Elf_Shdr *shdr)
{
FAR Elf_Shdr *shstr;
FAR uint8_t *buffer;
off_t offset;
size_t readlen;
size_t bytesread;
size_t bytesread = 0;
int shstrndx;
int ret;
@ -101,13 +97,13 @@ static inline int modlib_sectname(FAR struct mod_loadinfo_s *loadinfo,
/* Loop until we get the entire section name into memory */
bytesread = 0;
for (; ; )
{
FAR uint8_t *buffer = &loadinfo->iobuffer[bytesread];
size_t readlen = loadinfo->buflen - bytesread;
/* Get the number of bytes to read */
readlen = loadinfo->buflen - bytesread;
if (offset + readlen > loadinfo->filelen)
{
if (loadinfo->filelen <= offset)
@ -121,7 +117,6 @@ static inline int modlib_sectname(FAR struct mod_loadinfo_s *loadinfo,
/* Read that number of bytes into the array */
buffer = &loadinfo->iobuffer[bytesread];
ret = modlib_read(loadinfo, buffer, readlen, offset);
if (ret < 0)
{
@ -178,8 +173,6 @@ static inline int modlib_sectname(FAR struct mod_loadinfo_s *loadinfo,
int modlib_findsection(FAR struct mod_loadinfo_s *loadinfo,
FAR const char *sectname)
{
FAR const Elf_Shdr *shdr;
int ret;
int i;
/* Search through the shdr[] array in loadinfo for a section named
@ -188,10 +181,11 @@ int modlib_findsection(FAR struct mod_loadinfo_s *loadinfo,
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
{
FAR const Elf_Shdr *shdr = &loadinfo->shdr[i];
/* Get the name of this section */
shdr = &loadinfo->shdr[i];
ret = modlib_sectname(loadinfo, shdr);
int ret = modlib_sectname(loadinfo, shdr);
if (ret < 0)
{
berr("ERROR: modlib_sectname failed: %d\n", ret);

View File

@ -28,6 +28,7 @@
#include <nuttx/symtab.h>
#include <nuttx/lib/modlib.h>
#include <nuttx/symtab.h>
/****************************************************************************
* Pre-processor Definitions

View File

@ -50,7 +50,7 @@
*
****************************************************************************/
int modlib_uninitialize(struct mod_loadinfo_s *loadinfo)
int modlib_uninitialize(FAR struct mod_loadinfo_s *loadinfo)
{
/* Free all working buffers */
@ -78,27 +78,27 @@ int modlib_uninitialize(struct mod_loadinfo_s *loadinfo)
*
****************************************************************************/
int modlib_freebuffers(struct mod_loadinfo_s *loadinfo)
int modlib_freebuffers(FAR struct mod_loadinfo_s *loadinfo)
{
/* Release all working allocations */
if (loadinfo->shdr != NULL)
{
lib_free((FAR void *)loadinfo->shdr);
loadinfo->shdr = NULL;
lib_free(loadinfo->shdr);
loadinfo->shdr = NULL;
}
if (loadinfo->phdr != NULL)
{
lib_free((FAR void *)loadinfo->phdr);
loadinfo->phdr = NULL;
lib_free(loadinfo->phdr);
loadinfo->phdr = NULL;
}
if (loadinfo->iobuffer != NULL)
{
lib_free((FAR void *)loadinfo->iobuffer);
loadinfo->iobuffer = NULL;
loadinfo->buflen = 0;
lib_free(loadinfo->iobuffer);
loadinfo->iobuffer = NULL;
loadinfo->buflen = 0;
}
return OK;

View File

@ -50,7 +50,7 @@
*
****************************************************************************/
int modlib_unload(struct mod_loadinfo_s *loadinfo)
int modlib_unload(FAR struct mod_loadinfo_s *loadinfo)
{
/* Free all working buffers */

View File

@ -29,7 +29,8 @@
#include <errno.h>
#include <nuttx/elf.h>
#include <nuttx/lib/modlib.h>
#include "modlib/modlib.h"
/****************************************************************************
* Private Constant Data
@ -78,13 +79,10 @@ int modlib_verifyheader(FAR const Elf_Ehdr *ehdr)
/* Verify that this is a relocatable file */
if (ehdr->e_type != ET_REL)
if (ehdr->e_type != ET_REL && ehdr->e_type != ET_DYN)
{
if (ehdr->e_type != ET_DYN)
{
berr("ERROR: Not a relocatable file: e_type=%d\n", ehdr->e_type);
return -EINVAL;
}
berr("ERROR: Not a relocatable file: e_type=%d\n", ehdr->e_type);
return -EINVAL;
}
/* Verify that this file works with the currently configured architecture */

View File

@ -188,6 +188,7 @@ FAR void *insmod(FAR const char *filename, FAR const char *modname)
if (modp == NULL)
{
berr("Failed to allocate struct module_s\n");
ret = -ENOMEM;
goto errout_with_loadinfo;
}
@ -218,11 +219,11 @@ FAR void *insmod(FAR const char *filename, FAR const char *modname)
/* Save the load information */
modp->textalloc = (FAR void *)loadinfo.textalloc;
modp->dataalloc = (FAR void *)loadinfo.datastart;
modp->textalloc = (FAR void *)loadinfo.textalloc;
modp->dataalloc = (FAR void *)loadinfo.datastart;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
modp->textsize = loadinfo.textsize;
modp->datasize = loadinfo.datasize;
modp->textsize = loadinfo.textsize;
modp->datasize = loadinfo.datasize;
#endif
/* Get the module initializer entry point */
@ -249,7 +250,7 @@ FAR void *insmod(FAR const char *filename, FAR const char *modname)
modlib_uninitialize(&loadinfo);
modlib_registry_unlock();
return (FAR void *)modp;
return modp;
errout_with_load:
modlib_unload(&loadinfo);

View File

@ -76,7 +76,7 @@ FAR void *modhandle(FAR const char *name)
}
modlib_registry_unlock();
return (FAR void *)modp;
return modp;
}
#endif /* CONFIG_MODULE */

View File

@ -148,7 +148,7 @@ static int modprocfs_callback(FAR struct module_s *modp, FAR void *arg)
priv->buffer += copysize;
priv->remaining -= copysize;
return (priv->totalsize >= priv->buflen) ? 1 : 0;
return priv->totalsize >= priv->buflen;
}
/****************************************************************************
@ -188,7 +188,7 @@ static int modprocfs_open(FAR struct file *filep, FAR const char *relpath,
* filep->f_priv.
*/
filep->f_priv = (FAR void *)priv;
filep->f_priv = priv;
return OK;
}
@ -222,7 +222,7 @@ static ssize_t modprocfs_read(FAR struct file *filep, FAR char *buffer,
FAR struct modprocfs_file_s *priv;
int ret;
finfo("buffer=%p buflen=%lu\n", buffer, (unsigned long)buflen);
finfo("buffer=%p buflen=%zu\n", buffer, buflen);
/* Recover our private data from the struct file instance */
@ -283,7 +283,7 @@ static int modprocfs_dup(FAR const struct file *oldp, FAR struct file *newp)
/* Save the new attributes in the new file structure */
newp->f_priv = (FAR void *)newpriv;
newp->f_priv = newpriv;
return OK;
}
@ -297,7 +297,7 @@ static int modprocfs_dup(FAR const struct file *oldp, FAR struct file *newp)
static int modprocfs_stat(FAR const char *relpath, FAR struct stat *buf)
{
memset(buf, 0, sizeof(struct stat));
buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR;
buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR;
return OK;
}

View File

@ -121,11 +121,11 @@ int rmmod(FAR void *handle)
*/
#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
up_textheap_free((FAR void *)modp->textalloc);
up_textheap_free(modp->textalloc);
#else
kmm_free((FAR void *)modp->textalloc);
kmm_free(modp->textalloc);
#endif
kmm_free((FAR void *)modp->dataalloc);
kmm_free(modp->dataalloc);
modp->textalloc = NULL;
modp->dataalloc = NULL;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)