sysdep-cancel.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <sysdep.h>
  15. #ifndef __ASSEMBLER__
  16. # include <linuxthreads/internals.h>
  17. #endif
  18. #if !defined NOT_IN_libc || defined IS_IN_libpthread
  19. # ifdef PROF
  20. # define PSEUDO_PROF \
  21. .set noat; \
  22. lda AT, _mcount; \
  23. jsr AT, (AT), _mcount; \
  24. .set at
  25. # else
  26. # define PSEUDO_PROF
  27. # endif
  28. /* ??? Assumes that nothing comes between PSEUDO and PSEUDO_END
  29. besides "ret". */
  30. # undef PSEUDO
  31. # define PSEUDO(name, syscall_name, args) \
  32. .globl name; \
  33. .align 4; \
  34. .type name, @function; \
  35. .usepv name, std; \
  36. cfi_startproc; \
  37. __LABEL(name) \
  38. ldgp gp, 0(pv); \
  39. PSEUDO_PROF; \
  40. PSEUDO_PREPARE_ARGS \
  41. SINGLE_THREAD_P(t0); \
  42. bne t0, $pseudo_cancel; \
  43. lda v0, SYS_ify(syscall_name); \
  44. call_pal PAL_callsys; \
  45. bne a3, SYSCALL_ERROR_LABEL; \
  46. __LABEL($pseudo_ret) \
  47. .subsection 2; \
  48. __LABEL($pseudo_cancel) \
  49. subq sp, 64, sp; \
  50. cfi_def_cfa_offset(64); \
  51. stq ra, 0(sp); \
  52. cfi_offset(ra, -64); \
  53. SAVE_ARGS_##args; \
  54. CENABLE; \
  55. LOAD_ARGS_##args; \
  56. lda v0, SYS_ify(syscall_name); \
  57. call_pal PAL_callsys; \
  58. stq v0, 8(sp); \
  59. bne a3, $multi_error; \
  60. CDISABLE; \
  61. ldq ra, 0(sp); \
  62. ldq v0, 8(sp); \
  63. addq sp, 64, sp; \
  64. cfi_remember_state; \
  65. cfi_restore(ra); \
  66. cfi_def_cfa_offset(0); \
  67. ret; \
  68. cfi_restore_state; \
  69. __LABEL($multi_error) \
  70. CDISABLE; \
  71. ldq ra, 0(sp); \
  72. ldq v0, 8(sp); \
  73. addq sp, 64, sp; \
  74. cfi_restore(ra); \
  75. cfi_def_cfa_offset(0); \
  76. __LABEL($syscall_error) \
  77. SYSCALL_ERROR_HANDLER; \
  78. .previous
  79. # undef PSEUDO_END
  80. # define PSEUDO_END(sym) \
  81. .subsection 2; \
  82. cfi_endproc; \
  83. .size sym, .-sym
  84. # define SAVE_ARGS_0 /* Nothing. */
  85. # define SAVE_ARGS_1 SAVE_ARGS_0; stq a0, 8(sp)
  86. # define SAVE_ARGS_2 SAVE_ARGS_1; stq a1, 16(sp)
  87. # define SAVE_ARGS_3 SAVE_ARGS_2; stq a2, 24(sp)
  88. # define SAVE_ARGS_4 SAVE_ARGS_3; stq a3, 32(sp)
  89. # define SAVE_ARGS_5 SAVE_ARGS_4; stq a4, 40(sp)
  90. # define SAVE_ARGS_6 SAVE_ARGS_5; stq a5, 48(sp)
  91. # define LOAD_ARGS_0 /* Nothing. */
  92. # define LOAD_ARGS_1 LOAD_ARGS_0; ldq a0, 8(sp)
  93. # define LOAD_ARGS_2 LOAD_ARGS_1; ldq a1, 16(sp)
  94. # define LOAD_ARGS_3 LOAD_ARGS_2; ldq a2, 24(sp)
  95. # define LOAD_ARGS_4 LOAD_ARGS_3; ldq a3, 32(sp)
  96. # define LOAD_ARGS_5 LOAD_ARGS_4; ldq a4, 40(sp)
  97. # define LOAD_ARGS_6 LOAD_ARGS_5; ldq a5, 48(sp)
  98. # ifdef IS_IN_libpthread
  99. # define __local_enable_asynccancel __pthread_enable_asynccancel
  100. # define __local_disable_asynccancel __pthread_disable_asynccancel
  101. # define __local_multiple_threads __pthread_multiple_threads
  102. # else
  103. # define __local_enable_asynccancel __libc_enable_asynccancel
  104. # define __local_disable_asynccancel __libc_disable_asynccancel
  105. # define __local_multiple_threads __libc_multiple_threads
  106. # endif
  107. # ifdef __PIC__
  108. # define CENABLE bsr ra, __local_enable_asynccancel !samegp
  109. # define CDISABLE bsr ra, __local_disable_asynccancel !samegp
  110. # else
  111. # define CENABLE jsr ra, __local_enable_asynccancel; ldgp ra, 0(gp)
  112. # define CDISABLE jsr ra, __local_disable_asynccancel; ldgp ra, 0(gp)
  113. # endif
  114. # ifndef __ASSEMBLER__
  115. extern int __local_multiple_threads attribute_hidden;
  116. # define SINGLE_THREAD_P \
  117. __builtin_expect (__local_multiple_threads == 0, 1)
  118. # elif defined(__PIC__)
  119. # define SINGLE_THREAD_P(reg) ldl reg, __local_multiple_threads(gp) !gprel
  120. # else
  121. # define SINGLE_THREAD_P(reg) \
  122. ldah reg, __local_multiple_threads(gp) !gprelhigh; \
  123. ldl reg, __local_multiple_threads(reg) !gprellow
  124. # endif
  125. #elif !defined __ASSEMBLER__
  126. /* This code should never be used but we define it anyhow. */
  127. # define SINGLE_THREAD_P (1)
  128. #endif