sysdep-cancel.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* Copyright (C) 2003, 2006 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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <sysdep.h>
  15. #include <tls.h>
  16. #ifndef __ASSEMBLER__
  17. # include <nptl/pthreadP.h>
  18. #endif
  19. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  20. # ifdef PROF
  21. # define PSEUDO_PROF \
  22. .set noat; \
  23. lda AT, _mcount; \
  24. jsr AT, (AT), _mcount; \
  25. .set at
  26. # else
  27. # define PSEUDO_PROF
  28. # endif
  29. /* ??? Assumes that nothing comes between PSEUDO and PSEUDO_END
  30. besides "ret". */
  31. # undef PSEUDO
  32. # define PSEUDO(name, syscall_name, args) \
  33. .globl name; \
  34. .align 4; \
  35. .type name, @function; \
  36. .usepv name, std; \
  37. cfi_startproc; \
  38. __LABEL(name) \
  39. ldgp gp, 0(pv); \
  40. PSEUDO_PROF; \
  41. PSEUDO_PREPARE_ARGS \
  42. SINGLE_THREAD_P(t0); \
  43. bne t0, $pseudo_cancel; \
  44. lda v0, SYS_ify(syscall_name); \
  45. call_pal PAL_callsys; \
  46. bne a3, SYSCALL_ERROR_LABEL; \
  47. __LABEL($pseudo_ret) \
  48. .subsection 2; \
  49. cfi_startproc; \
  50. __LABEL($pseudo_cancel) \
  51. subq sp, 64, sp; \
  52. cfi_def_cfa_offset(64); \
  53. stq ra, 0(sp); \
  54. cfi_offset(ra, -64); \
  55. SAVE_ARGS_##args; \
  56. CENABLE; \
  57. LOAD_ARGS_##args; \
  58. /* Save the CENABLE return value in RA. That register \
  59. is preserved across syscall and the real return \
  60. address is saved on the stack. */ \
  61. mov v0, ra; \
  62. lda v0, SYS_ify(syscall_name); \
  63. call_pal PAL_callsys; \
  64. stq v0, 8(sp); \
  65. mov ra, a0; \
  66. bne a3, $multi_error; \
  67. CDISABLE; \
  68. ldq ra, 0(sp); \
  69. ldq v0, 8(sp); \
  70. addq sp, 64, sp; \
  71. cfi_remember_state; \
  72. cfi_restore(ra); \
  73. cfi_def_cfa_offset(0); \
  74. ret; \
  75. cfi_restore_state; \
  76. __LABEL($multi_error) \
  77. CDISABLE; \
  78. ldq ra, 0(sp); \
  79. ldq v0, 8(sp); \
  80. addq sp, 64, sp; \
  81. cfi_restore(ra); \
  82. cfi_def_cfa_offset(0); \
  83. __LABEL($syscall_error) \
  84. SYSCALL_ERROR_HANDLER; \
  85. cfi_endproc; \
  86. .previous
  87. # undef PSEUDO_END
  88. # define PSEUDO_END(sym) \
  89. cfi_endproc; \
  90. .subsection 2; \
  91. .size sym, .-sym
  92. # define SAVE_ARGS_0 /* Nothing. */
  93. # define SAVE_ARGS_1 SAVE_ARGS_0; stq a0, 8(sp)
  94. # define SAVE_ARGS_2 SAVE_ARGS_1; stq a1, 16(sp)
  95. # define SAVE_ARGS_3 SAVE_ARGS_2; stq a2, 24(sp)
  96. # define SAVE_ARGS_4 SAVE_ARGS_3; stq a3, 32(sp)
  97. # define SAVE_ARGS_5 SAVE_ARGS_4; stq a4, 40(sp)
  98. # define SAVE_ARGS_6 SAVE_ARGS_5; stq a5, 48(sp)
  99. # define LOAD_ARGS_0 /* Nothing. */
  100. # define LOAD_ARGS_1 LOAD_ARGS_0; ldq a0, 8(sp)
  101. # define LOAD_ARGS_2 LOAD_ARGS_1; ldq a1, 16(sp)
  102. # define LOAD_ARGS_3 LOAD_ARGS_2; ldq a2, 24(sp)
  103. # define LOAD_ARGS_4 LOAD_ARGS_3; ldq a3, 32(sp)
  104. # define LOAD_ARGS_5 LOAD_ARGS_4; ldq a4, 40(sp)
  105. # define LOAD_ARGS_6 LOAD_ARGS_5; ldq a5, 48(sp)
  106. # ifdef IS_IN_libpthread
  107. # define __local_enable_asynccancel __pthread_enable_asynccancel
  108. # define __local_disable_asynccancel __pthread_disable_asynccancel
  109. # define __local_multiple_threads __pthread_multiple_threads
  110. # elif !defined NOT_IN_libc
  111. # define __local_enable_asynccancel __libc_enable_asynccancel
  112. # define __local_disable_asynccancel __libc_disable_asynccancel
  113. # define __local_multiple_threads __libc_multiple_threads
  114. # elif defined IS_IN_librt
  115. # define __local_enable_asynccancel __librt_enable_asynccancel
  116. # define __local_disable_asynccancel __librt_disable_asynccancel
  117. # else
  118. # error Unsupported library
  119. # endif
  120. # ifdef __PIC__
  121. # define CENABLE bsr ra, __local_enable_asynccancel !samegp
  122. # define CDISABLE bsr ra, __local_disable_asynccancel !samegp
  123. # else
  124. # define CENABLE jsr ra, __local_enable_asynccancel; ldgp ra, 0(gp)
  125. # define CDISABLE jsr ra, __local_disable_asynccancel; ldgp ra, 0(gp)
  126. # endif
  127. # if defined IS_IN_libpthread || !defined NOT_IN_libc
  128. # ifndef __ASSEMBLER__
  129. extern int __local_multiple_threads attribute_hidden;
  130. # define SINGLE_THREAD_P \
  131. __builtin_expect (__local_multiple_threads == 0, 1)
  132. # elif defined(__PIC__)
  133. # define SINGLE_THREAD_P(reg) ldl reg, __local_multiple_threads(gp) !gprel
  134. # else
  135. # define SINGLE_THREAD_P(reg) \
  136. ldah reg, __local_multiple_threads(gp) !gprelhigh; \
  137. ldl reg, __local_multiple_threads(reg) !gprellow
  138. # endif
  139. # else
  140. # ifndef __ASSEMBLER__
  141. # define SINGLE_THREAD_P \
  142. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  143. header.multiple_threads) == 0, 1)
  144. # else
  145. # define SINGLE_THREAD_P(reg) \
  146. call_pal PAL_rduniq; \
  147. ldl reg, MULTIPLE_THREADS_OFFSET($0)
  148. # endif
  149. # endif
  150. #else
  151. # define SINGLE_THREAD_P (1)
  152. # define NO_CANCELLATION 1
  153. #endif
  154. #ifndef __ASSEMBLER__
  155. # define RTLD_SINGLE_THREAD_P \
  156. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  157. header.multiple_threads) == 0, 1)
  158. #endif