diff --git a/include/dllfcn.h b/include/dllfcn.h index 76d3844d45..cbf1d445ed 100644 --- a/include/dllfcn.h +++ b/include/dllfcn.h @@ -104,6 +104,26 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Name: dlsymtab + * + * Description: + * dlsymtab() is a non-standard shared library interface. It selects the + * symbol table to use when binding a shared libary to the base firmware + * which may be in FLASH memory. + * + * Input Parameters: + * symtab - The new symbol table. + * nsymbols - The number of symbols in the symbol table. + * + * Returned Value: + * Always returns OK. + * + ****************************************************************************/ + +struct symtab_s; +int dlsymtab(FAR const struct symtab_s *symtab, int nsymbols); + /**************************************************************************** * Name: dlopen * diff --git a/include/nuttx/module.h b/include/nuttx/module.h index b55eef7bd9..83b04c5de7 100644 --- a/include/nuttx/module.h +++ b/include/nuttx/module.h @@ -107,10 +107,10 @@ typedef CODE int (*mod_uninitializer_t)(FAR void *arg); struct mod_info_s { - mod_uninitializer_t uninitializer; /* Module uninitializer */ - FAR void *arg; /* Uninitializer argument */ - FAR struct symtab_s *exports; /* Symbols exported by module */ - unsigned int nexports; /* Number of symobols in exports list */ + 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() @@ -128,7 +128,7 @@ struct mod_info_s typedef CODE int (*mod_initializer_t)(FAR struct mod_info_s *modinfo); -#ifdef __KERNEL__ +#if defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT) /* This is the type of the callback function used by mod_registry_foreach() */ struct module_s; @@ -163,7 +163,7 @@ extern "C" * ****************************************************************************/ -#ifdef __KERNEL__ +#if defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT) void mod_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols); #endif @@ -182,7 +182,7 @@ void mod_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols); * ****************************************************************************/ -#ifdef __KERNEL__ +#if defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT) void mod_setsymtab(FAR const struct symtab_s *symtab, int nsymbols); #endif @@ -301,7 +301,7 @@ FAR void *modhandle(FAR const char *name); * ****************************************************************************/ -#ifdef __KERNEL__ +#if defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT) int mod_registry_foreach(mod_callback_t callback, FAR void *arg); #endif diff --git a/libc/dllfcn/Make.defs b/libc/dllfcn/Make.defs index f821a254f7..aa92ba5229 100644 --- a/libc/dllfcn/Make.defs +++ b/libc/dllfcn/Make.defs @@ -37,7 +37,7 @@ ifeq ($(CONFIG_LIBC_DLLFCN),y) # Add the dllfcn.h files to the build -CSRCS += lib_dlopen.c lib_dlclose.c lib_dlsym.c lib_dlerror.c +CSRCS += lib_dlopen.c lib_dlclose.c lib_dlsym.c lib_dlerror.c lib_dlsymtab.c # Add the dllfcn.h directory to the build diff --git a/libc/dllfcn/lib_dlsymtab.c b/libc/dllfcn/lib_dlsymtab.c new file mode 100644 index 0000000000..1b192024fb --- /dev/null +++ b/libc/dllfcn/lib_dlsymtab.c @@ -0,0 +1,103 @@ +/**************************************************************************** + * libc/dllfcn/lib_symtab.c + * + * Copyright (C) 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: dlsymtab + * + * Description: + * dlsymtab() is a non-standard shared library interface. It selects the + * symbol table to use when binding a shared libary to the base firmware + * which may be in FLASH memory. + * + * Input Parameters: + * symtab - The new symbol table. + * nsymbols - The number of symbols in the symbol table. + * + * Returned Value: + * Always returns OK. + * + ****************************************************************************/ + +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. + */ + + mod_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 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 + * and (2) must like in a shared memory region accessible from all + * processes. The .data/.bss portion of the module must be allocated in + * the user space of each process, but must lie at the same virtual address + * so that it can be referenced from the one copy of the text in the shared + * memory region. + */ + +#warning Missing logic + return NULL; +#endif +} \ No newline at end of file