sem_wait.S 3.5 KB

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