1 /* Copyright (C) 2002, 2003 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <shlib-compat.h>
22 #include <pthread-errnos.h>
32 /* For the calculation see asm/vsyscall.h. */
33 #define VSYSCALL_ADDR_vgettimeofday 0xffffffffff600000
39 .type sem_timedwait,@function
43 /* First check for cancellation. */
44 movl %fs:CANCELHANDLING, %eax
45 andl $0xfffffff9, %eax
61 /* Check whether the timeout value is valid. */
63 cfi_adjust_cfa_offset(8)
65 cfi_adjust_cfa_offset(8)
67 cfi_adjust_cfa_offset(8)
69 cfi_adjust_cfa_offset(24)
72 cfi_offset(12, -16) /* %r12 */
74 cfi_offset(13, -24) /* %r13 */
76 /* Check for invalid nanosecond field. */
77 cmpq $1000000000, 8(%r13)
79 cfi_offset(14, -24) /* %r14 */
82 7: call __pthread_enable_asynccancel
87 movq $VSYSCALL_ADDR_vgettimeofday, %rax
90 /* Compute relative timeout. */
93 mul %rdi /* Milli seconds to nano seconds. */
99 addq $1000000000, %rsi
102 movl $ETIMEDOUT, %r14d
103 js 6f /* Time is already up. */
105 movq %rdi, (%rsp) /* Store relative timeout. */
111 movq $SYS_futex, %rax
117 call __pthread_disable_asynccancel
121 cmpq $-EWOULDBLOCK, %r14
130 cmpxchgl %ecx, (%r12)
135 cfi_adjust_cfa_offset(-24)
137 cfi_adjust_cfa_offset(-8)
140 cfi_adjust_cfa_offset(-8)
143 cfi_adjust_cfa_offset(-8)
147 cfi_adjust_cfa_offset(48)
148 cfi_offset(12, -16) /* %r12 */
149 cfi_offset(13, -24) /* %r13 */
150 cfi_offset(14, -32) /* %r14 */
154 movq errno@gottpoff(%rip), %rdx
155 movl %r14d, %fs:(%rdx)
157 callq __errno_location@plt
163 cfi_adjust_cfa_offset(-48)
169 movq $0xffffffffffffffff, %fs:RESULT
171 orl $0x10, %fs:CANCELHANDLING
172 movq %fs:CLEANUP_JMP_BUF, %rdi
173 jmp HIDDEN_JUMPTARGET (__pthread_unwind)
175 .size sem_timedwait,.-sem_timedwait