sysdep-cancel.h 3.9 KB

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