clone.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Copyright (C) 1996, 1997,98,99,2000,02 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. Hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
  19. */
  20. #define _ERRNO_H 1
  21. #include <bits/errno.h>
  22. #include <sys/syscall.h>
  23. #define LINKAGE 4
  24. #define PTR_SIZE 4
  25. #define PARMS LINKAGE /* no space for saved regs */
  26. #define FUNC PARMS
  27. #define STACK FUNC+4
  28. #define FLAGS STACK+PTR_SIZE
  29. #define ARG FLAGS+4
  30. #define PTID ARG+PTR_SIZE
  31. #define TLS PTID+PTR_SIZE
  32. #define CTID TLS+PTR_SIZE
  33. .text
  34. .globl __clone;
  35. .type __clone,@function;
  36. .align 1<<4;
  37. __clone:
  38. /* Sanity check arguments. */
  39. movl $-EINVAL,%eax
  40. movl FUNC(%esp),%ecx /* no NULL function pointers */
  41. #ifdef __PIC__
  42. jecxz __syscall_error
  43. #else
  44. testl %ecx,%ecx
  45. jz __syscall_error
  46. #endif
  47. movl STACK(%esp),%ecx /* no NULL stack pointers */
  48. #ifdef __PIC__
  49. jecxz __syscall_error
  50. #else
  51. testl %ecx,%ecx
  52. jz __syscall_error
  53. #endif
  54. /* Insert the argument onto the new stack. */
  55. subl $16,%ecx
  56. movl ARG(%esp),%eax /* no negative argument counts */
  57. movl %eax,12(%ecx)
  58. /* Save the function pointer as the zeroth argument.
  59. It will be popped off in the child in the ebx frobbing below. */
  60. movl FUNC(%esp),%eax
  61. movl %eax,8(%ecx)
  62. /* Don't leak any information. */
  63. movl $0,4(%ecx)
  64. movl $0,(%ecx)
  65. /* Do the system call */
  66. pushl %ebx
  67. pushl %esi
  68. pushl %edi
  69. movl TLS+12(%esp),%esi
  70. movl PTID+12(%esp),%edx
  71. movl FLAGS+12(%esp),%ebx
  72. movl CTID+12(%esp),%edi
  73. movl $__NR_clone,%eax
  74. int $0x80
  75. popl %edi
  76. popl %esi
  77. popl %ebx
  78. test %eax,%eax
  79. jl __syscall_error
  80. jz .Lthread_start
  81. .Lpseudo_end:
  82. ret
  83. .Lthread_start:
  84. subl %ebp,%ebp /* terminate the stack frame */
  85. call *%ebx
  86. #ifdef __PIC__
  87. call .Lhere
  88. .Lhere:
  89. popl %ebx
  90. addl $_GLOBAL_OFFSET_TABLE_+[.-.Lhere], %ebx
  91. #endif
  92. movl %eax, %ebx
  93. movl $__NR_exit, %eax
  94. int $0x80
  95. __syscall_error:
  96. negl %eax
  97. pushl %eax
  98. #ifdef __PIC__
  99. call .Lthere
  100. .Lthere:
  101. popl %ebx
  102. addl $_GLOBAL_OFFSET_TABLE_+[.- .Lthere ], %ebx
  103. call __errno_location@PLT
  104. #else
  105. call __errno_location
  106. #endif
  107. popl %ecx
  108. movl %ecx, (%eax)
  109. xorl %eax, %eax
  110. decl %eax
  111. .Lsize:
  112. .size __clone,.Lsize-__clone
  113. .weak clone ; clone = __clone