You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2024/08/01 13:58:31 UTC

(nuttx) branch master updated: task_fork.c: Fix vfork for BUILD_KERNEL

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 6047a9fe14 task_fork.c: Fix vfork for BUILD_KERNEL
6047a9fe14 is described below

commit 6047a9fe146ad4b4e8b2dc7bffe92d9075db429f
Author: Ville Juven <vi...@unikie.com>
AuthorDate: Thu Aug 1 12:41:41 2024 +0300

    task_fork.c: Fix vfork for BUILD_KERNEL
    
    Two things need to be done when vfork'ing:
    - Must attach to parent's address environment (the addrenv is shared)
    - Must allocate a kernel stack (where would the register context go otherwise)
    
    Note that this code assumes the address environment is shared, since we
    don't support fork() which would _clone_ the address environment instead.
---
 sched/task/task_fork.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/sched/task/task_fork.c b/sched/task/task_fork.c
index 51b61f93fb..00ade225f3 100644
--- a/sched/task/task_fork.c
+++ b/sched/task/task_fork.c
@@ -145,6 +145,19 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
 
   child->cmn.flags |= TCB_FLAG_FREE_TCB;
 
+#if defined(CONFIG_ARCH_ADDRENV)
+  /* Join the parent address environment (REVISIT: vfork() only) */
+
+  if (ttype != TCB_FLAG_TTYPE_KERNEL)
+    {
+      ret = addrenv_join(parent, &child->cmn);
+      if (ret < 0)
+        {
+          goto errout_with_tcb;
+        }
+    }
+#endif
+
   /* Initialize the task join */
 
   nxtask_joininit(&child->cmn);
@@ -184,6 +197,19 @@ FAR struct task_tcb_s *nxtask_setup_fork(start_t retaddr)
       goto errout_with_tcb;
     }
 
+#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_ARCH_KERNEL_STACK)
+  /* Allocate the kernel stack */
+
+  if (ttype != TCB_FLAG_TTYPE_KERNEL)
+    {
+      ret = up_addrenv_kstackalloc(&child->cmn);
+      if (ret < 0)
+        {
+          goto errout_with_tcb;
+        }
+    }
+#endif
+
   /* Setup thread local storage */
 
   ret = tls_dup_info(&child->cmn, parent);