public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix __rtld_mrlock_{lock,change}
@ 2006-10-27  8:32 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2006-10-27  8:32 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

__rtld_mrlock_{lock,change} can get into an endless loop.  If lock is
changed between oldval = lock and the atomic compare and swap, the loop
will cycle until something changes lock back to the oldvalue (which doesn't
have to happen ever).  When CAS is unsuccessful, we need to reread oldval,
either from lock directly or better yet from what CAS returned.

2006-10-27  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/rtld-lowlevel.h (__rtld_mrlock_lock,
	__rtld_mrlock_change): Update oldval if atomic compare and exchange
	failed.

--- libc/nptl/sysdeps/unix/sysv/linux/rtld-lowlevel.h.jj	2006-10-19 17:26:40.000000000 +0200
+++ libc/nptl/sysdeps/unix/sysv/linux/rtld-lowlevel.h	2006-10-25 21:36:37.000000000 +0200
@@ -67,6 +67,7 @@ typedef int __rtld_mrlock_t;
 							       oldval);	      \
 		if (__builtin_expect (ret == oldval, 1))		      \
 		  goto out;						      \
+		oldval = ret;						      \
 	      }								      \
 	    atomic_delay ();						      \
 	  }								      \
@@ -112,6 +113,7 @@ typedef int __rtld_mrlock_t;
 							       oldval);	      \
 		if (__builtin_expect (ret == oldval, 1))		      \
 		  goto out;						      \
+		oldval = ret;						      \
 	      }								      \
 	    atomic_delay ();						      \
 	  }								      \

	Jakub

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-10-27  8:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-27  8:32 [PATCH] Fix __rtld_mrlock_{lock,change} Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).