sysdep-cancel.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Copyright (C) 2002, 2003, 2004, 2005 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 <nptl/pthreadP.h>
  20. #endif
  21. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  22. # undef PSEUDO
  23. # define PSEUDO(name, syscall_name, args) \
  24. .text; \
  25. ENTRY (name) \
  26. SINGLE_THREAD_P; \
  27. jne L(pseudo_cancel); \
  28. .type __##syscall_name##_nocancel,@function; \
  29. .globl __##syscall_name##_nocancel; \
  30. __##syscall_name##_nocancel: \
  31. DO_CALL (syscall_name, args); \
  32. cmpq $-4095, %rax; \
  33. jae SYSCALL_ERROR_LABEL; \
  34. ret; \
  35. .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
  36. L(pseudo_cancel): \
  37. /* Save registers that might get destroyed. */ \
  38. SAVESTK_##args \
  39. PUSHARGS_##args \
  40. CENABLE \
  41. /* Restore registers. */ \
  42. POPARGS_##args \
  43. /* The return value from CENABLE is argument for CDISABLE. */ \
  44. movq %rax, (%rsp); \
  45. movl $SYS_ify (syscall_name), %eax; \
  46. syscall; \
  47. movq (%rsp), %rdi; \
  48. /* Save %rax since it's the error code from the syscall. */ \
  49. movq %rax, 8(%rsp); \
  50. CDISABLE \
  51. movq 8(%rsp), %rax; \
  52. RESTSTK_##args \
  53. cmpq $-4095, %rax; \
  54. jae SYSCALL_ERROR_LABEL; \
  55. L(pseudo_end):
  56. # define PUSHARGS_0 /* Nothing. */
  57. # define PUSHARGS_1 PUSHARGS_0 movq %rdi, 8(%rsp);
  58. # define PUSHARGS_2 PUSHARGS_1 movq %rsi, 16(%rsp);
  59. # define PUSHARGS_3 PUSHARGS_2 movq %rdx, 24(%rsp);
  60. # define PUSHARGS_4 PUSHARGS_3 movq %rcx, 32(%rsp);
  61. # define PUSHARGS_5 PUSHARGS_4 movq %r8, 40(%rsp);
  62. # define PUSHARGS_6 PUSHARGS_5 movq %r9, 48(%rsp);
  63. # define POPARGS_0 /* Nothing. */
  64. # define POPARGS_1 POPARGS_0 movq 8(%rsp), %rdi;
  65. # define POPARGS_2 POPARGS_1 movq 16(%rsp), %rsi;
  66. # define POPARGS_3 POPARGS_2 movq 24(%rsp), %rdx;
  67. # define POPARGS_4 POPARGS_3 movq 32(%rsp), %r10;
  68. # define POPARGS_5 POPARGS_4 movq 40(%rsp), %r8;
  69. # define POPARGS_6 POPARGS_5 movq 48(%rsp), %r9;
  70. /* We always have to align the stack before calling a function. */
  71. # define SAVESTK_0 subq $24, %rsp; cfi_adjust_cfa_offset (24);
  72. # define SAVESTK_1 SAVESTK_0
  73. # define SAVESTK_2 SAVESTK_1
  74. # define SAVESTK_3 subq $40, %rsp; cfi_adjust_cfa_offset (40);
  75. # define SAVESTK_4 SAVESTK_3
  76. # define SAVESTK_5 subq $56, %rsp; cfi_adjust_cfa_offset (56);
  77. # define SAVESTK_6 SAVESTK_5
  78. # define RESTSTK_0 addq $24,%rsp; cfi_adjust_cfa_offset (-24);
  79. # define RESTSTK_1 RESTSTK_0
  80. # define RESTSTK_2 RESTSTK_1
  81. # define RESTSTK_3 addq $40, %rsp; cfi_adjust_cfa_offset (-40);
  82. # define RESTSTK_4 RESTSTK_3
  83. # define RESTSTK_5 addq $56, %rsp; cfi_adjust_cfa_offset (-56);
  84. # define RESTSTK_6 RESTSTK_5
  85. # ifdef IS_IN_libpthread
  86. # define CENABLE call __pthread_enable_asynccancel;
  87. # define CDISABLE call __pthread_disable_asynccancel;
  88. # define __local_multiple_threads __pthread_multiple_threads
  89. # elif !defined NOT_IN_libc
  90. # define CENABLE call __libc_enable_asynccancel;
  91. # define CDISABLE call __libc_disable_asynccancel;
  92. # define __local_multiple_threads __libc_multiple_threads
  93. # elif defined IS_IN_librt
  94. # define CENABLE call __librt_enable_asynccancel;
  95. # define CDISABLE call __librt_disable_asynccancel;
  96. # else
  97. # error Unsupported library
  98. # endif
  99. # if defined IS_IN_libpthread || !defined NOT_IN_libc
  100. # ifndef __ASSEMBLER__
  101. extern int __local_multiple_threads attribute_hidden;
  102. # define SINGLE_THREAD_P \
  103. __builtin_expect (__local_multiple_threads == 0, 1)
  104. # else
  105. # define SINGLE_THREAD_P cmpl $0, __local_multiple_threads(%rip)
  106. # endif
  107. # else
  108. # ifndef __ASSEMBLER__
  109. # define SINGLE_THREAD_P \
  110. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  111. header.multiple_threads) == 0, 1)
  112. # else
  113. # define SINGLE_THREAD_P cmpl $0, %fs:MULTIPLE_THREADS_OFFSET
  114. # endif
  115. # endif
  116. #elif !defined __ASSEMBLER__
  117. # define SINGLE_THREAD_P (1)
  118. # define NO_CANCELLATION 1
  119. #endif