sysdep-cancel.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
  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 <tls.h>
  16. #include <pt-machine.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. .text; \
  24. ENTRY (name) \
  25. SINGLE_THREAD_P; \
  26. jne L(pseudo_cancel); \
  27. DO_CALL (syscall_name, args); \
  28. cmpl $-4095, %eax; \
  29. jae SYSCALL_ERROR_LABEL; \
  30. ret; \
  31. L(pseudo_cancel): \
  32. CENABLE \
  33. SAVE_OLDTYPE_##args \
  34. PUSHCARGS_##args \
  35. DOCARGS_##args \
  36. movl $SYS_ify (syscall_name), %eax; \
  37. int $0x80 \
  38. POPCARGS_##args; \
  39. POPSTATE_##args \
  40. cmpl $-4095, %eax; \
  41. jae SYSCALL_ERROR_LABEL; \
  42. L(pseudo_end):
  43. # define SAVE_OLDTYPE_0 movl %eax, %ecx;
  44. # define SAVE_OLDTYPE_1 SAVE_OLDTYPE_0
  45. # define SAVE_OLDTYPE_2 pushl %eax; cfi_adjust_cfa_offset (4);
  46. # define SAVE_OLDTYPE_3 SAVE_OLDTYPE_2
  47. # define SAVE_OLDTYPE_4 SAVE_OLDTYPE_2
  48. # define SAVE_OLDTYPE_5 SAVE_OLDTYPE_2
  49. # define PUSHCARGS_0 /* No arguments to push. */
  50. # define DOCARGS_0 /* No arguments to frob. */
  51. # define POPCARGS_0 /* No arguments to pop. */
  52. # define _PUSHCARGS_0 /* No arguments to push. */
  53. # define _POPCARGS_0 /* No arguments to pop. */
  54. # define PUSHCARGS_1 movl %ebx, %edx; cfi_register (ebx, edx); PUSHCARGS_0
  55. # define DOCARGS_1 _DOARGS_1 (4)
  56. # define POPCARGS_1 POPCARGS_0; movl %edx, %ebx; cfi_restore (ebx);
  57. # define _PUSHCARGS_1 pushl %ebx; cfi_adjust_cfa_offset (4); \
  58. cfi_rel_offset (ebx, 0); _PUSHCARGS_0
  59. # define _POPCARGS_1 _POPCARGS_0; popl %ebx; \
  60. cfi_adjust_cfa_offset (-4); cfi_restore (ebx);
  61. # define PUSHCARGS_2 PUSHCARGS_1
  62. # define DOCARGS_2 _DOARGS_2 (12)
  63. # define POPCARGS_2 POPCARGS_1
  64. # define _PUSHCARGS_2 _PUSHCARGS_1
  65. # define _POPCARGS_2 _POPCARGS_1
  66. # define PUSHCARGS_3 _PUSHCARGS_2
  67. # define DOCARGS_3 _DOARGS_3 (20)
  68. # define POPCARGS_3 _POPCARGS_3
  69. # define _PUSHCARGS_3 _PUSHCARGS_2
  70. # define _POPCARGS_3 _POPCARGS_2
  71. # define PUSHCARGS_4 _PUSHCARGS_4
  72. # define DOCARGS_4 _DOARGS_4 (28)
  73. # define POPCARGS_4 _POPCARGS_4
  74. # define _PUSHCARGS_4 pushl %esi; cfi_adjust_cfa_offset (4); \
  75. cfi_rel_offset (esi, 0); _PUSHCARGS_3
  76. # define _POPCARGS_4 _POPCARGS_3; popl %esi; \
  77. cfi_adjust_cfa_offset (-4); cfi_restore (esi);
  78. # define PUSHCARGS_5 _PUSHCARGS_5
  79. # define DOCARGS_5 _DOARGS_5 (36)
  80. # define POPCARGS_5 _POPCARGS_5
  81. # define _PUSHCARGS_5 pushl %edi; cfi_adjust_cfa_offset (4); \
  82. cfi_rel_offset (edi, 0); _PUSHCARGS_4
  83. # define _POPCARGS_5 _POPCARGS_4; popl %edi; \
  84. cfi_adjust_cfa_offset (-4); cfi_restore (edi);
  85. # ifdef IS_IN_libpthread
  86. # define CENABLE call __pthread_enable_asynccancel;
  87. # define CDISABLE call __pthread_disable_asynccancel
  88. # elif defined IS_IN_librt
  89. # ifdef __PIC__
  90. # define CENABLE pushl %ebx; \
  91. call __i686.get_pc_thunk.bx; \
  92. addl $_GLOBAL_OFFSET_TABLE_, %ebx; \
  93. call __librt_enable_asynccancel@PLT; \
  94. popl %ebx;
  95. # define CDISABLE pushl %ebx; \
  96. call __i686.get_pc_thunk.bx; \
  97. addl $_GLOBAL_OFFSET_TABLE_, %ebx; \
  98. call __librt_disable_asynccancel@PLT; \
  99. popl %ebx;
  100. # else
  101. # define CENABLE call __librt_enable_asynccancel;
  102. # define CDISABLE call __librt_disable_asynccancel
  103. # endif
  104. # else
  105. # define CENABLE call __libc_enable_asynccancel;
  106. # define CDISABLE call __libc_disable_asynccancel
  107. # endif
  108. # define POPSTATE_0 \
  109. pushl %eax; cfi_adjust_cfa_offset (4); movl %ecx, %eax; \
  110. CDISABLE; popl %eax; cfi_adjust_cfa_offset (-4);
  111. # define POPSTATE_1 POPSTATE_0
  112. # define POPSTATE_2 xchgl (%esp), %eax; CDISABLE; popl %eax; \
  113. cfi_adjust_cfa_offset (-4);
  114. # define POPSTATE_3 POPSTATE_2
  115. # define POPSTATE_4 POPSTATE_3
  116. # define POPSTATE_5 POPSTATE_4
  117. #if !defined NOT_IN_libc
  118. # define __local_multiple_threads __libc_multiple_threads
  119. #elif defined IS_IN_libpthread
  120. # define __local_multiple_threads __pthread_multiple_threads
  121. #else
  122. # define __local_multiple_threads __librt_multiple_threads
  123. #endif
  124. # ifndef __ASSEMBLER__
  125. # if defined FLOATING_STACKS && defined __UCLIBC_HAS_TLS__ && defined __PIC__
  126. # define SINGLE_THREAD_P \
  127. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  128. p_header.data.multiple_threads) == 0, 1)
  129. # else
  130. extern int __local_multiple_threads
  131. # if !defined NOT_IN_libc || defined IS_IN_libpthread
  132. attribute_hidden;
  133. # else
  134. ;
  135. # endif
  136. # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  137. # endif
  138. # else
  139. # if !defined __PIC__
  140. # define SINGLE_THREAD_P cmpl $0, __local_multiple_threads
  141. # elif defined FLOATING_STACKS && defined __UCLIBC_HAS_TLS__
  142. # define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET
  143. # else
  144. # if !defined NOT_IN_libc || defined IS_IN_libpthread
  145. # define __SINGLE_THREAD_CMP cmpl $0, __local_multiple_threads@GOTOFF(%ecx)
  146. # else
  147. # define __SINGLE_THREAD_CMP \
  148. movl __local_multiple_threads@GOT(%ecx), %ecx;\
  149. cmpl $0, (%ecx)
  150. # endif
  151. # if !defined HAVE_HIDDEN || !defined __UCLIBC_HAS_TLS__
  152. # define SINGLE_THREAD_P \
  153. SETUP_PIC_REG (cx); \
  154. addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
  155. __SINGLE_THREAD_CMP
  156. # else
  157. # define SINGLE_THREAD_P \
  158. call __i686.get_pc_thunk.cx; \
  159. addl $_GLOBAL_OFFSET_TABLE_, %ecx; \
  160. __SINGLE_THREAD_CMP
  161. # endif
  162. # endif
  163. # endif
  164. #elif !defined __ASSEMBLER__
  165. /* This code should never be used but we define it anyhow. */
  166. # define SINGLE_THREAD_P (1)
  167. #endif