From 8ec22e916e5b0e09b4ea34358d6f9c48cf659cfc Mon Sep 17 00:00:00 2001 From: Masayuki Ishikawa Date: Thu, 26 Jul 2018 13:40:28 +0000 Subject: [PATCH] Merged in masayuki2009/nuttx.nuttx/refactor_binfmt_exec (pull request #697) binfmt: Refactor binfmt_exec.c This change also fixes an argv issue for CONFIG_SCHED_ONEXIT=n or CONFIG_SCHED_HAVE_PARENT=n Signed-off-by: Masayuki Ishikawa Approved-by: GregoryN --- binfmt/binfmt_exec.c | 50 ++++++++------------------------------------ 1 file changed, 9 insertions(+), 41 deletions(-) diff --git a/binfmt/binfmt_exec.c b/binfmt/binfmt_exec.c index bab26547843..d6ecd57dff4 100644 --- a/binfmt/binfmt_exec.c +++ b/binfmt/binfmt_exec.c @@ -119,7 +119,6 @@ int exec(FAR const char *filename, FAR char * const *argv, FAR const struct symtab_s *exports, int nexports) { -#if defined(CONFIG_SCHED_ONEXIT) && defined(CONFIG_SCHED_HAVE_PARENT) FAR struct binary_s *bin; int pid; int errcode; @@ -178,6 +177,7 @@ int exec(FAR const char *filename, FAR char * const *argv, goto errout_with_lock; } +#if defined(CONFIG_SCHED_ONEXIT) && defined(CONFIG_SCHED_HAVE_PARENT) /* Set up to unload the module (and free the binary_s structure) * when the task exists. */ @@ -187,6 +187,14 @@ int exec(FAR const char *filename, FAR char * const *argv, { berr("ERROR: Failed to schedule unload '%s': %d\n", filename, ret); } +#else + /* Free the binary_s structure here */ + + binfmt_freeargv(bin); + kmm_free(bin); + + /* TODO: How does the module get unloaded in this case? */ +#endif sched_unlock(); return pid; @@ -202,46 +210,6 @@ errout: set_errno(errcode); return ERROR; -#else - struct binary_s bin; - int errcode; - 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) - { - errcode = -ret; - berr("ERROR: Failed to load program '%s': %d\n", filename, errcode); - goto errout; - } - - /* Then start the module */ - - ret = exec_module(&bin); - if (ret < 0) - { - errcode = -ret; - berr("ERROR: Failed to execute program '%s': %d\n", filename, errcode); - goto errout_with_module; - } - - /* TODO: How does the module get unloaded in this case? */ - - return ret; - -errout_with_module: - (void)unload_module(&bin); -errout: - set_errno(errcode); - return ERROR; -#endif } #endif /* !CONFIG_BINFMT_DISABLE */