sysdep-cancel.h 6.3 KB

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