sysdep-cancel.h 4.6 KB

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