sysdep-cancel.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Copyright (C) 2003, 2005 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Phil Blundell <pb@nexus.co.uk>, 2003.
  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 <tls.h>
  16. #include <pt-machine.h>
  17. #ifndef __ASSEMBLER__
  18. # include <linuxthreads/internals.h>
  19. #endif
  20. #if !defined NOT_IN_libc || defined IS_IN_libpthread
  21. /* We push lr onto the stack, so we have to use ldmib instead of ldmia
  22. to find the saved arguments. */
  23. # ifdef __PIC__
  24. # undef DOARGS_5
  25. # undef DOARGS_6
  26. # undef DOARGS_7
  27. # define DOARGS_5 str r4, [sp, $-4]!; ldr r4, [sp, $8];
  28. # define DOARGS_6 mov ip, sp; stmfd sp!, {r4, r5}; ldmib ip, {r4, r5};
  29. # define DOARGS_7 mov ip, sp; stmfd sp!, {r4, r5, r6}; ldmib ip, {r4, r5, r6};
  30. # endif
  31. # undef PSEUDO_RET
  32. # define PSEUDO_RET \
  33. ldrcc pc, [sp], $4; \
  34. ldr lr, [sp], $4; \
  35. b PLTJMP(SYSCALL_ERROR)
  36. # undef PSEUDO
  37. # define PSEUDO(name, syscall_name, args) \
  38. .section ".text"; \
  39. PSEUDO_PROLOGUE; \
  40. ENTRY (name); \
  41. SINGLE_THREAD_P; \
  42. bne .Lpseudo_cancel; \
  43. DO_CALL (syscall_name, args); \
  44. cmn r0, $4096; \
  45. RETINSTR(cc, lr); \
  46. b PLTJMP(SYSCALL_ERROR); \
  47. .Lpseudo_cancel: \
  48. str lr, [sp, $-4]!; \
  49. DOCARGS_##args; /* save syscall args around CENABLE. */ \
  50. CENABLE; \
  51. mov ip, r0; /* put mask in safe place. */ \
  52. UNDOCARGS_##args; /* restore syscall args. */ \
  53. swi SYS_ify (syscall_name); /* do the call. */ \
  54. str r0, [sp, $-4]!; /* save syscall return value. */ \
  55. mov r0, ip; /* get mask back. */ \
  56. CDISABLE; \
  57. ldr r0, [sp], $4; /* retrieve return value. */ \
  58. UNDOC2ARGS_##args; /* fix register damage. */ \
  59. cmn r0, $4096;
  60. # define DOCARGS_0
  61. # define UNDOCARGS_0
  62. # define UNDOC2ARGS_0
  63. # define DOCARGS_1 str r0, [sp, #-4]!;
  64. # define UNDOCARGS_1 ldr r0, [sp], #4;
  65. # define UNDOC2ARGS_1
  66. # define DOCARGS_2 str r1, [sp, #-4]!; str r0, [sp, #-4]!;
  67. # define UNDOCARGS_2 ldr r0, [sp], #4; ldr r1, [sp], #4;
  68. # define UNDOC2ARGS_2
  69. # define DOCARGS_3 str r2, [sp, #-4]!; str r1, [sp, #-4]!; str r0, [sp, #-4]!;
  70. # define UNDOCARGS_3 ldr r0, [sp], #4; ldr r1, [sp], #4; ldr r2, [sp], #4
  71. # define UNDOC2ARGS_3
  72. # define DOCARGS_4 stmfd sp!, {r0-r3}
  73. # define UNDOCARGS_4 ldmfd sp!, {r0-r3}
  74. # define UNDOC2ARGS_4
  75. # define DOCARGS_5 stmfd sp!, {r0-r3}
  76. # define UNDOCARGS_5 ldmfd sp, {r0-r3}; str r4, [sp, #-4]!; ldr r4, [sp, #24]
  77. # define UNDOC2ARGS_5 ldr r4, [sp], #20
  78. # ifdef IS_IN_libpthread
  79. # define CENABLE bl PLTJMP(__pthread_enable_asynccancel)
  80. # define CDISABLE bl PLTJMP(__pthread_disable_asynccancel)
  81. # define __local_multiple_threads __pthread_multiple_threads
  82. # else
  83. # define CENABLE bl PLTJMP(__libc_enable_asynccancel)
  84. # define CDISABLE bl PLTJMP(__libc_disable_asynccancel)
  85. # define __local_multiple_threads __libc_multiple_threads
  86. # endif
  87. # ifndef __ASSEMBLER__
  88. extern int __local_multiple_threads attribute_hidden;
  89. # define SINGLE_THREAD_P __builtin_expect (__local_multiple_threads == 0, 1)
  90. # else
  91. # if !defined __PIC__
  92. # define SINGLE_THREAD_P \
  93. ldr ip, =__local_multiple_threads; \
  94. ldr ip, [ip]; \
  95. teq ip, #0;
  96. # define PSEUDO_PROLOGUE
  97. # else
  98. # define SINGLE_THREAD_P \
  99. ldr ip, 1b; \
  100. 2: \
  101. ldr ip, [pc, ip]; \
  102. teq ip, #0;
  103. # define PSEUDO_PROLOGUE \
  104. 1: .word __local_multiple_threads - 2f - 8;
  105. # endif
  106. # endif
  107. #elif !defined __ASSEMBLER__
  108. /* This code should never be used but we define it anyhow. */
  109. # define SINGLE_THREAD_P (1)
  110. #endif