]>
Commit | Line | Data |
---|---|---|
0566b130 | 1 | /* Copyright (C) 2002, 2003 Free Software Foundation, Inc. |
76a50749 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 | |
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 | |
18 | 02111-1307 USA. */ | |
19 | ||
20 | #include <sysdep.h> | |
21 | #include <shlib-compat.h> | |
22 | ||
23 | .text | |
24 | ||
25 | #ifndef UP | |
26 | # define LOCK lock | |
27 | #else | |
28 | # define | |
29 | #endif | |
30 | ||
31 | #define SYS_gettimeofday __NR_gettimeofday | |
32 | #define SYS_futex 240 | |
33 | #define FUTEX_WAKE 1 | |
34 | ||
35 | #define EINTR 4 | |
36 | #define EAGAIN 11 | |
37 | #define EWOULDBLOCK EAGAIN | |
38 | #define EINVAL 22 | |
39 | #define ETIMEDOUT 110 | |
40 | ||
41 | ||
42 | .globl __new_sem_wait | |
43 | .type __new_sem_wait,@function | |
44 | .align 16 | |
45 | __new_sem_wait: | |
46 | pushl %ebx | |
47 | pushl %esi | |
48 | ||
49 | movl 12(%esp), %ebx | |
50 | ||
51 | 3: movl (%ebx), %eax | |
52 | 2: testl %eax, %eax | |
53 | je,pn 1f | |
54 | ||
55 | leal -1(%eax), %edx | |
56 | LOCK | |
57 | cmpxchgl %edx, (%ebx) | |
58 | jne,pn 2b | |
59 | xorl %eax, %eax | |
60 | ||
61 | popl %esi | |
62 | popl %ebx | |
63 | ret | |
64 | ||
65 | 1: xorl %esi, %esi | |
66 | movl $SYS_futex, %eax | |
67 | movl %esi, %ecx | |
68 | movl %esi, %edx | |
097eca29 | 69 | ENTER_KERNEL |
76a50749 UD |
70 | |
71 | testl %eax, %eax | |
72 | je 3b | |
73 | cmpl $-EWOULDBLOCK, %eax | |
74 | je 3b | |
75 | negl %eax | |
76 | #ifdef PIC | |
77 | call __i686.get_pc_thunk.bx | |
78 | #else | |
79 | movl $4f, %ebx | |
80 | 4: | |
81 | #endif | |
82 | addl $_GLOBAL_OFFSET_TABLE_, %ebx | |
a218c9cf | 83 | #if USE___THREAD |
76a50749 UD |
84 | movl %gs:0, %edx |
85 | subl errno@gottpoff(%ebx), %edx | |
86 | movl %eax, (%edx) | |
a218c9cf UD |
87 | #else |
88 | movl %eax, %edx | |
89 | call __errno_location@plt | |
90 | movl %edx, (%eax) | |
91 | #endif | |
76a50749 UD |
92 | orl $-1, %eax |
93 | popl %esi | |
94 | popl %ebx | |
95 | ret | |
96 | .size __new_sem_wait,.-__new_sem_wait | |
97 | .symver __new_sem_wait, sem_wait@@GLIBC_2.1 | |
98 | #if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1) | |
99 | .global __old_sem_wait | |
100 | __old_sem_wait = __new_sem_wait | |
101 | .symver __old_sem_wait, sem_wait@GLIBC_2.0 | |
102 | #endif | |
103 | ||
104 | ||
105 | .globl __new_sem_trywait | |
106 | .type __new_sem_trywait,@function | |
107 | .align 16 | |
108 | __new_sem_trywait: | |
109 | movl 4(%esp), %ecx | |
110 | ||
111 | movl (%ecx), %eax | |
112 | 2: testl %eax, %eax | |
113 | jz 1f | |
114 | ||
115 | leal -1(%eax), %edx | |
116 | LOCK | |
117 | cmpxchgl %edx, (%ecx) | |
118 | jne,pn 2b | |
119 | xorl %eax, %eax | |
120 | ret | |
121 | ||
122 | 1: | |
123 | #ifdef PIC | |
124 | call __i686.get_pc_thunk.cx | |
125 | #else | |
126 | movl $3f, %ecx | |
127 | 3: | |
128 | #endif | |
129 | addl $_GLOBAL_OFFSET_TABLE_, %ecx | |
a218c9cf | 130 | #if USE___THREAD |
76a50749 UD |
131 | movl %gs:0, %edx |
132 | subl errno@gottpoff(%ecx), %edx | |
133 | movl $EAGAIN, (%edx) | |
a218c9cf UD |
134 | #else |
135 | call __errno_location@plt | |
136 | movl $EAGAIN, (%eax) | |
137 | #endif | |
76a50749 UD |
138 | orl $-1, %eax |
139 | ret | |
140 | .size __new_sem_trywait,.-__new_sem_trywait | |
141 | .symver __new_sem_trywait, sem_trywait@@GLIBC_2.1 | |
142 | #if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1) | |
143 | .global __old_sem_trywait | |
144 | __old_sem_trywait = __new_sem_trywait | |
145 | .symver __old_sem_trywait, sem_trywait@GLIBC_2.0 | |
146 | #endif | |
147 | ||
148 | ||
149 | .globl sem_timedwait | |
150 | .type sem_timedwait,@function | |
151 | .align 16 | |
152 | sem_timedwait: | |
153 | movl 4(%esp), %ecx | |
154 | ||
155 | movl (%ecx), %eax | |
156 | 2: testl %eax, %eax | |
157 | je,pn 1f | |
158 | ||
159 | leal -1(%eax), %edx | |
160 | LOCK | |
161 | cmpxchgl %edx, (%ecx) | |
162 | jne,pn 2b | |
163 | ||
164 | xorl %eax, %eax | |
165 | ret | |
166 | ||
167 | /* Check whether the timeout value is valid. */ | |
168 | 1: pushl %esi | |
169 | pushl %edi | |
170 | pushl %ebx | |
171 | subl $8, %esp | |
172 | ||
173 | movl %esp, %esi | |
174 | movl 28(%esp), %edi | |
175 | ||
176 | /* Check for invalid nanosecond field. */ | |
177 | cmpl $1000000000, 4(%edi) | |
178 | movl $EINVAL, %eax | |
179 | jae 6f | |
180 | ||
181 | 7: xorl %ecx, %ecx | |
182 | movl %esp, %ebx | |
183 | movl %ecx, %edx | |
184 | movl $SYS_gettimeofday, %eax | |
097eca29 | 185 | ENTER_KERNEL |
76a50749 UD |
186 | |
187 | /* Compute relative timeout. */ | |
188 | movl 4(%esp), %eax | |
189 | movl $1000, %edx | |
190 | mul %edx /* Milli seconds to nano seconds. */ | |
191 | movl (%edi), %ecx | |
192 | movl 4(%edi), %edx | |
193 | subl (%esp), %ecx | |
194 | subl %eax, %edx | |
195 | jns 5f | |
196 | addl $1000000000, %edx | |
197 | decl %ecx | |
198 | 5: testl %ecx, %ecx | |
199 | movl $ETIMEDOUT, %eax | |
200 | js 6f /* Time is already up. */ | |
201 | ||
202 | movl %ecx, (%esp) /* Store relative timeout. */ | |
203 | movl %edx, 4(%esp) | |
204 | movl 24(%esp), %ebx | |
205 | xorl %ecx, %ecx | |
206 | movl $SYS_futex, %eax | |
207 | xorl %edx, %edx | |
097eca29 | 208 | ENTER_KERNEL |
76a50749 UD |
209 | |
210 | testl %eax, %eax | |
211 | je,pt 9f | |
212 | cmpl $-EWOULDBLOCK, %eax | |
213 | jne 3f | |
214 | ||
215 | 9: movl (%ebx), %eax | |
216 | 8: testl %eax, %eax | |
217 | je 7b | |
218 | ||
219 | leal -1(%eax), %ecx | |
220 | LOCK | |
221 | cmpxchgl %ecx, (%ebx) | |
222 | jne,pn 8b | |
223 | ||
224 | addl $8, %esp | |
225 | xorl %eax, %eax | |
226 | popl %ebx | |
227 | popl %edi | |
228 | popl %esi | |
229 | ret | |
230 | ||
231 | 3: negl %eax | |
232 | 6: | |
233 | #ifdef PIC | |
234 | call __i686.get_pc_thunk.bx | |
235 | #else | |
236 | movl $4f, %ebx | |
237 | 4: | |
238 | #endif | |
239 | addl $_GLOBAL_OFFSET_TABLE_, %ebx | |
a218c9cf | 240 | #if USE___THREAD |
76a50749 UD |
241 | movl %gs:0, %edx |
242 | subl errno@gottpoff(%ebx), %edx | |
243 | movl %eax, (%edx) | |
a218c9cf UD |
244 | #else |
245 | movl %eax, %edx | |
246 | call __errno_location@plt | |
247 | movl %edx, (%eax) | |
248 | #endif | |
76a50749 UD |
249 | |
250 | addl $8, %esp | |
251 | orl $-1, %eax | |
252 | popl %ebx | |
253 | popl %edi | |
254 | popl %esi | |
255 | ret | |
256 | .size sem_timedwait,.-sem_timedwait | |
257 | ||
258 | ||
259 | .globl __new_sem_post | |
260 | .type __new_sem_post,@function | |
261 | .align 16 | |
262 | __new_sem_post: | |
263 | pushl %esi | |
264 | pushl %ebx | |
265 | ||
266 | movl 12(%esp), %ebx | |
267 | movl $1, %edx | |
268 | LOCK | |
269 | xaddl %edx, (%ebx) | |
270 | ||
271 | xorl %esi, %esi | |
272 | movl $SYS_futex, %eax | |
273 | movl $FUTEX_WAKE, %ecx | |
274 | incl %edx | |
097eca29 | 275 | ENTER_KERNEL |
76a50749 UD |
276 | |
277 | testl %eax, %eax | |
278 | js 1f | |
279 | ||
0566b130 | 280 | xorl %eax, %eax |
76a50749 UD |
281 | popl %ebx |
282 | popl %esi | |
283 | ret | |
284 | ||
285 | 1: | |
286 | #ifdef PIC | |
287 | call __i686.get_pc_thunk.bx | |
288 | #else | |
289 | movl $4f, %ebx | |
290 | 4: | |
291 | #endif | |
292 | addl $_GLOBAL_OFFSET_TABLE_, %ebx | |
a218c9cf | 293 | #if USE___THREAD |
76a50749 UD |
294 | movl %gs:0, %edx |
295 | subl errno@gottpoff(%ebx), %edx | |
296 | movl $EINVAL, (%edx) | |
a218c9cf UD |
297 | #else |
298 | call __errno_location@plt | |
299 | movl $EAGAIN, (%eax) | |
300 | #endif | |
76a50749 UD |
301 | |
302 | orl $-1, %eax | |
303 | popl %ebx | |
304 | popl %esi | |
305 | ret | |
306 | .size __new_sem_post,.-__new_sem_post | |
307 | .symver __new_sem_post, sem_post@@GLIBC_2.1 | |
308 | #if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1) | |
309 | .global __old_sem_post | |
310 | __old_sem_post = __new_sem_post | |
311 | .symver __old_sem_post, sem_post@GLIBC_2.0 | |
312 | #endif | |
313 | ||
314 | ||
315 | #ifdef PIC | |
316 | .section .gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits | |
317 | .globl __i686.get_pc_thunk.bx | |
318 | .hidden __i686.get_pc_thunk.bx | |
319 | .type __i686.get_pc_thunk.bx,@function | |
320 | __i686.get_pc_thunk.bx: | |
321 | movl (%esp), %ebx; | |
322 | ret | |
323 | .size __i686.get_pc_thunk.bx,.-__i686.get_pc_thunk.bx | |
324 | ||
325 | ||
326 | .section .gnu.linkonce.t.__i686.get_pc_thunk.cx,"ax",@progbits | |
327 | .globl __i686.get_pc_thunk.cx | |
328 | .hidden __i686.get_pc_thunk.cx | |
329 | .type __i686.get_pc_thunk.cx,@function | |
330 | __i686.get_pc_thunk.cx: | |
331 | movl (%esp), %ecx; | |
332 | ret | |
333 | .size __i686.get_pc_thunk.cx,.-__i686.get_pc_thunk.cx | |
334 | #endif |