Shared libraries: Add a non-standard dllfnc.h function to set the symbol table.

This commit is contained in:
Gregory Nutt 2017-01-23 08:20:24 -06:00
parent f6504be6ef
commit a06d26e044
4 changed files with 132 additions and 9 deletions

View File

@ -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
*

View File

@ -109,7 +109,7 @@ struct mod_info_s
{
mod_uninitializer_t uninitializer; /* Module uninitializer */
FAR void *arg; /* Uninitializer argument */
FAR struct symtab_s *exports; /* Symbols exported by module */
FAR const struct symtab_s *exports; /* Symbols exported by module */
unsigned int nexports; /* Number of symobols in exports list */
};
@ -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

View File

@ -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

103
libc/dllfcn/lib_dlsymtab.c Normal file
View File

@ -0,0 +1,103 @@
/****************************************************************************
* libc/dllfcn/lib_symtab.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#include <dllfcn.h>
#include <nuttx/module.h>
/****************************************************************************
* 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
}