sysdep-cancel.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* Copyright (C) 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If
  13. not, see <http://www.gnu.org/licenses/>.  */
  14. #include <tls.h>
  15. #include <sysdep.h>
  16. #ifndef __ASSEMBLER__
  17. # include <pthreadP.h>
  18. #endif
  19. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  20. /* NOTE: We do mark syscalls with unwind annotations, for the benefit of
  21. cancellation; but they're really only accurate at the point of the
  22. syscall. The ARM unwind directives are not rich enough without adding
  23. a custom personality function. */
  24. #ifdef __ASSEMBLER__
  25. #undef ret
  26. #define ret \
  27. CMP D0Re0, #-4095; \
  28. MOVLO PC, D1RtP; \
  29. MOV D1Ar1, D0Re0; \
  30. B SYSCALL_ERROR;
  31. #endif /* __ASSEMBLER__ */
  32. # undef PSEUDO
  33. # define PSEUDO(name, syscall_name, args) \
  34. .section ".text"; \
  35. .type ___##syscall_name##_nocancel,%function; \
  36. .globl ___##syscall_name##_nocancel; \
  37. ___##syscall_name##_nocancel: \
  38. cfi_startproc; \
  39. DO_CALL (syscall_name, args); \
  40. MOV PC, D1RtP; \
  41. cfi_endproc; \
  42. .size ___##syscall_name##_nocancel,.-___##syscall_name##_nocancel; \
  43. .globl _##name; \
  44. .type _##name, @function; \
  45. name##: \
  46. _##name##: \
  47. DOCARGS_##args; \
  48. SINGLE_THREAD_P; \
  49. UNDOCARGS_##args; \
  50. BNE .Lpseudo_cancel; \
  51. cfi_remember_state; \
  52. DO_CALL (syscall_name, 0); \
  53. ret \
  54. cfi_restore_state; \
  55. .Lpseudo_cancel: \
  56. MSETL [A0StP++], D0FrT, D0.5; \
  57. DOCARGS_##args; /* save syscall args etc. around CENABLE. */ \
  58. CENABLE; \
  59. MOV D0FrT, D0Re0; /* put mask in safe place. */ \
  60. UNDOCARGS_##args; /* restore syscall args. */ \
  61. DO_CALL(syscall_name, 0); /* do the call. */ \
  62. MOV D0.5, D0Re0; /* save syscall return value. */ \
  63. MOV D1Ar1, D0FrT; /* get mask back. */ \
  64. CDISABLE; \
  65. MOV D0Re0, D0.5; /* retrieve return value. */ \
  66. GETL D0.5, D1.5, [--A0StP]; \
  67. GETL D0FrT, D1RtP, [--A0StP];
  68. # define DOCARGS_0
  69. # define UNDOCARGS_0
  70. # define DOCARGS_1 \
  71. SETL [A0StP++], D1Ar1, D0Ar2
  72. # define UNDOCARGS_1 \
  73. GETL D1Ar1, D0Ar2, [--A0StP]
  74. # define DOCARGS_2 DOCARGS_1
  75. # define UNDOCARGS_2 UNDOCARGS_2
  76. # define DOCARGS_3 \
  77. MSETL [A0StP++], D1Ar1, D1Ar3
  78. # define UNDOCARGS_3 \
  79. GETL D1Ar1, D0Ar2, [--A0StP]; \
  80. GETL D1Ar3, D0Ar4, [--A0StP]
  81. # define DOCARGS_4 DOCARGS_3
  82. # define UNDOCARGS_4 UNDOCARGS_3
  83. # define DOCARGS_5 \
  84. MSETL [A0StP++], D1Ar1, D1Ar3, D1Ar5
  85. # define UNDOCARGS_5 \
  86. GETL D1Ar1, D0Ar2, [--A0StP]; \
  87. GETL D1Ar3, D0Ar4, [--A0StP]; \
  88. GETL D1Ar5, D0Ar6, [--A0StP]
  89. # define DOCARGS_6 DOCARGS_5
  90. # define UNDOCARGS_6 UNDOCARGS_5
  91. # ifdef IS_IN_libpthread
  92. # define CENABLE CALLR D1RtP, ___pthread_enable_asynccancel@PLT
  93. # define CDISABLE CALLR D1RtP, ___pthread_disable_asynccancel@PLT
  94. # define __local_multiple_threads __pthread_multiple_threads
  95. # elif !defined NOT_IN_libc
  96. # define CENABLE CALLR D1RtP, ___libc_enable_asynccancel@PLT
  97. # define CDISABLE CALLR D1RtP, ___libc_disable_asynccancel@PLT
  98. # define __local_multiple_threads __libc_multiple_threads
  99. # elif defined IS_IN_librt
  100. # define CENABLE CALLR D1RtP, ___librt_enable_asynccancel@PLT
  101. # define CDISABLE CALLR D1RtP, ___librt_disable_asynccancel@PLT
  102. # else
  103. # error Unsupported library
  104. # endif
  105. #ifndef __ASSEMBLER__
  106. # define SINGLE_THREAD_P \
  107. likely(THREAD_GETMEM (THREAD_SELF, \
  108. header.multiple_threads) == 0)
  109. #else
  110. # define SINGLE_THREAD_P \
  111. SETL [A0StP++], D0FrT, D1RtP; \
  112. CALLR D1RtP, ___metag_load_tp@PLT; \
  113. SUB D0Re0, D0Re0, #TLS_PRE_TCB_SIZE; \
  114. GETD D0Re0, [D0Re0 + #MULTIPLE_THREADS_OFFSET]; \
  115. CMP D0Re0, #0; \
  116. GETL D0FrT, D1RtP, [--A0StP]
  117. #endif
  118. #elif !defined __ASSEMBLER__
  119. /* For rtld, et cetera. */
  120. # define SINGLE_THREAD_P 1
  121. # define NO_CANCELLATION 1
  122. #endif
  123. #ifndef __ASSEMBLER__
  124. # define RTLD_SINGLE_THREAD_P \
  125. likely(THREAD_GETMEM (THREAD_SELF, \
  126. header.multiple_threads) == 0)
  127. #endif