]> git.saurik.com Git - apple/libc.git/blob - i386/sys/vfork.s
Libc-320.tar.gz
[apple/libc.git] / i386 / sys / vfork.s
1 /*
2 * Copyright (c) 1999-2003 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 /*
26 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
27 */
28 #include "SYS.h"
29
30 #if defined(__DYNAMIC__)
31 #define GET_CURRENT_PID PICIFY(__current_pid)
32
33 NON_LAZY_STUB(__current_pid)
34 #define __current_pid (%edx)
35 #else
36 #define GET_CURRENT_PID
37 #endif
38
39 /*
40 * If __current_pid >= 0, we want to put a -1 in there
41 * otherwise we just decrement it
42 */
43
44 LEAF(_vfork, 0)
45 GET_CURRENT_PID
46 movl __current_pid, %eax
47 0:
48 xorl %ecx, %ecx
49 testl %eax, %eax
50 cmovs %eax, %ecx
51 decl %ecx
52 lock
53 cmpxchgl %ecx, __current_pid
54 jne 0b
55 popl %ecx
56 movl $(SYS_vfork), %eax // code for vfork -> eax
57 UNIX_SYSCALL_TRAP // do the system call
58 jnb L1 // jump if CF==0
59 GET_CURRENT_PID
60 lock
61 incl __current_pid
62 pushl %ecx
63 BRANCH_EXTERN(cerror)
64
65 L1:
66 testl %edx, %edx // CF=OF=0, ZF set if zero result
67 jz L2 // parent, since r1 == 0 in parent, 1 in child
68 xorl %eax, %eax // zero eax
69 jmp *%ecx
70
71 L2:
72 GET_CURRENT_PID
73 lock
74 incl __current_pid
75 jmp *%ecx