binfmt/: Run all .c files under binfmt/ through tools/nxstyle and fix all resulting complaints.

This commit is contained in:
Gregory Nutt 2020-01-11 10:10:49 -06:00 committed by Alan Carvalho de Assis
parent 98f431d8d8
commit 7a72d1e8ca
15 changed files with 74 additions and 56 deletions

View file

@ -53,6 +53,7 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* This is an artificial limit to detect error conditions where an argv[]
* list is not properly terminated.
*/
@ -60,7 +61,7 @@
#define MAX_EXEC_ARGS 256
/****************************************************************************
* Public Function
* Public Functions
****************************************************************************/
/****************************************************************************
@ -187,10 +188,10 @@ void binfmt_freeargv(FAR struct binary_s *binp)
kmm_free(binp->argbuffer);
}
/* Nullify the allocated argv[] array and the argument buffer pointers */
/* Nullify the allocated argv[] array and the argument buffer pointers */
binp->argbuffer = (FAR char *)NULL;
binp->argv = (FAR char **)NULL;
binp->argbuffer = (FAR char *)NULL;
binp->argv = (FAR char **)NULL;
}
#endif

View file

@ -197,6 +197,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
kmm_free(bin);
/* TODO: How does the module get unloaded in this case? */
#endif
sched_unlock();
@ -212,7 +213,6 @@ errout_with_bin:
errout:
set_errno(errcode);
return ERROR;
}
#endif /* !CONFIG_BINFMT_DISABLE */

View file

@ -50,6 +50,7 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* If CONFIG_LIBC_EXECFUNCS is defined in the configuration, then the
* following must also be defined:
*/
@ -113,7 +114,7 @@ void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
* size are returned as a single atomic operation.
*/
flags = enter_critical_section();
flags = enter_critical_section();
#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
/* If a bring-up symbol table has been provided and if the exec symbol
@ -121,11 +122,11 @@ void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
* symbol table.
*/
if (g_exec_symtab == NULL)
{
g_exec_symtab = CONFIG_EXECFUNCS_SYMTAB_ARRAY;
g_exec_nsymbols = CONFIG_EXECFUNCS_NSYMBOLS_VAR;
}
if (g_exec_symtab == NULL)
{
g_exec_symtab = CONFIG_EXECFUNCS_SYMTAB_ARRAY;
g_exec_nsymbols = CONFIG_EXECFUNCS_NSYMBOLS_VAR;
}
#endif
/* Return the symbol table and its size */

View file

