diff options
author | Siddhesh Poyarekar <siddhesh@redhat.com> | 2012-10-10 12:17:27 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@redhat.com> | 2012-10-10 12:52:56 +0530 |
commit | 0e3b5d6a6859d74a18033d3a55e0ee92340437b3 (patch) | |
tree | b4f8c7fe139fb80e4fba77409942b68942a5df48 /nptl/sysdeps/unix/sysv/linux/i386 | |
parent | f96f12423a1b801f4a198f2568e29e85bd9cc473 (diff) | |
download | glibc-0e3b5d6a6859d74a18033d3a55e0ee92340437b3.zip glibc-0e3b5d6a6859d74a18033d3a55e0ee92340437b3.tar.gz glibc-0e3b5d6a6859d74a18033d3a55e0ee92340437b3.tar.bz2 |
Take lock in pthread_cond_wait cleanup handler only when needed
[BZ #14652]
When a thread waiting in pthread_cond_wait with a PI mutex is
cancelled after it has returned successfully from the futex syscall
but just before async cancellation is disabled, it enters its
cancellation handler with the mutex held and simply calling a
mutex_lock again will result in a deadlock. Hence, it is necessary to
see if the thread owns the lock and try to lock it only if it doesn't.
Diffstat (limited to 'nptl/sysdeps/unix/sysv/linux/i386')
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S | 18 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S | 18 |
2 files changed, 32 insertions, 4 deletions
diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S index 6761c13..884987c 100644 --- a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S +++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_timedwait.S @@ -649,10 +649,24 @@ __condvar_tw_cleanup: movl $0x7fffffff, %edx ENTER_KERNEL + /* Lock the mutex only if we don't own it already. This only happens + in case of PI mutexes, if we got cancelled after a successful + return of the futex syscall and before disabling async + cancellation. */ 5: movl 24+FRAME_SIZE(%esp), %eax - call __pthread_mutex_cond_lock + movl MUTEX_KIND(%eax), %ebx + andl $(ROBUST_BIT|PI_BIT), %ebx + cmpl $PI_BIT, %ebx + jne 8f + + movl (%eax), %ebx + andl $TID_MASK, %ebx + cmpl %ebx, %gs:TID + je 9f + +8: call __pthread_mutex_cond_lock - movl %esi, (%esp) +9: movl %esi, (%esp) .LcallUR: call _Unwind_Resume hlt diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S index 0af06ac..bf1e5fe 100644 --- a/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S +++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_wait.S @@ -566,10 +566,24 @@ __condvar_w_cleanup: movl $0x7fffffff, %edx ENTER_KERNEL + /* Lock the mutex only if we don't own it already. This only happens + in case of PI mutexes, if we got cancelled after a successful + return of the futex syscall and before disabling async + cancellation. */ 5: movl 24+FRAME_SIZE(%esp), %eax - call __pthread_mutex_cond_lock + movl MUTEX_KIND(%eax), %ebx + andl $(ROBUST_BIT|PI_BIT), %ebx + cmpl $PI_BIT, %ebx + jne 8f + + movl (%eax), %ebx + andl $TID_MASK, %ebx + cmpl %ebx, %gs:TID + je 9f + +8: call __pthread_mutex_cond_lock - movl %esi, (%esp) +9: movl %esi, (%esp) .LcallUR: call _Unwind_Resume hlt |