0006-arm-add-RESET_PID-in-the-clone-impl.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. From 60f9eaa155d0f7ff935da37ecdf253c5c744a3ce Mon Sep 17 00:00:00 2001
  2. From: Wang Yufen <wangyufen@huawei.com>
  3. Date: Fri, 5 Sep 2014 15:19:21 +0800
  4. Subject: [PATCH 6/6] arm: add RESET_PID in the clone impl
  5. Called getpid() When creating a new process with clone(), getpid() returns
  6. the father_process's value. It should be child_process's value.
  7. The reason is missing a RESET_PID in the arm clone impl.
  8. Signed-off-by: Wang Yufen <wangyufen@huawei.com>
  9. Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
  10. ---
  11. libc/sysdeps/linux/arm/clone.S | 61 +++++++++++++++++++++++++++++++----------
  12. libc/sysdeps/linux/arm/sysdep.h | 36 ++++++++++++++++++++++++
  13. 2 files changed, 83 insertions(+), 14 deletions(-)
  14. diff --git a/libc/sysdeps/linux/arm/clone.S b/libc/sysdeps/linux/arm/clone.S
  15. index 03cd10e..29045ef 100644
  16. --- a/libc/sysdeps/linux/arm/clone.S
  17. +++ b/libc/sysdeps/linux/arm/clone.S
  18. @@ -19,12 +19,17 @@
  19. /* clone() is even more special than fork() as it mucks with stacks
  20. and invokes a function in the right context after its all over. */
  21. +#include <sysdep.h>
  22. #define _ERRNO_H
  23. #include <features.h>
  24. #include <bits/errno.h>
  25. #include <sys/syscall.h>
  26. #include <bits/arm_asm.h>
  27. #include <bits/arm_bx.h>
  28. +#include <sysdep-cancel.h>
  29. +
  30. +#define CLONE_VM 0x00000100
  31. +#define CLONE_THREAD 0x00010000
  32. #if defined(__NR_clone)
  33. /* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg); */
  34. @@ -87,6 +92,8 @@ __error:
  35. .pool
  36. #else
  37. __clone:
  38. +.fnstart
  39. +.cantunwind
  40. @ sanity check args
  41. cmp r0, #0
  42. IT(te, ne)
  43. @@ -95,32 +102,58 @@ __clone:
  44. beq __error
  45. @ insert the args onto the new stack
  46. - sub r1, r1, #8
  47. - str r3, [r1, #4]
  48. - @ save the function pointer as the 0th element
  49. - str r0, [r1]
  50. + str r3, [r1, #-4]!
  51. + str r0, [r1, #-4]!
  52. @ do the system call
  53. @ get flags
  54. mov r0, r2
  55. +#ifdef RESET_PID
  56. + mov ip, r2
  57. +#endif
  58. @ new sp is already in r1
  59. - @ load remaining arguments off the stack
  60. - stmfd sp!, {r4}
  61. - ldr r2, [sp, #4]
  62. - ldr r3, [sp, #8]
  63. - ldr r4, [sp, #12]
  64. - DO_CALL (clone)
  65. - movs a1, a1
  66. - IT(t, ne)
  67. - ldmnefd sp!, {r4}
  68. + push {r4, r7}
  69. + cfi_adjust_cfa_offset (8)
  70. + cfi_rel_offset (r4, 0)
  71. + cfi_rel_offset (r7, 4)
  72. + ldr r2, [sp, #8]
  73. + ldr r3, [sp, #12]
  74. + ldr r4, [sp, #16]
  75. + ldr r7, =SYS_ify(clone)
  76. + swi 0x0
  77. + cfi_endproc
  78. + cmp r0, #0
  79. + beq 1f
  80. + pop {r4, r7}
  81. blt __error
  82. - IT(t, ne)
  83. #if defined(__USE_BX__)
  84. bxne lr
  85. #else
  86. movne pc, lr
  87. #endif
  88. + cfi_startproc
  89. +.fnend
  90. +PSEUDO_END (__clone)
  91. +
  92. +1:
  93. + .fnstart
  94. + .cantunwind
  95. +#ifdef RESET_PID
  96. + tst ip, #CLONE_THREAD
  97. + bne 3f
  98. + GET_TLS (lr)
  99. + mov r1, r0
  100. + tst ip, #CLONE_VM
  101. + ldr r7, =SYS_ify(getpid)
  102. + ite ne
  103. + movne r0, #-1
  104. + swieq 0x0
  105. + NEGOFF_ADJ_BASE (r1, TID_OFFSET)
  106. + str r0, NEGOFF_OFF1 (r1, TID_OFFSET)
  107. + str r0, NEGOFF_OFF2 (r1, PID_OFFSET, TID_OFFSET)
  108. +3:
  109. +#endif
  110. @ pick the function arg and call address off the stack and execute
  111. ldr r0, [sp, #4]
  112. mov lr, pc
  113. diff --git a/libc/sysdeps/linux/arm/sysdep.h b/libc/sysdeps/linux/arm/sysdep.h
  114. index 64f4040..2d0a9cc 100644
  115. --- a/libc/sysdeps/linux/arm/sysdep.h
  116. +++ b/libc/sysdeps/linux/arm/sysdep.h
  117. @@ -213,6 +213,42 @@ __local_syscall_error: \
  118. sees the right arguments.
  119. */
  120. +#if __ARM_ARCH > 6 || defined (__ARM_ARCH_6K__) || defined (__ARM_ARCH_6ZK__)
  121. +# define ARCH_HAS_HARD_TP
  122. +#endif
  123. +
  124. +# ifdef __thumb2__
  125. +# define NEGOFF_ADJ_BASE(R, OFF) add R, R, $OFF
  126. +# define NEGOFF_ADJ_BASE2(D, S, OFF) add D, S, $OFF
  127. +# define NEGOFF_OFF1(R, OFF) [R]
  128. +# define NEGOFF_OFF2(R, OFFA, OFFB) [R, $((OFFA) - (OFFB))]
  129. +# else
  130. +# define NEGOFF_ADJ_BASE(R, OFF)
  131. +# define NEGOFF_ADJ_BASE2(D, S, OFF) mov D, S
  132. +# define NEGOFF_OFF1(R, OFF) [R, $OFF]
  133. +# define NEGOFF_OFF2(R, OFFA, OFFB) [R, $OFFA]
  134. +# endif
  135. +
  136. +# ifdef ARCH_HAS_HARD_TP
  137. +/* If the cpu has cp15 available, use it. */
  138. +# define GET_TLS(TMP) mrc p15, 0, r0, c13, c0, 3
  139. +# else
  140. +/* At this generic level we have no tricks to pull. Call the ABI routine. */
  141. +# define GET_TLS(TMP) \
  142. + push { r1, r2, r3, lr }; \
  143. + cfi_remember_state; \
  144. + cfi_adjust_cfa_offset (16); \
  145. + cfi_rel_offset (r1, 0); \
  146. + cfi_rel_offset (r2, 4); \
  147. + cfi_rel_offset (r3, 8); \
  148. + cfi_rel_offset (lr, 12); \
  149. + bl __aeabi_read_tp; \
  150. + pop { r1, r2, r3, lr }; \
  151. + cfi_restore_state
  152. +# endif /* ARCH_HAS_HARD_TP */
  153. +
  154. +
  155. +
  156. #undef DO_CALL
  157. #if defined(__ARM_EABI__)
  158. --
  159. 1.8.5.2 (Apple Git-48)