sem_wait.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <sysdep.h>
  17. #include <shlib-compat.h>
  18. #include <pthread-errnos.h>
  19. #ifndef UP
  20. # define LOCK lock
  21. #else
  22. # define
  23. #endif
  24. #define SYS_futex 202
  25. .text
  26. .globl sem_wait
  27. .type sem_wait,@function
  28. .align 16
  29. cfi_startproc
  30. sem_wait:
  31. /* First check for cancellation. */
  32. movl %fs:CANCELHANDLING, %eax
  33. andl $0xfffffff9, %eax
  34. cmpl $8, %eax
  35. je 4f
  36. pushq %r12
  37. cfi_adjust_cfa_offset(8)
  38. cfi_offset(12, -16)
  39. pushq %r13
  40. cfi_adjust_cfa_offset(8)
  41. movq %rdi, %r13
  42. cfi_offset(13, -24)
  43. 3: movl (%r13), %eax
  44. 2: testl %eax, %eax
  45. je 1f
  46. leaq -1(%rax), %rdx
  47. LOCK
  48. cmpxchgl %edx, (%r13)
  49. jne 2b
  50. xorl %eax, %eax
  51. popq %r13
  52. cfi_adjust_cfa_offset(-8)
  53. cfi_restore(13)
  54. popq %r12
  55. cfi_adjust_cfa_offset(-8)
  56. cfi_restore(12)
  57. retq
  58. cfi_adjust_cfa_offset(16)
  59. cfi_offset(12, -16)
  60. cfi_offset(13, -24)
  61. 1: call __pthread_enable_asynccancel
  62. movl %eax, %r8d
  63. xorq %r10, %r10
  64. movl $SYS_futex, %eax
  65. movq %r13, %rdi
  66. movq %r10, %rsi
  67. movq %r10, %rdx
  68. syscall
  69. movq %rax, %r12
  70. movl %r8d, %edi
  71. call __pthread_disable_asynccancel
  72. testq %r12, %r12
  73. je 3b
  74. cmpq $-EWOULDBLOCK, %r12
  75. je 3b
  76. negq %r12
  77. #if USE___THREAD
  78. movq errno@gottpoff(%rip), %rdx
  79. movl %r12d, %fs:(%rdx)
  80. #else
  81. callq __errno_location@plt
  82. movl %r12d, (%rax)
  83. #endif
  84. orl $-1, %eax
  85. popq %r13
  86. cfi_adjust_cfa_offset(-8)
  87. cfi_restore(13)
  88. popq %r12
  89. cfi_adjust_cfa_offset(-8)
  90. cfi_restore(12)
  91. retq
  92. 4: /* Canceled. */
  93. movq $0xffffffffffffffff, %fs:RESULT
  94. LOCK
  95. orl $0x10, %fs:CANCELHANDLING
  96. movq %fs:CLEANUP_JMP_BUF, %rdi
  97. jmp HIDDEN_JUMPTARGET (__pthread_unwind)
  98. cfi_endproc
  99. .size sem_wait,.-sem_wait