clone.c 1.7 KB

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