2 * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
30 * File: libc/ppc/sys/vfork.s
33 * 23-Jun-1998 Umesh Vaishampayan (umeshv@apple.com)
42 #if defined(__DYNAMIC__)
43 #define GET_CURRENT_PID PICIFY(__current_pid)
45 NON_LAZY_STUB(__current_pid)
46 #define __current_pid (%edx)
48 #define GET_CURRENT_PID
52 * If __current_pid >= 0, we want to put a -1 in there
53 * otherwise we just decrement it
58 movl __current_pid, %eax
65 cmpxchgl %ecx, __current_pid
68 movl $(SYS_vfork), %eax // code for vfork -> eax
69 UNIX_SYSCALL_TRAP // do the system call
70 jnb L1 // jump if CF==0
75 BRANCH_EXTERN(tramp_cerror)
78 testl %edx, %edx // CF=OF=0, ZF set if zero result
79 jz L2 // parent, since r1 == 0 in parent, 1 in child
80 xorl %eax, %eax // zero eax
89 #elif defined(__x86_64__)
92 * If __current_pid >= 0, we want to put a -1 in there
93 * otherwise we just decrement it
97 movq __current_pid@GOTPCREL(%rip), %rax
104 movq __current_pid@GOTPCREL(%rip), %rdx
106 cmpxchgl %ecx, (%rdx)
108 popq %rdi // return address in %rdi
109 movq $ SYSCALL_CONSTRUCT_UNIX(SYS_vfork), %rax // code for vfork -> rax
110 UNIX_SYSCALL_TRAP // do the system call
111 jnb L1 // jump if CF==0
112 pushq %rdi // put return address back on stack for cerror
113 movq __current_pid@GOTPCREL(%rip), %rcx
117 BRANCH_EXTERN(_cerror)
120 testl %edx, %edx // CF=OF=0, ZF set if zero result
121 jz L2 // parent, since r1 == 0 in parent, 1 in child
122 xorq %rax, %rax // zero rax
126 movq __current_pid@GOTPCREL(%rip), %rdx
132 #error Unsupported architecture