aboutsummaryrefslogtreecommitdiff
path: root/nptl
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-12-21 21:50:33 +0000
committerUlrich Drepper <drepper@redhat.com>2006-12-21 21:50:33 +0000
commitfc242bef00206c3bab4117345734ce744f0b7eff (patch)
tree8eaf53937aa9e43d99ea7e520329907b6c313b79 /nptl
parent571511d557820b9ddbc400b7922f8904387ff78c (diff)
downloadglibc-fc242bef00206c3bab4117345734ce744f0b7eff.tar
glibc-fc242bef00206c3bab4117345734ce744f0b7eff.tar.gz
glibc-fc242bef00206c3bab4117345734ce744f0b7eff.tar.bz2
glibc-fc242bef00206c3bab4117345734ce744f0b7eff.zip
* include/atomic.h (atomic_forced_read): New macro.
Diffstat (limited to 'nptl')
-rw-r--r--nptl/ChangeLog5
-rw-r--r--nptl/sysdeps/unix/sysv/linux/pthread_kill.c18
2 files changed, 18 insertions, 5 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index 510693de6f..631e20ddbb 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,3 +1,8 @@
+2006-12-21 Jakub Jelinek <jakub@redhat.com>
+
+ * sysdeps/unix/sysv/linux/pthread_kill.c (pthread_kill): Make sure
+ tid isn't reread from pd->tid in between ESRCH test and the syscall.
+
2006-12-06 Jakub Jelinek <jakub@redhat.com>
* sysdeps/unix/sysv/linux/s390/s390-32/sysdep-cancel.h (PSEUDO): Handle
diff --git a/nptl/sysdeps/unix/sysv/linux/pthread_kill.c b/nptl/sysdeps/unix/sysv/linux/pthread_kill.c
index 9115d6f40b..259c954322 100644
--- a/nptl/sysdeps/unix/sysv/linux/pthread_kill.c
+++ b/nptl/sysdeps/unix/sysv/linux/pthread_kill.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -33,7 +33,15 @@ __pthread_kill (threadid, signo)
struct pthread *pd = (struct pthread *) threadid;
/* Make sure the descriptor is valid. */
- if (INVALID_TD_P (pd))
+ if (DEBUGGING_P && INVALID_TD_P (pd))
+ /* Not a valid thread handle. */
+ return ESRCH;
+
+ /* Force load of pd->tid into local variable or register. Oherwise
+ if a thread exits between ESRCH test and tgkill, we might return
+ EINVAL, because pd->tid would be cleared by the kernel. */
+ pid_t tid = atomic_forced_read (pd->tid);
+ if (__builtin_expect (tid <= 0, 0))
/* Not a valid thread handle. */
return ESRCH;
@@ -53,15 +61,15 @@ __pthread_kill (threadid, signo)
int val;
#if __ASSUME_TGKILL
val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
- pd->tid, signo);
+ tid, signo);
#else
# ifdef __NR_tgkill
val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
- pd->tid, signo);
+ tid, signo);
if (INTERNAL_SYSCALL_ERROR_P (val, err)
&& INTERNAL_SYSCALL_ERRNO (val, err) == ENOSYS)
# endif
- val = INTERNAL_SYSCALL (tkill, err, 2, pd->tid, signo);
+ val = INTERNAL_SYSCALL (tkill, err, 2, tid, signo);
#endif
return (INTERNAL_SYSCALL_ERROR_P (val, err)