clone.S 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Richard Henderson (rth@tamu.edu).
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. /* clone() is even more special than fork() as it mucks with stacks
  17. and invokes a function in the right context after its all over. */
  18. #include <asm/errno.h>
  19. #include <asm/unistd.h>
  20. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  21. .text
  22. .align 4
  23. .globl __clone
  24. .type __clone,@function
  25. __clone:
  26. save %sp,-96,%sp
  27. /* sanity check arguments */
  28. tst %i0
  29. be .Lerror
  30. orcc %i1,%g0,%o1
  31. be .Lerror
  32. mov %i2,%o0
  33. /* Do the system call */
  34. set __NR_clone,%g1
  35. ta 0x10
  36. bcs .Lerror
  37. tst %o1
  38. bne __thread_start
  39. nop
  40. ret
  41. restore %o0,%g0,%o0
  42. .Lerror:
  43. call __errno_location
  44. or %g0,EINVAL,%i0
  45. st %i0,[%o0]
  46. ret
  47. restore %g0,-1,%o0
  48. .size __clone, .-__clone
  49. .type __thread_start,@function
  50. __thread_start:
  51. call %i0
  52. mov %i3,%o0
  53. call _exit,0
  54. nop
  55. .size __thread_start, .-__thread_start
  56. .weak clone ; clone = __clone