binfmt/: Run all .c files under binfmt/ through tools/nxstyle and fix all resulting complaints.
This commit is contained in:
parent
98f431d8d8
commit
7a72d1e8ca
@ -53,6 +53,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* This is an artificial limit to detect error conditions where an argv[]
|
/* This is an artificial limit to detect error conditions where an argv[]
|
||||||
* list is not properly terminated.
|
* list is not properly terminated.
|
||||||
*/
|
*/
|
||||||
@ -60,7 +61,7 @@
|
|||||||
#define MAX_EXEC_ARGS 256
|
#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);
|
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->argbuffer = (FAR char *)NULL;
|
||||||
binp->argv = (FAR char **)NULL;
|
binp->argv = (FAR char **)NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -197,6 +197,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
|
|||||||
kmm_free(bin);
|
kmm_free(bin);
|
||||||
|
|
||||||
/* TODO: How does the module get unloaded in this case? */
|
/* TODO: How does the module get unloaded in this case? */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sched_unlock();
|
sched_unlock();
|
||||||
@ -212,7 +213,6 @@ errout_with_bin:
|
|||||||
errout:
|
errout:
|
||||||
set_errno(errcode);
|
set_errno(errcode);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !CONFIG_BINFMT_DISABLE */
|
#endif /* !CONFIG_BINFMT_DISABLE */
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* If CONFIG_LIBC_EXECFUNCS is defined in the configuration, then the
|
/* If CONFIG_LIBC_EXECFUNCS is defined in the configuration, then the
|
||||||
* following must also be defined:
|
* 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.
|
* size are returned as a single atomic operation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
flags = enter_critical_section();
|
flags = enter_critical_section();
|
||||||
|
|
||||||
#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
|
#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
|
||||||
/* If a bring-up symbol table has been provided and if the exec symbol
|
/* 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.
|
* symbol table.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (g_exec_symtab == NULL)
|
if (g_exec_symtab == NULL)
|
||||||
{
|
{
|
||||||
g_exec_symtab = CONFIG_EXECFUNCS_SYMTAB_ARRAY;
|
g_exec_symtab = CONFIG_EXECFUNCS_SYMTAB_ARRAY;
|
||||||
g_exec_nsymbols = CONFIG_EXECFUNCS_NSYMBOLS_VAR;
|
g_exec_nsymbols = CONFIG_EXECFUNCS_NSYMBOLS_VAR;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Return the symbol table and its size */
|
/* Return the symbol table and its size */
|
||||||
|
@ -291,9 +291,11 @@ static int elf_relocate(FAR struct elf_loadinfo_s *loadinfo, int relidx,
|
|||||||
|
|
||||||
/* Calculate the relocation address. */
|
/* 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);
|
relidx, i, rel->r_offset, dstsec->sh_size);
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
break;
|
break;
|
||||||
|
@ -200,7 +200,6 @@ int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Save the address of the .ctors (actually, .init_array) where it was
|
/* Save the address of the .ctors (actually, .init_array) where it was
|
||||||
* loaded into memory. Since the .ctors lie in allocated memory, they
|
* loaded into memory. Since the .ctors lie in allocated memory, they
|
||||||
* will be relocated via the normal mechanism.
|
* will be relocated via the normal mechanism.
|
||||||
|
@ -200,7 +200,6 @@ int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
/* Save the address of the .dtors (actually, .init_array) where it was
|
/* Save the address of the .dtors (actually, .init_array) where it was
|
||||||
* loaded into memory. Since the .dtors lie in allocated memory, they
|
* loaded into memory. Since the .dtors lie in allocated memory, they
|
||||||
* will be relocated via the normal mechanism.
|
* will be relocated via the normal mechanism.
|
||||||
|
@ -120,8 +120,8 @@ 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((FAR void *)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");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -166,7 +166,8 @@ static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
|
|||||||
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
|
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
|
||||||
|
|
||||||
/* SHF_ALLOC indicates that the section requires memory during
|
/* SHF_ALLOC indicates that the section requires memory during
|
||||||
* execution */
|
* execution.
|
||||||
|
*/
|
||||||
|
|
||||||
if ((shdr->sh_flags & SHF_ALLOC) == 0)
|
if ((shdr->sh_flags & SHF_ALLOC) == 0)
|
||||||
{
|
{
|
||||||
|
@ -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 */
|
/* Check if the base code exports a symbol of this name */
|
||||||
|
|
||||||
#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
|
#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
|
||||||
symbol = symtab_findorderedbyname(exports, (FAR char *)loadinfo->iobuffer, nexports);
|
symbol = symtab_findorderedbyname(exports,
|
||||||
|
(FAR char *)loadinfo->iobuffer,
|
||||||
|
nexports);
|
||||||
#else
|
#else
|
||||||
symbol = symtab_findbyname(exports, (FAR char *)loadinfo->iobuffer, nexports);
|
symbol = symtab_findbyname(exports, (FAR char *)loadinfo->iobuffer,
|
||||||
|
nexports);
|
||||||
#endif
|
#endif
|
||||||
if (!symbol)
|
if (!symbol)
|
||||||
{
|
{
|
||||||
|
@ -87,7 +87,7 @@ int elf_unload(struct elf_loadinfo_s *loadinfo)
|
|||||||
|
|
||||||
elf_addrenv_free(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
|
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||||
#ifndef CONFIG_ARCH_ADDRENV
|
#ifndef CONFIG_ARCH_ADDRENV
|
||||||
@ -95,6 +95,7 @@ int elf_unload(struct elf_loadinfo_s *loadinfo)
|
|||||||
{
|
{
|
||||||
kumm_free(loadinfo->ctoralloc);
|
kumm_free(loadinfo->ctoralloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadinfo->dtoralloc != 0)
|
if (loadinfo->dtoralloc != 0)
|
||||||
{
|
{
|
||||||
kumm_free(loadinfo->dtoralloc);
|
kumm_free(loadinfo->dtoralloc);
|
||||||
|
@ -287,9 +287,10 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
|
|||||||
result = OK;
|
result = OK;
|
||||||
switch (NXFLAT_RELOC_TYPE(reloc.r_info))
|
switch (NXFLAT_RELOC_TYPE(reloc.r_info))
|
||||||
{
|
{
|
||||||
/* NXFLAT_RELOC_TYPE_REL32I Meaning: Object file contains a 32-bit offset
|
/* NXFLAT_RELOC_TYPE_REL32I Meaning: Object file contains a 32-bit
|
||||||
* into I-Space at the offset.
|
* offset into I-Space at the offset.
|
||||||
* Fixup: Add mapped I-Space address to the offset.
|
* Fixup: Add mapped I-Space address to the
|
||||||
|
* offset.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
case NXFLAT_RELOC_TYPE_REL32I:
|
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
|
#ifdef NXFLAT_RELOC_TYPE_REL32ID
|
||||||
case 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;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
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;
|
result = -EINVAL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -348,8 +351,10 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
|
|||||||
#ifdef CONFIG_NXFLAT_DUMPBUFFER
|
#ifdef CONFIG_NXFLAT_DUMPBUFFER
|
||||||
if (ret == OK && nrelocs > 0)
|
if (ret == OK && nrelocs > 0)
|
||||||
{
|
{
|
||||||
relocs = (FAR struct nxflat_reloc_s *)(offset - loadinfo->isize + loadinfo->dspace->region);
|
relocs = (FAR struct nxflat_reloc_s *)
|
||||||
nxflat_dumpbuffer("GOT", (FAR const uint8_t *)relocs, nrelocs * sizeof(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
|
#endif
|
||||||
|
|
||||||
@ -462,7 +467,8 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
|
|||||||
offset = imports[i].i_funcname;
|
offset = imports[i].i_funcname;
|
||||||
DEBUGASSERT(offset < loadinfo->isize);
|
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. */
|
/* 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
|
#ifdef CONFIG_NXFLAT_DUMPBUFFER
|
||||||
if (nimports > 0)
|
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
|
#endif
|
||||||
|
|
||||||
@ -549,8 +556,8 @@ static inline int nxflat_clearbss(FAR struct nxflat_loadinfo_s *loadinfo)
|
|||||||
|
|
||||||
/* Zero the BSS area */
|
/* Zero the BSS area */
|
||||||
|
|
||||||
memset((FAR void *)(loadinfo->dspace->region + loadinfo->datasize), 0,
|
memset((FAR void *)(loadinfo->dspace->region + loadinfo->datasize), 0,
|
||||||
loadinfo->bsssize);
|
loadinfo->bsssize);
|
||||||
|
|
||||||
/* Restore the original address environment */
|
/* Restore the original address environment */
|
||||||
|
|
||||||
|
@ -138,32 +138,31 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
|
|||||||
|
|
||||||
/* 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, bufptr, bytesleft);
|
nbytes = nx_read(loadinfo->filfd, bufptr, bytesleft);
|
||||||
if (nbytes < 0)
|
if (nbytes < 0)
|
||||||
{
|
{
|
||||||
if (nbytes != -EINTR)
|
if (nbytes != -EINTR)
|
||||||
{
|
{
|
||||||
berr("Read from offset %d failed: %d\n",
|
berr("Read from offset %d failed: %d\n",
|
||||||
offset, (int)nbytes);
|
offset, (int)nbytes);
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (nbytes == 0)
|
else if (nbytes == 0)
|
||||||
{
|
{
|
||||||
berr("Unexpected end of file\n");
|
berr("Unexpected end of file\n");
|
||||||
return -ENODATA;
|
return -ENODATA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bytesread += nbytes;
|
bytesread += nbytes;
|
||||||
bytesleft -= nbytes;
|
bytesleft -= nbytes;
|
||||||
bufptr += nbytes;
|
bufptr += nbytes;
|
||||||
offset += nbytes;
|
offset += nbytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (bytesread < readsize);
|
while (bytesread < readsize);
|
||||||
|
|
||||||
nxflat_dumpreaddata(buffer, readsize);
|
nxflat_dumpreaddata(buffer, readsize);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo)
|
|||||||
{
|
{
|
||||||
close(loadinfo->filfd);
|
close(loadinfo->filfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@
|
|||||||
int nxflat_unload(FAR struct nxflat_loadinfo_s *loadinfo)
|
int nxflat_unload(FAR struct nxflat_loadinfo_s *loadinfo)
|
||||||
{
|
{
|
||||||
/* Release the memory segments */
|
/* Release the memory segments */
|
||||||
|
|
||||||
/* Release the I-Space mmap'ed file */
|
/* Release the I-Space mmap'ed file */
|
||||||
|
|
||||||
if (loadinfo->ispace)
|
if (loadinfo->ispace)
|
||||||
|
@ -119,11 +119,13 @@ static void nxflat_dumploadinfo(FAR struct nxflat_loadinfo_s *loadinfo)
|
|||||||
|
|
||||||
binfo(" DSPACE:\n");
|
binfo(" DSPACE:\n");
|
||||||
binfo(" dspace: %08lx\n", loadinfo->dspace);
|
binfo(" dspace: %08lx\n", loadinfo->dspace);
|
||||||
|
|
||||||
if (loadinfo->dspace != NULL)
|
if (loadinfo->dspace != NULL)
|
||||||
{
|
{
|
||||||
binfo(" crefs: %d\n", loadinfo->dspace->crefs);
|
binfo(" crefs: %d\n", loadinfo->dspace->crefs);
|
||||||
binfo(" region: %08lx\n", loadinfo->dspace->region);
|
binfo(" region: %08lx\n", loadinfo->dspace->region);
|
||||||
}
|
}
|
||||||
|
|
||||||
binfo(" datasize: %08lx\n", loadinfo->datasize);
|
binfo(" datasize: %08lx\n", loadinfo->datasize);
|
||||||
binfo(" bsssize: %08lx\n", loadinfo->bsssize);
|
binfo(" bsssize: %08lx\n", loadinfo->bsssize);
|
||||||
binfo(" (pad): %08lx\n", loadinfo->dsize - dsize);
|
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);
|
berr("Failed to register binfmt: %d\n", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user