sysdep-cancel.h 5.7 KB

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