CPU_LWP_FORK(9) | Kernel Developer's Manual | CPU_LWP_FORK(9) |
void
cpu_lwp_fork(struct lwp *l1, struct lwp *l2, void *stack, size_t stacksize, void (*func)(void *), void *arg);
void
child_return(void *arg);
cpu_lwp_fork() rigs the child's kernel stack so that it will start in proc_trampoline(). proc_trampoline() does not have a normal calling sequence and is entered by cpu_switch(). If an alternate user-level stack is requested (with non-zero values in both the stack and stacksize arguments), the user stack pointer is set up accordingly.
After being entered by cpu_switch() and while running in user context (within the kernel) proc_trampoline() will invoke the function func with the argument arg. If a kernel thread is being created, the return path and argument are specified with func and arg. If a user process is being created, fork1() will pass child_return() and l2 to cpu_lwp_fork() as func and arg respectively. This causes the newly-created child process to go directly to user level with an apparent return value of 0 from fork(2), while the parent process returns normally.
April 13, 2010 | NetBSD 6.1 |