diff --git a/include/nuttx/lib/modlib.h b/include/nuttx/lib/modlib.h index a0b68893ea..7df5e34462 100644 --- a/include/nuttx/lib/modlib.h +++ b/include/nuttx/lib/modlib.h @@ -65,6 +65,20 @@ # define CONFIG_MODLIB_BUFFERINCR 32 #endif +/* CONFIG_DEBUG_INFO, and CONFIG_DEBUG_BINFMT have to be defined or + * CONFIG_MODLIB_DUMPBUFFER does nothing. + */ + +#if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_DEBUG_BINFMT) +# undef CONFIG_MODLIB_DUMPBUFFER +#endif + +#ifdef CONFIG_MODLIB_DUMPBUFFER +# define modlib_dumpbuffer(m,b,n) sinfodumpbuffer(m,b,n) +#else +# define modlib_dumpbuffer(m,b,n) +#endif + /* Module names. These are only used by the kernel module and will be * disabled in all other configurations. * diff --git a/libc/dllfcn/lib_dlclose.c b/libc/dllfcn/lib_dlclose.c index 3a83e7df42..4a84457823 100644 --- a/libc/dllfcn/lib_dlclose.c +++ b/libc/dllfcn/lib_dlclose.c @@ -40,8 +40,135 @@ #include #include +#include #include +#include + +#include "libc.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dlremove + * + * Description: + * Remove a previously installed shared library from memory. + * + * Input Parameters: + * handle - The shared library handle previously returned by dlopen(). + * + * Returned Value: + * Zero (OK) on success. On any failure, -1 (ERROR) is returned the + * errno value is set appropriately. + * + ****************************************************************************/ + +#ifdef CONFIG_BUILD_PROTECTED +static inline int dlremove(FAR void *handle) +{ + FAR struct module_s *modp = (FAR struct module_s *)handle; + int ret; + + DEBUGASSERT(modp != NULL); + + /* Get exclusive access to the module registry */ + + modlib_registry_lock(); + + /* Verify that the module is in the registry */ + + ret = modlib_registry_verify(modp); + if (ret < 0) + { + serr("ERROR: Failed to verify module: %d\n", ret); + goto errout_with_lock; + } + +#if CONFIG_MODLIB_MAXDEPEND > 0 + /* Refuse to remove any module that other modules may depend upon. */ + + if (modp->dependents > 0) + { + serr("ERROR: Module has dependents: %d\n", modp->dependents); + ret = -EBUSY; + goto errout_with_lock; + } +#endif + + /* Is there an uninitializer? */ + + if (modp->modinfo.uninitializer != NULL) + { + /* Try to uninitialize the module */ + + ret = modp->modinfo.uninitializer(modp->modinfo.arg); + + /* Did the module sucessfully uninitialize? */ + + if (ret < 0) + { + serr("ERROR: Failed to uninitialize the module: %d\n", ret); + goto errout_with_lock; + } + + /* Nullify so that the uninitializer cannot be called again */ + + modp->modinfo.uninitializer = NULL; +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + modp->initializer = NULL; + modp->modinfo.arg = NULL; + modp->modinfo.exports = NULL; + modp->modinfo.nexports = 0; +#endif + } + + /* Release resources held by the module */ + + if (modp->alloc != NULL) + { + /* Free the module memory */ + + lib_free((FAR void *)modp->alloc); + + /* Nullify so that the memory cannot be freed again */ + + modp->alloc = NULL; +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + modp->textsize = 0; + modp->datasize = 0; +#endif + } + + /* Remove the module from the registry */ + + ret = modlib_registry_del(modp); + if (ret < 0) + { + serr("ERROR: Failed to remove the module from the registry: %d\n", ret); + goto errout_with_lock; + } + +#if CONFIG_MODLIB_MAXDEPEND > 0 + /* Eliminate any dependencies that this module has on other modules */ + + (void)modlib_undepend(modp); +#endif + modlib_registry_unlock(); + + /* And free the registry entry */ + + lib_free(modp); + return OK; + +errout_with_lock: + modlib_registry_unlock(); + set_errno(-ret); + return ERROR; +} +#endif /**************************************************************************** * Public Functions @@ -103,12 +230,10 @@ int dlclose(FAR void *handle) * space and using the kernel symbol table and one residing in user space * using the user space symbol table. * - * The brute force way to accomplish this is by just copying the kernel - * module code into libc/module. + * dlremove() is essentially a clone of rmmod(). */ -#warning Missing logic - return -ENOSYS; + return dlremove(handle); #else /* if defined(CONFIG_BUILD_KERNEL) */ /* The KERNEL build is considerably more complex: In order to be shared, diff --git a/libc/dllfcn/lib_dlopen.c b/libc/dllfcn/lib_dlopen.c index 1ee51ca6a5..7c5c7fd645 100644 --- a/libc/dllfcn/lib_dlopen.c +++ b/libc/dllfcn/lib_dlopen.c @@ -44,8 +44,220 @@ #include #include #include +#include #include +#include + +#include "libc.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dldump_loadinfo + ****************************************************************************/ + +#ifdef CONFIG_BUILD_PROTECTED +#if defined(CONFIG_DEBUG_INFO) && defined(CONFIG_DEBUG_BINFMT) +static void dldump_loadinfo(FAR struct mod_loadinfo_s *loadinfo) +{ + int i; + + binfo("LOAD_INFO:\n"); + binfo(" textalloc: %08lx\n", (long)loadinfo->textalloc); + binfo(" datastart: %08lx\n", (long)loadinfo->datastart); + binfo(" textsize: %ld\n", (long)loadinfo->textsize); + binfo(" datasize: %ld\n", (long)loadinfo->datasize); + binfo(" filelen: %ld\n", (long)loadinfo->filelen); + binfo(" filfd: %d\n", loadinfo->filfd); + binfo(" symtabidx: %d\n", loadinfo->symtabidx); + binfo(" strtabidx: %d\n", loadinfo->strtabidx); + + binfo("ELF Header:\n"); + binfo(" e_ident: %02x %02x %02x %02x\n", + loadinfo->ehdr.e_ident[0], loadinfo->ehdr.e_ident[1], + loadinfo->ehdr.e_ident[2], loadinfo->ehdr.e_ident[3]); + binfo(" e_type: %04x\n", loadinfo->ehdr.e_type); + binfo(" e_machine: %04x\n", loadinfo->ehdr.e_machine); + binfo(" e_version: %08x\n", loadinfo->ehdr.e_version); + binfo(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry); + binfo(" e_phoff: %d\n", loadinfo->ehdr.e_phoff); + binfo(" e_shoff: %d\n", loadinfo->ehdr.e_shoff); + binfo(" e_flags: %08x\n" , loadinfo->ehdr.e_flags); + binfo(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize); + binfo(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize); + binfo(" e_phnum: %d\n", loadinfo->ehdr.e_phnum); + binfo(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize); + binfo(" e_shnum: %d\n", loadinfo->ehdr.e_shnum); + binfo(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx); + + if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0) + { + for (i = 0; i < loadinfo->ehdr.e_shnum; i++) + { + FAR Elf32_Shdr *shdr = &loadinfo->shdr[i]; + binfo("Sections %d:\n", i); + binfo(" sh_name: %08x\n", shdr->sh_name); + binfo(" sh_type: %08x\n", shdr->sh_type); + binfo(" sh_flags: %08x\n", shdr->sh_flags); + binfo(" sh_addr: %08x\n", shdr->sh_addr); + binfo(" sh_offset: %d\n", shdr->sh_offset); + binfo(" sh_size: %d\n", shdr->sh_size); + binfo(" sh_link: %d\n", shdr->sh_link); + binfo(" sh_info: %d\n", shdr->sh_info); + binfo(" sh_addralign: %d\n", shdr->sh_addralign); + binfo(" sh_entsize: %d\n", shdr->sh_entsize); + } + } +} +#else +# define dldump_loadinfo(i) +#endif +#endif + +/**************************************************************************** + * Name: dldump_initializer + ****************************************************************************/ + +#ifdef CONFIG_BUILD_PROTECTED +#ifdef CONFIG_MODLIB_DUMPBUFFER +static void dldump_initializer(mod_initializer_t initializer, + FAR struct mod_loadinfo_s *loadinfo) +{ + modlib_dumpbuffer("Initializer code", (FAR const uint8_t *)initializer, + MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512)); +} +#else +# define dldump_initializer(b,l) +#endif +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dlinsert + * + * Description: + * Verify that the file is an ELF module binary and, if so, load the + * shared library into user memory and initialize it for use. + * + * NOTE: modlib_setsymtab() had to have been called by application logic + * logic prior to calling this. Otherwise, dlinsert will be unable to + * resolve symbols in the OS module. + * + * Input Parameters: + * filename - Full path to the shared library file to be loaded + * + * Returned Value: + * A non-NULL module handle that can be used on subsequent calls to other + * shared library interfaces is returned on success. If insmod() was + * unable to load the module insmod() will return a NULL handle and the + * errno variable will be set appropriately. + * + ****************************************************************************/ + +#ifdef CONFIG_BUILD_PROTECTED +static inline FAR void *dlinsert(FAR const char *filename) +{ + struct mod_loadinfo_s loadinfo; + FAR struct module_s *modp; + mod_initializer_t initializer; + int ret; + + binfo("Loading file: %s\n", filename); + + /* Get exclusive access to the module registry */ + + modlib_registry_lock(); + + /* Initialize the ELF library to load the program binary. */ + + ret = modlib_initialize(filename, &loadinfo); + dldump_loadinfo(&loadinfo); + if (ret != 0) + { + serr("ERROR: Failed to initialize to load module: %d\n", ret); + goto errout_with_lock; + } + + /* Allocate a module registry entry to hold the module data */ + + modp = (FAR struct module_s *)lib_zalloc(sizeof(struct module_s)); + if (ret != 0) + { + binfo("Failed to initialize for load of ELF program: %d\n", ret); + goto errout_with_loadinfo; + } + + /* Load the program binary */ + + ret = modlib_load(&loadinfo); + dldump_loadinfo(&loadinfo); + if (ret != 0) + { + binfo("Failed to load ELF program binary: %d\n", ret); + goto errout_with_registry_entry; + } + + /* Bind the program to the kernel symbol table */ + + ret = modlib_bind(modp, &loadinfo); + if (ret != 0) + { + binfo("Failed to bind symbols program binary: %d\n", ret); + goto errout_with_load; + } + + /* Save the load information */ + + modp->alloc = (FAR void *)loadinfo.textalloc; +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + modp->textsize = loadinfo.textsize; + modp->datasize = loadinfo.datasize; +#endif + + /* Get the module initializer entry point */ + + initializer = (mod_initializer_t)(loadinfo.textalloc + loadinfo.ehdr.e_entry); +#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE) + modp->initializer = initializer; +#endif + dldump_initializer(initializer, &loadinfo); + + /* Call the module initializer */ + + ret = initializer(&modp->modinfo); + if (ret < 0) + { + binfo("Failed to initialize the module: %d\n", ret); + goto errout_with_load; + } + + /* Add the new module entry to the registry */ + + modlib_registry_add(modp); + + modlib_uninitialize(&loadinfo); + modlib_registry_unlock(); + return (FAR void *)modp; + +errout_with_load: + modlib_unload(&loadinfo); + (void)modlib_undepend(modp); +errout_with_registry_entry: + lib_free(modp); +errout_with_loadinfo: + modlib_uninitialize(&loadinfo); +errout_with_lock: + modlib_registry_unlock(); + set_errno(-ret); + return NULL; +} +#endif /**************************************************************************** * Public Functions @@ -192,12 +404,10 @@ FAR void *dlopen(FAR const char *file, int mode) * space and using the kernel symbol table and one residing in user space * using the user space symbol table. * - * The brute force way to accomplish this is by just copying the kernel - * module code into libc/module. + * dlinsert() is essentially a clone of insmod(). */ -#warning Missing logic - return NULL; + return dlinsert(file); #else /* if defined(CONFIG_BUILD_KERNEL) */ /* The KERNEL build is considerably more complex: In order to be shared, diff --git a/libc/dllfcn/lib_dlsym.c b/libc/dllfcn/lib_dlsym.c index d57255aadc..6d0bbf1367 100644 --- a/libc/dllfcn/lib_dlsym.c +++ b/libc/dllfcn/lib_dlsym.c @@ -40,8 +40,84 @@ #include #include +#include #include +#include +#include + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dlgetsym + * + * Description: + * dlgetsym() implements dlsym() for the PROTECTED build. + * + * Input Parameters: + * handle - The opaque, non-NULL value returned by a previous successful + * call to insmod(). + * name - A pointer to the symbol name string. + * + * Returned Value: + * See dlsym(). + * + ****************************************************************************/ + +#ifdef CONFIG_BUILD_PROTECTED +static inline FAR const void *dlgetsym(FAR void *handle, + FAR const char *name) +{ + FAR struct module_s *modp = (FAR struct module_s *)handle; + FAR const struct symtab_s *symbol; + int err; + int ret; + + /* Verify that the module is in the registry */ + + modlib_registry_lock(); + ret = modlib_registry_verify(modp); + if (ret < 0) + { + serr("ERROR: Failed to verify module: %d\n", ret); + err = -ret; + goto errout_with_lock; + } + + /* Does the module have a symbol table? */ + + if (modp->modinfo.exports == NULL || modp->modinfo.nexports == 0) + { + serr("ERROR: Module has no symbol table\n"); + err = ENOENT; + goto errout_with_lock; + } + + /* Search the symbol table for the matching symbol */ + + symbol = symtab_findbyname(modp->modinfo.exports, name, + modp->modinfo.nexports); + if (symbol == NULL) + { + serr("ERROR: Failed to find symbol in symbol \"$s\" in table\n", name); + err = ENOENT; + goto errout_with_lock; + } + + /* Return the address within the module assoicated with the symbol */ + + modlib_registry_unlock(); + DEBUGASSERT(symbol->sym_value != NULL); + return symbol->sym_value; + +errout_with_lock: + modlib_registry_unlock(); + set_errno(err); + return NULL; +} +#endif /**************************************************************************** * Public Functions @@ -93,12 +169,10 @@ FAR void *dlsym(FAR void *handle, FAR const char *name) * space and using the kernel symbol table and one residing in user space * using the user space symbol table. * - * The brute force way to accomplish this is by just copying the kernel - * module code into libc/module. + * dlgetsem() is essentially a clone of modsym(). */ -#warning Missing logic - return NULL; + return (FAR void *)dlgetsym(handle, name); #else /* if defined(CONFIG_BUILD_KERNEL) */ /* The KERNEL build is considerably more complex: In order to be shared, diff --git a/libc/dllfcn/lib_dlsymtab.c b/libc/dllfcn/lib_dlsymtab.c index 199e6b1e2a..a4f827bb5d 100644 --- a/libc/dllfcn/lib_dlsymtab.c +++ b/libc/dllfcn/lib_dlsymtab.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -67,27 +68,14 @@ int dlsymtab(FAR const struct symtab_s *symtab, int nsymbols) { -#if defined(CONFIG_BUILD_FLAT) - /* In the FLAT build, a shared library is essentially the same as a kernel - * module. +#if defined(CONFIG_BUILD_FLAT) || defined(CONFIG_BUILD_PROTECTED) + /* Set the symbol take information that will be used by this instance of + * the module library. */ modlib_setsymtab(symtab, nsymbols); return OK; -#elif defined(CONFIG_BUILD_PROTECTED) - /* The PROTECTED build is equivalent to the FLAT build EXCEPT that there - * must be two copies of the module logic: One residing in kernel - * space and using the kernel symbol table and one residing in user space - * using the user space symbol table. - * - * The brute force way to accomplish this is by just copying the kernel - * module code into libc/module. - */ - -#warning Missing logic - return NULL; - #else /* if defined(CONFIG_BUILD_KERNEL) */ /* The KERNEL build is considerably more complex: In order to be shared, * the .text portion of the module must be (1) build for PIC/PID operation @@ -99,6 +87,6 @@ int dlsymtab(FAR const struct symtab_s *symtab, int nsymbols) */ #warning Missing logic - return NULL; + return -ENOSYS; #endif } diff --git a/libc/modlib/modlib_init.c b/libc/modlib/modlib_init.c index 80cea9d685..964272ca0a 100644 --- a/libc/modlib/modlib_init.c +++ b/libc/modlib/modlib_init.c @@ -66,9 +66,9 @@ #endif #ifdef CONFIG_MODLIB_DUMPBUFFER -# define mod_dumpbuffer(m,b,n) sinfodumpbuffer(m,b,n) +# define modlib_dumpbuffer(m,b,n) sinfodumpbuffer(m,b,n) #else -# define mod_dumpbuffer(m,b,n) +# define modlib_dumpbuffer(m,b,n) #endif /**************************************************************************** @@ -76,7 +76,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_filelen + * Name: modlib_filelen * * Description: * Get the size of the ELF file @@ -87,8 +87,8 @@ * ****************************************************************************/ -static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo, - FAR const char *filename) +static inline int modlib_filelen(FAR struct mod_loadinfo_s *loadinfo, + FAR const char *filename) { struct stat buf; int ret; @@ -151,10 +151,10 @@ int modlib_initialize(FAR const char *filename, /* Get the length of the file. */ - ret = mod_filelen(loadinfo, filename); + ret = modlib_filelen(loadinfo, filename); if (ret < 0) { - serr("ERROR: mod_filelen failed: %d\n", ret); + serr("ERROR: modlib_filelen failed: %d\n", ret); return ret; } @@ -178,7 +178,7 @@ int modlib_initialize(FAR const char *filename, return ret; } - mod_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr, + modlib_dumpbuffer("ELF header", (FAR const uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr)); /* Verify the ELF header */ diff --git a/sched/module/mod_insmod.c b/sched/module/mod_insmod.c index 537f0e3b2d..c20cc7f3f6 100644 --- a/sched/module/mod_insmod.c +++ b/sched/module/mod_insmod.c @@ -58,20 +58,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* CONFIG_DEBUG_INFO, and CONFIG_DEBUG_BINFMT have to be defined or - * CONFIG_MODLIB_DUMPBUFFER does nothing. - */ - -#if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_DEBUG_BINFMT) -# undef CONFIG_MODLIB_DUMPBUFFER -#endif - -#ifdef CONFIG_MODLIB_DUMPBUFFER -# define mod_dumpbuffer(m,b,n) sinfodumpbuffer(m,b,n) -#else -# define mod_dumpbuffer(m,b,n) -#endif - #ifndef MIN # define MIN(a,b) (a < b ? a : b) #endif @@ -89,50 +75,50 @@ static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo) { int i; - sinfo("LOAD_INFO:\n"); - sinfo(" textalloc: %08lx\n", (long)loadinfo->textalloc); - sinfo(" datastart: %08lx\n", (long)loadinfo->datastart); - sinfo(" textsize: %ld\n", (long)loadinfo->textsize); - sinfo(" datasize: %ld\n", (long)loadinfo->datasize); - sinfo(" filelen: %ld\n", (long)loadinfo->filelen); - sinfo(" filfd: %d\n", loadinfo->filfd); - sinfo(" symtabidx: %d\n", loadinfo->symtabidx); - sinfo(" strtabidx: %d\n", loadinfo->strtabidx); + binfo("LOAD_INFO:\n"); + binfo(" textalloc: %08lx\n", (long)loadinfo->textalloc); + binfo(" datastart: %08lx\n", (long)loadinfo->datastart); + binfo(" textsize: %ld\n", (long)loadinfo->textsize); + binfo(" datasize: %ld\n", (long)loadinfo->datasize); + binfo(" filelen: %ld\n", (long)loadinfo->filelen); + binfo(" filfd: %d\n", loadinfo->filfd); + binfo(" symtabidx: %d\n", loadinfo->symtabidx); + binfo(" strtabidx: %d\n", loadinfo->strtabidx); - sinfo("ELF Header:\n"); - sinfo(" e_ident: %02x %02x %02x %02x\n", + binfo("ELF Header:\n"); + binfo(" e_ident: %02x %02x %02x %02x\n", loadinfo->ehdr.e_ident[0], loadinfo->ehdr.e_ident[1], loadinfo->ehdr.e_ident[2], loadinfo->ehdr.e_ident[3]); - sinfo(" e_type: %04x\n", loadinfo->ehdr.e_type); - sinfo(" e_machine: %04x\n", loadinfo->ehdr.e_machine); - sinfo(" e_version: %08x\n", loadinfo->ehdr.e_version); - sinfo(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry); - sinfo(" e_phoff: %d\n", loadinfo->ehdr.e_phoff); - sinfo(" e_shoff: %d\n", loadinfo->ehdr.e_shoff); - sinfo(" e_flags: %08x\n" , loadinfo->ehdr.e_flags); - sinfo(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize); - sinfo(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize); - sinfo(" e_phnum: %d\n", loadinfo->ehdr.e_phnum); - sinfo(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize); - sinfo(" e_shnum: %d\n", loadinfo->ehdr.e_shnum); - sinfo(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx); + binfo(" e_type: %04x\n", loadinfo->ehdr.e_type); + binfo(" e_machine: %04x\n", loadinfo->ehdr.e_machine); + binfo(" e_version: %08x\n", loadinfo->ehdr.e_version); + binfo(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry); + binfo(" e_phoff: %d\n", loadinfo->ehdr.e_phoff); + binfo(" e_shoff: %d\n", loadinfo->ehdr.e_shoff); + binfo(" e_flags: %08x\n" , loadinfo->ehdr.e_flags); + binfo(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize); + binfo(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize); + binfo(" e_phnum: %d\n", loadinfo->ehdr.e_phnum); + binfo(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize); + binfo(" e_shnum: %d\n", loadinfo->ehdr.e_shnum); + binfo(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx); if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0) { for (i = 0; i < loadinfo->ehdr.e_shnum; i++) { FAR Elf32_Shdr *shdr = &loadinfo->shdr[i]; - sinfo("Sections %d:\n", i); - sinfo(" sh_name: %08x\n", shdr->sh_name); - sinfo(" sh_type: %08x\n", shdr->sh_type); - sinfo(" sh_flags: %08x\n", shdr->sh_flags); - sinfo(" sh_addr: %08x\n", shdr->sh_addr); - sinfo(" sh_offset: %d\n", shdr->sh_offset); - sinfo(" sh_size: %d\n", shdr->sh_size); - sinfo(" sh_link: %d\n", shdr->sh_link); - sinfo(" sh_info: %d\n", shdr->sh_info); - sinfo(" sh_addralign: %d\n", shdr->sh_addralign); - sinfo(" sh_entsize: %d\n", shdr->sh_entsize); + binfo("Sections %d:\n", i); + binfo(" sh_name: %08x\n", shdr->sh_name); + binfo(" sh_type: %08x\n", shdr->sh_type); + binfo(" sh_flags: %08x\n", shdr->sh_flags); + binfo(" sh_addr: %08x\n", shdr->sh_addr); + binfo(" sh_offset: %d\n", shdr->sh_offset); + binfo(" sh_size: %d\n", shdr->sh_size); + binfo(" sh_link: %d\n", shdr->sh_link); + binfo(" sh_info: %d\n", shdr->sh_info); + binfo(" sh_addralign: %d\n", shdr->sh_addralign); + binfo(" sh_entsize: %d\n", shdr->sh_entsize); } } } @@ -148,8 +134,8 @@ static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo) static void mod_dumpinitializer(mod_initializer_t initializer, FAR struct mod_loadinfo_s *loadinfo) { - mod_dumpbuffer("Initializer code", (FAR const uint8_t *)initializer, - MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512)); + modlib_dumpbuffer("Initializer code", (FAR const uint8_t *)initializer, + MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512)); } #else # define mod_dumpinitializer(b,l) @@ -167,7 +153,7 @@ static void mod_dumpinitializer(mod_initializer_t initializer, * module into kernel memory and initialize it for use. * * NOTE: modlib_setsymtab() had to have been called in board-specific OS - * logicprior to calling this function from application logic (perhaps via + * logic prior to calling this function from application logic (perhaps via * boardctl(BOARDIOC_OS_SYMTAB). Otherwise, insmod will be unable to * resolve symbols in the OS module. * @@ -193,7 +179,7 @@ FAR void *insmod(FAR const char *filename, FAR const char *modname) int ret; DEBUGASSERT(filename != NULL && modname != NULL); - sinfo("Loading file: %s\n", filename); + binfo("Loading file: %s\n", filename); /* Get exclusive access to the module registry */ @@ -223,7 +209,7 @@ FAR void *insmod(FAR const char *filename, FAR const char *modname) modp = (FAR struct module_s *)kmm_zalloc(sizeof(struct module_s)); if (ret != 0) { - sinfo("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; } @@ -237,7 +223,7 @@ FAR void *insmod(FAR const char *filename, FAR const char *modname) mod_dumploadinfo(&loadinfo); if (ret != 0) { - sinfo("Failed to load ELF program binary: %d\n", ret); + binfo("Failed to load ELF program binary: %d\n", ret); goto errout_with_registry_entry; } @@ -246,7 +232,7 @@ FAR void *insmod(FAR const char *filename, FAR const char *modname) ret = modlib_bind(modp, &loadinfo); if (ret != 0) { - sinfo("Failed to bind symbols program binary: %d\n", ret); + binfo("Failed to bind symbols program binary: %d\n", ret); goto errout_with_load; } @@ -271,7 +257,7 @@ FAR void *insmod(FAR const char *filename, FAR const char *modname) ret = initializer(&modp->modinfo); if (ret < 0) { - sinfo("Failed to initialize the module: %d\n", ret); + binfo("Failed to initialize the module: %d\n", ret); goto errout_with_load; }