4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
33 * pid = vforkx(flags);
34 * syscall trap: forksys(2, flags)
37 * syscall trap: forksys(2, 0)
40 * %edx == 0 in parent process, %edx = 1 in child process.
41 * %eax == pid of child in parent, %eax == pid of parent in child.
43 * The child gets a zero return value.
44 * The parent gets the pid of the child.
48 * The child of vfork() will execute in the parent's address space,
49 * thereby changing the stack before the parent runs again.
50 * Therefore we have to be careful how we return from vfork().
51 * Pity the poor debugger developer who has to deal with this kludge.
53 * We block all blockable signals while performing the vfork() system call
54 * trap. This enables us to set curthread->ul_vfork safely, so that we
55 * don't end up in a signal handler with curthread->ul_vfork set wrong.
59 movl
4(%esp
), %eax
/* flags */
62 xorl
%eax
, %eax
/* flags = 0 */
64 popl
%ecx
/* save return %eip in %ecx */
65 pushl
%eax
/* flags */
66 pushl $MASKSET3
/* block all signals */
72 __SYSCALLINT
(lwp_sigmask
)
77 __SYSCALLINT
(forksys
) /* vforkx(flags) */
80 /* reconstruct stack before jumping to __cerror */
83 pushl
%eax
/* save the vfork() error number */
85 pushl
%gs
:UL_SIGMASK+
12 /* reinstate signals */
86 pushl
%gs
:UL_SIGMASK+
8
87 pushl
%gs
:UL_SIGMASK+
4
91 __SYSCALLINT
(lwp_sigmask
)
94 popl
%eax
/* restore the vfork() error number */
100 * To determine if we are (still) a child of vfork(), the child
101 * increments curthread->ul_vfork by one and the parent decrements
102 * it by one. If the result is zero, then we are not a child of
103 * vfork(), else we are. We do this to deal with the case of
104 * a vfork() child calling vfork().
108 movl
%gs
:UL_VFORK
, %edx
109 cmpl $
0, %edx
/* don't let it go negative */
111 subl $
1, %edx
/* curthread->ul_vfork--; */
114 xorl
%eax
, %eax
/* zero the return value in the child */
115 movl
%gs
:UL_VFORK
, %edx
116 addl $
1, %edx
/* curthread->ul_vfork++; */
118 movl
%edx
, %gs
:UL_VFORK
120 * Clear the schedctl interface in both parent and child.
121 * (The child might have modified the parent.)
124 movl
%edx
, %gs
:UL_SCHEDCTL
125 movl
%edx
, %gs
:UL_SCHEDCTL_CALLED
126 pushl
%eax
/* save the vfork() return value */
128 pushl
%gs
:UL_SIGMASK+
12 /* reinstate signals */
129 pushl
%gs
:UL_SIGMASK+
8
130 pushl
%gs
:UL_SIGMASK+
4
134 __SYSCALLINT
(lwp_sigmask
)
137 popl
%eax
/* restore the vfork() return value */
138 jmp
*%ecx
/* jump back to the caller */