sysdep-cancel.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. # undef PSEUDO
  22. # define PSEUDO(name, syscall_name, args) \
  23. .text; \
  24. L(pseudo_cancel): \
  25. STM_##args \
  26. stmg %r13,%r15,104(%r15); \
  27. lgr %r14,%r15; \
  28. aghi %r15,-160; \
  29. stg %r14,0(%r15); \
  30. brasl %r14,CENABLE; \
  31. lgr %r0,%r2; \
  32. LM_##args \
  33. DO_CALL(syscall_name, args); \
  34. lgr %r13,%r2; \
  35. lgr %r2,%r0; \
  36. brasl %r14,CDISABLE; \
  37. lgr %r2,%r13; \
  38. lmg %r13,%r15,104+160(%r15); \
  39. j L(pseudo_check); \
  40. ENTRY(name) \
  41. SINGLE_THREAD_P \
  42. jne L(pseudo_cancel); \
  43. DO_CALL(syscall_name, args); \
  44. L(pseudo_check): \
  45. lghi %r4,-4095; \
  46. clgr %r2,%r4; \
  47. jgnl SYSCALL_ERROR_LABEL; \
  48. L(pseudo_end):
  49. # ifdef IS_IN_libpthread
  50. # define CENABLE __pthread_enable_asynccancel
  51. # define CDISABLE __pthread_disable_asynccancel
  52. # define __local_multiple_threads __pthread_multiple_threads
  53. # elif !defined NOT_IN_libc
  54. # define CENABLE __libc_enable_asynccancel
  55. # define CDISABLE __libc_disable_asynccancel
  56. # define __local_multiple_threads __libc_multiple_threads
  57. # else
  58. # define CENABLE __librt_enable_asynccancel@PLT
  59. # define CDISABLE __librt_disable_asynccancel@PLT
  60. # endif
  61. #define STM_0 /* Nothing */
  62. #define STM_1 stg %r2,16(%r15);
  63. #define STM_2 stmg %r2,%r3,16(%r15);
  64. #define STM_3 stmg %r2,%r4,16(%r15);
  65. #define STM_4 stmg %r2,%r5,16(%r15);
  66. #define STM_5 stmg %r2,%r5,16(%r15);
  67. #define LM_0 /* Nothing */
  68. #define LM_1 lg %r2,16+160(%r15);
  69. #define LM_2 lmg %r2,%r3,16+160(%r15);
  70. #define LM_3 lmg %r2,%r4,16+160(%r15);
  71. #define LM_4 lmg %r2,%r5,16+160(%r15);
  72. #define LM_5 lmg %r2,%r5,16+160(%r15);
  73. # if !defined NOT_IN_libc || defined IS_IN_libpthread
  74. # ifndef __ASSEMBLER__
  75. extern int __local_multiple_threads attribute_hidden;
  76. # define SINGLE_THREAD_P \
  77. __builtin_expect (__local_multiple_threads == 0, 1)
  78. # else
  79. # define SINGLE_THREAD_P \
  80. larl %r1,__local_multiple_threads; \
  81. icm %r0,15,0(%r1);
  82. # endif
  83. # else
  84. # ifndef __ASSEMBLER__
  85. # define SINGLE_THREAD_P \
  86. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  87. p_header.data.multiple_threads) == 0, 1)
  88. # else
  89. # define SINGLE_THREAD_P \
  90. ear %r1,%a0; \
  91. sllg %r1,%r1,32; \
  92. ear %r1,%a1; \
  93. icm %r1,15,MULTIPLE_THREADS_OFFSET(%r1);
  94. # endif
  95. # endif
  96. #elif !defined __ASSEMBLER__
  97. /* This code should never be used but we define it anyhow. */
  98. # define SINGLE_THREAD_P (1)
  99. #endif