Update copyright notices with scripts/update-copyrights
[glibc.git] / nptl / sysdeps / unix / sysv / linux / x86_64 / sem_wait.S
blob8f4d0686ec5bb1a9fb3c367dd7c34a7c2efb3876
1 /* Copyright (C) 2002-2014 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <http://www.gnu.org/licenses/>.  */
19 #include <sysdep.h>
20 #include <lowlevellock.h>
21 #include <shlib-compat.h>
22 #include <pthread-errnos.h>
23 #include <structsem.h>
26         .text
28         .globl  sem_wait
29         .type   sem_wait,@function
30         .align  16
31 sem_wait:
32 .LSTARTCODE:
33         cfi_startproc
34 #ifdef SHARED
35         cfi_personality(DW_EH_PE_pcrel | DW_EH_PE_sdata4 | DW_EH_PE_indirect,
36                         DW.ref.__gcc_personality_v0)
37         cfi_lsda(DW_EH_PE_pcrel | DW_EH_PE_sdata4, .LexceptSTART)
38 #else
39         cfi_personality(DW_EH_PE_udata4, __gcc_personality_v0)
40         cfi_lsda(DW_EH_PE_udata4, .LexceptSTART)
41 #endif
43 #if VALUE == 0
44         movl    (%rdi), %eax
45 #else
46         movl    VALUE(%rdi), %eax
47 #endif
48 2:      testl   %eax, %eax
49         je      1f
51         leal    -1(%rax), %edx
52         LOCK
53 #if VALUE == 0
54         cmpxchgl %edx, (%rdi)
55 #else
56         cmpxchgl %edx, VALUE(%rdi)
57 #endif
58         jne     2b
60         xorl    %eax, %eax
61         retq
63         /* This push is only needed to store the sem_t pointer for the
64            exception handler.  */
65 1:      pushq   %rdi
66         cfi_adjust_cfa_offset(8)
68         LOCK
69         LP_OP(add) $1, NWAITERS(%rdi)
71 .LcleanupSTART:
72 6:      call    __pthread_enable_asynccancel
73         movl    %eax, %r8d
75         xorq    %r10, %r10
76         movl    $SYS_futex, %eax
77 #if FUTEX_WAIT == 0
78         movl    PRIVATE(%rdi), %esi
79 #else
80         movl    $FUTEX_WAIT, %esi
81         orl     PRIVATE(%rdi), %esi
82 #endif
83         xorl    %edx, %edx
84         syscall
85         movq    %rax, %rcx
87         xchgq   %r8, %rdi
88         call    __pthread_disable_asynccancel
89 .LcleanupEND:
90         movq    %r8, %rdi
92         testq   %rcx, %rcx
93         je      3f
94         cmpq    $-EWOULDBLOCK, %rcx
95         jne     4f
98 #if VALUE == 0
99         movl    (%rdi), %eax
100 #else
101         movl    VALUE(%rdi), %eax
102 #endif
103 5:      testl   %eax, %eax
104         je      6b
106         leal    -1(%rax), %edx
107         LOCK
108 #if VALUE == 0
109         cmpxchgl %edx, (%rdi)
110 #else
111         cmpxchgl %edx, VALUE(%rdi)
112 #endif
113         jne     5b
115         xorl    %eax, %eax
117 9:      LOCK
118         LP_OP(sub) $1, NWAITERS(%rdi)
120         leaq    8(%rsp), %rsp
121         cfi_adjust_cfa_offset(-8)
123         retq
125         cfi_adjust_cfa_offset(8)
126 4:      negq    %rcx
127         movq    errno@gottpoff(%rip), %rdx
128         movl    %ecx, %fs:(%rdx)
129         orl     $-1, %eax
131         jmp 9b
132         .size   sem_wait,.-sem_wait
135         .type   sem_wait_cleanup,@function
136 sem_wait_cleanup:
137         movq    (%rsp), %rdi
138         LOCK
139         LP_OP(sub) $1, NWAITERS(%rdi)
140         movq    %rax, %rdi
141 .LcallUR:
142         call    _Unwind_Resume@PLT
143         hlt
144 .LENDCODE:
145         cfi_endproc
146         .size   sem_wait_cleanup,.-sem_wait_cleanup
149         .section .gcc_except_table,"a",@progbits
150 .LexceptSTART:
151         .byte   DW_EH_PE_omit                   # @LPStart format
152         .byte   DW_EH_PE_omit                   # @TType format
153         .byte   DW_EH_PE_uleb128                # call-site format
154         .uleb128 .Lcstend-.Lcstbegin
155 .Lcstbegin:
156         .uleb128 .LcleanupSTART-.LSTARTCODE
157         .uleb128 .LcleanupEND-.LcleanupSTART
158         .uleb128 sem_wait_cleanup-.LSTARTCODE
159         .uleb128  0
160         .uleb128 .LcallUR-.LSTARTCODE
161         .uleb128 .LENDCODE-.LcallUR
162         .uleb128 0
163         .uleb128  0
164 .Lcstend:
167 #ifdef SHARED
168         .hidden DW.ref.__gcc_personality_v0
169         .weak   DW.ref.__gcc_personality_v0
170         .section .gnu.linkonce.d.DW.ref.__gcc_personality_v0,"aw",@progbits
171         .align  LP_SIZE
172         .type   DW.ref.__gcc_personality_v0, @object
173         .size   DW.ref.__gcc_personality_v0, LP_SIZE
174 DW.ref.__gcc_personality_v0:
175         ASM_ADDR __gcc_personality_v0
176 #endif