sysdep-cancel.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright (C) 2002-2006, 2009 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
  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 <pthreadP.h>
  19. #endif
  20. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  21. /* The code to disable cancellation depends on the fact that the called
  22. functions are special. They don't modify registers other than %rax
  23. and %r11 if they return. Therefore we don't have to preserve other
  24. registers around these calls. */
  25. # undef PSEUDO
  26. # define PSEUDO(name, syscall_name, args) \
  27. .text; \
  28. ENTRY (name) \
  29. SINGLE_THREAD_P; \
  30. jne L(pseudo_cancel); \
  31. .type __##syscall_name##_nocancel,@function; \
  32. .globl __##syscall_name##_nocancel; \
  33. __##syscall_name##_nocancel: \
  34. DO_CALL (syscall_name, args); \
  35. cmpq $-4095, %rax; \
  36. jae SYSCALL_ERROR_LABEL; \
  37. ret; \
  38. .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
  39. L(pseudo_cancel): \
  40. /* We always have to align the stack before calling a function. */ \
  41. subq $8, %rsp; cfi_adjust_cfa_offset (8); \
  42. CENABLE \
  43. /* The return value from CENABLE is argument for CDISABLE. */ \
  44. movq %rax, (%rsp); \
  45. DO_CALL (syscall_name, args); \
  46. movq (%rsp), %rdi; \
  47. /* Save %rax since it's the error code from the syscall. */ \
  48. movq %rax, %rdx; \
  49. CDISABLE \
  50. movq %rdx, %rax; \
  51. addq $8,%rsp; cfi_adjust_cfa_offset (-8); \
  52. cmpq $-4095, %rax; \
  53. jae SYSCALL_ERROR_LABEL; \
  54. L(pseudo_end):
  55. # ifdef IS_IN_libpthread
  56. # define CENABLE call __pthread_enable_asynccancel;
  57. # define CDISABLE call __pthread_disable_asynccancel;
  58. # define __local_multiple_threads __pthread_multiple_threads
  59. # elif !defined NOT_IN_libc
  60. # define CENABLE call __libc_enable_asynccancel;
  61. # define CDISABLE call __libc_disable_asynccancel;
  62. # define __local_multiple_threads __libc_multiple_threads
  63. # elif defined IS_IN_librt
  64. # define CENABLE call __librt_enable_asynccancel;
  65. # define CDISABLE call __librt_disable_asynccancel;
  66. # else
  67. # error Unsupported library
  68. # endif
  69. # if defined IS_IN_libpthread || !defined NOT_IN_libc
  70. # ifndef __ASSEMBLER__
  71. extern int __local_multiple_threads attribute_hidden;
  72. # define SINGLE_THREAD_P \
  73. __builtin_expect (__local_multiple_threads == 0, 1)
  74. # else
  75. # define SINGLE_THREAD_P cmpl $0, __local_multiple_threads(%rip)
  76. # endif
  77. # else
  78. # ifndef __ASSEMBLER__
  79. # define SINGLE_THREAD_P \
  80. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  81. header.multiple_threads) == 0, 1)
  82. # else
  83. # define SINGLE_THREAD_P cmpl $0, %fs:MULTIPLE_THREADS_OFFSET
  84. # endif
  85. # endif
  86. #elif !defined __ASSEMBLER__
  87. # define SINGLE_THREAD_P (1)
  88. # define NO_CANCELLATION 1
  89. #endif
  90. #ifndef __ASSEMBLER__
  91. # define RTLD_SINGLE_THREAD_P \
  92. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  93. header.multiple_threads) == 0, 1)
  94. #endif