clone.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Pat Beirne <patb@corelcomputer.com>
  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. #define _ERRNO_H
  19. #include <features.h>
  20. #include <bits/errno.h>
  21. #include <sys/syscall.h>
  22. #include <bits/arm_asm.h>
  23. #if defined(__NR_clone)
  24. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  25. .text
  26. .global clone
  27. .type clone,%function
  28. .align 2
  29. #if defined(THUMB1_ONLY)
  30. .thumb_func
  31. clone:
  32. @ sanity check args
  33. cmp r0, #0
  34. beq __einval
  35. cmp r1, #0
  36. beq __einval
  37. @ insert the args onto the new stack
  38. sub r1, r1, #8
  39. str r3, [r1, #4]
  40. @ save the function pointer as the 0th element
  41. str r0, [r1]
  42. @ do the system call
  43. @ get flags
  44. mov r0, r2
  45. @ new sp is already in r1
  46. DO_CALL (clone)
  47. movs a1, a1
  48. blt __error
  49. beq 1f
  50. bx lr
  51. 1:
  52. @ pick the function arg and call address off the stack and execute
  53. ldr r0, [sp, #4]
  54. ldr r1, [sp]
  55. bl 2f @ blx r1
  56. @ and we are done, passing the return value through r0
  57. bl HIDDEN_JUMPTARGET(_exit)
  58. @ Should never return
  59. b .
  60. 2:
  61. bx r1
  62. __einval:
  63. ldr r0, =-EINVAL
  64. __error:
  65. push {r3, lr}
  66. bl __syscall_error
  67. POP_RET
  68. .pool
  69. #else
  70. clone:
  71. @ sanity check args
  72. cmp r0, #0
  73. IT(te, ne)
  74. cmpne r1, #0
  75. moveq r0, #-EINVAL
  76. beq __error
  77. @ insert the args onto the new stack
  78. sub r1, r1, #8
  79. str r3, [r1, #4]
  80. @ save the function pointer as the 0th element
  81. str r0, [r1]
  82. @ do the system call
  83. @ get flags
  84. mov r0, r2
  85. @ new sp is already in r1
  86. DO_CALL (clone)
  87. movs a1, a1
  88. blt __error
  89. IT(t, ne)
  90. #if defined(__USE_BX__)
  91. bxne lr
  92. #else
  93. movne pc, lr
  94. #endif
  95. @ pick the function arg and call address off the stack and execute
  96. ldr r0, [sp, #4]
  97. mov lr, pc
  98. ldr pc, [sp]
  99. @ and we are done, passing the return value through r0
  100. b HIDDEN_JUMPTARGET(_exit)
  101. __error:
  102. b __syscall_error
  103. #endif
  104. .size clone,.-clone
  105. #endif