clone.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * libc/sysdeps/linux/v850/clone.c -- `clone' syscall for linux/v850
  3. *
  4. * Copyright (C) 2002,03 NEC Electronics Corporation
  5. * Copyright (C) 2002,03 Miles Bader <miles@gnu.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU Lesser
  8. * General Public License. See the file COPYING.LIB in the main
  9. * directory of this archive for more details.
  10. *
  11. * Written by Miles Bader <miles@gnu.org>
  12. */
  13. #include <errno.h>
  14. #include <sys/syscall.h>
  15. int
  16. clone (int (*fn)(void *arg), void *child_stack, int flags, void *arg)
  17. {
  18. register unsigned long rval asm (SYSCALL_RET) = -EINVAL;
  19. if (fn && child_stack)
  20. {
  21. register unsigned long syscall asm (SYSCALL_NUM);
  22. register unsigned long arg0 asm (SYSCALL_ARG0);
  23. register unsigned long arg1 asm (SYSCALL_ARG1);
  24. /* Clone this thread. */
  25. arg0 = flags;
  26. arg1 = (unsigned long)child_stack;
  27. syscall = __NR_clone;
  28. asm volatile ("trap " SYSCALL_SHORT_TRAP
  29. : "=r" (rval), "=r" (syscall)
  30. : "1" (syscall), "r" (arg0), "r" (arg1)
  31. : SYSCALL_SHORT_CLOBBERS);
  32. if (rval == 0)
  33. /* In child thread, call FN and exit. */
  34. {
  35. arg0 = (*fn) (arg);
  36. syscall = __NR_exit;
  37. asm volatile ("trap " SYSCALL_SHORT_TRAP
  38. : "=r" (rval), "=r" (syscall)
  39. : "1" (syscall), "r" (arg0)
  40. : SYSCALL_SHORT_CLOBBERS);
  41. }
  42. }
  43. __syscall_return (int, rval);
  44. }