vfork.c 891 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. */
  6. #include <sys/syscall.h>
  7. #if (defined __NR_vfork || defined __NR_clone || (defined __ARCH_USE_MMU__ && defined __NR_fork)) && (defined __USE_BSD || defined __USE_XOPEN_EXTENDED)
  8. # include <unistd.h>
  9. extern __typeof(vfork) __vfork attribute_hidden;
  10. # if defined __NR_clone && !defined __NR_vfork
  11. # include <signal.h>
  12. # include <sys/types.h>
  13. pid_t __vfork(void)
  14. {
  15. pid_t pid = INLINE_SYSCALL(clone, 4, SIGCHLD,
  16. NULL, NULL, NULL);
  17. if (pid < 0)
  18. return -1;
  19. return pid;
  20. }
  21. # elif defined __NR_vfork
  22. # define __NR___vfork __NR_vfork
  23. _syscall0(pid_t, __vfork)
  24. # else
  25. /* Trivial implementation for arches that lack vfork */
  26. pid_t __vfork(void)
  27. {
  28. return fork();
  29. }
  30. # endif
  31. strong_alias(__vfork,vfork)
  32. libc_hidden_weak(vfork)
  33. #endif