]> git.saurik.com Git - apple/libc.git/blob - ppc/sys/vfork.s
d345e457a913aaa695d2d27cee22be8191b09224
[apple/libc.git] / ppc / sys / vfork.s
1 /*
2 * Copyright (c) 1999-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /* Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
24 *
25 * File: libc/ppc/sys/vfork.s
26 *
27 * HISTORY
28 * 23-Jun-1998 Umesh Vaishampayan (umeshv@apple.com)
29 * Created from fork.s
30 *
31 */
32
33 /* We use mode-independent "g" opcodes such as "srgi", and/or
34 * mode-independent macros such as MI_GET_ADDRESS. These expand
35 * into word operations when targeting __ppc__, and into doubleword
36 * operations when targeting __ppc64__.
37 */
38 #include <architecture/ppc/mode_independent_asm.h>
39
40 /* In vfork(), the child runs in parent's address space. */
41
42 #include "SYS.h"
43
44 MI_ENTRY_POINT(_vfork)
45 MI_GET_ADDRESS(r5,__current_pid) // get address of __current_pid in r5
46 2:
47 lwarx r6,0,r5 // don't cache pid across vfork
48 cmpwi r6,0
49 ble-- 3f // is another vfork in progress
50 li r6,0 // if not, erase the stored pid
51 3:
52 addi r6,r6,-1 // count the parallel vforks in
53 stwcx. r6,0,r5 // negative cached pid values
54 bne-- 2b
55
56 li r0,SYS_vfork
57 sc
58 b Lbotch // error return
59
60 cmpwi r4,0
61 beq Lparent // parent, since a1 == 0 in parent,
62
63 li r3,0 // child
64 blr
65
66 Lparent: // r3 == child's pid
67 lwarx r6,0,r5 // we're back, decrement vfork count
68 addi r6,r6,1
69 stwcx. r6,0,r5
70 bne-- Lparent
71 blr // return pid
72
73 Lbotch:
74 lwarx r6,0,r5 // never went, decrement vfork count
75 addi r6,r6,1
76 stwcx. r6,0,r5
77 bne-- Lbotch
78
79 MI_BRANCH_EXTERNAL(cerror)
80