1*c4c8c26cSscole.\" $NetBSD: cpu_lwp_fork.9,v 1.7 2018/04/26 14:59:11 scole Exp $ 27d7fe4b7Srpaulo.\" 3ff8e3c8cSrpaulo.\" Copyright (c) 2002, 2005, 2006 The NetBSD Foundation, Inc. 47d7fe4b7Srpaulo.\" All rights reserved. 57d7fe4b7Srpaulo.\" 67d7fe4b7Srpaulo.\" This code is derived from software contributed to The NetBSD Foundation 77d7fe4b7Srpaulo.\" by Gregory McGarry; and Rui Paulo. 87d7fe4b7Srpaulo.\" 97d7fe4b7Srpaulo.\" Redistribution and use in source and binary forms, with or without 107d7fe4b7Srpaulo.\" modification, are permitted provided that the following conditions 117d7fe4b7Srpaulo.\" are met: 127d7fe4b7Srpaulo.\" 1. Redistributions of source code must retain the above copyright 137d7fe4b7Srpaulo.\" notice, this list of conditions and the following disclaimer. 147d7fe4b7Srpaulo.\" 2. Redistributions in binary form must reproduce the above copyright 157d7fe4b7Srpaulo.\" notice, this list of conditions and the following disclaimer in the 167d7fe4b7Srpaulo.\" documentation and/or other materials provided with the distribution. 177d7fe4b7Srpaulo.\" 187d7fe4b7Srpaulo.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 197d7fe4b7Srpaulo.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 207d7fe4b7Srpaulo.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 217d7fe4b7Srpaulo.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 227d7fe4b7Srpaulo.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 237d7fe4b7Srpaulo.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 247d7fe4b7Srpaulo.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 257d7fe4b7Srpaulo.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 267d7fe4b7Srpaulo.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 277d7fe4b7Srpaulo.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 287d7fe4b7Srpaulo.\" POSSIBILITY OF SUCH DAMAGE. 297d7fe4b7Srpaulo.\" 30*c4c8c26cSscole.Dd April 26, 2018 317d7fe4b7Srpaulo.Dt CPU_LWP_FORK 9 327d7fe4b7Srpaulo.Os 337d7fe4b7Srpaulo.Sh NAME 347d7fe4b7Srpaulo.Nm cpu_lwp_fork , 357d7fe4b7Srpaulo.Nm child_return , 362f5e87a5Smartin.Nm lwp_trampoline 377d7fe4b7Srpaulo.Nd finish a fork operation 387d7fe4b7Srpaulo.Sh SYNOPSIS 397d7fe4b7Srpaulo.In sys/proc.h 407d7fe4b7Srpaulo.Ft void 417d7fe4b7Srpaulo.Fn cpu_lwp_fork "struct lwp *l1" "struct lwp *l2" "void *stack" \ 427d7fe4b7Srpaulo"size_t stacksize" "void (*func)(void *)" "void *arg" 437d7fe4b7Srpaulo.Ft void 447d7fe4b7Srpaulo.Fn child_return "void *arg" 457d7fe4b7Srpaulo.Sh DESCRIPTION 467d7fe4b7Srpaulo.Fn cpu_lwp_fork 477d7fe4b7Srpaulois the machine-dependent portion of 487d7fe4b7Srpaulo.Fn fork1 49ff8e3c8cSrpaulowhich finishes a fork operation, with child lwp 50ff8e3c8cSrpaulo.Fa l2 517d7fe4b7Srpaulonearly set up. 527d7fe4b7SrpauloIt copies and updates the PCB and trap frame from the parent 53ff8e3c8cSrpaulo.Fa l1 , 547d7fe4b7Srpaulomaking the child ready to run. 557d7fe4b7Srpaulo.Pp 567d7fe4b7Srpaulo.Fn cpu_lwp_fork 577d7fe4b7Srpaulorigs the child's kernel stack so that it will start in 582f5e87a5Smartin.Fn lwp_trampoline . 592f5e87a5Smartin.Fn lwp_trampoline 607d7fe4b7Srpaulodoes not have a normal calling sequence and is entered by 61*c4c8c26cSscole.Fn cpu_switchto . 627d7fe4b7SrpauloIf an alternate user-level stack is requested (with non-zero values 637d7fe4b7Srpauloin both the 647d7fe4b7Srpaulo.Fa stack 657d7fe4b7Srpauloand 667d7fe4b7Srpaulo.Fa stacksize 677d7fe4b7Srpauloarguments), the user stack pointer is set up accordingly. 687d7fe4b7Srpaulo.Pp 697d7fe4b7SrpauloAfter being entered by 70*c4c8c26cSscole.Fn cpu_switchto 717d7fe4b7Srpauloand while running in user context (within the kernel) 722f5e87a5Smartin.Fn lwp_trampoline 737d7fe4b7Srpaulowill invoke the function 747d7fe4b7Srpaulo.Fa func 757d7fe4b7Srpaulowith the argument 767d7fe4b7Srpaulo.Fa arg . 777d7fe4b7SrpauloIf a kernel thread is being created, the return path and argument 787d7fe4b7Srpauloare specified with 797d7fe4b7Srpaulo.Fa func 807d7fe4b7Srpauloand 817d7fe4b7Srpaulo.Fa arg . 827d7fe4b7SrpauloIf a user process is being created, 837d7fe4b7Srpaulo.Fn fork1 847d7fe4b7Srpaulowill pass 857d7fe4b7Srpaulo.Fn child_return 867d7fe4b7Srpauloand 87ff8e3c8cSrpaulo.Fa l2 887d7fe4b7Srpauloto 897d7fe4b7Srpaulo.Fn cpu_lwp_fork 907d7fe4b7Srpauloas 917d7fe4b7Srpaulo.Fa func 927d7fe4b7Srpauloand 937d7fe4b7Srpaulo.Fa arg 947d7fe4b7Srpaulorespectively. 957d7fe4b7SrpauloThis causes the newly-created child process to go directly to user 967d7fe4b7Srpaulolevel with an apparent return value of 0 from 977d7fe4b7Srpaulo.Xr fork 2 , 987d7fe4b7Srpaulowhile the parent process returns normally. 997d7fe4b7Srpaulo.Sh SEE ALSO 1007d7fe4b7Srpaulo.Xr fork 2 , 101a8e44989Sjruoho.Xr cpu_switchto 9 , 1027d7fe4b7Srpaulo.Xr fork1 9 103