Added exec()

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1979 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2009-07-12 18:43:59 +00:00
parent 93e34db926
commit 29899e1069
5 changed files with 166 additions and 9 deletions

View File

@ -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.

View File

@ -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 &lt;spudmonkey@racsa.co.cr&gt;
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 &lt;spudmonkey@racsa.co.cr&gt;

View File

@ -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

125
binfmt/binfmt_exec.c Normal file
View File

@ -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 */

View File

@ -85,7 +85,7 @@ struct binfmt_s
};
/****************************************************************************
* Public Functions
* Public Data
****************************************************************************/
#undef EXTERN
@ -96,6 +96,10 @@ extern "C" {
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: register_binfmt
*
@ -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)
}