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 dummy(int x)9static void dummy(int x) { } 10 weak_alias(dummy, __aio_atfork); 11 _Fork(void)12pid_t _Fork(void) 13 { 14 pid_t ret; 15 sigset_t set; 16 __block_all_sigs(&set); 17 __aio_atfork(-1); 18 LOCK(__abort_lock); 19 #ifdef SYS_fork 20 ret = __syscall(SYS_fork); 21 #else 22 ret = __syscall(SYS_clone, SIGCHLD, 0); 23 #endif 24 if (!ret) { 25 pthread_t self = __pthread_self(); 26 self->tid = __syscall(SYS_gettid); 27 self->pid = self->tid; 28 self->robust_list.off = 0; 29 self->robust_list.pending = 0; 30 self->next = self->prev = self; 31 __thread_list_lock = 0; 32 libc.threads_minus_1 = 0; 33 if (libc.need_locks) libc.need_locks = -1; 34 } 35 UNLOCK(__abort_lock); 36 __aio_atfork(!ret); 37 __restore_sigs(&set); 38 return __syscall_ret(ret); 39 }