This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new dcafd95  sched: group: Fix dataabort when exiting task or pthread if 
ARCH_ADDRENV=y
dcafd95 is described below

commit dcafd9597128d4d8273ea74f97ecd1e8eda584d5
Author: Masayuki Ishikawa <[email protected]>
AuthorDate: Sun Feb 27 21:39:43 2022 +0900

    sched: group: Fix dataabort when exiting task or pthread if ARCH_ADDRENV=y
    
    Summary:
    - I noticed that exiting task or pthread causes dataabort if ARCH_ADDRENV=y
    - This commit fixes this issue by switching the addrenv correctly
    
    Impact:
    - CONFIG_ARCH_ADDRENV=y only
    
    Testing:
    - Tested with sabre-6quad:netknsh (not merged yet)
    
    Signed-off-by: Masayuki Ishikawa <[email protected]>
---
 sched/group/group_create.c | 26 ++++++++++++++++++++++++++
 sched/group/group_leave.c  | 11 ++++++-----
 2 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/sched/group/group_create.c b/sched/group/group_create.c
index d699beb..6f2aa1b 100644
--- a/sched/group/group_create.c
+++ b/sched/group/group_create.c
@@ -244,13 +244,39 @@ void group_deallocate(FAR struct task_group_s *group)
 {
   if (group)
     {
+#ifdef CONFIG_ARCH_ADDRENV
+      save_addrenv_t oldenv;
+
+      /* NOTE: switch the addrenv before accessing group->tg_info
+       * located in the userland, also save the current addrenv
+       */
+
+      up_addrenv_select(&group->tg_addrenv, &oldenv);
+#endif
+
       if (group->tg_info)
         {
           nxsem_destroy(&group->tg_info->ta_sem);
           group_free(group, group->tg_info);
         }
 
+#ifdef CONFIG_ARCH_ADDRENV
+      /* Destroy the group address environment */
+
+      up_addrenv_destroy(&group->tg_addrenv);
+
+      /* Mark no address environment */
+
+      g_pid_current = INVALID_PROCESS_ID;
+#endif
+
       kmm_free(group);
+
+#ifdef CONFIG_ARCH_ADDRENV
+      /* Restore the previous addrenv */
+
+      up_addrenv_restore(&oldenv);
+#endif
     }
 }
 
diff --git a/sched/group/group_leave.c b/sched/group/group_leave.c
index 455a534..d1b52f5 100644
--- a/sched/group/group_leave.c
+++ b/sched/group/group_leave.c
@@ -175,11 +175,12 @@ static inline void group_release(FAR struct task_group_s 
*group)
 #endif
 
 #ifdef CONFIG_ARCH_ADDRENV
-  /* Destroy the group address environment */
-
-  up_addrenv_destroy(&group->tg_addrenv);
-
-  /* Mark no address environment */
+  /* NOTE:
+   * We do not destroy the group address environment here.
+   * It will be done in the group_deallocate().
+   * However, we mark no address environment here,
+   * so that group_addrenv() can work correctly
+   */
 
   g_pid_current = INVALID_PROCESS_ID;
 #endif

Reply via email to