sysdep-cancel.h 4.2 KB

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