@ -291,9 +291,11 @@ static int elf_relocate(FAR struct elf_loadinfo_s *loadinfo, int relidx,
/* Calculate the relocation address. */
if (rel->r_offset < 0 || rel->r_offset > dstsec->sh_size - sizeof(uint32_t))
if (rel->r_offset < 0 ||
rel->r_offset > dstsec->sh_size - sizeof(uint32_t))
{
berr("Section %d reloc %d: Relocation address out of range, offset %d size %d\n",
berr("Section %d reloc %d: Relocation address out of range, "
"offset %d size %d\n",
relidx, i, rel->r_offset, dstsec->sh_size);
ret = -EINVAL;
break;

View file

@ -200,7 +200,6 @@ int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo)
}
else
{
/* Save the address of the .ctors (actually, .init_array) where it was
* loaded into memory. Since the .ctors lie in allocated memory, they
* will be relocated via the normal mechanism.

View file

@ -200,7 +200,6 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo)
}
else
{
/* Save the address of the .dtors (actually, .init_array) where it was
* loaded into memory. Since the .dtors lie in allocated memory, they
* will be relocated via the normal mechanism.

View file

@ -120,8 +120,8 @@ int elf_reallocbuffer(FAR struct elf_loadinfo_s *loadinfo, size_t increment)
/* And perform the reallocation */
buffer = kmm_realloc((FAR void *)loadinfo->iobuffer, newsize);
if (!buffer)
buffer = kmm_realloc((FAR void *)loadinfo->iobuffer, newsize);
if (!buffer)
{
berr("Failed to reallocate the I/O buffer\n");
return -ENOMEM;

View file

@ -166,7 +166,8 @@ static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
/* SHF_ALLOC indicates that the section requires memory during
* execution */
* execution.
*/
if ((shdr->sh_flags & SHF_ALLOC) == 0)
{

View file

@ -305,9 +305,12 @@ int elf_symvalue(FAR struct elf_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
/* Check if the base code exports a symbol of this name */
#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
symbol = symtab_findorderedbyname(exports, (FAR char *)loadinfo->iobuffer, nexports);
symbol = symtab_findorderedbyname(exports,
(FAR char *)loadinfo->iobuffer,
nexports);
#else
symbol = symtab_findbyname(exports, (FAR char *)loadinfo->iobuffer, nexports);
symbol = symtab_findbyname(exports, (FAR char *)loadinfo->iobuffer,
nexports);
#endif
if (!symbol)
{

View file

@ -87,7 +87,7 @@ int elf_unload(struct elf_loadinfo_s *loadinfo)
elf_addrenv_free(loadinfo);
/* Release memory used to hold static constructors and destructors */
/* Release memory used to hold static constructors and destructors */
#ifdef CONFIG_BINFMT_CONSTRUCTORS
#ifndef CONFIG_ARCH_ADDRENV
@ -95,6 +95,7 @@ int elf_unload(struct elf_loadinfo_s *loadinfo)
{
kumm_free(loadinfo->ctoralloc);
}
if (loadinfo->dtoralloc != 0)
{
kumm_free(loadinfo->dtoralloc);

View file

@ -287,9 +287,10 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
result = OK;
switch (NXFLAT_RELOC_TYPE(reloc.r_info))
{
/* NXFLAT_RELOC_TYPE_REL32I Meaning: Object file contains a 32-bit offset
* into I-Space at the offset.
* Fixup: Add mapped I-Space address to the offset.
/* NXFLAT_RELOC_TYPE_REL32I Meaning: Object file contains a 32-bit
* offset into I-Space at the offset.
* Fixup: Add mapped I-Space address to the
* offset.
*/
case NXFLAT_RELOC_TYPE_REL32I:
@ -322,14 +323,16 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
#ifdef NXFLAT_RELOC_TYPE_REL32ID
case NXFLAT_RELOC_TYPE_REL32ID:
{
result = nxflat_bindrel32id(loadinfo, NXFLAT_RELOC_OFFSET(reloc.r_info));
result = nxflat_bindrel32id(loadinfo,
NXFLAT_RELOC_OFFSET(reloc.r_info));
}
break;
#endif
default:
{
berr("ERROR: Unrecognized relocation type: %d\n", NXFLAT_RELOC_TYPE(reloc.r_info));
berr("ERROR: Unrecognized relocation type: %d\n",
NXFLAT_RELOC_TYPE(reloc.r_info));
result = -EINVAL;
}
break;
@ -348,8 +351,10 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
#ifdef CONFIG_NXFLAT_DUMPBUFFER
if (ret == OK && nrelocs > 0)
{
relocs = (FAR struct nxflat_reloc_s *)(offset - loadinfo->isize + loadinfo->dspace->region);
nxflat_dumpbuffer("GOT", (FAR const uint8_t *)relocs, nrelocs * sizeof(struct nxflat_reloc_s));
relocs = (FAR struct nxflat_reloc_s *)
(offset - loadinfo->isize + loadinfo->dspace->region);
nxflat_dumpbuffer("GOT", (FAR const uint8_t *)relocs,
nrelocs * sizeof(struct nxflat_reloc_s));
}
#endif
@ -462,7 +467,8 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
offset = imports[i].i_funcname;
DEBUGASSERT(offset < loadinfo->isize);
symname = (FAR char *)(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s));
symname = (FAR char *)
(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s));
/* Find the exported symbol value for this this symbol name. */
@ -494,7 +500,8 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
#ifdef CONFIG_NXFLAT_DUMPBUFFER
if (nimports > 0)
{
nxflat_dumpbuffer("Imports", (FAR const uint8_t *)imports, nimports * sizeof(struct nxflat_import_s));
nxflat_dumpbuffer("Imports", (FAR const uint8_t *)imports,
nimports * sizeof(struct nxflat_import_s));
}
#endif
@ -549,8 +556,8 @@ static inline int nxflat_clearbss(FAR struct nxflat_loadinfo_s *loadinfo)
/* Zero the BSS area */
memset((FAR void *)(loadinfo->dspace->region + loadinfo->datasize), 0,
loadinfo->bsssize);
memset((FAR void *)(loadinfo->dspace->region + loadinfo->datasize), 0,
loadinfo->bsssize);
/* Restore the original address environment */

View file

@ -138,32 +138,31 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
/* Read the file data at offset into the user buffer */
nbytes = nx_read(loadinfo->filfd, bufptr, bytesleft);
if (nbytes < 0)
{
if (nbytes != -EINTR)
{
berr("Read from offset %d failed: %d\n",
offset, (int)nbytes);
return nbytes;
}
}
else if (nbytes == 0)
{
berr("Unexpected end of file\n");
return -ENODATA;
}
else
{
bytesread += nbytes;
bytesleft -= nbytes;
bufptr += nbytes;
offset += nbytes;
}
nbytes = nx_read(loadinfo->filfd, bufptr, bytesleft);
if (nbytes < 0)
{
if (nbytes != -EINTR)
{
berr("Read from offset %d failed: %d\n",
offset, (int)nbytes);
return nbytes;
}
}
else if (nbytes == 0)
{
berr("Unexpected end of file\n");
return -ENODATA;
}
else
{
bytesread += nbytes;
bytesleft -= nbytes;
bufptr += nbytes;
offset += nbytes;
}
}
while (bytesread < readsize);
nxflat_dumpreaddata(buffer, readsize);
return OK;
}

View file

@ -80,6 +80,7 @@ int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo)
{
close(loadinfo->filfd);
}
return OK;
}

View file

@ -82,6 +82,7 @@
int nxflat_unload(FAR struct nxflat_loadinfo_s *loadinfo)
{
/* Release the memory segments */
/* Release the I-Space mmap'ed file */
if (loadinfo->ispace)

View file

@ -119,11 +119,13 @@ static void nxflat_dumploadinfo(FAR struct nxflat_loadinfo_s *loadinfo)
binfo(" DSPACE:\n");
binfo(" dspace: %08lx\n", loadinfo->dspace);
if (loadinfo->dspace != NULL)
{
binfo(" crefs: %d\n", loadinfo->dspace->crefs);
binfo(" region: %08lx\n", loadinfo->dspace->region);
}
binfo(" datasize: %08lx\n", loadinfo->datasize);
binfo(" bsssize: %08lx\n", loadinfo->bsssize);
binfo(" (pad): %08lx\n", loadinfo->dsize - dsize);
@ -265,7 +267,7 @@ static int nxflat_unloadbinary(FAR struct binary_s *binp)
*/
}
return OK;
return OK;
}
/****************************************************************************
@ -299,6 +301,7 @@ int nxflat_initialize(void)
{
berr("Failed to register binfmt: %d\n", ret);
}
return ret;
}