Blame SOURCES/glibc-rh580498.patch

b9ba6d
2010-07-03  Ulrich Drepper  <drepper@redhat.com>
b9ba6d
b9ba6d
	* tst-abstime.c (do_test): Some more cleanups
b9ba6d
b9ba6d
2010-07-02  Ulrich Drepper  <drepper@redhat.com>
b9ba6d
b9ba6d
	* tst-abstime.c: Correct testing and add test for sem_timedwait.
b9ba6d
b9ba6d
2010-07-01  Andreas Schwab  <schwab@redhat.com>
b9ba6d
	    Ulrich Drepper  <drepper@redhat.com>
b9ba6d
b9ba6d
	* Makefile (tests): Add tst-abstime.
b9ba6d
	* tst-abstime.c: New file.
b9ba6d
	* sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
b9ba6d
	(__lll_timedlock_wait): Check for timestamp before the Epoch.
b9ba6d
	* sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
b9ba6d
	(__lll_timedlock_wait): Likewise.
b9ba6d
	* sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
b9ba6d
	(__lll_robust_timedlock_wait): Likewise.
b9ba6d
	* sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
b9ba6d
	(__pthread_cond_timedwait): Likewise.
b9ba6d
	* sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
b9ba6d
	(pthread_rwlock_timedrdlock): Likewise.
b9ba6d
	* sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
b9ba6d
	(pthread_rwlock_timedwrlock): Likewise.
b9ba6d
	* sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S (sem_timedwait):
b9ba6d
	Likewise.
b9ba6d
b9ba6d
Index: glibc-2.12-2-gc4ccff1/nptl/Makefile
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/nptl/Makefile
b9ba6d
+++ glibc-2.12-2-gc4ccff1/nptl/Makefile
b9ba6d
@@ -256,6 +256,7 @@ tests = tst-typesizes \
b9ba6d
 	tst-sched1 \
b9ba6d
 	tst-backtrace1 \
b9ba6d
 	tst-oddstacklimit \
b9ba6d
+	tst-abstime \
b9ba6d
 	tst-vfork1 tst-vfork2 tst-vfork1x tst-vfork2x \
b9ba6d
 	tst-getpid1 tst-getpid2 tst-getpid3 \
b9ba6d
 	tst-initializers1 $(patsubst %,tst-initializers1-%,c89 gnu89 c99 gnu99)
b9ba6d
Index: glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
b9ba6d
+++ glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S
b9ba6d
@@ -188,6 +188,9 @@ __lll_timedlock_wait:
b9ba6d
 	je	.Lreltmo
b9ba6d
 # endif
b9ba6d
 
b9ba6d
+	cmpl	$0, (%edx)
b9ba6d
+	js	8f
b9ba6d
+
b9ba6d
 	movl	%ecx, %ebx
b9ba6d
 	movl	%esi, %ecx
b9ba6d
 	movl	%edx, %esi
b9ba6d
@@ -223,6 +226,9 @@ __lll_timedlock_wait:
b9ba6d
 	cfi_restore(%ebp)
b9ba6d
 	ret
b9ba6d
 
b9ba6d
+8:	movl	$ETIMEDOUT, %eax
b9ba6d
+	jmp	7b
b9ba6d
+
b9ba6d
 # ifndef __ASSUME_FUTEX_CLOCK_REALTIME
b9ba6d
 .Lreltmo:
b9ba6d
 	/* Check for a valid timeout value.  */
b9ba6d
Index: glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
b9ba6d
+++ glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
b9ba6d
@@ -169,9 +169,13 @@ __lll_timedlock_wait:
b9ba6d
 	je	.Lreltmo
b9ba6d
 # endif
b9ba6d
 
b9ba6d
+	cmpq	$0, (%rdx)
b9ba6d
+	js	5f
b9ba6d
+
b9ba6d
 	pushq	%r9
b9ba6d
 	cfi_adjust_cfa_offset(8)
b9ba6d
 	cfi_rel_offset(%r9, 0)
b9ba6d
+
b9ba6d
 	movq	%rdx, %r10
b9ba6d
 	movl	$0xffffffff, %r9d
b9ba6d
 	LOAD_FUTEX_WAIT_ABS (%esi)
b9ba6d
@@ -202,6 +206,9 @@ __lll_timedlock_wait:
b9ba6d
 	cfi_restore(%r9)
b9ba6d
 	retq
b9ba6d
 
b9ba6d
+5:	movl	$ETIMEDOUT, %eax
b9ba6d
+	retq
b9ba6d
+
b9ba6d
 # ifndef __ASSUME_FUTEX_CLOCK_REALTIME
b9ba6d
 .Lreltmo:
b9ba6d
 	/* Check for a valid timeout value.  */
