]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/x86_64/sem_wait.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / x86_64 / sem_wait.S
CommitLineData
b168057a 1/* Copyright (C) 2002-2015 Free Software Foundation, Inc.
db5f2fc9
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
4
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.
9
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.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
db5f2fc9
UD
18
19#include <sysdep.h>
e51deae7 20#include <lowlevellock.h>
db5f2fc9 21#include <shlib-compat.h>
326132db 22#include <pthread-errnos.h>
3d2dd6ca 23#include <structsem.h>
db5f2fc9 24
db5f2fc9
UD
25
26 .text
27
7588880f
UD
28 .globl sem_wait
29 .type sem_wait,@function
db5f2fc9 30 .align 16
7588880f 31sem_wait:
3d2dd6ca 32.LSTARTCODE:
c3c2f3cf
UD
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
7726edc2 42
3d2dd6ca 43#if VALUE == 0
0adae468 44 movl (%rdi), %eax
3d2dd6ca 45#else
0adae468 46 movl VALUE(%rdi), %eax
3d2dd6ca 47#endif
db5f2fc9
UD
482: testl %eax, %eax
49 je 1f
50
3d2dd6ca 51 leal -1(%rax), %edx
db5f2fc9 52 LOCK
3d2dd6ca 53#if VALUE == 0
0adae468 54 cmpxchgl %edx, (%rdi)
3d2dd6ca 55#else
0adae468 56 cmpxchgl %edx, VALUE(%rdi)
3d2dd6ca 57#endif
db5f2fc9 58 jne 2b
db5f2fc9 59
0adae468 60 xorl %eax, %eax
db5f2fc9
UD
61 retq
62
9083bcc5
UD
63 /* This push is only needed to store the sem_t pointer for the
64 exception handler. */
651: pushq %rdi
0adae468 66 cfi_adjust_cfa_offset(8)
0adae468
UD
67
68 LOCK
dde05f00 69 LP_OP(add) $1, NWAITERS(%rdi)
3d2dd6ca
UD
70
71.LcleanupSTART:
726: call __pthread_enable_asynccancel
7726edc2
UD
73 movl %eax, %r8d
74
75 xorq %r10, %r10
ee618985 76 movl $SYS_futex, %eax
42e6c665
UD
77#if FUTEX_WAIT == 0
78 movl PRIVATE(%rdi), %esi
79#else
3d2dd6ca 80 movl $FUTEX_WAIT, %esi
42e6c665
UD
81 orl PRIVATE(%rdi), %esi
82#endif
3d2dd6ca 83 xorl %edx, %edx
db5f2fc9 84 syscall
9083bcc5 85 movq %rax, %rcx
7726edc2 86
9083bcc5 87 xchgq %r8, %rdi
7726edc2 88 call __pthread_disable_asynccancel
3d2dd6ca 89.LcleanupEND:
9083bcc5 90 movq %r8, %rdi
db5f2fc9 91
9083bcc5 92 testq %rcx, %rcx
3d2dd6ca 93 je 3f
9083bcc5 94 cmpq $-EWOULDBLOCK, %rcx
3d2dd6ca
UD
95 jne 4f
96
973:
98#if VALUE == 0
9083bcc5 99 movl (%rdi), %eax
3d2dd6ca 100#else
9083bcc5 101 movl VALUE(%rdi), %eax
3d2dd6ca
UD
102#endif
1035: testl %eax, %eax
104 je 6b
105
106 leal -1(%rax), %edx
107 LOCK
108#if VALUE == 0
9083bcc5 109 cmpxchgl %edx, (%rdi)
3d2dd6ca 110#else
9083bcc5 111 cmpxchgl %edx, VALUE(%rdi)
3d2dd6ca
UD
112#endif
113 jne 5b
114
0adae468
UD
115 xorl %eax, %eax
116
9083bcc5 1179: LOCK
dde05f00 118 LP_OP(sub) $1, NWAITERS(%rdi)
9083bcc5
UD
119
120 leaq 8(%rsp), %rsp
0adae468 121 cfi_adjust_cfa_offset(-8)
0adae468
UD
122
123 retq
124
9083bcc5
UD
125 cfi_adjust_cfa_offset(8)
1264: negq %rcx
db5f2fc9 127 movq errno@gottpoff(%rip), %rdx
9083bcc5 128 movl %ecx, %fs:(%rdx)
db5f2fc9 129 orl $-1, %eax
7726edc2 130
3d2dd6ca 131 jmp 9b
7588880f 132 .size sem_wait,.-sem_wait
3d2dd6ca
UD
133
134
135 .type sem_wait_cleanup,@function
136sem_wait_cleanup:
9083bcc5 137 movq (%rsp), %rdi
3d2dd6ca 138 LOCK
dde05f00 139 LP_OP(sub) $1, NWAITERS(%rdi)
3d2dd6ca
UD
140 movq %rax, %rdi
141.LcallUR:
142 call _Unwind_Resume@PLT
143 hlt
144.LENDCODE:
c3c2f3cf 145 cfi_endproc
3d2dd6ca
UD
146 .size sem_wait_cleanup,.-sem_wait_cleanup
147
148
149 .section .gcc_except_table,"a",@progbits
150.LexceptSTART:
c3c2f3cf
UD
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
3d2dd6ca
UD
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:
165
166
3d2dd6ca
UD
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
dde05f00 171 .align LP_SIZE
3d2dd6ca 172 .type DW.ref.__gcc_personality_v0, @object
dde05f00 173 .size DW.ref.__gcc_personality_v0, LP_SIZE
3d2dd6ca 174DW.ref.__gcc_personality_v0:
dde05f00 175 ASM_ADDR __gcc_personality_v0
3d2dd6ca 176#endif