casaroli commented on code in PR #19562: URL: https://github.com/apache/nuttx/pull/19562#discussion_r3743828530
########## include/nuttx/sched.h: ########## @@ -1136,34 +1159,55 @@ void nxtask_startup(main_t entrypt, int argc, FAR char *argv[]); #endif /**************************************************************************** - * Internal fork support. The overall sequence is: - * - * 1) User code calls fork(). fork() is provided in architecture-specific - * code. - * 2) fork()and calls nxtask_setup_fork(). + * Internal support for the two cloning primitives, vfork() and fork(). The + * sequence below is common to both, and `vfork' says which one was called: + * + * vfork() the child shares the parent's memory and the parent is + * suspended until the child _exit()s or exec()s. + * fork() the child gets its own copy of the parent's memory at the same + * virtual addresses, and both run. + * + * 1) User code calls vfork() or fork(). Both are libc wrappers around + * up_fork(), which is provided in architecture-specific code. + * 2) The architecture-specific code snapshots the caller's registers and + * calls nxtask_setup_fork(). * 3) nxtask_setup_fork() allocates and configures the child task's TCB. * This consists of: * - Allocation of the child task's TCB. * - Initialization of file descriptors and streams * - Configuration of environment variables - * - Allocate and initialize the stack + * - Establishing the child's address environment: joined to the parent's + * for vfork(), duplicated from it for fork() + * - Allocating the stack, or inheriting the parent's for fork() * - Setup the input parameters for the task. * - Initialization of the TCB (including call to up_initial_state()) - * 4) fork() provides any additional operating context. fork must: + * 4) The architecture-specific code provides any additional operating + * context: * - Initialize special values in any CPU registers that were not * already configured by up_initial_state() - * 5) fork() then calls nxtask_start_fork() + * - Relocate the copied stack, unless the child shares the parent's + * 5) It then calls nxtask_start_fork(), which for vfork() additionally + * suspends the caller. * 6) nxtask_start_fork() then executes the child thread. * * nxtask_abort_fork() may be called if an error occurs between * steps 3 and 6. * + * nxtask_resume_vfork() releases a suspended vfork() parent. It is called + * from nxsched_release_tcb(), the last point in the child's life -- by which + * time the child is off the ready-to-run list and an exec()ing child has + * already handed its pid to the program it loaded. + * ****************************************************************************/ -FAR struct tcb_s *nxtask_setup_fork(start_t retaddr); -pid_t nxtask_start_fork(FAR struct tcb_s *child); +FAR struct tcb_s *nxtask_setup_fork(start_t retaddr, bool vfork); +pid_t nxtask_start_fork(FAR struct tcb_s *child, bool vfork); void nxtask_abort_fork(FAR struct tcb_s *child, int errcode); +#ifdef CONFIG_ARCH_HAVE_VFORK +void nxtask_resume_vfork(FAR struct tcb_s *child); Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
