sysdep-cancel.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* Copyright (C) 2003, 2004, 2005 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, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #include <sysdep.h>
  16. #include <tcb-offsets.h>
  17. #ifndef __ASSEMBLER__
  18. # include <pthreadP.h>
  19. #endif
  20. #if !defined NOT_IN_libc || defined IS_IN_libpthread || defined IS_IN_librt
  21. # undef PSEUDO
  22. # define PSEUDO(name, syscall_name, args) \
  23. .section ".text"; \
  24. PSEUDO_PROLOGUE; \
  25. .type __##syscall_name##_nocancel,%function; \
  26. .globl __##syscall_name##_nocancel; \
  27. __##syscall_name##_nocancel: \
  28. DO_CALL (syscall_name, args); \
  29. PSEUDO_RET; \
  30. .size __##syscall_name##_nocancel,.-__##syscall_name##_nocancel; \
  31. ENTRY (name); \
  32. SINGLE_THREAD_P; \
  33. DOARGS_##args; \
  34. bne .Lpseudo_cancel; \
  35. DO_CALL (syscall_name, 0); \
  36. UNDOARGS_##args; \
  37. cmn r0, $4096; \
  38. PSEUDO_RET; \
  39. .Lpseudo_cancel: \
  40. DOCARGS_##args; /* save syscall args etc. around CENABLE. */ \
  41. CENABLE; \
  42. mov ip, r0; /* put mask in safe place. */ \
  43. UNDOCARGS_##args; /* restore syscall args. */ \
  44. swi SYS_ify (syscall_name); /* do the call. */ \
  45. str r0, [sp, $-4]!; /* save syscall return value. */ \
  46. mov r0, ip; /* get mask back. */ \
  47. CDISABLE; \
  48. ldmfd sp!, {r0, lr}; /* retrieve return value and address. */ \
  49. UNDOARGS_##args; \
  50. cmn r0, $4096;
  51. # define DOCARGS_0 str lr, [sp, #-4]!;
  52. # define UNDOCARGS_0
  53. # define DOCARGS_1 stmfd sp!, {r0, lr};
  54. # define UNDOCARGS_1 ldr r0, [sp], #4;
  55. # define DOCARGS_2 stmfd sp!, {r0, r1, lr};
  56. # define UNDOCARGS_2 ldmfd sp!, {r0, r1};
  57. # define DOCARGS_3 stmfd sp!, {r0, r1, r2, lr};
  58. # define UNDOCARGS_3 ldmfd sp!, {r0, r1, r2};
  59. # define DOCARGS_4 stmfd sp!, {r0, r1, r2, r3, lr};
  60. # define UNDOCARGS_4 ldmfd sp!, {r0, r1, r2, r3};
  61. # define DOCARGS_5 DOCARGS_4
  62. # define UNDOCARGS_5 UNDOCARGS_4
  63. # define DOCARGS_6 DOCARGS_5
  64. # define UNDOCARGS_6 UNDOCARGS_5
  65. # ifdef IS_IN_libpthread
  66. # define CENABLE bl PLTJMP(__pthread_enable_asynccancel)
  67. # define CDISABLE bl PLTJMP(__pthread_disable_asynccancel)
  68. # define __local_multiple_threads __pthread_multiple_threads
  69. # elif !defined NOT_IN_libc
  70. # define CENABLE bl PLTJMP(__libc_enable_asynccancel)
  71. # define CDISABLE bl PLTJMP(__libc_disable_asynccancel)
  72. # define __local_multiple_threads __libc_multiple_threads
  73. # elif defined IS_IN_librt
  74. # define CENABLE bl PLTJMP(__librt_enable_asynccancel)
  75. # define CDISABLE bl PLTJMP(__librt_disable_asynccancel)
  76. # else
  77. # error Unsupported library
  78. # endif
  79. # if defined IS_IN_libpthread || !defined NOT_IN_libc
  80. # ifndef __ASSEMBLER__
  81. extern int __local_multiple_threads attribute_hidden;
  82. # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  83. # else
  84. # define SINGLE_THREAD_P \
  85. ldr ip, 1b; \
  86. 2: \
  87. ldr ip, [pc, ip]; \
  88. teq ip, #0;
  89. # define PSEUDO_PROLOGUE \
  90. 1: .word __local_multiple_threads - 2f - 8;
  91. # endif
  92. # else
  93. /* There is no __local_multiple_threads for librt, so use the TCB. */
  94. # ifndef __ASSEMBLER__
  95. # define SINGLE_THREAD_P \
  96. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  97. header.multiple_threads) == 0, 1)
  98. # else
  99. # define PSEUDO_PROLOGUE
  100. # define SINGLE_THREAD_P \
  101. stmfd sp!, {r0, lr}; \
  102. bl __aeabi_read_tp; \
  103. ldr ip, [r0, #MULTIPLE_THREADS_OFFSET]; \
  104. ldmfd sp!, {r0, lr}; \
  105. teq ip, #0
  106. # define SINGLE_THREAD_P_PIC(x) SINGLE_THREAD_P
  107. # endif
  108. # endif
  109. #elif !defined __ASSEMBLER__
  110. /* For rtld, et cetera. */
  111. # define SINGLE_THREAD_P 1
  112. # define NO_CANCELLATION 1
  113. #endif
  114. #ifndef __ASSEMBLER__
  115. # define RTLD_SINGLE_THREAD_P \
  116. __builtin_expect (THREAD_GETMEM (THREAD_SELF, \
  117. header.multiple_threads) == 0, 1)
  118. #endif