1 #include <unistd.h> 2 #include <signal.h> 3 #include "syscall.h" 4 #include "libc.h" 5 #include "lock.h" 6 #include "pthread_impl.h" 7 #include "aio_impl.h" 8 #include "proc_xid_impl.h" 9 dummy(int x)10static void dummy(int x) { } 11 weak_alias(dummy, __aio_atfork); 12 _Fork(void)13pid_t _Fork(void) 14 { 15 pid_t ret; 16 sigset_t set; 17 __block_all_sigs(&set); 18 __aio_atfork(-1); 19 LOCK(__abort_lock); 20 #ifdef SYS_fork 21 ret = __syscall(SYS_fork); 22 #else 23 ret = __syscall(SYS_clone, SIGCHLD, 0); 24 #endif 25 if (!ret) { 26 pthread_t self = __pthread_self(); 27 self->tid = __syscall(SYS_gettid); 28 self->pid = self->tid; 29 self->proc_tid = -1; 30 self->robust_list.off = 0; 31 self->robust_list.pending = 0; 32 self->next = self->prev = self; 33 __thread_list_lock = 0; 34 libc.threads_minus_1 = 0; 35 __clear_proc_pid(); 36 if (libc.need_locks) libc.need_locks = -1; 37 } 38 UNLOCK(__abort_lock); 39 __aio_atfork(!ret); 40 __restore_sigs(&set); 41 return __syscall_ret(ret); 42 } 43