sysdep-cancel.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* Copyright (C) 2003, 2004, 2005 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 <pthreadP.h>
  18. #endif
  19. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  20. # ifdef __PIC__
  21. # define PSEUDO_CPLOAD .cpload t9;
  22. # define PSEUDO_ERRJMP move a0, v0; la t9, __syscall_error; jr t9;
  23. # define PSEUDO_SAVEGP sw gp, 32(sp); cfi_rel_offset (gp, 32);
  24. # define PSEUDO_LOADGP lw gp, 32(sp);
  25. # else
  26. # define PSEUDO_CPLOAD
  27. # define PSEUDO_ERRJMP move a0, v0; j __syscall_error;
  28. # define PSEUDO_SAVEGP
  29. # define PSEUDO_LOADGP
  30. # endif
  31. # undef PSEUDO
  32. # define PSEUDO(name, syscall_name, args) \
  33. .align 2; \
  34. L(pseudo_start): \
  35. cfi_startproc; \
  36. 99: PSEUDO_ERRJMP \
  37. .type __##syscall_name##_nocancel, @function; \
  38. .globl __##syscall_name##_nocancel; \
  39. __##syscall_name##_nocancel: \
  40. .set noreorder; \
  41. PSEUDO_CPLOAD \
  42. li v0, SYS_ify(syscall_name); \
  43. syscall; \
  44. .set reorder; \
  45. bne a3, zero, 99b; \
  46. ret; \
  47. .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
  48. ENTRY (name) \
  49. .set noreorder; \
  50. PSEUDO_CPLOAD \
  51. .set reorder; \
  52. SINGLE_THREAD_P(v1); \
  53. bne zero, v1, L(pseudo_cancel); \
  54. .set noreorder; \
  55. li v0, SYS_ify(syscall_name); \
  56. syscall; \
  57. .set reorder; \
  58. bne a3, zero, 99b; \
  59. ret; \
  60. L(pseudo_cancel): \
  61. SAVESTK_##args; \
  62. sw ra, 28(sp); \
  63. cfi_rel_offset (ra, 28); \
  64. PSEUDO_SAVEGP \
  65. PUSHARGS_##args; /* save syscall args */ \
  66. CENABLE; \
  67. PSEUDO_LOADGP \
  68. sw v0, 44(sp); /* save mask */ \
  69. POPARGS_##args; /* restore syscall args */ \
  70. .set noreorder; \
  71. li v0, SYS_ify (syscall_name); \
  72. syscall; \
  73. .set reorder; \
  74. sw v0, 36(sp); /* save syscall result */ \
  75. sw a3, 40(sp); /* save syscall error flag */ \
  76. lw a0, 44(sp); /* pass mask as arg1 */ \
  77. CDISABLE; \
  78. PSEUDO_LOADGP \
  79. lw v0, 36(sp); /* restore syscall result */ \
  80. lw a3, 40(sp); /* restore syscall error flag */ \
  81. lw ra, 28(sp); /* restore return address */ \
  82. .set noreorder; \
  83. bne a3, zero, 99b; \
  84. RESTORESTK; \
  85. L(pseudo_end): \
  86. .set reorder;
  87. # undef PSEUDO_END
  88. # define PSEUDO_END(sym) cfi_endproc; .end sym; .size sym,.-sym
  89. # define PUSHARGS_0 /* nothing to do */
  90. # define PUSHARGS_1 PUSHARGS_0 sw a0, 0(sp); cfi_rel_offset (a0, 0);
  91. # define PUSHARGS_2 PUSHARGS_1 sw a1, 4(sp); cfi_rel_offset (a1, 4);
  92. # define PUSHARGS_3 PUSHARGS_2 sw a2, 8(sp); cfi_rel_offset (a2, 8);
  93. # define PUSHARGS_4 PUSHARGS_3 sw a3, 12(sp); cfi_rel_offset (a3, 12);
  94. # define PUSHARGS_5 PUSHARGS_4 /* handled by SAVESTK_## */
  95. # define PUSHARGS_6 PUSHARGS_5
  96. # define PUSHARGS_7 PUSHARGS_6
  97. # define POPARGS_0 /* nothing to do */
  98. # define POPARGS_1 POPARGS_0 lw a0, 0(sp);
  99. # define POPARGS_2 POPARGS_1 lw a1, 4(sp);
  100. # define POPARGS_3 POPARGS_2 lw a2, 8(sp);
  101. # define POPARGS_4 POPARGS_3 lw a3, 12(sp);
  102. # define POPARGS_5 POPARGS_4 /* args already in new stackframe */
  103. # define POPARGS_6 POPARGS_5
  104. # define POPARGS_7 POPARGS_6
  105. # define STKSPACE 48
  106. # define SAVESTK_0 subu sp, STKSPACE; cfi_adjust_cfa_offset(STKSPACE)
  107. # define SAVESTK_1 SAVESTK_0
  108. # define SAVESTK_2 SAVESTK_1
  109. # define SAVESTK_3 SAVESTK_2
  110. # define SAVESTK_4 SAVESTK_3
  111. # define SAVESTK_5 lw t0, 16(sp); \
  112. SAVESTK_0; \
  113. sw t0, 16(sp)
  114. # define SAVESTK_6 lw t0, 16(sp); \
  115. lw t1, 20(sp); \
  116. SAVESTK_0; \
  117. sw t0, 16(sp); \
  118. sw t1, 20(sp)
  119. # define SAVESTK_7 lw t0, 16(sp); \
  120. lw t1, 20(sp); \
  121. lw t2, 24(sp); \
  122. SAVESTK_0; \
  123. sw t0, 16(sp); \
  124. sw t1, 20(sp); \
  125. sw t2, 24(sp)
  126. # define RESTORESTK addu sp, STKSPACE; cfi_adjust_cfa_offset(-STKSPACE)
  127. # ifdef __PIC__
  128. /* We use jalr rather than jal. This means that the assembler will not
  129. automatically restore $gp (in case libc has multiple GOTs) so we must
  130. do it manually - which we have to do anyway since we don't use .cprestore.
  131. It also shuts up the assembler warning about not using .cprestore. */
  132. # define PSEUDO_JMP(sym) la t9, sym; jalr t9;
  133. # else
  134. # define PSEUDO_JMP(sym) jal sym;
  135. # endif
  136. # ifdef IS_IN_libpthread
  137. # define CENABLE PSEUDO_JMP (__pthread_enable_asynccancel)
  138. # define CDISABLE PSEUDO_JMP (__pthread_disable_asynccancel)
  139. # elif defined IS_IN_librt
  140. # define CENABLE PSEUDO_JMP (__librt_enable_asynccancel)
  141. # define CDISABLE PSEUDO_JMP (__librt_disable_asynccancel)
  142. # else
  143. # define CENABLE PSEUDO_JMP (__libc_enable_asynccancel)
  144. # define CDISABLE PSEUDO_JMP (__libc_disable_asynccancel)
  145. # endif
  146. # ifndef __ASSEMBLER__
  147. # define SINGLE_THREAD_P \
  148. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  149. header.multiple_threads) \
  150. == 0, 1)
  151. # else
  152. # define SINGLE_THREAD_P(reg) \
  153. READ_THREAD_POINTER(reg); \
  154. lw reg, MULTIPLE_THREADS_OFFSET(reg)
  155. #endif
  156. #elif !defined __ASSEMBLER__
  157. # define SINGLE_THREAD_P 1
  158. # define NO_CANCELLATION 1
  159. #endif
  160. #ifndef __ASSEMBLER__
  161. # define RTLD_SINGLE_THREAD_P \
  162. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  163. header.multiple_threads) == 0, 1)
  164. #endif