clone.S 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <sys/syscall.h>
  20. #include "NM_Macros.S"
  21. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  22. .text
  23. .align 2
  24. .globl clone
  25. .type clone,@function
  26. clone:
  27. save %sp,-16
  28. MOVIP %l0, -EINVAL
  29. /* sanity check arguments */
  30. skprnz %i0 /* no NULL function pointers */
  31. br CLONE_ERROR_LABEL
  32. mov %o0, %i2
  33. skprnz %i1 /* no NULL stack pointers */
  34. br CLONE_ERROR_LABEL
  35. mov %o1, %i1
  36. /* Do the system call */
  37. MOVIP %g1, __NR_clone
  38. trap 63
  39. /* if ret >=0? */
  40. cmpi %o0, 0
  41. skps cc_pl
  42. br CLONE_ERROR_LABEL
  43. mov %l0, %o0
  44. /* Start thread */
  45. skprz %o1
  46. br __thread_start
  47. nop
  48. mov %i0, %o0
  49. ret
  50. restore
  51. CLONE_ERROR_LABEL:
  52. neg %l0
  53. MOVIA %g1, __errno_location@h
  54. call %g1
  55. nop
  56. st [%o0], %l0 /* store errno */
  57. xor %i0, %i0
  58. dec %i0 /* retval=-1 */
  59. ret
  60. restore
  61. .size clone, .-clone
  62. .type __thread_start,@function
  63. __thread_start:
  64. call %i0
  65. mov %o0, %i3
  66. MOVIA %g1, _exit@h
  67. call %g1
  68. nop
  69. .size __thread_start, .-__thread_start