fork.c 776 B

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