mirror of
https://github.com/apache/nuttx.git
synced 2026-09-27 18:58:27 +08:00
Revert "Exec: Support run exec in current task"
This reverts commit 670c245ff2.
This commit is contained in:
committed by
Petro Karashchenko
parent
b1bbbfa084
commit
1b97c05ab5
@@ -61,7 +61,5 @@ if(CONFIG_BUILTIN)
|
|||||||
list(APPEND SRCS builtin.c)
|
list(APPEND SRCS builtin.c)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_include_directories(binfmt PRIVATE ${CMAKE_SOURCE_DIR}/sched)
|
|
||||||
|
|
||||||
target_sources(binfmt PRIVATE ${SRCS})
|
target_sources(binfmt PRIVATE ${SRCS})
|
||||||
target_include_directories(binfmt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(binfmt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|||||||
@@ -58,8 +58,6 @@ endif
|
|||||||
include libnxflat/Make.defs
|
include libnxflat/Make.defs
|
||||||
include libelf/Make.defs
|
include libelf/Make.defs
|
||||||
|
|
||||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)sched
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
|||||||
+8
-55
@@ -37,11 +37,11 @@
|
|||||||
#ifndef CONFIG_BINFMT_DISABLE
|
#ifndef CONFIG_BINFMT_DISABLE
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: exec_internel
|
* Name: exec_spawn
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* exec() configurable version, delivery the spawn attribute if this
|
* exec() configurable version, delivery the spawn attribute if this
|
||||||
@@ -64,7 +64,6 @@
|
|||||||
* nexports - The number of symbols in the exports table.
|
* nexports - The number of symbols in the exports table.
|
||||||
* actions - The spawn file actions
|
* actions - The spawn file actions
|
||||||
* attr - The spawn attributes.
|
* attr - The spawn attributes.
|
||||||
* spawn - Is spawn in new task.
|
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* It returns the PID of the exec'ed module. On failure, it returns
|
* It returns the PID of the exec'ed module. On failure, it returns
|
||||||
@@ -72,11 +71,10 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int exec_internel(FAR const char *filename,
|
int exec_spawn(FAR const char *filename, FAR char * const *argv,
|
||||||
FAR char * const *argv, FAR char * const *envp,
|
FAR char * const *envp, FAR const struct symtab_s *exports,
|
||||||
FAR const struct symtab_s *exports, int nexports,
|
int nexports, FAR const posix_spawn_file_actions_t *actions,
|
||||||
FAR const posix_spawn_file_actions_t *actions,
|
FAR const posix_spawnattr_t *attr)
|
||||||
FAR const posix_spawnattr_t *attr, bool spawn)
|
|
||||||
{
|
{
|
||||||
FAR struct binary_s *bin;
|
FAR struct binary_s *bin;
|
||||||
irqstate_t flags;
|
irqstate_t flags;
|
||||||
@@ -134,7 +132,7 @@ static int exec_internel(FAR const char *filename,
|
|||||||
|
|
||||||
/* Then start the module */
|
/* Then start the module */
|
||||||
|
|
||||||
pid = exec_module(bin, filename, argv, envp, actions, spawn);
|
pid = exec_module(bin, filename, argv, envp, actions);
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
{
|
{
|
||||||
ret = pid;
|
ret = pid;
|
||||||
@@ -177,50 +175,6 @@ errout:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: exec_spawn
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* exec() configurable version, delivery the spawn attribute if this
|
|
||||||
* process has special customization.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* filename - The path to the program to be executed. If
|
|
||||||
* CONFIG_LIBC_ENVPATH is defined in the configuration, then
|
|
||||||
* this may be a relative path from the current working
|
|
||||||
* directory. Otherwise, path must be the absolute path to the
|
|
||||||
* program.
|
|
||||||
* argv - A pointer to an array of string arguments. The end of the
|
|
||||||
* array is indicated with a NULL entry.
|
|
||||||
* envp - A pointer to an array of environment strings. Terminated with
|
|
||||||
* a NULL entry.
|
|
||||||
* exports - The address of the start of the caller-provided symbol
|
|
||||||
* table. This symbol table contains the addresses of symbols
|
|
||||||
* exported by the caller and made available for linking the
|
|
||||||
* module into the system.
|
|
||||||
* nexports - The number of symbols in the exports table.
|
|
||||||
* actions - The spawn file actions
|
|
||||||
* attr - The spawn attributes.
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* It returns the PID of the exec'ed module. On failure, it returns
|
|
||||||
* the negative errno value appropriately.
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
int exec_spawn(FAR const char *filename, FAR char * const *argv,
|
|
||||||
FAR char * const *envp, FAR const struct symtab_s *exports,
|
|
||||||
int nexports, FAR const posix_spawn_file_actions_t *actions,
|
|
||||||
FAR const posix_spawnattr_t *attr)
|
|
||||||
{
|
|
||||||
return exec_internel(filename, argv, envp,
|
|
||||||
exports, nexports, actions, attr, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: exec
|
* Name: exec
|
||||||
*
|
*
|
||||||
@@ -291,8 +245,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = exec_internel(filename, argv, envp,
|
ret = exec_spawn(filename, argv, envp, exports, nexports, NULL, NULL);
|
||||||
exports, nexports, NULL, NULL, false);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
set_errno(-ret);
|
set_errno(-ret);
|
||||||
|
|||||||
@@ -36,7 +36,6 @@
|
|||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/kmalloc.h>
|
#include <nuttx/kmalloc.h>
|
||||||
#include <nuttx/sched.h>
|
#include <nuttx/sched.h>
|
||||||
#include <sched/sched.h>
|
|
||||||
#include <nuttx/spawn.h>
|
#include <nuttx/spawn.h>
|
||||||
#include <nuttx/binfmt/binfmt.h>
|
#include <nuttx/binfmt/binfmt.h>
|
||||||
|
|
||||||
@@ -97,91 +96,6 @@ static void exec_ctors(FAR void *arg)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: exec_swap
|
|
||||||
*
|
|
||||||
* Description:
|
|
||||||
* swap the pid of tasks, and reverse parent-child relationship.
|
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* ptcb - parent task tcb.
|
|
||||||
* chtcb - child task tcb.
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* none
|
|
||||||
*
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void exec_swap(FAR struct tcb_s *ptcb, FAR struct tcb_s *chtcb)
|
|
||||||
{
|
|
||||||
int pndx;
|
|
||||||
int chndx;
|
|
||||||
pid_t pid;
|
|
||||||
irqstate_t flags;
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
|
||||||
FAR pid_t *tg_members;
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
||||||
# ifdef CONFIG_SCHED_CHILD_STATUS
|
|
||||||
FAR struct child_status_s *tg_children;
|
|
||||||
# else
|
|
||||||
uint16_t tg_nchildren;
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DEBUGASSERT(ptcb);
|
|
||||||
DEBUGASSERT(chtcb);
|
|
||||||
|
|
||||||
flags = enter_critical_section();
|
|
||||||
|
|
||||||
pndx = PIDHASH(ptcb->pid);
|
|
||||||
chndx = PIDHASH(chtcb->pid);
|
|
||||||
|
|
||||||
DEBUGASSERT(g_pidhash[pndx]);
|
|
||||||
DEBUGASSERT(g_pidhash[chndx]);
|
|
||||||
|
|
||||||
/* Exchange g_pidhash index */
|
|
||||||
|
|
||||||
g_pidhash[pndx] = chtcb;
|
|
||||||
g_pidhash[chndx] = ptcb;
|
|
||||||
|
|
||||||
/* Exchange pid */
|
|
||||||
|
|
||||||
pid = chtcb->pid;
|
|
||||||
chtcb->pid = ptcb->pid;
|
|
||||||
ptcb->pid = pid;
|
|
||||||
|
|
||||||
/* Exchange group info. This will reverse parent-child relationship */
|
|
||||||
|
|
||||||
pid = chtcb->group->tg_pid;
|
|
||||||
chtcb->group->tg_pid = ptcb->group->tg_pid;
|
|
||||||
ptcb->group->tg_pid = pid;
|
|
||||||
|
|
||||||
pid = chtcb->group->tg_ppid;
|
|
||||||
chtcb->group->tg_ppid = ptcb->group->tg_ppid;
|
|
||||||
ptcb->group->tg_ppid = pid;
|
|
||||||
|
|
||||||
#ifdef HAVE_GROUP_MEMBERS
|
|
||||||
tg_members = chtcb->group->tg_members;
|
|
||||||
chtcb->group->tg_members = ptcb->group->tg_members;
|
|
||||||
ptcb->group->tg_members = tg_members;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
||||||
# ifdef CONFIG_SCHED_CHILD_STATUS
|
|
||||||
tg_children = chtcb->group->tg_children;
|
|
||||||
chtcb->group->tg_children = ptcb->group->tg_children;
|
|
||||||
ptcb->group->tg_children = tg_children;
|
|
||||||
# else
|
|
||||||
tg_nchildren = chtcb->group->tg_nchildren;
|
|
||||||
chtcb->group->tg_nchildren = ptcb->group->tg_nchildren;
|
|
||||||
ptcb->group->tg_nchildren = tg_nchildren;
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
leave_critical_section(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -202,8 +116,7 @@ static void exec_swap(FAR struct tcb_s *ptcb, FAR struct tcb_s *chtcb)
|
|||||||
int exec_module(FAR struct binary_s *binp,
|
int exec_module(FAR struct binary_s *binp,
|
||||||
FAR const char *filename, FAR char * const *argv,
|
FAR const char *filename, FAR char * const *argv,
|
||||||
FAR char * const *envp,
|
FAR char * const *envp,
|
||||||
FAR const posix_spawn_file_actions_t *actions,
|
FAR const posix_spawn_file_actions_t *actions)
|
||||||
bool spawn)
|
|
||||||
{
|
{
|
||||||
FAR struct task_tcb_s *tcb;
|
FAR struct task_tcb_s *tcb;
|
||||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||||
@@ -379,11 +292,6 @@ int exec_module(FAR struct binary_s *binp,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!spawn)
|
|
||||||
{
|
|
||||||
exec_swap(this_task(), (FAR struct tcb_s *)tcb);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then activate the task at the provided priority */
|
/* Then activate the task at the provided priority */
|
||||||
|
|
||||||
nxtask_activate((FAR struct tcb_s *)tcb);
|
nxtask_activate((FAR struct tcb_s *)tcb);
|
||||||
|
|||||||
@@ -270,8 +270,7 @@ int unload_module(FAR struct binary_s *bin);
|
|||||||
int exec_module(FAR struct binary_s *binp,
|
int exec_module(FAR struct binary_s *binp,
|
||||||
FAR const char *filename, FAR char * const *argv,
|
FAR const char *filename, FAR char * const *argv,
|
||||||
FAR char * const *envp,
|
FAR char * const *envp,
|
||||||
FAR const posix_spawn_file_actions_t *actions,
|
FAR const posix_spawn_file_actions_t *actions);
|
||||||
bool spawn);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: exec
|
* Name: exec
|
||||||
|
|||||||
Reference in New Issue
Block a user