sysdep-cancel.h 5.9 KB

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