1 #define _GNU_SOURCE 2 #include <unistd.h> 3 #include <signal.h> 4 #include "syscall.h" 5 #include "pthread_impl.h" 6 #include "proc_xid_impl.h" 7 __vfork(void)8hidden pid_t __vfork(void) 9 { 10 /* vfork syscall cannot be made from C code */ 11 #ifdef SYS_fork 12 return syscall(SYS_fork); 13 #else 14 return syscall(SYS_clone, SIGCHLD, 0); 15 #endif 16 } 17 vfork(void)18pid_t vfork(void) 19 { 20 pthread_t self = __pthread_self(); 21 pid_t parent_pid = self->pid; 22 self->pid = 0; 23 int parent_by_vfork = self->by_vfork; 24 self->by_vfork = 1; 25 pid_t ret = __vfork(); 26 if (ret != 0) { 27 self->pid = parent_pid; 28 self->by_vfork = parent_by_vfork; 29 } else { 30 self->proc_tid = -1; 31 __clear_proc_pid(); 32 } 33 return ret; 34 } 35