1.\" $NetBSD: cpu_lwp_fork.9,v 1.2 2006/01/29 03:09:19 rpaulo Exp $ 2.\" 3.\" Copyright (c) 2002, 2005, 2006 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Gregory McGarry; and Rui Paulo. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd January 29, 2006 38.Dt CPU_LWP_FORK 9 39.Os 40.Sh NAME 41.Nm cpu_lwp_fork , 42.Nm child_return , 43.Nm proc_trampoline 44.Nd finish a fork operation 45.Sh SYNOPSIS 46.In sys/proc.h 47.Ft void 48.Fn cpu_lwp_fork "struct lwp *l1" "struct lwp *l2" "void *stack" \ 49"size_t stacksize" "void (*func)(void *)" "void *arg" 50.Ft void 51.Fn child_return "void *arg" 52.Sh DESCRIPTION 53.Fn cpu_lwp_fork 54is the machine-dependent portion of 55.Fn fork1 56which finishes a fork operation, with child lwp 57.Fa l2 58nearly set up. 59It copies and updates the PCB and trap frame from the parent 60.Fa l1 , 61making the child ready to run. 62.Pp 63.Fn cpu_lwp_fork 64rigs the child's kernel stack so that it will start in 65.Fn proc_trampoline . 66.Fn proc_trampoline 67does not have a normal calling sequence and is entered by 68.Fn cpu_switch . 69If an alternate user-level stack is requested (with non-zero values 70in both the 71.Fa stack 72and 73.Fa stacksize 74arguments), the user stack pointer is set up accordingly. 75.Pp 76After being entered by 77.Fn cpu_switch 78and while running in user context (within the kernel) 79.Fn proc_trampoline 80will invoke the function 81.Fa func 82with the argument 83.Fa arg . 84If a kernel thread is being created, the return path and argument 85are specified with 86.Fa func 87and 88.Fa arg . 89If a user process is being created, 90.Fn fork1 91will pass 92.Fn child_return 93and 94.Fa l2 95to 96.Fn cpu_lwp_fork 97as 98.Fa func 99and 100.Fa arg 101respectively. 102This causes the newly-created child process to go directly to user 103level with an apparent return value of 0 from 104.Xr fork 2 , 105while the parent process returns normally. 106.Sh SEE ALSO 107.Xr fork 2 , 108.Xr cpu_switch 9 , 109.Xr fork1 9 110