]> git.saurik.com Git - apple/libc.git/blame - ppc/sys/getpid.s
Libc-262.tar.gz
[apple/libc.git] / ppc / sys / getpid.s
CommitLineData
e9ce8d39
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22#include "SYS.h"
5b2abdfb
A
23 .data
24 EXPORT(__current_pid)
25 .long 0
e9ce8d39 26
5b2abdfb
A
27TEXT
28LEAF(_getpid)
29#if defined(__DYNAMIC__)
30 mflr r0
31 bcl 20,31,1f
321:
33 mflr r5
34 mtlr r0
35 addis r5, r5, ha16(__current_pid - 1b)
36 addi r5, r5, lo16(__current_pid - 1b)
37#else
38 lis r5,ha16(__current_pid)
39 ori r5,r5,lo16(__current_pid)
40#endif
41 lwz r3,0(r5) // get the cached pid
42 cmpwi r3,0 // if positive,
43 bgtlr+ // return it
44
45 SYSCALL_NONAME(getpid, 0)
e9ce8d39 46
5b2abdfb
A
47 lwarx r4,0,r5 // see if we can cache it
48 cmpwi r4,0 // we cant if there are any
49 bltlr- // vforks in progress
e9ce8d39 50
5b2abdfb
A
51 stwcx. r3,0,r5 // ignore cache conflicts
52 blr
53END(_getpid)