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
+2 -2
View File
@@ -88,7 +88,7 @@ static void exec_ctors(FAR void *arg)
for (i = 0; i < binp->nctors; i++) 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)();
ctor++; ctor++;
@@ -272,7 +272,7 @@ int exec_module(FAR struct binary_s *binp,
if (binp->nctors > 0) if (binp->nctors > 0)
{ {
nxtask_starthook(tcb, exec_ctors, (FAR void *)binp); nxtask_starthook(tcb, exec_ctors, binp);
} }
#endif #endif
+1 -1
View File
@@ -24,7 +24,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/binfmt/binfmt.h> #include "binfmt.h"
#ifndef CONFIG_BINFMT_DISABLE #ifndef CONFIG_BINFMT_DISABLE
+5 -5
View File
@@ -69,7 +69,7 @@ static inline int exec_dtors(FAR struct binary_s *binp)
/* Instantiate the address environment containing the destructors */ /* Instantiate the address environment containing the destructors */
#ifdef CONFIG_ARCH_ADDRENV #ifdef CONFIG_ARCH_ADDRENV
ret = addrenv_select(&binp->addrenv); ret = addrenv_select(binp->addrenv, &binp->oldenv);
if (ret < 0) if (ret < 0)
{ {
berr("ERROR: addrenv_select() failed: %d\n", ret); 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++) 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)();
dtor++; dtor++;
@@ -90,7 +90,7 @@ static inline int exec_dtors(FAR struct binary_s *binp)
/* Restore the address environment */ /* Restore the address environment */
#ifdef CONFIG_ARCH_ADDRENV #ifdef CONFIG_ARCH_ADDRENV
return addrenv_restore(); return addrenv_restore(binp->oldenv);
#else #else
return OK; return OK;
#endif #endif
@@ -169,12 +169,12 @@ int unload_module(FAR struct binary_s *binp)
#if defined(CONFIG_ARCH_USE_TEXT_HEAP) #if defined(CONFIG_ARCH_USE_TEXT_HEAP)
if (i == 0) if (i == 0)
{ {
up_textheap_free((FAR void *)binp->alloc[i]); up_textheap_free(binp->alloc[i]);
} }
else else
#endif #endif
{ {
kumm_free((FAR void *)binp->alloc[i]); kumm_free(binp->alloc[i]);
} }
} }
} }
+1 -1
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. * the priority. That is a bug and needs to be fixed.
*/ */
builtin = builtin_for_index(index); builtin = builtin_for_index(index);
if (builtin == NULL) if (builtin == NULL)
{ {
berr("ERROR: %s is not a builtin application\n", filename); berr("ERROR: %s is not a builtin application\n", filename);
+11 -11
View File
@@ -47,7 +47,7 @@
* have to be defined or CONFIG_ELF_DUMPBUFFER does nothing. * 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 # undef CONFIG_ELF_DUMPBUFFER
#endif #endif
@@ -300,22 +300,22 @@ static int elf_loadbinary(FAR struct binary_s *binp,
binp->addrenv = loadinfo.addrenv; binp->addrenv = loadinfo.addrenv;
#else #else
binp->alloc[0] = (FAR void *)loadinfo.textalloc; binp->alloc[0] = (FAR void *)loadinfo.textalloc;
binp->alloc[1] = (FAR void *)loadinfo.dataalloc; binp->alloc[1] = (FAR void *)loadinfo.dataalloc;
#ifdef CONFIG_BINFMT_CONSTRUCTORS # ifdef CONFIG_BINFMT_CONSTRUCTORS
binp->alloc[2] = loadinfo.ctoralloc; binp->alloc[2] = loadinfo.ctoralloc;
binp->alloc[3] = loadinfo.dtoralloc; binp->alloc[3] = loadinfo.dtoralloc;
#endif # endif
#endif #endif
#ifdef CONFIG_BINFMT_CONSTRUCTORS #ifdef CONFIG_BINFMT_CONSTRUCTORS
/* Save information about constructors and destructors. */ /* Save information about constructors and destructors. */
binp->ctors = loadinfo.ctors; binp->ctors = loadinfo.ctors;
binp->nctors = loadinfo.nctors; binp->nctors = loadinfo.nctors;
binp->dtors = loadinfo.dtors; binp->dtors = loadinfo.dtors;
binp->ndtors = loadinfo.ndtors; binp->ndtors = loadinfo.ndtors;
#endif #endif
#ifdef CONFIG_SCHED_USER_IDENTITY #ifdef CONFIG_SCHED_USER_IDENTITY
+1 -6
View File
@@ -25,11 +25,6 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/binfmt/elf.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). * Allocate memory for the ELF image (textalloc and dataalloc).
* If CONFIG_ARCH_ADDRENV=n, textalloc will be allocated using kmm_zalloc() * If CONFIG_ARCH_ADDRENV=n, textalloc will be allocated using kmm_zalloc()
* and dataalloc will be a offset from textalloc. * 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(). * using up_addrenv_create().
* In either case, there will be a unique instance of textalloc and * In either case, there will be a unique instance of textalloc and
* dataalloc (and stack) for each instance of a process. * dataalloc (and stack) for each instance of a process.
+14 -16
View File
@@ -40,7 +40,7 @@
****************************************************************************/ ****************************************************************************/
#define ELF_TEXT_WRE (PROT_READ | PROT_WRITE | PROT_EXEC) #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 * Private Constant Data
@@ -144,14 +144,13 @@ errout_with_addrenv:
/* Allocate memory to hold the ELF image */ /* 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) loadinfo->textalloc = (uintptr_t)
up_textheap_memalign(loadinfo->textalign, up_textheap_memalign(loadinfo->textalign, textsize);
textsize); # else
#else loadinfo->textalloc = (uintptr_t)
loadinfo->textalloc = (uintptr_t)kumm_memalign(loadinfo->textalign, kumm_memalign(loadinfo->textalign, textsize);
textsize); # endif
#endif
if (!loadinfo->textalloc) if (!loadinfo->textalloc)
{ {
@@ -160,8 +159,8 @@ errout_with_addrenv:
if (loadinfo->datasize > 0) if (loadinfo->datasize > 0)
{ {
loadinfo->dataalloc = (uintptr_t)kumm_memalign(loadinfo->dataalign, loadinfo->dataalloc = (uintptr_t)
datasize); kumm_memalign(loadinfo->dataalign, datasize);
if (!loadinfo->dataalloc) if (!loadinfo->dataalloc)
{ {
return -ENOMEM; return -ENOMEM;
@@ -236,7 +235,7 @@ int elf_addrenv_restore(FAR struct elf_loadinfo_s *loadinfo)
/* Remove write access to .text */ /* Remove write access to .text */
ret = up_addrenv_mprot(&loadinfo->addrenv->addrenv, loadinfo->textalloc, ret = up_addrenv_mprot(&loadinfo->addrenv->addrenv, loadinfo->textalloc,
loadinfo->textsize, ELF_TEXT_WRD); loadinfo->textsize, ELF_TEXT_RE);
if (ret < 0) if (ret < 0)
{ {
berr("ERROR: up_addrenv_text_disable_write failed: %d\n", ret); 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: * Description:
* Release the address environment previously created by * 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. * conditions after the module has been loaded but not yet started.
* After the module has been started, the address environment will * After the module has been started, the address environment will
* automatically be freed when the module exits. * 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 (loadinfo->textalloc != 0)
{ {
#if defined(CONFIG_ARCH_USE_TEXT_HEAP) # if defined(CONFIG_ARCH_USE_TEXT_HEAP)
up_textheap_free((FAR void *)loadinfo->textalloc); up_textheap_free((FAR void *)loadinfo->textalloc);
#else # else
kumm_free((FAR void *)loadinfo->textalloc); kumm_free((FAR void *)loadinfo->textalloc);
#endif # endif
} }
if (loadinfo->dataalloc != 0) if (loadinfo->dataalloc != 0)
{ {
kumm_free((FAR void *)loadinfo->dataalloc); kumm_free((FAR void *)loadinfo->dataalloc);
} }
#endif #endif
/* Clear out all indications of the allocated address environment */ /* Clear out all indications of the allocated address environment */
+3 -4
View File
@@ -113,7 +113,7 @@ int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo)
ctorsize = shdr->sh_size; ctorsize = shdr->sh_size;
loadinfo->nctors = ctorsize / sizeof(binfmt_ctor_t); 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); ctoridx, ctorsize, sizeof(binfmt_ctor_t), loadinfo->nctors);
/* Check if there are any constructors. It is not an error if there /* 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]); ((FAR void *)(&loadinfo->ctors)[i]);
binfo("ctor %d: " binfo("ctor %d: "
"%08" PRIxPTR " + %08" PRIxPTR " = %08" PRIxPTR "\n", "%08" PRIxPTR " + %08" PRIxPTR " = %08" PRIxPTR "\n", i,
i, *ptr, (uintptr_t)loadinfo->textalloc, *ptr, loadinfo->textalloc, (*ptr + loadinfo->textalloc));
(uintptr_t)(*ptr + loadinfo->textalloc));
*ptr += loadinfo->textalloc; *ptr += loadinfo->textalloc;
} }
+3 -4
View File
@@ -115,7 +115,7 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo)
loadinfo->ndtors = dtorsize / sizeof(binfmt_dtor_t); loadinfo->ndtors = dtorsize / sizeof(binfmt_dtor_t);
binfo("dtoridx=%d dtorsize=%d sizeof(binfmt_dtor_t)=%d ndtors=%d\n", 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 /* Check if there are any destructors. It is not an error if there
* are none. * are none.
@@ -169,9 +169,8 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo)
((FAR void *)(&loadinfo->dtors)[i]); ((FAR void *)(&loadinfo->dtors)[i]);
binfo("dtor %d: " binfo("dtor %d: "
"%08" PRIxPTR " + %08" PRIxPTR " = %08" PRIxPTR "\n", "%08" PRIxPTR " + %08" PRIxPTR " = %08" PRIxPTR "\n", i,
i, *ptr, (uintptr_t)loadinfo->textalloc, *ptr, loadinfo->textalloc, (*ptr + loadinfo->textalloc));
(uintptr_t)(*ptr + loadinfo->textalloc));
*ptr += loadinfo->textalloc; *ptr += loadinfo->textalloc;
} }
+1 -1
View File
@@ -45,7 +45,7 @@
* be defined or CONFIG_ELF_DUMPBUFFER does nothing. * 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 # undef CONFIG_ELF_DUMPBUFFER
#endif #endif
+2 -2
View File
@@ -63,7 +63,7 @@
int elf_allocbuffer(FAR struct elf_loadinfo_s *loadinfo) int elf_allocbuffer(FAR struct elf_loadinfo_s *loadinfo)
{ {
/* Has a buffer been allocated> */ /* Has a buffer been allocated? */
if (!loadinfo->iobuffer) if (!loadinfo->iobuffer)
{ {
@@ -105,7 +105,7 @@ int elf_reallocbuffer(FAR struct elf_loadinfo_s *loadinfo, size_t increment)
/* And perform the reallocation */ /* And perform the reallocation */
buffer = kmm_realloc((FAR void *)loadinfo->iobuffer, newsize); buffer = kmm_realloc(loadinfo->iobuffer, newsize);
if (!buffer) if (!buffer)
{ {
berr("Failed to reallocate the I/O buffer\n"); berr("Failed to reallocate the I/O buffer\n");
+20 -27
View File
@@ -52,7 +52,7 @@
/* _ALIGN_UP: 'a' is assumed to be a power of two */ /* _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 * 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 textsize = 0;
size_t datasize; size_t datasize = 0;
int i; int i;
/* Accumulate the size each section into memory that is marked SHF_ALLOC */ /* 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++) for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
{ {
FAR Elf_Shdr *shdr = &loadinfo->shdr[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) static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
{ {
FAR uint8_t *text; FAR uint8_t *text = (FAR uint8_t *)loadinfo->textalloc;
FAR uint8_t *data; FAR uint8_t *data = (FAR uint8_t *)loadinfo->dataalloc;
FAR uint8_t **pptr; FAR uint8_t **pptr;
int ret; int ret;
int i; 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 */ /* Read each section into memory that is marked SHF_ALLOC + SHT_NOBITS */
binfo("Loaded sections:\n"); 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++) 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) 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 #ifdef CONFIG_ELF_EXIDX_SECTNAME
int exidx; int exidx;
#endif #endif
@@ -289,21 +297,6 @@ int elf_load(FAR struct elf_loadinfo_s *loadinfo)
elf_elfsize(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. */ /* Allocate (and zero) memory for the ELF file. */
ret = elf_addrenv_alloc(loadinfo, loadinfo->textsize, loadinfo->datasize, ret = elf_addrenv_alloc(loadinfo, loadinfo->textsize, loadinfo->datasize,
+16 -14
View File
@@ -25,6 +25,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <inttypes.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@@ -52,19 +53,19 @@
* Name: elf_dumpreaddata * Name: elf_dumpreaddata
****************************************************************************/ ****************************************************************************/
#if defined(ELF_DUMP_READDATA) #ifdef ELF_DUMP_READDATA
static inline void elf_dumpreaddata(FAR char *buffer, int buflen) static inline void elf_dumpreaddata(FAR char *buffer, size_t buflen)
{ {
FAR uint32_t *buf32 = (FAR uint32_t *)buffer; FAR uint32_t *buf32 = (FAR uint32_t *)buffer;
int i; size_t i;
int j; size_t j;
for (i = 0; i < buflen; i += 32) 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)) for (j = 0; j < 32; j += sizeof(uint32_t))
{ {
syslog(LOG_DEBUG, " %08x", *buf32++); syslog(LOG_DEBUG, " %08" PRIx32, *buf32++);
} }
syslog(LOG_DEBUG, "\n"); 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, int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
size_t readsize, off_t offset) size_t readsize, off_t offset)
{ {
size_t nsize = readsize;
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 */
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. */ /* 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); rpos = file_seek(&loadinfo->file, offset, SEEK_SET);
if (rpos != offset) if (rpos != offset)
{ {
berr("Failed to seek to position %lu: %d\n", berr("Failed to seek to position %" PRIdOFF ": %" PRIdOFF "\n",
(unsigned long)offset, (int)rpos); offset, rpos);
return rpos; return rpos;
} }
/* Read the file data at offset into the user buffer */ /* 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) if (nbytes < 0)
{ {
/* EINTR just means that we received a signal */ /* EINTR just means that we received a signal */
if (nbytes != -EINTR) if (nbytes != -EINTR)
{ {
berr("Read from offset %lu failed: %d\n", berr("Read from offset %" PRIdOFF " failed: %zd\n",
(unsigned long)offset, (int)nbytes); offset, nbytes);
return nbytes; return nbytes;
} }
} }
@@ -138,11 +141,10 @@ int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
else else
{ {
readsize -= nbytes; readsize -= nbytes;
buffer += nbytes;
offset += nbytes; offset += nbytes;
} }
} }
elf_dumpreaddata(buffer, readsize); elf_dumpreaddata(buffer, nsize);
return OK; return OK;
} }
+9 -13
View File
@@ -63,10 +63,8 @@ static inline int elf_sectname(FAR struct elf_loadinfo_s *loadinfo,
FAR const Elf_Shdr *shdr) FAR const Elf_Shdr *shdr)
{ {
FAR Elf_Shdr *shstr; FAR Elf_Shdr *shstr;
FAR uint8_t *buffer;
off_t offset; off_t offset;
size_t readlen; size_t bytesread = 0;
size_t bytesread;
int shstrndx; int shstrndx;
int ret; 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 */ /* Loop until we get the entire section name into memory */
bytesread = 0;
for (; ; ) for (; ; )
{ {
FAR uint8_t *buffer = &loadinfo->iobuffer[bytesread];
size_t readlen = loadinfo->buflen - bytesread;
/* Get the number of bytes to read */ /* Get the number of bytes to read */
readlen = loadinfo->buflen - bytesread;
if (offset + readlen > loadinfo->filelen) if (offset + readlen > loadinfo->filelen)
{ {
if (loadinfo->filelen <= offset) 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 */ /* Read that number of bytes into the array */
buffer = &loadinfo->iobuffer[bytesread];
ret = elf_read(loadinfo, buffer, readlen, offset + bytesread); ret = elf_read(loadinfo, buffer, readlen, offset + bytesread);
if (ret < 0) 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); loadinfo->shdr = (FAR FAR Elf_Shdr *)kmm_malloc(shdrsize);
if (!loadinfo->shdr) if (!loadinfo->shdr)
{ {
berr("Failed to allocate the section header table. Size: %ld\n", berr("Failed to allocate the section header table. Size: %zu\n",
(long)shdrsize); shdrsize);
return -ENOMEM; return -ENOMEM;
} }
@@ -246,8 +243,6 @@ int elf_loadshdrs(FAR struct elf_loadinfo_s *loadinfo)
int elf_findsection(FAR struct elf_loadinfo_s *loadinfo, int elf_findsection(FAR struct elf_loadinfo_s *loadinfo,
FAR const char *sectname) FAR const char *sectname)
{ {
FAR const Elf_Shdr *shdr;
int ret;
int i; int i;
/* Search through the shdr[] array in loadinfo for a section named /* 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++) for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
{ {
FAR const Elf_Shdr *shdr = &loadinfo->shdr[i];
/* Get the name of this section */ /* Get the name of this section */
shdr = &loadinfo->shdr[i]; int ret = elf_sectname(loadinfo, shdr);
ret = elf_sectname(loadinfo, shdr);
if (ret < 0) if (ret < 0)
{ {
berr("elf_sectname failed: %d\n", ret); berr("elf_sectname failed: %d\n", ret);
+5 -8
View File
@@ -66,10 +66,8 @@
static int elf_symname(FAR struct elf_loadinfo_s *loadinfo, static int elf_symname(FAR struct elf_loadinfo_s *loadinfo,
FAR const Elf_Sym *sym) FAR const Elf_Sym *sym)
{ {
FAR uint8_t *buffer;
off_t offset; off_t offset;
size_t readlen; size_t bytesread = 0;
size_t bytesread;
int ret; int ret;
/* Get the file offset to the string that is the name of the symbol. The /* 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 */ /* Loop until we get the entire symbol name into memory */
bytesread = 0;
for (; ; ) for (; ; )
{ {
FAR uint8_t *buffer = &loadinfo->iobuffer[bytesread];
size_t readlen = loadinfo->buflen - bytesread;
/* Get the number of bytes to read */ /* Get the number of bytes to read */
readlen = loadinfo->buflen - bytesread;
if (offset + readlen > loadinfo->filelen) if (offset + readlen > loadinfo->filelen)
{ {
if (loadinfo->filelen <= offset) 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 */ /* Read that number of bytes into the array */
buffer = &loadinfo->iobuffer[bytesread];
ret = elf_read(loadinfo, buffer, readlen, offset + bytesread); ret = elf_read(loadinfo, buffer, readlen, offset + bytesread);
if (ret < 0) 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)symbol->sym_value,
(uintptr_t)(sym->st_value + (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; break;
+6 -6
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 */ /* Release all working allocations */
if (loadinfo->shdr) if (loadinfo->shdr)
{ {
kmm_free((FAR void *)loadinfo->shdr); kmm_free(loadinfo->shdr);
loadinfo->shdr = NULL; loadinfo->shdr = NULL;
} }
if (loadinfo->iobuffer) if (loadinfo->iobuffer)
{ {
kmm_free((FAR void *)loadinfo->iobuffer); kmm_free(loadinfo->iobuffer);
loadinfo->iobuffer = NULL; loadinfo->iobuffer = NULL;
loadinfo->buflen = 0; loadinfo->buflen = 0;
} }
return OK; return OK;
+3 -3
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 */ /* 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 */ /* Release memory used to hold static constructors and destructors */
#ifdef CONFIG_BINFMT_CONSTRUCTORS #ifdef CONFIG_BINFMT_CONSTRUCTORS
#ifndef CONFIG_ARCH_ADDRENV # ifndef CONFIG_ARCH_ADDRENV
if (loadinfo->ctoralloc != 0) if (loadinfo->ctoralloc != 0)
{ {
kumm_free(loadinfo->ctoralloc); kumm_free(loadinfo->ctoralloc);
@@ -85,7 +85,7 @@ int elf_unload(struct elf_loadinfo_s *loadinfo)
{ {
kumm_free(loadinfo->dtoralloc); kumm_free(loadinfo->dtoralloc);
} }
#endif # endif
loadinfo->ctoralloc = NULL; loadinfo->ctoralloc = NULL;
loadinfo->ctors = NULL; loadinfo->ctors = NULL;
+1 -1
View File
@@ -86,7 +86,7 @@ int elf_verifyheader(FAR const Elf_Ehdr *ehdr)
/* Verify that this is a relocatable file */ /* 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", berr("Not a relocatable or executable file: e_type=%d\n",
ehdr->e_type); ehdr->e_type);
+16 -6
View File
@@ -25,11 +25,6 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/binfmt/nxflat.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 * Name: nxflat_addrenv_alloc
* *
+2
View File
@@ -36,6 +36,8 @@
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include <nuttx/binfmt/nxflat.h> #include <nuttx/binfmt/nxflat.h>
#include "libnxflat.h"
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
+1 -1
View File
@@ -48,7 +48,7 @@
* have to be defined or CONFIG_NXFLAT_DUMPBUFFER does nothing. * 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 # undef CONFIG_NXFLAT_DUMPBUFFER
#endif #endif
+3 -5
View File
@@ -28,10 +28,8 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <spawn.h> #include <spawn.h>
#include <sys/types.h> #include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/sched.h> #include <nuttx/sched.h>
#include <nuttx/streams.h> #include <nuttx/streams.h>
@@ -47,8 +45,8 @@
/* The type of one C++ constructor or destructor */ /* The type of one C++ constructor or destructor */
typedef FAR void (*binfmt_ctor_t)(void); typedef CODE void (*binfmt_ctor_t)(void);
typedef FAR void (*binfmt_dtor_t)(void); typedef CODE void (*binfmt_dtor_t)(void);
/* This describes the file to be loaded. /* This describes the file to be loaded.
* *
@@ -141,7 +139,7 @@ struct binfmt_s
CODE int (*unload)(FAR struct binary_s *bin); CODE int (*unload)(FAR struct binary_s *bin);
/* Unload module callback */ /* Coredump callback */
CODE int (*coredump)(FAR struct memory_region_s *regions, CODE int (*coredump)(FAR struct memory_region_s *regions,
FAR struct lib_outstream_s *stream, FAR struct lib_outstream_s *stream,
+2 -13
View File
@@ -56,17 +56,6 @@
# define CONFIG_ELF_BUFFERINCR 32 # define CONFIG_ELF_BUFFERINCR 32
#endif #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 * Public Types
****************************************************************************/ ****************************************************************************/
@@ -82,7 +71,7 @@ struct elf_loadinfo_s
* *
* If CONFIG_ARCH_ADDRENV=n, elfalloc will be allocated using kmm_malloc() * If CONFIG_ARCH_ADDRENV=n, elfalloc will be allocated using kmm_malloc()
* (or kmm_zalloc()). * (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 * up_addrenv_create(). In either case, there will be a unique instance
* of elfalloc (and stack) for each instance of a process. * 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 * Name: elf_coredump
-15
View File
@@ -112,21 +112,6 @@ extern "C"
#define EXTERN extern #define EXTERN extern
#endif #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 * Name: nxflat_init
* *
+3 -3
View File
@@ -52,11 +52,11 @@
# define CONFIG_MODLIB_BUFFERINCR 32 # define CONFIG_MODLIB_BUFFERINCR 32
#endif #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. * 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 # undef CONFIG_MODLIB_DUMPBUFFER
#endif #endif
@@ -77,7 +77,7 @@
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
# define HAVE_MODLIB_NAMES # define HAVE_MODLIB_NAMES
# define MODLIB_NAMEMAX 16 # define MODLIB_NAMEMAX NAME_MAX
#endif #endif
/**************************************************************************** /****************************************************************************
+6 -2
View File
@@ -129,7 +129,11 @@ static inline int dlremove(FAR void *handle)
{ {
/* Free the module memory */ /* 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 */ /* Nullify so that the memory cannot be freed again */
@@ -143,7 +147,7 @@ static inline int dlremove(FAR void *handle)
{ {
/* Free the module memory */ /* Free the module memory */
lib_free((FAR void *)modp->dataalloc); lib_free(modp->dataalloc);
/* Nullify so that the memory cannot be freed again */ /* Nullify so that the memory cannot be freed again */
+1 -1
View File
@@ -55,5 +55,5 @@
FAR char *dlerror(void) FAR char *dlerror(void)
{ {
return (FAR char *)strerror(get_errno()); return strerror(get_errno());
} }
+13 -16
View File
@@ -32,6 +32,7 @@
#include <debug.h> #include <debug.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <sys/param.h>
#include <nuttx/envpath.h> #include <nuttx/envpath.h>
#include <nuttx/module.h> #include <nuttx/module.h>
@@ -49,7 +50,7 @@
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_BUILD_PROTECTED #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) static void dldump_loadinfo(FAR struct mod_loadinfo_s *loadinfo)
{ {
int i; int i;
@@ -118,18 +119,16 @@ static void dldump_loadinfo(FAR struct mod_loadinfo_s *loadinfo)
} }
} }
} }
#else # else
# define dldump_loadinfo(i) # define dldump_loadinfo(i)
#endif # endif
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: dldump_initializer * Name: dldump_initializer
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_BUILD_PROTECTED #if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MODLIB_DUMPBUFFER)
#ifdef CONFIG_MODLIB_DUMPBUFFER
#define MIN(a,b) ((a) < (b) ? (a) : (b))
static void dldump_initializer(mod_initializer_t initializer, static void dldump_initializer(mod_initializer_t initializer,
FAR struct mod_loadinfo_s *loadinfo) FAR struct mod_loadinfo_s *loadinfo)
{ {
@@ -139,7 +138,6 @@ static void dldump_initializer(mod_initializer_t initializer,
#else #else
# define dldump_initializer(b,l) # define dldump_initializer(b,l)
#endif #endif
#endif
/**************************************************************************** /****************************************************************************
* Public Functions * 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 */ /* Allocate a module registry entry to hold the module data */
modp = (FAR struct module_s *)lib_zalloc(sizeof(struct module_s)); 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); binfo("Failed to initialize for load of ELF program: %d\n", ret);
goto errout_with_loadinfo; goto errout_with_loadinfo;
} }
memset(modp, 0, sizeof(*modp));
/* Load the program binary */ /* Load the program binary */
ret = modlib_load(&loadinfo); ret = modlib_load(&loadinfo);
@@ -233,11 +230,11 @@ static inline FAR void *dlinsert(FAR const char *filename)
/* Save the load information */ /* Save the load information */
modp->textalloc = (FAR void *)loadinfo.textalloc; modp->textalloc = (FAR void *)loadinfo.textalloc;
modp->dataalloc = (FAR void *)loadinfo.datastart; modp->dataalloc = (FAR void *)loadinfo.datastart;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
modp->textsize = loadinfo.textsize; modp->textsize = loadinfo.textsize;
modp->datasize = loadinfo.datasize; modp->datasize = loadinfo.datasize;
#endif #endif
/* Get the module initializer entry point */ /* Get the module initializer entry point */
@@ -290,7 +287,7 @@ static inline FAR void *dlinsert(FAR const char *filename)
modlib_uninitialize(&loadinfo); modlib_uninitialize(&loadinfo);
modlib_registry_unlock(); modlib_registry_unlock();
return (FAR void *)modp; return modp;
errout_with_load: errout_with_load:
modlib_unload(&loadinfo); modlib_unload(&loadinfo);
-1
View File
@@ -27,7 +27,6 @@
#include <dlfcn.h> #include <dlfcn.h>
#include <errno.h> #include <errno.h>
#include <nuttx/module.h>
#include <nuttx/lib/modlib.h> #include <nuttx/lib/modlib.h>
/**************************************************************************** /****************************************************************************
+1 -2
View File
@@ -23,10 +23,9 @@ ifeq ($(CONFIG_LIBC_MODLIB),y)
# Add the nuttx/lib/modlib.h files to the build # 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_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_read.c modlib_registry.c modlib_sections.c
CSRCS += modlib_symbols.c modlib_symtab.c modlib_uninit.c modlib_unload.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 # Add the modlib directory to the build
-5
View File
@@ -25,11 +25,6 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <nuttx/arch.h>
#include <nuttx/lib/modlib.h> #include <nuttx/lib/modlib.h>
/**************************************************************************** /****************************************************************************
+25 -24
View File
@@ -593,26 +593,26 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
switch (dyn[i].d_tag) switch (dyn[i].d_tag)
{ {
case DT_REL : case DT_REL :
reldata.reloff[I_REL] = dyn[i].d_un.d_val; reldata.reloff[I_REL] = dyn[i].d_un.d_val;
break; break;
case DT_RELSZ : case DT_RELSZ :
reldata.relsz[I_REL] = dyn[i].d_un.d_val; reldata.relsz[I_REL] = dyn[i].d_un.d_val;
break; break;
case DT_RELENT : case DT_RELENT :
reldata.relentsz = dyn[i].d_un.d_val; reldata.relentsz = dyn[i].d_un.d_val;
break; break;
case DT_SYMTAB : case DT_SYMTAB :
reldata.symoff = dyn[i].d_un.d_val; reldata.symoff = dyn[i].d_un.d_val;
break; break;
case DT_STRTAB : case DT_STRTAB :
reldata.stroff = dyn[i].d_un.d_val; reldata.stroff = dyn[i].d_un.d_val;
break; break;
case DT_JMPREL : case DT_JMPREL :
reldata.reloff[I_PLT] = dyn[i].d_un.d_val; reldata.reloff[I_PLT] = dyn[i].d_un.d_val;
break; break;
case DT_PLTRELSZ : case DT_PLTRELSZ :
reldata.relsz[I_PLT] = dyn[i].d_un.d_val; reldata.relsz[I_PLT] = dyn[i].d_un.d_val;
break; break;
} }
} }
@@ -626,7 +626,7 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
return -ENOMEM; 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); symhdr->sh_offset);
if (ret < 0) if (ret < 0)
{ {
@@ -666,7 +666,7 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
relsize = reldata.relsz[idx_rel]; relsize = reldata.relsz[idx_rel];
} }
ret = modlib_read(loadinfo, (FAR uint8_t *) rels, ret = modlib_read(loadinfo, (FAR uint8_t *)rels,
relsize, relsize,
reldata.reloff[idx_rel] + reldata.reloff[idx_rel] +
i * sizeof(Elf_Rel)); i * sizeof(Elf_Rel));
@@ -717,7 +717,7 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
} }
addr = rel->r_offset + loadinfo->textalloc; addr = rel->r_offset + loadinfo->textalloc;
*(uintptr_t *)addr = (uintptr_t)ep; *(FAR uintptr_t *)addr = (uintptr_t)ep;
} }
} }
else else
@@ -726,10 +726,11 @@ static int modlib_relocatedyn(FAR struct module_s *modp,
addr = rel->r_offset - loadinfo->datasec + loadinfo->datastart; addr = rel->r_offset - loadinfo->datasec + loadinfo->datastart;
if ((*(uint32_t *) addr) < loadinfo->datasec) if ((*(FAR uint32_t *)addr) < loadinfo->datasec)
dynsym.st_value = *(uint32_t *) addr + loadinfo->textalloc; dynsym.st_value = *(FAR uint32_t *)addr +
loadinfo->textalloc;
else else
dynsym.st_value = *(uint32_t *) addr - dynsym.st_value = *(FAR uint32_t *)addr -
loadinfo->datasec + loadinfo->datastart; loadinfo->datasec + loadinfo->datastart;
ret = up_relocate(rel, &dynsym, addr); ret = up_relocate(rel, &dynsym, addr);
} }
@@ -872,11 +873,11 @@ int modlib_bind(FAR struct module_s *modp,
switch (loadinfo->shdr[i].sh_type) switch (loadinfo->shdr[i].sh_type)
{ {
case SHT_REL : case SHT_REL :
ret = modlib_relocate(modp, loadinfo, i); ret = modlib_relocate(modp, loadinfo, i);
break; break;
case SHT_RELA : case SHT_RELA :
ret = modlib_relocateadd(modp, loadinfo, i); ret = modlib_relocateadd(modp, loadinfo, i);
break; break;
} }
} }
+2 -2
View File
@@ -56,7 +56,7 @@ int modlib_depend(FAR struct module_s *importer,
FAR struct module_s *exporter) FAR struct module_s *exporter)
{ {
#if CONFIG_MODLIB_MAXDEPEND > 0 #if CONFIG_MODLIB_MAXDEPEND > 0
int freendx; int freendx = -1;
int i; int i;
DEBUGASSERT(importer != NULL && exporter != NULL); 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. * 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; FAR const struct module_s *modp;
+1 -2
View File
@@ -45,7 +45,7 @@
* have to be defined or CONFIG_MODLIB_DUMPBUFFER does nothing. * 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 # undef CONFIG_MODLIB_DUMPBUFFER
#endif #endif
@@ -127,7 +127,6 @@ int modlib_initialize(FAR const char *filename,
/* Clear the load info structure */ /* Clear the load info structure */
memset(loadinfo, 0, sizeof(struct mod_loadinfo_s)); memset(loadinfo, 0, sizeof(struct mod_loadinfo_s));
loadinfo->filfd = -1;
/* Open the binary file for reading (only) */ /* Open the binary file for reading (only) */
+1 -1
View File
@@ -95,7 +95,7 @@ int modlib_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo,
/* And perform the reallocation */ /* And perform the reallocation */
buffer = lib_realloc((FAR void *)loadinfo->iobuffer, newsize); buffer = lib_realloc(loadinfo->iobuffer, newsize);
if (!buffer) if (!buffer)
{ {
berr("ERROR: Failed to reallocate the I/O buffer\n"); berr("ERROR: Failed to reallocate the I/O buffer\n");
+13 -20
View File
@@ -50,7 +50,7 @@
/* _ALIGN_UP: 'a' is assumed to be a power of two */ /* _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 * 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 textsize = 0;
size_t datasize; size_t datasize = 0;
int i; int i;
/* Accumulate the size each section into memory that is marked SHF_ALLOC */ /* Accumulate the size each section into memory that is marked SHF_ALLOC */
textsize = 0;
datasize = 0;
if (loadinfo->ehdr.e_phnum > 0) if (loadinfo->ehdr.e_phnum > 0)
{ {
for (i = 0; i < loadinfo->ehdr.e_phnum; i++) 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) if (phdr->p_flags & PF_X)
{ {
textsize += phdr->p_memsz; textsize += phdr->p_memsz;
textaddr = (void *) phdr->p_vaddr; textaddr = (FAR void *)phdr->p_vaddr;
} }
else else
{ {
datasize += phdr->p_memsz; datasize += phdr->p_memsz;
loadinfo->datasec = phdr->p_vaddr; loadinfo->datasec = phdr->p_vaddr;
loadinfo->segpad = 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) static inline int modlib_loadfile(FAR struct mod_loadinfo_s *loadinfo)
{ {
FAR uint8_t *text; FAR uint8_t *text = (FAR uint8_t *)loadinfo->textalloc;
FAR uint8_t *data; FAR uint8_t *data = (FAR uint8_t *)loadinfo->datastart;
FAR uint8_t **pptr; FAR uint8_t **pptr;
int ret; int ret;
int i; int i;
/* Read each PT_LOAD area into memory */ /* Read each PT_LOAD area into memory */
binfo("Loading sections - text: %p.%x data: %p.%x\n", binfo("Loading sections - text: %p.%zx data: %p.%zx\n",
(void *)loadinfo->textalloc, (int) loadinfo->textsize, text, loadinfo->textsize, data, loadinfo->datasize);
(void *)loadinfo->datastart, (int) loadinfo->datasize);
text = (FAR uint8_t *)loadinfo->textalloc;
data = (FAR uint8_t *)loadinfo->datastart;
if (loadinfo->ehdr.e_phnum > 0) if (loadinfo->ehdr.e_phnum > 0)
{ {
@@ -191,11 +185,10 @@ static inline int modlib_loadfile(FAR struct mod_loadinfo_s *loadinfo)
} }
else 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, ret = modlib_read(loadinfo, data, phdr->p_filesz,
phdr->p_offset); phdr->p_offset);
memset((FAR void *)((uintptr_t) data + phdr->p_filesz), 0, memset(data + phdr->p_filesz, 0, bsssize);
bsssize);
} }
if (ret < 0) 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, *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 /* SHT_NOBITS indicates that there is no data in the file for the
* section. * section.
+6 -6
View File
@@ -85,8 +85,8 @@ int modlib_loadhdrs(FAR struct mod_loadinfo_s *loadinfo)
loadinfo->shdr = (FAR Elf_Shdr *)lib_malloc(shdrsize); loadinfo->shdr = (FAR Elf_Shdr *)lib_malloc(shdrsize);
if (!loadinfo->shdr) if (!loadinfo->shdr)
{ {
berr("ERROR: Failed to allocate the section header table. Size: %ld\n", berr("ERROR: Failed to allocate the section header table. Size: %zu\n",
(long)shdrsize); shdrsize);
return -ENOMEM; return -ENOMEM;
} }
@@ -116,9 +116,9 @@ int modlib_loadhdrs(FAR struct mod_loadinfo_s *loadinfo)
loadinfo->phdr = (FAR Elf_Phdr *)lib_malloc(phdrsize); loadinfo->phdr = (FAR Elf_Phdr *)lib_malloc(phdrsize);
if (!loadinfo->phdr) if (!loadinfo->phdr)
{ {
lib_free((FAR void *)loadinfo->shdr); lib_free(loadinfo->shdr);
berr("ERROR: Failed to allocate the program header table." berr("ERROR: Failed to allocate the program header table."
"Size: %ld\n", (long)phdrsize); "Size: %zu\n", phdrsize);
return -ENOMEM; return -ENOMEM;
} }
@@ -129,8 +129,8 @@ int modlib_loadhdrs(FAR struct mod_loadinfo_s *loadinfo)
if (ret < 0) if (ret < 0)
{ {
berr("ERROR: Failed to read program header table: %d\n", ret); berr("ERROR: Failed to read program header table: %d\n", ret);
lib_free((FAR void *)loadinfo->phdr); lib_free(loadinfo->phdr);
lib_free((FAR void *)loadinfo->shdr); lib_free(loadinfo->shdr);
} }
} }
else else
+16 -14
View File
@@ -25,6 +25,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <inttypes.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@@ -48,19 +49,19 @@
* Name: modlib_dumpreaddata * Name: modlib_dumpreaddata
****************************************************************************/ ****************************************************************************/
#if defined(ELF_DUMP_READDATA) #ifdef ELF_DUMP_READDATA
static inline void modlib_dumpreaddata(FAR char *buffer, int buflen) static inline void modlib_dumpreaddata(FAR char *buffer, size_t buflen)
{ {
FAR uint32_t *buf32 = (FAR uint32_t *)buffer; FAR uint32_t *buf32 = (FAR uint32_t *)buffer;
int i; size_t i;
int j; size_t j;
for (i = 0; i < buflen; i += 32) 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)) for (j = 0; j < 32; j += sizeof(uint32_t))
{ {
syslog(LOG_DEBUG, " %08x", *buf32++); syslog(LOG_DEBUG, " %08" PRIx32, *buf32++);
} }
syslog(LOG_DEBUG, "\n"); 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, int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
size_t readsize, off_t offset) size_t readsize, off_t offset)
{ {
size_t nsize = readsize;
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 */
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. */ /* 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) if (rpos != offset)
{ {
int errval = _NX_GETERRNO(rpos); int errval = _NX_GETERRNO(rpos);
berr("ERROR: Failed to seek to position %lu: %d\n", berr("ERROR: Failed to seek to position %" PRIdOFF ": %d\n",
(unsigned long)offset, errval); offset, errval);
return -errval; return -errval;
} }
/* Read the file data at offset into the user buffer */ /* 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) if (nbytes < 0)
{ {
int errval = _NX_GETERRNO(nbytes); 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) if (errval != EINTR)
{ {
berr("ERROR: Read from offset %lu failed: %d\n", berr("ERROR: Read from offset %" PRIdOFF " failed: %d\n",
(unsigned long)offset, errval); offset, errval);
return -errval; return -errval;
} }
} }
@@ -134,11 +137,10 @@ int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer,
else else
{ {
readsize -= nbytes; readsize -= nbytes;
buffer += nbytes;
offset += nbytes; offset += nbytes;
} }
} }
modlib_dumpreaddata(buffer, readsize); modlib_dumpreaddata(buffer, nsize);
return OK; return OK;
} }
-1
View File
@@ -45,7 +45,6 @@
****************************************************************************/ ****************************************************************************/
static rmutex_t g_modlock = NXRMUTEX_INITIALIZER; static rmutex_t g_modlock = NXRMUTEX_INITIALIZER;
static FAR struct module_s *g_mod_registry; static FAR struct module_s *g_mod_registry;
/**************************************************************************** /****************************************************************************
+7 -13
View File
@@ -29,8 +29,6 @@
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
#include <nuttx/lib/modlib.h>
#include "libc.h" #include "libc.h"
#include "modlib/modlib.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 const Elf_Shdr *shdr)
{ {
FAR Elf_Shdr *shstr; FAR Elf_Shdr *shstr;
FAR uint8_t *buffer;
off_t offset; off_t offset;
size_t readlen; size_t bytesread = 0;
size_t bytesread;
int shstrndx; int shstrndx;
int ret; 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 */ /* Loop until we get the entire section name into memory */
bytesread = 0;
for (; ; ) for (; ; )
{ {
FAR uint8_t *buffer = &loadinfo->iobuffer[bytesread];
size_t readlen = loadinfo->buflen - bytesread;
/* Get the number of bytes to read */ /* Get the number of bytes to read */
readlen = loadinfo->buflen - bytesread;
if (offset + readlen > loadinfo->filelen) if (offset + readlen > loadinfo->filelen)
{ {
if (loadinfo->filelen <= offset) 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 */ /* Read that number of bytes into the array */
buffer = &loadinfo->iobuffer[bytesread];
ret = modlib_read(loadinfo, buffer, readlen, offset); ret = modlib_read(loadinfo, buffer, readlen, offset);
if (ret < 0) 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, int modlib_findsection(FAR struct mod_loadinfo_s *loadinfo,
FAR const char *sectname) FAR const char *sectname)
{ {
FAR const Elf_Shdr *shdr;
int ret;
int i; int i;
/* Search through the shdr[] array in loadinfo for a section named /* 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++) for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
{ {
FAR const Elf_Shdr *shdr = &loadinfo->shdr[i];
/* Get the name of this section */ /* Get the name of this section */
shdr = &loadinfo->shdr[i]; int ret = modlib_sectname(loadinfo, shdr);
ret = modlib_sectname(loadinfo, shdr);
if (ret < 0) if (ret < 0)
{ {
berr("ERROR: modlib_sectname failed: %d\n", ret); berr("ERROR: modlib_sectname failed: %d\n", ret);
+1
View File
@@ -28,6 +28,7 @@
#include <nuttx/symtab.h> #include <nuttx/symtab.h>
#include <nuttx/lib/modlib.h> #include <nuttx/lib/modlib.h>
#include <nuttx/symtab.h>
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
+9 -9
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 */ /* 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 */ /* Release all working allocations */
if (loadinfo->shdr != NULL) if (loadinfo->shdr != NULL)
{ {
lib_free((FAR void *)loadinfo->shdr); lib_free(loadinfo->shdr);
loadinfo->shdr = NULL; loadinfo->shdr = NULL;
} }
if (loadinfo->phdr != NULL) if (loadinfo->phdr != NULL)
{ {
lib_free((FAR void *)loadinfo->phdr); lib_free(loadinfo->phdr);
loadinfo->phdr = NULL; loadinfo->phdr = NULL;
} }
if (loadinfo->iobuffer != NULL) if (loadinfo->iobuffer != NULL)
{ {
lib_free((FAR void *)loadinfo->iobuffer); lib_free(loadinfo->iobuffer);
loadinfo->iobuffer = NULL; loadinfo->iobuffer = NULL;
loadinfo->buflen = 0; loadinfo->buflen = 0;
} }
return OK; return OK;
+1 -1
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 */ /* Free all working buffers */
+5 -7
View File
@@ -29,7 +29,8 @@
#include <errno.h> #include <errno.h>
#include <nuttx/elf.h> #include <nuttx/elf.h>
#include <nuttx/lib/modlib.h>
#include "modlib/modlib.h"
/**************************************************************************** /****************************************************************************
* Private Constant Data * Private Constant Data
@@ -78,13 +79,10 @@ int modlib_verifyheader(FAR const Elf_Ehdr *ehdr)
/* Verify that this is a relocatable file */ /* 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 */ /* Verify that this file works with the currently configured architecture */
+6 -5
View File
@@ -188,6 +188,7 @@ FAR void *insmod(FAR const char *filename, FAR const char *modname)
if (modp == NULL) if (modp == NULL)
{ {
berr("Failed to allocate struct module_s\n"); berr("Failed to allocate struct module_s\n");
ret = -ENOMEM;
goto errout_with_loadinfo; goto errout_with_loadinfo;
} }
@@ -218,11 +219,11 @@ FAR void *insmod(FAR const char *filename, FAR const char *modname)
/* Save the load information */ /* Save the load information */
modp->textalloc = (FAR void *)loadinfo.textalloc; modp->textalloc = (FAR void *)loadinfo.textalloc;
modp->dataalloc = (FAR void *)loadinfo.datastart; modp->dataalloc = (FAR void *)loadinfo.datastart;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
modp->textsize = loadinfo.textsize; modp->textsize = loadinfo.textsize;
modp->datasize = loadinfo.datasize; modp->datasize = loadinfo.datasize;
#endif #endif
/* Get the module initializer entry point */ /* 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_uninitialize(&loadinfo);
modlib_registry_unlock(); modlib_registry_unlock();
return (FAR void *)modp; return modp;
errout_with_load: errout_with_load:
modlib_unload(&loadinfo); modlib_unload(&loadinfo);
+1 -1
View File
@@ -76,7 +76,7 @@ FAR void *modhandle(FAR const char *name)
} }
modlib_registry_unlock(); modlib_registry_unlock();
return (FAR void *)modp; return modp;
} }
#endif /* CONFIG_MODULE */ #endif /* CONFIG_MODULE */
+5 -5
View File
@@ -148,7 +148,7 @@ static int modprocfs_callback(FAR struct module_s *modp, FAR void *arg)
priv->buffer += copysize; priv->buffer += copysize;
priv->remaining -= 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.
*/ */
filep->f_priv = (FAR void *)priv; filep->f_priv = priv;
return OK; return OK;
} }
@@ -222,7 +222,7 @@ static ssize_t modprocfs_read(FAR struct file *filep, FAR char *buffer,
FAR struct modprocfs_file_s *priv; FAR struct modprocfs_file_s *priv;
int ret; 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 */ /* 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 */ /* Save the new attributes in the new file structure */
newp->f_priv = (FAR void *)newpriv; newp->f_priv = newpriv;
return OK; 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) static int modprocfs_stat(FAR const char *relpath, FAR struct stat *buf)
{ {
memset(buf, 0, sizeof(struct stat)); 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; return OK;
} }
+3 -3
View File
@@ -121,11 +121,11 @@ int rmmod(FAR void *handle)
*/ */
#if defined(CONFIG_ARCH_USE_TEXT_HEAP) #if defined(CONFIG_ARCH_USE_TEXT_HEAP)
up_textheap_free((FAR void *)modp->textalloc); up_textheap_free(modp->textalloc);
#else #else
kmm_free((FAR void *)modp->textalloc); kmm_free(modp->textalloc);
#endif #endif
kmm_free((FAR void *)modp->dataalloc); kmm_free(modp->dataalloc);
modp->textalloc = NULL; modp->textalloc = NULL;
modp->dataalloc = NULL; modp->dataalloc = NULL;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)