mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 17:33:08 +08:00
Move module support from binfmt/ to sched/ so that it can be configured and built independently from binfmt features
This commit is contained in:
@@ -106,6 +106,10 @@
|
||||
#include <stdbool.h>
|
||||
#include <sched.h>
|
||||
|
||||
#if defined(CONFIG_ELF) || defined(CONFIG_MODULE)
|
||||
# include <elf32.h>
|
||||
#endif
|
||||
|
||||
#include <arch/arch.h>
|
||||
|
||||
/****************************************************************************
|
||||
@@ -1251,6 +1255,80 @@ int up_shmat(FAR uintptr_t *pages, unsigned int npages, uintptr_t vaddr);
|
||||
int up_shmdt(uintptr_t vaddr, unsigned int npages);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Interfaces required for ELF module support
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: up_checkarch
|
||||
*
|
||||
* Description:
|
||||
* Given the ELF header in 'hdr', verify that the module is appropriate
|
||||
* for the current, configured architecture. Every architecture that uses
|
||||
* the module loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hdr - The ELF header read from the module file.
|
||||
*
|
||||
* Returned Value:
|
||||
* True if the architecture supports this module file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_ELF) || defined(CONFIG_MODULE)
|
||||
bool up_checkarch(FAR const Elf32_Ehdr *hdr);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_relocate and up_relocateadd
|
||||
*
|
||||
* Description:
|
||||
* Perform on architecture-specific ELF relocation. Every architecture
|
||||
* that uses the module loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rel - The relocation type
|
||||
* sym - The ELF symbol structure containing the fully resolved value.
|
||||
* There are a few relocation types for a few architectures that do
|
||||
* not require symbol information. For those, this value will be
|
||||
* NULL. Implementations of these functions must be able to handle
|
||||
* that case.
|
||||
* addr - The address that requires the relocation.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the relocation was successful. Otherwise, a negated errno
|
||||
* value indicating the cause of the relocation failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_ELF) || defined(CONFIG_MODULE)
|
||||
int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
||||
uintptr_t addr);
|
||||
int up_relocateadd(FAR const Elf32_Rela *rel,
|
||||
FAR const Elf32_Sym *sym, uintptr_t addr);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_coherent_dcache
|
||||
*
|
||||
* Description:
|
||||
* Ensure that the I and D caches are coherent within specified region
|
||||
* by cleaning the D cache (i.e., flushing the D cache contents to memory
|
||||
* and invalidating the I cache. This is typically used when code has been
|
||||
* written to a memory region, and will be executed.
|
||||
*
|
||||
* Input Parameters:
|
||||
* addr - virtual start address of region
|
||||
* len - Size of the address region in bytes
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_HAVE_COHERENT_DCACHE
|
||||
void up_coherent_dcache(uintptr_t addr, size_t len);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_interrupt_context
|
||||
*
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <elf32.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
/****************************************************************************
|
||||
@@ -271,97 +272,6 @@ int elf_initialize(void);
|
||||
|
||||
void elf_uninitialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs must be provided by architecture-specific logic.
|
||||
* (These really belong in include/nuttx/arch.h):
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: up_checkarch
|
||||
*
|
||||
* Description:
|
||||
* Given the ELF header in 'hdr', verify that the ELF file is appropriate
|
||||
* for the current, configured architecture. Every architecture that uses
|
||||
* the ELF loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hdr - The ELF header read from the ELF file.
|
||||
*
|
||||
* Returned Value:
|
||||
* True if the architecture supports this ELF file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool up_checkarch(FAR const Elf32_Ehdr *hdr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_relocate and up_relocateadd
|
||||
*
|
||||
* Description:
|
||||
* Perform on architecture-specific ELF relocation. Every architecture
|
||||
* that uses the ELF loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rel - The relocation type
|
||||
* sym - The ELF symbol structure containing the fully resolved value.
|
||||
* There are a few relocation types for a few architectures that do
|
||||
* not require symbol information. For those, this value will be
|
||||
* NULL. Implementations of these functions must be able to handle
|
||||
* that case.
|
||||
* addr - The address that requires the relocation.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the relocation was successful. Otherwise, a negated errno
|
||||
* value indicating the cause of the relocation failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
||||
uintptr_t addr);
|
||||
int up_relocateadd(FAR const Elf32_Rela *rel,
|
||||
FAR const Elf32_Sym *sym, uintptr_t addr);
|
||||
|
||||
#ifdef CONFIG_UCLIBCXX_EXCEPTION
|
||||
/****************************************************************************
|
||||
* Name: up_init_exidx
|
||||
*
|
||||
* Description:
|
||||
* Load the boundaries of the Exception Index ELF section in order to
|
||||
* support exception handling for loaded ELF modules.
|
||||
*
|
||||
* Input Parameters:
|
||||
* address - The ELF section address for the Exception Index
|
||||
* size - The size of the ELF section.
|
||||
*
|
||||
* Returned Value:
|
||||
* Always returns Zero (OK).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_init_exidx(Elf32_Addr address, Elf32_Word size);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_coherent_dcache
|
||||
*
|
||||
* Description:
|
||||
* Ensure that the I and D caches are coherent within specified region
|
||||
* by cleaning the D cache (i.e., flushing the D cache contents to memory
|
||||
* and invalidating the I cache. This is typically used when code has been
|
||||
* written to a memory region, and will be executed.
|
||||
*
|
||||
* Input Parameters:
|
||||
* addr - virtual start address of region
|
||||
* len - Size of the address region in bytes
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_HAVE_COHERENT_DCACHE
|
||||
void up_coherent_dcache(uintptr_t addr, size_t len);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/binfmt/module.h
|
||||
* include/nuttx/module.h
|
||||
*
|
||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
@@ -33,8 +33,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_BINFMT_MODULE_H
|
||||
#define __INCLUDE_NUTTX_BINFMT_MODULE_H
|
||||
#ifndef __INCLUDE_NUTTX_MODULE_H
|
||||
#define __INCLUDE_NUTTX_MODULE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <elf32.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
/****************************************************************************
|
||||
@@ -71,17 +72,6 @@
|
||||
# define CONFIG_MODULE_BUFFERINCR 32
|
||||
#endif
|
||||
|
||||
/* Allocation array size and indices */
|
||||
|
||||
#define LIBMODULE_MODULE_ALLOC 0
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
# define LIBMODULE_CTORS_ALLOC 1
|
||||
# define LIBMODULE_CTPRS_ALLOC 2
|
||||
# define LIBMODULE_NALLOC 3
|
||||
#else
|
||||
# define LIBMODULE_NALLOC 1
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@@ -106,21 +96,14 @@
|
||||
|
||||
typedef CODE int (*mod_initializer_t)(void);
|
||||
|
||||
/* This describes the file to be loaded.
|
||||
*
|
||||
* NOTE 1: The 'filename' must be the full, absolute path to the file to be
|
||||
* executed unless CONFIG_BINFMT_EXEPATH is defined. In that case,
|
||||
* 'filename' may be a relative path; a set of candidate absolute paths
|
||||
* will be generated using the PATH environment variable and load_module()
|
||||
* will attempt to load each file that is found at those absolute paths.
|
||||
*/
|
||||
/* This describes the file to be loaded. */
|
||||
|
||||
struct symtab_s;
|
||||
struct module_s
|
||||
{
|
||||
/* Information provided to insmod by the caller */
|
||||
|
||||
FAR const char *filename; /* Full path to the binary to be loaded (See NOTE 1 above) */
|
||||
FAR const char *filename; /* Full path to the binary to be loaded */
|
||||
FAR const struct symtab_s *exports; /* Table of exported symbols */
|
||||
int nexports; /* The number of symbols in exports[] */
|
||||
|
||||
@@ -156,80 +139,9 @@ extern "C"
|
||||
|
||||
int insmod(FAR struct module_s *modp);
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs must be provided by architecture-specific logic.
|
||||
* (These really belong in include/nuttx/arch.h):
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: up_checkarch
|
||||
*
|
||||
* Description:
|
||||
* Given the ELF header in 'hdr', verify that the module is appropriate
|
||||
* for the current, configured architecture. Every architecture that uses
|
||||
* the module loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hdr - The ELF header read from the module file.
|
||||
*
|
||||
* Returned Value:
|
||||
* True if the architecture supports this module file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool up_checkarch(FAR const Elf32_Ehdr *hdr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_relocate and up_relocateadd
|
||||
*
|
||||
* Description:
|
||||
* Perform on architecture-specific ELF relocation. Every architecture
|
||||
* that uses the module loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rel - The relocation type
|
||||
* sym - The ELF symbol structure containing the fully resolved value.
|
||||
* There are a few relocation types for a few architectures that do
|
||||
* not require symbol information. For those, this value will be
|
||||
* NULL. Implementations of these functions must be able to handle
|
||||
* that case.
|
||||
* addr - The address that requires the relocation.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the relocation was successful. Otherwise, a negated errno
|
||||
* value indicating the cause of the relocation failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
||||
uintptr_t addr);
|
||||
int up_relocateadd(FAR const Elf32_Rela *rel,
|
||||
FAR const Elf32_Sym *sym, uintptr_t addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_coherent_dcache
|
||||
*
|
||||
* Description:
|
||||
* Ensure that the I and D caches are coherent within specified region
|
||||
* by cleaning the D cache (i.e., flushing the D cache contents to memory
|
||||
* and invalidating the I cache. This is typically used when code has been
|
||||
* written to a memory region, and will be executed.
|
||||
*
|
||||
* Input Parameters:
|
||||
* addr - virtual start address of region
|
||||
* len - Size of the address region in bytes
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_HAVE_COHERENT_DCACHE
|
||||
void up_coherent_dcache(uintptr_t addr, size_t len);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_BINFMT_MODULE_H */
|
||||
#endif /* __INCLUDE_NUTTX_MODULE_H */
|
||||
Reference in New Issue
Block a user