1 /* Copyright (C) 2002-2019 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/>. */
20 #include <pthread-errnos.h>
21 #include <kernel-features.h>
22 #include <lowlevellock.h>
24 #include <stap-probe.h>
28 #define LOAD_PRIVATE_FUTEX_WAIT(reg) \
29 movl $(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
30 #define LOAD_PRIVATE_FUTEX_WAKE(reg) \
31 movl $(FUTEX_WAKE | FUTEX_PRIVATE_FLAG), reg
32 #define LOAD_FUTEX_WAIT(reg) \
33 xorl $(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
34 #define LOAD_FUTEX_WAIT_ABS(reg) \
35 xorl $(FUTEX_WAIT_BITSET | FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME), reg
36 #define LOAD_FUTEX_WAKE(reg) \
37 xorl $(FUTEX_WAKE | FUTEX_PRIVATE_FLAG), reg
40 .globl __lll_lock_wait_private
41 .type __lll_lock_wait_private,@function
42 .hidden __lll_lock_wait_private
44 __lll_lock_wait_private:
47 cfi_adjust_cfa_offset(8)
49 cfi_adjust_cfa_offset(8)
52 xorq %r10, %r10 /* No timeout. */
54 LOAD_PRIVATE_FUTEX_WAIT (%esi)
56 cmpl %edx, %eax /* NB: %edx == 2 */
59 1: LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
64 xchgl %eax, (%rdi) /* NB: lock is implied */
70 cfi_adjust_cfa_offset(-8)
73 cfi_adjust_cfa_offset(-8)
77 .size __lll_lock_wait_private,.-__lll_lock_wait_private
80 .globl __lll_lock_wait
81 .type __lll_lock_wait,@function
82 .hidden __lll_lock_wait
87 cfi_adjust_cfa_offset(8)
89 cfi_adjust_cfa_offset(8)
92 xorq %r10, %r10 /* No timeout. */
94 LOAD_FUTEX_WAIT (%esi)
96 cmpl %edx, %eax /* NB: %edx == 2 */
99 1: LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
100 movl $SYS_futex, %eax
104 xchgl %eax, (%rdi) /* NB: lock is implied */
110 cfi_adjust_cfa_offset(-8)
113 cfi_adjust_cfa_offset(-8)
117 .size __lll_lock_wait,.-__lll_lock_wait
124 .globl __lll_timedlock_wait
125 .type __lll_timedlock_wait,@function
126 .hidden __lll_timedlock_wait
128 __lll_timedlock_wait:
134 cfi_adjust_cfa_offset(8)
135 cfi_rel_offset(%r9, 0)
138 movl $0xffffffff, %r9d
139 LOAD_FUTEX_WAIT_ABS (%esi)
145 1: movl $SYS_futex, %eax
149 2: xchgl %edx, (%rdi) /* NB: lock is implied */
154 cmpl $-ETIMEDOUT, %eax
163 cfi_adjust_cfa_offset(-8)
167 5: movl $ETIMEDOUT, %eax
171 .size __lll_timedlock_wait,.-__lll_timedlock_wait
175 .globl __lll_unlock_wake_private
176 .type __lll_unlock_wake_private,@function
177 .hidden __lll_unlock_wake_private
179 __lll_unlock_wake_private:
182 cfi_adjust_cfa_offset(8)
184 cfi_adjust_cfa_offset(8)
185 cfi_offset(%rsi, -16)
186 cfi_offset(%rdx, -24)
189 LOAD_PRIVATE_FUTEX_WAKE (%esi)
190 movl $1, %edx /* Wake one thread. */
191 movl $SYS_futex, %eax
195 cfi_adjust_cfa_offset(-8)
198 cfi_adjust_cfa_offset(-8)
202 .size __lll_unlock_wake_private,.-__lll_unlock_wake_private
205 .globl __lll_unlock_wake
206 .type __lll_unlock_wake,@function
207 .hidden __lll_unlock_wake
212 cfi_adjust_cfa_offset(8)
214 cfi_adjust_cfa_offset(8)
215 cfi_offset(%rsi, -16)
216 cfi_offset(%rdx, -24)
219 LOAD_FUTEX_WAKE (%esi)
220 movl $1, %edx /* Wake one thread. */
221 movl $SYS_futex, %eax
225 cfi_adjust_cfa_offset(-8)
228 cfi_adjust_cfa_offset(-8)
232 .size __lll_unlock_wake,.-__lll_unlock_wake