aboutsummaryrefslogtreecommitdiff
path: root/nuttx/binfmt
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/binfmt')
-rw-r--r--nuttx/binfmt/Kconfig82
-rw-r--r--nuttx/binfmt/Makefile107
-rw-r--r--nuttx/binfmt/binfmt_dumpmodule.c108
-rw-r--r--nuttx/binfmt/binfmt_exec.c192
-rw-r--r--nuttx/binfmt/binfmt_execmodule.c264
-rw-r--r--nuttx/binfmt/binfmt_exepath.c286
-rw-r--r--nuttx/binfmt/binfmt_globals.c71
-rw-r--r--nuttx/binfmt/binfmt_internal.h88
-rw-r--r--nuttx/binfmt/binfmt_loadmodule.c266
-rw-r--r--nuttx/binfmt/binfmt_register.c104
-rw-r--r--nuttx/binfmt/binfmt_schedunload.c333
-rw-r--r--nuttx/binfmt/binfmt_unloadmodule.c199
-rw-r--r--nuttx/binfmt/binfmt_unregister.c138
-rw-r--r--nuttx/binfmt/builtin.c198
-rw-r--r--nuttx/binfmt/elf.c323
-rw-r--r--nuttx/binfmt/libbuiltin/Kconfig4
-rw-r--r--nuttx/binfmt/libbuiltin/Make.defs52
-rw-r--r--nuttx/binfmt/libbuiltin/libbuiltin_getname.c96
-rw-r--r--nuttx/binfmt/libbuiltin/libbuiltin_isavail.c103
-rw-r--r--nuttx/binfmt/libelf/Kconfig40
-rw-r--r--nuttx/binfmt/libelf/Make.defs58
-rw-r--r--nuttx/binfmt/libelf/gnu-elf.ld129
-rw-r--r--nuttx/binfmt/libelf/libelf.h341
-rw-r--r--nuttx/binfmt/libelf/libelf_addrenv.c176
-rw-r--r--nuttx/binfmt/libelf/libelf_bind.c334
-rw-r--r--nuttx/binfmt/libelf/libelf_ctors.c215
-rw-r--r--nuttx/binfmt/libelf/libelf_dtors.c215
-rw-r--r--nuttx/binfmt/libelf/libelf_init.c202
-rw-r--r--nuttx/binfmt/libelf/libelf_iobuffer.c136
-rw-r--r--nuttx/binfmt/libelf/libelf_load.c288
-rw-r--r--nuttx/binfmt/libelf/libelf_read.c165
-rw-r--r--nuttx/binfmt/libelf/libelf_sections.c284
-rw-r--r--nuttx/binfmt/libelf/libelf_symbols.c329
-rw-r--r--nuttx/binfmt/libelf/libelf_uninit.c126
-rw-r--r--nuttx/binfmt/libelf/libelf_unload.c114
-rw-r--r--nuttx/binfmt/libelf/libelf_verify.c120
-rw-r--r--nuttx/binfmt/libnxflat/Kconfig9
-rw-r--r--nuttx/binfmt/libnxflat/Make.defs54
-rw-r--r--nuttx/binfmt/libnxflat/gnu-nxflat-gotoff.ld187
-rw-r--r--nuttx/binfmt/libnxflat/gnu-nxflat-pcrel.ld187
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat.h136
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_addrenv.c235
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_bind.c615
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_init.c189
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_load.c222
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_read.c167
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_uninit.c85
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_unload.c97
-rw-r--r--nuttx/binfmt/libnxflat/libnxflat_verify.c101
-rw-r--r--nuttx/binfmt/nxflat.c280
-rw-r--r--nuttx/binfmt/symtab_findbyname.c97
-rw-r--r--nuttx/binfmt/symtab_findbyvalue.c121
-rw-r--r--nuttx/binfmt/symtab_findorderedbyname.c139
-rw-r--r--nuttx/binfmt/symtab_findorderedbyvalue.c127
54 files changed, 0 insertions, 9334 deletions
diff --git a/nuttx/binfmt/Kconfig b/nuttx/binfmt/Kconfig
deleted file mode 100644
index 6e5f7c251..000000000
--- a/nuttx/binfmt/Kconfig
+++ /dev/null
@@ -1,82 +0,0 @@
-#
-# For a description of the syntax of this configuration file,
-# see misc/tools/kconfig-language.txt.
-#
-
-config BINFMT_DISABLE
- bool "Disble BINFMT support"
- default n
- ---help---
- By default, support for loadable binary formats is built. This logic
- may be suppressed be defining this setting.
-
-if !BINFMT_DISABLE
-
-config BINFMT_EXEPATH
- bool "Support PATH variable"
- default n
- depends on !DISABLE_ENVIRON
- ---help---
- Use the contents of the PATH environment variable to locate executable
- files. Default: n
-
-config PATH_INITIAL
- string "Initial PATH Value"
- default ""
- depends on BINFMT_EXEPATH
- ---help---
- The initial value of the PATH variable. This is the colon-separated
- list of absolute paths. E.g., "/bin:/usr/bin:/sbin"
-
-config NXFLAT
- bool "Enable the NXFLAT Binary Format"
- default n
- select PIC
- ---help---
- Enable support for the NXFLAT binary format. Default: n
-
-if NXFLAT
-source binfmt/libnxflat/Kconfig
-endif
-
-config ELF
- bool "Enable the ELF Binary Format"
- default n
- ---help---
- Enable support for the ELF binary format. Default: n
-
-if ELF
-source binfmt/libelf/Kconfig
-endif
-
-config BUILTIN
- bool "Support Builtin Applications"
- default n
- ---help---
- Enable support for builtin applications. This features assigns a string
- name to an application and in addition if FS_BINFS is defined, retaining
- those names in a file system from which they can be executed. This feature
- is also the underlying requirement to support built-in applications in the
- NuttShell (NSH).
-
-if BUILTIN
-source binfmt/libbuiltin/Kconfig
-endif
-
-endif
-
-config PIC
- bool
- default n
-
-config BINFMT_CONSTRUCTORS
- bool "C++ Static Constructor Support"
- default n
- depends on HAVE_CXX && SCHED_STARTHOOK && ELF
- ---help---
- Build in support for C++ constructors in loaded modules. Currently
- only support for ELF binary formats.
-
-config SYMTAB_ORDEREDBYNAME
- bool "Symbol Tables Ordered by Name"
- default n
diff --git a/nuttx/binfmt/Makefile b/nuttx/binfmt/Makefile
deleted file mode 100644
index 2f692beb1..000000000
--- a/nuttx/binfmt/Makefile
+++ /dev/null
@@ -1,107 +0,0 @@
-############################################################################
-# nxflat/Makefile
-#
-# Copyright (C) 2007-2009, 2012-2013 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.
-#
-############################################################################
-
--include $(TOPDIR)/Make.defs
-DELIM ?= $(strip /)
-
-ifeq ($(WINTOOL),y)
-INCDIROPT = -w
-endif
-CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(TOPDIR)$(DELIM)sched"}
-
-# Basic BINFMT source files
-
-BINFMT_ASRCS =
-BINFMT_CSRCS = binfmt_globals.c binfmt_register.c binfmt_unregister.c
-BINFMT_CSRCS += binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c
-BINFMT_CSRCS += binfmt_exec.c binfmt_dumpmodule.c
-
-ifeq ($(CONFIG_BINFMT_EXEPATH),y)
-BINFMT_CSRCS += binfmt_exepath.c
-endif
-
-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
-
-# Add configured binary modules
-
-VPATH =
-SUBDIRS =
-DEPPATH = --dep-path .
-
-include libnxflat$(DELIM)Make.defs
-include libelf$(DELIM)Make.defs
-include libbuiltin$(DELIM)Make.defs
-
-BINFMT_AOBJS = $(BINFMT_ASRCS:.S=$(OBJEXT))
-BINFMT_COBJS = $(BINFMT_CSRCS:.c=$(OBJEXT))
-
-BINFMT_SRCS = $(BINFMT_ASRCS) $(BINFMT_CSRCS)
-BINFMT_OBJS = $(BINFMT_AOBJS) $(BINFMT_COBJS)
-
-BIN = libbinfmt$(LIBEXT)
-
-all: $(BIN)
-
-$(BINFMT_AOBJS): %$(OBJEXT): %.S
- $(call ASSEMBLE, $<, $@)
-
-$(BINFMT_COBJS): %$(OBJEXT): %.c
- $(call COMPILE, $<, $@)
-
-$(BIN): $(BINFMT_OBJS)
- $(call ARCHIVE, $@, $(BINFMT_OBJS))
-
-.depend: Makefile $(BINFMT_SRCS)
- $(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(BINFMT_SRCS) >Make.dep
- $(Q) touch $@
-
-depend: .depend
-
-clean:
- $(call DELFILE, $(BIN))
- $(call CLEAN)
-
-distclean: clean
- $(call DELFILE, Make.dep)
- $(call DELFILE, .depend)
-
--include Make.dep
diff --git a/nuttx/binfmt/binfmt_dumpmodule.c b/nuttx/binfmt/binfmt_dumpmodule.c
deleted file mode 100644
index d320bc830..000000000
--- a/nuttx/binfmt/binfmt_dumpmodule.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_dumpmodule.c
- *
- * Copyright (C) 2009, 2012 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 <sched.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/binfmt.h>
-
-#include "binfmt_internal.h"
-
-#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT) && !defined(CONFIG_BINFMT_DISABLE)
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Name: dump_module
- *
- * Description:
- * Load a module into memory and prep it for execution.
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ***********************************************************************/
-
-int dump_module(FAR const struct binary_s *bin)
-{
- if (bin)
- {
- bdbg("Module:\n");
- bdbg(" filename: %s\n", bin->filename);
- bdbg(" argv: %p\n", bin->argv);
- bdbg(" entrypt: %p\n", bin->entrypt);
- bdbg(" mapped: %p size=%d\n", bin->mapped, bin->mapsize);
- bdbg(" alloc: %p %p %p\n", bin->alloc[0], bin->alloc[1], bin->alloc[2]);
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
- bdbg(" ctors: %p nctors=%d\n", bin->ctors, bin->nctors);
- bdbg(" dtors: %p ndtors=%d\n", bin->dtors, bin->ndtors);
-#endif
-#ifdef CONFIG_ADDRENV
- bdbg(" addrenv: %p\n", bin->addrenv);
-#endif
- bdbg(" stacksize: %d\n", bin->stacksize);
- }
- return OK;
-}
-#endif
-
-
diff --git a/nuttx/binfmt/binfmt_exec.c b/nuttx/binfmt/binfmt_exec.c
deleted file mode 100644
index 4226b6cfc..000000000
--- a/nuttx/binfmt/binfmt_exec.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_exec.c
- *
- * Copyright (C) 2009, 2013 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 <string.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/binfmt.h>
-
-#include "binfmt_internal.h"
-
-#ifndef CONFIG_BINFMT_DISABLE
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: exec
- *
- * Description:
- * This is a convenience function that wraps load_ and exec_module into
- * one call. If CONFIG_SCHED_ONEXIT is also defined, this function will
- * automatically call schedule_unload() to unload the module when task
- * exits.
- *
- * Input Parameter:
- * filename - Fulll path to the binary to be loaded
- * argv - Argument list
- * exports - Table of exported symbols
- * nexports - The number of symbols in exports
- *
- * Returned Value:
- * This is an end-user function, so it follows the normal convention:
- * It returns the PID of the exec'ed module. On failure, it returns
- * -1 (ERROR) and sets errno appropriately.
- *
- ****************************************************************************/
-
-int exec(FAR const char *filename, FAR const char **argv,
- FAR const struct symtab_s *exports, int nexports)
-{
-#ifdef CONFIG_SCHED_ONEXIT
- FAR struct binary_s *bin;
- int pid;
- int ret;
-
- /* Allocate the load information */
-
- bin = (FAR struct binary_s *)kzalloc(sizeof(struct binary_s));
- if (!bin)
- {
- set_errno(ENOMEM);
- return ERROR;
- }
-
- /* Load the module into memory */
-
- bin->filename = filename;
- bin->exports = exports;
- bin->nexports = nexports;
-
- ret = load_module(bin);
- if (ret < 0)
- {
- bdbg("ERROR: Failed to load program '%s'\n", filename);
- kfree(bin);
- return ERROR;
- }
-
- /* Disable pre-emption so that the executed module does
- * not return until we get a chance to connect the on_exit
- * handler.
- */
-
- sched_lock();
-
- /* Then start the module */
-
- pid = exec_module(bin);
- if (pid < 0)
- {
- bdbg("ERROR: Failed to execute program '%s'\n", filename);
- sched_unlock();
- unload_module(bin);
- kfree(bin);
- return ERROR;
- }
-
- /* Set up to unload the module (and free the binary_s structure)
- * when the task exists.
- */
-
- ret = schedule_unload(pid, bin);
- if (ret < 0)
- {
- bdbg("ERROR: Failed to schedul unload '%s'\n", filename);
- }
-
- sched_unlock();
- return pid;
-#else
- struct binary_s bin;
- int ret;
-
- /* Load the module into memory */
-
- memset(&bin, 0, sizeof(struct binary_s));
- bin.filename = filename;
- bin.exports = exports;
- bin.nexports = nexports;
-
- ret = load_module(&bin);
- if (ret < 0)
- {
- bdbg("ERROR: Failed to load program '%s'\n", filename);
- return ERROR;
- }
-
- /* Then start the module */
-
- ret = exec_module(&bin);
- if (ret < 0)
- {
- bdbg("ERROR: Failed to execute program '%s'\n", filename);
- unload_module(&bin);
- return ERROR;
- }
-
- /* TODO: How does the module get unloaded in this case? */
-
- return ret;
-#endif
-}
-
-#endif /* CONFIG_BINFMT_DISABLE */
-
diff --git a/nuttx/binfmt/binfmt_execmodule.c b/nuttx/binfmt/binfmt_execmodule.c
deleted file mode 100644
index 10068b482..000000000
--- a/nuttx/binfmt/binfmt_execmodule.c
+++ /dev/null
@@ -1,264 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_execmodule.c
- *
- * Copyright (C) 2009, 2013 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 <sys/types.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <sched.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/arch.h>
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/binfmt.h>
-
-#include "os_internal.h"
-#include "binfmt_internal.h"
-
-#ifndef CONFIG_BINFMT_DISABLE
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-/* If C++ constructors are used, then CONFIG_SCHED_STARTHOOK must also be
- * selected be the start hook is used to schedule execution of the
- * constructors.
- */
-
-#if defined(CONFIG_BINFMT_CONSTRUCTORS) && !defined(CONFIG_SCHED_STARTHOOK)
-# errror "CONFIG_SCHED_STARTHOOK must be defined to use constructors"
-#endif
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: exec_ctors
- *
- * Description:
- * Execute C++ static constructors. This function is registered as a
- * start hook and runs on the thread of the newly created task before
- * the new task's main function is called.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
-static void exec_ctors(FAR void *arg)
-{
- FAR const struct binary_s *binp = (FAR const struct binary_s *)arg;
- binfmt_ctor_t *ctor = binp->ctors;
- int i;
-
- /* Execute each constructor */
-
- for (i = 0; i < binp->nctors; i++)
- {
- bvdbg("Calling ctor %d at %p\n", i, (FAR void *)ctor);
-
- (*ctor)();
- ctor++;
- }
-}
-#endif
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: exec_module
- *
- * Description:
- * Execute a module that has been loaded into memory by load_module().
- *
- * Returned Value:
- * This is an end-user function, so it follows the normal convention:
- * Returns the PID of the exec'ed module. On failure, it returns
- * -1 (ERROR) and sets errno appropriately.
- *
- ****************************************************************************/
-
-int exec_module(FAR const struct binary_s *binp)
-{
- FAR _TCB *tcb;
-#ifndef CONFIG_CUSTOM_STACK
- FAR uint32_t *stack;
-#endif
- pid_t pid;
- int err;
- int ret;
-
- /* Sanity checking */
-
-#ifdef CONFIG_DEBUG
- if (!binp || !binp->entrypt || binp->stacksize <= 0)
- {
- err = EINVAL;
- goto errout;
- }
-#endif
-
- bdbg("Executing %s\n", binp->filename);
-
- /* Allocate a TCB for the new task. */
-
- tcb = (FAR _TCB*)kzalloc(sizeof(_TCB));
- if (!tcb)
- {
- err = ENOMEM;
- goto errout;
- }
-
- /* Allocate the stack for the new task */
-
-#ifndef CONFIG_CUSTOM_STACK
- stack = (FAR uint32_t*)kmalloc(binp->stacksize);
- if (!tcb)
- {
- err = ENOMEM;
- goto errout_with_tcb;
- }
-
- /* Initialize the task */
-
- ret = task_init(tcb, binp->filename, binp->priority, stack,
- binp->stacksize, binp->entrypt, binp->argv);
-#else
- /* Initialize the task */
-
- ret = task_init(tcb, binp->filename, binp->priority, stack,
- binp->entrypt, binp->argv);
-#endif
- if (ret < 0)
- {
- err = errno;
- bdbg("task_init() failed: %d\n", err);
- goto errout_with_stack;
- }
-
- /* Note that tcb->flags are not modified. 0=normal task */
- /* tcb->flags |= TCB_FLAG_TTYPE_TASK; */
-
- /* Add the D-Space address as the PIC base address. By convention, this
- * must be the first allocated address space.
- */
-
-#ifdef CONFIG_PIC
- tcb->dspace = binp->alloc[0];
-
- /* Re-initialize the task's initial state to account for the new PIC base */
-
- up_initial_state(tcb);
-#endif
-
- /* Assign the address environment to the task */
-
-#ifdef CONFIG_ADDRENV
- ret = up_addrenv_assign(binp->addrenv, tcb);
- if (ret < 0)
- {
- err = -ret;
- bdbg("up_addrenv_assign() failed: %d\n", ret);
- goto errout_with_stack;
- }
-#endif
-
- /* Setup a start hook that will execute all of the C++ static constructors
- * on the newly created thread. The struct binary_s must persist at least
- * until the new task has been started.
- */
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
- task_starthook(tcb, exec_ctors, (FAR void *)binp);
-#endif
-
- /* Get the assigned pid before we start the task */
-
- pid = tcb->pid;
-
- /* Then activate the task at the provided priority */
-
- ret = task_activate(tcb);
- if (ret < 0)
- {
- err = errno;
- bdbg("task_activate() failed: %d\n", err);
- goto errout_with_stack;
- }
-
- return (int)pid;
-
-errout_with_stack:
-#ifndef CONFIG_CUSTOM_STACK
- tcb->stack_alloc_ptr = NULL;
- sched_releasetcb(tcb);
- kfree(stack);
-#else
- sched_releasetcb(tcb);
-#endif
- goto errout;
-
-errout_with_tcb:
- kfree(tcb);
-errout:
- errno = err;
- bdbg("returning errno: %d\n", err);
- return ERROR;
-}
-
-#endif /* CONFIG_BINFMT_DISABLE */
-
diff --git a/nuttx/binfmt/binfmt_exepath.c b/nuttx/binfmt/binfmt_exepath.c
deleted file mode 100644
index 4fd7ad918..000000000
--- a/nuttx/binfmt/binfmt_exepath.c
+++ /dev/null
@@ -1,286 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_exepath.c
- *
- * Copyright (C) 2012 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 <sys/types.h>
-#include <sys/stat.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/binfmt.h>
-
-#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-struct exepath_s
-{
- FAR char *next; /* Pointer to the next (unterminated) value in the PATH variable */
- char path[1];
-};
-#define SIZEOF_EXEPATH_S(n) (sizeof(struct exepath_s) + (n) - 1)
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: exepath_init
- *
- * Description:
- * Initialize for the traversal of each value in the PATH variable. The
- * usage is sequence is as follows:
- *
- * 1) Call exepath_init() to initialize for the traversal. exepath_init()
- * will return an opaque handle that can then be provided to
- * exepath_next() and exepath_release().
- * 2) Call exepath_next() repeatedly to examine every file that lies
- * in the directories of the PATH variable
- * 3) Call exepath_release() to free resources set aside by exepath_init().
- *
- * Input Parameters:
- * None
- *
- * Returned Value:
- * On success, exepath_init() return a non-NULL, opaque handle that may
- * subsequently be used in calls to exepath_next() and exepath_release().
- * On error, a NULL handle value will be returned. The most likely cause
- * of an error would be that the there is no value associated with the
- * PATH variable.
- *
- ****************************************************************************/
-
-EXEPATH_HANDLE exepath_init(void)
-{
- FAR struct exepath_s *exepath;
- FAR char *path;
-
- /* Get the value of the PATH variable */
-
- path = getenv("PATH");
- if (!path)
- {
- /* getenv() will return a NULL value if the PATH variable does not
- * exist in the environment.
- */
-
- return (EXEPATH_HANDLE)NULL;
- }
-
- /* Allocate a container for the PATH variable contents */
-
- exepath = (FAR struct exepath_s *)kmalloc(SIZEOF_EXEPATH_S(strlen(path) + 1));
- if (!exepath)
- {
- /* Ooops.. we are out of memory */
-
- return (EXEPATH_HANDLE)NULL;
- }
-
- /* Populate the container */
-
- strcpy(exepath->path, path);
- exepath->next = exepath->path;
-
- /* And return the containing cast to an opaque handle */
-
- return (EXEPATH_HANDLE)exepath;
-}
-
- /****************************************************************************
- * Name: exepath_next
- *
- * Description:
- * Traverse all possible values in the PATH variable in attempt to find
- * the full path to an executable file when only a relative path is
- * provided.
- *
- * Input Parameters:
- * handle - The handle value returned by exepath_init
- * relpath - The relative path to the file to be found.
- *
- * Returned Value:
- * On success, a non-NULL pointer to a null-terminated string is provided.
- * This is the full path to a file that exists in the file system. This
- * function will verify that the file exists (but will not verify that it
- * is marked executable).
- *
- * NOTE: The string pointer return in the success case points to allocated
- * memory. This memory must be freed by the called by calling kfree().
- *
- * NULL is returned if no path is found to any file with the provided
- * 'relpath' from any absolute path in the PATH variable. In this case,
- * there is no point in calling exepath_next() further; exepath_release()
- * must be called to release resources set aside by expath_init().
- *
- ****************************************************************************/
-
-FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath)
-{
- FAR struct exepath_s *exepath = (FAR struct exepath_s *)handle;
- struct stat buf;
- FAR char *endptr;
- FAR char *path;
- FAR char *fullpath;
- int pathlen;
- int ret;
-
- /* Verify that a value handle and relative path were provided */
-
- DEBUGASSERT(exepath && relpath);
- DEBUGASSERT(relpath[0] != '\0' && relpath[0] != '/');
-
- /* Loop until (1) we find a file with this relative path from one of the
- * absolute paths in the PATH variable, or (2) all of the absolute paths
- * in the PATH variable have been considered.
- */
-
- for (;;)
- {
- /* Make sure that exepath->next points to the beginning of a string */
-
- path = exepath->next;
- if (*path == '\0')
- {
- /* If it points to a NULL it means that either (1) the PATH varialbe
- * is empty, or (2) we have already examined all of the paths in the
- * path variable.
- */
-
- return (FAR char *)NULL;
- }
-
- /* Okay... 'path' points to the beginning of the string. The string may
- * be termined either with (1) ':' which separates the path from the
- * next path in the list, or (2) NUL which marks the end of the list.
- */
-
- endptr = strchr(path, ':');
- if (!endptr)
- {
- /* If strchr returns NUL it means that ':' does not appear in the
- * string. Therefore, this must be the final path in the PATH
- * variable content.
- */
-
- endptr = &path[strlen(path)];
- exepath->next = endptr;
- DEBUGASSERT(*endptr == '\0');
- }
- else
- {
- DEBUGASSERT(*endptr == ':');
- exepath->next = endptr + 1;
- *endptr = '\0';
- }
-
- pathlen = strlen(path) + strlen(relpath) + 2;
- fullpath = (FAR char *)kmalloc(pathlen);
- if (!fullpath)
- {
- /* Failed to allocate memory */
-
- return (FAR char *)NULL;
- }
-
- /* Construct the full path */
-
- sprintf(fullpath, "%s/%s", path, relpath);
-
- /* Verify that a regular file exists at this path */
-
- ret = stat(fullpath, &buf);;
- if (ret == OK && S_ISREG(buf.st_mode))
- {
- return fullpath;
- }
-
- /* Failed to stat the file. Just free the allocated memory and
- * continue to try the next path.
- */
-
- kfree(fullpath);
- }
-
- /* We will not get here */
-}
-
-/****************************************************************************
- * Name: exepath_release
- *
- * Description:
- * Release all resources set aside by exepath_init() when the handle value
- * was created. The handle value is invalid on return from this function.
- * Attempts to all exepath_next() or exepath_release() with such a 'stale'
- * handle will result in undefined (i.e., not good) behavior.
- *
- * Input Parameters:
- * handle - The handle value returned by exepath_init
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-void exepath_release(EXEPATH_HANDLE handle)
-{
- kfree(handle);
-}
-
-#endif /* !CONFIG_BINFMT_DISABLE && CONFIG_BINFMT_EXEPATH */
-
diff --git a/nuttx/binfmt/binfmt_globals.c b/nuttx/binfmt/binfmt_globals.c
deleted file mode 100644
index d3246bd50..000000000
--- a/nuttx/binfmt/binfmt_globals.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_globals.c
- *
- * Copyright (C) 2009 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 <nuttx/binfmt/binfmt.h>
-
-#ifndef CONFIG_BINFMT_DISABLE
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/* This is a list of registered handlers for different binary formats. This
- * list should only be accessed by normal user programs. It should be sufficient
- * protection to simply disable pre-emption when accessing this list.
- */
-
-FAR struct binfmt_s *g_binfmts;
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-#endif /* CONFIG_BINFMT_DISABLE */
-
-
diff --git a/nuttx/binfmt/binfmt_internal.h b/nuttx/binfmt/binfmt_internal.h
deleted file mode 100644
index fa750543a..000000000
--- a/nuttx/binfmt/binfmt_internal.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_internal.h
- *
- * Copyright (C) 2009 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 __BINFMT_BINFMT_INTERNAL_H
-#define __BINFMT_BINFMT_INTERNAL_H
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <nuttx/binfmt/binfmt.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-#undef EXTERN
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C" {
-#else
-#define EXTERN extern
-#endif
-
-/* This is a list of registered handlers for different binary formats. This
- * list should only be accessed by normal user programs. It should be sufficient
- * protection to simply disable pre-emption when accessing this list.
- */
-
-EXTERN FAR struct binfmt_s *g_binfmts;
-
-/***********************************************************************
- * Public Function Prototypes
- ***********************************************************************/
-
-/* Dump the contents of struct binary_s */
-
-#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
-EXTERN int dump_module(FAR const struct binary_s *bin);
-#else
-# define dump_module(bin)
-#endif
-
-#undef EXTERN
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __BINFMT_BINFMT_INTERNAL_H */
-
diff --git a/nuttx/binfmt/binfmt_loadmodule.c b/nuttx/binfmt/binfmt_loadmodule.c
deleted file mode 100644
index 322ed2c48..000000000
--- a/nuttx/binfmt/binfmt_loadmodule.c
+++ /dev/null
@@ -1,266 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_loadmodule.c
- *
- * Copyright (C) 2009 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 <sched.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/binfmt.h>
-
-#include "binfmt_internal.h"
-
-#ifndef CONFIG_BINFMT_DISABLE
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: load_default_priority
- *
- * Description:
- * Set the default priority of the module to be loaded. This may be
- * changed (1) by the actions of the binary format's load() method if
- * the binary format contains priority informaition, or (2) by the user
- * between calls to load_module() and exec_module().
- *
- * Returned Value:
- * Zero (OK) is returned on success; Otherwise, -1 (ERROR) is returned and
- * the errno variable is set appropriately.
- *
- ****************************************************************************/
-
-static int load_default_priority(FAR struct binary_s *bin)
-{
- struct sched_param param;
- int ret;
-
- /* Get the priority of this thread */
-
- ret = sched_getparam(0, &param);
- if (ret < 0)
- {
- bdbg("ERROR: sched_getparam failed: %d\n", errno);
- return ERROR;
- }
-
- /* Save that as the priority of child thread */
-
- bin->priority = param.sched_priority;
- return ret;
-}
-
-/****************************************************************************
- * Name: load_absmodule
- *
- * Description:
- * Load a module into memory, bind it to an exported symbol take, and
- * prep the module for execution. bin->filename is known to be an absolute
- * path to the file to be loaded.
- *
- * Returned Value:
- * Zero (OK) is returned on success; a negated errno value is returned on
- * failure.
- *
- ****************************************************************************/
-
-static int load_absmodule(FAR struct binary_s *bin)
-{
- FAR struct binfmt_s *binfmt;
- int ret = -ENOENT;
-
- bdbg("Loading %s\n", bin->filename);
-
- /* Disabling pre-emption should be sufficient protection while accessing
- * the list of registered binary format handlers.
- */
-
- sched_lock();
-
- /* Traverse the list of registered binary format handlers. Stop
- * when either (1) a handler recognized and loads the format, or
- * (2) no handler recognizes the format.
- */
-
- for (binfmt = g_binfmts; binfmt; binfmt = binfmt->next)
- {
- /* Use this handler to try to load the format */
-
- ret = binfmt->load(bin);
- if (ret == OK)
- {
- /* Successfully loaded -- break out with ret == 0 */
-
- bvdbg("Successfully loaded module %s\n", bin->filename);
- dump_module(bin);
- break;
- }
- }
-
- sched_unlock();
- return ret;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: load_module
- *
- * Description:
- * Load a module into memory, bind it to an exported symbol take, and
- * prep the module for execution.
- *
- * Returned Value:
- * This is an end-user function, so it follows the normal convention:
- * Returns 0 (OK) on success. On failure, it returns -1 (ERROR) with
- * errno set appropriately.
- *
- ****************************************************************************/
-
-int load_module(FAR struct binary_s *bin)
-{
- int ret = -EINVAL;
-
- /* Verify that we were provided something to work with */
-
-#ifdef CONFIG_DEBUG
- if (bin && bin->filename)
-#endif
- {
- /* Set the default priority of the new program. */
-
- ret = load_default_priority(bin);
- if (ret < 0)
- {
- /* The errno is already set in this case */
-
- return ERROR;
- }
-
- /* Were we given a relative path? Or an absolute path to the file to
- * be loaded? Absolute paths start with '/'.
- */
-
-#ifdef CONFIG_BINFMT_EXEPATH
- if (bin->filename[0] != '/')
- {
- FAR const char *relpath;
- FAR char *fullpath;
- EXEPATH_HANDLE handle;
-
- /* Set aside the relative path */
-
- relpath = bin->filename;
- ret = -ENOENT;
-
- /* Initialize to traverse the PATH variable */
-
- handle = exepath_init();
- if (handle)
- {
- /* Get the next absolute file path */
-
- while ((fullpath = exepath_next(handle, relpath)) != NULL)
- {
- /* Try to load the file at this path */
-
- bin->filename = fullpath;
- ret = load_absmodule(bin);
-
- /* Free the allocated fullpath */
-
- kfree(fullpath);
-
- /* Break out of the loop with ret == OK on success */
-
- if (ret == OK)
- {
- break;
- }
- }
- }
-
- /* Restore the relative path. This is not needed for anything
- * but debug output after the file has been loaded.
- */
-
- bin->filename = relpath;
- }
- else
-#endif
- {
- /* We already have the one and only absolute path to the file to
- * be loaded.
- */
-
- ret = load_absmodule(bin);
- }
- }
-
- /* This is an end-user function. Return failures via errno */
-
- if (ret < 0)
- {
- bdbg("Returning errno %d\n", -ret);
- errno = -ret;
- return ERROR;
- }
-
- return OK;
-}
-
-#endif /* CONFIG_BINFMT_DISABLE */
-
diff --git a/nuttx/binfmt/binfmt_register.c b/nuttx/binfmt/binfmt_register.c
deleted file mode 100644
index 925f29353..000000000
--- a/nuttx/binfmt/binfmt_register.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_register.c
- *
- * Copyright (C) 2009 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 <string.h>
-#include <sched.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/binfmt.h>
-
-#include "binfmt_internal.h"
-
-#ifndef CONFIG_BINFMT_DISABLE
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: register_binfmt
- *
- * Description:
- * Register a loader for a binary format
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int register_binfmt(FAR struct binfmt_s *binfmt)
-{
- if (binfmt)
- {
- /* Add the new binary format handler to the head of the list of
- * handlers
- */
-
- sched_lock();
- binfmt->next = g_binfmts;
- g_binfmts = binfmt;
- sched_unlock();
- return OK;
- }
- return -EINVAL;
-}
-
-#endif /* CONFIG_BINFMT_DISABLE */
-
diff --git a/nuttx/binfmt/binfmt_schedunload.c b/nuttx/binfmt/binfmt_schedunload.c
deleted file mode 100644
index 972d17963..000000000
--- a/nuttx/binfmt/binfmt_schedunload.c
+++ /dev/null
@@ -1,333 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_schedunload.c
- *
- * Copyright (C) 2013 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 <sched.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/binfmt.h>
-
-#include "binfmt_internal.h"
-
-#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_SCHED_HAVE_PARENT)
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-FAR struct binary_s *g_unloadhead;
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: unload_list_add
- *
- * Description:
- * If CONFIG_SCHED_HAVE_PARENT is defined then schedul_unload() will
- * manage instances of struct binary_s allocated with kmalloc. It
- * will keep the binary data in a link list and when SIGCHLD is received
- * (meaning that the task has exit'ed, schedul_unload() will find the
- * data, unload the module, and free the structure.
- *
- * This function will add one structure to the linked list
- *
- * Input Parameter:
- * pid - The task ID of the child task
- * bin - This structure must have been allocated with kmalloc() and must
- * persist until the task unloads
-
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-static void unload_list_add(pid_t pid, FAR struct binary_s *bin)
-{
- irqstate_t flags;
-
- /* Save the PID in the structure so that we recover it later */
-
- bin->pid = pid;
-
- /* Disable deliver of any signals while we muck with the list. The graceful
- * way to do this would be block delivery of SIGCHLD would be with
- * sigprocmask. Here we do it the quick'n'dirty way by just disabling
- * interrupts.
- */
-
- flags = irqsave();
- bin->flink = g_unloadhead;
- g_unloadhead = bin;
- irqrestore(flags);
-}
-
-/****************************************************************************
- * Name: unload_list_remove
- *
- * Description:
- * If CONFIG_SCHED_HAVE_PARENT is defined then schedul_unload() will
- * manage instances of struct binary_s allocated with kmalloc. It
- * will keep the binary data in a link list and when SIGCHLD is received
- * (meaning that the task has exit'ed, schedul_unload() will find the
- * data, unload the module, and free the structure.
- *
- * This function will remove one structure to the linked list
- *
- * Input Parameter:
- * pid - The task ID of the child task
- *
- * Returned Value:
- * On success, the load structure is returned. NULL is returned on
- * failure.
- *
- ****************************************************************************/
-
-static FAR struct binary_s *unload_list_remove(pid_t pid)
-{
- FAR struct binary_s *curr;
- FAR struct binary_s *prev;
-
- /* Note the asymmetry. We do not have to disable interrupts here because
- * the main thread cannot run while we are in the interrupt handler. Here,
- * it should be sufficient to disable pre-emption so that no other thread
- * can run.
- */
-
- sched_lock();
-
- /* Find the structure in the unload list with the matching PID */
-
- for (prev = NULL, curr = g_unloadhead;
- curr && (curr->pid != pid);
- prev = curr, curr = curr->flink);
-
- /* Did we find it? It must be there. Hmmm.. we should probably ASSERT if
- * we do not!
- */
-
- if (curr)
- {
- /* Was there another entry before this one? */
-
- if (prev)
- {
- /* Yes.. remove the current entry from after the previous entry */
-
- prev->flink = curr->flink;
- }
- else
- {
- /* No.. remove the current entry from the head of the list */
-
- g_unloadhead = curr->flink;
- }
-
- /* Nullify the forward link ... superstitious */
-
- curr->flink = NULL;
- }
-
- sched_unlock();
- return curr;
-}
-
-/****************************************************************************
- * Name: unload_callback
- *
- * Description:
- * If CONFIG_SCHED_HAVE_PARENT is defined, this function may be called to
- * automatically unload the module when task exits. It assumes that
- * bin was allocated with kmalloc() or friends and will also automatically
- * free the structure with kfree() when the task exists.
- *
- * Input Parameter:
- * pid - The ID of the task that just exited
- * arg - A reference to the load structure cast to FAR void *
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-static void unload_callback(int signo, siginfo_t *info, void *ucontext)
-{
- FAR struct binary_s *bin;
- int ret;
-
- /* Sanity checking */
-
- if (!info || signo != SIGCHLD)
- {
- blldbg("ERROR:Bad signal callback: signo=%d info=%p\n", signo, callback);
- return;
- }
-
- /* Get the load information for this pid */
-
- bin = unload_list_remove(info->si_pid);
- if (!bin)
- {
- blldbg("ERROR: Could not find load info for PID=%d\n", info->si_pid);
- return;
- }
-
- /* Unload the module */
-
- ret = unload_module(bin);
- if (ret < 0)
- {
- blldbg("ERROR: unload_module failed: %d\n", get_errno());
- }
-
- /* Free the load structure */
-
- kfree(bin);
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: schedule_unload
- *
- * Description:
- * If CONFIG_SCHED_HAVE_PARENT is defined, this function may be called by
- * the parent of the the newly created task to automatically unload the
- * module when the task exits. This assumes that (1) the caller is the
- * parent of the created task, (2) that bin was allocated with kmalloc()
- * or friends. It will also automatically free the structure with kfree()
- * after unloading the module.
- *
- * Input Parameter:
- * pid - The task ID of the child task
- * bin - This structure must have been allocated with kmalloc() and must
- * persist until the task unloads
- *
- * Returned Value:
- * This is an end-user function, so it follows the normal convention:
- * It returns 0 (OK) if the callback was successfully scheduled. On
- * failure, it returns -1 (ERROR) and sets errno appropriately.
- *
- * On failures, the 'bin' structure will not be deallocated and the
- * module not not be unloaded.
- *
- ****************************************************************************/
-
-int schedule_unload(pid_t pid, FAR struct binary_s *bin)
-{
- struct sigaction act;
- struct sigaction oact;
- sigset_t sigset;
- irqstate_t flags;
- int errorcode;
- int ret;
-
- /* Make sure that SIGCHLD is unmasked */
-
- (void)sigemptyset(&sigset);
- (void)sigaddset(&sigset, SIGCHLD);
- ret = sigprocmask(SIG_UNBLOCK, &sigset, NULL);
- if (ret != OK)
- {
- /* The errno value will get trashed by the following debug output */
-
- errorcode = get_errno();
- bvdbg("ERROR: sigprocmask failed: %d\n", ret);
- goto errout;
- }
-
- /* Add the structure to the list. We want to do this *before* connecting
- * the signal handler. This does, however, make error recovery more
- * complex if sigaction() fails below because then we have to remove the
- * unload structure for the list in an unexpected context.
- */
-
- unload_list_add(pid, bin);
-
- /* Register the SIGCHLD handler */
-
- act.sa_sigaction = unload_callback;
- act.sa_flags = SA_SIGINFO;
-
- (void)sigfillset(&act.sa_mask);
- (void)sigdelset(&act.sa_mask, SIGCHLD);
-
- ret = sigaction(SIGCHLD, &act, &oact);
- if (ret != OK)
- {
- /* The errno value will get trashed by the following debug output */
-
- errorcode = get_errno();
- bvdbg("ERROR: sigaction failed: %d\n" , ret);
-
- /* Emergency removal from the list */
-
- flags = irqsave();
- if (unload_list_remove(pid) != bin)
- {
- blldbg("ERROR: Failed to remove structure\n");
- }
-
- goto errout;
- }
-
- return OK;
-
-errout:
- set_errno(errorcode);
- return ERROR;
-}
-
-#endif /* !CONFIG_BINFMT_DISABLE && CONFIG_SCHED_HAVE_PARENT */
-
diff --git a/nuttx/binfmt/binfmt_unloadmodule.c b/nuttx/binfmt/binfmt_unloadmodule.c
deleted file mode 100644
index 365f26a34..000000000
--- a/nuttx/binfmt/binfmt_unloadmodule.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_loadmodule.c
- *
- * Copyright (C) 2009, 2012 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 <sys/mman.h>
-#include <stdlib.h>
-#include <sched.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/binfmt.h>
-
-#include "binfmt_internal.h"
-
-#ifndef CONFIG_BINFMT_DISABLE
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: exec_dtors
- *
- * Description:
- * Execute C++ static constructors.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
-static inline int exec_dtors(FAR const struct binary_s *binp)
-{
- binfmt_dtor_t *dtor = binp->dtors;
-#ifdef CONFIG_ADDRENV
- hw_addrenv_t oldenv;
- int ret;
-#endif
- int i;
-
- /* Instantiate the address enviroment containing the destructors */
-
-#ifdef CONFIG_ADDRENV
- ret = up_addrenv_select(binp->addrenv, &oldenv);
- if (ret < 0)
- {
- bdbg("up_addrenv_select() failed: %d\n", ret);
- return ret;
- }
-#endif
-
- /* Execute each destructor */
-
- for (i = 0; i < binp->ndtors; i++)
- {
- bvdbg("Calling dtor %d at %p\n", i, (FAR void *)dtor);
-
- (*dtor)();
- dtor++;
- }
-
- /* Restore the address enviroment */
-
-#ifdef CONFIG_ADDRENV
- return up_addrenv_restore(oldenv);
-#else
- return OK;
-#endif
-}
-#endif
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: unload_module
- *
- * Description:
- * Unload a (non-executing) module from memory. If the module has
- * been started (via exec_module) and has not exited, calling this will
- * be fatal.
- *
- * However, this function must be called after the module exist. How
- * this is done is up to your logic. Perhaps you register it to be
- * called by on_exit()?
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int unload_module(FAR const struct binary_s *binp)
-{
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
- int ret;
-#endif
- int i;
-
- if (binp)
- {
- /* Execute C++ desctructors */
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
- ret = exec_dtors(binp);
- if (ret < 0)
- {
- bdbg("exec_ctors() failed: %d\n", ret);
- set_errno(-ret);
- return ERROR;
- }
-#endif
-
- /* Unmap mapped address spaces */
-
- if (binp->mapped)
- {
- bvdbg("Unmapping address space: %p\n", binp->mapped);
-
- munmap(binp->mapped, binp->mapsize);
- }
-
- /* Free allocated address spaces */
-
- for (i = 0; i < BINFMT_NALLOC; i++)
- {
- if (binp->alloc[i])
- {
- bvdbg("Freeing alloc[%d]: %p\n", i, binp->alloc[i]);
- free((FAR void *)binp->alloc[i]);
- }
- }
-
- /* Notice that the address environment is not destroyed. This should
- * happen automatically when the task exits.
- */
- }
-
- return OK;
-}
-
-#endif /* CONFIG_BINFMT_DISABLE */
-
diff --git a/nuttx/binfmt/binfmt_unregister.c b/nuttx/binfmt/binfmt_unregister.c
deleted file mode 100644
index f895e354d..000000000
--- a/nuttx/binfmt/binfmt_unregister.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/****************************************************************************
- * binfmt/binfmt_unregister.c
- *
- * Copyright (C) 2009 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 <string.h>
-#include <sched.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/binfmt.h>
-
-#include "binfmt_internal.h"
-
-#ifndef CONFIG_BINFMT_DISABLE
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: unregister_binfmt
- *
- * Description:
- * Register a loader for a binary format
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int unregister_binfmt(FAR struct binfmt_s *binfmt)
-{
- FAR struct binfmt_s *curr;
- FAR struct binfmt_s *prev;
- int ret = -EINVAL;
-
- if (binfmt)
- {
- /* Disabling pre-emption should be sufficient protection while
- * accessing the list of registered binary format handlers.
- */
-
- sched_lock();
-
- /* Search the list of registered binary format handlers for the
- * one to be unregistered.
- */
-
- for (prev = NULL, curr = g_binfmts;
- curr && curr != binfmt;
- prev = curr, curr = curr->next);
-
- /* Was it in the list? */
-
- if (curr)
- {
- /* Yes.. was it at the head of the list? */
-
- if (!prev)
- {
- /* Yes.. remove it from the head of the list */
-
- g_binfmts = binfmt->next;
- }
- else
- {
- /* No.. remove it from the middle/end of the list */
-
- prev->next = binfmt->next;
- }
-
- binfmt->next = NULL;
- ret = OK;
- }
-
- sched_unlock();
- }
-
- return ret;
-}
-
-#endif /* CONFIG_BINFMT_DISABLE */
-
diff --git a/nuttx/binfmt/builtin.c b/nuttx/binfmt/builtin.c
deleted file mode 100644
index e492f72e5..000000000
--- a/nuttx/binfmt/builtin.c
+++ /dev/null
@@ -1,198 +0,0 @@
-/****************************************************************************
- * binfmt/builtin.c
- *
- * Copyright (C) 2012 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 <sys/types.h>
-#include <sys/ioctl.h>
-
-#include <stdint.h>
-#include <string.h>
-#include <fcntl.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/fs/ioctl.h>
-#include <nuttx/binfmt/binfmt.h>
-#include <nuttx/binfmt/builtin.h>
-
-#ifdef CONFIG_BUILTIN
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static int builtin_loadbinary(FAR struct binary_s *binp);
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-static struct binfmt_s g_builtin_binfmt =
-{
- NULL, /* next */
- builtin_loadbinary, /* load */
-};
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: builtin_loadbinary
- *
- * Description:
- * Verify that the file is an builtin binary.
- *
- ****************************************************************************/
-
-static int builtin_loadbinary(struct binary_s *binp)
-{
- FAR const char *filename;
- FAR const struct builtin_s *b;
- int fd;
- int index;
- int ret;
-
- bvdbg("Loading file: %s\n", binp->filename);
-
- /* Open the binary file for reading (only) */
-
- fd = open(binp->filename, O_RDONLY);
- if (fd < 0)
- {
- int errval = errno;
- bdbg("ERROR: Failed to open binary %s: %d\n", binp->filename, errval);
- return -errval;
- }
-
- /* If this file is a BINFS file system, then we can recover the name of
- * the file using the FIOC_FILENAME ioctl() call.
- */
-
- ret = ioctl(fd, FIOC_FILENAME, (unsigned long)((uintptr_t)&filename));
- if (ret < 0)
- {
- int errval = errno;
- bdbg("ERROR: FIOC_FILENAME ioctl failed: %d\n", errval);
- return -errval;
- }
-
- /* Other file systems may also support FIOC_FILENAME, so the real proof
- * is that we can look up the index to this name in g_builtins[].
- */
-
- index = builtin_isavail(filename);
- if (index < 0)
- {
- int errval = errno;
- bdbg("ERROR: %s is not a builtin application\n", filename);
- return -errval;
-
- }
-
- /* Return the load information. NOTE: that there is no way to configure
- * the priority. That is a bug and needs to be fixed.
- */
-
- b = builtin_for_index(index);
- binp->entrypt = b->main;
- binp->stacksize = b->stacksize;
- binp->priority = b->priority;
- return OK;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: builtin_initialize
- *
- * Description:
- * Builtin support is built unconditionally. However, it order to
- * use this binary format, this function must be called during system
- * format in order to register the builtin binary format.
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int builtin_initialize(void)
-{
- int ret;
-
- /* Register ourselves as a binfmt loader */
-
- bvdbg("Registering Builtin Loader\n");
-
- ret = register_binfmt(&g_builtin_binfmt);
- if (ret != 0)
- {
- bdbg("Failed to register binfmt: %d\n", ret);
- }
-
- return ret;
-}
-
-/****************************************************************************
- * Name: builtin_uninitialize
- *
- * Description:
- * Unregister the builtin binary loader
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-void builtin_uninitialize(void)
-{
- unregister_binfmt(&g_builtin_binfmt);
-}
-
-#endif /* CONFIG_BUILTIN */
-
diff --git a/nuttx/binfmt/elf.c b/nuttx/binfmt/elf.c
deleted file mode 100644
index 9dc59fbdd..000000000
--- a/nuttx/binfmt/elf.c
+++ /dev/null
@@ -1,323 +0,0 @@
-/****************************************************************************
- * binfmt/elf.c
- *
- * Copyright (C) 2012 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 <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <elf32.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <arpa/inet.h>
-#include <nuttx/binfmt/binfmt.h>
-#include <nuttx/binfmt/elf.h>
-
-#ifdef CONFIG_ELF
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
- * defined or CONFIG_ELF_DUMPBUFFER does nothing.
- */
-
-#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
-# undef CONFIG_ELF_DUMPBUFFER
-#endif
-
-#ifndef CONFIG_ELF_STACKSIZE
-# define CONFIG_ELF_STACKSIZE 2048
-#endif
-
-#ifdef CONFIG_ELF_DUMPBUFFER
-# define elf_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
-#else
-# define elf_dumpbuffer(m,b,n)
-#endif
-
-#ifndef MIN
-# define MIN(a,b) (a < b ? a : b)
-#endif
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static int elf_loadbinary(FAR struct binary_s *binp);
-#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
-static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo);
-#endif
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-static struct binfmt_s g_elfbinfmt =
-{
- NULL, /* next */
- elf_loadbinary, /* load */
-};
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_dumploadinfo
- ****************************************************************************/
-
-#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
-static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo)
-{
- int i;
-
- bdbg("LOAD_INFO:\n");
- bdbg(" elfalloc: %08lx\n", (long)loadinfo->elfalloc);
- bdbg(" elfsize: %ld\n", (long)loadinfo->elfsize);
- bdbg(" filelen: %ld\n", (long)loadinfo->filelen);
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
- bdbg(" ctoralloc: %08lx\n", (long)loadinfo->ctoralloc);
- bdbg(" ctors: %08lx\n", (long)loadinfo->ctors);
- bdbg(" nctors: %d\n", loadinfo->nctors);
- bdbg(" dtoralloc: %08lx\n", (long)loadinfo->dtoralloc);
- bdbg(" dtors: %08lx\n", (long)loadinfo->dtors);
- bdbg(" ndtors: %d\n", loadinfo->ndtors);
-#endif
- bdbg(" filfd: %d\n", loadinfo->filfd);
- bdbg(" symtabidx: %d\n", loadinfo->symtabidx);
- bdbg(" strtabidx: %d\n", loadinfo->strtabidx);
-
- bdbg("ELF Header:\n");
- bdbg(" e_ident: %02x %02x %02x %02x\n",
- loadinfo->ehdr.e_ident[0], loadinfo->ehdr.e_ident[1],
- loadinfo->ehdr.e_ident[2], loadinfo->ehdr.e_ident[3]);
- bdbg(" e_type: %04x\n", loadinfo->ehdr.e_type);
- bdbg(" e_machine: %04x\n", loadinfo->ehdr.e_machine);
- bdbg(" e_version: %08x\n", loadinfo->ehdr.e_version);
- bdbg(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry);
- bdbg(" e_phoff: %d\n", loadinfo->ehdr.e_phoff);
- bdbg(" e_shoff: %d\n", loadinfo->ehdr.e_shoff);
- bdbg(" e_flags: %08x\n" , loadinfo->ehdr.e_flags);
- bdbg(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize);
- bdbg(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize);
- bdbg(" e_phnum: %d\n", loadinfo->ehdr.e_phnum);
- bdbg(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize);
- bdbg(" e_shnum: %d\n", loadinfo->ehdr.e_shnum);
- bdbg(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx);
-
- if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0)
- {
- for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
- {
- FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
- bdbg("Sections %d:\n", i);
- bdbg(" sh_name: %08x\n", shdr->sh_name);
- bdbg(" sh_type: %08x\n", shdr->sh_type);
- bdbg(" sh_flags: %08x\n", shdr->sh_flags);
- bdbg(" sh_addr: %08x\n", shdr->sh_addr);
- bdbg(" sh_offset: %d\n", shdr->sh_offset);
- bdbg(" sh_size: %d\n", shdr->sh_size);
- bdbg(" sh_link: %d\n", shdr->sh_link);
- bdbg(" sh_info: %d\n", shdr->sh_info);
- bdbg(" sh_addralign: %d\n", shdr->sh_addralign);
- bdbg(" sh_entsize: %d\n", shdr->sh_entsize);
- }
- }
-}
-#else
-# define elf_dumploadinfo(i)
-#endif
-
-/****************************************************************************
- * Name: elf_loadbinary
- *
- * Description:
- * Verify that the file is an ELF binary and, if so, load the ELF
- * binary into memory
- *
- ****************************************************************************/
-
-static int elf_loadbinary(struct binary_s *binp)
-{
- struct elf_loadinfo_s loadinfo; /* Contains globals for libelf */
- int ret;
-
- bvdbg("Loading file: %s\n", binp->filename);
-
- /* Initialize the ELF library to load the program binary. */
-
- ret = elf_init(binp->filename, &loadinfo);
- elf_dumploadinfo(&loadinfo);
- if (ret != 0)
- {
- bdbg("Failed to initialize for load of ELF program: %d\n", ret);
- goto errout;
- }
-
- /* Load the program binary */
-
- ret = elf_load(&loadinfo);
- elf_dumploadinfo(&loadinfo);
- if (ret != 0)
- {
- bdbg("Failed to load ELF program binary: %d\n", ret);
- goto errout_with_init;
- }
-
- /* Bind the program to the exported symbol table */
-
- ret = elf_bind(&loadinfo, binp->exports, binp->nexports);
- if (ret != 0)
- {
- bdbg("Failed to bind symbols program binary: %d\n", ret);
- goto errout_with_load;
- }
-
- /* Return the load information */
-
- binp->entrypt = (main_t)(loadinfo.elfalloc + loadinfo.ehdr.e_entry);
- binp->stacksize = CONFIG_ELF_STACKSIZE;
-
- /* Add the ELF allocation to the alloc[] only if there is no address
- * enironment. If there is an address environment, it will automatically
- * be freed when the function exits
- *
- * REVISIT: If the module is loaded then unloaded, wouldn't this cause
- * a memory leak?
- */
-
-#ifdef CONFIG_ADDRENV
-# warning "REVISIT"
-#else
- binp->alloc[0] = (FAR void *)loadinfo.elfalloc;
-#endif
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
- /* Save information about constructors. NOTE: desctructors are not
- * yet supported.
- */
-
- binp->alloc[1] = loadinfo.ctoralloc;
- binp->ctors = loadinfo.ctors;
- binp->nctors = loadinfo.nctors;
-
- binp->alloc[2] = loadinfo.dtoralloc;
- binp->dtors = loadinfo.dtors;
- binp->ndtors = loadinfo.ndtors;
-#endif
-
-#ifdef CONFIG_ADDRENV
- /* Save the address environment. This will be needed when the module is
- * executed for the up_addrenv_assign() call.
- */
-
- binp->addrenv = loadinfo.addrenv;
-#endif
-
- elf_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt,
- MIN(loadinfo.allocsize - loadinfo.ehdr.e_entry, 512));
-
- elf_uninit(&loadinfo);
- return OK;
-
-errout_with_load:
- elf_unload(&loadinfo);
-errout_with_init:
- elf_uninit(&loadinfo);
-errout:
- return ret;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_initialize
- *
- * Description:
- * ELF support is built unconditionally. However, it order to
- * use this binary format, this function must be called during system
- * format in order to register the ELF binary format.
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_initialize(void)
-{
- int ret;
-
- /* Register ourselves as a binfmt loader */
-
- bvdbg("Registering ELF\n");
-
- ret = register_binfmt(&g_elfbinfmt);
- if (ret != 0)
- {
- bdbg("Failed to register binfmt: %d\n", ret);
- }
-
- return ret;
-}
-
-/****************************************************************************
- * Name: elf_uninitialize
- *
- * Description:
- * Unregister the ELF binary loader
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-void elf_uninitialize(void)
-{
- unregister_binfmt(&g_elfbinfmt);
-}
-
-#endif /* CONFIG_ELF */
-
diff --git a/nuttx/binfmt/libbuiltin/Kconfig b/nuttx/binfmt/libbuiltin/Kconfig
deleted file mode 100644
index ae2bf3130..000000000
--- a/nuttx/binfmt/libbuiltin/Kconfig
+++ /dev/null
@@ -1,4 +0,0 @@
-#
-# For a description of the syntax of this configuration file,
-# see misc/tools/kconfig-language.txt.
-#
diff --git a/nuttx/binfmt/libbuiltin/Make.defs b/nuttx/binfmt/libbuiltin/Make.defs
deleted file mode 100644
index 5eec1acde..000000000
--- a/nuttx/binfmt/libbuiltin/Make.defs
+++ /dev/null
@@ -1,52 +0,0 @@
-############################################################################
-# binfmt/libbuiltin/Make.defs
-#
-# Copyright (C) 2013 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.
-#
-############################################################################
-
-ifeq ($(CONFIG_BUILTIN),y)
-
-# Builtin application interfaces
-
-BINFMT_CSRCS += builtin.c
-
-# Builtin library interfaces
-
-BINFMT_CSRCS += libbuiltin_getname.c libbuiltin_isavail.c
-
-# Hook the libbuiltin subdirectory into the build
-
-VPATH += libbuiltin
-SUBDIRS += libbuiltin
-DEPPATH += --dep-path libbuiltin
-
-endif
diff --git a/nuttx/binfmt/libbuiltin/libbuiltin_getname.c b/nuttx/binfmt/libbuiltin/libbuiltin_getname.c
deleted file mode 100644
index d1e3958b3..000000000
--- a/nuttx/binfmt/libbuiltin/libbuiltin_getname.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************************
- * binfmt/libbuiltin/libbuiltin_getname.c
- *
- * Originally by:
- *
- * Copyright (C) 2011 Uros Platise. All rights reserved.
- * Author: Uros Platise <uros.platise@isotel.eu>
- *
- * With subsequent updates, modifications, and general maintenance by:
- *
- * Copyright (C) 2012-2013 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 <nuttx/binfmt/builtin.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: builtin_getname
- *
- * Description:
- * Return the name of the application at index in the table of builtin
- * applications.
- *
- ****************************************************************************/
-
-FAR const char *builtin_getname(int index)
-{
- FAR const struct builtin_s *builtin;
-
- builtin = builtin_for_index(index);
-
- if (builtin != NULL)
- {
- return builtin->name;
- }
-
- return NULL;
-}
diff --git a/nuttx/binfmt/libbuiltin/libbuiltin_isavail.c b/nuttx/binfmt/libbuiltin/libbuiltin_isavail.c
deleted file mode 100644
index 7a480c0f3..000000000
--- a/nuttx/binfmt/libbuiltin/libbuiltin_isavail.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/****************************************************************************
- * binfmt/libbuiltin/libbuiltin_isavail.c
- *
- * Originally by:
- *
- * Copyright (C) 2011 Uros Platise. All rights reserved.
- * Author: Uros Platise <uros.platise@isotel.eu>
- *
- * With subsequent updates, modifications, and general maintenance by:
- *
- * Copyright (C) 2012-2013 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 <string.h>
-#include <limits.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/builtin.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: builtin_isavail
- *
- * Description:
- * Return the index into the table of applications for the application with
- * the name 'appname'.
- *
- ****************************************************************************/
-
-int builtin_isavail(FAR const char *appname)
-{
- FAR const char *name;
- int i;
-
- for (i = 0; (name = builtin_getname(i)); i++)
- {
- if (!strncmp(name, appname, NAME_MAX))
- {
- return i;
- }
- }
-
- set_errno(ENOENT);
- return ERROR;
-}
diff --git a/nuttx/binfmt/libelf/Kconfig b/nuttx/binfmt/libelf/Kconfig
deleted file mode 100644
index f6f579276..000000000
--- a/nuttx/binfmt/libelf/Kconfig
+++ /dev/null
@@ -1,40 +0,0 @@
-#
-# For a description of the syntax of this configuration file,
-# see misc/tools/kconfig-language.txt.
-#
-
-config ELF_ALIGN_LOG2
- int "Log2 Section Alignment"
- default 2
- ---help---
- Align all sections to this Log2 value: 0->1, 1->2, 2->4, etc.
-
-config ELF_STACKSIZE
- int "ELF Stack Size"
- default 2048
- ---help---
- This is the default stack size that will will be used when starting ELF binaries.
-
-config ELF_BUFFERSIZE
- int "ELF I/O Buffer Size"
- default 128
- ---help---
- This is an I/O buffer that is used to access the ELF file. Variable length items
- will need to be read (such as symbol names). This is really just this initial
- size of the buffer; it will be reallocated as necessary to hold large symbol
- names). Default: 128
-
-config ELF_BUFFERINCR
- int "ELF I/O Buffer Realloc Increment"
- default 32
- ---help---
- This is an I/O buffer that is used to access the ELF file. Variable length items
- will need to be read (such as symbol names). This value specifies the size
- increment to use each time the buffer is reallocated. Default: 32
-
-config ELF_DUMPBUFFER
- bool "Dump ELF buffers"
- default n
- depends on DEBUG && DEBUG_VERBOSE
- ---help---
- Dump various ELF buffers for debug purposes
diff --git a/nuttx/binfmt/libelf/Make.defs b/nuttx/binfmt/libelf/Make.defs
deleted file mode 100644
index 93d95a23c..000000000
--- a/nuttx/binfmt/libelf/Make.defs
+++ /dev/null
@@ -1,58 +0,0 @@
-############################################################################
-# binfmt/libelf/Make.defs
-#
-# Copyright (C) 2012 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.
-#
-############################################################################
-
-ifeq ($(CONFIG_ELF),y)
-
-# ELF application interfaces
-
-BINFMT_CSRCS += elf.c
-
-# ELF library
-
-BINFMT_CSRCS += libelf_bind.c libelf_init.c libelf_addrenv.c libelf_iobuffer.c
-BINFMT_CSRCS += libelf_load.c libelf_read.c libelf_sections.c libelf_symbols.c
-BINFMT_CSRCS += libelf_uninit.c libelf_unload.c libelf_verify.c
-
-ifeq ($(CONFIG_BINFMT_CONSTRUCTORS),y)
-BINFMT_CSRCS += libelf_ctors.c libelf_dtors.c
-endif
-
-# Hook the libelf subdirectory into the build
-
-VPATH += libelf
-SUBDIRS += libelf
-DEPPATH += --dep-path libelf
-
-endif
diff --git a/nuttx/binfmt/libelf/gnu-elf.ld b/nuttx/binfmt/libelf/gnu-elf.ld
deleted file mode 100644
index b2a3dc113..000000000
--- a/nuttx/binfmt/libelf/gnu-elf.ld
+++ /dev/null
@@ -1,129 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/gnu-elf.ld
- *
- * Copyright (C) 2012 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.
- *
- ****************************************************************************/
-
-SECTIONS
-{
- .text 0x00000000 :
- {
- _stext = . ;
- *(.text)
- *(.text.*)
- *(.gnu.warning)
- *(.stub)
- *(.glue_7)
- *(.glue_7t)
- *(.jcr)
-
- /* C++ support: The .init and .fini sections contain specific logic
- * to manage static constructors and destructors.
- */
-
- *(.gnu.linkonce.t.*)
- *(.init) /* Old ABI */
- *(.fini) /* Old ABI */
- _etext = . ;
- }
-
- .rodata :
- {
- _srodata = . ;
- *(.rodata)
- *(.rodata1)
- *(.rodata.*)
- *(.gnu.linkonce.r*)
- _erodata = . ;
- }
-
- .data :
- {
- _sdata = . ;
- *(.data)
- *(.data1)
- *(.data.*)
- *(.gnu.linkonce.d*)
- _edata = . ;
- }
-
- /* C++ support. For each global and static local C++ object,
- * GCC creates a small subroutine to construct the object. Pointers
- * to these routines (not the routines themselves) are stored as
- * simple, linear arrays in the .ctors section of the object file.
- * Similarly, pointers to global/static destructor routines are
- * stored in .dtors.
- */
-
- .ctors :
- {
- _sctors = . ;
- *(.ctors) /* Old ABI: Unallocated */
- *(.init_array) /* New ABI: Allocated */
- _edtors = . ;
- }
-
- .dtors :
- {
- _sdtors = . ;
- *(.dtors) /* Old ABI: Unallocated */
- *(.fini_array) /* New ABI: Allocated */
- _edtors = . ;
- }
-
- .bss :
- {
- _sbss = . ;
- *(.bss)
- *(.bss.*)
- *(.sbss)
- *(.sbss.*)
- *(.gnu.linkonce.b*)
- *(COMMON)
- _ebss = . ;
- }
-
- /* Stabs debugging sections. */
-
- .stab 0 : { *(.stab) }
- .stabstr 0 : { *(.stabstr) }
- .stab.excl 0 : { *(.stab.excl) }
- .stab.exclstr 0 : { *(.stab.exclstr) }
- .stab.index 0 : { *(.stab.index) }
- .stab.indexstr 0 : { *(.stab.indexstr) }
- .comment 0 : { *(.comment) }
- .debug_abbrev 0 : { *(.debug_abbrev) }
- .debug_info 0 : { *(.debug_info) }
- .debug_line 0 : { *(.debug_line) }
- .debug_pubnames 0 : { *(.debug_pubnames) }
- .debug_aranges 0 : { *(.debug_aranges) }
-}
diff --git a/nuttx/binfmt/libelf/libelf.h b/nuttx/binfmt/libelf/libelf.h
deleted file mode 100644
index 04c9144f6..000000000
--- a/nuttx/binfmt/libelf/libelf.h
+++ /dev/null
@@ -1,341 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf.h
- *
- * Copyright (C) 2012 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 __BINFMT_LIBELF_LIBELF_H
-#define __BINFMT_LIBELF_LIBELF_H
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-#include <elf32.h>
-
-#include <nuttx/arch.h>
-#include <nuttx/binfmt/elf.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Types
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_verifyheader
- *
- * Description:
- * Given the header from a possible ELF executable, verify that it is
- * an ELF executable.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_verifyheader(FAR const Elf32_Ehdr *header);
-
-/****************************************************************************
- * Name: elf_read
- *
- * Description:
- * Read 'readsize' bytes from the object file at 'offset'. The data is
- * read into 'buffer.' If 'buffer' is part of the ELF address environment,
- * then the caller is responsibile for assuring that that address
- * environment is in place before calling this function (i.e., that
- * elf_addrenv_select() has been called if CONFIG_ADDRENV=y).
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
- size_t readsize, off_t offset);
-
-/****************************************************************************
- * Name: elf_loadshdrs
- *
- * Description:
- * Loads section headers into memory.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_loadshdrs(FAR struct elf_loadinfo_s *loadinfo);
-
-/****************************************************************************
- * Name: elf_findsection
- *
- * Description:
- * A section by its name.
- *
- * Input Parameters:
- * loadinfo - Load state information
- * sectname - Name of the section to find
- *
- * Returned Value:
- * On success, the index to the section is returned; A negated errno value
- * is returned on failure.
- *
- ****************************************************************************/
-
-int elf_findsection(FAR struct elf_loadinfo_s *loadinfo,
- FAR const char *sectname);
-
-/****************************************************************************
- * Name: elf_findsymtab
- *
- * Description:
- * Find the symbol table section.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_findsymtab(FAR struct elf_loadinfo_s *loadinfo);
-
-/****************************************************************************
- * Name: elf_readsym
- *
- * Description:
- * Read the ELFT symbol structure at the specfied index into memory.
- *
- * Input Parameters:
- * loadinfo - Load state information
- * index - Symbol table index
- * sym - Location to return the table entry
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_readsym(FAR struct elf_loadinfo_s *loadinfo, int index,
- FAR Elf32_Sym *sym);
-
-/****************************************************************************
- * Name: elf_symvalue
- *
- * Description:
- * Get the value of a symbol. The updated value of the symbol is returned
- * in the st_value field of the symbol table entry.
- *
- * 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
- * failure.
- *
- ****************************************************************************/
-
-int elf_symvalue(FAR struct elf_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
- FAR const struct symtab_s *exports, int nexports);
-
-/****************************************************************************
- * Name: elf_freebuffers
- *
- * Description:
- * Release all working buffers.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_freebuffers(FAR struct elf_loadinfo_s *loadinfo);
-
-/****************************************************************************
- * Name: elf_allocbuffer
- *
- * Description:
- * Perform the initial allocation of the I/O buffer, if it has not already
- * been allocated.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_allocbuffer(FAR struct elf_loadinfo_s *loadinfo);
-
-/****************************************************************************
- * Name: elf_reallocbuffer
- *
- * Description:
- * Increase the size of I/O buffer by the specified buffer increment.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_reallocbuffer(FAR struct elf_loadinfo_s *loadinfo, size_t increment);
-
-/****************************************************************************
- * Name: elf_findctors
- *
- * Description:
- * Find C++ static constructors.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
-int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo);
-#endif
-
-/****************************************************************************
- * Name: elf_loaddtors
- *
- * Description:
- * Load pointers to static destructors into an in-memory array.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
-int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo);
-#endif
-
-/****************************************************************************
- * Name: elf_addrenv_alloc
- *
- * Description:
- * Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
- * elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
- * elfalloc will be allocated using up_addrenv_create(). In either case,
- * there will be a unique instance of elfalloc (and stack) for each
- * instance of a process.
- *
- * Input Parameters:
- * loadinfo - Load state information
- * envsize - The size (in bytes) of the address environment needed for the
- * ELF image.
- *
- * Returned Value:
- * Zero (OK) on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo, size_t envsize);
-
-/****************************************************************************
- * Name: elf_addrenv_select
- *
- * Description:
- * Temporarity select the task's address environemnt.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * Zero (OK) on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_ADDRENV
-# define elf_addrenv_select(l) up_addrenv_select((l)->addrenv, &(l)->oldenv)
-#endif
-
-/****************************************************************************
- * Name: elf_addrenv_restore
- *
- * Description:
- * Restore the address environment before elf_addrenv_select() was called..
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * Zero (OK) on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_ADDRENV
-# define elf_addrenv_restore(l) up_addrenv_restore((l)->oldenv)
-#endif
-
-/****************************************************************************
- * Name: elf_addrenv_free
- *
- * Description:
- * Release the address environment previously created by
- * elf_addrenv_alloc(). This function is called only under certain error
- * conditions after the the module has been loaded but not yet started.
- * After the module has been started, the address environment will
- * automatically be freed when the module exits.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * None.
- *
- ****************************************************************************/
-
-void elf_addrenv_free(FAR struct elf_loadinfo_s *loadinfo);
-
-#endif /* __BINFMT_LIBELF_LIBELF_H */
diff --git a/nuttx/binfmt/libelf/libelf_addrenv.c b/nuttx/binfmt/libelf/libelf_addrenv.c
deleted file mode 100644
index 193062a54..000000000
--- a/nuttx/binfmt/libelf/libelf_addrenv.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_addrenv.c
- *
- * Copyright (C) 2012 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 <errno.h>
-#include <debug.h>
-
-#include <nuttx/arch.h>
-#include <nuttx/kmalloc.h>
-
-#include "libelf.h"
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_addrenv_alloc
- *
- * Description:
- * Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
- * elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
- * elfalloc will be allocated using up_addrenv_create(). In either case,
- * there will be a unique instance of elfalloc (and stack) for each
- * instance of a process.
- *
- * Input Parameters:
- * loadinfo - Load state information
- * envsize - The size (in bytes) of the address environment needed for the
- * ELF image.
- *
- * Returned Value:
- * Zero (OK) on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo, size_t envsize)
-{
-#ifdef CONFIG_ADDRENV
- FAR void *vaddr;
- int ret;
-
- /* Create an address environment for the new ELF task */
-
- ret = up_addrenv_create(envsize, &loadinfo->addrenv);
- if (ret < 0)
- {
- bdbg("ERROR: up_addrenv_create failed: %d\n", ret);
- return ret;
- }
-
- /* Get the virtual address associated with the start of the address
- * environment. This is the base address that we will need to use to
- * access the ELF image (but only if the address environment has been
- * selected.
- */
-
- ret = up_addrenv_vaddr(loadinfo->addrenv, &vaddr);
- if (ret < 0)
- {
- bdbg("ERROR: up_addrenv_vaddr failed: %d\n", ret);
- return ret;
- }
-
- loadinfo->elfalloc = (uintptr_t)vaddr;
- return OK;
-#else
- /* Allocate memory to hold the ELF image */
-
- loadinfo->elfalloc = (uintptr_t)kzalloc(envsize);
- if (!loadinfo->elfalloc)
- {
- return -ENOMEM;
- }
-
- return OK;
-#endif
-}
-
-/****************************************************************************
- * Name: elf_addrenv_free
- *
- * Description:
- * Release the address environment previously created by
- * elf_addrenv_create(). This function is called only under certain error
- * conditions after the the module has been loaded but not yet started.
- * After the module has been started, the address environment will
- * automatically be freed when the module exits.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * None.
- *
- ****************************************************************************/
-
-void elf_addrenv_free(FAR struct elf_loadinfo_s *loadinfo)
-{
-#ifdef CONFIG_ADDRENV
- int ret;
-
- /* Free the address environemnt */
-
- ret = up_addrenv_destroy(loadinfo->addrenv);
- if (ret < 0)
- {
- bdbg("ERROR: up_addrenv_destroy failed: %d\n", ret);
- }
-
- /* Clear out all indications of the allocated address environment */
-
- loadinfo->elfalloc = 0;
- loadinfo->elfsize = 0;
- loadinfo->addrenv = 0;
-#else
- /* If there is an allocation for the ELF image, free it */
-
- if (loadinfo->elfalloc != 0)
- {
- kfree((FAR void *)loadinfo->elfalloc);
- loadinfo->elfalloc = 0;
- }
-
- loadinfo->elfsize = 0;
-#endif
-}
diff --git a/nuttx/binfmt/libelf/libelf_bind.c b/nuttx/binfmt/libelf/libelf_bind.c
deleted file mode 100644
index ccdb5108e..000000000
--- a/nuttx/binfmt/libelf/libelf_bind.c
+++ /dev/null
@@ -1,334 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_bind.c
- *
- * Copyright (C) 2012 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 <stdint.h>
-#include <string.h>
-#include <elf32.h>
-#include <errno.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/binfmt/elf.h>
-#include <nuttx/binfmt/symtab.h>
-
-#include "libelf.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
- * defined or CONFIG_ELF_DUMPBUFFER does nothing.
- */
-
-#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
-# undef CONFIG_ELF_DUMPBUFFER
-#endif
-
-#ifndef CONFIG_ELF_BUFFERSIZE
-# define CONFIG_ELF_BUFFERSIZE 128
-#endif
-
-#ifdef CONFIG_ELF_DUMPBUFFER
-# define elf_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
-#else
-# define elf_dumpbuffer(m,b,n)
-#endif
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_readrel
- *
- * Description:
- * Read the ELF32_Rel structure into memory.
- *
- ****************************************************************************/
-
-static inline int elf_readrel(FAR struct elf_loadinfo_s *loadinfo,
- FAR const Elf32_Shdr *relsec,
- int index, FAR Elf32_Rel *rel)
-{
- off_t offset;
-
- /* Verify that the symbol table index lies within symbol table */
-
- if (index < 0 || index > (relsec->sh_size / sizeof(Elf32_Rel)))
- {
- bdbg("Bad relocation symbol index: %d\n", index);
- return -EINVAL;
- }
-
- /* Get the file offset to the symbol table entry */
-
- offset = relsec->sh_offset + sizeof(Elf32_Rel) * index;
-
- /* And, finally, read the symbol table entry into memory */
-
- return elf_read(loadinfo, (FAR uint8_t*)rel, sizeof(Elf32_Rel), offset);
-}
-
-/****************************************************************************
- * Name: elf_relocate and elf_relocateadd
- *
- * Description:
- * Perform all relocations associated with a section.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static int elf_relocate(FAR struct elf_loadinfo_s *loadinfo, int relidx,
- FAR const struct symtab_s *exports, int nexports)
-
-{
- FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx];
- FAR Elf32_Shdr *dstsec = &loadinfo->shdr[relsec->sh_info];
- Elf32_Rel rel;
- Elf32_Sym sym;
- uintptr_t addr;
- int symidx;
- int ret;
- int i;
-
- /* Examine each relocation in the section. 'relsec' is the section
- * containing the relations. 'dstsec' is the section containing the data
- * to be relocated.
- */
-
- for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++)
- {
- /* Read the relocation entry into memory */
-
- ret = elf_readrel(loadinfo, relsec, i, &rel);
- if (ret < 0)
- {
- bdbg("Section %d reloc %d: Failed to read relocation entry: %d\n",
- relidx, i, ret);
- return ret;
- }
-
- /* Get the symbol table index for the relocation. This is contained
- * in a bit-field within the r_info element.
- */
-
- symidx = ELF32_R_SYM(rel.r_info);
-
- /* Read the symbol table entry into memory */
-
- ret = elf_readsym(loadinfo, symidx, &sym);
- if (ret < 0)
- {
- bdbg("Section %d reloc %d: Failed to read symbol[%d]: %d\n",
- relidx, i, symidx, ret);
- return ret;
- }
-
- /* Get the value of the symbol (in sym.st_value) */
-
- ret = elf_symvalue(loadinfo, &sym, exports, nexports);
- if (ret < 0)
- {
- bdbg("Section %d reloc %d: Failed to get value of symbol[%d]: %d\n",
- relidx, i, symidx, ret);
- return ret;
- }
-
- /* Calculate the relocation address. */
-
- if (rel.r_offset < 0 || rel.r_offset > dstsec->sh_size - sizeof(uint32_t))
- {
- bdbg("Section %d reloc %d: Relocation address out of range, offset %d size %d\n",
- relidx, i, rel.r_offset, dstsec->sh_size);
- return -EINVAL;
- }
-
- addr = dstsec->sh_addr + rel.r_offset;
-
- /* If CONFIG_ADDRENV=y, then 'addr' lies in a virtual address space that
- * may not be in place now. elf_addrenv_select() will temporarily
- * instantiate that address space.
- */
-
-#ifdef CONFIG_ADDRENV
- ret = elf_addrenv_select(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: elf_addrenv_select() failed: %d\n", ret);
- return ret;
- }
-#endif
-
- /* Now perform the architecture-specific relocation */
-
- ret = arch_relocate(&rel, &sym, addr);
- if (ret < 0)
- {
-#ifdef CONFIG_ADDRENV
- (void)elf_addrenv_restore(loadinfo);
-#endif
- bdbg("ERROR: Section %d reloc %d: Relocation failed: %d\n", ret);
- return ret;
- }
-
- /* Restore the original address environment */
-
-#ifdef CONFIG_ADDRENV
- ret = elf_addrenv_restore(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: elf_addrenv_restore() failed: %d\n", ret);
- return ret;
- }
-#endif
- }
-
- return OK;
-}
-
-static int elf_relocateadd(FAR struct elf_loadinfo_s *loadinfo, int relidx,
- FAR const struct symtab_s *exports, int nexports)
-{
- bdbg("Not implemented\n");
- return -ENOSYS;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_bind
- *
- * Description:
- * Bind the imported symbol names in the loaded module described by
- * 'loadinfo' using the exported symbol values provided by 'symtab'.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
- FAR const struct symtab_s *exports, int nexports)
-{
- int ret;
- int i;
-
- /* Find the symbol and string tables */
-
- ret = elf_findsymtab(loadinfo);
- if (ret < 0)
- {
- return ret;
- }
-
- /* Allocate an I/O buffer. This buffer is used by elf_symname() to
- * accumulate the variable length symbol name.
- */
-
- ret = elf_allocbuffer(loadinfo);
- if (ret < 0)
- {
- bdbg("elf_allocbuffer failed: %d\n", ret);
- return -ENOMEM;
- }
-
- /* Process relocations in every allocated section */
-
- for (i = 1; i < loadinfo->ehdr.e_shnum; i++)
- {
- /* Get the index to the relocation section */
-
- int infosec = loadinfo->shdr[i].sh_info;
- if (infosec >= loadinfo->ehdr.e_shnum)
- {
- continue;
- }
-
- /* Make sure that the section is allocated. We can't relocated
- * sections that were not loaded into memory.
- */
-
- if ((loadinfo->shdr[infosec].sh_flags & SHF_ALLOC) == 0)
- {
- continue;
- }
-
- /* Process the relocations by type */
-
- if (loadinfo->shdr[i].sh_type == SHT_REL)
- {
- ret = elf_relocate(loadinfo, i, exports, nexports);
- }
- else if (loadinfo->shdr[i].sh_type == SHT_RELA)
- {
- ret = elf_relocateadd(loadinfo, i, exports, nexports);
- }
-
- if (ret < 0)
- {
- break;
- }
- }
-
- /* Flush the instruction cache before starting the newly loaded module */
-
-#ifdef CONFIG_ELF_ICACHE
- arch_flushicache((FAR void*)loadinfo->elfalloc, loadinfo->elfsize);
-#endif
-
- return ret;
-}
-
diff --git a/nuttx/binfmt/libelf/libelf_ctors.c b/nuttx/binfmt/libelf/libelf_ctors.c
deleted file mode 100644
index 20f1256e2..000000000
--- a/nuttx/binfmt/libelf/libelf_ctors.c
+++ /dev/null
@@ -1,215 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_ctors.c
- *
- * Copyright (C) 2012 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 <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/elf.h>
-
-#include "libelf.h"
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_loadctors
- *
- * Description:
- * Load pointers to static constructors into an in-memory array.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo)
-{
- FAR Elf32_Shdr *shdr;
- size_t ctorsize;
- int ctoridx;
- int ret;
- int i;
-
- DEBUGASSERT(loadinfo->ctors == NULL);
-
- /* Allocate an I/O buffer if necessary. This buffer is used by
- * elf_sectname() to accumulate the variable length symbol name.
- */
-
- ret = elf_allocbuffer(loadinfo);
- if (ret < 0)
- {
- bdbg("elf_allocbuffer failed: %d\n", ret);
- return -ENOMEM;
- }
-
- /* Find the index to the section named ".ctors." NOTE: On old ABI system,
- * .ctors is the name of the section containing the list of constructors;
- * On newer systems, the similar section is called .init_array. It is
- * expected that the linker script will force the section name to be ".ctors"
- * in either case.
- */
-
- ctoridx = elf_findsection(loadinfo, ".ctors");
- if (ctoridx < 0)
- {
- /* This may not be a failure. -ENOENT indicates that the file has no
- * static constructor section.
- */
-
- bvdbg("elf_findsection .ctors section failed: %d\n", ctoridx);
- return ret == -ENOENT ? OK : ret;
- }
-
- /* Now we can get a pointer to the .ctor section in the section header
- * table.
- */
-
- shdr = &loadinfo->shdr[ctoridx];
-
- /* Get the size of the .ctor section and the number of constructors that
- * will need to be called.
- */
-
- ctorsize = shdr->sh_size;
- loadinfo->nctors = ctorsize / sizeof(binfmt_ctor_t);
-
- bvdbg("ctoridx=%d ctorsize=%d sizeof(binfmt_ctor_t)=%d nctors=%d\n",
- ctoridx, ctorsize, sizeof(binfmt_ctor_t), loadinfo->nctors);
-
- /* Check if there are any constructors. It is not an error if there
- * are none.
- */
-
- if (loadinfo->nctors > 0)
- {
- /* Check an assumption that we made above */
-
- DEBUGASSERT(shdr->sh_size == loadinfo->nctors * sizeof(binfmt_ctor_t));
-
- /* In the old ABI, the .ctors section is not allocated. In that case,
- * we need to allocate memory to hold the .ctors and then copy the
- * from the file into the allocated memory.
- *
- * SHF_ALLOC indicates that the section requires memory during
- * execution.
- */
-
- if ((shdr->sh_flags & SHF_ALLOC) == 0)
- {
- /* Allocate memory to hold a copy of the .ctor section */
-
- loadinfo->ctoralloc = (binfmt_ctor_t*)kmalloc(ctorsize);
- if (!loadinfo->ctoralloc)
- {
- bdbg("Failed to allocate memory for .ctors\n");
- return -ENOMEM;
- }
-
- loadinfo->ctors = (binfmt_ctor_t *)loadinfo->ctoralloc;
-
- /* Read the section header table into memory */
-
- ret = elf_read(loadinfo, (FAR uint8_t*)loadinfo->ctors, ctorsize,
- shdr->sh_offset);
- if (ret < 0)
- {
- bdbg("Failed to allocate .ctors: %d\n", ret);
- return ret;
- }
-
- /* Fix up all of the .ctor addresses. Since the addresses
- * do not lie in allocated memory, there will be no relocation
- * section for them.
- */
-
- for (i = 0; i < loadinfo->nctors; i++)
- {
- FAR uintptr_t *ptr = (uintptr_t *)((FAR void *)(&loadinfo->ctors)[i]);
-
- bvdbg("ctor %d: %08lx + %08lx = %08lx\n",
- i, *ptr, loadinfo->elfalloc, *ptr + loadinfo->elfalloc);
-
- *ptr += loadinfo->elfalloc;
- }
- }
- else
- {
-
- /* Save the address of the .ctors (actually, .init_array) where it was
- * loaded into memory. Since the .ctors lie in allocated memory, they
- * will be relocated via the normal mechanism.
- */
-
- loadinfo->ctors = (binfmt_ctor_t*)shdr->sh_addr;
- }
- }
-
- return OK;
-}
-
-#endif /* CONFIG_BINFMT_CONSTRUCTORS */
diff --git a/nuttx/binfmt/libelf/libelf_dtors.c b/nuttx/binfmt/libelf/libelf_dtors.c
deleted file mode 100644
index c0c73a337..000000000
--- a/nuttx/binfmt/libelf/libelf_dtors.c
+++ /dev/null
@@ -1,215 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_dtors.c
- *
- * Copyright (C) 2012 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 <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/elf.h>
-
-#include "libelf.h"
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_loaddtors
- *
- * Description:
- * Load pointers to static destructors into an in-memory array.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo)
-{
- FAR Elf32_Shdr *shdr;
- size_t dtorsize;
- int dtoridx;
- int ret;
- int i;
-
- DEBUGASSERT(loadinfo->dtors == NULL);
-
- /* Allocate an I/O buffer if necessary. This buffer is used by
- * elf_sectname() to accumulate the variable length symbol name.
- */
-
- ret = elf_allocbuffer(loadinfo);
- if (ret < 0)
- {
- bdbg("elf_allocbuffer failed: %d\n", ret);
- return -ENOMEM;
- }
-
- /* Find the index to the section named ".dtors." NOTE: On old ABI system,
- * .dtors is the name of the section containing the list of destructors;
- * On newer systems, the similar section is called .fini_array. It is
- * expected that the linker script will force the section name to be ".dtors"
- * in either case.
- */
-
- dtoridx = elf_findsection(loadinfo, ".dtors");
- if (dtoridx < 0)
- {
- /* This may not be a failure. -ENOENT indicates that the file has no
- * static destructor section.
- */
-
- bvdbg("elf_findsection .dtors section failed: %d\n", dtoridx);
- return ret == -ENOENT ? OK : ret;
- }
-
- /* Now we can get a pointer to the .dtor section in the section header
- * table.
- */
-
- shdr = &loadinfo->shdr[dtoridx];
-
- /* Get the size of the .dtor section and the number of destructors that
- * will need to be called.
- */
-
- dtorsize = shdr->sh_size;
- loadinfo->ndtors = dtorsize / sizeof(binfmt_dtor_t);
-
- bvdbg("dtoridx=%d dtorsize=%d sizeof(binfmt_dtor_t)=%d ndtors=%d\n",
- dtoridx, dtorsize, sizeof(binfmt_dtor_t), loadinfo->ndtors);
-
- /* Check if there are any destructors. It is not an error if there
- * are none.
- */
-
- if (loadinfo->ndtors > 0)
- {
- /* Check an assumption that we made above */
-
- DEBUGASSERT(shdr->sh_size == loadinfo->ndtors * sizeof(binfmt_dtor_t));
-
- /* In the old ABI, the .dtors section is not allocated. In that case,
- * we need to allocate memory to hold the .dtors and then copy the
- * from the file into the allocated memory.
- *
- * SHF_ALLOC indicates that the section requires memory during
- * execution.
- */
-
- if ((shdr->sh_flags & SHF_ALLOC) == 0)
- {
- /* Allocate memory to hold a copy of the .dtor section */
-
- loadinfo->ctoralloc = (binfmt_dtor_t*)kmalloc(dtorsize);
- if (!loadinfo->ctoralloc)
- {
- bdbg("Failed to allocate memory for .dtors\n");
- return -ENOMEM;
- }
-
- loadinfo->dtors = (binfmt_dtor_t *)loadinfo->ctoralloc;
-
- /* Read the section header table into memory */
-
- ret = elf_read(loadinfo, (FAR uint8_t*)loadinfo->dtors, dtorsize,
- shdr->sh_offset);
- if (ret < 0)
- {
- bdbg("Failed to allocate .dtors: %d\n", ret);
- return ret;
- }
-
- /* Fix up all of the .dtor addresses. Since the addresses
- * do not lie in allocated memory, there will be no relocation
- * section for them.
- */
-
- for (i = 0; i < loadinfo->ndtors; i++)
- {
- FAR uintptr_t *ptr = (uintptr_t *)((FAR void *)(&loadinfo->dtors)[i]);
-
- bvdbg("dtor %d: %08lx + %08lx = %08lx\n",
- i, *ptr, loadinfo->elfalloc, *ptr + loadinfo->elfalloc);
-
- *ptr += loadinfo->elfalloc;
- }
- }
- else
- {
-
- /* Save the address of the .dtors (actually, .init_array) where it was
- * loaded into memory. Since the .dtors lie in allocated memory, they
- * will be relocated via the normal mechanism.
- */
-
- loadinfo->dtors = (binfmt_dtor_t*)shdr->sh_addr;
- }
- }
-
- return OK;
-}
-
-#endif /* CONFIG_BINFMT_CONSTRUCTORS */
diff --git a/nuttx/binfmt/libelf/libelf_init.c b/nuttx/binfmt/libelf/libelf_init.c
deleted file mode 100644
index fa4b7983c..000000000
--- a/nuttx/binfmt/libelf/libelf_init.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_init.c
- *
- * Copyright (C) 2012 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 <sys/stat.h>
-
-#include <stdint.h>
-#include <string.h>
-#include <fcntl.h>
-#include <elf32.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/elf.h>
-
-#include "libelf.h"
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
- * defined or CONFIG_ELF_DUMPBUFFER does nothing.
- */
-
-#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
-# undef CONFIG_ELF_DUMPBUFFER
-#endif
-
-#ifdef CONFIG_ELF_DUMPBUFFER
-# define elf_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
-#else
-# define elf_dumpbuffer(m,b,n)
-#endif
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_filelen
- *
- * Description:
- * Get the size of the ELF file
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static inline int elf_filelen(FAR struct elf_loadinfo_s *loadinfo,
- FAR const char *filename)
-{
- struct stat buf;
- int ret;
-
- /* Get the file stats */
-
- ret = stat(filename, &buf);
- if (ret < 0)
- {
- int errval = errno;
- bdbg("Failed to fstat file: %d\n", errval);
- return -errval;
- }
-
- /* Verify that it is a regular file */
-
- if (!S_ISREG(buf.st_mode))
- {
- bdbg("Not a regular file. mode: %d\n", buf.st_mode);
- return -ENOENT;
- }
-
- /* TODO: Verify that the file is readable. Not really important because
- * we will detect this when we try to open the file read-only.
- */
-
- /* Return the size of the file in the loadinfo structure */
-
- loadinfo->filelen = buf.st_size;
- return OK;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_init
- *
- * Description:
- * This function is called to configure the library to process an ELF
- * program binary.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo)
-{
- int ret;
-
- bvdbg("filename: %s loadinfo: %p\n", filename, loadinfo);
-
- /* Clear the load info structure */
-
- memset(loadinfo, 0, sizeof(struct elf_loadinfo_s));
-
- /* Get the length of the file. */
-
- ret = elf_filelen(loadinfo, filename);
- if (ret < 0)
- {
- bdbg("elf_filelen failed: %d\n", ret);
- return ret;
- }
-
- /* Open the binary file for reading (only) */
-
- loadinfo->filfd = open(filename, O_RDONLY);
- if (loadinfo->filfd < 0)
- {
- int errval = errno;
- bdbg("Failed to open ELF binary %s: %d\n", filename, errval);
- return -errval;
- }
-
- /* Read the ELF ehdr from offset 0 */
-
- ret = elf_read(loadinfo, (FAR uint8_t*)&loadinfo->ehdr, sizeof(Elf32_Ehdr), 0);
- if (ret < 0)
- {
- bdbg("Failed to read ELF header: %d\n", ret);
- return ret;
- }
-
- elf_dumpbuffer("ELF header", (FAR const uint8_t*)&loadinfo->ehdr, sizeof(Elf32_Ehdr));
-
- /* Verify the ELF header */
-
- ret = elf_verifyheader(&loadinfo->ehdr);
- if (ret <0)
- {
- /* This may not be an error because we will be called to attempt loading
- * EVERY binary. If elf_verifyheader() does not recognize the ELF header,
- * it will -ENOEXEC whcih simply informs the system that the file is not an
- * ELF file. elf_verifyheader() will return other errors if the ELF header
- * is not correctly formed.
- */
-
- bdbg("Bad ELF header: %d\n", ret);
- return ret;
- }
-
- return OK;
-}
-
diff --git a/nuttx/binfmt/libelf/libelf_iobuffer.c b/nuttx/binfmt/libelf/libelf_iobuffer.c
deleted file mode 100644
index ead99ca09..000000000
--- a/nuttx/binfmt/libelf/libelf_iobuffer.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/elf_iobuffer.c
- *
- * Copyright (C) 2012 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 <debug.h>
-#include <errno.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/elf.h>
-
-#include "libelf.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_allocbuffer
- *
- * Description:
- * Perform the initial allocation of the I/O buffer, if it has not already
- * been allocated.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_allocbuffer(FAR struct elf_loadinfo_s *loadinfo)
-{
- /* Has a buffer been allocated> */
-
- if (!loadinfo->iobuffer)
- {
- /* No.. allocate one now */
-
- loadinfo->iobuffer = (FAR uint8_t *)kmalloc(CONFIG_ELF_BUFFERSIZE);
- if (!loadinfo->iobuffer)
- {
- bdbg("Failed to allocate an I/O buffer\n");
- return -ENOMEM;
- }
-
- loadinfo->buflen = CONFIG_ELF_BUFFERSIZE;
- }
-
- return OK;
-}
-
-/****************************************************************************
- * Name: elf_reallocbuffer
- *
- * Description:
- * Increase the size of I/O buffer by the specified buffer increment.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_reallocbuffer(FAR struct elf_loadinfo_s *loadinfo, size_t increment)
-{
- FAR void *buffer;
- size_t newsize;
-
- /* Get the new size of the allocation */
-
- newsize = loadinfo->buflen + increment;
-
- /* And perform the reallocation */
-
- buffer = krealloc((FAR void *)loadinfo->iobuffer, newsize);
- if (!buffer)
- {
- bdbg("Failed to reallocate the I/O buffer\n");
- return -ENOMEM;
- }
-
- /* Save the new buffer info */
-
- loadinfo->iobuffer = buffer;
- loadinfo->buflen = newsize;
- return OK;
-}
-
diff --git a/nuttx/binfmt/libelf/libelf_load.c b/nuttx/binfmt/libelf/libelf_load.c
deleted file mode 100644
index 0e4ad9798..000000000
--- a/nuttx/binfmt/libelf/libelf_load.c
+++ /dev/null
@@ -1,288 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_load.c
- *
- * Copyright (C) 2012 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 <sys/types.h>
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <elf32.h>
-#include <assert.h>
-#include <errno.h>
-#include <debug.h>
-
-#include <nuttx/binfmt/elf.h>
-
-#include "libelf.h"
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-#define ELF_ALIGN_MASK ((1 << CONFIG_ELF_ALIGN_LOG2) - 1)
-#define ELF_ALIGNUP(a) (((unsigned long)(a) + ELF_ALIGN_MASK) & ~ELF_ALIGN_MASK)
-#define ELF_ALIGNDOWN(a) ((unsigned long)(a) & ~ELF_ALIGN_MASK)
-
-
-#ifndef MAX
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-#endif
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_elfsize
- *
- * Description:
- * Calculate total memory allocation for the ELF file.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static void elf_elfsize(struct elf_loadinfo_s *loadinfo)
-{
- size_t elfsize;
- int i;
-
- /* Accumulate the size each section into memory that is marked SHF_ALLOC */
-
- elfsize = 0;
- for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
- {
- FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
-
- /* SHF_ALLOC indicates that the section requires memory during
- * execution.
- */
-
- if ((shdr->sh_flags & SHF_ALLOC) != 0)
- {
- elfsize += ELF_ALIGNUP(shdr->sh_size);
- }
- }
-
- /* Save the allocation size */
-
- loadinfo->elfsize = elfsize;
-}
-
-/****************************************************************************
- * Name: elf_loadfile
- *
- * Description:
- * Allocate memory for the file and read the section data into the
- * allocated memory. Section addresses in the shdr[] are updated to point
- * to the corresponding position in the allocated memory.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
-{
- FAR uint8_t *dest;
- int ret;
- int i;
-
- /* Allocate (and zero) memory for the ELF file. */
-
- ret = elf_addrenv_alloc(loadinfo, loadinfo->elfsize);
- if (ret < 0)
- {
- bdbg("ERROR: elf_addrenv_alloc() failed: %d\n", ret);
- return ret;
- }
-
- /* Read each section into memory that is marked SHF_ALLOC + SHT_NOBITS */
-
- bvdbg("Loaded sections:\n");
- dest = (FAR uint8_t*)loadinfo->elfalloc;
-
- for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
- {
- FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
-
- /* SHF_ALLOC indicates that the section requires memory during
- * execution */
-
- if ((shdr->sh_flags & SHF_ALLOC) == 0)
- {
- continue;
- }
-
- /* SHT_NOBITS indicates that there is no data in the file for the
- * section.
- */
-
- if (shdr->sh_type != SHT_NOBITS)
- {
- /* If CONFIG_ADDRENV=y, then 'dest' lies in a virtual address space
- * that may not be in place now. elf_addrenv_select() will
- * temporarily instantiate that address space.
- */
-
-#ifdef CONFIG_ADDRENV
- ret = elf_addrenv_select(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: elf_addrenv_select() failed: %d\n", ret);
- return ret;
- }
-#endif
-
- /* Read the section data from sh_offset to dest */
-
- ret = elf_read(loadinfo, dest, shdr->sh_size, shdr->sh_offset);
- if (ret < 0)
- {
- bdbg("Failed to read section %d: %d\n", i, ret);
- return ret;
- }
-
- /* Restore the original address environment */
-
-#ifdef CONFIG_ADDRENV
- ret = elf_addrenv_restore(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: elf_addrenv_restore() failed: %d\n", ret);
- return ret;
- }
-#endif
- }
-
- /* Update sh_addr to point to copy in memory */
-
- bvdbg("%d. %08x->%08x\n", i, (long)shdr->sh_addr, (long)dest);
- shdr->sh_addr = (uintptr_t)dest;
-
- /* Setup the memory pointer for the next time through the loop */
-
- dest += ELF_ALIGNUP(shdr->sh_size);
- }
-
- return OK;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_load
- *
- * Description:
- * Loads the binary into memory, allocating memory, performing relocations
- * and inializing the data and bss segments.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_load(FAR struct elf_loadinfo_s *loadinfo)
-{
- int ret;
-
- bvdbg("loadinfo: %p\n", loadinfo);
- DEBUGASSERT(loadinfo && loadinfo->filfd >= 0);
-
- /* Load section headers into memory */
-
- ret = elf_loadshdrs(loadinfo);
- if (ret < 0)
- {
- bdbg("elf_loadshdrs failed: %d\n", ret);
- goto errout_with_buffers;
- }
-
- /* Determine total size to allocate */
-
- elf_elfsize(loadinfo);
-
- /* Allocate memory and load sections into memory */
-
- ret = elf_loadfile(loadinfo);
- if (ret < 0)
- {
- bdbg("elf_loadfile failed: %d\n", ret);
- goto errout_with_buffers;
- }
-
- /* Load static constructors and destructors. */
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
- ret = elf_loadctors(loadinfo);
- if (ret < 0)
- {
- bdbg("elf_loadctors failed: %d\n", ret);
- goto errout_with_buffers;
- }
-
- ret = elf_loaddtors(loadinfo);
- if (ret < 0)
- {
- bdbg("elf_loaddtors failed: %d\n", ret);
- goto errout_with_buffers;
- }
-#endif
-
- return OK;
-
- /* Error exits */
-
-errout_with_buffers:
- elf_unload(loadinfo);
- return ret;
-}
-
diff --git a/nuttx/binfmt/libelf/libelf_read.c b/nuttx/binfmt/libelf/libelf_read.c
deleted file mode 100644
index 25ee7ba29..000000000
--- a/nuttx/binfmt/libelf/libelf_read.c
+++ /dev/null
@@ -1,165 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_read.c
- *
- * Copyright (C) 2012 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 <sys/types.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <string.h>
-#include <elf32.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/elf.h>
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-#undef ELF_DUMP_READDATA /* Define to dump all file data read */
-#define DUMPER syslog /* If ELF_DUMP_READDATA is defined, this
- * is the API used to dump data */
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_dumpreaddata
- ****************************************************************************/
-
-#if defined(ELF_DUMP_READDATA)
-static inline void elf_dumpreaddata(char *buffer, int buflen)
-{
- uint32_t *buf32 = (uint32_t*)buffer;
- int i;
- int j;
-
- for (i = 0; i < buflen; i += 32)
- {
- DUMPER("%04x:", i);
- for (j = 0; j < 32; j += sizeof(uint32_t))
- {
- DUMPER(" %08x", *buf32++);
- }
- DUMPER("\n");
- }
-}
-#else
-# define elf_dumpreaddata(b,n)
-#endif
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_read
- *
- * Description:
- * Read 'readsize' bytes from the object file at 'offset'. The data is
- * read into 'buffer.' If 'buffer' is part of the ELF address environment,
- * then the caller is responsibile for assuring that that address
- * environment is in place before calling this function (i.e., that
- * elf_addrenv_select() has been called if CONFIG_ADDRENV=y).
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
- size_t readsize, off_t offset)
-{
- ssize_t nbytes; /* Number of bytes read */
- off_t rpos; /* Position returned by lseek */
-
- bvdbg("Read %ld bytes from offset %ld\n", (long)readsize, (long)offset);
-
- /* Loop until all of the requested data has been read. */
-
- while (readsize > 0)
- {
- /* Seek to the next read position */
-
- rpos = lseek(loadinfo->filfd, offset, SEEK_SET);
- if (rpos != offset)
- {
- int errval = errno;
- bdbg("Failed to seek to position %ld: %d\n", (long)offset, errval);
- return -errval;
- }
-
- /* Read the file data at offset into the user buffer */
-
- nbytes = read(loadinfo->filfd, buffer, readsize);
- if (nbytes < 0)
- {
- int errval = errno;
-
- /* EINTR just means that we received a signal */
-
- if (errval != EINTR)
- {
- bdbg("Read of .data failed: %d\n", errval);
- return -errval;
- }
- }
- else if (nbytes == 0)
- {
- bdbg("Unexpected end of file\n");
- return -ENODATA;
- }
- else
- {
- readsize -= nbytes;
- buffer += nbytes;
- offset += nbytes;
- }
- }
-
- elf_dumpreaddata(buffer, readsize);
- return OK;
-}
diff --git a/nuttx/binfmt/libelf/libelf_sections.c b/nuttx/binfmt/libelf/libelf_sections.c
deleted file mode 100644
index c41793544..000000000
--- a/nuttx/binfmt/libelf/libelf_sections.c
+++ /dev/null
@@ -1,284 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_sections.c
- *
- * Copyright (C) 2012 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 <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
-#include <debug.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/elf.h>
-
-#include "libelf.h"
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_sectname
- *
- * Description:
- * Get the symbol name in loadinfo->iobuffer[].
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static inline int elf_sectname(FAR struct elf_loadinfo_s *loadinfo,
- FAR const Elf32_Shdr *shdr)
-{
- FAR Elf32_Shdr *shstr;
- FAR uint8_t *buffer;
- off_t offset;
- size_t readlen;
- size_t bytesread;
- int shstrndx;
- int ret;
-
- /* Get the section header table index of the entry associated with the
- * section name string table. If the file has no section name string table,
- * this member holds the value SH_UNDEF.
- */
-
- shstrndx = loadinfo->ehdr.e_shstrndx;
- if (shstrndx == SHN_UNDEF)
- {
- bdbg("No section header string table\n");
- return -EINVAL;
- }
-
- /* Get the section name string table section header */
-
- shstr = &loadinfo->shdr[shstrndx];
-
- /* Get the file offset to the string that is the name of the section. This
- * is the sum of:
- *
- * shstr->sh_offset: The file offset to the first byte of the section
- * header string table data.
- * shdr->sh_name: The offset to the name of the section in the section
- * name table
- */
-
- offset = shstr->sh_offset + shdr->sh_name;
-
- /* Loop until we get the entire section name into memory */
-
- buffer = loadinfo->iobuffer;
- bytesread = 0;
-
- for (;;)
- {
- /* Get the number of bytes to read */
-
- readlen = loadinfo->buflen - bytesread;
- if (offset + readlen > loadinfo->filelen)
- {
- readlen = loadinfo->filelen - offset;
- if (readlen <= 0)
- {
- bdbg("At end of file\n");
- return -EINVAL;
- }
- }
-
- /* Read that number of bytes into the array */
-
- buffer = &loadinfo->iobuffer[bytesread];
- ret = elf_read(loadinfo, buffer, readlen, offset);
- if (ret < 0)
- {
- bdbg("Failed to read section name\n");
- return ret;
- }
-
- bytesread += readlen;
-
- /* Did we read the NUL terminator? */
-
- if (memchr(buffer, '\0', readlen) != NULL)
- {
- /* Yes, the buffer contains a NUL terminator. */
-
- return OK;
- }
-
- /* No.. then we have to read more */
-
- ret = elf_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR);
- if (ret < 0)
- {
- bdbg("elf_reallocbuffer failed: %d\n", ret);
- return ret;
- }
- }
-
- /* We will not get here */
-
- return OK;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_loadshdrs
- *
- * Description:
- * Loads section headers into memory.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_loadshdrs(FAR struct elf_loadinfo_s *loadinfo)
-{
- size_t shdrsize;
- int ret;
-
- DEBUGASSERT(loadinfo->shdr == NULL);
-
- /* Verify that there are sections */
-
- if (loadinfo->ehdr.e_shnum < 1)
- {
- bdbg("No sections(?)\n");
- return -EINVAL;
- }
-
- /* Get the total size of the section header table */
-
- shdrsize = (size_t)loadinfo->ehdr.e_shentsize * (size_t)loadinfo->ehdr.e_shnum;
- if(loadinfo->ehdr.e_shoff + shdrsize > loadinfo->filelen)
- {
- bdbg("Insufficent space in file for section header table\n");
- return -ESPIPE;
- }
-
- /* Allocate memory to hold a working copy of the sector header table */
-
- loadinfo->shdr = (FAR Elf32_Shdr*)kmalloc(shdrsize);
- if (!loadinfo->shdr)
- {
- bdbg("Failed to allocate the section header table. Size: %ld\n", (long)shdrsize);
- return -ENOMEM;
- }
-
- /* Read the section header table into memory */
-
- ret = elf_read(loadinfo, (FAR uint8_t*)loadinfo->shdr, shdrsize, loadinfo->ehdr.e_shoff);
- if (ret < 0)
- {
- bdbg("Failed to read section header table: %d\n", ret);
- }
-
- return ret;
-}
-
-/****************************************************************************
- * Name: elf_findsection
- *
- * Description:
- * A section by its name.
- *
- * Input Parameters:
- * loadinfo - Load state information
- * sectname - Name of the section to find
- *
- * Returned Value:
- * On success, the index to the section is returned; A negated errno value
- * is returned on failure.
- *
- ****************************************************************************/
-
-int elf_findsection(FAR struct elf_loadinfo_s *loadinfo,
- FAR const char *sectname)
-{
- FAR const Elf32_Shdr *shdr;
- int ret;
- int i;
-
- /* Search through the shdr[] array in loadinfo for a section named 'sectname' */
-
- for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
- {
- /* Get the name of this section */
-
- shdr = &loadinfo->shdr[i];
- ret = elf_sectname(loadinfo, shdr);
- if (ret < 0)
- {
- bdbg("elf_sectname failed: %d\n", ret);
- return ret;
- }
-
- /* Check if the name of this section is 'sectname' */
-
- bvdbg("%d. Comparing \"%s\" and .\"%s\"\n",
- i, loadinfo->iobuffer, sectname);
-
- if (strcmp((FAR const char *)loadinfo->iobuffer, sectname) == 0)
- {
- /* We found it... return the index */
-
- return i;
- }
- }
-
- /* We failed to find a section with this name. */
-
- return -ENOENT;
-}
diff --git a/nuttx/binfmt/libelf/libelf_symbols.c b/nuttx/binfmt/libelf/libelf_symbols.c
deleted file mode 100644
index 2d94b11af..000000000
--- a/nuttx/binfmt/libelf/libelf_symbols.c
+++ /dev/null
@@ -1,329 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_symbols.c
- *
- * Copyright (C) 2012 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 <stdlib.h>
-#include <string.h>
-#include <elf32.h>
-#include <errno.h>
-#include <debug.h>
-
-#include <nuttx/binfmt/elf.h>
-#include <nuttx/binfmt/symtab.h>
-
-#include "libelf.h"
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-#ifndef CONFIG_ELF_BUFFERINCR
-# define CONFIG_ELF_BUFFERINCR 32
-#endif
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_symname
- *
- * Description:
- * Get the symbol name in loadinfo->iobuffer[].
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static int elf_symname(FAR struct elf_loadinfo_s *loadinfo,
- FAR const Elf32_Sym *sym)
-{
- FAR uint8_t *buffer;
- off_t offset;
- size_t readlen;
- size_t bytesread;
- int ret;
-
- /* Get the file offset to the string that is the name of the symbol. The
- * st_name member holds an offset into the file's symbol string table.
- */
-
- if (sym->st_name == 0)
- {
- bdbg("Symbol has no name\n");
- return -ENOENT;
- }
-
- offset = loadinfo->shdr[loadinfo->strtabidx].sh_offset + sym->st_name;
-
- /* Loop until we get the entire symbol name into memory */
-
- bytesread = 0;
-
- for (;;)
- {
- /* Get the number of bytes to read */
-
- readlen = loadinfo->buflen - bytesread;
- if (offset + readlen > loadinfo->filelen)
- {
- readlen = loadinfo->filelen - offset;
- if (readlen <= 0)
- {
- bdbg("At end of file\n");
- return -EINVAL;
- }
- }
-
- /* Read that number of bytes into the array */
-
- buffer = &loadinfo->iobuffer[bytesread];
- ret = elf_read(loadinfo, buffer, readlen, offset);
- if (ret < 0)
- {
- bdbg("elf_read failed: %d\n", ret);
- return ret;
- }
-
- bytesread += readlen;
-
- /* Did we read the NUL terminator? */
-
- if (memchr(buffer, '\0', readlen) != NULL)
- {
- /* Yes, the buffer contains a NUL terminator. */
-
- return OK;
- }
-
- /* No.. then we have to read more */
-
- ret = elf_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR);
- if (ret < 0)
- {
- bdbg("elf_reallocbuffer failed: %d\n", ret);
- return ret;
- }
- }
-
- /* We will not get here */
-
- return OK;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_findsymtab
- *
- * Description:
- * Find the symbol table section.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_findsymtab(FAR struct elf_loadinfo_s *loadinfo)
-{
- int i;
-
- /* Find the symbol table section header and its associated string table */
-
- for (i = 1; i < loadinfo->ehdr.e_shnum; i++)
- {
- if (loadinfo->shdr[i].sh_type == SHT_SYMTAB)
- {
- loadinfo->symtabidx = i;
- loadinfo->strtabidx = loadinfo->shdr[i].sh_link;
- break;
- }
- }
-
- /* Verify that there is a symbol and string table */
-
- if (loadinfo->symtabidx == 0)
- {
- bdbg("No symbols in ELF file\n");
- return -EINVAL;
- }
-
- return OK;
-}
-
-/****************************************************************************
- * Name: elf_readsym
- *
- * Description:
- * Read the ELFT symbol structure at the specfied index into memory.
- *
- * Input Parameters:
- * loadinfo - Load state information
- * index - Symbol table index
- * sym - Location to return the table entry
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_readsym(FAR struct elf_loadinfo_s *loadinfo, int index,
- FAR Elf32_Sym *sym)
-{
- FAR Elf32_Shdr *symtab = &loadinfo->shdr[loadinfo->symtabidx];
- off_t offset;
-
- /* Verify that the symbol table index lies within symbol table */
-
- if (index < 0 || index > (symtab->sh_size / sizeof(Elf32_Sym)))
- {
- bdbg("Bad relocation symbol index: %d\n", index);
- return -EINVAL;
- }
-
- /* Get the file offset to the symbol table entry */
-
- offset = symtab->sh_offset + sizeof(Elf32_Sym) * index;
-
- /* And, finally, read the symbol table entry into memory */
-
- return elf_read(loadinfo, (FAR uint8_t*)sym, sizeof(Elf32_Sym), offset);
-}
-
-/****************************************************************************
- * Name: elf_symvalue
- *
- * Description:
- * Get the value of a symbol. The updated value of the symbol is returned
- * in the st_value field of the symbol table entry.
- *
- * Input Parameters:
- * loadinfo - Load state information
- * sym - Symbol table entry (value might be undefined)
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_symvalue(FAR struct elf_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
- FAR const struct symtab_s *exports, int nexports)
-{
- FAR const struct symtab_s *symbol;
- uintptr_t secbase;
- int ret;
-
- switch (sym->st_shndx)
- {
- case SHN_COMMON:
- {
- /* NuttX ELF modules should be compiled with -fno-common. */
-
- bdbg("SHN_COMMON: Re-compile with -fno-common\n");
- return -EINVAL;
- }
-
- case SHN_ABS:
- {
- /* st_value already holds the correct value */
-
- bvdbg("SHN_ABS: st_value=%08lx\n", (long)sym->st_value);
- return OK;
- }
-
- case SHN_UNDEF:
- {
- /* Get the name of the undefined symbol */
-
- ret = elf_symname(loadinfo, sym);
- if (ret < 0)
- {
- bdbg("SHN_UNDEF: Failed to get symbol name: %d\n", ret);
- return ret;
- }
-
- /* Check if the base code exports a symbol of this name */
-
-#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
- symbol = symtab_findorderedbyname(exports, (FAR char *)loadinfo->iobuffer, nexports);
-#else
- symbol = symtab_findbyname(exports, (FAR char *)loadinfo->iobuffer, nexports);
-#endif
- if (!symbol)
- {
- bdbg("SHN_UNDEF: Exported symbol \"%s\" not found\n", loadinfo->iobuffer);
- return -ENOENT;
- }
-
- /* Yes... add the exported symbol value to the ELF symbol table entry */
-
- bvdbg("SHN_ABS: name=%s %08x+%08x=%08x\n",
- loadinfo->iobuffer, sym->st_value, symbol->sym_value,
- sym->st_value + symbol->sym_value);
-
- sym->st_value += (Elf32_Word)((uintptr_t)symbol->sym_value);
- }
- break;
-
- default:
- {
- secbase = loadinfo->shdr[sym->st_shndx].sh_addr;
-
- bvdbg("Other: %08x+%08x=%08x\n",
- sym->st_value, secbase, sym->st_value + secbase);
-
- sym->st_value += secbase;
- }
- break;
- }
-
- return OK;
-}
diff --git a/nuttx/binfmt/libelf/libelf_uninit.c b/nuttx/binfmt/libelf/libelf_uninit.c
deleted file mode 100644
index 3ec6f6c61..000000000
--- a/nuttx/binfmt/libelf/libelf_uninit.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_uninit.c
- *
- * Copyright (C) 2012 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 <unistd.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/elf.h>
-
-#include "libelf.h"
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_uninit
- *
- * Description:
- * Releases any resources committed by elf_init(). This essentially
- * undoes the actions of elf_init.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_uninit(struct elf_loadinfo_s *loadinfo)
-{
- /* Free all working buffers */
-
- elf_freebuffers(loadinfo);
-
- /* Close the ELF file */
-
- if (loadinfo->filfd >= 0)
- {
- close(loadinfo->filfd);
- }
-
- return OK;
-}
-
-/****************************************************************************
- * Name: elf_freebuffers
- *
- * Description:
- * Release all working buffers.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_freebuffers(struct elf_loadinfo_s *loadinfo)
-{
- /* Release all working allocations */
-
- if (loadinfo->shdr)
- {
- kfree((FAR void *)loadinfo->shdr);
- loadinfo->shdr = NULL;
- }
-
- if (loadinfo->iobuffer)
- {
- kfree((FAR void *)loadinfo->iobuffer);
- loadinfo->iobuffer = NULL;
- loadinfo->buflen = 0;
- }
-
- return OK;
-}
diff --git a/nuttx/binfmt/libelf/libelf_unload.c b/nuttx/binfmt/libelf/libelf_unload.c
deleted file mode 100644
index 539e5faf7..000000000
--- a/nuttx/binfmt/libelf/libelf_unload.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/libelf_unload.c
- *
- * Copyright (C) 2012 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 <stdlib.h>
-#include <debug.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/elf.h>
-
-#include "libelf.h"
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_unload
- *
- * Description:
- * This function unloads the object from memory. This essentially undoes
- * the actions of elf_load. It is called only under certain error
- * conditions after the the module has been loaded but not yet started.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int elf_unload(struct elf_loadinfo_s *loadinfo)
-{
- /* Free all working buffers */
-
- elf_freebuffers(loadinfo);
-
- /* Release memory holding the relocated ELF image */
-
- elf_addrenv_free(loadinfo);
-
- /* Release memory used to hold static constructors and destructors */
-
-#ifdef CONFIG_BINFMT_CONSTRUCTORS
- if (loadinfo->ctoralloc != 0)
- {
- kfree(loadinfo->ctoralloc);
- loadinfo->ctoralloc = NULL;
- }
-
- loadinfo->ctors = NULL;
- loadinfo->nctors = 0;
-
- if (loadinfo->dtoralloc != 0)
- {
- kfree(loadinfo->dtoralloc);
- loadinfo->dtoralloc = NULL;
- }
-
- loadinfo->dtors = NULL;
- loadinfo->ndtors = 0;
-#endif
-
- return OK;
-}
-
diff --git a/nuttx/binfmt/libelf/libelf_verify.c b/nuttx/binfmt/libelf/libelf_verify.c
deleted file mode 100644
index c5f185ec3..000000000
--- a/nuttx/binfmt/libelf/libelf_verify.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************************
- * binfmt/libelf/elf_verify.c
- *
- * Copyright (C) 2012 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 <string.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/elf.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-static const char g_elfmagic[EI_MAGIC_SIZE] = { 0x7f, 'E', 'L', 'F' };
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: elf_verifyheader
- *
- * Description:
- * Given the header from a possible ELF executable, verify that it
- * is an ELF executable.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- * -ENOEXEC : Not an ELF file
- * -EINVAL : Not a relocatable ELF file or not supported by the current,
- * configured architecture.
- *
- ****************************************************************************/
-
-int elf_verifyheader(FAR const Elf32_Ehdr *ehdr)
-{
- if (!ehdr)
- {
- bdbg("NULL ELF header!");
- return -ENOEXEC;
- }
-
- /* Verify that the magic number indicates an ELF file */
-
- if (memcmp(ehdr->e_ident, g_elfmagic, EI_MAGIC_SIZE) != 0)
- {
- bvdbg("Not ELF magic {%02x, %02x, %02x, %02x}\n",
- ehdr->e_ident[0], ehdr->e_ident[1], ehdr->e_ident[2], ehdr->e_ident[3]);
- return -ENOEXEC;
- }
-
- /* Verify that this is a relocatable file */
-
- if (ehdr->e_type != ET_REL)
- {
- bdbg("Not a relocatable file: e_type=%d\n", ehdr->e_type);
- return -EINVAL;
- }
-
- /* Verify that this file works with the currently configured architecture */
-
- if (arch_checkarch(ehdr))
- {
- bdbg("Not a supported architecture\n");
- return -ENOEXEC;
- }
-
- /* Looks good so far... we still might find some problems later. */
-
- return OK;
-}
-
diff --git a/nuttx/binfmt/libnxflat/Kconfig b/nuttx/binfmt/libnxflat/Kconfig
deleted file mode 100644
index fdb270cfb..000000000
--- a/nuttx/binfmt/libnxflat/Kconfig
+++ /dev/null
@@ -1,9 +0,0 @@
-#
-# For a description of the syntax of this configuration file,
-# see misc/tools/kconfig-language.txt.
-#
-
-config NXFLAT_DUMPBUFFER
- bool "Dump NXFLAT buffers"
- default n
- depends on DEBUG && DEBUG_VERBOSE
diff --git a/nuttx/binfmt/libnxflat/Make.defs b/nuttx/binfmt/libnxflat/Make.defs
deleted file mode 100644
index 6a0bf1873..000000000
--- a/nuttx/binfmt/libnxflat/Make.defs
+++ /dev/null
@@ -1,54 +0,0 @@
-############################################################################
-# binfmt/libnxflat/Make.defs
-#
-# Copyright (C) 2009 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.
-#
-############################################################################
-
-ifeq ($(CONFIG_NXFLAT),y)
-
-# NXFLAT application interfaces
-
-BINFMT_CSRCS += nxflat.c
-
-# NXFLAT library
-
-BINFMT_CSRCS += libnxflat_init.c libnxflat_uninit.c libnxflat_addrenv.c
-BINFMT_CSRCS += libnxflat_load.c libnxflat_unload.c libnxflat_verify.c
-BINFMT_CSRCS += libnxflat_read.c libnxflat_bind.c
-
-# Hook the libnxflat subdirectory into the build
-
-VPATH += libnxflat
-SUBDIRS += libnxflat
-DEPPATH += --dep-path libnxflat
-
-endif
diff --git a/nuttx/binfmt/libnxflat/gnu-nxflat-gotoff.ld b/nuttx/binfmt/libnxflat/gnu-nxflat-gotoff.ld
deleted file mode 100644
index 47debd663..000000000
--- a/nuttx/binfmt/libnxflat/gnu-nxflat-gotoff.ld
+++ /dev/null
@@ -1,187 +0,0 @@
-/****************************************************************************
- * examples/nxflat/gnu-nxflat-gotoff.ld
- *
- * Copyright (C) 2009, 2012 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.
- *
- ****************************************************************************/
-
-MEMORY
-{
- ISPACE : ORIGIN = 0x0, LENGTH = 2097152
- DSPACE : ORIGIN = 0x0, LENGTH = 2097152
-}
-
-/****************************************************************************
- * The XFLAT program image is divided into two segments:
- *
- * (1) ISpace (Instruction Space). This is the segment that contains
- * code (.text). Everything in the segment should be fetch-able
- * machine PC instructions (jump, branch, call, etc.).
- * (2) DSpace (Data Space). This is the segment that contains both
- * read-write data (.data, .bss) as well as read-only data (.rodata).
- * Everything in this segment should be access-able with machine
- * PIC load and store instructions.
- *
- * Older versions of GCC (at least up to GCC 4.3.3), use GOT-relative
- * addressing to access RO data. In that case, read-only data (.rodata) must
- * reside in D-Space and this linker script should be used.
- *
- * Newer versions of GCC (at least as of GCC 4.6.3), use PC-relative
- * addressing to access RO data. In that case, read-only data (.rodata) must
- * reside in I-Space and this linker script should NOT be used with those
- * newer tools.
- *
- ****************************************************************************/
-
-SECTIONS
-{
- .text 0x00000000 :
- {
- /* ISpace is located at address 0. Every (unrelocated) ISpace
- * address is an offset from the begining of this segment.
- */
-
- text_start = . ;
-
- *(.text)
- *(.text.*)
- *(.gnu.warning)
- *(.stub)
- *(.glue_7)
- *(.glue_7t)
- *(.jcr)
-
- /* C++ support: The .init and .fini sections contain XFLAT-
- * specific logic to manage static constructors and destructors.
- */
-
- *(.gnu.linkonce.t.*)
- *(.init)
- *(.fini)
-
- /* This is special code area at the end of the normal
- text section. It contains a small lookup table at
- the start followed by the code pointed to by entries
- in the lookup table. */
-
- . = ALIGN (4) ;
- PROVIDE(__ctbp = .);
- *(.call_table_data)
- *(.call_table_text)
-
- _etext = . ;
-
- } > ISPACE
-
- /* DSpace is also located at address 0. Every (unrelocated) DSpace
- * address is an offset from the begining of this segment.
- */
-
- .data 0x00000000 :
- {
- /* In this model, .rodata is access using PC-relative addressing
- * and, hence, must also reside in the .text section.
- */
-
- __data_start = . ;
- *(.rodata)
- *(.rodata1)
- *(.rodata.*)
- *(.gnu.linkonce.r*)
-
- *(.data)
- *(.data1)
- *(.data.*)
- *(.gnu.linkonce.d*)
- *(.data1)
- *(.eh_frame)
- *(.gcc_except_table)
-
- *(.gnu.linkonce.s.*)
- *(__libc_atexit)
- *(__libc_subinit)
- *(__libc_subfreeres)
- *(.note.ABI-tag)
-
- /* C++ support. For each global and static local C++ object,
- * GCC creates a small subroutine to construct the object. Pointers
- * to these routines (not the routines themselves) are stored as
- * simple, linear arrays in the .ctors section of the object file.
- * Similarly, pointers to global/static destructor routines are
- * stored in .dtors.
- */
-
- *(.gnu.linkonce.d.*)
-
- _ctors_start = . ;
- *(.ctors)
- _ctors_end = . ;
- _dtors_start = . ;
- *(.dtors)
- _dtors_end = . ;
-
- _edata = . ;
- edata = ALIGN( 0x10 ) ;
- } > DSPACE
-
- .bss :
- {
- __bss_start = _edata ;
- *(.dynsbss)
- *(.sbss)
- *(.sbss.*)
- *(.scommon)
- *(.dynbss)
- *(.bss)
- *(.bss.*)
- *(.bss*)
- *(.gnu.linkonce.b*)
- *(COMMON)
- end = ALIGN( 0x10 ) ;
- _end = ALIGN( 0x10 ) ;
- } > DSPACE
-
- .got 0 : { *(.got.plt) *(.got) }
- .junk 0 : { *(.rel*) *(.rela*) }
- /* Stabs debugging sections. */
- .stab 0 : { *(.stab) }
- .stabstr 0 : { *(.stabstr) }
- .stab.excl 0 : { *(.stab.excl) }
- .stab.exclstr 0 : { *(.stab.exclstr) }
- .stab.index 0 : { *(.stab.index) }
- .stab.indexstr 0 : { *(.stab.indexstr) }
- .comment 0 : { *(.comment) }
- .debug_abbrev 0 : { *(.debug_abbrev) }
- .debug_info 0 : { *(.debug_info) }
- .debug_line 0 : { *(.debug_line) }
- .debug_pubnames 0 : { *(.debug_pubnames) }
- .debug_aranges 0 : { *(.debug_aranges) }
-}
diff --git a/nuttx/binfmt/libnxflat/gnu-nxflat-pcrel.ld b/nuttx/binfmt/libnxflat/gnu-nxflat-pcrel.ld
deleted file mode 100644
index 71e4399ba..000000000
--- a/nuttx/binfmt/libnxflat/gnu-nxflat-pcrel.ld
+++ /dev/null
@@ -1,187 +0,0 @@
-/****************************************************************************
- * examples/nxflat/gnu-nxflat-pcrel.ld
- *
- * Copyright (C) 2012 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.
- *
- ****************************************************************************/
-
-MEMORY
-{
- ISPACE : ORIGIN = 0x0, LENGTH = 2097152
- DSPACE : ORIGIN = 0x0, LENGTH = 2097152
-}
-
-/****************************************************************************
- * The XFLAT program image is divided into two segments:
- *
- * (1) ISpace (Instruction Space). This is the segment that contains
- * code (.text) as well as read-only data (.rodata). Everything in the
- * segment should be fetch-able machine PC instructions (jump, branch,
- * call, etc.) or PC-relative loads.
- * (2) DSpace (Data Space). This is the segment that contains read-write
- * data (.data, .bss). Everything in this segment should be access-able
- * with machine PIC load and store instructions.
- *
- * Older versions of GCC (at least up to GCC 4.3.3), use GOT-relative
- * addressing to access RO data. In that case, read-only data (.rodata) must
- * reside in D-Space and this linker script should NOT be used with those
- * older tools.
- *
- * Newer versions of GCC (at least as of GCC 4.6.3), use PC-relative
- * addressing to access RO data. In that case, read-only data (.rodata) must
- * reside in I-Space and this linker script should be used.
- *
- ****************************************************************************/
-
-SECTIONS
-{
- .text 0x00000000 :
- {
- /* ISpace is located at address 0. Every (unrelocated) ISpace
- * address is an offset from the begining of this segment.
- */
-
- text_start = . ;
-
- *(.text)
- *(.text.*)
- *(.gnu.warning)
- *(.stub)
- *(.glue_7)
- *(.glue_7t)
- *(.jcr)
-
- /* C++ support: The .init and .fini sections contain XFLAT-
- * specific logic to manage static constructors and destructors.
- */
-
- *(.gnu.linkonce.t.*)
- *(.init)
- *(.fini)
-
- /* This is special code area at the end of the normal
- text section. It contains a small lookup table at
- the start followed by the code pointed to by entries
- in the lookup table. */
-
- . = ALIGN (4) ;
- PROVIDE(__ctbp = .);
- *(.call_table_data)
- *(.call_table_text)
-
- /* In this model, .rodata is access using PC-relative addressing
- * and, hence, must also reside in the .text section.
- */
-
- *(.rodata)
- *(.rodata1)
- *(.rodata.*)
- *(.gnu.linkonce.r*)
-
- _etext = . ;
-
- } > ISPACE
-
- /* DSpace is also located at address 0. Every (unrelocated) DSpace
- * address is an offset from the begining of this segment.
- */
-
- .data 0x00000000 :
- {
- __data_start = . ;
- *(.data)
- *(.data1)
- *(.data.*)
- *(.gnu.linkonce.d*)
- *(.data1)
- *(.eh_frame)
- *(.gcc_except_table)
-
- *(.gnu.linkonce.s.*)
- *(__libc_atexit)
- *(__libc_subinit)
- *(__libc_subfreeres)
- *(.note.ABI-tag)
-
- /* C++ support. For each global and static local C++ object,
- * GCC creates a small subroutine to construct the object. Pointers
- * to these routines (not the routines themselves) are stored as
- * simple, linear arrays in the .ctors section of the object file.
- * Similarly, pointers to global/static destructor routines are
- * stored in .dtors.
- */
-
- *(.gnu.linkonce.d.*)
-
- _ctors_start = . ;
- *(.ctors)
- _ctors_end = . ;
- _dtors_start = . ;
- *(.dtors)
- _dtors_end = . ;
-
- _edata = . ;
- edata = ALIGN( 0x10 ) ;
- } > DSPACE
-
- .bss :
- {
- __bss_start = _edata ;
- *(.dynsbss)
- *(.sbss)
- *(.sbss.*)
- *(.scommon)
- *(.dynbss)
- *(.bss)
- *(.bss.*)
- *(.bss*)
- *(.gnu.linkonce.b*)
- *(COMMON)
- end = ALIGN( 0x10 ) ;
- _end = ALIGN( 0x10 ) ;
- } > DSPACE
-
- .got 0 : { *(.got.plt) *(.got) }
- .junk 0 : { *(.rel*) *(.rela*) }
- /* Stabs debugging sections. */
- .stab 0 : { *(.stab) }
- .stabstr 0 : { *(.stabstr) }
- .stab.excl 0 : { *(.stab.excl) }
- .stab.exclstr 0 : { *(.stab.exclstr) }
- .stab.index 0 : { *(.stab.index) }
- .stab.indexstr 0 : { *(.stab.indexstr) }
- .comment 0 : { *(.comment) }
- .debug_abbrev 0 : { *(.debug_abbrev) }
- .debug_info 0 : { *(.debug_info) }
- .debug_line 0 : { *(.debug_line) }
- .debug_pubnames 0 : { *(.debug_pubnames) }
- .debug_aranges 0 : { *(.debug_aranges) }
-}
diff --git a/nuttx/binfmt/libnxflat/libnxflat.h b/nuttx/binfmt/libnxflat/libnxflat.h
deleted file mode 100644
index cb1cb7057..000000000
--- a/nuttx/binfmt/libnxflat/libnxflat.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/****************************************************************************
- * binfmt/libnxflat/libnxflat.h
- *
- * Copyright (C) 2012 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 __BINFMT_LIBNXFLAT_LIBNXFLAT_H
-#define __BINFMT_LIBNXFLAT_LIBNXFLAT_H
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-
-#include <nuttx/arch.h>
-#include <nuttx/binfmt/nxflat.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Types
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_addrenv_alloc
- *
- * Description:
- * Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
- * elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
- * elfalloc will be allocated using up_addrenv_create(). In either case,
- * there will be a unique instance of elfalloc (and stack) for each
- * instance of a process.
- *
- * Input Parameters:
- * loadinfo - Load state information
- * envsize - The size (in bytes) of the address environment needed for the
- * ELF image.
- *
- * Returned Value:
- * Zero (OK) on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-int nxflat_addrenv_alloc(FAR struct nxflat_loadinfo_s *loadinfo, size_t envsize);
-
-/****************************************************************************
- * Name: nxflat_addrenv_select
- *
- * Description:
- * Temporarity select the task's address environemnt.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * Zero (OK) on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_ADDRENV
-# define nxflat_addrenv_select(l) up_addrenv_select((l)->addrenv, &(l)->oldenv)
-#endif
-
-/****************************************************************************
- * Name: nxflat_addrenv_restore
- *
- * Description:
- * Restore the address environment before nxflat_addrenv_select() was called..
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * Zero (OK) on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_ADDRENV
-# define nxflat_addrenv_restore(l) up_addrenv_restore((l)->oldenv)
-#endif
-
-/****************************************************************************
- * Name: nxflat_addrenv_free
- *
- * Description:
- * Release the address environment previously created by
- * nxflat_addrenv_create(). This function is called only under certain
- * error conditions after the the module has been loaded but not yet
- * started. After the module has been started, the address environment
- * will automatically be freed when the module exits.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * None.
- *
- ****************************************************************************/
-
-void nxflat_addrenv_free(FAR struct nxflat_loadinfo_s *loadinfo);
-
-#endif /* __BINFMT_LIBNXFLAT_LIBNXFLAT_H */
diff --git a/nuttx/binfmt/libnxflat/libnxflat_addrenv.c b/nuttx/binfmt/libnxflat/libnxflat_addrenv.c
deleted file mode 100644
index 2d9255b28..000000000
--- a/nuttx/binfmt/libnxflat/libnxflat_addrenv.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/****************************************************************************
- * binfmt/libnxflat/libnxflat_addrenv.c
- *
- * Copyright (C) 2012 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 <string.h>
-#include <errno.h>
-#include <debug.h>
-
-#include <nuttx/arch.h>
-#include <nuttx/kmalloc.h>
-
-#include "libnxflat.h"
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_addrenv_alloc
- *
- * Description:
- * Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
- * elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
- * elfalloc will be allocated using up_addrenv_create(). In either case,
- * there will be a unique instance of elfalloc (and stack) for each
- * instance of a process.
- *
- * Input Parameters:
- * loadinfo - Load state information
- * envsize - The size (in bytes) of the address environment needed for the
- * ELF image.
- *
- * Returned Value:
- * Zero (OK) on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-int nxflat_addrenv_alloc(FAR struct nxflat_loadinfo_s *loadinfo, size_t envsize)
-{
- FAR struct dspace_s *dspace;
-#ifdef CONFIG_ADDRENV
- FAR void *vaddr;
- hw_addrenv_t oldenv;
- int ret;
-#endif
-
- DEBUGASSERT(!loadinfo->dspace);
-
- /* Allocate the struct dspace_s container for the D-Space allocation */
-
- dspace = (FAR struct dspace_s *)kmalloc(sizeof(struct dspace_s));
- if (dspace == 0)
- {
- bdbg("ERROR: Failed to allocate DSpace\n");
- return -ENOMEM;
- }
-
-#ifdef CONFIG_ADDRENV
- /* Create a D-Space address environment for the new NXFLAT task */
-
- ret = up_addrenv_create(envsize, &loadinfo->addrenv);
- if (ret < 0)
- {
- bdbg("ERROR: up_addrenv_create failed: %d\n", ret);
- goto errout_with_dspace;
- }
-
- /* Get the virtual address associated with the start of the address
- * environment. This is the base address that we will need to use to
- * access the D-Space region (but only if the address environment has been
- * selected.
- */
-
- ret = up_addrenv_vaddr(loadinfo->addrenv, &vaddr);
- if (ret < 0)
- {
- bdbg("ERROR: up_addrenv_vaddr failed: %d\n", ret);
- goto errout_with_addrenv;
- }
-
- /* Clear all of the allocated D-Space memory. We have to temporarily
- * selected the D-Space address environment to do this.
- */
-
- ret = up_addrenv_select(loadinfo->addrenv, &oldenv);
- if (ret < 0)
- {
- bdbg("ERROR: up_addrenv_select failed: %d\n", ret);
- goto errout_with_addrenv;
- }
-
- memset(vaddr, 0, envsize);
-
- ret = up_addrenv_restore(oldenv);
- if (ret < 0)
- {
- bdbg("ERROR: up_addrenv_restore failed: %d\n", ret);
- goto errout_with_addrenv;
- }
-
- /* Success... save the fruits of our labor */
-
- loadinfo->dspace = dspace;
- dspace->crefs = 1;
- dspace->region = (FAR uint8_t *)vaddr;
- return OK;
-
-errout_with_addrenv:
- (void)up_addrenv_destroy(loadinfo->addrenv);
- loadinfo->addrenv = 0;
-
-errout_with_dspace:
- kfree(dspace);
- return ret;
-#else
- /* Allocate (and zero) memory to hold the ELF image */
-
- dspace->region = (FAR uint8_t *)kzalloc(envsize);
- if (!dspace->region)
- {
- kfree(dspace);
- return -ENOMEM;
- }
-
- loadinfo->dspace = dspace;
- dspace->crefs = 1;
- return OK;
-#endif
-}
-
-/****************************************************************************
- * Name: nxflat_addrenv_free
- *
- * Description:
- * Release the address environment previously created by
- * nxflat_addrenv_create(). This function is called only under certain
- * error conditions after the the module has been loaded but not yet
- * started. After the module has been started, the address environment
- * will automatically be freed when the module exits.
- *
- * Input Parameters:
- * loadinfo - Load state information
- *
- * Returned Value:
- * None.
- *
- ****************************************************************************/
-
-void nxflat_addrenv_free(FAR struct nxflat_loadinfo_s *loadinfo)
-{
- FAR struct dspace_s *dspace;
-#ifdef CONFIG_ADDRENV
- int ret;
-#endif
-
- DEBUGASSERT(loadinfo);
- dspace = loadinfo->dspace;
-
- if (dspace)
- {
-#ifdef CONFIG_ADDRENV
- /* Destroy the address environment */
-
- ret = up_addrenv_destroy(loadinfo->addrenv);
- if (ret < 0)
- {
- bdbg("ERROR: up_addrenv_destroy failed: %d\n", ret);
- }
-
- loadinfo->addrenv = 0;
-#else
- /* Free the allocated D-Space region */
-
- if (dspace->region)
- {
- kfree(dspace->region);
- }
-#endif
-
- /* Now destroy the D-Space container */
-
- DEBUGASSERT(dspace->crefs == 1);
- kfree(dspace);
- loadinfo->dspace = NULL;
- }
-}
diff --git a/nuttx/binfmt/libnxflat/libnxflat_bind.c b/nuttx/binfmt/libnxflat/libnxflat_bind.c
deleted file mode 100644
index 816810a46..000000000
--- a/nuttx/binfmt/libnxflat/libnxflat_bind.c
+++ /dev/null
@@ -1,615 +0,0 @@
-/****************************************************************************
- * binfmt/libnxflat/libnxflat_bind.c
- *
- * Copyright (C) 2009 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 <nuttx/compiler.h>
-
-#include <stdint.h>
-#include <string.h>
-#include <nxflat.h>
-#include <errno.h>
-#include <assert.h>
-#include <debug.h>
-
-#include <arpa/inet.h>
-
-#include <nuttx/binfmt/nxflat.h>
-#include <nuttx/binfmt/symtab.h>
-
-#include "libnxflat.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
- * defined or CONFIG_NXFLAT_DUMPBUFFER does nothing.
- */
-
-#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
-# undef CONFIG_NXFLAT_DUMPBUFFER
-#endif
-
-#ifdef CONFIG_NXFLAT_DUMPBUFFER
-# define nxflat_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
-#else
-# define nxflat_dumpbuffer(m,b,n)
-#endif
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_bindrel32i
- *
- * Description:
- * Perform the NXFLAT_RELOC_TYPE_REL32I binding:
- *
- * Meaning: Object file contains a 32-bit offset into I-Space at the offset.
- * Fixup: Add mapped I-Space address to the offset.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static inline int nxflat_bindrel32i(FAR struct nxflat_loadinfo_s *loadinfo,
- uint32_t offset)
-{
- uint32_t *addr;
-
- bvdbg("NXFLAT_RELOC_TYPE_REL32I Offset: %08x I-Space: %p\n",
- offset, loadinfo->ispace + sizeof(struct nxflat_hdr_s));
-
- if (offset < loadinfo->dsize)
- {
- addr = (uint32_t*)(offset + loadinfo->dspace->region);
- bvdbg(" Before: %08x\n", *addr);
- *addr += (uint32_t)(loadinfo->ispace + sizeof(struct nxflat_hdr_s));
- bvdbg(" After: %08x\n", *addr);
- return OK;
- }
- else
- {
- bdbg("Offset: %08 does not lie in D-Space size: %08x\n",
- offset, loadinfo->dsize);
- return -EINVAL;
- }
-}
-
-/****************************************************************************
- * Name: nxflat_bindrel32d
- *
- * Description:
- * Perform the NXFLAT_RELOC_TYPE_REL32D binding:
- *
- * Meaning: Object file contains a 32-bit offset into D-Space at the offset.
- * Fixup: Add allocated D-Space address to the offset.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static inline int nxflat_bindrel32d(FAR struct nxflat_loadinfo_s *loadinfo,
- uint32_t offset)
-{
- uint32_t *addr;
-
- bvdbg("NXFLAT_RELOC_TYPE_REL32D Offset: %08x D-Space: %p\n",
- offset, loadinfo->dspace->region);
-
- if (offset < loadinfo->dsize)
- {
- addr = (uint32_t*)(offset + loadinfo->dspace->region);
- bvdbg(" Before: %08x\n", *addr);
- *addr += (uint32_t)(loadinfo->dspace->region);
- bvdbg(" After: %08x\n", *addr);
- return OK;
- }
- else
- {
- bdbg("Offset: %08 does not lie in D-Space size: %08x\n",
- offset, loadinfo->dsize);
- return -EINVAL;
- }
-}
-
-/****************************************************************************
- * Name: nxflat_bindrel32id
- *
- * Description:
- * Perform the NXFLAT_RELOC_TYPE_REL32ID binding:
- *
- * Meaning: Object file contains a 32-bit offset into I-Space at the offset
- * that will unfortunately be references relative to the GOT
- * Fixup: Add allocated the mapped I-Space address MINUS the allocated
- * D-Space address to the offset.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-#ifdef NXFLAT_RELOC_TYPE_REL32ID
-static inline int nxflat_bindrel32id(FAR struct nxflat_loadinfo_s *loadinfo,
- uint32_t offset)
-{
- uint32_t *addr;
-
- bvdbg("NXFLAT_RELOC_TYPE_REL32D Offset: %08x D-Space: %p\n",
- offset, loadinfo->dspace->region);
-
- if (offset < loadinfo->dsize)
- {
- addr = (uint32_t*)(offset + loadinfo->dspace->region);
- bvdbg(" Before: %08x\n", *addr);
- *addr += ((uint32_t)loadinfo->ispace - (uint32_t)(loadinfo->dspace->region));
- bvdbg(" After: %08x\n", *addr);
- return OK;
- }
- else
- {
- bdbg("Offset: %08 does not lie in D-Space size: %08x\n",
- offset, loadinfo->dsize);
- return -EINVAL;
- }
-}
-#endif
-
-/****************************************************************************
- * Name: nxflat_gotrelocs
- *
- * Description:
- * Bind all of the GOT relocations in the loaded module described by
- * 'loadinfo'
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
-{
- FAR struct nxflat_reloc_s *relocs;
- FAR struct nxflat_reloc_s reloc;
- FAR struct nxflat_hdr_s *hdr;
- uint32_t offset;
- uint16_t nrelocs;
- int ret;
- int result;
- int i;
-
- /* The NXFLAT header is the first thing at the beginning of the ISpace. */
-
- hdr = (FAR struct nxflat_hdr_s*)loadinfo->ispace;
-
- /* From this, we can get the offset to the list of relocation entries */
-
- offset = ntohl(hdr->h_relocstart);
- nrelocs = ntohs(hdr->h_reloccount);
- bvdbg("offset: %08lx nrelocs: %d\n", (long)offset, nrelocs);
-
- /* The value of the relocation list that we get from the header is a
- * file offset. We will have to convert this to an offset into the
- * DSpace segment to get the pointer to the beginning of the relocation
- * list.
- */
-
- DEBUGASSERT(offset >= loadinfo->isize);
- DEBUGASSERT(offset + nrelocs * sizeof(struct nxflat_reloc_s)
- <= (loadinfo->isize + loadinfo->dsize));
-
- relocs = (FAR struct nxflat_reloc_s *)
- (offset - loadinfo->isize + loadinfo->dspace->region);
- bvdbg("isize: %08lx dpsace: %p relocs: %p\n",
- (long)loadinfo->isize, loadinfo->dspace->region, relocs);
-
- /* All relocations are performed within the D-Space allocation. If
- * CONFIG_ADDRENV=y, then that D-Space allocation lies in an address
- * environment that may not be in place. So, in that case, we must call
- * nxflat_addrenv_select to temporarily instantiate that address space
- * before the relocations can be performed.
- */
-
-#ifdef CONFIG_ADDRENV
- ret = nxflat_addrenv_select(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
- return ret;
- }
-#endif
-
- /* Now, traverse the relocation list of and bind each GOT relocation. */
-
- ret = OK; /* Assume success */
- for (i = 0; i < nrelocs; i++)
- {
- /* Handle the relocation by the relocation type */
-
-#ifdef CONFIG_CAN_PASS_STRUCTS
- reloc = *relocs++;
-#else
- memcpy(&reloc, relocs, sizeof(struct nxflat_reloc_s));
- relocs++;
-#endif
-
- result = OK;
- switch (NXFLAT_RELOC_TYPE(reloc.r_info))
- {
- /* NXFLAT_RELOC_TYPE_REL32I Meaning: Object file contains a 32-bit offset
- * into I-Space at the offset.
- * Fixup: Add mapped I-Space address to the offset.
- */
-
- case NXFLAT_RELOC_TYPE_REL32I:
- {
- result = nxflat_bindrel32i(loadinfo, NXFLAT_RELOC_OFFSET(reloc.r_info));
- }
- break;
-
- /* NXFLAT_RELOC_TYPE_REL32D Meaning: Object file contains a 32-bit offset
- * into D-Space at the offset.
- * Fixup: Add allocated D-Space address to the
- * offset.
- */
-
- case NXFLAT_RELOC_TYPE_REL32D:
- {
- result = nxflat_bindrel32d(loadinfo, NXFLAT_RELOC_OFFSET(reloc.r_info));
- }
- break;
-
- /* NXFLAT_RELOC_TYPE_REL32ID Meaning: Object file contains a 32-bit offset
- * into I-Space at the offset that will
- * unfortunately be references relative
- * to the GOT
- * Fixup: Add allocated the mapped I-Space
- * address MINUS the allocated D-Space
- * address to the offset.
- */
-
-#ifdef NXFLAT_RELOC_TYPE_REL32ID
- case NXFLAT_RELOC_TYPE_REL32ID:
- {
- result = nxflat_bindrel32id(loadinfo, NXFLAT_RELOC_OFFSET(reloc.r_info));
- }
- break;
-#endif
-
- default:
- {
- bdbg("ERROR: Unrecognized relocation type: %d\n", NXFLAT_RELOC_TYPE(reloc.r_info));
- result = -EINVAL;
- }
- break;
- }
-
- /* Check for failures */
-
- if (result < 0 && ret == OK)
- {
- ret = result;
- }
- }
-
- /* Dump the relocation got */
-
-#ifdef CONFIG_NXFLAT_DUMPBUFFER
- if (ret == OK && nrelocs > 0)
- {
- relocs = (FAR struct nxflat_reloc_s*)(offset - loadinfo->isize + loadinfo->dspace->region);
- nxflat_dumpbuffer("GOT", (FAR const uint8_t*)relocs, nrelocs * sizeof(struct nxflat_reloc_s));
- }
-#endif
-
- /* Restore the original address environment */
-
-#ifdef CONFIG_ADDRENV
- ret = nxflat_addrenv_restore(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
- }
-#endif
-
- return ret;
-}
-
-/****************************************************************************
- * Name: nxflat_bindimports
- *
- * Description:
- * Bind the imported symbol names in the loaded module described by
- * 'loadinfo' using the exported symbol values provided by 'symtab'
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
- FAR const struct symtab_s *exports,
- int nexports)
-{
- FAR struct nxflat_import_s *imports;
- FAR struct nxflat_hdr_s *hdr;
- FAR const struct symtab_s *symbol;
-
- char *symname;
- uint32_t offset;
- uint16_t nimports;
-#ifdef CONFIG_ADDRENV
- int ret;
-#endif
- int i;
-
- /* The NXFLAT header is the first thing at the beginning of the ISpace. */
-
- hdr = (FAR struct nxflat_hdr_s*)loadinfo->ispace;
-
- /* From this, we can get the offset to the list of symbols imported by
- * this module and the number of symbols imported by this module.
- */
-
- offset = ntohl(hdr->h_importsymbols);
- nimports = ntohs(hdr->h_importcount);
- bvdbg("Imports offset: %08x nimports: %d\n", offset, nimports);
-
- /* The import[] table resides within the D-Space allocation. If
- * CONFIG_ADDRENV=y, then that D-Space allocation lies in an address
- * environment that may not be in place. So, in that case, we must call
- * nxflat_addrenv_select to temporarily instantiate that address space
- * before the import[] table can be modified.
- */
-
-#ifdef CONFIG_ADDRENV
- ret = nxflat_addrenv_select(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
- return ret;
- }
-#endif
-
- /* Verify that this module requires imported symbols */
-
- if (offset != 0 && nimports > 0)
- {
- /* It does.. make sure that exported symbols are provided */
-
- DEBUGASSERT(exports && nexports > 0);
-
- /* If non-zero, the value of the imported symbol list that we get
- * from the header is a file offset. We will have to convert this
- * to an offset into the DSpace segment to get the pointer to the
- * beginning of the imported symbol list.
- */
-
- DEBUGASSERT(offset >= loadinfo->isize &&
- offset < loadinfo->isize + loadinfo->dsize);
-
- imports = (struct nxflat_import_s*)
- (offset - loadinfo->isize + loadinfo->dspace->region);
-
- /* Now, traverse the list of imported symbols and attempt to bind
- * each symbol to the value exported by from the exported symbol
- * table.
- */
-
- for (i = 0; i < nimports; i++)
- {
- bvdbg("Import[%d] (%08p) offset: %08x func: %08x\n",
- i, &imports[i], imports[i].i_funcname, imports[i].i_funcaddress);
-
- /* Get a pointer to the imported symbol name. The name itself
- * lies in the TEXT segment. But the reference to the name
- * lies in DATA segment. Therefore, the name reference should
- * have been relocated when the module was loaded.
- */
-
- offset = imports[i].i_funcname;
- DEBUGASSERT(offset < loadinfo->isize);
-
- symname = (char*)(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s));
-
- /* Find the exported symbol value for this this symbol name. */
-
-#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
- symbol = symtab_findorderedbyname(exports, symname, nexports);
-#else
- symbol = symtab_findbyname(exports, symname, nexports);
-#endif
- if (!symbol)
- {
- bdbg("Exported symbol \"%s\" not found\n", symname);
-#ifdef CONFIG_ADDRENV
- (void)nxflat_addrenv_restore(loadinfo);
-#endif
- return -ENOENT;
- }
-
- /* And put this into the module's import structure. */
-
- imports[i].i_funcaddress = (uint32_t)symbol->sym_value;
-
- bvdbg("Bound import[%d] (%08p) to export '%s' (%08x)\n",
- i, &imports[i], symname, imports[i].i_funcaddress);
- }
- }
-
- /* Dump the relocation import table */
-
-#ifdef CONFIG_NXFLAT_DUMPBUFFER
- if (nimports > 0)
- {
- nxflat_dumpbuffer("Imports", (FAR const uint8_t*)imports, nimports * sizeof(struct nxflat_import_s));
- }
-#endif
-
- /* Restore the original address environment */
-
-#ifdef CONFIG_ADDRENV
- ret = nxflat_addrenv_restore(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
- }
-
- return ret;
-#else
- return OK;
-#endif
-}
-
-/****************************************************************************
- * Name: nxflat_clearbss
- *
- * Description:
- * Clear uninitialized .bss memory
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-static inline int nxflat_clearbss(FAR struct nxflat_loadinfo_s *loadinfo)
-{
-#ifdef CONFIG_ADDRENV
- int ret;
-#endif
-
- /* .bss resides within the D-Space allocation. If CONFIG_ADDRENV=y, then
- * that D-Space allocation lies in an address environment that may not be
- * in place. So, in that case, we must call nxflat_addrenv_select to
- * temporarily instantiate that address space before the .bss can be
- * accessed.
- */
-
-#ifdef CONFIG_ADDRENV
- ret = nxflat_addrenv_select(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
- return ret;
- }
-#endif
-
- /* Zero the BSS area */
-
- memset((void*)(loadinfo->dspace->region + loadinfo->datasize), 0,
- loadinfo->bsssize);
-
- /* Restore the original address environment */
-
-#ifdef CONFIG_ADDRENV
- ret = nxflat_addrenv_restore(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
- }
-
- return ret;
-#else
- return OK;
-#endif
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_bind
- *
- * Description:
- * Bind the imported symbol names in the loaded module described by
- * 'loadinfo' using the exported symbol values provided by 'symtab'.
- * After binding the module, clear the BSS region (which held the relocation
- * data) in preparation for execution.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int nxflat_bind(FAR struct nxflat_loadinfo_s *loadinfo,
- FAR const struct symtab_s *exports, int nexports)
-{
- /* Bind the imported symbol, absolute relocations separately. This is done
- * before the standard relocations because that logic may modify the
- * import list (for the better hopefully, but we don't want to depend on it).
- */
-
- int ret = nxflat_bindimports(loadinfo, exports, nexports);
- if (ret == OK)
- {
- /* Then bind all GOT relocations */
-
- ret = nxflat_gotrelocs(loadinfo);
- if (ret == OK)
- {
- /* Zero the BSS area, trashing the relocations that lived in that
- * space in the loaded file.
- */
-
- ret = nxflat_clearbss(loadinfo);
- }
- }
-
- return ret;
-}
-
diff --git a/nuttx/binfmt/libnxflat/libnxflat_init.c b/nuttx/binfmt/libnxflat/libnxflat_init.c
deleted file mode 100644
index b7cac8d86..000000000
--- a/nuttx/binfmt/libnxflat/libnxflat_init.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/****************************************************************************
- * binfmt/libnxflat/libnxflat_init.c
- *
- * Copyright (C) 2009 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 <sys/stat.h>
-#include <stdint.h>
-#include <string.h>
-#include <fcntl.h>
-#include <nxflat.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <arpa/inet.h>
-#include <nuttx/binfmt/nxflat.h>
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
- * defined or CONFIG_NXFLAT_DUMPBUFFER does nothing.
- */
-
-#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
-# undef CONFIG_NXFLAT_DUMPBUFFER
-#endif
-
-#ifdef CONFIG_NXFLAT_DUMPBUFFER
-# define nxflat_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
-#else
-# define nxflat_dumpbuffer(m,b,n)
-#endif
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_init
- *
- * Description:
- * This function is called to configure the library to process an NXFLAT
- * program binary.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
-{
- uint32_t datastart;
- uint32_t dataend;
- uint32_t bssstart;
- uint32_t bssend;
- int ret;
-
- bvdbg("filename: %s loadinfo: %p\n", filename, loadinfo);
-
- /* Clear the load info structure */
-
- memset(loadinfo, 0, sizeof(struct nxflat_loadinfo_s));
-
- /* Open the binary file */
-
- loadinfo->filfd = open(filename, O_RDONLY);
- if (loadinfo->filfd < 0)
- {
- int errval = errno;
- bdbg("Failed to open NXFLAT binary %s: %d\n", filename, errval);
- return -errval;
- }
-
- /* Read the NXFLAT header from offset 0 */
-
- ret = nxflat_read(loadinfo, (char*)&loadinfo->header,
- sizeof(struct nxflat_hdr_s), 0);
- if (ret < 0)
- {
- bdbg("Failed to read NXFLAT header: %d\n", ret);
- return ret;
- }
- nxflat_dumpbuffer("NXFLAT header", (FAR const uint8_t*)&loadinfo->header,
- sizeof(struct nxflat_hdr_s));
-
- /* Verify the NXFLAT header */
-
- if (nxflat_verifyheader(&loadinfo->header) != 0)
- {
- /* This is not an error because we will be called to attempt loading
- * EVERY binary. Returning -ENOEXEC simply informs the system that
- * the file is not an NXFLAT file. Besides, if there is something worth
- * complaining about, nnxflat_verifyheader() has already
- * done so.
- */
-
- bdbg("Bad NXFLAT header\n");
- return -ENOEXEC;
- }
-
- /* Save all of the input values in the loadinfo structure
- * and extract some additional information from the xflat
- * header. Note that the information in the xflat header is in
- * network order.
- */
-
- datastart = ntohl(loadinfo->header.h_datastart);
- dataend = ntohl(loadinfo->header.h_dataend);
- bssstart = dataend;
- bssend = ntohl(loadinfo->header.h_bssend);
-
- /* And put this information into the loadinfo structure as well.
- *
- * Note that:
- *
- * isize = the address range from 0 up to datastart.
- * datasize = the address range from datastart up to dataend
- * bsssize = the address range from dataend up to bssend.
- */
-
- loadinfo->entryoffs = ntohl(loadinfo->header.h_entry);
- loadinfo->isize = datastart;
-
- loadinfo->datasize = dataend - datastart;
- loadinfo->bsssize = bssend - dataend;
- loadinfo->stacksize = ntohl(loadinfo->header.h_stacksize);
-
- /* This is the initial dspace size. We'll re-calculate this later
- * after the memory has been allocated.
- */
-
- loadinfo->dsize = bssend - datastart;
-
- /* Get the offset to the start of the relocations (we'll relocate
- * this later).
- */
-
- loadinfo->relocstart = ntohl(loadinfo->header.h_relocstart);
- loadinfo->reloccount = ntohs(loadinfo->header.h_reloccount);
-
- return 0;
-}
-
diff --git a/nuttx/binfmt/libnxflat/libnxflat_load.c b/nuttx/binfmt/libnxflat/libnxflat_load.c
deleted file mode 100644
index 5f13b577a..000000000
--- a/nuttx/binfmt/libnxflat/libnxflat_load.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/****************************************************************************
- * binfmt/libnxflat/libnxflat_load.c
- *
- * Copyright (C) 2009 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 <sys/types.h>
-#include <sys/mman.h>
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <nxflat.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <arpa/inet.h>
-
-#include <nuttx/binfmt/nxflat.h>
-
-#include "libnxflat.h"
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-#ifndef MAX
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-#endif
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_load
- *
- * Description:
- * Loads the binary specified by nxflat_init into memory, mapping
- * the I-space executable regions, allocating the D-Space region,
- * and inializing the data segment (relocation information is
- * temporarily loaded into the BSS region. BSS will be cleared
- * by nxflat_bind() after the relocation data has been processed).
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
-{
- off_t doffset; /* Offset to .data in the NXFLAT file */
- uint32_t dreadsize; /* Total number of bytes of .data to be read */
- uint32_t relocsize; /* Memory needed to hold relocations */
- uint32_t extrasize; /* MAX(BSS size, relocsize) */
- int ret = OK;
-
- /* Calculate the extra space we need to allocate. This extra space will be
- * the size of the BSS section. This extra space will also be used
- * temporarily to hold relocation information. So the allocated size of this
- * region will either be the size of .data + size of.bss section OR, the
- * size of .data + the relocation entries, whichever is larger
- *
- * This is the amount of memory that we have to have to hold the
- * relocations.
- */
-
- relocsize = loadinfo->reloccount * sizeof(struct nxflat_reloc_s);
-
- /* In the file, the relocations should lie at the same offset as BSS.
- * The additional amount that we allocate have to be either (1) the
- * BSS size, or (2) the size of the relocation records, whicher is
- * larger.
- */
-
- extrasize = MAX(loadinfo->bsssize, relocsize);
-
- /* Use this additional amount to adjust the total size of the dspace
- * region.
- */
-
- loadinfo->dsize = loadinfo->datasize + extrasize;
-
- /* The number of bytes of data that we have to read from the file is
- * the data size plus the size of the relocation table.
- */
-
- dreadsize = loadinfo->datasize + relocsize;
-
- /* We'll need this a few times. */
-
- doffset = loadinfo->isize;
-
- /* We will make two mmap calls create an address space for the executable.
- * We will attempt to map the file to get the ISpace address space and
- * to allocate RAM to get the DSpace address space. If the filesystem does
- * not support file mapping, the map() implementation should do the
- * right thing.
- */
-
- /* The following call will give as a pointer to the mapped file ISpace.
- * This may be in ROM, RAM, Flash, ... We don't really care where the memory
- * resides as long as it is fully initialized and ready to execute.
- */
-
- loadinfo->ispace = (uint32_t)mmap(NULL, loadinfo->isize, PROT_READ,
- MAP_SHARED|MAP_FILE, loadinfo->filfd, 0);
- if (loadinfo->ispace == (uint32_t)MAP_FAILED)
- {
- bdbg("Failed to map NXFLAT ISpace: %d\n", errno);
- return -errno;
- }
-
- bvdbg("Mapped ISpace (%d bytes) at %08x\n", loadinfo->isize, loadinfo->ispace);
-
- /* The following call allocate D-Space memory and will provide a pointer
- * to the allocated (but still uninitialized) D-Space memory.
- */
-
- ret = nxflat_addrenv_alloc(loadinfo, loadinfo->dsize);
- if (ret < 0)
- {
- bdbg("ERROR: nxflat_addrenv_alloc() failed: %d\n", ret);
- return ret;
- }
-
- bvdbg("Allocated DSpace (%d bytes) at %p\n",
- loadinfo->dsize, loadinfo->dspace->region);
-
- /* If CONFIG_ADDRENV=y, then the D-Space allocation lies in an address
- * environment that may not be in place. So, in that case, we must call
- * nxflat_addrenv_select to temporarily instantiate that address space
- * it can be initialized.
- */
-
-#ifdef CONFIG_ADDRENV
- ret = nxflat_addrenv_select(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
- return ret;
- }
-#endif
-
- /* Now, read the data into allocated DSpace at doffset into the allocated
- * DSpace memory.
- */
-
- ret = nxflat_read(loadinfo, (char*)loadinfo->dspace->region, dreadsize, doffset);
- if (ret < 0)
- {
- bdbg("Failed to read .data section: %d\n", ret);
- goto errout;
- }
-
- bvdbg("TEXT: %08x Entry point offset: %08x Data offset: %08x\n",
- loadinfo->ispace, loadinfo->entryoffs, doffset);
-
- /* Restore the original address environment */
-
-#ifdef CONFIG_ADDRENV
- ret = nxflat_addrenv_restore(loadinfo);
- if (ret < 0)
- {
- bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
- return ret;
- }
-#endif
-
- return OK;
-
-errout:
-#ifdef CONFIG_ADDRENV
- (void)nxflat_addrenv_restore(loadinfo);
-#endif
- (void)nxflat_unload(loadinfo);
- return ret;
-}
-
diff --git a/nuttx/binfmt/libnxflat/libnxflat_read.c b/nuttx/binfmt/libnxflat/libnxflat_read.c
deleted file mode 100644
index 103a81f81..000000000
--- a/nuttx/binfmt/libnxflat/libnxflat_read.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/****************************************************************************
- * binfmt/libnxflat/libnxflat_read.c
- *
- * Copyright (C) 2009 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 <sys/types.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <string.h>
-#include <nxflat.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <arpa/inet.h>
-#include <nuttx/binfmt/nxflat.h>
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-#undef NXFLAT_DUMP_READDATA /* Define to dump all file data read */
-#define DUMPER syslog /* If NXFLAT_DUMP_READDATA is defined, this
- * is the API used to dump data */
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_dumpreaddata
- ****************************************************************************/
-
-#if defined(NXFLAT_DUMP_READDATA)
-static inline void nxflat_dumpreaddata(char *buffer, int buflen)
-{
- uint32_t *buf32 = (uint32_t*)buffer;
- int i;
- int j;
-
- for (i = 0; i < buflen; i += 32)
- {
- DUMPER("%04x:", i);
- for (j = 0; j < 32; j += sizeof(uint32_t))
- {
- DUMPER(" %08x", *buf32++);
- }
- DUMPER("\n");
- }
-}
-#else
-# define nxflat_dumpreaddata(b,n)
-#endif
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_read
- *
- * Description:
- * Read 'readsize' bytes from the object file at 'offset'
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize, int offset)
-{
- ssize_t nbytes; /* Number of bytes read */
- off_t rpos; /* Position returned by lseek */
- char *bufptr; /* Next buffer location to read into */
- int bytesleft; /* Number of bytes of .data left to read */
- int bytesread; /* Total number of bytes read */
-
- bvdbg("Read %d bytes from offset %d\n", readsize, offset);
-
- /* Seek to the position in the object file where the initialized
- * data is saved.
- */
-
- bytesread = 0;
- bufptr = buffer;
- bytesleft = readsize;
- do
- {
- rpos = lseek(loadinfo->filfd, offset, SEEK_SET);
- if (rpos != offset)
- {
- int errval = errno;
- bdbg("Failed to seek to position %d: %d\n", offset, errval);
- return -errval;
- }
-
- /* Read the file data at offset into the user buffer */
-
- nbytes = read(loadinfo->filfd, bufptr, bytesleft);
- if (nbytes < 0)
- {
- int errval = errno;
- if (errval != EINTR)
- {
- bdbg("Read of .data failed: %d\n", errval);
- return -errval;
- }
- }
- else if (nbytes == 0)
- {
- bdbg("Unexpected end of file\n");
- return -ENODATA;
- }
- else
- {
- bytesread += nbytes;
- bytesleft -= nbytes;
- bufptr += nbytes;
- offset += nbytes;
- }
- }
- while (bytesread < readsize);
-
- nxflat_dumpreaddata(buffer, readsize);
- return OK;
-}
-
diff --git a/nuttx/binfmt/libnxflat/libnxflat_uninit.c b/nuttx/binfmt/libnxflat/libnxflat_uninit.c
deleted file mode 100644
index b9715196b..000000000
--- a/nuttx/binfmt/libnxflat/libnxflat_uninit.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************************
- * binfmt/libnxflat/libnxflat_uninit.c
- *
- * Copyright (C) 2009 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 <unistd.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/nxflat.h>
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_uninit
- *
- * Description:
- * Releases any resources committed by nxflat_init(). This essentially
- * undoes the actions of nxflat_init.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo)
-{
- if (loadinfo->filfd >= 0)
- {
- close(loadinfo->filfd);
- }
- return OK;
-}
-
diff --git a/nuttx/binfmt/libnxflat/libnxflat_unload.c b/nuttx/binfmt/libnxflat/libnxflat_unload.c
deleted file mode 100644
index eb1aa0343..000000000
--- a/nuttx/binfmt/libnxflat/libnxflat_unload.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
- * binfmt/libnxflat/libnxflat_unload.c
- *
- * Copyright (C) 2009 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 <sys/mman.h>
-
-#include <stdlib.h>
-#include <debug.h>
-
-#include <nuttx/kmalloc.h>
-#include <nuttx/binfmt/nxflat.h>
-
-#include "libnxflat.h"
-
-/****************************************************************************
- * Pre-Processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_unload
- *
- * Description:
- * This function unloads the object from memory. This essentially undoes
- * the actions of nxflat_load. It is called only under certain error
- * conditions after the the module has been loaded but not yet started.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int nxflat_unload(struct nxflat_loadinfo_s *loadinfo)
-{
- /* Release the memory segments */
- /* Release the I-Space mmap'ed file */
-
- if (loadinfo->ispace)
- {
- munmap((void*)loadinfo->ispace, loadinfo->isize);
- loadinfo->ispace = 0;
- }
-
- /* Release the D-Space address environment */
-
- nxflat_addrenv_free(loadinfo);
- return OK;
-}
diff --git a/nuttx/binfmt/libnxflat/libnxflat_verify.c b/nuttx/binfmt/libnxflat/libnxflat_verify.c
deleted file mode 100644
index 20af5d2f7..000000000
--- a/nuttx/binfmt/libnxflat/libnxflat_verify.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/****************************************************************************
- * binfmt/libnxflat/nxflat_verify.c
- *
- * Copyright (C) 2009 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 <string.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <arpa/inet.h>
-#include <nuttx/binfmt/nxflat.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Constant Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_verifyheader
- *
- * Description:
- * Given the header from a possible NXFLAT executable, verify that it
- * is an NXFLAT executable.
- *
- * Returned Value:
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int nxflat_verifyheader(const struct nxflat_hdr_s *header)
-{
- if (!header)
- {
- bdbg("NULL NXFLAT header!");
- return -ENOEXEC;
- }
-
- /* Check the FLT header -- magic number and revision.
- *
- * If the magic number does not match. Just return
- * silently. This is not our binary.
- */
-
- if (strncmp(header->h_magic, NXFLAT_MAGIC, 4) != 0)
- {
- bdbg("Unrecognized magic=\"%c%c%c%c\"\n",
- header->h_magic[0], header->h_magic[1],
- header->h_magic[2], header->h_magic[3]);
- return -ENOEXEC;
- }
-
- return OK;
-}
diff --git a/nuttx/binfmt/nxflat.c b/nuttx/binfmt/nxflat.c
deleted file mode 100644
index db29941ca..000000000
--- a/nuttx/binfmt/nxflat.c
+++ /dev/null
@@ -1,280 +0,0 @@
-/****************************************************************************
- * binfmt/nxflat.c
- *
- * Copyright (C) 2009 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 <sys/types.h>
-#include <stdint.h>
-#include <string.h>
-#include <nxflat.h>
-#include <debug.h>
-#include <errno.h>
-
-#include <arpa/inet.h>
-#include <nuttx/binfmt/binfmt.h>
-#include <nuttx/binfmt/nxflat.h>
-
-#ifdef CONFIG_NXFLAT
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
- * defined or CONFIG_NXFLAT_DUMPBUFFER does nothing.
- */
-
-#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
-# undef CONFIG_NXFLAT_DUMPBUFFER
-#endif
-
-#ifdef CONFIG_NXFLAT_DUMPBUFFER
-# define nxflat_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
-#else
-# define nxflat_dumpbuffer(m,b,n)
-#endif
-
-#ifndef MIN
-# define MIN(a,b) (a < b ? a : b)
-#endif
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static int nxflat_loadbinary(struct binary_s *binp);
-#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
-static void nxflat_dumploadinfo(struct nxflat_loadinfo_s *loadinfo);
-#endif
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-static struct binfmt_s g_nxflatbinfmt =
-{
- NULL, /* next */
- nxflat_loadbinary, /* load */
-};
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: nxflat_dumploadinfo
- ****************************************************************************/
-
-#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
-static void nxflat_dumploadinfo(struct nxflat_loadinfo_s *loadinfo)
-{
- unsigned long dsize = loadinfo->datasize + loadinfo->bsssize;
-
- bdbg("LOAD_INFO:\n");
- bdbg(" ISPACE:\n");
- bdbg(" ispace: %08lx\n", loadinfo->ispace);
- bdbg(" entryoffs: %08lx\n", loadinfo->entryoffs);
- bdbg(" isize: %08lx\n", loadinfo->isize);
-
- bdbg(" DSPACE:\n");
- bdbg(" dspace: %08lx\n", loadinfo->dspace);
- if (loadinfo->dspace != NULL)
- {
- bdbg(" crefs: %d\n", loadinfo->dspace->crefs);
- bdbg(" region: %08lx\n", loadinfo->dspace->region);
- }
- bdbg(" datasize: %08lx\n", loadinfo->datasize);
- bdbg(" bsssize: %08lx\n", loadinfo->bsssize);
- bdbg(" (pad): %08lx\n", loadinfo->dsize - dsize);
- bdbg(" stacksize: %08lx\n", loadinfo->stacksize);
- bdbg(" dsize: %08lx\n", loadinfo->dsize);
-
- bdbg(" RELOCS:\n");
- bdbg(" relocstart: %08lx\n", loadinfo->relocstart);
- bdbg(" reloccount: %d\n", loadinfo->reloccount);
-
- bdbg(" HANDLES:\n");
- bdbg(" filfd: %d\n", loadinfo->filfd);
-}
-#else
-# define nxflat_dumploadinfo(i)
-#endif
-
-/****************************************************************************
- * Name: nxflat_loadbinary
- *
- * Description:
- * Verify that the file is an NXFLAT binary and, if so, load the NXFLAT
- * binary into memory
- *
- ****************************************************************************/
-
-static int nxflat_loadbinary(struct binary_s *binp)
-{
- struct nxflat_loadinfo_s loadinfo; /* Contains globals for libnxflat */
- int ret;
-
- bvdbg("Loading file: %s\n", binp->filename);
-
- /* Initialize the xflat library to load the program binary. */
-
- ret = nxflat_init(binp->filename, &loadinfo);
- nxflat_dumploadinfo(&loadinfo);
- if (ret != 0)
- {
- bdbg("Failed to initialize for load of NXFLAT program: %d\n", ret);
- goto errout;
- }
-
- /* Load the program binary */
-
- ret = nxflat_load(&loadinfo);
- nxflat_dumploadinfo(&loadinfo);
- if (ret != 0)
- {
- bdbg("Failed to load NXFLAT program binary: %d\n", ret);
- goto errout_with_init;
- }
-
- /* Bind the program to the exported symbol table */
-
- ret = nxflat_bind(&loadinfo, binp->exports, binp->nexports);
- if (ret != 0)
- {
- bdbg("Failed to bind symbols program binary: %d\n", ret);
- goto errout_with_load;
- }
-
- /* Return the load information. By convention, D-space address
- * space is stored as the first allocated memory.
- */
-
- binp->entrypt = (main_t)(loadinfo.ispace + loadinfo.entryoffs);
- binp->mapped = (void*)loadinfo.ispace;
- binp->mapsize = loadinfo.isize;
- binp->stacksize = loadinfo.stacksize;
-
- /* Add the ELF allocation to the alloc[] only if there is no address
- * enironment. If there is an address environment, it will automatically
- * be freed when the function exits
- *
- * REVISIT: If the module is loaded then unloaded, wouldn't this cause
- * a memory leak?
- */
-
-#ifdef CONFIG_ADDRENV
-# warning "REVISIT"
-#else
- binp->alloc[0] = (void*)loadinfo.dspace;
-#endif
-
-#ifdef CONFIG_ADDRENV
- /* Save the address environment. This will be needed when the module is
- * executed for the up_addrenv_assign() call.
- */
-
- binp->addrenv = loadinfo.addrenv;
-#endif
-
- nxflat_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt,
- MIN(loadinfo.isize - loadinfo.entryoffs, 512));
-
- nxflat_uninit(&loadinfo);
- return OK;
-
-errout_with_load:
- nxflat_unload(&loadinfo);
-errout_with_init:
- nxflat_uninit(&loadinfo);
-errout:
- return ret;
-}
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/***********************************************************************
- * Name: nxflat_initialize
- *
- * Description:
- * NXFLAT support is built unconditionally. However, it order to
- * use this binary format, this function must be called during system
- * format in order to register the NXFLAT binary format.
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ***********************************************************************/
-
-int nxflat_initialize(void)
-{
- int ret;
-
- /* Register ourselves as a binfmt loader */
-
- bvdbg("Registering NXFLAT\n");
- ret = register_binfmt(&g_nxflatbinfmt);
- if (ret != 0)
- {
- bdbg("Failed to register binfmt: %d\n", ret);
- }
- return ret;
-}
-
-/****************************************************************************
- * Name: nxflat_uninitialize
- *
- * Description:
- * Unregister the NXFLAT binary loader
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-void nxflat_uninitialize(void)
-{
- unregister_binfmt(&g_nxflatbinfmt);
-}
-
-#endif /* CONFIG_NXFLAT */
-
diff --git a/nuttx/binfmt/symtab_findbyname.c b/nuttx/binfmt/symtab_findbyname.c
deleted file mode 100644
index c0343e270..000000000
--- a/nuttx/binfmt/symtab_findbyname.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
- * binfmt/symtab_findbyname.c
- *
- * Copyright (C) 2009 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 <string.h>
-#include <debug.h>
-#include <assert.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/symtab.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/****************************************************************************
- * 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)
-{
- DEBUGASSERT(symtab != NULL && name != NULL);
- for (; nsyms > 0; symtab++, nsyms--)
- {
- if (strcmp(name, symtab->sym_name) == 0)
- {
- return symtab;
- }
- }
- return NULL;
-}
-
diff --git a/nuttx/binfmt/symtab_findbyvalue.c b/nuttx/binfmt/symtab_findbyvalue.c
deleted file mode 100644
index c47d5c751..000000000
--- a/nuttx/binfmt/symtab_findbyvalue.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/****************************************************************************
- * binfmt/symtab_findbyvalue.c
- *
- * Copyright (C) 2009 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 <stddef.h>
-#include <debug.h>
-#include <assert.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/symtab.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/****************************************************************************
- * 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)
-{
- FAR const struct symtab_s *retval = NULL;
-
- DEBUGASSERT(symtab != NULL);
- for (; nsyms > 0; symtab++, nsyms--)
- {
- /* Look for symbols of lesser or equal value (probably address) to value */
-
- if (symtab->sym_value <= value)
- {
- /* Found one. Is it the largest we have found so far? */
-
- if (!retval || symtab->sym_value > retval->sym_value)
- {
- /* Yes, then it is the new candidate for the symbol whose value
- * just below 'value'
- */
-
- retval = symtab;
-
- /* If it is exactly equal to the search 'value', then we might as
- * well terminate early because we can't do any better than that.
- */
-
- if (retval->sym_value == value)
- {
- break;
- }
- }
- }
- }
-
- return retval;
-}
-
diff --git a/nuttx/binfmt/symtab_findorderedbyname.c b/nuttx/binfmt/symtab_findorderedbyname.c
deleted file mode 100644
index a678788e7..000000000
--- a/nuttx/binfmt/symtab_findorderedbyname.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/****************************************************************************
- * binfmt/symtab_findorderedbyname.c
- *
- * Copyright (C) 2009 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 <string.h>
-#include <debug.h>
-#include <assert.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/symtab.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/****************************************************************************
- * 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.
- *
- * This function uses qsort() to implement the search and, hence, is a lot
- * larger than symbtab_findbyname(). This function not be used, unless
- * the symbol table is large and the performance benefit is worth the
- * increased size.
- *
- * 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)
-{
- int low = 0;
- int high = nsyms -1;
- int mid;
- int cmp;
-
- /* Loop until the range has been isolated to a single symbol table
- * entry that may or may not match the search name.
- */
-
- DEBUGASSERT(symtab != NULL && name != NULL);
- while (low < high)
- {
- /* Compare the name to the one in the middle. (or just below
- * the middle in the case where one is even and one is odd).
- */
-
- mid = (low + high) >> 1;
- cmp = strcmp(name, symtab[mid].sym_name);
- if (cmp < 0)
- {
- /* name < symtab[mid].sym_name */
-
- high = mid - 1;
- }
- else if (cmp > 0)
- {
- /* name > symtab[mid].sym_name */
-
- low = mid + 1;
- }
- else
- {
- /* symtab[mid].sym_name == name */
-
- return &symtab[mid];
- }
- }
-
- /* low == high... One final check. We might not have actually tested
- * the final symtab[] name.
- *
- * Example: Only the last pass through loop, suppose low = 1, high = 2,
- * mid = 1, and symtab[high].sym_name == name. Then we would get here with
- * low = 2, high = 2, but symtab[2].sym_name was never tested.
- */
-
- return strcmp(name, symtab[low].sym_name) == 0 ? &symtab[low] : NULL;
-}
-
diff --git a/nuttx/binfmt/symtab_findorderedbyvalue.c b/nuttx/binfmt/symtab_findorderedbyvalue.c
deleted file mode 100644
index bad4bf8cd..000000000
--- a/nuttx/binfmt/symtab_findorderedbyvalue.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/****************************************************************************
- * binfmt/symtab_findorderedbyvalue.c
- *
- * Copyright (C) 2009 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 <stddef.h>
-#include <debug.h>
-#include <assert.h>
-#include <errno.h>
-
-#include <nuttx/binfmt/symtab.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/***********************************************************************
- * Public Functions
- ***********************************************************************/
-
-/****************************************************************************
- * 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)
-{
- int low = 0;
- int high = nsyms -1;
- int mid;
-
- /* Loop until the range has been isolated to a single symbol table
- * entry that may or may not match the search name.
- */
-
- DEBUGASSERT(symtab != NULL);
- while (low < high)
- {
- /* Compare the name to the one in the middle. (or just below
- * the middle in the case where one is even and one is odd).
- */
-
- mid = (low + high) >> 1;
- if ( value < symtab[mid].sym_value)
- {
- high = mid - 1;
- }
- else if (value > symtab[mid].sym_value)
- {
- low = mid + 1;
- }
- else /* if (value == symtab[mid].sym_value) */
- {
- return &symtab[mid];
- }
- }
-
- /* low == high... One final check. We might not have actually tested
- * the final symtab[] name.
- *
- * Example: Only the last pass through loop, suppose low = 1, high = 2,
- * mid = 1, and symtab[high].sym_name == name. Then we would get here with
- * low = 2, high = 2, but symtab[2].sym_name was never tested.
- */
-
- return value == symtab[low].sym_value ? &symtab[low] : NULL;
-}
-