clone2.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Copyright (C) 2000, 2001, 2003, 2004, 2006 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include "sysdep.h"
  16. #include "sysdep.h"
  17. #include <asm/errno.h>
  18. /* int __clone2(int (*fn) (void *arg), void *child_stack_base, */
  19. /* size_t child_stack_size, int flags, void *arg, */
  20. /* pid_t *parent_tid, void *tls, pid_t *child_tid) */
  21. #define CHILD p8
  22. #define PARENT p9
  23. ENTRY(__clone2)
  24. .prologue
  25. alloc r2=ar.pfs,8,1,6,0
  26. cmp.eq p6,p0=0,in0
  27. cmp.eq p7,p0=0,in1
  28. mov r8=EINVAL
  29. mov out0=in3 /* Flags are first syscall argument. */
  30. mov out1=in1 /* Stack address. */
  31. (p6) br.cond.spnt.many __syscall_error /* no NULL function pointers */
  32. (p7) br.cond.spnt.many __syscall_error /* no NULL stack pointers */
  33. ;;
  34. mov out2=in2 /* Stack size. */
  35. mov out3=in5 /* Parent TID Pointer */
  36. mov out4=in7 /* Child TID Pointer */
  37. mov out5=in6 /* TLS pointer */
  38. /*
  39. * clone2() is special: the child cannot execute br.ret right
  40. * after the system call returns, because it starts out
  41. * executing on an empty stack. Because of this, we can't use
  42. * the new (lightweight) syscall convention here. Instead, we
  43. * just fall back on always using "break".
  44. *
  45. * Furthermore, since the child starts with an empty stack, we
  46. * need to avoid unwinding past invalid memory. To that end,
  47. * we'll pretend now that __clone2() is the end of the
  48. * call-chain. This is wrong for the parent, but only until
  49. * it returns from clone2() but it's better than the
  50. * alternative.
  51. */
  52. mov r15=SYS_ify (clone2)
  53. .save rp, r0
  54. break __BREAK_SYSCALL
  55. .body
  56. cmp.eq p6,p0=-1,r10
  57. cmp.eq CHILD,PARENT=0,r8 /* Are we the child? */
  58. (p6) br.cond.spnt.many __syscall_error
  59. ;;
  60. (CHILD) mov loc0=gp
  61. (PARENT) ret
  62. ;;
  63. #ifdef RESET_PID
  64. tbit.nz p6,p0=in3,16 /* CLONE_THREAD */
  65. tbit.z p7,p10=in3,8 /* CLONE_VM */
  66. (p6) br.cond.dptk 1f
  67. ;;
  68. mov r15=SYS_ify (getpid)
  69. (p10) addl r8=-1,r0
  70. (p7) break __BREAK_SYSCALL
  71. ;;
  72. add r9=PID,r13
  73. add r10=TID,r13
  74. ;;
  75. st4 [r9]=r8
  76. st4 [r10]=r8
  77. ;;
  78. #endif
  79. 1: ld8 out1=[in0],8 /* Retrieve code pointer. */
  80. mov out0=in4 /* Pass proper argument to fn */
  81. ;;
  82. ld8 gp=[in0] /* Load function gp. */
  83. mov b6=out1
  84. br.call.dptk.many rp=b6 /* Call fn(arg) in the child */
  85. ;;
  86. mov out0=r8 /* Argument to _exit */
  87. mov gp=loc0
  88. .globl HIDDEN_JUMPTARGET(_exit)
  89. br.call.dpnt.many rp=HIDDEN_JUMPTARGET(_exit)
  90. /* call _exit with result from fn. */
  91. ret /* Not reached. */
  92. PSEUDO_END(__clone2)
  93. /* For now we leave __clone undefined. This is unlikely to be a */
  94. /* problem, since at least the i386 __clone in glibc always failed */
  95. /* with a 0 sp (eventhough the kernel explicitly handled it). */
  96. /* Thus all such calls needed to pass an explicit sp, and as a result, */
  97. /* would be unlikely to work on ia64. */