clone.S 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Copyright (C) 1996, 1997, 1998, 2000, 2003, 2004, 2007
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Richard Henderson (rth@tamu.edu).
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  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. #include <sysdep.h>
  21. #define CLONE_VM 0x00000100
  22. #define CLONE_THREAD 0x00010000
  23. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg,
  24. pid_t *ptid, void *tls, pid_t *ctid); */
  25. .text
  26. ENTRY (__clone)
  27. save %sp,-96,%sp
  28. cfi_def_cfa_register(%fp)
  29. cfi_window_save
  30. cfi_register(%o7, %i7)
  31. /* sanity check arguments */
  32. orcc %i0,%g0,%g2
  33. be .Leinval
  34. orcc %i1,%g0,%o1
  35. be .Leinval
  36. mov %i2,%o0
  37. /* The child_stack is the top of the stack, allocate one
  38. whole stack frame from that as this is what the kernel
  39. expects. */
  40. sub %o1, 96, %o1
  41. mov %i3, %g3
  42. mov %i2, %g4
  43. /* ptid */
  44. mov %i4,%o2
  45. /* tls */
  46. mov %i5,%o3
  47. /* ctid */
  48. ld [%fp+92],%o4
  49. /* Do the system call */
  50. set __NR_clone,%g1
  51. ta 0x10
  52. bcs .Lerror
  53. tst %o1
  54. bne __thread_start
  55. nop
  56. jmpl %i7 + 8, %g0
  57. restore %o0,%g0,%o0
  58. .Leinval:
  59. mov EINVAL, %o0
  60. .Lerror:
  61. call __errno_location
  62. mov %o0, %i0
  63. st %i0,[%o0]
  64. jmpl %i7 + 8, %g0
  65. restore %g0,-1,%o0
  66. END(__clone)
  67. .type __thread_start,@function
  68. __thread_start:
  69. mov %g0, %fp /* terminate backtrace */
  70. call %g2
  71. mov %g3,%o0
  72. call exit,0
  73. nop
  74. .size __thread_start, .-__thread_start
  75. weak_alias (__clone, clone)