sysdep-cancel.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
  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 <linuxthreads/internals.h>
  19. #endif
  20. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  21. # if !defined NOT_IN_libc || defined IS_IN_libpthread
  22. # define PSEUDO_CANCEL(name, syscall_name, args) \
  23. L(pseudo_cancel): \
  24. STM_##args \
  25. stm %r12,%r15,48(%r15); \
  26. lr %r14,%r15; \
  27. ahi %r15,-96; \
  28. st %r14,0(%r15); \
  29. basr %r13,0; \
  30. 0: l %r1,1f-0b(%r13); \
  31. bas %r14,0(%r1,%r13); \
  32. lr %r0,%r2; \
  33. LM_##args \
  34. DO_CALL(syscall_name, args); \
  35. l %r1,2f-0b(%r13); \
  36. lr %r12,%r2; \
  37. lr %r2,%r0; \
  38. bas %r14,0(%r1,%r13); \
  39. lr %r2,%r12; \
  40. lm %r12,%r15,48+96(%r15); \
  41. j L(pseudo_check); \
  42. 1: .long CENABLE-0b; \
  43. 2: .long CDISABLE-0b;
  44. # else /* !libc.so && !libpthread.so */
  45. # define PSEUDO_CANCEL(name, syscall_name, args) \
  46. L(pseudo_cancel): \
  47. STM_##args \
  48. stm %r11,%r15,44(%r15); \
  49. lr %r14,%r15; \
  50. ahi %r15,-96; \
  51. st %r14,0(%r15); \
  52. basr %r13,0; \
  53. 0: l %r12,3f-0b(%r13); \
  54. l %r1,1f-0b(%r13); \
  55. la %r12,0(%r12,%r13); \
  56. bas %r14,0(%r1,%r13); \
  57. lr %r0,%r2; \
  58. LM_##args \
  59. DO_CALL(syscall_name, args); \
  60. l %r1,2f-0b(%r13); \
  61. lr %r11,%r2; \
  62. lr %r2,%r0; \
  63. bas %r14,0(%r1,%r13); \
  64. lr %r2,%r11; \
  65. lm %r11,%r15,44+96(%r15); \
  66. j L(pseudo_check); \
  67. 1: .long CENABLE@PLT-0b; \
  68. 2: .long CDISABLE@PLT-0b; \
  69. 3: .long _GLOBAL_OFFSET_TABLE_-0b;
  70. # endif
  71. # undef PSEUDO
  72. # define PSEUDO(name, syscall_name, args) \
  73. .text; \
  74. PSEUDO_CANCEL(name, syscall_name, args) \
  75. ENTRY(name) \
  76. SINGLE_THREAD_P(%r1) \
  77. jne L(pseudo_cancel); \
  78. DO_CALL(syscall_name, args); \
  79. L(pseudo_check): \
  80. lhi %r4,-4095; \
  81. clr %r2,%r4; \
  82. jnl SYSCALL_ERROR_LABEL; \
  83. L(pseudo_end):
  84. # ifdef IS_IN_libpthread
  85. # define CENABLE __pthread_enable_asynccancel
  86. # define CDISABLE __pthread_disable_asynccancel
  87. # elif !defined NOT_IN_libc
  88. # define CENABLE __libc_enable_asynccancel
  89. # define CDISABLE __libc_disable_asynccancel
  90. # else
  91. # define CENABLE __librt_enable_asynccancel
  92. # define CDISABLE __librt_disable_asynccancel
  93. # endif
  94. #define STM_0 /* Nothing */
  95. #define STM_1 st %r2,8(%r15);
  96. #define STM_2 stm %r2,%r3,8(%r15);
  97. #define STM_3 stm %r2,%r4,8(%r15);
  98. #define STM_4 stm %r2,%r5,8(%r15);
  99. #define STM_5 stm %r2,%r5,8(%r15);
  100. #define LM_0 /* Nothing */
  101. #define LM_1 l %r2,8+96(%r15);
  102. #define LM_2 lm %r2,%r3,8+96(%r15);
  103. #define LM_3 lm %r2,%r4,8+96(%r15);
  104. #define LM_4 lm %r2,%r5,8+96(%r15);
  105. #define LM_5 lm %r2,%r5,8+96(%r15);
  106. # ifndef __ASSEMBLER__
  107. # define SINGLE_THREAD_P \
  108. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  109. p_header.data.multiple_threads) == 0, 1)
  110. # else
  111. # define SINGLE_THREAD_P(reg) \
  112. ear reg,%a0; \
  113. icm reg,15,MULTIPLE_THREADS_OFFSET(reg);
  114. # endif
  115. #elif !defined __ASSEMBLER__
  116. /* This code should never be used but we define it anyhow. */
  117. # define SINGLE_THREAD_P (1)
  118. #endif