sysdep-cancel.h 4.2 KB

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