sysdep-cancel.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* Copyright (C) 2002, 2003, 2004, 2005, 2006 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 <sysdep.h>
  17. #include <tls.h>
  18. #ifndef __ASSEMBLER__
  19. # include <pthreadP.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. cmpl $0, %gs:MULTIPLE_THREADS_OFFSET; \
  27. jne L(pseudo_cancel); \
  28. .type __##syscall_name##_nocancel,@function; \
  29. .globl __##syscall_name##_nocancel; \
  30. __##syscall_name##_nocancel: \
  31. DO_CALL (syscall_name, args); \
  32. cmpl $-4095, %eax; \
  33. jae SYSCALL_ERROR_LABEL; \
  34. ret; \
  35. .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
  36. L(pseudo_cancel): \
  37. CENABLE \
  38. SAVE_OLDTYPE_##args \
  39. PUSHCARGS_##args \
  40. DOCARGS_##args \
  41. movl $SYS_ify (syscall_name), %eax; \
  42. ENTER_KERNEL; \
  43. POPCARGS_##args; \
  44. POPSTATE_##args \
  45. cmpl $-4095, %eax; \
  46. jae SYSCALL_ERROR_LABEL; \
  47. L(pseudo_end):
  48. # define SAVE_OLDTYPE_0 movl %eax, %ecx;
  49. # define SAVE_OLDTYPE_1 SAVE_OLDTYPE_0
  50. # define SAVE_OLDTYPE_2 pushl %eax; cfi_adjust_cfa_offset (4);
  51. # define SAVE_OLDTYPE_3 SAVE_OLDTYPE_2
  52. # define SAVE_OLDTYPE_4 SAVE_OLDTYPE_2
  53. # define SAVE_OLDTYPE_5 SAVE_OLDTYPE_2
  54. # define SAVE_OLDTYPE_6 SAVE_OLDTYPE_2
  55. # define PUSHCARGS_0 /* No arguments to push. */
  56. # define DOCARGS_0 /* No arguments to frob. */
  57. # define POPCARGS_0 /* No arguments to pop. */
  58. # define _PUSHCARGS_0 /* No arguments to push. */
  59. # define _POPCARGS_0 /* No arguments to pop. */
  60. # define PUSHCARGS_1 movl %ebx, %edx; cfi_register (ebx, edx); PUSHCARGS_0
  61. # define DOCARGS_1 _DOARGS_1 (4)
  62. # define POPCARGS_1 POPCARGS_0; movl %edx, %ebx; cfi_restore (ebx);
  63. # define _PUSHCARGS_1 pushl %ebx; cfi_adjust_cfa_offset (4); \
  64. cfi_rel_offset (ebx, 0); _PUSHCARGS_0
  65. # define _POPCARGS_1 _POPCARGS_0; popl %ebx; \
  66. cfi_adjust_cfa_offset (-4); cfi_restore (ebx);
  67. # define PUSHCARGS_2 PUSHCARGS_1
  68. # define DOCARGS_2 _DOARGS_2 (12)
  69. # define POPCARGS_2 POPCARGS_1
  70. # define _PUSHCARGS_2 _PUSHCARGS_1
  71. # define _POPCARGS_2 _POPCARGS_1
  72. # define PUSHCARGS_3 _PUSHCARGS_2
  73. # define DOCARGS_3 _DOARGS_3 (20)
  74. # define POPCARGS_3 _POPCARGS_3
  75. # define _PUSHCARGS_3 _PUSHCARGS_2
  76. # define _POPCARGS_3 _POPCARGS_2
  77. # define PUSHCARGS_4 _PUSHCARGS_4
  78. # define DOCARGS_4 _DOARGS_4 (28)
  79. # define POPCARGS_4 _POPCARGS_4
  80. # define _PUSHCARGS_4 pushl %esi; cfi_adjust_cfa_offset (4); \
  81. cfi_rel_offset (esi, 0); _PUSHCARGS_3
  82. # define _POPCARGS_4 _POPCARGS_3; popl %esi; \
  83. cfi_adjust_cfa_offset (-4); cfi_restore (esi);
  84. # define PUSHCARGS_5 _PUSHCARGS_5
  85. # define DOCARGS_5 _DOARGS_5 (36)
  86. # define POPCARGS_5 _POPCARGS_5
  87. # define _PUSHCARGS_5 pushl %edi; cfi_adjust_cfa_offset (4); \
  88. cfi_rel_offset (edi, 0); _PUSHCARGS_4
  89. # define _POPCARGS_5 _POPCARGS_4; popl %edi; \
  90. cfi_adjust_cfa_offset (-4); cfi_restore (edi);
  91. # define PUSHCARGS_6 _PUSHCARGS_6
  92. # define DOCARGS_6 _DOARGS_6 (44)
  93. # define POPCARGS_6 _POPCARGS_6
  94. # define _PUSHCARGS_6 pushl %ebp; cfi_adjust_cfa_offset (4); \
  95. cfi_rel_offset (ebp, 0); _PUSHCARGS_5
  96. # define _POPCARGS_6 _POPCARGS_5; popl %ebp; \
  97. cfi_adjust_cfa_offset (-4); cfi_restore (ebp);
  98. # ifdef IS_IN_libpthread
  99. # define CENABLE call __pthread_enable_asynccancel;
  100. # define CDISABLE call __pthread_disable_asynccancel
  101. # elif !defined NOT_IN_libc
  102. # define CENABLE call __libc_enable_asynccancel;
  103. # define CDISABLE call __libc_disable_asynccancel
  104. # elif defined IS_IN_librt
  105. # define CENABLE call __librt_enable_asynccancel;
  106. # define CDISABLE call __librt_disable_asynccancel
  107. # else
  108. # error Unsupported library
  109. # endif
  110. # define POPSTATE_0 \
  111. pushl %eax; cfi_adjust_cfa_offset (4); movl %ecx, %eax; \
  112. CDISABLE; popl %eax; cfi_adjust_cfa_offset (-4);
  113. # define POPSTATE_1 POPSTATE_0
  114. # define POPSTATE_2 xchgl (%esp), %eax; CDISABLE; popl %eax; \
  115. cfi_adjust_cfa_offset (-4);
  116. # define POPSTATE_3 POPSTATE_2
  117. # define POPSTATE_4 POPSTATE_3
  118. # define POPSTATE_5 POPSTATE_4
  119. # define POPSTATE_6 POPSTATE_5
  120. # ifndef __ASSEMBLER__
  121. # define SINGLE_THREAD_P \
  122. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  123. header.multiple_threads) == 0, 1)
  124. # else
  125. # define SINGLE_THREAD_P cmpl $0, %gs:MULTIPLE_THREADS_OFFSET
  126. # endif
  127. #elif !defined __ASSEMBLER__
  128. # define SINGLE_THREAD_P (1)
  129. # define NO_CANCELLATION 1
  130. #endif
  131. #ifndef __ASSEMBLER__
  132. # define RTLD_SINGLE_THREAD_P \
  133. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  134. header.multiple_threads) == 0, 1)
  135. #endif