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