1 /* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <pthread-errnos.h>
23 #include <lowlevellock.h>
24 #include <lowlevelrobustlock.h>
25 #include <kernel-features.h>
29 #define FUTEX_WAITERS 0x80000000
30 #define FUTEX_OWNER_DIED 0x40000000
32 #ifdef __ASSUME_PRIVATE_FUTEX
33 # define LOAD_FUTEX_WAIT(reg) \
34 xorl $(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), reg
37 # define LOAD_FUTEX_WAIT(reg) \
38 xorl $FUTEX_PRIVATE_FLAG, reg ; \
39 andl %fs:PRIVATE_FUTEX, reg
41 # define LOAD_FUTEX_WAIT(reg) \
42 xorl $FUTEX_PRIVATE_FLAG, reg ; \
43 andl %fs:PRIVATE_FUTEX, reg ; \
48 /* For the calculation see asm/vsyscall.h. */
49 #define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
52 .globl __lll_robust_lock_wait
53 .type __lll_robust_lock_wait,@function
54 .hidden __lll_robust_lock_wait
56 __lll_robust_lock_wait:
59 cfi_adjust_cfa_offset(8)
61 cfi_adjust_cfa_offset(8)
65 xorq %r10, %r10 /* No timeout. */
66 LOAD_FUTEX_WAIT (%esi)
69 orl $FUTEX_WAITERS, %edx
71 testl $FUTEX_OWNER_DIED, %eax
81 1: movl $SYS_futex, %eax
90 orl $FUTEX_WAITERS, %edx
97 cfi_adjust_cfa_offset(-8)
100 cfi_adjust_cfa_offset(-8)
104 .size __lll_robust_lock_wait,.-__lll_robust_lock_wait
107 .globl __lll_robust_timedlock_wait
108 .type __lll_robust_timedlock_wait,@function
109 .hidden __lll_robust_timedlock_wait
111 __lll_robust_timedlock_wait:
113 /* Check for a valid timeout value. */
114 cmpq $1000000000, 8(%rdx)
118 cfi_adjust_cfa_offset(8)
120 cfi_adjust_cfa_offset(8)
122 cfi_adjust_cfa_offset(8)
124 cfi_adjust_cfa_offset(8)
127 cfi_offset(%r12, -32)
128 cfi_offset(%r13, -40)
130 cfi_adjust_cfa_offset(8)
132 /* Stack frame for the timespec and timeval structs. */
134 cfi_adjust_cfa_offset(32)
139 1: movq %rax, 16(%rsp)
141 /* Get current time. */
144 movq $VSYSCALL_ADDR_vgettimeofday, %rax
145 /* This is a regular function call, all caller-save registers
146 might be clobbered. */
149 /* Compute relative timeout. */
152 mul %rdi /* Milli seconds to nano seconds. */
158 addq $1000000000, %rsi
161 js 8f /* Time is already up. */
164 movq %rdi, (%rsp) /* Store relative timeout. */
169 orl $FUTEX_WAITERS, %edx
171 testl $FUTEX_OWNER_DIED, %eax
178 cmpxchgl %edx, (%r12)
179 movq $0, %rcx /* Must use mov to avoid changing cc. */
184 LOAD_FUTEX_WAIT (%esi)
186 movl $SYS_futex, %eax
196 orl $FUTEX_WAITERS, %edx
198 cmpxchgl %edx, (%r12)
202 cfi_adjust_cfa_offset(-40)
204 cfi_adjust_cfa_offset(-8)
207 cfi_adjust_cfa_offset(-8)
210 cfi_adjust_cfa_offset(-8)
213 cfi_adjust_cfa_offset(-8)
217 3: movl $EINVAL, %eax
220 cfi_adjust_cfa_offset(72)
223 cfi_offset(%r12, -32)
224 cfi_offset(%r13, -40)
225 /* Check whether the time expired. */
226 7: cmpq $-ETIMEDOUT, %rcx
229 8: movl $ETIMEDOUT, %eax
232 .size __lll_robust_timedlock_wait,.-__lll_robust_timedlock_wait