xref: /titanic_41/usr/src/lib/libc/sparc/sys/vforkx.s (revision a18dc42fc967d11feba9b8be61c6727dc6c56b48)
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 2008 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#pragma ident	"%Z%%M%	%I%	%E% SMI"
31
32	.file	"%M%"
33
34#include "SYS.h"
35#include <assym.h>
36
37/*
38 * pid = vforkx(flags);
39 * syscall trap: forksys(2, flags)
40 *
41 * pid = vfork();
42 * syscall trap: forksys(2, 0)
43 *
44 * From the syscall:
45 * %o1 == 0 in parent process, %o1 == 1 in child process.
46 * %o0 == pid of child in parent, %o0 == pid of parent in child.
47 *
48 * The child gets a zero return value.
49 * The parent gets the pid of the child.
50 */
51
52/*
53 * Note that since the SPARC architecture maintains stack maintence
54 * information (return pc, sp, fp) in the register windows, both parent
55 * and child can execute in a common address space without conflict.
56 *
57 * We block all blockable signals while performing the vfork() system call
58 * trap.  This enables us to set curthread->ul_vfork safely, so that we
59 * don't end up in a signal handler with curthread->ul_vfork set wrong.
60 */
61
62	ENTRY_NP(vforkx)
63	ba	0f
64	mov	%o0, %o3		/* flags */
65	ENTRY_NP(vfork)
66	clr	%o3			/* flags = 0 */
670:
68	mov	SIG_SETMASK, %o0	/* block all signals */
69	set	MASKSET0, %o1
70	set	MASKSET1, %o2
71	SYSTRAP_2RVALS(lwp_sigmask)
72
73	mov	%o3, %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, %o3		/* 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	SYSTRAP_2RVALS(lwp_sigmask)
85
86	ba	__cerror
87	mov	%o3, %o0		/* restore the vfork() error number */
88
891:
90	/*
91	 * To determine if we are (still) a child of vfork(), the child
92	 * increments curthread->ul_vfork by one and the parent decrements
93	 * it by one.  If the result is zero, then we are not a child of
94	 * vfork(), else we are.  We do this to deal with the case of
95	 * a vfork() child calling vfork().
96	 */
97	bnz,pt	%icc, 2f
98	ld	[%g7 + UL_VFORK], %g1
99	brnz,a,pt %g1, 3f		/* don't let it go negative */
100	sub	%g1, 1, %g1		/* curthread->ul_vfork--; */
101	ba,a	3f
1022:
103	clr	%o0			/* zero the return value in the child */
104	add	%g1, 1, %g1		/* curthread->ul_vfork++; */
1053:
106	st	%g1, [%g7 + UL_VFORK]
107	/*
108	 * Clear the schedctl interface in both parent and child.
109	 * (The child might have modified the parent.)
110	 */
111	stn	%g0, [%g7 + UL_SCHEDCTL]
112	stn	%g0, [%g7 + UL_SCHEDCTL_CALLED]
113	mov	%o0, %o3		/* save the vfork() return value */
114
115	mov	SIG_SETMASK, %o0	/* reinstate signals */
116	ld	[%g7 + UL_SIGMASK], %o1
117	ld	[%g7 + UL_SIGMASK + 4], %o2
118	SYSTRAP_2RVALS(lwp_sigmask)
119
120	retl
121	mov	%o3, %o0		/* restore the vfork() return value */
122	SET_SIZE(vfork)
123	SET_SIZE(vforkx)
124