2014-09-16 00:15:19 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* binfmt/binfmt_execsymtab.c
|
|
|
|
*
|
2024-09-09 15:12:59 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-03 21:47:23 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2014-09-16 00:15:19 +08:00
|
|
|
*
|
2021-02-03 21:47:23 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-09-16 00:15:19 +08:00
|
|
|
*
|
2021-02-03 21:47:23 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-09-16 00:15:19 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2016-02-14 22:46:08 +08:00
|
|
|
#include <nuttx/irq.h>
|
2023-07-09 05:23:32 +08:00
|
|
|
#include <nuttx/symtab.h>
|
2014-09-16 00:15:19 +08:00
|
|
|
#include <nuttx/binfmt/symtab.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_LIBC_EXECFUNCS
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2020-01-12 00:10:49 +08:00
|
|
|
|
2014-09-16 00:15:19 +08:00
|
|
|
/* If CONFIG_LIBC_EXECFUNCS is defined in the configuration, then the
|
|
|
|
* following must also be defined:
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
|
|
|
|
/* Symbol table used by exec[l|v] */
|
|
|
|
|
2018-07-16 01:20:37 +08:00
|
|
|
# ifndef CONFIG_EXECFUNCS_SYMTAB_ARRAY
|
|
|
|
# error "CONFIG_EXECFUNCS_SYMTAB_ARRAY must be defined"
|
2014-09-16 00:15:19 +08:00
|
|
|
# endif
|
|
|
|
|
|
|
|
/* Number of Symbols in the Table */
|
|
|
|
|
2018-07-17 02:15:09 +08:00
|
|
|
# ifndef CONFIG_EXECFUNCS_NSYMBOLS_VAR
|
|
|
|
# error "CONFIG_EXECFUNCS_NSYMBOLS_VAR must be defined"
|
2014-09-16 00:15:19 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-03 06:30:35 +08:00
|
|
|
* Public Data
|
2014-09-16 00:15:19 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
|
2018-07-16 01:20:37 +08:00
|
|
|
extern const struct symtab_s CONFIG_EXECFUNCS_SYMTAB_ARRAY[];
|
2018-07-17 02:15:09 +08:00
|
|
|
extern int CONFIG_EXECFUNCS_NSYMBOLS_VAR;
|
2014-09-16 00:15:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR const struct symtab_s *g_exec_symtab;
|
|
|
|
static int g_exec_nsymbols;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: exec_getsymtab
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the current symbol table selection as an atomic operation.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* symtab - The location to store the symbol table.
|
2020-04-22 16:24:15 +08:00
|
|
|
* nsymbols - The location to store the number of symbols in the symbol
|
|
|
|
* table.
|
2014-09-16 00:15:19 +08:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
|
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
|
2018-07-18 00:34:56 +08:00
|
|
|
DEBUGASSERT(symtab != NULL && nsymbols != NULL);
|
2014-09-16 00:15:19 +08:00
|
|
|
|
|
|
|
/* Disable interrupts very briefly so that both the symbol table and its
|
|
|
|
* size are returned as a single atomic operation.
|
|
|
|
*/
|
|
|
|
|
2020-01-12 00:10:49 +08:00
|
|
|
flags = enter_critical_section();
|
2018-07-18 00:34:56 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
|
|
|
|
/* If a bring-up symbol table has been provided and if the exec symbol
|
|
|
|
* table has not yet been initialized, then use the provided start-up
|
|
|
|
* symbol table.
|
|
|
|
*/
|
|
|
|
|
2020-01-12 00:10:49 +08:00
|
|
|
if (g_exec_symtab == NULL)
|
|
|
|
{
|
|
|
|
g_exec_symtab = CONFIG_EXECFUNCS_SYMTAB_ARRAY;
|
|
|
|
g_exec_nsymbols = CONFIG_EXECFUNCS_NSYMBOLS_VAR;
|
|
|
|
}
|
2018-07-18 00:34:56 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Return the symbol table and its size */
|
|
|
|
|
2014-09-16 00:15:19 +08:00
|
|
|
*symtab = g_exec_symtab;
|
|
|
|
*nsymbols = g_exec_nsymbols;
|
2016-02-14 22:46:08 +08:00
|
|
|
leave_critical_section(flags);
|
2014-09-16 00:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: exec_setsymtab
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Select a new 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 exec_setsymtab(FAR const struct symtab_s *symtab, int nsymbols)
|
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
|
2018-07-18 00:34:56 +08:00
|
|
|
DEBUGASSERT(symtab != NULL);
|
2014-09-16 00:15:19 +08:00
|
|
|
|
|
|
|
/* Disable interrupts very briefly so that both the symbol table and its
|
|
|
|
* size are set as a single atomic operation.
|
|
|
|
*/
|
|
|
|
|
2016-02-14 22:46:08 +08:00
|
|
|
flags = enter_critical_section();
|
2014-09-16 00:15:19 +08:00
|
|
|
g_exec_symtab = symtab;
|
|
|
|
g_exec_nsymbols = nsymbols;
|
2016-02-14 22:46:08 +08:00
|
|
|
leave_critical_section(flags);
|
2014-09-16 00:15:19 +08:00
|
|
|
}
|
|
|
|
|
2020-02-07 21:17:25 +08:00
|
|
|
#endif /* CONFIG_LIBC_EXECFUNCS */
|