vfork.c 919 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 __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. weak_alias(__vfork, vfork)
  22. libc_hidden_weak(vfork)
  23. # elif defined __NR_vfork
  24. # define __NR___vfork __NR_vfork
  25. _syscall0(pid_t, __vfork)
  26. # else
  27. /* Trivial implementation for arches that lack vfork */
  28. pid_t __vfork(void)
  29. {
  30. return fork();
  31. }
  32. # endif
  33. strong_alias(__vfork,vfork)
  34. libc_hidden_weak(vfork)
  35. #endif