sysdep-cancel.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /* Copyright (C) 2003, 2004, 2005, 2009 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 <tcb-offsets.h>
  17. #ifndef __ASSEMBLER__
  18. # include <pthreadP.h>
  19. #endif
  20. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  21. /* NOTE: We do mark syscalls with unwind annotations, for the benefit of
  22. cancellation; but they're really only accurate at the point of the
  23. syscall. The ARM unwind directives are not rich enough without adding
  24. a custom personality function. */
  25. # undef PSEUDO
  26. # define PSEUDO(name, syscall_name, args) \
  27. .section ".text"; \
  28. PSEUDO_PROLOGUE; \
  29. .type __##syscall_name##_nocancel,%function; \
  30. .globl __##syscall_name##_nocancel; \
  31. __##syscall_name##_nocancel: \
  32. cfi_sections(.debug_frame); \
  33. cfi_startproc; \
  34. DO_CALL (syscall_name, args); \
  35. PSEUDO_RET; \
  36. cfi_endproc; \
  37. .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
  38. ENTRY (name); \
  39. SINGLE_THREAD_P; \
  40. DOARGS_##args; \
  41. bne .Lpseudo_cancel; \
  42. cfi_remember_state; \
  43. DO_CALL (syscall_name, 0); \
  44. UNDOARGS_##args; \
  45. cmn r0, $4096; \
  46. PSEUDO_RET; \
  47. cfi_restore_state; \
  48. .Lpseudo_cancel: \
  49. .fnstart; \
  50. DOCARGS_##args; /* save syscall args etc. around CENABLE. */ \
  51. CENABLE; \
  52. mov ip, r0; /* put mask in safe place. */ \
  53. UNDOCARGS_##args; /* restore syscall args. */ \
  54. ldr r7, =SYS_ify (syscall_name); \
  55. swi 0x0; /* do the call. */ \
  56. .fnend; /* Past here we can't easily unwind. */ \
  57. mov r7, r0; /* save syscall return value. */ \
  58. mov r0, ip; /* get mask back. */ \
  59. CDISABLE; \
  60. mov r0, r7; /* retrieve return value. */ \
  61. RESTORE_LR_##args; \
  62. UNDOARGS_##args; \
  63. cmn r0, $4096
  64. /* DOARGS pushes four bytes on the stack for five arguments, eight bytes for
  65. six arguments, and nothing for fewer. In order to preserve doubleword
  66. alignment, sometimes we must save an extra register. */
  67. # define RESTART_UNWIND \
  68. .fnend; \
  69. .fnstart; \
  70. .save {r7, lr}
  71. # define DOCARGS_0 \
  72. stmfd sp!, {r7, lr}; \
  73. cfi_adjust_cfa_offset (8); \
  74. cfi_rel_offset (r7, 0); \
  75. cfi_rel_offset (lr, 4); \
  76. .save {r7, lr}
  77. # define UNDOCARGS_0
  78. # define RESTORE_LR_0 \
  79. ldmfd sp!, {r7, lr}; \
  80. cfi_adjust_cfa_offset (-8); \
  81. cfi_restore (r7); \
  82. cfi_restore (lr)
  83. # define DOCARGS_1 \
  84. stmfd sp!, {r0, r1, r7, lr}; \
  85. cfi_adjust_cfa_offset (16); \
  86. cfi_rel_offset (r7, 8); \
  87. cfi_rel_offset (lr, 12); \
  88. .save {r7, lr}; \
  89. .pad #8
  90. # define UNDOCARGS_1 \
  91. ldr r0, [sp], #8; \
  92. cfi_adjust_cfa_offset (-8); \
  93. RESTART_UNWIND
  94. # define RESTORE_LR_1 \
  95. RESTORE_LR_0
  96. # define DOCARGS_2 \
  97. stmfd sp!, {r0, r1, r7, lr}; \
  98. cfi_adjust_cfa_offset (16); \
  99. cfi_rel_offset (r7, 8); \
  100. cfi_rel_offset (lr, 12); \
  101. .save {r7, lr}; \
  102. .pad #8
  103. # define UNDOCARGS_2 \
  104. ldmfd sp!, {r0, r1}; \
  105. cfi_adjust_cfa_offset (-8); \
  106. RESTART_UNWIND
  107. # define RESTORE_LR_2 \
  108. RESTORE_LR_0
  109. # define DOCARGS_3 \
  110. stmfd sp!, {r0, r1, r2, r3, r7, lr}; \
  111. cfi_adjust_cfa_offset (24); \
  112. cfi_rel_offset (r7, 16); \
  113. cfi_rel_offset (lr, 20); \
  114. .save {r7, lr}; \
  115. .pad #16
  116. # define UNDOCARGS_3 \
  117. ldmfd sp!, {r0, r1, r2, r3}; \
  118. cfi_adjust_cfa_offset (-16); \
  119. RESTART_UNWIND
  120. # define RESTORE_LR_3 \
  121. RESTORE_LR_0
  122. # define DOCARGS_4 \
  123. stmfd sp!, {r0, r1, r2, r3, r7, lr}; \
  124. cfi_adjust_cfa_offset (24); \
  125. cfi_rel_offset (r7, 16); \
  126. cfi_rel_offset (lr, 20); \
  127. .save {r7, lr}; \
  128. .pad #16
  129. # define UNDOCARGS_4 \
  130. ldmfd sp!, {r0, r1, r2, r3}; \
  131. cfi_adjust_cfa_offset (-16); \
  132. RESTART_UNWIND
  133. # define RESTORE_LR_4 \
  134. RESTORE_LR_0
  135. /* r4 is only stmfd'ed for correct stack alignment. */
  136. # define DOCARGS_5 \
  137. .save {r4}; \
  138. stmfd sp!, {r0, r1, r2, r3, r4, r7, lr}; \
  139. cfi_adjust_cfa_offset (28); \
  140. cfi_rel_offset (r7, 20); \
  141. cfi_rel_offset (lr, 24); \
  142. .save {r7, lr}; \
  143. .pad #20
  144. # define UNDOCARGS_5 \
  145. ldmfd sp!, {r0, r1, r2, r3}; \
  146. cfi_adjust_cfa_offset (-16); \
  147. .fnend; \
  148. .fnstart; \
  149. .save {r4}; \
  150. .save {r7, lr}; \
  151. .pad #4
  152. # define RESTORE_LR_5 \
  153. ldmfd sp!, {r4, r7, lr}; \
  154. cfi_adjust_cfa_offset (-12); \
  155. /* r4 will be marked as restored later. */ \
  156. cfi_restore (r7); \
  157. cfi_restore (lr)
  158. # define DOCARGS_6 \
  159. .save {r4, r5}; \
  160. stmfd sp!, {r0, r1, r2, r3, r7, lr}; \
  161. cfi_adjust_cfa_offset (24); \
  162. cfi_rel_offset (r7, 16); \
  163. cfi_rel_offset (lr, 20); \
  164. .save {r7, lr}; \
  165. .pad #16
  166. # define UNDOCARGS_6 \
  167. ldmfd sp!, {r0, r1, r2, r3}; \
  168. cfi_adjust_cfa_offset (-16); \
  169. .fnend; \
  170. .fnstart; \
  171. .save {r4, r5}; \
  172. .save {r7, lr}
  173. # define RESTORE_LR_6 \
  174. RESTORE_LR_0
  175. # ifdef IS_IN_libpthread
  176. # define CENABLE bl PLTJMP(__pthread_enable_asynccancel)
  177. # define CDISABLE bl PLTJMP(__pthread_disable_asynccancel)
  178. # define __local_multiple_threads __pthread_multiple_threads
  179. # elif !defined NOT_IN_libc
  180. # define CENABLE bl PLTJMP(__libc_enable_asynccancel)
  181. # define CDISABLE bl PLTJMP(__libc_disable_asynccancel)
  182. # define __local_multiple_threads __libc_multiple_threads
  183. # elif defined IS_IN_librt
  184. # define CENABLE bl PLTJMP(__librt_enable_asynccancel)
  185. # define CDISABLE bl PLTJMP(__librt_disable_asynccancel)
  186. # else
  187. # error Unsupported library
  188. # endif
  189. # if defined IS_IN_libpthread || !defined NOT_IN_libc
  190. # ifndef __ASSEMBLER__
  191. extern int __local_multiple_threads attribute_hidden;
  192. # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  193. # else
  194. # define SINGLE_THREAD_P \
  195. ldr ip, 1b; \
  196. 2: \
  197. ldr ip, [pc, ip]; \
  198. teq ip, #0;
  199. # define PSEUDO_PROLOGUE \
  200. 1: .word __local_multiple_threads - 2f - 8;
  201. # endif
  202. # else
  203. /* There is no __local_multiple_threads for librt, so use the TCB. */
  204. # ifndef __ASSEMBLER__
  205. # define SINGLE_THREAD_P \
  206. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  207. header.multiple_threads) == 0, 1)
  208. # else
  209. # define PSEUDO_PROLOGUE
  210. # define SINGLE_THREAD_P \
  211. stmfd sp!, {r0, lr}; \
  212. cfi_adjust_cfa_offset (8); \
  213. cfi_rel_offset (lr, 4); \
  214. bl __aeabi_read_tp; \
  215. ldr ip, [r0, #MULTIPLE_THREADS_OFFSET]; \
  216. ldmfd sp!, {r0, lr}; \
  217. cfi_adjust_cfa_offset (-8); \
  218. cfi_restore (lr); \
  219. teq ip, #0
  220. # define SINGLE_THREAD_P_PIC(x) SINGLE_THREAD_P
  221. # endif
  222. # endif
  223. #elif !defined __ASSEMBLER__
  224. /* For rtld, et cetera. */
  225. # define SINGLE_THREAD_P 1
  226. # define NO_CANCELLATION 1
  227. #endif
  228. #ifndef __ASSEMBLER__
  229. # define RTLD_SINGLE_THREAD_P \
  230. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  231. header.multiple_threads) == 0, 1)
  232. #endif