diff options
author | Ulrich Drepper <drepper@redhat.com> | 2007-05-07 14:26:13 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2007-05-07 14:26:13 +0000 |
commit | 6780bc44e8b651cc67dbef2761fc92bdee46c45e (patch) | |
tree | 5674ef24d888a342bea9ecc39645b5141ca9828e /nptl | |
parent | f84ecfd74fe96e4a97e069fc1b728c8bd676cdbb (diff) | |
download | glibc-6780bc44e8b651cc67dbef2761fc92bdee46c45e.tar.gz glibc-6780bc44e8b651cc67dbef2761fc92bdee46c45e.tar.xz glibc-6780bc44e8b651cc67dbef2761fc92bdee46c45e.zip |
* sysdeps/unix/sysv/linux/lowlevelrobustlock.c
(__lll_robust_lock_wait): Fix race caused by reloading of futex value. (__lll_robust_timedlock_wait): Likewise. Reported by Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>.
Diffstat (limited to 'nptl')
-rw-r--r-- | nptl/ChangeLog | 7 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c | 22 |
2 files changed, 26 insertions, 3 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog index d4ccf50d7e..20b1374e03 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,10 @@ +2007-05-07 Ulrich Drepper <drepper@redhat.com> + + * sysdeps/unix/sysv/linux/lowlevelrobustlock.c + (__lll_robust_lock_wait): Fix race caused by reloading of futex value. + (__lll_robust_timedlock_wait): Likewise. + Reported by Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>. + 2007-05-06 Mike Frysinger <vapier@gentoo.org> [BZ #4465] diff --git a/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c b/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c index 3e88ee1866..30ef991bd0 100644 --- a/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c +++ b/nptl/sysdeps/unix/sysv/linux/lowlevelrobustlock.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2006 Free Software Foundation, Inc. +/* Copyright (C) 2006, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2006. @@ -30,6 +30,10 @@ __lll_robust_lock_wait (int *futex) int oldval = *futex; int tid = THREAD_GETMEM (THREAD_SELF, tid); + /* If the futex changed meanwhile try locking again. */ + if (oldval == 0) + goto try; + do { if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0)) @@ -41,6 +45,9 @@ __lll_robust_lock_wait (int *futex) continue; lll_futex_wait (futex, newval); + + try: + ; } while ((oldval = atomic_compare_and_exchange_val_acq (futex, tid | FUTEX_WAITERS, @@ -57,6 +64,11 @@ __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime) return EINVAL; int tid = THREAD_GETMEM (THREAD_SELF, tid); + int oldval = *futex; + + /* If the futex changed meanwhile try locking again. */ + if (oldval == 0) + goto try; do { @@ -80,7 +92,6 @@ __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime) return ETIMEDOUT; /* Wait. */ - int oldval = *futex; if (__builtin_expect (oldval & FUTEX_OWNER_DIED, 0)) return oldval; @@ -90,8 +101,13 @@ __lll_robust_timedlock_wait (int *futex, const struct timespec *abstime) continue; lll_futex_timed_wait (futex, newval, &rt); + + try: + ; } - while (atomic_compare_and_exchange_bool_acq (futex, tid | FUTEX_WAITERS, 0)); + while ((oldval = atomic_compare_and_exchange_val_acq (futex, + tid | FUTEX_WAITERS, + 0)) != 0); return 0; } |