12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include <unistd.h>
- #include <tls.h>
- #include <sysdep.h>
- #ifdef __NR_getxpid
- # undef __NR_getpid
- # define __NR_getpid __NR_getxpid
- #endif
- #ifndef NOT_IN_libc
- static inline __attribute__((always_inline)) pid_t really_getpid (pid_t oldval);
- static inline __attribute__((always_inline)) pid_t
- really_getpid (pid_t oldval)
- {
- if (__builtin_expect (oldval == 0, 1))
- {
- pid_t selftid = THREAD_GETMEM (THREAD_SELF, tid);
- if (__builtin_expect (selftid != 0, 1))
- return selftid;
- }
- INTERNAL_SYSCALL_DECL (err);
- pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
-
- if (oldval == 0)
- THREAD_SETMEM (THREAD_SELF, tid, result);
- return result;
- }
- #endif
- static pid_t
- __getpid (void)
- {
- #ifdef NOT_IN_libc
- INTERNAL_SYSCALL_DECL (err);
- pid_t result = INTERNAL_SYSCALL (getpid, err, 0);
- #else
- pid_t result = THREAD_GETMEM (THREAD_SELF, pid);
- if (__builtin_expect (result <= 0, 0))
- result = really_getpid (result);
- #endif
- return result;
- }
- weak_alias(__getpid, getpid)
- libc_hidden_weak(getpid)
- #if !defined NOT_IN_libc && !defined __NR_getppid
- strong_alias(getpid,getppid)
- #endif
|