sysdep-cancel.h 6.3 KB

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