b9ba6d
Index: glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
b9ba6d
+++ glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
b9ba6d
@@ -125,6 +125,9 @@ __lll_robust_timedlock_wait:
b9ba6d
 	je	.Lreltmo
b9ba6d
 # endif
b9ba6d
 
b9ba6d
+	cmpq	$0, (%rdx)
b9ba6d
+	js	7f
b9ba6d
+
b9ba6d
 	pushq	%r9
b9ba6d
 	cfi_adjust_cfa_offset(8)
b9ba6d
 	cfi_rel_offset(%r9, 0)
b9ba6d
@@ -180,6 +183,9 @@ __lll_robust_timedlock_wait:
b9ba6d
 	cfi_adjust_cfa_offset(-8)
b9ba6d
 	cfi_restore(%r9)
b9ba6d
 
b9ba6d
+7:	movl	$ETIMEDOUT, %eax
b9ba6d
+	retq
b9ba6d
+
b9ba6d
 
b9ba6d
 # ifndef __ASSUME_FUTEX_CLOCK_REALTIME
b9ba6d
 .Lreltmo:
b9ba6d
Index: glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
b9ba6d
+++ glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
b9ba6d
@@ -144,6 +144,10 @@ __pthread_cond_timedwait:
b9ba6d
 	movq	%r9, 24(%rsp)
b9ba6d
 	movl	%edx, 4(%rsp)
b9ba6d
 
b9ba6d
+	cmpq	$0, (%r13)
b9ba6d
+	movq	$-ETIMEDOUT, %r14
b9ba6d
+	js	36f
b9ba6d
+
b9ba6d
 38:	movl	cond_futex(%rdi), %r12d
b9ba6d
 
b9ba6d
 	/* Unlock.  */
b9ba6d
Index: glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
b9ba6d
+++ glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
b9ba6d
@@ -102,6 +102,9 @@ pthread_rwlock_timedrdlock:
b9ba6d
 	je	.Lreltmo
b9ba6d
 #endif
b9ba6d
 
b9ba6d
+	cmpq	$0, (%r13)
b9ba6d
+	js	16f		/* Time is already up.  */
b9ba6d
+
b9ba6d
 	movl	$FUTEX_PRIVATE_FLAG|FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, %esi
b9ba6d
 	xorl	PSHARED(%r12), %esi
b9ba6d
 	movq	%r13, %r10
b9ba6d
Index: glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
b9ba6d
+++ glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
b9ba6d
@@ -99,6 +99,9 @@ pthread_rwlock_timedwrlock:
b9ba6d
 	je	.Lreltmo
b9ba6d
 #endif
b9ba6d
 
b9ba6d
+	cmpq	$0, (%r13)
b9ba6d
+	js	16f		/* Time is already up. */
b9ba6d
+
b9ba6d
 	movl	$FUTEX_PRIVATE_FLAG|FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, %esi
b9ba6d
 	xorl	PSHARED(%r12), %esi
b9ba6d
 	movq	%r13, %r10
b9ba6d
Index: glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
b9ba6d
+++ glibc-2.12-2-gc4ccff1/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
b9ba6d
@@ -77,6 +77,9 @@ sem_timedwait:
b9ba6d
 	je	.Lreltmo
b9ba6d
 #endif
b9ba6d
 
b9ba6d
+	cmpq	$0, (%rsi)
b9ba6d
+	js	16f
b9ba6d
+
b9ba6d
 	/* This push is only needed to store the sem_t pointer for the
b9ba6d
 	   exception handler.  */
b9ba6d
 	pushq	%rdi
b9ba6d
@@ -169,6 +172,19 @@ sem_timedwait:
b9ba6d
 
b9ba6d
 	retq
b9ba6d
 
b9ba6d
+16:
b9ba6d
+#if USE___THREAD
b9ba6d
+	movq	errno@gottpoff(%rip), %rdx
b9ba6d
+	movl	$ETIMEDOUT, %fs:(%rdx)
b9ba6d
+#else
b9ba6d
+	callq	__errno_location@plt
b9ba6d
+	movl	$ETIMEDOUT, (%rax)
b9ba6d
+#endif
b9ba6d
+
b9ba6d
+	orl	$-1, %eax
b9ba6d
+
b9ba6d
+	retq
b9ba6d
+
b9ba6d
 #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
b9ba6d
 .Lreltmo:
b9ba6d
 	pushq	%r12
