sem_wait.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 <pthread-errnos.h>
  18. #include <tcb-offsets.h>
  19. #include <tls.h>
  20. #ifndef UP
  21. # define LOCK lock
  22. #else
  23. # define
  24. #endif
  25. #define FUTEX_WAKE 1
  26. .text
  27. .globl __new_sem_wait
  28. .type __new_sem_wait,@function
  29. .align 16
  30. cfi_startproc
  31. __new_sem_wait:
  32. /* First check for cancellation. */
  33. movl %gs:CANCELHANDLING, %eax
  34. andl $0xfffffff9, %eax
  35. cmpl $8, %eax
  36. je 5f
  37. pushl %ebx
  38. cfi_adjust_cfa_offset(4)
  39. pushl %esi
  40. cfi_adjust_cfa_offset(4)
  41. subl $4, %esp
  42. cfi_adjust_cfa_offset(4)
  43. movl 16(%esp), %ebx
  44. cfi_offset(3, -8) /* %ebx */
  45. cfi_offset(6, -12) /* %esi */
  46. 3: movl (%ebx), %eax
  47. 2: testl %eax, %eax
  48. je,pn 1f
  49. leal -1(%eax), %edx
  50. LOCK
  51. cmpxchgl %edx, (%ebx)
  52. jne,pn 2b
  53. xorl %eax, %eax
  54. movl 4(%esp), %esi
  55. cfi_restore(6)
  56. movl 8(%esp), %ebx
  57. cfi_restore(3)
  58. addl $12, %esp
  59. cfi_adjust_cfa_offset(-12)
  60. ret
  61. cfi_adjust_cfa_offset(8)
  62. cfi_offset(3, -8) /* %ebx */
  63. cfi_offset(6, -12) /* %esi */
  64. 1: call __pthread_enable_asynccancel
  65. movl %eax, (%esp)
  66. xorl %esi, %esi
  67. movl $SYS_futex, %eax
  68. movl %esi, %ecx
  69. movl %esi, %edx
  70. ENTER_KERNEL
  71. movl %eax, %esi
  72. movl (%esp), %eax
  73. call __pthread_disable_asynccancel
  74. testl %esi, %esi
  75. je 3b
  76. cmpl $-EWOULDBLOCK, %esi
  77. je 3b
  78. negl %esi
  79. #ifdef __PIC__
  80. call __x86.get_pc_thunk.bx
  81. #else
  82. movl $4f, %ebx
  83. 4:
  84. #endif
  85. addl $_GLOBAL_OFFSET_TABLE_, %ebx
  86. #if USE___THREAD
  87. # ifdef NO_TLS_DIRECT_SEG_REFS
  88. movl errno@gotntpoff(%ebx), %edx
  89. addl %gs:0, %edx
  90. movl %esi, (%edx)
  91. # else
  92. movl errno@gotntpoff(%ebx), %edx
  93. movl %esi, %gs:(%edx)
  94. # endif
  95. #else
  96. call __errno_location@plt
  97. movl %esi, (%eax)
  98. #endif
  99. orl $-1, %eax
  100. movl 4(%esp), %esi
  101. cfi_restore(6)
  102. movl 8(%esp), %ebx
  103. cfi_restore(3)
  104. addl $12, %esp
  105. cfi_adjust_cfa_offset(-12)
  106. ret
  107. 5: /* Canceled. */
  108. movl $0xffffffff, %gs:RESULT
  109. LOCK
  110. orl $0x10, %gs:CANCELHANDLING
  111. movl %gs:CLEANUP_JMP_BUF, %eax
  112. jmp HIDDEN_JUMPTARGET (__pthread_unwind)
  113. cfi_endproc
  114. .size __new_sem_wait,.-__new_sem_wait
  115. weak_alias(__new_sem_wait, sem_wait)