sysdep-cancel.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Copyright (C) 2003 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; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <sysdep.h>
  16. #include <tls.h>
  17. /* #include <pt-machine.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. /* CENABLE/CDISABLE in PSEUDO below use call8, stack frame size must be
  23. * at least 32.
  24. */
  25. #if FRAMESIZE < 32
  26. #undef FRAMESIZE
  27. #define FRAMESIZE 32
  28. #endif
  29. # undef PSEUDO
  30. # define PSEUDO(name, syscall_name, args) \
  31. .text; \
  32. ENTRY (name) \
  33. SINGLE_THREAD_P(a15); \
  34. bnez a15, .Lpseudo_cancel; \
  35. DO_CALL (syscall_name, args); \
  36. bgez a2, .Lpseudo_done; \
  37. movi a4, -4095; \
  38. blt a2, a4, .Lpseudo_done; \
  39. j SYSCALL_ERROR_LABEL; \
  40. .Lpseudo_done: \
  41. retw; \
  42. .Lpseudo_cancel: \
  43. /* The syscall args are in a2...a7; no need to save */ \
  44. CENABLE; \
  45. /* The return value is in a10 and preserved across the syscall */ \
  46. DO_CALL (syscall_name, args); \
  47. CDISABLE; \
  48. bgez a2, .Lpseudo_end; \
  49. movi a4, -4095; \
  50. blt a2, a4, .Lpseudo_end; \
  51. j SYSCALL_ERROR_LABEL; \
  52. .Lpseudo_end:
  53. # ifdef IS_IN_libpthread
  54. # define CENABLE_FUNC __pthread_enable_asynccancel
  55. # define CDISABLE_FUNC __pthread_disable_asynccancel
  56. # define __local_multiple_threads __pthread_multiple_threads
  57. # elif !defined NOT_IN_libc
  58. # define CENABLE_FUNC __libc_enable_asynccancel
  59. # define CDISABLE_FUNC __libc_disable_asynccancel
  60. # define __local_multiple_threads __libc_multiple_threads
  61. # elif defined IS_IN_librt
  62. # define CENABLE_FUNC __librt_enable_asynccancel
  63. # define CDISABLE_FUNC __librt_disable_asynccancel
  64. # else
  65. # error Unsupported library
  66. # endif
  67. # define CENABLE movi a8, CENABLE_FUNC; \
  68. callx8 a8
  69. # define CDISABLE movi a8, CDISABLE_FUNC; \
  70. callx8 a8
  71. # if defined IS_IN_libpthread || !defined NOT_IN_libc
  72. # ifndef __ASSEMBLER__
  73. extern int __local_multiple_threads attribute_hidden;
  74. # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  75. # else
  76. # define SINGLE_THREAD_P(reg) movi reg, __local_multiple_threads; \
  77. l32i reg, reg, 0;
  78. # endif
  79. # else
  80. # ifndef __ASSEMBLER__
  81. # define SINGLE_THREAD_P \
  82. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  83. header.multiple_threads) == 0, 1)
  84. # else
  85. # define SINGLE_THREAD_P(reg) \
  86. rur reg, threadptr; \
  87. l32i reg, reg, MULTIPLE_THREADS_OFFSET;
  88. # endif
  89. # endif
  90. #else
  91. /* This code should never be used but we define it anyhow. */
  92. # define SINGLE_THREAD_P (1)
  93. # define NO_CANCELLATION 1
  94. #endif
  95. #ifndef __ASSEMBLER__
  96. # define RTLD_SINGLE_THREAD_P \
  97. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  98. header.multiple_threads) == 0, 1)
  99. #endif