b9ba6d
Index: glibc-2.12-2-gc4ccff1/nptl/tst-abstime.c
b9ba6d
===================================================================
b9ba6d
--- /dev/null
b9ba6d
+++ glibc-2.12-2-gc4ccff1/nptl/tst-abstime.c
b9ba6d
@@ -0,0 +1,98 @@
b9ba6d
+/* Copyright (C) 2010 Free Software Foundation, Inc.
b9ba6d
+   This file is part of the GNU C Library.
b9ba6d
+   Contributed by Andreas Schwab <schwab@redhat.com>, 2010.
b9ba6d
+
b9ba6d
+   The GNU C Library is free software; you can redistribute it and/or
b9ba6d
+   modify it under the terms of the GNU Lesser General Public
b9ba6d
+   License as published by the Free Software Foundation; either
b9ba6d
+   version 2.1 of the License, or (at your option) any later version.
b9ba6d
+
b9ba6d
+   The GNU C Library is distributed in the hope that it will be useful,
b9ba6d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b9ba6d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b9ba6d
+   Lesser General Public License for more details.
b9ba6d
+
b9ba6d
+   You should have received a copy of the GNU Lesser General Public
b9ba6d
+   License along with the GNU C Library; if not, write to the Free
b9ba6d
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
b9ba6d
+   02111-1307 USA.  */
b9ba6d
+
b9ba6d
+#include <errno.h>
b9ba6d
+#include <pthread.h>
b9ba6d
+#include <semaphore.h>
b9ba6d
+#include <stdio.h>
b9ba6d
+
b9ba6d
+static pthread_cond_t c = PTHREAD_COND_INITIALIZER;
b9ba6d
+static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER;
b9ba6d
+static pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER;
b9ba6d
+static pthread_rwlock_t rw1 = PTHREAD_RWLOCK_INITIALIZER;
b9ba6d
+static pthread_rwlock_t rw2 = PTHREAD_RWLOCK_INITIALIZER;
b9ba6d
+static sem_t sem;
b9ba6d
+
b9ba6d
+static void *
b9ba6d
+th (void *arg)
b9ba6d
+{
b9ba6d
+  long int res = 0;
b9ba6d
+  int r;
b9ba6d
+  struct timespec t = { -2, 0 };
b9ba6d
+
b9ba6d
+  r = pthread_mutex_timedlock (&m1, &t);
b9ba6d
+  if (r != ETIMEDOUT)
b9ba6d
+    {
b9ba6d
+      puts ("pthread_mutex_timedlock did not return ETIMEDOUT");
b9ba6d
+      res = 1;
b9ba6d
+    }
b9ba6d
+  r = pthread_rwlock_timedrdlock (&rw1, &t);
b9ba6d
+  if (r != ETIMEDOUT)
b9ba6d
+    {
b9ba6d
+      puts ("pthread_rwlock_timedrdlock did not return ETIMEDOUT");
b9ba6d
+      res = 1;
b9ba6d
+    }
b9ba6d
+  r = pthread_rwlock_timedwrlock (&rw2, &t);
b9ba6d
+  if (r != ETIMEDOUT)
b9ba6d
+    {
b9ba6d
+      puts ("pthread_rwlock_timedwrlock did not return ETIMEDOUT");
b9ba6d
+      res = 1;
b9ba6d
+    }
b9ba6d
+  return (void *) res;
b9ba6d
+}
b9ba6d
+
b9ba6d
+static int
b9ba6d
+do_test (void)
b9ba6d
+{
b9ba6d
+  int res = 0;
b9ba6d
+  int r;
b9ba6d
+  struct timespec t = { -2, 0 };
b9ba6d
+  pthread_t pth;
b9ba6d
+
b9ba6d
+  sem_init (&sem, 0, 0);
b9ba6d
+  r = sem_timedwait (&sem, &t);
b9ba6d
+  if (r != -1 || errno != ETIMEDOUT)
b9ba6d
+    {
b9ba6d
+      puts ("sem_timedwait did not fail with ETIMEDOUT");
b9ba6d
+      res = 1;
b9ba6d
+    }
b9ba6d
+
b9ba6d
+  pthread_mutex_lock (&m1;;
b9ba6d
+  pthread_rwlock_wrlock (&rw1);
b9ba6d
+  pthread_rwlock_rdlock (&rw2);
b9ba6d
+  pthread_mutex_lock (&m2;;
b9ba6d
+  if (pthread_create (&pth, 0, th, 0) != 0)
b9ba6d
+    {
b9ba6d
+      puts ("cannot create thread");
b9ba6d
+      return 1;
b9ba6d
+    }
b9ba6d
+  r = pthread_cond_timedwait (&c, &m2, &t);
b9ba6d
+  if (r != ETIMEDOUT)
b9ba6d
+    {
b9ba6d
+      puts ("pthread_cond_timedwait did not return ETIMEDOUT");
b9ba6d
+      res = 1;
b9ba6d
+    }
b9ba6d
+  void *thres;
b9ba6d
+  pthread_join (pth, &thres);
b9ba6d
+  return res | (thres != NULL);
b9ba6d
+}
b9ba6d
+
b9ba6d
+
b9ba6d
+#define TEST_FUNCTION do_test ()
b9ba6d
+#include "../test-skeleton.c"