mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 08:38:38 +08:00
Modules: Add mod_setsymtab to set global symtol table once. Now we can remove symbol table parameters from the insmod call. This will make implementing an NSH insmod command much easier
This commit is contained in:
parent
076f382f79
commit
e8d0f85c8b
17 changed files with 437 additions and 239 deletions
|
@ -1,7 +1,7 @@
|
|||
############################################################################
|
||||
# nxflat/Makefile
|
||||
#
|
||||
# Copyright (C) 2007-2009, 2012-2014 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2007-2009, 2012-2015 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
|
@ -56,11 +56,6 @@ ifeq ($(CONFIG_SCHED_HAVE_PARENT),y)
|
|||
BINFMT_CSRCS += binfmt_schedunload.c
|
||||
endif
|
||||
|
||||
# Symbol table source files
|
||||
|
||||
BINFMT_CSRCS += symtab_findbyname.c symtab_findbyvalue.c
|
||||
BINFMT_CSRCS += symtab_findorderedbyname.c symtab_findorderedbyvalue.c
|
||||
|
||||
ifeq ($(CONFIG_LIBC_EXECFUNCS),y)
|
||||
BINFMT_CSRCS += binfmt_execsymtab.c
|
||||
endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* include/nuttx/binfmt/symtab.h
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -41,34 +41,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* struct symbtab_s describes one entry in the symbol table. A symbol table
|
||||
* is a fixed size array of struct symtab_s. The information is intentionally
|
||||
* minimal and supports only:
|
||||
*
|
||||
* 1. Function pointers as sym_values. Of other kinds of values need to be
|
||||
* supported, then typing information would also need to be included in
|
||||
* the structure.
|
||||
*
|
||||
* 2. Fixed size arrays. There is no explicit provisional for dyanamically
|
||||
* adding or removing entries from the symbol table (realloc might be
|
||||
* used for that purpose if needed). The intention is to support only
|
||||
* fixed size arrays completely defined at compilation or link time.
|
||||
*/
|
||||
|
||||
struct symtab_s
|
||||
{
|
||||
FAR const char *sym_name; /* A pointer to the symbol name string */
|
||||
FAR const void *sym_value; /* The value associated witht the string */
|
||||
};
|
||||
#include <nuttx/symtab.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
@ -87,7 +60,7 @@ extern "C"
|
|||
* Name: exec_getsymtab
|
||||
*
|
||||
* Description:
|
||||
* Get the current symbol table selection as an atomic operation.
|
||||
* Get the current application symbol table selection as an atomic operation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* symtab - The location to store the symbol table.
|
||||
|
@ -104,7 +77,7 @@ void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols);
|
|||
* Name: exec_setsymtab
|
||||
*
|
||||
* Description:
|
||||
* Select a new symbol table selection as an atomic operation.
|
||||
* Select a new application symbol table selection as an atomic operation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* symtab - The new symbol table.
|
||||
|
@ -117,82 +90,4 @@ void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols);
|
|||
|
||||
void exec_setsymtab(FAR const struct symtab_s *symtab, int nsymbols);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findbyname
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table with the matching name.
|
||||
* This version assumes that table is not ordered with respect to symbol
|
||||
* name and, hence, access time will be linear with respect to nsyms.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct symtab_s *
|
||||
symtab_findbyname(FAR const struct symtab_s *symtab,
|
||||
FAR const char *name, int nsyms);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findorderedbyname
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table with the matching name.
|
||||
* This version assumes that table ordered with respect to symbol name.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct symtab_s *
|
||||
symtab_findorderedbyname(FAR const struct symtab_s *symtab,
|
||||
FAR const char *name, int nsyms);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findbyvalue
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table whose value closest (but not greater
|
||||
* than), the provided value. This version assumes that table is not ordered
|
||||
* with respect to symbol name and, hence, access time will be linear with
|
||||
* respect to nsyms.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct symtab_s *
|
||||
symtab_findbyvalue(FAR const struct symtab_s *symtab,
|
||||
FAR void *value, int nsyms);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findorderedbyvalue
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table whose value closest (but not greater
|
||||
* than), the provided value. This version assumes that table is ordered
|
||||
* with respect to symbol name.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct symtab_s *
|
||||
symtab_findorderedbyvalue(FAR const struct symtab_s *symtab,
|
||||
FAR void *value, int nsyms);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_BINFMT_SYMTAB_H */
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include <elf32.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/symtab.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -132,6 +133,44 @@ extern "C"
|
|||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mod_getsymtab
|
||||
*
|
||||
* Description:
|
||||
* Get the current kernel symbol table selection as an atomic operation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* symtab - The location to store the symbol table.
|
||||
* nsymbols - The location to store the number of symbols in the symbol table.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __KERNEL__
|
||||
void mod_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mod_setsymtab
|
||||
*
|
||||
* Description:
|
||||
* Select a new kernel symbol table selection as an atomic operation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* symtab - The new symbol table.
|
||||
* nsymbols - The number of symbols in the symbol table.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __KERNEL__
|
||||
void mod_setsymtab(FAR const struct symtab_s *symtab, int nsymbols);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: insmod
|
||||
*
|
||||
|
@ -139,13 +178,16 @@ extern "C"
|
|||
* Verify that the file is an ELF module binary and, if so, load the
|
||||
* module into kernel memory and initialize it for use.
|
||||
*
|
||||
* NOTE: mod_setsymtab had to have been called in board-specific OS logic
|
||||
* prior to calling this function from application logic (perhaps via
|
||||
* boardctl(BOARDIOC_OS_SYMTAB). Otherwise, insmod will be unable to
|
||||
* resolve symbols in the OS module.
|
||||
*
|
||||
* Input Parameters:
|
||||
*
|
||||
* filename - Full path to the module binary to be loaded
|
||||
* modulename - The name that can be used to refer to the module after
|
||||
* it has been loaded.
|
||||
* exports - Table of exported symbols
|
||||
* nexports - The number of symbols in exports[]
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success. On any failure, -1 (ERROR) is returned the
|
||||
|
@ -153,8 +195,7 @@ extern "C"
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int insmod(FAR const char *filename, FAR const char *modulename,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
int insmod(FAR const char *filename, FAR const char *modulename);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: rmmod
|
||||
|
|
164
include/nuttx/symtab.h
Normal file
164
include/nuttx/symtab.h
Normal file
|
@ -0,0 +1,164 @@
|
|||
/****************************************************************************
|
||||
* include/nuttx/binfmt/symtab.h
|
||||
*
|
||||
* Copyright (C) 2009, 2015 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_SYMTAB_H
|
||||
#define __INCLUDE_NUTTX_SYMTAB_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* struct symbtab_s describes one entry in the symbol table. A symbol table
|
||||
* is a fixed size array of struct symtab_s. The information is intentionally
|
||||
* minimal and supports only:
|
||||
*
|
||||
* 1. Function pointers as sym_values. Of other kinds of values need to be
|
||||
* supported, then typing information would also need to be included in
|
||||
* the structure.
|
||||
*
|
||||
* 2. Fixed size arrays. There is no explicit provisional for dyanamically
|
||||
* adding or removing entries from the symbol table (realloc might be
|
||||
* used for that purpose if needed). The intention is to support only
|
||||
* fixed size arrays completely defined at compilation or link time.
|
||||
*/
|
||||
|
||||
struct symtab_s
|
||||
{
|
||||
FAR const char *sym_name; /* A pointer to the symbol name string */
|
||||
FAR const void *sym_value; /* The value associated witht the string */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findbyname
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table with the matching name.
|
||||
* This version assumes that table is not ordered with respect to symbol
|
||||
* name and, hence, access time will be linear with respect to nsyms.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct symtab_s *
|
||||
symtab_findbyname(FAR const struct symtab_s *symtab,
|
||||
FAR const char *name, int nsyms);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findorderedbyname
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table with the matching name.
|
||||
* This version assumes that table ordered with respect to symbol name.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct symtab_s *
|
||||
symtab_findorderedbyname(FAR const struct symtab_s *symtab,
|
||||
FAR const char *name, int nsyms);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findbyvalue
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table whose value closest (but not greater
|
||||
* than), the provided value. This version assumes that table is not ordered
|
||||
* with respect to symbol name and, hence, access time will be linear with
|
||||
* respect to nsyms.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct symtab_s *
|
||||
symtab_findbyvalue(FAR const struct symtab_s *symtab,
|
||||
FAR void *value, int nsyms);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findorderedbyvalue
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table whose value closest (but not greater
|
||||
* than), the provided value. This version assumes that table is ordered
|
||||
* with respect to symbol name.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct symtab_s *
|
||||
symtab_findorderedbyvalue(FAR const struct symtab_s *symtab,
|
||||
FAR void *value, int nsyms);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_SYMTAB_H */
|
||||
|
|
@ -77,10 +77,20 @@
|
|||
* which to receive the board unique ID.
|
||||
* DEPENDENCIES: Board logic must provide the board_uniqueid() interface.
|
||||
*
|
||||
* CMD: BOARDIOC_SYMTAB
|
||||
* DESCRIPTION: Select a symbol table
|
||||
* CMD: BOARDIOC_APP_SYMTAB
|
||||
* DESCRIPTION: Select the application symbol table. This symbol table
|
||||
* provides the symbol definitions exported to application
|
||||
* code from application space.
|
||||
* ARG: A pointer to an instance of struct boardioc_symtab_s
|
||||
* CONFIGURATION: CONFIG_BOARDCTL_SYMTAB
|
||||
* CONFIGURATION: CONFIG_BOARDCTL_APP_SYMTAB
|
||||
* DEPENDENCIES: None
|
||||
*
|
||||
* CMD: BOARDIOC_OS_SYMTAB
|
||||
* DESCRIPTION: Select the OS symbol table. This symbol table provides
|
||||
* the symbol definitions exported by the OS to kernel
|
||||
* modules.
|
||||
* ARG: A pointer to an instance of struct boardioc_symtab_s
|
||||
* CONFIGURATION: CONFIG_BOARDCTL_OS_SYMTAB
|
||||
* DEPENDENCIES: None
|
||||
*
|
||||
* CMD: BOARDIOC_TSCTEST_SETUP
|
||||
|
@ -125,13 +135,14 @@
|
|||
#define BOARDIOC_POWEROFF _BOARDIOC(0x0002)
|
||||
#define BOARDIOC_RESET _BOARDIOC(0x0003)
|
||||
#define BOARDIOC_UNIQUEID _BOARDIOC(0x0004)
|
||||
#define BOARDIOC_SYMTAB _BOARDIOC(0x0005)
|
||||
#define BOARDIOC_TSCTEST_SETUP _BOARDIOC(0x0006)
|
||||
#define BOARDIOC_TSCTEST_TEARDOWN _BOARDIOC(0x0007)
|
||||
#define BOARDIOC_ADCTEST_SETUP _BOARDIOC(0x0008)
|
||||
#define BOARDIOC_PWMTEST_SETUP _BOARDIOC(0x0009)
|
||||
#define BOARDIOC_CAN_INITIALIZE _BOARDIOC(0x000a)
|
||||
#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x000b)
|
||||
#define BOARDIOC_APP_SYMTAB _BOARDIOC(0x0005)
|
||||
#define BOARDIOC_OS_SYMTAB _BOARDIOC(0x0006)
|
||||
#define BOARDIOC_TSCTEST_SETUP _BOARDIOC(0x0007)
|
||||
#define BOARDIOC_TSCTEST_TEARDOWN _BOARDIOC(0x0008)
|
||||
#define BOARDIOC_ADCTEST_SETUP _BOARDIOC(0x0009)
|
||||
#define BOARDIOC_PWMTEST_SETUP _BOARDIOC(0x000a)
|
||||
#define BOARDIOC_CAN_INITIALIZE _BOARDIOC(0x000b)
|
||||
#define BOARDIOC_GRAPHICS_SETUP _BOARDIOC(0x000c)
|
||||
|
||||
/* If CONFIG_BOARDCTL_IOCTL=y, then boad-specific commands will be support.
|
||||
* In this case, all commands not recognized by boardctl() will be forwarded
|
||||
|
@ -140,7 +151,7 @@
|
|||
* User defined board commands may begin with this value:
|
||||
*/
|
||||
|
||||
#define BOARDIOC_USER _BOARDIOC(0x000c)
|
||||
#define BOARDIOC_USER _BOARDIOC(0x000d)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
|
|
|
@ -81,6 +81,7 @@ include dirent/Make.defs
|
|||
include termios/Make.defs
|
||||
include spawn/Make.defs
|
||||
include queue/Make.defs
|
||||
include symtab/Make.defs
|
||||
include wqueue/Make.defs
|
||||
include misc/Make.defs
|
||||
include audio/Make.defs
|
||||
|
|
44
libc/symtab/Make.defs
Normal file
44
libc/symtab/Make.defs
Normal file
|
@ -0,0 +1,44 @@
|
|||
############################################################################
|
||||
# libc/symtab/Make.defs
|
||||
#
|
||||
# Copyright (C) 2015 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Symbol table source files
|
||||
|
||||
CSRCS += symtab_findbyname.c symtab_findbyvalue.c
|
||||
CSRCS += symtab_findorderedbyname.c symtab_findorderedbyvalue.c
|
||||
|
||||
# Add the symtab directory to the build
|
||||
|
||||
DEPPATH += --dep-path symtab
|
||||
VPATH += :symtab
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* binfmt/symtab_findbyname.c
|
||||
* libc/symtab/symtab_findbyname.c
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -44,23 +44,7 @@
|
|||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
#include <nuttx/symtab.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
@ -94,4 +78,3 @@ symtab_findbyname(FAR const struct symtab_s *symtab,
|
|||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* binfmt/symtab_findbyvalue.c
|
||||
* libc/symtab/symtab_findbyvalue.c
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -44,23 +44,7 @@
|
|||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
#include <nuttx/symtab.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
@ -118,4 +102,3 @@ symtab_findbyvalue(FAR const struct symtab_s *symtab,
|
|||
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* binfmt/symtab_findorderedbyname.c
|
||||
* libc/symtab/symtab_findorderedbyname.c
|
||||
*
|
||||
* Copyright (C) 2009, 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2014-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -44,23 +44,7 @@
|
|||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
#include <nuttx/symtab.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* binfmt/symtab_findorderedbyvalue.c
|
||||
* libc/symtab/symtab_findorderedbyvalue.c
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -44,23 +44,7 @@
|
|||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
#include <nuttx/symtab.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
|
@ -124,4 +108,3 @@ symtab_findorderedbyvalue(FAR const struct symtab_s *symtab,
|
|||
|
||||
return value == symtab[low].sym_value ? &symtab[low] : NULL;
|
||||
}
|
||||
|
|
@ -42,8 +42,8 @@ CSRCS += mod_insmod.c mod_rmmod.c
|
|||
# loadable module library
|
||||
|
||||
CSRCS += mod_bind.c mod_init.c mod_iobuffer.c mod_load.c mod_read.c
|
||||
CSRCS += mod_registry.c mod_sections.c mod_symbols.c mod_uninit.c
|
||||
CSRCS += mod_unload.c mod_verify.c
|
||||
CSRCS += mod_registry.c mod_sections.c mod_symbols.c mod_symtab.c
|
||||
CSRCS += mod_uninit.c mod_unload.c mod_verify.c
|
||||
|
||||
# procfs support
|
||||
|
||||
|
|
|
@ -98,8 +98,7 @@ static inline int mod_readrel(FAR struct mod_loadinfo_s *loadinfo,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx)
|
||||
|
||||
{
|
||||
FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx];
|
||||
|
@ -149,7 +148,7 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx,
|
|||
|
||||
/* Get the value of the symbol (in sym.st_value) */
|
||||
|
||||
ret = mod_symvalue(loadinfo, &sym, exports, nexports);
|
||||
ret = mod_symvalue(loadinfo, &sym);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* The special error -ESRCH is returned only in one condition: The
|
||||
|
@ -200,8 +199,7 @@ static int mod_relocate(FAR struct mod_loadinfo_s *loadinfo, int relidx,
|
|||
return OK;
|
||||
}
|
||||
|
||||
static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx)
|
||||
{
|
||||
sdbg("Not implemented\n");
|
||||
return -ENOSYS;
|
||||
|
@ -216,7 +214,7 @@ static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx,
|
|||
*
|
||||
* Description:
|
||||
* Bind the imported symbol names in the loaded module described by
|
||||
* 'loadinfo' using the exported symbol values provided by 'symtab'.
|
||||
* 'loadinfo' using the exported symbol values provided by mod_setsymtab().
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
|
@ -224,8 +222,7 @@ static int mod_relocateadd(FAR struct mod_loadinfo_s *loadinfo, int relidx,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mod_bind(FAR struct mod_loadinfo_s *loadinfo,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
int mod_bind(FAR struct mod_loadinfo_s *loadinfo)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
|
@ -274,11 +271,11 @@ int mod_bind(FAR struct mod_loadinfo_s *loadinfo,
|
|||
|
||||
if (loadinfo->shdr[i].sh_type == SHT_REL)
|
||||
{
|
||||
ret = mod_relocate(loadinfo, i, exports, nexports);
|
||||
ret = mod_relocate(loadinfo, i);
|
||||
}
|
||||
else if (loadinfo->shdr[i].sh_type == SHT_RELA)
|
||||
{
|
||||
ret = mod_relocateadd(loadinfo, i, exports, nexports);
|
||||
ret = mod_relocateadd(loadinfo, i);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
|
|
|
@ -166,13 +166,16 @@ static void mod_dumpinitializer(mod_initializer_t initializer,
|
|||
* Verify that the file is an ELF module binary and, if so, load the
|
||||
* module into kernel memory and initialize it for use.
|
||||
*
|
||||
* NOTE: mod_setsymtab had to have been called in board-specific OS logic
|
||||
* prior to calling this function from application logic (perhaps via
|
||||
* boardctl(BOARDIOC_OS_SYMTAB). Otherwise, insmod will be unable to
|
||||
* resolve symbols in the OS module.
|
||||
*
|
||||
* Input Parameters:
|
||||
*
|
||||
* filename - Full path to the module binary to be loaded
|
||||
* modulename - The name that can be used to refer to the module after
|
||||
* it has been loaded.
|
||||
* exports - Table of exported symbols
|
||||
* nexports - The number of symbols in exports[]
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success. On any failure, -1 (ERROR) is returned the
|
||||
|
@ -180,8 +183,7 @@ static void mod_dumpinitializer(mod_initializer_t initializer,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int insmod(FAR const char *filename, FAR const char *modulename,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
int insmod(FAR const char *filename, FAR const char *modulename)
|
||||
{
|
||||
struct mod_loadinfo_s loadinfo;
|
||||
FAR struct module_s *modp;
|
||||
|
@ -237,9 +239,9 @@ int insmod(FAR const char *filename, FAR const char *modulename,
|
|||
goto errout_with_registry_entry;
|
||||
}
|
||||
|
||||
/* Bind the program to the exported symbol table */
|
||||
/* Bind the program to the kernel symbol table */
|
||||
|
||||
ret = mod_bind(&loadinfo, exports, nexports);
|
||||
ret = mod_bind(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
sdbg("Failed to bind symbols program binary: %d\n", ret);
|
||||
|
|
|
@ -261,8 +261,7 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym)
|
||||
{
|
||||
FAR const struct symtab_s *symbol;
|
||||
uintptr_t secbase;
|
||||
|
@ -306,9 +305,13 @@ int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
|
|||
/* Check if the base code exports a symbol of this name */
|
||||
|
||||
#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
|
||||
symbol = symtab_findorderedbyname(exports, (FAR char *)loadinfo->iobuffer, nexports);
|
||||
symbol = symtab_findorderedbyname(g_mod_symtab,
|
||||
(FAR char *)loadinfo->iobuffer,
|
||||
g_mod_nsymbols);
|
||||
#else
|
||||
symbol = symtab_findbyname(exports, (FAR char *)loadinfo->iobuffer, nexports);
|
||||
symbol = symtab_findbyname(g_mod_symtab,
|
||||
(FAR char *)loadinfo->iobuffer,
|
||||
g_mod_nsymbols);
|
||||
#endif
|
||||
if (!symbol)
|
||||
{
|
||||
|
|
110
sched/module/mod_symtab.c
Normal file
110
sched/module/mod_symtab.c
Normal file
|
@ -0,0 +1,110 @@
|
|||
/****************************************************************************
|
||||
* sched/module/mod_symtab.c
|
||||
*
|
||||
* Copyright (C) 2015 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 <assert.h>
|
||||
|
||||
#include <nuttx/symtab.h>
|
||||
#include <nuttx/module.h>
|
||||
|
||||
#include "module.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct symtab_s *g_mod_symtab;
|
||||
FAR int g_mod_nsymbols;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mod_getsymtab
|
||||
*
|
||||
* Description:
|
||||
* Get the current kernel symbol table selection as an atomic operation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* symtab - The location to store the symbol table.
|
||||
* nsymbols - The location to store the number of symbols in the symbol table.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mod_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
|
||||
{
|
||||
DEBUGASSERT(symtab != NULL && nsymbols != NULL);
|
||||
|
||||
/* Borrow the registry lock to assure atomic access */
|
||||
|
||||
mod_registry_lock();
|
||||
*symtab = g_mod_symtab;
|
||||
*nsymbols = g_mod_nsymbols;
|
||||
mod_registry_lock();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mod_setsymtab
|
||||
*
|
||||
* Description:
|
||||
* Select a new kernel symbol table selection as an atomic operation.
|
||||
*
|
||||
* Input Parameters:
|
||||
* symtab - The new symbol table.
|
||||
* nsymbols - The number of symbols in the symbol table.
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mod_setsymtab(FAR const struct symtab_s *symtab, int nsymbols)
|
||||
{
|
||||
/* Borrow the registry lock to assure atomic access */
|
||||
|
||||
mod_registry_lock();
|
||||
g_mod_symtab = symtab;
|
||||
g_mod_nsymbols = nsymbols;
|
||||
mod_registry_lock();
|
||||
}
|
|
@ -99,6 +99,13 @@ struct mod_loadinfo_s
|
|||
int filfd; /* Descriptor for the file being loaded */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct symtab_s *g_mod_symtab;
|
||||
FAR int g_mod_nsymbols;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
@ -154,7 +161,7 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo);
|
|||
*
|
||||
* Description:
|
||||
* Bind the imported symbol names in the loaded module described by
|
||||
* 'loadinfo' using the exported symbol values provided by 'symtab'.
|
||||
* 'loadinfo' using the exported symbol values provided by mod_setsymtab().
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
|
@ -162,9 +169,7 @@ int mod_load(FAR struct mod_loadinfo_s *loadinfo);
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct symtab_s;
|
||||
int mod_bind(FAR struct mod_loadinfo_s *loadinfo,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
int mod_bind(FAR struct mod_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mod_unload
|
||||
|
@ -290,8 +295,6 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index,
|
|||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* sym - Symbol table entry (value might be undefined)
|
||||
* exports - The symbol table to use for resolving undefined symbols.
|
||||
* nexports - Number of symbols in the symbol table.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
|
@ -305,8 +308,7 @@ int mod_readsym(FAR struct mod_loadinfo_s *loadinfo, int index,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
int mod_symvalue(FAR struct mod_loadinfo_s *loadinfo, FAR Elf32_Sym *sym);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mod_freebuffers
|
||||
|
|
Loading…
Reference in a new issue