sysdep-cancel.h 5.4 KB

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