sysdep-cancel.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Copyright (C) 2014-2016 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <sysdep.h>
  15. #include <tls.h>
  16. #ifndef __ASSEMBLER__
  17. # include <pthreadP.h>
  18. #endif
  19. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  20. #ifdef __ASSEMBLER__
  21. #undef ret
  22. #define ret
  23. # if !IS_IN_librt || !defined(PIC)
  24. # define AC_STACK_SIZE 16 /* space for r15, async_cancel arg and 2 temp words */
  25. # define AC_SET_GOT /* empty */
  26. # define AC_RESTORE_GOT /* empty */
  27. # else
  28. # define AC_STACK_SIZE 20 /* extra 4 bytes for r20 */
  29. # define AC_SET_GOT \
  30. swi r20, r1, AC_STACK_SIZE-4; \
  31. mfs r20, rpc; \
  32. addik r20, r20, _GLOBAL_OFFSET_TABLE_+8;
  33. # define AC_RESTORE_GOT \
  34. lwi r20, r1, AC_STACK_SIZE-4;
  35. # endif
  36. # undef PSEUDO
  37. # define PSEUDO(name, syscall_name, args) \
  38. .text; \
  39. ENTRY (name) \
  40. SINGLE_THREAD_P(r12); \
  41. bnei r12, L(pseudo_cancel); \
  42. .globl __##syscall_name##_nocancel; \
  43. .type __##syscall_name##_nocancel,@function; \
  44. __##syscall_name##_nocancel: \
  45. DO_CALL (syscall_name, args); \
  46. addik r4, r0, -4095; \
  47. cmpu r4, r4, r3; \
  48. rsubk r3,r3,r0; \
  49. rtsd r15,8; \
  50. addik r3,r0,-1; \
  51. rtsd r15, 8; \
  52. nop; \
  53. .size __##syscall_name##_nocancel, .-__##syscall_name##_nocancel; \
  54. L(pseudo_cancel): \
  55. addik r1, r1, -AC_STACK_SIZE; \
  56. swi r15, r1, 0; \
  57. AC_SET_GOT \
  58. DOCARGS_##args \
  59. CENABLE; \
  60. swi r3, r1, 8; \
  61. UNDOCARGS_##args \
  62. DO_CALL (syscall_name, args); \
  63. swi r3, r1, 12; \
  64. lwi r5, r1, 8; \
  65. CDISABLE; \
  66. lwi r3, r1, 12; \
  67. lwi r15, r1, 0; \
  68. AC_RESTORE_GOT \
  69. addik r1, r1, AC_STACK_SIZE; \
  70. addik r4, r0, -4095; \
  71. cmpu r4, r4, r3; \
  72. rsubk r3,r3,r0; \
  73. rtsd r15,8; \
  74. addik r3,r0,-1; \
  75. rtsd r15, 8; \
  76. nop;
  77. /*
  78. * Macros to save/restore syscall arguments across CENABLE
  79. * The arguments are saved into the caller's stack (original r1 + 4)
  80. */
  81. # define DOCARGS_0
  82. # define DOCARGS_1 swi r5, r1, AC_STACK_SIZE + 4;
  83. # define DOCARGS_2 swi r6, r1, AC_STACK_SIZE + 8; DOCARGS_1
  84. # define DOCARGS_3 swi r7, r1, AC_STACK_SIZE + 12; DOCARGS_2
  85. # define DOCARGS_4 swi r8, r1, AC_STACK_SIZE + 16; DOCARGS_3
  86. # define DOCARGS_5 swi r9, r1, AC_STACK_SIZE + 20; DOCARGS_4
  87. # define DOCARGS_6 swi r10, r1, AC_STACK_SIZE + 24; DOCARGS_5
  88. # define UNDOCARGS_0
  89. # define UNDOCARGS_1 lwi r5, r1, AC_STACK_SIZE + 4;
  90. # define UNDOCARGS_2 UNDOCARGS_1 lwi r6, r1, AC_STACK_SIZE + 8;
  91. # define UNDOCARGS_3 UNDOCARGS_2 lwi r7, r1, AC_STACK_SIZE + 12;
  92. # define UNDOCARGS_4 UNDOCARGS_3 lwi r8, r1, AC_STACK_SIZE + 16;
  93. # define UNDOCARGS_5 UNDOCARGS_4 lwi r9, r1, AC_STACK_SIZE + 20;
  94. # define UNDOCARGS_6 UNDOCARGS_5 lwi r10, r1, AC_STACK_SIZE + 24;
  95. # ifdef PIC
  96. # define PSEUDO_JMP(sym) brlid r15, sym##@PLTPC; addk r0, r0, r0
  97. # else
  98. # define PSEUDO_JMP(sym) brlid r15, sym; addk r0, r0, r0
  99. # endif
  100. # if defined IS_IN_libpthread
  101. # define CENABLE PSEUDO_JMP (__pthread_enable_asynccancel)
  102. # define CDISABLE PSEUDO_JMP (__pthread_disable_asynccancel)
  103. # define __local_multiple_threads __pthread_multiple_threads
  104. # elif !defined NOT_IN_libc
  105. # define CENABLE PSEUDO_JMP (__libc_enable_asynccancel)
  106. # define CDISABLE PSEUDO_JMP (__libc_disable_asynccancel)
  107. # define __local_multiple_threads __libc_multiple_threads
  108. # elif defined IS_IN_librt
  109. # define CENABLE PSEUDO_JMP (__librt_enable_asynccancel)
  110. # define CDISABLE PSEUDO_JMP (__librt_disable_asynccancel)
  111. # else
  112. # error Unsupported library
  113. # endif
  114. #define SINGLE_THREAD_P(reg) \
  115. lwi reg, r0, MULTIPLE_THREADS_OFFSET(reg)
  116. #else /* !__ASSEMBLER__ */
  117. # define SINGLE_THREAD_P \
  118. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  119. header.multiple_threads) == 0, 1)
  120. #endif /* __ASSEMBLER__ */
  121. #endif