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