sysdep-cancel.h 5.3 KB

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