fork.c 801 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * fork() for uClibc
  4. *
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <sys/syscall.h>
  10. #if defined __ARCH_USE_MMU__
  11. # include <unistd.h>
  12. extern __typeof(fork) __libc_fork;
  13. # if defined __NR_fork
  14. # include <cancel.h>
  15. # define __NR___libc_fork __NR_fork
  16. _syscall0(pid_t, fork)
  17. # elif defined __NR_clone && !defined __NR_fork
  18. # include <sys/types.h>
  19. # include <signal.h>
  20. # include <stddef.h>
  21. pid_t fork(void)
  22. {
  23. pid_t pid = INLINE_SYSCALL(clone, 4, SIGCHLD, NULL, NULL, NULL);
  24. if (pid < 0)
  25. return -1;
  26. return pid;
  27. }
  28. # endif
  29. # ifdef __UCLIBC_HAS_THREADS__
  30. strong_alias(fork,__libc_fork)
  31. libc_hidden_weak(fork)
  32. # else
  33. libc_hidden_def(fork)
  34. # endif
  35. #endif