Blame SOURCES/glibc-rh580498.patch

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