clone.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (C) 1998, 2002, 2003, 2004 Free Software Foundation, Inc.
  2. The GNU C Library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Lesser General Public
  4. License as published by the Free Software Foundation; either
  5. version 2.1 of the License, or (at your option) any later version.
  6. The GNU C Library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Lesser General Public License for more details.
  10. You should have received a copy of the GNU Lesser General Public
  11. License along with the GNU C Library; if not, see
  12. <http://www.gnu.org/licenses/>. */
  13. #include <stdarg.h>
  14. #include <sysdep.h>
  15. #include <unistd.h>
  16. extern int __or1k_clone (int (*fn)(void *), void *child_stack,
  17. int flags, void *arg, pid_t *ptid,
  18. void *tls, pid_t *ctid);
  19. /* or1k ABI uses stack for varargs, syscall uses registers.
  20. * This function moves from varargs to regs. */
  21. int
  22. __clone (int (*fn)(void *), void *child_stack,
  23. int flags, void *arg, ...
  24. /* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ )
  25. {
  26. void *ptid;
  27. void *tls;
  28. void *ctid;
  29. va_list ap;
  30. int err;
  31. va_start (ap, arg);
  32. ptid = va_arg (ap, void *);
  33. tls = va_arg (ap, void *);
  34. ctid = va_arg (ap, void *);
  35. va_end (ap);
  36. /* Sanity check the arguments */
  37. err = -EINVAL;
  38. if (!fn)
  39. goto syscall_error;
  40. if (!child_stack)
  41. goto syscall_error;
  42. return __or1k_clone (fn, child_stack, flags, arg, ptid, tls, ctid);
  43. syscall_error:
  44. __set_errno (-err);
  45. return -1;
  46. }
  47. weak_alias (__clone, clone)