clone.S 2.0 KB

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