sysdep-cancel.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* Copyright (C) 2003 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; see the file COPYING.LIB. If
  13. not, see <http://www.gnu.org/licenses/>.  */
  14. #include <sysdep.h>
  15. #include <tls.h>
  16. /* #include <pt-machine.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. #ifdef __ASSEMBLER__
  22. #if defined(__XTENSA_WINDOWED_ABI__)
  23. /* CENABLE/CDISABLE in PSEUDO below use call8, stack frame size must be
  24. * at least 32.
  25. */
  26. #if FRAMESIZE < 32
  27. #undef FRAMESIZE
  28. #define FRAMESIZE 32
  29. #endif
  30. # undef PSEUDO
  31. # define PSEUDO(name, syscall_name, args) \
  32. .text; \
  33. ENTRY (name) \
  34. SINGLE_THREAD_P(a15); \
  35. bnez a15, .Lpseudo_cancel; \
  36. DO_CALL (syscall_name, args); \
  37. bgez a2, .Lpseudo_done; \
  38. movi a4, -4095; \
  39. blt a2, a4, .Lpseudo_done; \
  40. j SYSCALL_ERROR_LABEL; \
  41. .Lpseudo_done: \
  42. retw; \
  43. .Lpseudo_cancel: \
  44. /* The syscall args are in a2...a7; no need to save */ \
  45. CENABLE; \
  46. /* The return value is in a10 and preserved across the syscall */ \
  47. DO_CALL (syscall_name, args); \
  48. CDISABLE; \
  49. bgez a2, .Lpseudo_end; \
  50. movi a4, -4095; \
  51. blt a2, a4, .Lpseudo_end; \
  52. j SYSCALL_ERROR_LABEL; \
  53. .Lpseudo_end:
  54. # define CENABLE movi a8, CENABLE_FUNC; \
  55. callx8 a8
  56. # define CDISABLE movi a8, CDISABLE_FUNC; \
  57. callx8 a8
  58. #elif defined(__XTENSA_CALL0_ABI__)
  59. # undef PSEUDO
  60. # define PSEUDO(name, syscall_name, args) \
  61. .text; \
  62. ENTRY (name) \
  63. SINGLE_THREAD_P(a10); \
  64. bnez a10, .Lpseudo_cancel; \
  65. DO_CALL (syscall_name, args); \
  66. bgez a2, .Lpseudo_done; \
  67. movi a4, -4095; \
  68. blt a2, a4, .Lpseudo_done; \
  69. j SYSCALL_ERROR_LABEL; \
  70. .Lpseudo_done: \
  71. ret; \
  72. .Lpseudo_cancel: \
  73. addi a1, a1, -32; \
  74. /* The syscall args are in a2...a7; save them */ \
  75. s32i a0, a1, 0; \
  76. s32i a2, a1, 4; \
  77. s32i a3, a1, 8; \
  78. s32i a4, a1, 12; \
  79. s32i a5, a1, 16; \
  80. s32i a6, a1, 20; \
  81. s32i a7, a1, 24; \
  82. CENABLE; \
  83. /* Move return value to a10 preserved across the syscall */ \
  84. mov a10, a2; \
  85. l32i a2, a1, 4; \
  86. l32i a3, a1, 8; \
  87. l32i a4, a1, 12; \
  88. l32i a5, a1, 16; \
  89. l32i a6, a1, 20; \
  90. l32i a7, a1, 24; \
  91. DO_CALL (syscall_name, args); \
  92. s32i a2, a1, 4; \
  93. mov a2, a10; \
  94. CDISABLE; \
  95. l32i a2, a1, 4; \
  96. l32i a0, a1, 0; \
  97. addi a1, a1, 32; \
  98. bgez a2, .Lpseudo_end; \
  99. movi a4, -4095; \
  100. blt a2, a4, .Lpseudo_end; \
  101. j SYSCALL_ERROR_LABEL; \
  102. .Lpseudo_end:
  103. # define CENABLE movi a0, CENABLE_FUNC; \
  104. callx0 a0
  105. # define CDISABLE movi a0, CDISABLE_FUNC; \
  106. callx0 a0
  107. #else
  108. #error Unsupported Xtensa ABI
  109. #endif
  110. #endif
  111. # ifdef IS_IN_libpthread
  112. # define CENABLE_FUNC __pthread_enable_asynccancel
  113. # define CDISABLE_FUNC __pthread_disable_asynccancel
  114. # define __local_multiple_threads __pthread_multiple_threads
  115. # elif !defined NOT_IN_libc
  116. # define CENABLE_FUNC __libc_enable_asynccancel
  117. # define CDISABLE_FUNC __libc_disable_asynccancel
  118. # define __local_multiple_threads __libc_multiple_threads
  119. # elif defined IS_IN_librt
  120. # define CENABLE_FUNC __librt_enable_asynccancel
  121. # define CDISABLE_FUNC __librt_disable_asynccancel
  122. # else
  123. # error Unsupported library
  124. # endif
  125. # if defined IS_IN_libpthread || !defined NOT_IN_libc
  126. # ifndef __ASSEMBLER__
  127. extern int __local_multiple_threads attribute_hidden;
  128. # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  129. # else
  130. # define SINGLE_THREAD_P(reg) movi reg, __local_multiple_threads; \
  131. l32i reg, reg, 0;
  132. # endif
  133. # else
  134. # ifndef __ASSEMBLER__
  135. # define SINGLE_THREAD_P \
  136. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  137. header.multiple_threads) == 0, 1)
  138. # else
  139. # define SINGLE_THREAD_P(reg) \
  140. rur reg, threadptr; \
  141. l32i reg, reg, MULTIPLE_THREADS_OFFSET;
  142. # endif
  143. # endif
  144. #else
  145. /* This code should never be used but we define it anyhow. */
  146. # define SINGLE_THREAD_P (1)
  147. # define NO_CANCELLATION 1
  148. #endif
  149. #ifndef __ASSEMBLER__
  150. # define RTLD_SINGLE_THREAD_P \
  151. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  152. header.multiple_threads) == 0, 1)
  153. #endif