summaryrefslogtreecommitdiff
path: root/nuttx/binfmt
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-07-12 18:43:59 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-07-12 18:43:59 +0000
commit5b17ece930357c52595d264f30a6ff87561df443 (patch)
tree339894a7958f29c77ac9aff63a973fc3121c1d5d /nuttx/binfmt
parentd705291ceef2d2d02a74c6ca33fd07f72171114f (diff)
downloadpx4-nuttx-5b17ece930357c52595d264f30a6ff87561df443.tar.gz
px4-nuttx-5b17ece930357c52595d264f30a6ff87561df443.tar.bz2
px4-nuttx-5b17ece930357c52595d264f30a6ff87561df443.zip
Added exec()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1979 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/binfmt')
-rw-r--r--nuttx/binfmt/Makefile4
-rw-r--r--nuttx/binfmt/binfmt_exec.c125
2 files changed, 127 insertions, 2 deletions
diff --git a/nuttx/binfmt/Makefile b/nuttx/binfmt/Makefile
index 0ba0c2862..dd9e459ce 100644
--- a/nuttx/binfmt/Makefile
+++ b/nuttx/binfmt/Makefile
@@ -48,11 +48,11 @@ endif
BINFMT_ASRCS =
BINFMT_CSRCS = binfmt_globals.c binfmt_register.c binfmt_unregister.c \
binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c \
- binfmt_dumpmodule.c
+ binfmt_exec.c binfmt_dumpmodule.c
SYMTAB_ASRCS =
SYMTAB_CSRCS = symtab_findbyname.c symtab_findbyvalue.c \
- symtab_findorderedbyname.c symtab_findorderedbyvalue.c
+ symtab_findorderedbyname.c symtab_findorderedbyvalue.c
SUBDIRS = libnxflat
diff --git a/nuttx/binfmt/binfmt_exec.c b/nuttx/binfmt/binfmt_exec.c
new file mode 100644
index 000000000..8a25445c0
--- /dev/null
+++ b/nuttx/binfmt/binfmt_exec.c
@@ -0,0 +1,125 @@
+/****************************************************************************
+ * binfmt/binfmt_exec.c
+ *
+ * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 <string.h>
+#include <sched.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/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.
+ *
+ * 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:
+ * 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)
+{
+ struct binary_s bin;
+ int ret;
+ int i;
+
+ 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", dirlist[i]);
+ return ERROR;
+ }
+
+ ret = exec_module(&bin, 50);
+ if (ret < 0)
+ {
+ bdbg("ERROR: Failed to execute program '%s'\n", dirlist[i]);
+ unload_module(&bin);
+ return ERROR;
+ }
+
+ return ret;
+}
+
+#endif /* CONFIG_BINFMT_DISABLE */
+