2014-09-15 18:15:19 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* binfmt/binfmt_execsymtab.c
|
|
|
|
*
|
2024-09-09 09:12:59 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-03 14:47:23 +01: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-15 18:15:19 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-09-15 18:15:19 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +01: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-15 18:15:19 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2016-02-14 15:46:08 +01:00
|
|
|
#include <nuttx/irq.h>
|
2023-07-08 23:23:32 +02:00
|
|
|
#include <nuttx/symtab.h>
|
2014-09-15 18:15:19 +02:00
|
|
|
#include <nuttx/binfmt/symtab.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_LIBC_EXECFUNCS
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2020-01-11 17:10:49 +01:00
|
|
|
|
2014-09-15 18:15:19 +02: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-15 19:20:37 +02:00
|
|
|
# ifndef CONFIG_EXECFUNCS_SYMTAB_ARRAY
|
|
|
|
# error "CONFIG_EXECFUNCS_SYMTAB_ARRAY must be defined"
|
2014-09-15 18:15:19 +02:00
|
|
|
# endif
|
|
|
|
|
|
|
|
/* Number of Symbols in the Table */
|
|
|
|
|
2018-07-16 20:15:09 +02:00
|
|
|
# ifndef CONFIG_EXECFUNCS_NSYMBOLS_VAR
|
|
|
|
# error "CONFIG_EXECFUNCS_NSYMBOLS_VAR must be defined"
|
2014-09-15 18:15:19 +02:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Data
|
2014-09-15 18:15:19 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
|
2018-07-15 19:20:37 +02:00
|
|
|
extern const struct symtab_s CONFIG_EXECFUNCS_SYMTAB_ARRAY[];
|
2018-07-16 20:15:09 +02:00
|
|
|
extern int CONFIG_EXECFUNCS_NSYMBOLS_VAR;
|
2014-09-15 18:15:19 +02: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 10:24:15 +02:00
|
|
|
* nsymbols - The location to store the number of symbols in the symbol
|
|
|
|
* table.
|
2014-09-15 18:15:19 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void exec_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
|
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
|
2018-07-17 18:34:56 +02:00
|
|
|
DEBUGASSERT(symtab != NULL && nsymbols != NULL);
|
2014-09-15 18:15:19 +02:00
|
|
|
|
|
|
|
/* Disable interrupts very briefly so that both the symbol table and its
|
|
|
|
* size are returned as a single atomic operation.
|
|
|
|
*/
|
|
|
|
|
2020-01-11 17:10:49 +01:00
|
|
|
flags = enter_critical_section();
|
2018-07-17 18:34:56 +02: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-11 17:10:49 +01:00
|
|
|
if (g_exec_symtab == NULL)
|
|
|
|
{
|
|
|
|
g_exec_symtab = CONFIG_EXECFUNCS_SYMTAB_ARRAY;
|
|
|
|
g_exec_nsymbols = CONFIG_EXECFUNCS_NSYMBOLS_VAR;
|
|
|
|
}
|
2018-07-17 18:34:56 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Return the symbol table and its size */
|
|
|
|
|
2014-09-15 18:15:19 +02:00
|
|
|
*symtab = g_exec_symtab;
|
|
|
|
*nsymbols = g_exec_nsymbols;
|
2016-02-14 15:46:08 +01:00
|
|
|
leave_critical_section(flags);
|
2014-09-15 18:15:19 +02: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-17 18:34:56 +02:00
|
|
|
DEBUGASSERT(symtab != NULL);
|
2014-09-15 18:15:19 +02:00
|
|
|
|
|
|
|
/* Disable interrupts very briefly so that both the symbol table and its
|
|
|
|
* size are set as a single atomic operation.
|
|
|
|
*/
|
|
|
|
|
2016-02-14 15:46:08 +01:00
|
|
|
flags = enter_critical_section();
|
2014-09-15 18:15:19 +02:00
|
|
|
g_exec_symtab = symtab;
|
|
|
|
g_exec_nsymbols = nsymbols;
|
2016-02-14 15:46:08 +01:00
|
|
|
leave_critical_section(flags);
|
2014-09-15 18:15:19 +02:00
|
|
|
}
|
|
|
|
|
2020-02-07 14:17:25 +01:00
|
|
|
#endif /* CONFIG_LIBC_EXECFUNCS */
|