diff --git a/include/nuttx/lib/modlib.h b/include/nuttx/lib/modlib.h index 2ddde316d4b..16382254451 100644 --- a/include/nuttx/lib/modlib.h +++ b/include/nuttx/lib/modlib.h @@ -228,7 +228,7 @@ int modlib_initialize(FAR const char *filename, int modlib_uninitialize(FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** - * Name: mod_load + * Name: modlib_load * * Description: * Loads the binary into memory, allocating memory, performing relocations @@ -240,7 +240,7 @@ int modlib_uninitialize(FAR struct mod_loadinfo_s *loadinfo); * ****************************************************************************/ -int mod_load(FAR struct mod_loadinfo_s *loadinfo); +int modlib_load(FAR struct mod_loadinfo_s *loadinfo); /**************************************************************************** * Name: modlib_bind @@ -262,7 +262,7 @@ int modlib_bind(FAR struct module_s *modp, FAR struct mod_loadinfo_s *loadinfo); * * Description: * This function unloads the object from memory. This essentially undoes - * the actions of mod_load. It is called only under certain error + * the actions of modlib_load. It is called only under certain error * conditions after the module has been loaded but not yet started. * * Input Parameters: @@ -335,7 +335,7 @@ int modlib_undepend(FAR struct module_s *importer); int mod_verifyheader(FAR const Elf32_Ehdr *header); /**************************************************************************** - * Name: mod_read + * Name: modlib_read * * Description: * Read 'readsize' bytes from the object file at 'offset'. The data is @@ -347,75 +347,8 @@ int mod_verifyheader(FAR const Elf32_Ehdr *header); * ****************************************************************************/ -int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, - size_t readsize, off_t offset); - -/**************************************************************************** - * Name: mod_loadshdrs - * - * Description: - * Loads section headers into memory. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo); - -/**************************************************************************** - * Name: mod_findsection - * - * Description: - * A section by its name. - * - * Input Parameters: - * loadinfo - Load state information - * sectname - Name of the section to find - * - * Returned Value: - * On success, the index to the section is returned; A negated errno value - * is returned on failure. - * - ****************************************************************************/ - -int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, - FAR const char *sectname); - -/**************************************************************************** - * Name: mod_findsymtab - * - * Description: - * Find the symbol table section. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo); - -/**************************************************************************** - * Name: mod_readsym - * - * Description: - * Read the ELFT symbol structure at the specfied index into memory. - * - * Input Parameters: - * loadinfo - Load state information - * index - Symbol table index - * sym - Location to return the table entry - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, - FAR Elf32_Sym *sym); +int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, + size_t readsize, off_t offset); /**************************************************************************** * Name: mod_symvalue @@ -458,35 +391,6 @@ int mod_symvalue(FAR struct module_s *modp, int mod_freebuffers(FAR struct mod_loadinfo_s *loadinfo); -/**************************************************************************** - * Name: mod_allocbuffer - * - * Description: - * Perform the initial allocation of the I/O buffer, if it has not already - * been allocated. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo); - -/**************************************************************************** - * Name: mod_reallocbuffer - * - * Description: - * Increase the size of I/O buffer by the specified buffer increment. - * - * Returned Value: - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment); - /**************************************************************************** * Name: modlib_registry_lock * diff --git a/libc/modlib/Make.defs b/libc/modlib/Make.defs index 7917eee92e2..98ac439d11b 100644 --- a/libc/modlib/Make.defs +++ b/libc/modlib/Make.defs @@ -37,8 +37,9 @@ ifeq ($(CONFIG_LIBC_MODLIB),y) # Add the nuttx/lib/modlib.h files to the build -CSRCS += modlib_bind.c modlib_depend.c modlib_init.c modlib_registry.c -CSRCS += modlib_uninit.c +CSRCS += modlib_bind.c modlib_depend.c modlib_init.c modlib_iobuffer.c +CSRCS += modlib_load.c modlib_read.c modlib_registry.c modlib_sections.c +CSRCS += modlib_symbols.c modlib_uninit.c # Add the modlib directory to the build diff --git a/libc/modlib/modlib.h b/libc/modlib/modlib.h new file mode 100644 index 00000000000..65ccefe8d0d --- /dev/null +++ b/libc/modlib/modlib.h @@ -0,0 +1,153 @@ +/**************************************************************************** + * libc/modlib/modlib.h + * + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __LIBC_MODLIB_MODLIB_H +#define __LIBC_MODLIB_MODLIB_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: modlib_findsymtab + * + * Description: + * Find the symbol table section. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int modlib_findsymtab(FAR struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: modlib_readsym + * + * Description: + * Read the ELFT symbol structure at the specfied index into memory. + * + * Input Parameters: + * loadinfo - Load state information + * index - Symbol table index + * sym - Location to return the table entry + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int modlib_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, + FAR Elf32_Sym *sym); + +/**************************************************************************** + * Name: modlib_loadshdrs + * + * Description: + * Loads section headers into memory. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int modlib_loadshdrs(FAR struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: modlib_findsection + * + * Description: + * A section by its name. + * + * Input Parameters: + * loadinfo - Load state information + * sectname - Name of the section to find + * + * Returned Value: + * On success, the index to the section is returned; A negated errno value + * is returned on failure. + * + ****************************************************************************/ + +#if 0 /* Not used */ +int modlib_findsection(FAR struct mod_loadinfo_s *loadinfo, + FAR const char *sectname); +#endif + +/**************************************************************************** + * Name: modlib_allocbuffer + * + * Description: + * Perform the initial allocation of the I/O buffer, if it has not already + * been allocated. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int modlib_allocbuffer(FAR struct mod_loadinfo_s *loadinfo); + +/**************************************************************************** + * Name: modlib_reallocbuffer + * + * Description: + * Increase the size of I/O buffer by the specified buffer increment. + * + * Returned Value: + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +int modlib_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment); + +#endif /* __LIBC_MODLIB_MODLIB_H */ diff --git a/libc/modlib/modlib_bind.c b/libc/modlib/modlib_bind.c index 08b745a6ffe..4acf7edd7b5 100644 --- a/libc/modlib/modlib_bind.c +++ b/libc/modlib/modlib_bind.c @@ -50,6 +50,8 @@ #include #include +#include "modlib/modlib.h" + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -82,7 +84,7 @@ static inline int modlib_readrel(FAR struct mod_loadinfo_s *loadinfo, /* And, finally, read the symbol table entry into memory */ - return mod_read(loadinfo, (FAR uint8_t *)rel, sizeof(Elf32_Rel), offset); + return modlib_read(loadinfo, (FAR uint8_t *)rel, sizeof(Elf32_Rel), offset); } /**************************************************************************** @@ -138,7 +140,7 @@ static int modlib_relocate(FAR struct module_s *modp, /* Read the symbol table entry into memory */ - ret = mod_readsym(loadinfo, symidx, &sym); + ret = modlib_readsym(loadinfo, symidx, &sym); if (ret < 0) { serr("ERROR: Section %d reloc %d: Failed to read symbol[%d]: %d\n", @@ -234,7 +236,7 @@ int modlib_bind(FAR struct module_s *modp, FAR struct mod_loadinfo_s *loadinfo) /* Find the symbol and string tables */ - ret = mod_findsymtab(loadinfo); + ret = modlib_findsymtab(loadinfo); if (ret < 0) { return ret; @@ -244,10 +246,10 @@ int modlib_bind(FAR struct module_s *modp, FAR struct mod_loadinfo_s *loadinfo) * accumulate the variable length symbol name. */ - ret = mod_allocbuffer(loadinfo); + ret = modlib_allocbuffer(loadinfo); if (ret < 0) { - serr("ERROR: mod_allocbuffer failed: %d\n", ret); + serr("ERROR: modlib_allocbuffer failed: %d\n", ret); return -ENOMEM; } diff --git a/libc/modlib/modlib_init.c b/libc/modlib/modlib_init.c index 0753e80f249..ac0075b4ab8 100644 --- a/libc/modlib/modlib_init.c +++ b/libc/modlib/modlib_init.c @@ -168,7 +168,7 @@ int modlib_initialize(FAR const char *filename, /* Read the ELF ehdr from offset 0 */ - ret = mod_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr, + ret = modlib_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr, sizeof(Elf32_Ehdr), 0); if (ret < 0) { diff --git a/sched/module/mod_iobuffer.c b/libc/modlib/modlib_iobuffer.c similarity index 88% rename from sched/module/mod_iobuffer.c rename to libc/modlib/modlib_iobuffer.c index b2ba2f28157..8c3aee01a1f 100644 --- a/sched/module/mod_iobuffer.c +++ b/libc/modlib/modlib_iobuffer.c @@ -1,7 +1,7 @@ /**************************************************************************** - * sched/module/mod_iobuffer.c + * libc/modlib/modlib_iobuffer.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -42,16 +42,18 @@ #include #include -#include #include #include +#include "libc.h" +#include "modlib/modlib.h" + /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: mod_allocbuffer + * Name: modlib_allocbuffer * * Description: * Perform the initial allocation of the I/O buffer, if it has not already @@ -63,7 +65,7 @@ * ****************************************************************************/ -int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) +int modlib_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) { /* Has a buffer been allocated> */ @@ -71,7 +73,7 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) { /* No.. allocate one now */ - loadinfo->iobuffer = (FAR uint8_t *)kmm_malloc(CONFIG_MODLIB_BUFFERSIZE); + loadinfo->iobuffer = (FAR uint8_t *)lib_malloc(CONFIG_MODLIB_BUFFERSIZE); if (!loadinfo->iobuffer) { serr("ERROR: Failed to allocate an I/O buffer\n"); @@ -85,7 +87,7 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_reallocbuffer + * Name: modlib_reallocbuffer * * Description: * Increase the size of I/O buffer by the specified buffer increment. @@ -96,7 +98,7 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment) +int modlib_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment) { FAR void *buffer; size_t newsize; @@ -107,7 +109,7 @@ int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment) /* And perform the reallocation */ - buffer = kmm_realloc((FAR void *)loadinfo->iobuffer, newsize); + buffer = lib_realloc((FAR void *)loadinfo->iobuffer, newsize); if (!buffer) { serr("ERROR: Failed to reallocate the I/O buffer\n"); @@ -120,4 +122,3 @@ int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment) loadinfo->buflen = newsize; return OK; } - diff --git a/sched/module/mod_load.c b/libc/modlib/modlib_load.c similarity index 91% rename from sched/module/mod_load.c rename to libc/modlib/modlib_load.c index 3287c1486e1..28738dbfaa1 100644 --- a/sched/module/mod_load.c +++ b/libc/modlib/modlib_load.c @@ -1,7 +1,7 @@ /**************************************************************************** - * sched/module/mod_load.c + * libc/modlib/modlib_load.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -50,10 +50,12 @@ #include #include -#include #include #include +#include "libc.h" +#include "modlib/modlib.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -75,7 +77,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: mod_elfsize + * Name: modlib_elfsize * * Description: * Calculate total memory allocation for the ELF file. @@ -86,7 +88,7 @@ * ****************************************************************************/ -static void mod_elfsize(struct mod_loadinfo_s *loadinfo) +static void modlib_elfsize(struct mod_loadinfo_s *loadinfo) { size_t textsize; size_t datasize; @@ -129,7 +131,7 @@ static void mod_elfsize(struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_loadfile + * Name: modlib_loadfile * * Description: * Read the section data into memory. Section addresses in the shdr[] are @@ -141,7 +143,7 @@ static void mod_elfsize(struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -static inline int mod_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 *data; @@ -188,7 +190,7 @@ static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo) { /* Read the section data from sh_offset to the memory region */ - ret = mod_read(loadinfo, *pptr, shdr->sh_size, shdr->sh_offset); + ret = modlib_read(loadinfo, *pptr, shdr->sh_size, shdr->sh_offset); if (ret < 0) { serr("ERROR: Failed to read section %d: %d\n", i, ret); @@ -225,7 +227,7 @@ static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo) ****************************************************************************/ /**************************************************************************** - * Name: mod_load + * Name: modlib_load * * Description: * Loads the binary into memory, allocating memory, performing relocations @@ -237,7 +239,7 @@ static inline int mod_loadfile(FAR struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -int mod_load(FAR struct mod_loadinfo_s *loadinfo) +int modlib_load(FAR struct mod_loadinfo_s *loadinfo) { int ret; @@ -246,22 +248,22 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo) /* Load section headers into memory */ - ret = mod_loadshdrs(loadinfo); + ret = modlib_loadshdrs(loadinfo); if (ret < 0) { - serr("ERROR: mod_loadshdrs failed: %d\n", ret); + serr("ERROR: modlib_loadshdrs failed: %d\n", ret); goto errout_with_buffers; } /* Determine total size to allocate */ - mod_elfsize(loadinfo); + modlib_elfsize(loadinfo); /* Allocate (and zero) memory for the ELF file. */ /* Allocate memory to hold the ELF image */ - loadinfo->textalloc = (uintptr_t)kmm_zalloc(loadinfo->textsize + loadinfo->datasize); + loadinfo->textalloc = (uintptr_t)lib_zalloc(loadinfo->textsize + loadinfo->datasize); if (!loadinfo->textalloc) { serr("ERROR: Failed to allocate memory for the module\n"); @@ -273,10 +275,10 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo) /* Load ELF section data into memory */ - ret = mod_loadfile(loadinfo); + ret = modlib_loadfile(loadinfo); if (ret < 0) { - serr("ERROR: mod_loadfile failed: %d\n", ret); + serr("ERROR: modlib_loadfile failed: %d\n", ret); goto errout_with_buffers; } diff --git a/sched/module/mod_read.c b/libc/modlib/modlib_read.c similarity index 89% rename from sched/module/mod_read.c rename to libc/modlib/modlib_read.c index cd1de81d393..84ae5fb3b60 100644 --- a/sched/module/mod_read.c +++ b/libc/modlib/modlib_read.c @@ -1,7 +1,7 @@ /**************************************************************************** - * sched/module/mod_read.c + * libc/modlib/modlib_read.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -56,20 +56,16 @@ #undef ELF_DUMP_READDATA /* Define to dump all file data read */ -/**************************************************************************** - * Private Constant Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: mod_dumpreaddata + * Name: modlib_dumpreaddata ****************************************************************************/ #if defined(ELF_DUMP_READDATA) -static inline void mod_dumpreaddata(FAR char *buffer, int buflen) +static inline void modlib_dumpreaddata(FAR char *buffer, int buflen) { FAR uint32_t *buf32 = (FAR uint32_t *)buffer; int i; @@ -87,7 +83,7 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen) } } #else -# define mod_dumpreaddata(b,n) +# define modlib_dumpreaddata(b,n) #endif /**************************************************************************** @@ -95,7 +91,7 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen) ****************************************************************************/ /**************************************************************************** - * Name: mod_read + * Name: modlib_read * * Description: * Read 'readsize' bytes from the object file at 'offset'. The data is @@ -107,8 +103,8 @@ static inline void mod_dumpreaddata(FAR char *buffer, int buflen) * ****************************************************************************/ -int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, - size_t readsize, off_t offset) +int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, + size_t readsize, off_t offset) { ssize_t nbytes; /* Number of bytes read */ off_t rpos; /* Position returned by lseek */ @@ -159,6 +155,6 @@ int mod_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, } } - mod_dumpreaddata(buffer, readsize); + modlib_dumpreaddata(buffer, readsize); return OK; } diff --git a/sched/module/mod_sections.c b/libc/modlib/modlib_sections.c similarity index 88% rename from sched/module/mod_sections.c rename to libc/modlib/modlib_sections.c index 574eb8b9ac5..58a11076ef5 100644 --- a/sched/module/mod_sections.c +++ b/libc/modlib/modlib_sections.c @@ -1,7 +1,7 @@ /**************************************************************************** - * sched/module/mod_sections.c + * libc/modlib/modlib_sections.c * - * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,16 +45,18 @@ #include #include -#include #include #include +#include "libc.h" +#include "modlib/modlib.h" + /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: mod_sectname + * Name: modlib_sectname * * Description: * Get the symbol name in loadinfo->iobuffer[]. @@ -65,8 +67,8 @@ * ****************************************************************************/ -static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, - FAR const Elf32_Shdr *shdr) +static inline int modlib_sectname(FAR struct mod_loadinfo_s *loadinfo, + FAR const Elf32_Shdr *shdr) { FAR Elf32_Shdr *shstr; FAR uint8_t *buffer; @@ -127,7 +129,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, /* Read that number of bytes into the array */ buffer = &loadinfo->iobuffer[bytesread]; - ret = mod_read(loadinfo, buffer, readlen, offset); + ret = modlib_read(loadinfo, buffer, readlen, offset); if (ret < 0) { serr("ERROR: Failed to read section name: %d\n", ret); @@ -147,7 +149,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, /* No.. then we have to read more */ - ret = mod_reallocbuffer(loadinfo, CONFIG_MODLIB_BUFFERINCR); + ret = modlib_reallocbuffer(loadinfo, CONFIG_MODLIB_BUFFERINCR); if (ret < 0) { serr("ERROR: mod_reallocbuffer failed: %d\n", ret); @@ -165,7 +167,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, ****************************************************************************/ /**************************************************************************** - * Name: mod_loadshdrs + * Name: modlib_loadshdrs * * Description: * Loads section headers into memory. @@ -176,7 +178,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo, * ****************************************************************************/ -int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) +int modlib_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) { size_t shdrsize; int ret; @@ -202,7 +204,7 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) /* Allocate memory to hold a working copy of the sector header table */ - loadinfo->shdr = (FAR FAR Elf32_Shdr *)kmm_malloc(shdrsize); + loadinfo->shdr = (FAR FAR Elf32_Shdr *)lib_malloc(shdrsize); if (!loadinfo->shdr) { serr("ERROR: Failed to allocate the section header table. Size: %ld\n", @@ -212,7 +214,7 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) /* Read the section header table into memory */ - ret = mod_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, + ret = modlib_read(loadinfo, (FAR uint8_t *)loadinfo->shdr, shdrsize, loadinfo->ehdr.e_shoff); if (ret < 0) { @@ -223,7 +225,7 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_findsection + * Name: modlib_findsection * * Description: * A section by its name. @@ -238,8 +240,9 @@ int mod_loadshdrs(FAR struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, - FAR const char *sectname) +#if 0 /* Not used */ +int modlib_findsection(FAR struct mod_loadinfo_s *loadinfo, + FAR const char *sectname) { FAR const Elf32_Shdr *shdr; int ret; @@ -252,10 +255,10 @@ int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, /* Get the name of this section */ shdr = &loadinfo->shdr[i]; - ret = mod_sectname(loadinfo, shdr); + ret = modlib_sectname(loadinfo, shdr); if (ret < 0) { - serr("ERROR: mod_sectname failed: %d\n", ret); + serr("ERROR: modlib_sectname failed: %d\n", ret); return ret; } @@ -276,3 +279,4 @@ int mod_findsection(FAR struct mod_loadinfo_s *loadinfo, return -ENOENT; } +#endif diff --git a/sched/module/mod_symbols.c b/libc/modlib/modlib_symbols.c similarity index 92% rename from sched/module/mod_symbols.c rename to libc/modlib/modlib_symbols.c index 4ec42c581a6..61500107df2 100644 --- a/sched/module/mod_symbols.c +++ b/libc/modlib/modlib_symbols.c @@ -1,5 +1,5 @@ /**************************************************************************** - * sched/module/mod_symbols.c + * libc/modlib/modlib_symbols.c * * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -49,6 +49,8 @@ #include #include +#include "modlib/modlib.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -80,7 +82,7 @@ struct mod_exportinfo_s ****************************************************************************/ /**************************************************************************** - * Name: mod_symname + * Name: modlib_symname * * Description: * Get the symbol name in loadinfo->iobuffer[]. @@ -95,8 +97,8 @@ struct mod_exportinfo_s * ****************************************************************************/ -static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, - FAR const Elf32_Sym *sym) +static int modlib_symname(FAR struct mod_loadinfo_s *loadinfo, + FAR const Elf32_Sym *sym) { FAR uint8_t *buffer; off_t offset; @@ -139,10 +141,10 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, /* Read that number of bytes into the array */ buffer = &loadinfo->iobuffer[bytesread]; - ret = mod_read(loadinfo, buffer, readlen, offset); + ret = modlib_read(loadinfo, buffer, readlen, offset); if (ret < 0) { - serr("ERROR: mod_read failed: %d\n", ret); + serr("ERROR: modlib_read failed: %d\n", ret); return ret; } @@ -159,7 +161,7 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, /* No.. then we have to read more */ - ret = mod_reallocbuffer(loadinfo, CONFIG_MODLIB_BUFFERINCR); + ret = modlib_reallocbuffer(loadinfo, CONFIG_MODLIB_BUFFERINCR); if (ret < 0) { serr("ERROR: mod_reallocbuffer failed: %d\n", ret); @@ -173,7 +175,7 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, } /**************************************************************************** - * Name: mod_symcallback + * Name: modlib_symcallback * * Description: * modlib_registry_foreach() callback function. Test if the provided module, @@ -186,7 +188,7 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo, * ****************************************************************************/ -static int mod_symcallback(FAR struct module_s *modp, FAR void *arg) +static int modlib_symcallback(FAR struct module_s *modp, FAR void *arg) { FAR struct mod_exportinfo_s *exportinfo = (FAR struct mod_exportinfo_s *)arg; int ret; @@ -227,7 +229,7 @@ static int mod_symcallback(FAR struct module_s *modp, FAR void *arg) ****************************************************************************/ /**************************************************************************** - * Name: mod_findsymtab + * Name: modlib_findsymtab * * Description: * Find the symbol table section. @@ -238,7 +240,7 @@ static int mod_symcallback(FAR struct module_s *modp, FAR void *arg) * ****************************************************************************/ -int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo) +int modlib_findsymtab(FAR struct mod_loadinfo_s *loadinfo) { int i; @@ -266,7 +268,7 @@ int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo) } /**************************************************************************** - * Name: mod_readsym + * Name: modlib_readsym * * Description: * Read the ELFT symbol structure at the specfied index into memory. @@ -282,8 +284,8 @@ int mod_findsymtab(FAR struct mod_loadinfo_s *loadinfo) * ****************************************************************************/ -int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, - FAR Elf32_Sym *sym) +int modlib_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, + FAR Elf32_Sym *sym) { FAR Elf32_Shdr *symtab = &loadinfo->shdr[loadinfo->symtabidx]; off_t offset; @@ -302,7 +304,7 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index, /* And, finally, read the symbol table entry into memory */ - return mod_read(loadinfo, (FAR uint8_t *)sym, sizeof(Elf32_Sym), offset); + return modlib_read(loadinfo, (FAR uint8_t *)sym, sizeof(Elf32_Sym), offset); } /**************************************************************************** @@ -359,7 +361,7 @@ int mod_symvalue(FAR struct module_s *modp, { /* Get the name of the undefined symbol */ - ret = mod_symname(loadinfo, sym); + ret = modlib_symname(loadinfo, sym); if (ret < 0) { /* There are a few relocations for a few architectures that do @@ -382,10 +384,10 @@ int mod_symvalue(FAR struct module_s *modp, exportinfo.modp = modp; exportinfo.symbol = NULL; - ret = modlib_registry_foreach(mod_symcallback, (FAR void *)&exportinfo); + ret = modlib_registry_foreach(modlib_symcallback, (FAR void *)&exportinfo); if (ret < 0) { - serr("ERROR: mod_symcallback failed: \n", ret); + serr("ERROR: modlib_symcallback failed: \n", ret); return ret; } diff --git a/sched/module/Make.defs b/sched/module/Make.defs index 7bf6394a766..cb7a3c7bf51 100644 --- a/sched/module/Make.defs +++ b/sched/module/Make.defs @@ -41,7 +41,6 @@ CSRCS += mod_insmod.c mod_rmmod.c mod_modsym.c mod_symtab.c mod_modhandle.c # Loadable module library -CSRCS += mod_iobuffer.c mod_load.c mod_read.c mod_sections.c mod_symbols.c CSRCS += mod_unload.c mod_verify.c # procfs support diff --git a/sched/module/mod_insmod.c b/sched/module/mod_insmod.c index 3f9a073b964..6c8e67f0df9 100644 --- a/sched/module/mod_insmod.c +++ b/sched/module/mod_insmod.c @@ -233,7 +233,7 @@ FAR void *insmod(FAR const char *filename, FAR const char *modulename) /* Load the program binary */ - ret = mod_load(&loadinfo); + ret = modlib_load(&loadinfo); mod_dumploadinfo(&loadinfo); if (ret != 0) { diff --git a/sched/module/mod_unload.c b/sched/module/mod_unload.c index 7cb08590c94..87e42017d00 100644 --- a/sched/module/mod_unload.c +++ b/sched/module/mod_unload.c @@ -55,7 +55,7 @@ * * Description: * This function unloads the object from memory. This essentially undoes - * the actions of mod_load. It is called only under certain error + * the actions of modlib_load(). It is called only under certain error * conditions after the module has been loaded but not yet started. * * Returned Value: