mirror of
https://github.com/apache/nuttx.git
synced 2025-12-07 18:12:33 +08:00
Squashed commit of the following:
binfmt: Fix some compilation issues introduced in previous changes. Verfied with the STM32F4-Discovery ELF configuration.
binfmt: schedule_unload() is an internal OS function and must not alter the errno variable.
binfmt: unload_module() is an internal OS function and must not alter the errno variable.
binfmt: load_module() is an internal OS function and must not alter the errno variable.
binfmt: exec_module() is an internal OS function and must not alter the errno variable.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* binfmt/binfmt_exec.c
|
||||
*
|
||||
* Copyright (C) 2009, 2013-2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2013-2014, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -120,7 +120,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
|
||||
ret = load_module(bin);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = get_errno();
|
||||
errcode = -ret;
|
||||
berr("ERROR: Failed to load program '%s': %d\n", filename, errcode);
|
||||
goto errout_with_argv;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
|
||||
pid = exec_module(bin);
|
||||
if (pid < 0)
|
||||
{
|
||||
errcode = get_errno();
|
||||
errcode = -pid;
|
||||
berr("ERROR: Failed to execute program '%s': %d\n", filename, errcode);
|
||||
goto errout_with_lock;
|
||||
}
|
||||
@@ -149,8 +149,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
|
||||
ret = schedule_unload(pid, bin);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = get_errno();
|
||||
berr("ERROR: Failed to schedule unload '%s': %d\n", filename, errcode);
|
||||
berr("ERROR: Failed to schedule unload '%s': %d\n", filename, ret);
|
||||
}
|
||||
|
||||
sched_unlock();
|
||||
@@ -158,7 +157,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
|
||||
|
||||
errout_with_lock:
|
||||
sched_unlock();
|
||||
unload_module(bin);
|
||||
(void)unload_module(bin);
|
||||
errout_with_argv:
|
||||
binfmt_freeargv(bin);
|
||||
errout_with_bin:
|
||||
@@ -182,7 +181,7 @@ errout:
|
||||
ret = load_module(&bin);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = get_errno();
|
||||
errcode = -ret;
|
||||
berr("ERROR: Failed to load program '%s': %d\n", filename, errcode);
|
||||
goto errout;
|
||||
}
|
||||
@@ -192,7 +191,7 @@ errout:
|
||||
ret = exec_module(&bin);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = get_errno();
|
||||
errcode = -ret;
|
||||
berr("ERROR: Failed to execute program '%s': %d\n", filename, errcode);
|
||||
goto errout_with_module;
|
||||
}
|
||||
@@ -202,7 +201,7 @@ errout:
|
||||
return ret;
|
||||
|
||||
errout_with_module:
|
||||
unload_module(&bin);
|
||||
(void)unload_module(&bin);
|
||||
errout:
|
||||
set_errno(errcode);
|
||||
return ERROR;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* binfmt/binfmt_execmodule.c
|
||||
*
|
||||
* Copyright (C) 2009, 2013-2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2013-2014, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -69,14 +69,6 @@
|
||||
# errror "CONFIG_SCHED_STARTHOOK must be defined to use constructors"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -128,9 +120,9 @@ static void exec_ctors(FAR void *arg)
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -142,7 +134,6 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
#endif
|
||||
FAR uint32_t *stack;
|
||||
pid_t pid;
|
||||
int errcode;
|
||||
int ret;
|
||||
|
||||
/* Sanity checking */
|
||||
@@ -150,8 +141,7 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
#ifdef CONFIG_DEBUG_FEATURES
|
||||
if (!binp || !binp->entrypt || binp->stacksize <= 0)
|
||||
{
|
||||
errcode = EINVAL;
|
||||
goto errout;
|
||||
return -EINVAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -162,8 +152,7 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
tcb = (FAR struct task_tcb_s *)kmm_zalloc(sizeof(struct task_tcb_s));
|
||||
if (!tcb)
|
||||
{
|
||||
errcode = ENOMEM;
|
||||
goto errout;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
@@ -173,7 +162,6 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_select() failed: %d\n", ret);
|
||||
errcode = -ret;
|
||||
goto errout_with_tcb;
|
||||
}
|
||||
|
||||
@@ -192,7 +180,7 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
stack = (FAR uint32_t *)kumm_malloc(binp->stacksize);
|
||||
if (!stack)
|
||||
{
|
||||
errcode = ENOMEM;
|
||||
ret = -ENOMEM;
|
||||
goto errout_with_addrenv;
|
||||
}
|
||||
|
||||
@@ -202,8 +190,8 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
stack, binp->stacksize, binp->entrypt, binp->argv);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = get_errno();
|
||||
berr("task_init() failed: %d\n", errcode);
|
||||
ret = -get_errno();
|
||||
berr("task_init() failed: %d\n", ret);
|
||||
goto errout_with_addrenv;
|
||||
}
|
||||
|
||||
@@ -225,7 +213,6 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_select() failed: %d\n", ret);
|
||||
errcode = -ret;
|
||||
goto errout_with_tcbinit;
|
||||
}
|
||||
#endif
|
||||
@@ -237,7 +224,6 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: shm_group_initialize() failed: %d\n", ret);
|
||||
errcode = -ret;
|
||||
goto errout_with_tcbinit;
|
||||
}
|
||||
#endif
|
||||
@@ -260,7 +246,6 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
ret = up_addrenv_clone(&binp->addrenv, &tcb->cmn.group->tg_addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = -ret;
|
||||
berr("ERROR: up_addrenv_clone() failed: %d\n", ret);
|
||||
goto errout_with_tcbinit;
|
||||
}
|
||||
@@ -291,8 +276,8 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
ret = task_activate((FAR struct tcb_s *)tcb);
|
||||
if (ret < 0)
|
||||
{
|
||||
errcode = get_errno();
|
||||
berr("task_activate() failed: %d\n", errcode);
|
||||
ret = -get_errno();
|
||||
berr("task_activate() failed: %d\n", ret);
|
||||
goto errout_with_tcbinit;
|
||||
}
|
||||
|
||||
@@ -303,7 +288,6 @@ int exec_module(FAR const struct binary_s *binp)
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: up_addrenv_select() failed: %d\n", ret);
|
||||
errcode = -ret;
|
||||
goto errout_with_tcbinit;
|
||||
}
|
||||
#endif
|
||||
@@ -314,7 +298,7 @@ errout_with_tcbinit:
|
||||
tcb->cmn.stack_alloc_ptr = NULL;
|
||||
sched_releasetcb(&tcb->cmn, TCB_FLAG_TTYPE_TASK);
|
||||
kumm_free(stack);
|
||||
goto errout;
|
||||
return ret;
|
||||
|
||||
errout_with_addrenv:
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
@@ -323,11 +307,7 @@ errout_with_addrenv:
|
||||
errout_with_tcb:
|
||||
#endif
|
||||
kmm_free(tcb);
|
||||
|
||||
errout:
|
||||
set_errno(errcode);
|
||||
berr("returning errno: %d\n", errcode);
|
||||
return ERROR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BINFMT_DISABLE */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* binfmt/binfmt_loadmodule.c
|
||||
*
|
||||
* Copyright (C) 2009, 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2014, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -76,8 +76,8 @@
|
||||
* 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.
|
||||
* Zero (OK) is returned on success; Otherwise a negated errno value is
|
||||
* returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -91,8 +91,9 @@ static int load_default_priority(FAR struct binary_s *bin)
|
||||
ret = sched_getparam(0, ¶m);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: sched_getparam failed: %d\n", get_errno());
|
||||
return ERROR;
|
||||
ret = -get_errno();
|
||||
berr("ERROR: sched_getparam failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Save that as the priority of child thread */
|
||||
@@ -168,9 +169,9 @@ static int load_absmodule(FAR struct binary_s *bin)
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -189,9 +190,7 @@ int load_module(FAR struct binary_s *bin)
|
||||
ret = load_default_priority(bin);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* The errno is already set in this case */
|
||||
|
||||
return ERROR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Were we given a relative path? Or an absolute path to the file to
|
||||
@@ -258,16 +257,7 @@ int load_module(FAR struct binary_s *bin)
|
||||
}
|
||||
}
|
||||
|
||||
/* This is an end-user function. Return failures via errno */
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: Returning errno %d\n", -ret);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return OK;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BINFMT_DISABLE */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* binfmt/binfmt_schedunload.c
|
||||
*
|
||||
* Copyright (C) 2013, 2016 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2013, 2016-2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -227,7 +227,7 @@ static void unload_callback(int signo, siginfo_t *info, void *ucontext)
|
||||
ret = unload_module(bin);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: unload_module failed: %d\n", get_errno());
|
||||
berr("ERROR: unload_module() failed: %d\n", ret);
|
||||
}
|
||||
|
||||
/* Free the load structure */
|
||||
@@ -256,9 +256,9 @@ static void unload_callback(int signo, siginfo_t *info, void *ucontext)
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* On failures, the 'bin' structure will not be deallocated and the
|
||||
* module not not be unloaded.
|
||||
@@ -271,7 +271,6 @@ int schedule_unload(pid_t pid, FAR struct binary_s *bin)
|
||||
struct sigaction oact;
|
||||
sigset_t set;
|
||||
irqstate_t flags;
|
||||
int errorcode;
|
||||
int ret;
|
||||
|
||||
/* Make sure that SIGCHLD is unmasked */
|
||||
@@ -283,9 +282,9 @@ int schedule_unload(pid_t pid, FAR struct binary_s *bin)
|
||||
{
|
||||
/* The errno value will get trashed by the following debug output */
|
||||
|
||||
errorcode = get_errno();
|
||||
ret = -get_errno();
|
||||
berr("ERROR: sigprocmask failed: %d\n", ret);
|
||||
goto errout;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Add the structure to the list. We want to do this *before* connecting
|
||||
@@ -309,7 +308,7 @@ int schedule_unload(pid_t pid, FAR struct binary_s *bin)
|
||||
{
|
||||
/* The errno value will get trashed by the following debug output */
|
||||
|
||||
errorcode = get_errno();
|
||||
ret = -get_errno();
|
||||
berr("ERROR: sigaction failed: %d\n" , ret);
|
||||
|
||||
/* Emergency removal from the list */
|
||||
@@ -321,14 +320,9 @@ int schedule_unload(pid_t pid, FAR struct binary_s *bin)
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
||||
errout:
|
||||
set_errno(errorcode);
|
||||
return ERROR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* !CONFIG_BINFMT_DISABLE && CONFIG_SCHED_HAVE_PARENT */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* binfmt/binfmt_loadmodule.c
|
||||
*
|
||||
* Copyright (C) 2009, 2012-2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2012-2013, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -162,8 +162,7 @@ int unload_module(FAR struct binary_s *binp)
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("binp->unload() failed: %d\n", ret);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,8 +173,7 @@ int unload_module(FAR struct binary_s *binp)
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("exec_ctors() failed: %d\n", ret);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ static void pcode_onexit(int exitcode, FAR void *arg)
|
||||
|
||||
/* And unload the module */
|
||||
|
||||
unload_module(binp);
|
||||
(void)unload_module(binp);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user