Modules: Move first five of many C files from sched/module to libc/modlib

This commit is contained in:
Gregory Nutt 2017-01-29 10:05:15 -06:00
parent 00e46b5966
commit 5e94dd22bb
22 changed files with 241 additions and 250 deletions

View File

@ -53,16 +53,16 @@
****************************************************************************/ ****************************************************************************/
/* Configuration ************************************************************/ /* Configuration ************************************************************/
#ifndef CONFIG_LIBC_MODLIB_ALIGN_LOG2 #ifndef CONFIG_MODLIB_ALIGN_LOG2
# define CONFIG_LIBC_MODLIB_ALIGN_LOG2 2 # define CONFIG_MODLIB_ALIGN_LOG2 2
#endif #endif
#ifndef CONFIG_LIBC_MODLIB_BUFFERSIZE #ifndef CONFIG_MODLIB_BUFFERSIZE
# define CONFIG_LIBC_MODLIB_BUFFERSIZE 128 # define CONFIG_MODLIB_BUFFERSIZE 128
#endif #endif
#ifndef CONFIG_LIBC_MODLIB_BUFFERINCR #ifndef CONFIG_MODLIB_BUFFERINCR
# define CONFIG_LIBC_MODLIB_BUFFERINCR 32 # define CONFIG_MODLIB_BUFFERINCR 32
#endif #endif
#define MODULENAME_MAX 16 #define MODULENAME_MAX 16
@ -71,6 +71,64 @@
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
/* This is the type of the function that is called to uninitialize the
* the loaded module. This may mean, for example, un-registering a device
* driver. If the module is successfully initialized, its memory will be
* deallocated.
*
* Input Parameters:
* arg - An opaque argument that was previously returned by the initializer
* function.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure to
* initialize the module. If zero is returned, then the module memory
* will be deallocated. If the module is still in use (for example with
* open driver instances), the uninitialization function should fail with
* -EBUSY
*/
typedef CODE int (*mod_uninitializer_t)(FAR void *arg);
/* The contect of this structure is returned by module_initialize().
*
* uninitializer - The pointer to the uninitialization function. NULL may
* be returned if no uninitialization is needed (i.e, the
* the module memory can be deallocated at any time).
* arg - An argument that will be passed to the uninitialization
function.
* exports - A symbol table exported by the module
* nexports - The number of symbols in the exported symbol table.
*/
struct mod_info_s
{
mod_uninitializer_t uninitializer; /* Module uninitializer */
FAR void *arg; /* Uninitializer argument */
FAR const struct symtab_s *exports; /* Symbols exported by module */
unsigned int nexports; /* Number of symobols in exports list */
};
/* A NuttX module is expected to export a function called module_initialize()
* that has the following function prototype. This function should appear as
* the entry point in the ELF module file and will be called by the binfmt
* logic after the module has been loaded into kernel memory.
*
* Input Parameters:
* modinfo - Module information returned by modlib_initialize().
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure to
* initialize the module.
*/
typedef CODE int (*mod_initializer_t)(FAR struct mod_info_s *modinfo);
/* This is the type of the callback function used by modlib_registry_foreach() */
struct module_s;
typedef CODE int (*mod_callback_t)(FAR struct module_s *modp, FAR void *arg);
/* This describes the file to be loaded. */ /* This describes the file to be loaded. */
struct symtab_s; struct symtab_s;
@ -88,14 +146,14 @@ struct module_s
size_t datasize; /* Size of the kernel .bss/.data memory allocation */ size_t datasize; /* Size of the kernel .bss/.data memory allocation */
#endif #endif
#if CONFIG_LIBC_MODLIB_MAXDEPEND > 0 #if CONFIG_MODLIB_MAXDEPEND > 0
uint8_t dependents; /* Number of modules that depend on this module */ uint8_t dependents; /* Number of modules that depend on this module */
/* This is an upacked array of pointers to other modules that this module /* This is an upacked array of pointers to other modules that this module
* depends upon. * depends upon.
*/ */
FAR struct module_s *dependencies[CONFIG_LIBC_MODLIB_MAXDEPEND]; FAR struct module_s *dependencies[CONFIG_MODLIB_MAXDEPEND];
#endif #endif
}; };
@ -139,7 +197,7 @@ FAR int g_mod_nsymbols;
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_initialize * Name: modlib_initialize
* *
* Description: * Description:
* This function is called to configure the library to process an kernel * This function is called to configure the library to process an kernel
@ -151,15 +209,15 @@ FAR int g_mod_nsymbols;
* *
****************************************************************************/ ****************************************************************************/
int mod_initialize(FAR const char *filename, int modlib_initialize(FAR const char *filename,
FAR struct mod_loadinfo_s *loadinfo); FAR struct mod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_uninitialize * Name: modlib_uninitialize
* *
* Description: * Description:
* Releases any resources committed by mod_init(). This essentially * Releases any resources committed by modlib_initialize(). This essentially
* undoes the actions of mod_initialize. * undoes the actions of modlib_initialize.
* *
* Returned Value: * Returned Value:
* 0 (OK) is returned on success and a negated errno is returned on * 0 (OK) is returned on success and a negated errno is returned on
@ -167,7 +225,7 @@ int mod_initialize(FAR const char *filename,
* *
****************************************************************************/ ****************************************************************************/
int mod_uninitialize(FAR struct mod_loadinfo_s *loadinfo); int modlib_uninitialize(FAR struct mod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_load * Name: mod_load
@ -185,7 +243,7 @@ int mod_uninitialize(FAR struct mod_loadinfo_s *loadinfo);
int mod_load(FAR struct mod_loadinfo_s *loadinfo); int mod_load(FAR struct mod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_bind * Name: modlib_bind
* *
* Description: * Description:
* Bind the imported symbol names in the loaded module described by * Bind the imported symbol names in the loaded module described by
@ -197,7 +255,7 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo);
* *
****************************************************************************/ ****************************************************************************/
int mod_bind(FAR struct module_s *modp, FAR struct mod_loadinfo_s *loadinfo); int modlib_bind(FAR struct module_s *modp, FAR struct mod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_unload * Name: mod_unload
@ -220,7 +278,7 @@ int mod_bind(FAR struct module_s *modp, FAR struct mod_loadinfo_s *loadinfo);
int mod_unload(struct mod_loadinfo_s *loadinfo); int mod_unload(struct mod_loadinfo_s *loadinfo);
/**************************************************************************** /****************************************************************************
* Name: mod_depend * Name: modlib_depend
* *
* Description: * Description:
* Set up module dependencies between the exporter and the importer of a * Set up module dependencies between the exporter and the importer of a
@ -236,12 +294,12 @@ int mod_unload(struct mod_loadinfo_s *loadinfo);
* *
****************************************************************************/ ****************************************************************************/
#if CONFIG_LIBC_MODLIB_MAXDEPEND > 0 #if CONFIG_MODLIB_MAXDEPEND > 0
int mod_depend(FAR struct module_s *importer, FAR struct module_s *exporter); int modlib_depend(FAR struct module_s *importer, FAR struct module_s *exporter);
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: mod_undepend * Name: modlib_undepend
* *
* Description: * Description:
* Tear down module dependencies between the exporters and the importer of * Tear down module dependencies between the exporters and the importer of
@ -257,8 +315,8 @@ int mod_depend(FAR struct module_s *importer, FAR struct module_s *exporter);
* *
****************************************************************************/ ****************************************************************************/
#if CONFIG_LIBC_MODLIB_MAXDEPEND > 0 #if CONFIG_MODLIB_MAXDEPEND > 0
int mod_undepend(FAR struct module_s *importer); int modlib_undepend(FAR struct module_s *importer);
#endif #endif
/**************************************************************************** /****************************************************************************
@ -430,7 +488,7 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo);
int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment); int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment);
/**************************************************************************** /****************************************************************************
* Name: mod_registry_lock * Name: modlib_registry_lock
* *
* Description: * Description:
* Get exclusive access to the module registry. * Get exclusive access to the module registry.
@ -443,10 +501,10 @@ int mod_reallocbuffer(FAR struct mod_loadinfo_s *loadinfo, size_t increment);
* *
****************************************************************************/ ****************************************************************************/
void mod_registry_lock(void); void modlib_registry_lock(void);
/**************************************************************************** /****************************************************************************
* Name: mod_registry_unlock * Name: modlib_registry_unlock
* *
* Description: * Description:
* Relinquish the lock on the module registry * Relinquish the lock on the module registry
@ -459,10 +517,10 @@ void mod_registry_lock(void);
* *
****************************************************************************/ ****************************************************************************/
void mod_registry_unlock(void); void modlib_registry_unlock(void);
/**************************************************************************** /****************************************************************************
* Name: mod_registry_add * Name: modlib_registry_add
* *
* Description: * Description:
* Add a new entry to the module registry. * Add a new entry to the module registry.
@ -478,10 +536,10 @@ void mod_registry_unlock(void);
* *
****************************************************************************/ ****************************************************************************/
void mod_registry_add(FAR struct module_s *modp); void modlib_registry_add(FAR struct module_s *modp);
/**************************************************************************** /****************************************************************************
* Name: mod_registry_del * Name: modlib_registry_del
* *
* Description: * Description:
* Remove a module entry from the registry * Remove a module entry from the registry
@ -498,10 +556,10 @@ void mod_registry_add(FAR struct module_s *modp);
* *
****************************************************************************/ ****************************************************************************/
int mod_registry_del(FAR struct module_s *modp); int modlib_registry_del(FAR struct module_s *modp);
/**************************************************************************** /****************************************************************************
* Name: mod_registry_find * Name: modlib_registry_find
* *
* Description: * Description:
* Find an entry in the module registry using the name of the module. * Find an entry in the module registry using the name of the module.
@ -518,10 +576,10 @@ int mod_registry_del(FAR struct module_s *modp);
* *
****************************************************************************/ ****************************************************************************/
FAR struct module_s *mod_registry_find(FAR const char *modulename); FAR struct module_s *modlib_registry_find(FAR const char *modulename);
/**************************************************************************** /****************************************************************************
* Name: mod_registry_verify * Name: modlib_registry_verify
* *
* Description: * Description:
* Verify that a module handle is valid by traversing the module list and * Verify that a module handle is valid by traversing the module list and
@ -539,6 +597,30 @@ FAR struct module_s *mod_registry_find(FAR const char *modulename);
* *
****************************************************************************/ ****************************************************************************/
int mod_registry_verify(FAR struct module_s *modp); int modlib_registry_verify(FAR struct module_s *modp);
/****************************************************************************
* Name: modlib_registry_foreach
*
* Description:
* Visit each module in the registry. This is an internal OS interface and
* not available for use by applications.
*
* Input Parameters:
* callback - This callback function was be called for each entry in the
* registry.
* arg - This opaque argument will be passed to the callback function.
*
* Returned Value:
* This function normally returns zero (OK). If, however, any callback
* function returns a non-zero value, the traversal will be terminated and
* that non-zero value will be returned.
*
* Assumptions:
* The caller does NOT hold the lock on the module registry.
*
****************************************************************************/
int modlib_registry_foreach(mod_callback_t callback, FAR void *arg);
#endif /* __INCLUDE_NUTTX_LIB_MODLIB_H */ #endif /* __INCLUDE_NUTTX_LIB_MODLIB_H */

View File

@ -44,78 +44,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <elf32.h>
#include <nuttx/arch.h>
#include <nuttx/symtab.h>
#include <nuttx/binfmt/binfmt.h>
/****************************************************************************
* Public Types
****************************************************************************/
/* This is the type of the function that is called to uninitialize the
* the loaded module. This may mean, for example, un-registering a device
* driver. If the module is successfully initialized, its memory will be
* deallocated.
*
* Input Parameters:
* arg - An opaque argument that was previously returned by the initializer
* function.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure to
* initialize the module. If zero is returned, then the module memory
* will be deallocated. If the module is still in use (for example with
* open driver instances), the uninitialization function should fail with
* -EBUSY
*/
typedef CODE int (*mod_uninitializer_t)(FAR void *arg);
/* The contect of this structure is returned by module_initialize().
*
* uninitializer - The pointer to the uninitialization function. NULL may
* be returned if no uninitialization is needed (i.e, the
* the module memory can be deallocated at any time).
* arg - An argument that will be passed to the uninitialization
function.
* exports - A symbol table exported by the module
* nexports - The number of symbols in the exported symbol table.
*/
struct mod_info_s
{
mod_uninitializer_t uninitializer; /* Module uninitializer */
FAR void *arg; /* Uninitializer argument */
FAR const struct symtab_s *exports; /* Symbols exported by module */
unsigned int nexports; /* Number of symobols in exports list */
};
/* A NuttX module is expected to export a function called module_initialize()
* that has the following function prototype. This function should appear as
* the entry point in the ELF module file and will be called by the binfmt
* logic after the module has been loaded into kernel memory.
*
* Input Parameters:
* modinfo - Module information returned by mod_initialize().
*
* Returned Value:
* Zero (OK) on success; a negated errno value on any failure to
* initialize the module.
*/
typedef CODE int (*mod_initializer_t)(FAR struct mod_info_s *modinfo);
#if defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT)
/* This is the type of the callback function used by mod_registry_foreach() */
struct module_s;
typedef CODE int (*mod_callback_t)(FAR struct module_s *modp, FAR void *arg);
#endif
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes
****************************************************************************/ ****************************************************************************/
@ -260,32 +188,6 @@ FAR const void *modsym(FAR void *handle, FAR const char *name);
FAR void *modhandle(FAR const char *name); FAR void *modhandle(FAR const char *name);
/****************************************************************************
* Name: mod_registry_foreach
*
* Description:
* Visit each module in the registry. This is an internal OS interface and
* not available for use by applications.
*
* Input Parameters:
* callback - This callback function was be called for each entry in the
* registry.
* arg - This opaque argument will be passed to the callback function.
*
* Returned Value:
* This function normally returns zero (OK). If, however, any callback
* function returns a non-zero value, the traversal will be terminated and
* that non-zero value will be returned.
*
* Assumptions:
* The caller does NOT hold the lock on the module registry.
*
****************************************************************************/
#if defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT)
int mod_registry_foreach(mod_callback_t callback, FAR void *arg);
#endif
#undef EXTERN #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@ -7,6 +7,10 @@ config LIBC_MODLIB
bool bool
default n default n
config MODLIB_NAMES
bool
default n
menu "Module library configuration" menu "Module library configuration"
depends on LIBC_MODLIB depends on LIBC_MODLIB

View File

@ -37,6 +37,9 @@ ifeq ($(CONFIG_LIBC_MODLIB),y)
# Add the nuttx/lib/modlib.h files to the build # 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
# Add the modlib directory to the build # Add the modlib directory to the build
DEPPATH += --dep-path modlib DEPPATH += --dep-path modlib

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* sched/module/mod_bind.c * libc/modlib/modlib_bind.c
* *
* Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
@ -55,14 +55,14 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_readrel * Name: modlib_readrel
* *
* Description: * Description:
* Read the ELF32_Rel structure into memory. * Read the ELF32_Rel structure into memory.
* *
****************************************************************************/ ****************************************************************************/
static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo, static inline int modlib_readrel(FAR struct mod_loadinfo_s *loadinfo,
FAR const Elf32_Shdr *relsec, FAR const Elf32_Shdr *relsec,
int index, FAR Elf32_Rel *rel) int index, FAR Elf32_Rel *rel)
{ {
@ -86,7 +86,7 @@ static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo,
} }
/**************************************************************************** /****************************************************************************
* Name: mod_relocate and mod_relocateadd * Name: modlib_relocate and modlib_relocateadd
* *
* Description: * Description:
* Perform all relocations associated with a section. * Perform all relocations associated with a section.
@ -97,7 +97,7 @@ static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo,
* *
****************************************************************************/ ****************************************************************************/
static int mod_relocate(FAR struct module_s *modp, static int modlib_relocate(FAR struct module_s *modp,
FAR struct mod_loadinfo_s *loadinfo, int relidx) FAR struct mod_loadinfo_s *loadinfo, int relidx)
{ {
@ -122,7 +122,7 @@ static int mod_relocate(FAR struct module_s *modp,
/* Read the relocation entry into memory */ /* Read the relocation entry into memory */
ret = mod_readrel(loadinfo, relsec, i, &rel); ret = modlib_readrel(loadinfo, relsec, i, &rel);
if (ret < 0) if (ret < 0)
{ {
serr("ERROR: Section %d reloc %d: Failed to read relocation entry: %d\n", serr("ERROR: Section %d reloc %d: Failed to read relocation entry: %d\n",
@ -199,7 +199,7 @@ static int mod_relocate(FAR struct module_s *modp,
return OK; return OK;
} }
static int mod_relocateadd(FAR struct module_s *modp, static int modlib_relocateadd(FAR struct module_s *modp,
FAR struct mod_loadinfo_s *loadinfo, int relidx) FAR struct mod_loadinfo_s *loadinfo, int relidx)
{ {
serr("ERROR: Not implemented\n"); serr("ERROR: Not implemented\n");
@ -211,7 +211,7 @@ static int mod_relocateadd(FAR struct module_s *modp,
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_bind * Name: modlib_bind
* *
* Description: * Description:
* Bind the imported symbol names in the loaded module described by * Bind the imported symbol names in the loaded module described by
@ -227,7 +227,7 @@ static int mod_relocateadd(FAR struct module_s *modp,
* *
****************************************************************************/ ****************************************************************************/
int mod_bind(FAR struct module_s *modp, FAR struct mod_loadinfo_s *loadinfo) int modlib_bind(FAR struct module_s *modp, FAR struct mod_loadinfo_s *loadinfo)
{ {
int ret; int ret;
int i; int i;
@ -276,11 +276,11 @@ int mod_bind(FAR struct module_s *modp, FAR struct mod_loadinfo_s *loadinfo)
if (loadinfo->shdr[i].sh_type == SHT_REL) if (loadinfo->shdr[i].sh_type == SHT_REL)
{ {
ret = mod_relocate(modp, loadinfo, i); ret = modlib_relocate(modp, loadinfo, i);
} }
else if (loadinfo->shdr[i].sh_type == SHT_RELA) else if (loadinfo->shdr[i].sh_type == SHT_RELA)
{ {
ret = mod_relocateadd(modp, loadinfo, i); ret = modlib_relocateadd(modp, loadinfo, i);
} }
if (ret < 0) if (ret < 0)

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* sched/module/mod_depend.c * libc/modlib/modlib_depend.c
* *
* Copyright (C) 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
@ -43,7 +43,6 @@
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/module.h> #include <nuttx/module.h>
#include <nuttx/lib/modlib.h> #include <nuttx/lib/modlib.h>
@ -52,7 +51,7 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_depend * Name: modlib_depend
* *
* Description: * Description:
* Set up module dependencies between the exporter and the importer of a * Set up module dependencies between the exporter and the importer of a
@ -68,9 +67,9 @@
* *
****************************************************************************/ ****************************************************************************/
int mod_depend(FAR struct module_s *importer, FAR struct module_s *exporter) int modlib_depend(FAR struct module_s *importer, FAR struct module_s *exporter)
{ {
#if CONFIG_LIBC_MODLIB_MAXDEPEND > 0 #if CONFIG_MODLIB_MAXDEPEND > 0
int freendx; int freendx;
int i; int i;
@ -82,11 +81,11 @@ int mod_depend(FAR struct module_s *importer, FAR struct module_s *exporter)
* list of dependencies. * list of dependencies.
* *
* The list dependency list is a a dumb, upacked array of pointers. This * The list dependency list is a a dumb, upacked array of pointers. This
* should not be too inefficient if the number of CONFIG_LIBC_MODLIB_MAXDEPEND * should not be too inefficient if the number of CONFIG_MODLIB_MAXDEPEND
* is small. Otherwise, a more dynamic data structure would be in order. * is small. Otherwise, a more dynamic data structure would be in order.
*/ */
for (i = 0, freendx = -1; i < CONFIG_LIBC_MODLIB_MAXDEPEND; i++) for (i = 0, freendx = -1; i < CONFIG_MODLIB_MAXDEPEND; i++)
{ {
FAR const struct module_s *modp; FAR const struct module_s *modp;
@ -149,7 +148,7 @@ int mod_depend(FAR struct module_s *importer, FAR struct module_s *exporter)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_undepend * Name: modlib_undepend
* *
* Description: * Description:
* Tear down module dependencies between the exporters and the importer of * Tear down module dependencies between the exporters and the importer of
@ -165,9 +164,9 @@ int mod_depend(FAR struct module_s *importer, FAR struct module_s *exporter)
* *
****************************************************************************/ ****************************************************************************/
int mod_undepend(FAR struct module_s *importer) int modlib_undepend(FAR struct module_s *importer)
{ {
#if CONFIG_LIBC_MODLIB_MAXDEPEND > 0 #if CONFIG_MODLIB_MAXDEPEND > 0
FAR struct module_s *exporter; FAR struct module_s *exporter;
int i; int i;
@ -175,11 +174,11 @@ int mod_undepend(FAR struct module_s *importer)
/* Decrement the dependency count on each of exporters of symbols used by /* Decrement the dependency count on each of exporters of symbols used by
* this importer module. This is an upacked array of pointers. This * this importer module. This is an upacked array of pointers. This
* should not be too inefficient if the number of CONFIG_LIBC_MODLIB_MAXDEPEND * should not be too inefficient if the number of CONFIG_MODLIB_MAXDEPEND
* is small. Otherwise, a more dynamic data structure would be in order. * is small. Otherwise, a more dynamic data structure would be in order.
*/ */
for (i = 0; i < CONFIG_LIBC_MODLIB_MAXDEPEND; i++) for (i = 0; i < CONFIG_MODLIB_MAXDEPEND; i++)
{ {
exporter = importer->dependencies[i]; exporter = importer->dependencies[i];
if (exporter != NULL) if (exporter != NULL)

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* sched/module/mod_init.c * libc/modlib/modlib_init.c
* *
* Copyright (C) 2015 Gregory Nutt. All rights reserved. * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -55,24 +55,20 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* CONFIG_DEBUG_FEATURES, CONFIG_DEBUG_INFO, and CONFIG_LIBC_MODLIB_DUMPBUFFER /* CONFIG_DEBUG_FEATURES, CONFIG_DEBUG_INFO, and CONFIG_MODLIB_DUMPBUFFER
* have to be defined or CONFIG_LIBC_MODLIB_DUMPBUFFER does nothing. * have to be defined or CONFIG_MODLIB_DUMPBUFFER does nothing.
*/ */
#if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_LIBC_MODLIB_DUMPBUFFER) #if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_MODLIB_DUMPBUFFER)
# undef CONFIG_LIBC_MODLIB_DUMPBUFFER # undef CONFIG_MODLIB_DUMPBUFFER
#endif #endif
#ifdef CONFIG_LIBC_MODLIB_DUMPBUFFER #ifdef CONFIG_MODLIB_DUMPBUFFER
# define mod_dumpbuffer(m,b,n) sinfodumpbuffer(m,b,n) # define mod_dumpbuffer(m,b,n) sinfodumpbuffer(m,b,n)
#else #else
# define mod_dumpbuffer(m,b,n) # define mod_dumpbuffer(m,b,n)
#endif #endif
/****************************************************************************
* Private Constant Data
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@ -128,7 +124,7 @@ static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo,
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_initialize * Name: modlib_initialize
* *
* Description: * Description:
* This function is called to configure the library to process an ELF * This function is called to configure the library to process an ELF
@ -140,7 +136,7 @@ static inline int mod_filelen(FAR struct mod_loadinfo_s *loadinfo,
* *
****************************************************************************/ ****************************************************************************/
int mod_initialize(FAR const char *filename, int modlib_initialize(FAR const char *filename,
FAR struct mod_loadinfo_s *loadinfo) FAR struct mod_loadinfo_s *loadinfo)
{ {
int ret; int ret;

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* sched/module/mod_registry.c * libc/modlib/modlib_registry.c
* *
* Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
@ -61,7 +61,7 @@ struct mod_registrylock_s
{ {
sem_t lock; /* The actual registry lock */ sem_t lock; /* The actual registry lock */
pid_t holder; /* The PID of the current holder of the lock */ pid_t holder; /* The PID of the current holder of the lock */
int16_t count; /* The number of nested calls to mod_registry_lock */ int16_t count; /* The number of nested calls to modlib_registry_lock */
}; };
/**************************************************************************** /****************************************************************************
@ -82,7 +82,7 @@ static FAR struct module_s *g_mod_registry;
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_registry_lock * Name: modlib_registry_lock
* *
* Description: * Description:
* Get exclusive access to the module registry. * Get exclusive access to the module registry.
@ -95,7 +95,7 @@ static FAR struct module_s *g_mod_registry;
* *
****************************************************************************/ ****************************************************************************/
void mod_registry_lock(void) void modlib_registry_lock(void)
{ {
pid_t me; pid_t me;
@ -131,7 +131,7 @@ void mod_registry_lock(void)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_registry_unlock * Name: modlib_registry_unlock
* *
* Description: * Description:
* Relinquish the lock on the module registry * Relinquish the lock on the module registry
@ -144,7 +144,7 @@ void mod_registry_lock(void)
* *
****************************************************************************/ ****************************************************************************/
void mod_registry_unlock(void) void modlib_registry_unlock(void)
{ {
DEBUGASSERT(g_modlock.holder == getpid()); DEBUGASSERT(g_modlock.holder == getpid());
@ -168,7 +168,7 @@ void mod_registry_unlock(void)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_registry_add * Name: modlib_registry_add
* *
* Description: * Description:
* Add a new entry to the module registry. * Add a new entry to the module registry.
@ -184,7 +184,7 @@ void mod_registry_unlock(void)
* *
****************************************************************************/ ****************************************************************************/
void mod_registry_add(FAR struct module_s *modp) void modlib_registry_add(FAR struct module_s *modp)
{ {
DEBUGASSERT(modp); DEBUGASSERT(modp);
modp->flink = g_mod_registry; modp->flink = g_mod_registry;
@ -192,7 +192,7 @@ void mod_registry_add(FAR struct module_s *modp)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_registry_del * Name: modlib_registry_del
* *
* Description: * Description:
* Remove a module entry from the registry * Remove a module entry from the registry
@ -209,7 +209,7 @@ void mod_registry_add(FAR struct module_s *modp)
* *
****************************************************************************/ ****************************************************************************/
int mod_registry_del(FAR struct module_s *modp) int modlib_registry_del(FAR struct module_s *modp)
{ {
FAR struct module_s *prev; FAR struct module_s *prev;
FAR struct module_s *curr; FAR struct module_s *curr;
@ -238,7 +238,7 @@ int mod_registry_del(FAR struct module_s *modp)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_registry_find * Name: modlib_registry_find
* *
* Description: * Description:
* Find an entry in the module registry using the name of the module. * Find an entry in the module registry using the name of the module.
@ -255,7 +255,7 @@ int mod_registry_del(FAR struct module_s *modp)
* *
****************************************************************************/ ****************************************************************************/
FAR struct module_s *mod_registry_find(FAR const char *modulename) FAR struct module_s *modlib_registry_find(FAR const char *modulename)
{ {
FAR struct module_s *modp; FAR struct module_s *modp;
@ -267,7 +267,7 @@ FAR struct module_s *mod_registry_find(FAR const char *modulename)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_registry_verify * Name: modlib_registry_verify
* *
* Description: * Description:
* Verify that a module handle is valid by traversing the module list and * Verify that a module handle is valid by traversing the module list and
@ -285,7 +285,7 @@ FAR struct module_s *mod_registry_find(FAR const char *modulename)
* *
****************************************************************************/ ****************************************************************************/
int mod_registry_verify(FAR struct module_s *modp) int modlib_registry_verify(FAR struct module_s *modp)
{ {
FAR struct module_s *node; FAR struct module_s *node;
@ -301,7 +301,7 @@ int mod_registry_verify(FAR struct module_s *modp)
} }
/**************************************************************************** /****************************************************************************
* Name: mod_registry_foreach * Name: modlib_registry_foreach
* *
* Description: * Description:
* Visit each module in the registry * Visit each module in the registry
@ -318,14 +318,14 @@ int mod_registry_verify(FAR struct module_s *modp)
* *
****************************************************************************/ ****************************************************************************/
int mod_registry_foreach(mod_callback_t callback, FAR void *arg) int modlib_registry_foreach(mod_callback_t callback, FAR void *arg)
{ {
FAR struct module_s *modp; FAR struct module_s *modp;
int ret = OK; int ret = OK;
/* Get exclusive access to the module registry */ /* Get exclusive access to the module registry */
mod_registry_lock(); modlib_registry_lock();
/* Visit each installed module */ /* Visit each installed module */
@ -340,6 +340,6 @@ int mod_registry_foreach(mod_callback_t callback, FAR void *arg)
} }
} }
mod_registry_unlock(); modlib_registry_unlock();
return ret; return ret;
} }

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* sched/module/mod_uninit.c * libc/modlib/modlib_uninit.c
* *
* Copyright (C) 2015 Gregory Nutt. All rights reserved. * Copyright (C) 2015. 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -47,16 +47,18 @@
#include <nuttx/module.h> #include <nuttx/module.h>
#include <nuttx/lib/modlib.h> #include <nuttx/lib/modlib.h>
#include "libc.h"
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mod_uninitialize * Name: modlib_uninitialize
* *
* Description: * Description:
* Releases any resources committed by mod_initialize(). This essentially * Releases any resources committed by modlib_initialize(). This
* undoes the actions of mod_initialize. * essentially undoes the actions of modlib_initialize.
* *
* Returned Value: * Returned Value:
* 0 (OK) is returned on success and a negated errno is returned on * 0 (OK) is returned on success and a negated errno is returned on
@ -64,7 +66,7 @@
* *
****************************************************************************/ ****************************************************************************/
int mod_uninitialize(struct mod_loadinfo_s *loadinfo) int modlib_uninitialize(struct mod_loadinfo_s *loadinfo)
{ {
/* Free all working buffers */ /* Free all working buffers */
@ -96,15 +98,15 @@ int mod_freebuffers(struct mod_loadinfo_s *loadinfo)
{ {
/* Release all working allocations */ /* Release all working allocations */
if (loadinfo->shdr) if (loadinfo->shdr != NULL)
{ {
kmm_free((FAR void *)loadinfo->shdr); lib_free((FAR void *)loadinfo->shdr);
loadinfo->shdr = NULL; loadinfo->shdr = NULL;
} }
if (loadinfo->iobuffer) if (loadinfo->iobuffer != NULL)
{ {
kmm_free((FAR void *)loadinfo->iobuffer); lib_free((FAR void *)loadinfo->iobuffer);
loadinfo->iobuffer = NULL; loadinfo->iobuffer = NULL;
loadinfo->buflen = 0; loadinfo->buflen = 0;
} }

View File

@ -1123,6 +1123,7 @@ config MODULE
bool "Enable loadable OS modules" bool "Enable loadable OS modules"
default n default n
select LIBC_MODLIB select LIBC_MODLIB
select LIBC_MODLIB_NAMES
select LIBC_ARCH_ELF select LIBC_ARCH_ELF
---help--- ---help---
Enable support for loadable OS modules. Default: n Enable support for loadable OS modules. Default: n

View File

@ -1,7 +1,7 @@
############################################################################ ############################################################################
# sched/module/Make.defs # sched/module/Make.defs
# #
# Copyright (C) 2015 Gregory Nutt. All rights reserved. # Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org> # Author: Gregory Nutt <gnutt@nuttx.org>
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -41,8 +41,7 @@ CSRCS += mod_insmod.c mod_rmmod.c mod_modsym.c mod_symtab.c mod_modhandle.c
# Loadable module library # Loadable module library
CSRCS += mod_bind.c mod_depend.c mod_init.c mod_iobuffer.c mod_load.c CSRCS += mod_iobuffer.c mod_load.c mod_read.c mod_sections.c mod_symbols.c
CSRCS += mod_read.c mod_registry.c mod_sections.c mod_symbols.c mod_uninit.c
CSRCS += mod_unload.c mod_verify.c CSRCS += mod_unload.c mod_verify.c
# procfs support # procfs support

View File

@ -59,14 +59,14 @@
****************************************************************************/ ****************************************************************************/
/* CONFIG_DEBUG_INFO, and CONFIG_DEBUG_BINFMT have to be defined or /* CONFIG_DEBUG_INFO, and CONFIG_DEBUG_BINFMT have to be defined or
* CONFIG_LIBC_MODLIB_DUMPBUFFER does nothing. * CONFIG_MODLIB_DUMPBUFFER does nothing.
*/ */
#if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_DEBUG_BINFMT) #if !defined(CONFIG_DEBUG_INFO) || !defined (CONFIG_DEBUG_BINFMT)
# undef CONFIG_LIBC_MODLIB_DUMPBUFFER # undef CONFIG_MODLIB_DUMPBUFFER
#endif #endif
#ifdef CONFIG_LIBC_MODLIB_DUMPBUFFER #ifdef CONFIG_MODLIB_DUMPBUFFER
# define mod_dumpbuffer(m,b,n) sinfodumpbuffer(m,b,n) # define mod_dumpbuffer(m,b,n) sinfodumpbuffer(m,b,n)
#else #else
# define mod_dumpbuffer(m,b,n) # define mod_dumpbuffer(m,b,n)
@ -144,7 +144,7 @@ static void mod_dumploadinfo(FAR struct mod_loadinfo_s *loadinfo)
* Name: mod_dumpinitializer * Name: mod_dumpinitializer
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_LIBC_MODLIB_DUMPBUFFER #ifdef CONFIG_MODLIB_DUMPBUFFER
static void mod_dumpinitializer(mod_initializer_t initializer, static void mod_dumpinitializer(mod_initializer_t initializer,
FAR struct mod_loadinfo_s *loadinfo) FAR struct mod_loadinfo_s *loadinfo)
{ {
@ -197,20 +197,20 @@ FAR void *insmod(FAR const char *filename, FAR const char *modulename)
/* Get exclusive access to the module registry */ /* Get exclusive access to the module registry */
mod_registry_lock(); modlib_registry_lock();
/* Check if this module is already installed */ /* Check if this module is already installed */
if (mod_registry_find(modulename) != NULL) if (modlib_registry_find(modulename) != NULL)
{ {
mod_registry_unlock(); modlib_registry_unlock();
ret = -EEXIST; ret = -EEXIST;
goto errout_with_lock; goto errout_with_lock;
} }
/* Initialize the ELF library to load the program binary. */ /* Initialize the ELF library to load the program binary. */
ret = mod_initialize(filename, &loadinfo); ret = modlib_initialize(filename, &loadinfo);
mod_dumploadinfo(&loadinfo); mod_dumploadinfo(&loadinfo);
if (ret != 0) if (ret != 0)
{ {
@ -243,7 +243,7 @@ FAR void *insmod(FAR const char *filename, FAR const char *modulename)
/* Bind the program to the kernel symbol table */ /* Bind the program to the kernel symbol table */
ret = mod_bind(modp, &loadinfo); ret = modlib_bind(modp, &loadinfo);
if (ret != 0) if (ret != 0)
{ {
sinfo("Failed to bind symbols program binary: %d\n", ret); sinfo("Failed to bind symbols program binary: %d\n", ret);
@ -277,21 +277,21 @@ FAR void *insmod(FAR const char *filename, FAR const char *modulename)
/* Add the new module entry to the registry */ /* Add the new module entry to the registry */
mod_registry_add(modp); modlib_registry_add(modp);
mod_uninitialize(&loadinfo); modlib_uninitialize(&loadinfo);
mod_registry_unlock(); modlib_registry_unlock();
return (FAR void *)modp; return (FAR void *)modp;
errout_with_load: errout_with_load:
mod_unload(&loadinfo); mod_unload(&loadinfo);
(void)mod_undepend(modp); (void)modlib_undepend(modp);
errout_with_registry_entry: errout_with_registry_entry:
kmm_free(modp); kmm_free(modp);
errout_with_loadinfo: errout_with_loadinfo:
mod_uninitialize(&loadinfo); modlib_uninitialize(&loadinfo);
errout_with_lock: errout_with_lock:
mod_registry_unlock(); modlib_registry_unlock();
set_errno(-ret); set_errno(-ret);
return NULL; return NULL;
} }

View File

@ -71,14 +71,14 @@ int mod_allocbuffer(FAR struct mod_loadinfo_s *loadinfo)
{ {
/* No.. allocate one now */ /* No.. allocate one now */
loadinfo->iobuffer = (FAR uint8_t *)kmm_malloc(CONFIG_LIBC_MODLIB_BUFFERSIZE); loadinfo->iobuffer = (FAR uint8_t *)kmm_malloc(CONFIG_MODLIB_BUFFERSIZE);
if (!loadinfo->iobuffer) if (!loadinfo->iobuffer)
{ {
serr("ERROR: Failed to allocate an I/O buffer\n"); serr("ERROR: Failed to allocate an I/O buffer\n");
return -ENOMEM; return -ENOMEM;
} }
loadinfo->buflen = CONFIG_LIBC_MODLIB_BUFFERSIZE; loadinfo->buflen = CONFIG_MODLIB_BUFFERSIZE;
} }
return OK; return OK;

View File

@ -58,7 +58,7 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define ELF_ALIGN_MASK ((1 << CONFIG_LIBC_MODLIB_ALIGN_LOG2) - 1) #define ELF_ALIGN_MASK ((1 << CONFIG_MODLIB_ALIGN_LOG2) - 1)
#define ELF_ALIGNUP(a) (((unsigned long)(a) + ELF_ALIGN_MASK) & ~ELF_ALIGN_MASK) #define ELF_ALIGNUP(a) (((unsigned long)(a) + ELF_ALIGN_MASK) & ~ELF_ALIGN_MASK)
#define ELF_ALIGNDOWN(a) ((unsigned long)(a) & ~ELF_ALIGN_MASK) #define ELF_ALIGNDOWN(a) ((unsigned long)(a) & ~ELF_ALIGN_MASK)

View File

@ -78,18 +78,18 @@ FAR void *modhandle(FAR const char *name)
/* Get exclusive access to the module registry */ /* Get exclusive access to the module registry */
mod_registry_lock(); modlib_registry_lock();
/* Find the module entry for this name in the registry */ /* Find the module entry for this name in the registry */
modp = mod_registry_find(name); modp = modlib_registry_find(name);
if (modp == NULL) if (modp == NULL)
{ {
serr("ERROR: Failed to find module %s: %d\n", name, ret); serr("ERROR: Failed to find module %s: %d\n", name, ret);
set_errno(ENOENT); set_errno(ENOENT);
} }
mod_registry_unlock(); modlib_registry_unlock();
return (FAR void *)modp; return (FAR void *)modp;
} }

View File

@ -44,6 +44,7 @@
#include <debug.h> #include <debug.h>
#include <nuttx/module.h> #include <nuttx/module.h>
#include <nuttx/symtab.h>
#include <nuttx/lib/modlib.h> #include <nuttx/lib/modlib.h>
/**************************************************************************** /****************************************************************************
@ -88,8 +89,8 @@ FAR const void *modsym(FAR void *handle, FAR const char *name)
/* Verify that the module is in the registry */ /* Verify that the module is in the registry */
mod_registry_lock(); modlib_registry_lock();
ret = mod_registry_verify(modp); ret = modlib_registry_verify(modp);
if (ret < 0) if (ret < 0)
{ {
serr("ERROR: Failed to verify module: %d\n", ret); serr("ERROR: Failed to verify module: %d\n", ret);
@ -119,12 +120,12 @@ FAR const void *modsym(FAR void *handle, FAR const char *name)
/* Return the address within the module assoicated with the symbol */ /* Return the address within the module assoicated with the symbol */
mod_registry_unlock(); modlib_registry_unlock();
DEBUGASSERT(symbol->sym_value != NULL); DEBUGASSERT(symbol->sym_value != NULL);
return symbol->sym_value; return symbol->sym_value;
errout_with_lock: errout_with_lock:
mod_registry_unlock(); modlib_registry_unlock();
set_errno(err); set_errno(err);
return NULL; return NULL;
} }

View File

@ -247,7 +247,7 @@ static ssize_t modprocfs_read(FAR struct file *filep, FAR char *buffer,
priv->buflen = buflen; priv->buflen = buflen;
priv->offset = filep->f_pos; priv->offset = filep->f_pos;
ret = mod_registry_foreach(modprocfs_callback, priv); ret = modlib_registry_foreach(modprocfs_callback, priv);
if (ret >= 0) if (ret >= 0)
{ {
filep->f_pos += priv->totalsize; filep->f_pos += priv->totalsize;

View File

@ -77,18 +77,18 @@ int rmmod(FAR void *handle)
/* Get exclusive access to the module registry */ /* Get exclusive access to the module registry */
mod_registry_lock(); modlib_registry_lock();
/* Verify that the module is in the registry */ /* Verify that the module is in the registry */
ret = mod_registry_verify(modp); ret = modlib_registry_verify(modp);
if (ret < 0) if (ret < 0)
{ {
serr("ERROR: Failed to verify module: %d\n", ret); serr("ERROR: Failed to verify module: %d\n", ret);
goto errout_with_lock; goto errout_with_lock;
} }
#if CONFIG_LIBC_MODLIB_MAXDEPEND > 0 #if CONFIG_MODLIB_MAXDEPEND > 0
/* Refuse to remove any module that other modules may depend upon. */ /* Refuse to remove any module that other modules may depend upon. */
if (modp->dependents > 0) if (modp->dependents > 0)
@ -145,19 +145,19 @@ int rmmod(FAR void *handle)
/* Remove the module from the registry */ /* Remove the module from the registry */
ret = mod_registry_del(modp); ret = modlib_registry_del(modp);
if (ret < 0) if (ret < 0)
{ {
serr("ERROR: Failed to remove the module from the registry: %d\n", ret); serr("ERROR: Failed to remove the module from the registry: %d\n", ret);
goto errout_with_lock; goto errout_with_lock;
} }
#if CONFIG_LIBC_MODLIB_MAXDEPEND > 0 #if CONFIG_MODLIB_MAXDEPEND > 0
/* Eliminate any dependencies that this module has on other modules */ /* Eliminate any dependencies that this module has on other modules */
(void)mod_undepend(modp); (void)modlib_undepend(modp);
#endif #endif
mod_registry_unlock(); modlib_registry_unlock();
/* And free the registry entry */ /* And free the registry entry */
@ -165,7 +165,7 @@ int rmmod(FAR void *handle)
return OK; return OK;
errout_with_lock: errout_with_lock:
mod_registry_unlock(); modlib_registry_unlock();
set_errno(-ret); set_errno(-ret);
return ERROR; return ERROR;
} }

View File

@ -147,7 +147,7 @@ static inline int mod_sectname(FAR struct mod_loadinfo_s *loadinfo,
/* No.. then we have to read more */ /* No.. then we have to read more */
ret = mod_reallocbuffer(loadinfo, CONFIG_LIBC_MODLIB_BUFFERINCR); ret = mod_reallocbuffer(loadinfo, CONFIG_MODLIB_BUFFERINCR);
if (ret < 0) if (ret < 0)
{ {
serr("ERROR: mod_reallocbuffer failed: %d\n", ret); serr("ERROR: mod_reallocbuffer failed: %d\n", ret);

View File

@ -55,8 +55,8 @@
/* Amount to reallocate buffer when buffer is full */ /* Amount to reallocate buffer when buffer is full */
#ifndef CONFIG_LIBC_MODLIB_BUFFERINCR #ifndef CONFIG_MODLIB_BUFFERINCR
# define CONFIG_LIBC_MODLIB_BUFFERINCR 32 # define CONFIG_MODLIB_BUFFERINCR 32
#endif #endif
/* Return values search for exported modules */ /* Return values search for exported modules */
@ -159,7 +159,7 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo,
/* No.. then we have to read more */ /* No.. then we have to read more */
ret = mod_reallocbuffer(loadinfo, CONFIG_LIBC_MODLIB_BUFFERINCR); ret = mod_reallocbuffer(loadinfo, CONFIG_MODLIB_BUFFERINCR);
if (ret < 0) if (ret < 0)
{ {
serr("ERROR: mod_reallocbuffer failed: %d\n", ret); serr("ERROR: mod_reallocbuffer failed: %d\n", ret);
@ -176,7 +176,7 @@ static int mod_symname(FAR struct mod_loadinfo_s *loadinfo,
* Name: mod_symcallback * Name: mod_symcallback
* *
* Description: * Description:
* mod_registry_foreach() callback function. Test if the provided module, * modlib_registry_foreach() callback function. Test if the provided module,
* modp, exports the symbol of interest. If so, return that symbol value * modp, exports the symbol of interest. If so, return that symbol value
* and setup the module dependency relationship. * and setup the module dependency relationship.
* *
@ -209,10 +209,10 @@ static int mod_symcallback(FAR struct module_s *modp, FAR void *arg)
* stop the traversal. * stop the traversal.
*/ */
ret = mod_depend(exportinfo->modp, modp); ret = modlib_depend(exportinfo->modp, modp);
if (ret < 0) if (ret < 0)
{ {
serr("ERROR: mod_depend failed: %d\n", ret); serr("ERROR: modlib_depend failed: %d\n", ret);
return ret; return ret;
} }
@ -382,7 +382,7 @@ int mod_symvalue(FAR struct module_s *modp,
exportinfo.modp = modp; exportinfo.modp = modp;
exportinfo.symbol = NULL; exportinfo.symbol = NULL;
ret = mod_registry_foreach(mod_symcallback, (FAR void *)&exportinfo); ret = modlib_registry_foreach(mod_symcallback, (FAR void *)&exportinfo);
if (ret < 0) if (ret < 0)
{ {
serr("ERROR: mod_symcallback failed: \n", ret); serr("ERROR: mod_symcallback failed: \n", ret);

View File

@ -77,10 +77,10 @@ void mod_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
/* Borrow the registry lock to assure atomic access */ /* Borrow the registry lock to assure atomic access */
mod_registry_lock(); modlib_registry_lock();
*symtab = g_mod_symtab; *symtab = g_mod_symtab;
*nsymbols = g_mod_nsymbols; *nsymbols = g_mod_nsymbols;
mod_registry_unlock(); modlib_registry_unlock();
} }
/**************************************************************************** /****************************************************************************
@ -102,8 +102,8 @@ void mod_setsymtab(FAR const struct symtab_s *symtab, int nsymbols)
{ {
/* Borrow the registry lock to assure atomic access */ /* Borrow the registry lock to assure atomic access */
mod_registry_lock(); modlib_registry_lock();
g_mod_symtab = symtab; g_mod_symtab = symtab;
g_mod_nsymbols = nsymbols; g_mod_nsymbols = nsymbols;
mod_registry_unlock(); modlib_registry_unlock();
} }

View File

@ -40,9 +40,11 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <string.h> #include <string.h>
#include <elf32.h>
#include <debug.h> #include <debug.h>
#include <errno.h> #include <errno.h>
#include <nuttx/arch.h>
#include <nuttx/module.h> #include <nuttx/module.h>
/**************************************************************************** /****************************************************************************