sysdep-cancel.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* Copyright (C) 2003, 2005 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Franz Sirl <Franz.Sirl-kernel@lauterbach.com>, 2003.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #include <tls.h>
  17. #ifndef __ASSEMBLER__
  18. # include <linuxthreads/internals.h>
  19. #endif
  20. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  21. # undef PSEUDO
  22. # define PSEUDO(name, syscall_name, args) \
  23. .section ".text"; \
  24. ENTRY (name) \
  25. SINGLE_THREAD_P; \
  26. bne- .Lpseudo_cancel; \
  27. DO_CALL (SYS_ify (syscall_name)); \
  28. PSEUDO_RET; \
  29. .Lpseudo_cancel: \
  30. stwu 1,-48(1); \
  31. mflr 9; \
  32. stw 9,52(1); \
  33. CGOTSETUP; \
  34. DOCARGS_##args; /* save syscall args around CENABLE. */ \
  35. CENABLE; \
  36. stw 3,16(1); /* store CENABLE return value (MASK). */ \
  37. UNDOCARGS_##args; /* restore syscall args. */ \
  38. DO_CALL (SYS_ify (syscall_name)); \
  39. mfcr 0; /* save CR/R3 around CDISABLE. */ \
  40. stw 3,8(1); \
  41. stw 0,12(1); \
  42. lwz 3,16(1); /* pass MASK to CDISABLE. */ \
  43. CDISABLE; \
  44. lwz 4,52(1); \
  45. lwz 0,12(1); /* restore CR/R3. */ \
  46. lwz 3,8(1); \
  47. CGOTRESTORE; \
  48. mtlr 4; \
  49. mtcr 0; \
  50. addi 1,1,48;
  51. # define DOCARGS_0
  52. # define UNDOCARGS_0
  53. # define DOCARGS_1 stw 3,20(1); DOCARGS_0
  54. # define UNDOCARGS_1 lwz 3,20(1); UNDOCARGS_0
  55. # define DOCARGS_2 stw 4,24(1); DOCARGS_1
  56. # define UNDOCARGS_2 lwz 4,24(1); UNDOCARGS_1
  57. # define DOCARGS_3 stw 5,28(1); DOCARGS_2
  58. # define UNDOCARGS_3 lwz 5,28(1); UNDOCARGS_2
  59. # define DOCARGS_4 stw 6,32(1); DOCARGS_3
  60. # define UNDOCARGS_4 lwz 6,32(1); UNDOCARGS_3
  61. # define DOCARGS_5 stw 7,36(1); DOCARGS_4
  62. # define UNDOCARGS_5 lwz 7,36(1); UNDOCARGS_4
  63. # define DOCARGS_6 stw 8,40(1); DOCARGS_5
  64. # define UNDOCARGS_6 lwz 8,40(1); UNDOCARGS_5
  65. # define CGOTSETUP
  66. # define CGOTRESTORE
  67. # ifdef IS_IN_libpthread
  68. # define CENABLE bl __pthread_enable_asynccancel@local
  69. # define CDISABLE bl __pthread_disable_asynccancel@local
  70. # elif !defined NOT_IN_libc
  71. # define CENABLE bl __libc_enable_asynccancel@local
  72. # define CDISABLE bl __libc_disable_asynccancel@local
  73. # else
  74. # define CENABLE bl JUMPTARGET(__librt_enable_asynccancel)
  75. # define CDISABLE bl JUMPTARGET(__librt_disable_asynccancel)
  76. # if defined HAVE_AS_REL16 && defined __PIC__
  77. # undef CGOTSETUP
  78. # define CGOTSETUP \
  79. bcl 20,31,1f; \
  80. 1: stw 30,44(1); \
  81. mflr 30; \
  82. addis 30,30,_GLOBAL_OFFSET_TABLE-1b@ha; \
  83. addi 30,30,_GLOBAL_OFFSET_TABLE-1b@l
  84. # undef CGOTRESTORE
  85. # define CGOTRESTORE \
  86. lwz 30,44(1)
  87. # endif
  88. # endif
  89. # ifdef HAVE_TLS_SUPPORT
  90. # ifndef __ASSEMBLER__
  91. # define SINGLE_THREAD_P \
  92. __builtin_expect (THREAD_GETMEM (THREAD_SELF, p_multiple_threads) == 0, 1)
  93. # else
  94. # define SINGLE_THREAD_P \
  95. lwz 10,MULTIPLE_THREADS_OFFSET(2); \
  96. cmpwi 10,0
  97. # endif
  98. # else
  99. # if !defined NOT_IN_libc
  100. # define __local_multiple_threads __libc_multiple_threads
  101. # else
  102. # define __local_multiple_threads __librt_multiple_threads
  103. # endif
  104. # ifndef __ASSEMBLER__
  105. extern int __local_multiple_threads attribute_hidden;
  106. # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  107. # else
  108. # if !defined __PIC__
  109. # define SINGLE_THREAD_P \
  110. lis 10,__local_multiple_threads@ha; \
  111. lwz 10,__local_multiple_threads@l(10); \
  112. cmpwi 10,0
  113. # else
  114. # ifdef HAVE_ASM_PPC_REL16
  115. # define SINGLE_THREAD_P \
  116. mflr 9; \
  117. bcl 20,31,1f; \
  118. 1:mflr 10; \
  119. addis 10,10,__local_multiple_threads-1b@ha; \
  120. lwz 10,__local_multiple_threads-1b@l(10); \
  121. mtlr 9; \
  122. cmpwi 10,0
  123. # else
  124. # define SINGLE_THREAD_P \
  125. mflr 9; \
  126. bl _GLOBAL_OFFSET_TABLE_@local-4; \
  127. mflr 10; \
  128. mtlr 9; \
  129. lwz 10,__local_multiple_threads@got(10); \
  130. lwz 10,0(10); \
  131. cmpwi 10,0
  132. # endif
  133. # endif
  134. # endif
  135. # endif
  136. #elif !defined __ASSEMBLER__
  137. /* This code should never be used but we define it anyhow. */
  138. # define SINGLE_THREAD_P (1)
  139. #endif