sysdep-cancel.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. // FIXME: ENTRY includes an entry instruction, here we'd want entry sp, 48!
  23. # undef PSEUDO
  24. # define PSEUDO(name, syscall_name, args) \
  25. .text; \
  26. ENTRY (name) \
  27. SINGLE_THREAD_P(a15); \
  28. bnez a15, .Lpseudo_cancel; \
  29. DO_CALL (syscall_name, args); \
  30. bgez a2, .Lpseudo_done; \
  31. movi a4, -4095; \
  32. blt a2, a4, .Lpseudo_done; \
  33. j SYSCALL_ERROR_LABEL; \
  34. .Lpseudo_done: \
  35. retw; \
  36. .Lpseudo_cancel: \
  37. /* The syscall args are in a2...a7; no need to save */ \
  38. CENABLE; \
  39. /* The return value is in a10 and preserved across the syscall */ \
  40. DO_CALL (syscall_name, args); \
  41. CDISABLE; \
  42. bgez a2, .Lpseudo_end; \
  43. movi a4, -4095; \
  44. blt a2, a4, .Lpseudo_end; \
  45. j SYSCALL_ERROR_LABEL; \
  46. .Lpseudo_end:
  47. # ifdef IS_IN_libpthread
  48. # define CENABLE_FUNC __pthread_enable_asynccancel
  49. # define CDISABLE_FUNC __pthread_disable_asynccancel
  50. # define __local_multiple_threads __pthread_multiple_threads
  51. # elif !defined NOT_IN_libc
  52. # define CENABLE_FUNC __libc_enable_asynccancel
  53. # define CDISABLE_FUNC __libc_disable_asynccancel
  54. # define __local_multiple_threads __libc_multiple_threads
  55. # elif defined IS_IN_librt
  56. # define CENABLE_FUNC __librt_enable_asynccancel
  57. # define CDISABLE_FUNC __librt_disable_asynccancel
  58. # else
  59. # error Unsupported library
  60. # endif
  61. # define CENABLE movi a8, CENABLE_FUNC; \
  62. callx8 a8
  63. # define CDISABLE movi a8, CDISABLE_FUNC; \
  64. callx8 a8
  65. # if defined IS_IN_libpthread || !defined NOT_IN_libc
  66. # ifndef __ASSEMBLER__
  67. extern int __local_multiple_threads attribute_hidden;
  68. # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  69. # else
  70. # define SINGLE_THREAD_P(reg) movi reg, __local_multiple_threads; \
  71. l32i reg, reg, 0;
  72. # endif
  73. # else
  74. # ifndef __ASSEMBLER__
  75. # define SINGLE_THREAD_P \
  76. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  77. header.multiple_threads) == 0, 1)
  78. # else
  79. # define SINGLE_THREAD_P(reg) \
  80. rur reg, threadptr; \
  81. l32i reg, reg, MULTIPLE_THREADS_OFFSET;
  82. # endif
  83. # endif
  84. #else
  85. /* This code should never be used but we define it anyhow. */
  86. # define SINGLE_THREAD_P (1)
  87. # define NO_CANCELLATION 1
  88. #endif
  89. #ifndef __ASSEMBLER__
  90. # define RTLD_SINGLE_THREAD_P \
  91. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  92. header.multiple_threads) == 0, 1)
  93. #endif