diff options
-rw-r--r-- | nuttx/ChangeLog | 9 | ||||
-rw-r--r-- | nuttx/Documentation/NuttX.html | 8 | ||||
-rw-r--r-- | nuttx/binfmt/Makefile | 4 | ||||
-rw-r--r-- | nuttx/binfmt/binfmt_exec.c | 125 | ||||
-rw-r--r-- | nuttx/include/nuttx/binfmt.h | 29 |
5 files changed, 166 insertions, 9 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 46ed65e94..9e2b42602 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -810,8 +810,9 @@ typical embeddd system. * sched/: Added gettimeofday(). This implementation is simply a thin wrapper around clock_gettimer(). - * lib/: Add gmtime() and localtime() - - - + * lib/: Add gmtime(), localtime(), and strftime() + * binfmt/: Add exec(). This is just a wrapper that executes both + load_ and exec_module() in a more familiar manner. It is not consistent + with more standard exec() functions, however, because (1) it returns + and (2) it requires symbol table arguments. diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index e91143d81..f1bf734e9 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> - <p>Last Updated: July 11, 2009</p> + <p>Last Updated: July 12, 2009</p> </td> </tr> </table> @@ -1483,7 +1483,11 @@ nuttx-0.4.10 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> typical embeddd system. * sched/: Added gettimeofday(). This implementation is simply a thin wrapper around clock_gettimer(). - * lib/: Add gmtime() and localtime() + * lib/: Add gmtime(), localtime(), and strftime() + * binfmt/: Add exec(). This is just a wrapper that executes both + load_ and exec_module() in a more familiar manner. It is not consistent + with more standard exec() functions, however, because (1) it returns + and (2) it requires symbol table arguments. nuttx-0.4.10 2009-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> 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 */ + diff --git a/nuttx/include/nuttx/binfmt.h b/nuttx/include/nuttx/binfmt.h index 3fe0b3a38..7029ca161 100644 --- a/nuttx/include/nuttx/binfmt.h +++ b/nuttx/include/nuttx/binfmt.h @@ -85,7 +85,7 @@ struct binfmt_s }; /**************************************************************************** - * Public Functions + * Public Data ****************************************************************************/ #undef EXTERN @@ -97,6 +97,10 @@ extern "C" { #endif /**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** * Name: register_binfmt * * Description: @@ -173,6 +177,29 @@ EXTERN int unload_module(FAR const struct binary_s *bin); EXTERN int exec_module(FAR const struct binary_s *bin, int priority); +/**************************************************************************** + * 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. + * + ****************************************************************************/ + +EXTERN int exec(FAR const char *filename, FAR const char **argv, + FAR const struct symtab_s *exports, int nexports); + #undef EXTERN #if defined(__cplusplus) } |