xref: /illumos-gate/usr/src/lib/libc/sparc/sys/vforkx.S (revision 0dd92943508086ca1800de461a7c66109737bcd5)
1/*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/*	Copyright (c) 1988 AT&T	*/
28/*	  All Rights Reserved	*/
29
30	.file	"vforkx.s"
31
32#include "SYS.h"
33#include <assym.h>
34
35/*
36 * pid = vforkx(flags);
37 * syscall trap: forksys(2, flags)
38 *
39 * pid = vfork();
40 * syscall trap: forksys(2, 0)
41 *
42 * From the syscall:
43 * %o1 == 0 in parent process, %o1 == 1 in child process.
44 * %o0 == pid of child in parent, %o0 == pid of parent in child.
45 *
46 * The child gets a zero return value.
47 * The parent gets the pid of the child.
48 */
49
50/*
51 * Note that since the SPARC architecture maintains stack maintence
52 * information (return pc, sp, fp) in the register windows, both parent
53 * and child can execute in a common address space without conflict.
54 *
55 * We block all blockable signals while performing the vfork() system call
56 * trap.  This enables us to set curthread->ul_vfork safely, so that we
57 * don't end up in a signal handler with curthread->ul_vfork set wrong.
58 */
59
60	ENTRY_NP(vforkx)
61	ba	0f
62	mov	%o0, %o5		/* flags */
63	ENTRY_NP(vfork)
64	clr	%o5			/* flags = 0 */
650:
66	mov	SIG_SETMASK, %o0	/* block all signals */
67	set	MASKSET0, %o1
68	set	MASKSET1, %o2
69	set	MASKSET2, %o3
70	set	MASKSET3, %o4
71	SYSTRAP_RVAL1(lwp_sigmask)
72
73	mov	%o5, %o1		/* flags */
74	mov	2, %o0
75	SYSTRAP_2RVALS(forksys)		/* vforkx(flags) */
76	bcc,a,pt %icc, 1f
77	tst	%o1
78
79	mov	%o0, %o5		/* save the vfork() error number */
80
81	mov	SIG_SETMASK, %o0	/* reinstate signals */
82	ld	[%g7 + UL_SIGMASK], %o1
83	ld	[%g7 + UL_SIGMASK + 4], %o2
84	ld	[%g7 + UL_SIGMASK + 8], %o3
85	ld	[%g7 + UL_SIGMASK + 12], %o4
86	SYSTRAP_RVAL1(lwp_sigmask)
87
88	ba	__cerror
89	mov	%o5, %o0		/* restore the vfork() error number */
90
911:
92	/*
93	 * To determine if we are (still) a child of vfork(), the child
94	 * increments curthread->ul_vfork by one and the parent decrements
95	 * it by one.  If the result is zero, then we are not a child of
96	 * vfork(), else we are.  We do this to deal with the case of
97	 * a vfork() child calling vfork().
98	 */
99	bnz,pt	%icc, 2f
100	ld	[%g7 + UL_VFORK], %g1
101	brnz,a,pt %g1, 3f		/* don't let it go negative */
102	sub	%g1, 1, %g1		/* curthread->ul_vfork--; */
103	ba,a	3f
1042:
105	clr	%o0			/* zero the return value in the child */
106	add	%g1, 1, %g1		/* curthread->ul_vfork++; */
1073:
108	st	%g1, [%g7 + UL_VFORK]
109	/*
110	 * Clear the schedctl interface in both parent and child.
111	 * (The child might have modified the parent.)
112	 */
113	stn	%g0, [%g7 + UL_SCHEDCTL]
114	stn	%g0, [%g7 + UL_SCHEDCTL_CALLED]
115	mov	%o0, %o5		/* save the vfork() return value */
116
117	mov	SIG_SETMASK, %o0	/* reinstate signals */
118	ld	[%g7 + UL_SIGMASK], %o1
119	ld	[%g7 + UL_SIGMASK + 4], %o2
120	ld	[%g7 + UL_SIGMASK + 8], %o3
121	ld	[%g7 + UL_SIGMASK + 12], %o4
122	SYSTRAP_RVAL1(lwp_sigmask)
123
124	retl
125	mov	%o5, %o0		/* restore the vfork() return value */
126	SET_SIZE(vfork)
127	SET_SIZE(vforkx)
128