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 #ifndef __LITEOS__ 9 #include "proc_xid_impl.h" 10 #endif 11 #include "fork_impl.h" 12 dummy(int x)13static void dummy(int x) { } 14 weak_alias(dummy, __aio_atfork); 15 __post_Fork(int ret)16void __post_Fork(int ret) 17 { 18 if (!ret) { 19 pthread_t self = __pthread_self(); 20 #ifdef __LITEOS_A__ 21 self->tid = __syscall(SYS_gettid); 22 self->pid = __syscall(SYS_getpid); 23 #else 24 self->tid = __syscall(SYS_set_tid_address, &__thread_list_lock); 25 self->pid = self->tid; 26 #endif 27 self->proc_tid = -1; 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 #ifndef __LITEOS__ 34 __clear_proc_pid(); 35 #endif 36 if (libc.need_locks) libc.need_locks = -1; 37 #ifdef __LITEOS_A__ 38 libc.exit = 0; 39 signal(SIGSYS, arm_do_signal); 40 #endif 41 } 42 UNLOCK(__abort_lock); 43 if (!ret) __aio_atfork(1); 44 } 45 _Fork(void)46pid_t _Fork(void) 47 { 48 pid_t ret; 49 sigset_t set; 50 51 __block_all_sigs(&set); 52 LOCK(__abort_lock); 53 54 #ifdef SYS_fork 55 ret = __syscall(SYS_fork); 56 #else 57 ret = __syscall(SYS_clone, SIGCHLD, 0); 58 #endif 59 60 __post_Fork(ret); 61 __restore_sigs(&set); 62 63 return __syscall_ret(ret); 64 } 65