olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh841653-13.patch

00db10
commit 5aded6f2abbe19bc77e563b7db10aa9dd037a90d
00db10
Author: Andreas Schwab <schwab@suse.de>
00db10
Date:   Wed Jan 13 16:04:42 2016 +0100
00db10
00db10
    Don't do lock elision on an error checking mutex (bug 17514)
00db10
    
00db10
    Error checking mutexes are not supposed to be subject to lock elision.
00db10
    That would defeat the error checking nature of the mutex because lock
00db10
    elision doesn't record ownership.
00db10
Index: glibc-2.17-c758a686/nptl/Makefile
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/nptl/Makefile
00db10
+++ glibc-2.17-c758a686/nptl/Makefile
00db10
@@ -266,7 +266,8 @@ tests = tst-typesizes \
00db10
 	tst-abstime \
00db10
 	tst-vfork1 tst-vfork2 tst-vfork1x tst-vfork2x \
00db10
 	tst-getpid1 tst-getpid2 tst-getpid3 \
00db10
-	tst-initializers1 $(patsubst %,tst-initializers1-%,c89 gnu89 c99 gnu99)
00db10
+	tst-initializers1 $(patsubst %,tst-initializers1-%,c89 gnu89 c99 gnu99) \
00db10
+	tst-mutex-errorcheck
00db10
 xtests = tst-setuid1 tst-setuid1-static tst-mutexpp1 tst-mutexpp6 tst-mutexpp10
00db10
 test-srcs = tst-oddstacklimit
00db10
 
00db10
Index: glibc-2.17-c758a686/nptl/pthread_mutex_timedlock.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/nptl/pthread_mutex_timedlock.c
00db10
+++ glibc-2.17-c758a686/nptl/pthread_mutex_timedlock.c
00db10
@@ -87,7 +87,8 @@ pthread_mutex_timedlock (mutex, abstime)
00db10
       if (__builtin_expect (mutex->__data.__owner == id, 0))
00db10
 	return EDEADLK;
00db10
 
00db10
-      /* FALLTHROUGH */
00db10
+      /* Don't do lock elision on an error checking mutex.  */
00db10
+      goto simple;
00db10
 
00db10
     case PTHREAD_MUTEX_TIMED_NP:
00db10
       FORCE_ELISION (mutex, goto elision);
00db10
Index: glibc-2.17-c758a686/nptl/tst-mutex-errorcheck.c
00db10
===================================================================
00db10
--- /dev/null
00db10
+++ glibc-2.17-c758a686/nptl/tst-mutex-errorcheck.c
00db10
@@ -0,0 +1,61 @@
00db10
+/* Check that error checking mutexes are not subject to lock elision.
00db10
+   Copyright (C) 2016 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#include <stdio.h>
00db10
+#include <errno.h>
00db10
+#include <time.h>
00db10
+#include <pthread.h>
00db10
+
00db10
+static int
00db10
+do_test (void)
00db10
+{
00db10
+  struct timespec tms = { 0 };
00db10
+  pthread_mutex_t mutex;
00db10
+  pthread_mutexattr_t mutexattr;
00db10
+  int ret = 0;
00db10
+
00db10
+  if (pthread_mutexattr_init (&mutexattr) != 0)
00db10
+    return 1;
00db10
+  if (pthread_mutexattr_settype (&mutexattr, PTHREAD_MUTEX_ERRORCHECK) != 0)
00db10
+    return 1;
00db10
+
00db10
+  if (pthread_mutex_init (&mutex, &mutexattr) != 0)
00db10
+    return 1;
00db10
+  if (pthread_mutexattr_destroy (&mutexattr) != 0)
00db10
+    return 1;
00db10
+
00db10
+  /* The call to pthread_mutex_timedlock erroneously enabled lock elision
00db10
+     on the mutex, which then triggered an assertion failure in
00db10
+     pthread_mutex_unlock.  It would also defeat the error checking nature
00db10
+     of the mutex.  */
00db10
+  if (pthread_mutex_timedlock (&mutex, &tms) != 0)
00db10
+    return 1;
00db10
+  if (pthread_mutex_timedlock (&mutex, &tms) != EDEADLK)
00db10
+    {
00db10
+      printf ("Failed error checking on locked mutex\n");
00db10
+      ret = 1;
00db10
+    }
00db10
+
00db10
+  if (pthread_mutex_unlock (&mutex) != 0)
00db10
+    ret = 1;
00db10
+
00db10
+  return ret;
00db10
+}
00db10
+
00db10
+#define TEST_FUNCTION do_test ()
00db10
+#include "../test-skeleton.c"