sem_wait.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* Copyright (C) 2002, 2003, 2005, 2007, 2009 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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #include <lowlevellock.h>
  17. #include <pthread-errnos.h>
  18. #include <structsem.h>
  19. .text
  20. .globl sem_wait
  21. .type sem_wait,@function
  22. .align 16
  23. sem_wait:
  24. .LSTARTCODE:
  25. cfi_startproc
  26. #if VALUE == 0
  27. movl (%rdi), %eax
  28. #else
  29. movl VALUE(%rdi), %eax
  30. #endif
  31. 2: testl %eax, %eax
  32. je 1f
  33. leal -1(%rax), %edx
  34. LOCK
  35. #if VALUE == 0
  36. cmpxchgl %edx, (%rdi)
  37. #else
  38. cmpxchgl %edx, VALUE(%rdi)
  39. #endif
  40. jne 2b
  41. xorl %eax, %eax
  42. retq
  43. /* This push is only needed to store the sem_t pointer for the
  44. exception handler. */
  45. 1: pushq %rdi
  46. cfi_adjust_cfa_offset(8)
  47. LOCK
  48. addq $1, NWAITERS(%rdi)
  49. .LcleanupSTART:
  50. 6: call __pthread_enable_asynccancel
  51. movl %eax, %r8d
  52. xorq %r10, %r10
  53. movl $SYS_futex, %eax
  54. #if FUTEX_WAIT == 0
  55. movl PRIVATE(%rdi), %esi
  56. #else
  57. movl $FUTEX_WAIT, %esi
  58. orl PRIVATE(%rdi), %esi
  59. #endif
  60. xorl %edx, %edx
  61. syscall
  62. movq %rax, %rcx
  63. xchgq %r8, %rdi
  64. call __pthread_disable_asynccancel
  65. .LcleanupEND:
  66. movq %r8, %rdi
  67. testq %rcx, %rcx
  68. je 3f
  69. cmpq $-EWOULDBLOCK, %rcx
  70. jne 4f
  71. 3:
  72. #if VALUE == 0
  73. movl (%rdi), %eax
  74. #else
  75. movl VALUE(%rdi), %eax
  76. #endif
  77. 5: testl %eax, %eax
  78. je 6b
  79. leal -1(%rax), %edx
  80. LOCK
  81. #if VALUE == 0
  82. cmpxchgl %edx, (%rdi)
  83. #else
  84. cmpxchgl %edx, VALUE(%rdi)
  85. #endif
  86. jne 5b
  87. xorl %eax, %eax
  88. 9: LOCK
  89. subq $1, NWAITERS(%rdi)
  90. leaq 8(%rsp), %rsp
  91. cfi_adjust_cfa_offset(-8)
  92. retq
  93. cfi_adjust_cfa_offset(8)
  94. 4: negq %rcx
  95. #if USE___THREAD
  96. movq errno@gottpoff(%rip), %rdx
  97. movl %ecx, %fs:(%rdx)
  98. #else
  99. # error "not supported. %rcx and %rdi must be preserved"
  100. callq __errno_location@plt
  101. movl %ecx, (%rax)
  102. #endif
  103. orl $-1, %eax
  104. jmp 9b
  105. .size sem_wait,.-sem_wait
  106. .type sem_wait_cleanup,@function
  107. sem_wait_cleanup:
  108. movq (%rsp), %rdi
  109. LOCK
  110. subq $1, NWAITERS(%rdi)
  111. movq %rax, %rdi
  112. .LcallUR:
  113. call _Unwind_Resume@PLT
  114. hlt
  115. .LENDCODE:
  116. cfi_endproc
  117. .size sem_wait_cleanup,.-sem_wait_cleanup
  118. .section .gcc_except_table,"a",@progbits
  119. .LexceptSTART:
  120. .byte DW_EH_PE_omit # @LPStart format
  121. .byte DW_EH_PE_omit # @TType format
  122. .byte DW_EH_PE_uleb128 # call-site format
  123. .uleb128 .Lcstend-.Lcstbegin
  124. .Lcstbegin:
  125. .uleb128 .LcleanupSTART-.LSTARTCODE
  126. .uleb128 .LcleanupEND-.LcleanupSTART
  127. .uleb128 sem_wait_cleanup-.LSTARTCODE
  128. .uleb128 0
  129. .uleb128 .LcallUR-.LSTARTCODE
  130. .uleb128 .LENDCODE-.LcallUR
  131. .uleb128 0
  132. .uleb128 0
  133. .Lcstend:
  134. #ifdef SHARED
  135. .hidden DW.ref.__gcc_personality_v0
  136. .weak DW.ref.__gcc_personality_v0
  137. .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
  138. .align 8
  139. .type DW.ref.__gcc_personality_v0, @object
  140. .size DW.ref.__gcc_personality_v0, 8
  141. DW.ref.__gcc_personality_v0:
  142. .quad __gcc_personality_v0
  143. #endif