This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix __rtld_mrlock_{lock,change}


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]