sysdep-cancel.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <sysdep.h>
  17. #include <tls.h>
  18. #ifndef __ASSEMBLER__
  19. # include <linuxthreads/internals.h>
  20. #endif
  21. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  22. # undef PSEUDO
  23. # define PSEUDO(name, syscall_name, args) \
  24. .section ".text"; \
  25. ENTRY (name) \
  26. SINGLE_THREAD_P; \
  27. bne- .Lpseudo_cancel; \
  28. DO_CALL (SYS_ify (syscall_name)); \
  29. PSEUDO_RET; \
  30. .Lpseudo_cancel: \
  31. stwu 1,-48(1); \
  32. mflr 9; \
  33. stw 9,52(1); \
  34. CGOTSETUP; \
  35. DOCARGS_##args; /* save syscall args around CENABLE. */ \
  36. CENABLE; \
  37. stw 3,16(1); /* store CENABLE return value (MASK). */ \
  38. UNDOCARGS_##args; /* restore syscall args. */ \
  39. DO_CALL (SYS_ify (syscall_name)); \
  40. mfcr 0; /* save CR/R3 around CDISABLE. */ \
  41. stw 3,8(1); \
  42. stw 0,12(1); \
  43. lwz 3,16(1); /* pass MASK to CDISABLE. */ \
  44. CDISABLE; \
  45. lwz 4,52(1); \
  46. lwz 0,12(1); /* restore CR/R3. */ \
  47. lwz 3,8(1); \
  48. CGOTRESTORE; \
  49. mtlr 4; \
  50. mtcr 0; \
  51. addi 1,1,48;
  52. # define DOCARGS_0
  53. # define UNDOCARGS_0
  54. # define DOCARGS_1 stw 3,20(1); DOCARGS_0
  55. # define UNDOCARGS_1 lwz 3,20(1); UNDOCARGS_0
  56. # define DOCARGS_2 stw 4,24(1); DOCARGS_1
  57. # define UNDOCARGS_2 lwz 4,24(1); UNDOCARGS_1
  58. # define DOCARGS_3 stw 5,28(1); DOCARGS_2
  59. # define UNDOCARGS_3 lwz 5,28(1); UNDOCARGS_2
  60. # define DOCARGS_4 stw 6,32(1); DOCARGS_3
  61. # define UNDOCARGS_4 lwz 6,32(1); UNDOCARGS_3
  62. # define DOCARGS_5 stw 7,36(1); DOCARGS_4
  63. # define UNDOCARGS_5 lwz 7,36(1); UNDOCARGS_4
  64. # define DOCARGS_6 stw 8,40(1); DOCARGS_5
  65. # define UNDOCARGS_6 lwz 8,40(1); UNDOCARGS_5
  66. # define CGOTSETUP
  67. # define CGOTRESTORE
  68. # ifdef IS_IN_libpthread
  69. # define CENABLE bl __pthread_enable_asynccancel@local
  70. # define CDISABLE bl __pthread_disable_asynccancel@local
  71. # elif !defined NOT_IN_libc
  72. # define CENABLE bl __libc_enable_asynccancel@local
  73. # define CDISABLE bl __libc_disable_asynccancel@local
  74. # else
  75. # define CENABLE bl JUMPTARGET(__librt_enable_asynccancel)
  76. # define CDISABLE bl JUMPTARGET(__librt_disable_asynccancel)
  77. # if defined HAVE_AS_REL16 && defined __PIC__
  78. # undef CGOTSETUP
  79. # define CGOTSETUP \
  80. bcl 20,31,1f; \
  81. 1: stw 30,44(1); \
  82. mflr 30; \
  83. addis 30,30,_GLOBAL_OFFSET_TABLE-1b@ha; \
  84. addi 30,30,_GLOBAL_OFFSET_TABLE-1b@l
  85. # undef CGOTRESTORE
  86. # define CGOTRESTORE \
  87. lwz 30,44(1)
  88. # endif
  89. # endif
  90. # ifdef HAVE_TLS_SUPPORT
  91. # ifndef __ASSEMBLER__
  92. # define SINGLE_THREAD_P \
  93. __builtin_expect (THREAD_GETMEM (THREAD_SELF, p_multiple_threads) == 0, 1)
  94. # else
  95. # define SINGLE_THREAD_P \
  96. lwz 10,MULTIPLE_THREADS_OFFSET(2); \
  97. cmpwi 10,0
  98. # endif
  99. # else
  100. # if !defined NOT_IN_libc
  101. # define __local_multiple_threads __libc_multiple_threads
  102. # else
  103. # define __local_multiple_threads __librt_multiple_threads
  104. # endif
  105. # ifndef __ASSEMBLER__
  106. extern int __local_multiple_threads attribute_hidden;
  107. # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  108. # else
  109. # if !defined __PIC__
  110. # define SINGLE_THREAD_P \
  111. lis 10,__local_multiple_threads@ha; \
  112. lwz 10,__local_multiple_threads@l(10); \
  113. cmpwi 10,0
  114. # else
  115. # ifdef HAVE_ASM_PPC_REL16
  116. # define SINGLE_THREAD_P \
  117. mflr 9; \
  118. bcl 20,31,1f; \
  119. 1:mflr 10; \
  120. addis 10,10,__local_multiple_threads-1b@ha; \
  121. lwz 10,__local_multiple_threads-1b@l(10); \
  122. mtlr 9; \
  123. cmpwi 10,0
  124. # else
  125. # define SINGLE_THREAD_P \
  126. mflr 9; \
  127. bl _GLOBAL_OFFSET_TABLE_@local-4; \
  128. mflr 10; \
  129. mtlr 9; \
  130. lwz 10,__local_multiple_threads@got(10); \
  131. lwz 10,0(10); \
  132. cmpwi 10,0
  133. # endif
  134. # endif
  135. # endif
  136. # endif
  137. #elif !defined __ASSEMBLER__
  138. /* This code should never be used but we define it anyhow. */
  139. # define SINGLE_THREAD_P (1)
  140. #endif