sysdep-cancel.h 4.7 KB

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