sysdep-cancel.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Copyright (C) 2003, 2004, 2005 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 <tls.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. DO_CALL (syscall_name, args); \
  33. PSEUDO_RET; \
  34. .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
  35. ENTRY (name); \
  36. SINGLE_THREAD_P; \
  37. DOARGS_##args; \
  38. bne .Lpseudo_cancel; \
  39. DO_CALL (syscall_name, 0); \
  40. UNDOARGS_##args; \
  41. cmn r0, $4096; \
  42. PSEUDO_RET; \
  43. .Lpseudo_cancel: \
  44. .fnstart; \
  45. DOCARGS_##args; /* save syscall args etc. around CENABLE. */ \
  46. CENABLE; \
  47. mov ip, r0; /* put mask in safe place. */ \
  48. UNDOCARGS_##args; /* restore syscall args. */ \
  49. ldr r7, =SYS_ify (syscall_name); \
  50. swi 0x0; /* do the call. */ \
  51. .fnend; /* Past here we can't easily unwind. */ \
  52. mov r7, r0; /* save syscall return value. */ \
  53. mov r0, ip; /* get mask back. */ \
  54. CDISABLE; \
  55. mov r0, r7; /* retrieve return value. */ \
  56. RESTORE_LR_##args; \
  57. UNDOARGS_##args; \
  58. cmn r0, $4096;
  59. /* DOARGS pushes four bytes on the stack for five arguments, eight bytes for
  60. six arguments, and nothing for fewer. In order to preserve doubleword
  61. alignment, sometimes we must save an extra register. */
  62. # define RESTART_UNWIND .fnend; .fnstart; .save {r7, lr}
  63. # define DOCARGS_0 stmfd sp!, {r7, lr}; .save {r7, lr}
  64. # define UNDOCARGS_0
  65. # define RESTORE_LR_0 ldmfd sp!, {r7, lr};
  66. # define DOCARGS_1 stmfd sp!, {r0, r1, r7, lr}; .save {r7, lr}; .pad #8
  67. # define UNDOCARGS_1 ldr r0, [sp], #8; RESTART_UNWIND
  68. # define RESTORE_LR_1 RESTORE_LR_0
  69. # define DOCARGS_2 stmfd sp!, {r0, r1, r7, lr}; .save {r7, lr}; .pad #8
  70. # define UNDOCARGS_2 ldmfd sp!, {r0, r1}; RESTART_UNWIND
  71. # define RESTORE_LR_2 RESTORE_LR_0
  72. # define DOCARGS_3 stmfd sp!, {r0, r1, r2, r3, r7, lr}; .save {r7, lr}; .pad #16
  73. # define UNDOCARGS_3 ldmfd sp!, {r0, r1, r2, r3}; RESTART_UNWIND
  74. # define RESTORE_LR_3 RESTORE_LR_0
  75. # define DOCARGS_4 stmfd sp!, {r0, r1, r2, r3, r7, lr}; .save {r7, lr}; .pad #16
  76. # define UNDOCARGS_4 ldmfd sp!, {r0, r1, r2, r3}; RESTART_UNWIND
  77. # define RESTORE_LR_4 RESTORE_LR_0
  78. # define DOCARGS_5 .save {r4}; stmfd sp!, {r0, r1, r2, r3, r4, r7, lr}; .save {r7, lr}; .pad #20
  79. # define UNDOCARGS_5 ldmfd sp!, {r0, r1, r2, r3}; .fnend; .fnstart; .save {r4}; .save {r7, lr}; .pad #4
  80. # define RESTORE_LR_5 ldmfd sp!, {r4, r7, lr}
  81. # define DOCARGS_6 .save {r4, r5}; stmfd sp!, {r0, r1, r2, r3, r7, lr}; .save {r7, lr}; .pad #20
  82. # define UNDOCARGS_6 ldmfd sp!, {r0, r1, r2, r3}; .fnend; .fnstart; .save {r4, r5}; .save {r7, lr}
  83. # define RESTORE_LR_6 RESTORE_LR_0
  84. # ifdef IS_IN_libpthread
  85. # define CENABLE bl PLTJMP(__pthread_enable_asynccancel)
  86. # define CDISABLE bl PLTJMP(__pthread_disable_asynccancel)
  87. # define __local_multiple_threads __pthread_multiple_threads
  88. # elif !defined NOT_IN_libc
  89. # define CENABLE bl PLTJMP(__libc_enable_asynccancel)
  90. # define CDISABLE bl PLTJMP(__libc_disable_asynccancel)
  91. # define __local_multiple_threads __libc_multiple_threads
  92. # elif defined IS_IN_librt
  93. # define CENABLE bl PLTJMP(__librt_enable_asynccancel)
  94. # define CDISABLE bl PLTJMP(__librt_disable_asynccancel)
  95. # else
  96. # error Unsupported library
  97. # endif
  98. # if defined IS_IN_libpthread || !defined NOT_IN_libc
  99. # ifndef __ASSEMBLER__
  100. extern int __local_multiple_threads attribute_hidden;
  101. # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  102. # else
  103. # define SINGLE_THREAD_P \
  104. ldr ip, 1b; \
  105. 2: \
  106. ldr ip, [pc, ip]; \
  107. teq ip, #0;
  108. # define PSEUDO_PROLOGUE \
  109. 1: .word __local_multiple_threads - 2f - 8;
  110. # endif
  111. # else
  112. /* There is no __local_multiple_threads for librt, so use the TCB. */
  113. # ifndef __ASSEMBLER__
  114. # define SINGLE_THREAD_P \
  115. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  116. header.multiple_threads) == 0, 1)
  117. # else
  118. # define PSEUDO_PROLOGUE
  119. # define SINGLE_THREAD_P \
  120. stmfd sp!, {r0, lr}; \
  121. bl __aeabi_read_tp; \
  122. ldr ip, [r0, #MULTIPLE_THREADS_OFFSET]; \
  123. ldmfd sp!, {r0, lr}; \
  124. teq ip, #0
  125. # define SINGLE_THREAD_P_PIC(x) SINGLE_THREAD_P
  126. # endif
  127. # endif
  128. #elif !defined __ASSEMBLER__
  129. /* For rtld, et cetera. */
  130. # define SINGLE_THREAD_P 1
  131. # define NO_CANCELLATION 1
  132. #endif