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 .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, %o3 /* flags */ 63 ENTRY_NP(vfork) 64 clr %o3 /* flags = 0 */ 650: 66 mov SIG_SETMASK, %o0 /* block all signals */ 67 set MASKSET0, %o1 68 set MASKSET1, %o2 69 SYSTRAP_2RVALS(lwp_sigmask) 70 71 mov %o3, %o1 /* flags */ 72 mov 2, %o0 73 SYSTRAP_2RVALS(forksys) /* vforkx(flags) */ 74 bcc,a,pt %icc, 1f 75 tst %o1 76 77 mov %o0, %o3 /* save the vfork() error number */ 78 79 mov SIG_SETMASK, %o0 /* reinstate signals */ 80 ld [%g7 + UL_SIGMASK], %o1 81 ld [%g7 + UL_SIGMASK + 4], %o2 82 SYSTRAP_2RVALS(lwp_sigmask) 83 84 ba __cerror 85 mov %o3, %o0 /* restore the vfork() error number */ 86 871: 88 /* 89 * To determine if we are (still) a child of vfork(), the child 90 * increments curthread->ul_vfork by one and the parent decrements 91 * it by one. If the result is zero, then we are not a child of 92 * vfork(), else we are. We do this to deal with the case of 93 * a vfork() child calling vfork(). 94 */ 95 bnz,pt %icc, 2f 96 ld [%g7 + UL_VFORK], %g1 97 brnz,a,pt %g1, 3f /* don't let it go negative */ 98 sub %g1, 1, %g1 /* curthread->ul_vfork--; */ 99 ba,a 3f 1002: 101 clr %o0 /* zero the return value in the child */ 102 add %g1, 1, %g1 /* curthread->ul_vfork++; */ 1033: 104 st %g1, [%g7 + UL_VFORK] 105 /* 106 * Clear the schedctl interface in both parent and child. 107 * (The child might have modified the parent.) 108 */ 109 stn %g0, [%g7 + UL_SCHEDCTL] 110 stn %g0, [%g7 + UL_SCHEDCTL_CALLED] 111 mov %o0, %o3 /* save the vfork() return value */ 112 113 mov SIG_SETMASK, %o0 /* reinstate signals */ 114 ld [%g7 + UL_SIGMASK], %o1 115 ld [%g7 + UL_SIGMASK + 4], %o2 116 SYSTRAP_2RVALS(lwp_sigmask) 117 118 retl 119 mov %o3, %o0 /* restore the vfork() return value */ 120 SET_SIZE(vfork) 121 SET_SIZE(vforkx) 122