From ad53cabf343c72329864d22f976eb12f6cb916a9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 27 Aug 2014 09:37:28 -0600 Subject: [PATCH] ADDRENV: Use a group flag to determine if there is an address environment (instead of the thread type) --- binfmt/binfmt_execmodule.c | 4 ++++ include/nuttx/sched.h | 1 + sched/group/group_addrenv.c | 23 +++++++++++++++-------- sched/group/group_leave.c | 4 ++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/binfmt/binfmt_execmodule.c b/binfmt/binfmt_execmodule.c index 5d49acf747..07c5072336 100644 --- a/binfmt/binfmt_execmodule.c +++ b/binfmt/binfmt_execmodule.c @@ -215,6 +215,10 @@ int exec_module(FAR const struct binary_s *binp) bdbg("ERROR: up_addrenv_clone() failed: %d\n", ret); goto errout_with_stack; } + + /* Mark that this group has an address environment */ + + tcb->cmn.group->tg_flags |= GROUP_FLAG_ADDRENV; #endif #ifdef CONFIG_BINFMT_CONSTRUCTORS diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index 7a4004d9a8..ecff5de230 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -133,6 +133,7 @@ /* Values for struct task_group tg_flags */ #define GROUP_FLAG_NOCLDWAIT (1 << 0) /* Bit 0: Do not retain child exit status */ +#define GROUP_FLAG_ADDRENV (1 << 1) /* Bit 1: Group has an address environment */ /* Values for struct child_status_s ch_flags */ diff --git a/sched/group/group_addrenv.c b/sched/group/group_addrenv.c index 48e61fd4a3..35dcab9cab 100644 --- a/sched/group/group_addrenv.c +++ b/sched/group/group_addrenv.c @@ -110,16 +110,22 @@ int group_addrenv(FAR struct tcb_s *tcb) DEBUGASSERT(tcb && tcb->group); group = tcb->group; - /* What is the ID of the group of the new thread to run? Use zero if the - * group is a kernel thread. - */ + /* Does the group have an address environment? */ - gid = 0; - if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL) + if ((group->tg_flags & GROUP_FLAG_ADDRENV) == 0) { - gid = group->tg_gid; + /* No... just return perhaps leaving a different address environment + * intact. + */ + + return OK; } + /* Get the ID of the group that needs the address environment */ + + gid = group->tg_gid; + DEBUGASSERT(gid != 0); + /* Are we going to change address environments? */ flags = irqsave(); @@ -129,10 +135,11 @@ int group_addrenv(FAR struct tcb_s *tcb) if (g_gid_current != 0) { - /* Find the old group this this ID */ + /* Find the old group with this ID. */ oldgroup = group_findbygid(g_gid_current); - DEBUGASSERT(oldgroup); + DEBUGASSERT(oldgroup && + (oldgroup->tg_flags & GROUP_FLAG_ADDRENV) != 0); if (oldgroup) { diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c index e3606f2eeb..403fe4c95c 100644 --- a/sched/group/group_leave.c +++ b/sched/group/group_leave.c @@ -212,6 +212,10 @@ static inline void group_release(FAR struct task_group_s *group) /* Destroy the group address environment */ (void)up_addrenv_destroy(&group->addrenv); + + /* Mark no address environment */ + + g_gid_current = 0; #endif #if defined(HAVE_GROUP_MEMBERS) || defined(CONFIG_ARCH_ADDRENV)