diff --git a/binfmt/binfmt_copyargv.c b/binfmt/binfmt_copyargv.c index d06865b51d..3ddd9d696f 100644 --- a/binfmt/binfmt_copyargv.c +++ b/binfmt/binfmt_copyargv.c @@ -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 diff --git a/binfmt/binfmt_exec.c b/binfmt/binfmt_exec.c index 8171d9463b..ed0b8340e1 100644 --- a/binfmt/binfmt_exec.c +++ b/binfmt/binfmt_exec.c @@ -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 */ diff --git a/binfmt/binfmt_execsymtab.c b/binfmt/binfmt_execsymtab.c index b36ee29fba..dfc6174a55 100644 --- a/binfmt/binfmt_execsymtab.c +++ b/binfmt/binfmt_execsymtab.c @@ -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 */ diff --git a/binfmt/libelf/libelf_bind.c b/binfmt/libelf/libelf_bind.c index bd16c496c0..d24b62f936 100644 --- a/binfmt/libelf/libelf_bind.c +++ b/binfmt/libelf/libelf_bind.c @@ -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; diff --git a/binfmt/libelf/libelf_ctors.c b/binfmt/libelf/libelf_ctors.c index b957038bc3..e82416a4c5 100644 --- a/binfmt/libelf/libelf_ctors.c +++ b/binfmt/libelf/libelf_ctors.c @@ -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. diff --git a/binfmt/libelf/libelf_dtors.c b/binfmt/libelf/libelf_dtors.c index 9e10f703f7..f02576c284 100644 --- a/binfmt/libelf/libelf_dtors.c +++ b/binfmt/libelf/libelf_dtors.c @@ -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. diff --git a/binfmt/libelf/libelf_iobuffer.c b/binfmt/libelf/libelf_iobuffer.c index 2f2f418628..9bf88e14bf 100644 --- a/binfmt/libelf/libelf_iobuffer.c +++ b/binfmt/libelf/libelf_iobuffer.c @@ -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; diff --git a/binfmt/libelf/libelf_load.c b/binfmt/libelf/libelf_load.c index 3bfe9c2e81..6111d840e4 100644 --- a/binfmt/libelf/libelf_load.c +++ b/binfmt/libelf/libelf_load.c @@ -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) { diff --git a/binfmt/libelf/libelf_symbols.c b/binfmt/libelf/libelf_symbols.c index d0f0c886d5..92fdd0bc58 100644 --- a/binfmt/libelf/libelf_symbols.c +++ b/binfmt/libelf/libelf_symbols.c @@ -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) { diff --git a/binfmt/libelf/libelf_unload.c b/binfmt/libelf/libelf_unload.c index 23361fcc20..e7557846bd 100644 --- a/binfmt/libelf/libelf_unload.c +++ b/binfmt/libelf/libelf_unload.c @@ -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); diff --git a/binfmt/libnxflat/libnxflat_bind.c b/binfmt/libnxflat/libnxflat_bind.c index 536ea9be56..57eb51e77c 100644 --- a/binfmt/libnxflat/libnxflat_bind.c +++ b/binfmt/libnxflat/libnxflat_bind.c @@ -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 */ diff --git a/binfmt/libnxflat/libnxflat_read.c b/binfmt/libnxflat/libnxflat_read.c index 09016f5d3d..853e6ce9bf 100644 --- a/binfmt/libnxflat/libnxflat_read.c +++ b/binfmt/libnxflat/libnxflat_read.c @@ -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; } - diff --git a/binfmt/libnxflat/libnxflat_uninit.c b/binfmt/libnxflat/libnxflat_uninit.c index 49ec961d99..d0ef11372f 100644 --- a/binfmt/libnxflat/libnxflat_uninit.c +++ b/binfmt/libnxflat/libnxflat_uninit.c @@ -80,6 +80,7 @@ int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo) { close(loadinfo->filfd); } + return OK; } diff --git a/binfmt/libnxflat/libnxflat_unload.c b/binfmt/libnxflat/libnxflat_unload.c index 7cca6f25f3..01ffd935e9 100644 --- a/binfmt/libnxflat/libnxflat_unload.c +++ b/binfmt/libnxflat/libnxflat_unload.c @@ -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) diff --git a/binfmt/nxflat.c b/binfmt/nxflat.c index 5227a2ff23..29e5f4a801 100644 --- a/binfmt/nxflat.c +++ b/binfmt/nxflat.c @@ -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; }