clone.S 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Copyright (C) 1996, 1997, 1998, 2000, 2003, 2004, 2007
  2. Free Software Foundation, Inc.
  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 <asm/unistd.h>
  19. #include <sysdep.h>
  20. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
  21. pid_t *ptid, void *tls, pid_t *ctid); */
  22. .text
  23. ENTRY (__clone)
  24. save %sp,-96,%sp
  25. cfi_def_cfa_register(%fp)
  26. cfi_window_save
  27. cfi_register(%o7, %i7)
  28. /* sanity check arguments */
  29. orcc %i0,%g0,%g2
  30. be .Leinval
  31. orcc %i1,%g0,%o1
  32. be .Leinval
  33. mov %i2,%o0
  34. /* The child_stack is the top of the stack, allocate one
  35. whole stack frame from that as this is what the kernel
  36. expects. */
  37. sub %o1, 96, %o1
  38. mov %i3, %g3
  39. /* ptid */
  40. mov %i4,%o2
  41. /* tls */
  42. mov %i5,%o3
  43. /* ctid */
  44. ld [%fp+92],%o4
  45. /* Do the system call */
  46. set __NR_clone,%g1
  47. ta 0x10
  48. bcs .Lerror
  49. tst %o1
  50. bne __thread_start
  51. nop
  52. jmpl %i7 + 8, %g0
  53. restore %o0,%g0,%o0
  54. .Leinval:
  55. mov EINVAL, %o0
  56. .Lerror:
  57. call __errno_location
  58. mov %o0, %i0
  59. st %i0,[%o0]
  60. jmpl %i7 + 8, %g0
  61. restore %g0,-1,%o0
  62. END(__clone)
  63. .type __thread_start,@function
  64. __thread_start:
  65. mov %g0, %fp /* terminate backtrace */
  66. call %g2
  67. mov %g3,%o0
  68. call exit,0
  69. nop
  70. .size __thread_start, .-__thread_start
  71. weak_alias (__clone, clone)