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


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

GNU C Library master sources branch master updated. glibc-2.24-148-gfbc9949


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  fbc994921b459d57b681a926780933a20745edf5 (commit)
       via  47677f2edc815e85d0383a89b09733e95e5d7302 (commit)
       via  49ad334ab10671dabb40eda8beba887ef902f0f3 (commit)
       via  91dd866ff1801b27e1db1e14a52eb89a213627e6 (commit)
       via  980d25d53e748abd3365aeec0a1ccd1316b4e6d6 (commit)
      from  80d8cb91dee8bdcc4e430b3e2620d95f89b1ee0b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=fbc994921b459d57b681a926780933a20745edf5

commit fbc994921b459d57b681a926780933a20745edf5
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Aug 22 10:31:42 2016 -0300

    rt: Set shm_open as a non cancellation point (BZ #18243)
    
    This patch changes shm_open to not act as a cancellation point.
    Cancellation is disable at start and reenable in function exit.
    It fixes BZ #18243.
    
    Tested on x86_64 and i686.
    
    	[BZ #18243]
    	* rt/Makefile (test): Add tst-shm-cancel.
    	* rt/tst-shm-cancel.c: New file.
    	* sysdeps/posix/shm_open.c: Disable asynchronous cancellation.

diff --git a/ChangeLog b/ChangeLog
index 6225e19..99af3a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
 2016-09-15  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
 	[BZ #18243]
+	* rt/Makefile (test): Add tst-shm-cancel.
+	* rt/tst-shm-cancel.c: New file.
+	* sysdeps/posix/shm_open.c: Disable asynchronous cancellation.
+
+	[BZ #18243]
 	* nptl/pthreadP.h (__pthread_testcancel): Add prototype and hidden_proto.
 	* nptl/pthread_testcancel.c (pthread_cancel): Add internal aliais
 	definition.
diff --git a/rt/Makefile b/rt/Makefile
index cfa6837..7593b11 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -53,7 +53,7 @@ tests := tst-shm tst-clock tst-clock_nanosleep tst-timer tst-timer2 \
 	 tst-timer3 tst-timer4 tst-timer5 \
 	 tst-cpuclock1 tst-cpuclock2 \
 	 tst-cputimer1 tst-cputimer2 tst-cputimer3 \
-	 tst-clock2
+	 tst-clock2 tst-shm-cancel
 
 extra-libs := librt
 extra-libs-others := $(extra-libs)
diff --git a/rt/tst-shm-cancel.c b/rt/tst-shm-cancel.c
new file mode 100644
index 0000000..43d9ee5
--- /dev/null
+++ b/rt/tst-shm-cancel.c
@@ -0,0 +1,130 @@
+/* Test for shm_open cancellation handling: BZ #18243.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <pthread.h>
+#include <sys/mman.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+static sem_t sem;	/* Use to sync with thread start.  */
+static const char shm_name[] = "/glibc-shm_open-cancel";
+
+static void
+remove_shm (int status, void *arg)
+{
+  shm_unlink (shm_name);
+}
+
+static void *
+tf (void *arg)
+{
+  pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, 0);
+
+  if (sem_wait (&sem) != 0)
+    {
+      printf ("error: sem_wait failed: %m");
+      exit (1);
+    }
+
+  if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, 0) != 0)
+    {
+      printf ("error: pthread_setcancelstate failed: %m");
+      exit (1);
+    }
+
+  /* Neither sem_unlink or sem_open should act on thread cancellation.  */
+  shm_unlink (shm_name);
+  on_exit (remove_shm, NULL);
+
+  int fd = shm_open (shm_name, O_CREAT, 0600);
+  if (fd == -1)
+    {
+      int exit_code;
+      if (errno == ENOSYS || errno == EACCES)
+	exit_code = 77;
+      else
+	exit_code = 1;
+      exit (exit_code);
+    }
+
+  if (pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, 0) != 0)
+    {
+      printf ("error: pthread_setcancelstate failed: %m");
+      exit (1);
+    }
+
+  if (close (fd) != 0)
+    {
+      printf ("error: pthread_setcancelstate failed: %m");
+      exit (1);
+    }
+
+  return NULL;
+}
+
+static int
+do_test (void)
+{
+  pthread_t td;
+
+  if (sem_init (&sem, 0, 0))
+    {
+      printf ("error: sem_init failed: %m\n");
+      exit (1);
+    }
+
+  if (pthread_create (&td, NULL, tf, NULL) != 0)
+    {
+      printf ("error: pthread_create failed: %m\n");
+      exit (1);
+    }
+
+  if (pthread_cancel (td) != 0)
+    {
+      printf ("error: pthread_cancel failed: %m\n");
+      exit (1);
+    }
+
+  if (sem_post (&sem) != 0)
+    {
+      printf ("error: sem_post failed: %m\n");
+      exit (1);
+    }
+
+  void *r;
+  if (pthread_join (td, &r) != 0)
+    {
+      printf ("error: pthread_join failed: %m\n");
+      exit (1);
+    }
+
+  if (r == PTHREAD_CANCELED)
+    {
+      puts ("error: pthread_join returned PTHREAD_CANCELED");
+      exit (1);
+    }
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include <test-skeleton.c>
diff --git a/sysdeps/posix/shm_open.c b/sysdeps/posix/shm_open.c
index f296162..0182e7b 100644
--- a/sysdeps/posix/shm_open.c
+++ b/sysdeps/posix/shm_open.c
@@ -40,6 +40,11 @@ shm_open (const char *name, int oflag, mode_t mode)
 # ifdef O_CLOEXEC
   oflag |= O_CLOEXEC;
 # endif
+
+  /* Disable asynchronous cancellation.  */
+  int state;
+  pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &state);
+
   int fd = open (shm_name, oflag, mode);
   if (fd == -1 && __glibc_unlikely (errno == EISDIR))
     /* It might be better to fold this error with EINVAL since
@@ -70,6 +75,8 @@ shm_open (const char *name, int oflag, mode_t mode)
     }
 # endif
 
+  pthread_setcancelstate (state, NULL);
+
   return fd;
 }
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=47677f2edc815e85d0383a89b09733e95e5d7302

commit 47677f2edc815e85d0383a89b09733e95e5d7302
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Mon Aug 22 09:39:46 2016 -0300

    nptl: Fix sem_wait and sem_timedwait cancellation (BZ#18243)
    
    This patch fixes both sem_wait and sem_timedwait cancellation point for
    uncontended case.  In this scenario only atomics are involved and thus
    the futex cancellable call is not issue and a pending cancellation signal
    is not handled.
    
    The fix is straighforward by calling pthread_testcancel is both function
    start.  Although it would be simpler to call CANCELLATION_P directly, I
    decided to add an internal pthread_testcancel alias and use it to export
    less internal implementation on such function.  A possible change on
    how pthread_testcancel is internally implemented would lead to either
    continue to force use CANCELLATION_P or to adjust its every use.
    
    GLIBC testcase also does have tests for uncontended cases, test-cancel12
    and test-cancel14.c,  however both are flawed by adding another
    cancellation point just after thread pthread_cleanup_pop:
    
     47 static void *
     48 tf (void *arg)
     49 {
     50   pthread_cleanup_push (cleanup, NULL);
     51
     52   int e = pthread_barrier_wait (&bar);
     53   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
     54     {
     55       puts ("tf: 1st barrier_wait failed");
     56       exit (1);
     57     }
     58
     59   /* This call should block and be cancelable.  */
     60   sem_wait (&sem);
     61
     62   pthread_cleanup_pop (0);
     63
     64   puts ("sem_wait returned");
     65
     66   return NULL;
     67 }
    
    So sem_{timed}wait does not act on cancellation, pthread_cleanup_pop executes
    'cleanup' and then 'puts' acts on cancellation.  Since pthread_cleanup_pop
    removed the clean-up handler, it will ran only once and thus it won't accuse
    an error to indicate sem_wait has not acted on the cancellation signal.
    
    This patch also fixes this behavior by removing the cancellation point 'puts'.
    It also adds some cleanup on all sem_{timed}wait cancel tests.
    
    It partially fixes BZ #18243.  Checked on x86_64.
    
    	[BZ #18243]
    	* nptl/pthreadP.h (__pthread_testcancel): Add prototype and hidden_proto.
    	* nptl/pthread_testcancel.c (pthread_cancel): Add internal aliais
    	definition.
    	* nptl/sem_timedwait.c (sem_timedwait): Add cancellation check for
    	uncontended case.
    	* nptl/sem_wait.c (__new_sem_wait): Likewise.
    	* nptl/tst-cancel12.c (cleanup): Remove wrong cancellation point.
    	(tf): Fix check for uncontended case.
    	(do_test): Likewise.
    	* nptl/tst-cancel13.c (cleanup): Remove wrong cancellation point.
    	(tf): Fix check for uncontended case.
    	(do_test): Likewise.
    	* nptl/tst-cancel14.c (cleanup): Remove wrong cancellation point.
    	(tf): Fix check for uncontended case.
    	(do_test): Likewise.
    	* nptl/tst-cancel15.c (cleanup): Remove wrong cancellation point.
    	(tf): Fix check for uncontended case.
    	(do_test): Likewise.

diff --git a/ChangeLog b/ChangeLog
index 065adb5..6225e19 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,25 @@
 2016-09-15  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	[BZ #18243]
+	* nptl/pthreadP.h (__pthread_testcancel): Add prototype and hidden_proto.
+	* nptl/pthread_testcancel.c (pthread_cancel): Add internal aliais
+	definition.
+	* nptl/sem_timedwait.c (sem_timedwait): Add cancellation check for
+	uncontended case.
+	* nptl/sem_wait.c (__new_sem_wait): Likewise.
+	* nptl/tst-cancel12.c (cleanup): Remove wrong cancellation point.
+	(tf): Fix check for uncontended case.
+	(do_test): Likewise.
+	* nptl/tst-cancel13.c (cleanup): Remove wrong cancellation point.
+	(tf): Fix check for uncontended case.
+	(do_test): Likewise.
+	* nptl/tst-cancel14.c (cleanup): Remove wrong cancellation point.
+	(tf): Fix check for uncontended case.
+	(do_test): Likewise.
+	* nptl/tst-cancel15.c (cleanup): Remove wrong cancellation point.
+	(tf): Fix check for uncontended case.
+	(do_test): Likewise.
+
 	* sysdeps/sparc/sparc32/sem_wait.c: Remove file.
 	* sysdeps/sparc/sparc32/sparcv9/sem_wait.c: Likewise.
 
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 4edc74b..6e0dd09 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -491,6 +491,7 @@ extern int __pthread_setcanceltype (int type, int *oldtype);
 extern int __pthread_enable_asynccancel (void) attribute_hidden;
 extern void __pthread_disable_asynccancel (int oldtype)
      internal_function attribute_hidden;
+extern void __pthread_testcancel (void);
 
 #if IS_IN (libpthread)
 hidden_proto (__pthread_mutex_init)
@@ -505,6 +506,7 @@ hidden_proto (__pthread_getspecific)
 hidden_proto (__pthread_setspecific)
 hidden_proto (__pthread_once)
 hidden_proto (__pthread_setcancelstate)
+hidden_proto (__pthread_testcancel)
 #endif
 
 extern int __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond);
diff --git a/nptl/pthread_testcancel.c b/nptl/pthread_testcancel.c
index 51be09f..fdef699 100644
--- a/nptl/pthread_testcancel.c
+++ b/nptl/pthread_testcancel.c
@@ -21,7 +21,9 @@
 
 
 void
-pthread_testcancel (void)
+__pthread_testcancel (void)
 {
   CANCELLATION_P (THREAD_SELF);
 }
+strong_alias (__pthread_testcancel, pthread_testcancel)
+hidden_def (__pthread_testcancel)
diff --git a/nptl/sem_timedwait.c b/nptl/sem_timedwait.c
index 1aab25a..a02e178 100644
--- a/nptl/sem_timedwait.c
+++ b/nptl/sem_timedwait.c
@@ -30,6 +30,9 @@ sem_timedwait (sem_t *sem, const struct timespec *abstime)
       return -1;
     }
 
+  /* Check sem_wait.c for a more detailed explanation why it is required.  */
+  __pthread_testcancel ();
+
   if (__new_sem_wait_fast ((struct new_sem *) sem, 0) == 0)
     return 0;
   else
diff --git a/nptl/sem_wait.c b/nptl/sem_wait.c
index 84b523a..b242c08 100644
--- a/nptl/sem_wait.c
+++ b/nptl/sem_wait.c
@@ -23,6 +23,19 @@
 int
 __new_sem_wait (sem_t *sem)
 {
+  /* We need to check whether we need to act upon a cancellation request here
+     because POSIX specifies that cancellation points "shall occur" in
+     sem_wait and sem_timedwait, which also means that they need to check
+     this regardless whether they block or not (unlike "may occur"
+     functions).  See the POSIX Rationale for this requirement: Section
+     "Thread Cancellation Overview" [1] and austin group issue #1076 [2]
+     for thoughs on why this may be a suboptimal design.
+
+     [1] http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html
+     [2] http://austingroupbugs.net/view.php?id=1076 for thoughts on why this
+   */
+  __pthread_testcancel ();
+
   if (__new_sem_wait_fast ((struct new_sem *) sem, 0) == 0)
     return 0;
   else
diff --git a/nptl/tst-cancel12.c b/nptl/tst-cancel12.c
index ac8f5a0..a720ccf 100644
--- a/nptl/tst-cancel12.c
+++ b/nptl/tst-cancel12.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2003-2016 Free Software Foundation, Inc.
+/* Test sem_wait cancellation for uncontended case.
+   Copyright (C) 2003-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
 
@@ -39,8 +40,6 @@ cleanup (void *arg)
       puts ("second call to cleanup");
       exit (1);
     }
-
-  printf ("cleanup call #%d\n", ncall);
 }
 
 
@@ -52,17 +51,15 @@ tf (void *arg)
   int e = pthread_barrier_wait (&bar);
   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
     {
-      puts ("tf: 1st barrier_wait failed");
+      puts ("error: tf: 1st barrier_wait failed");
       exit (1);
     }
 
-  /* This call should block and be cancelable.  */
+  /* This call should be cancelable.  */
   sem_wait (&sem);
 
   pthread_cleanup_pop (0);
 
-  puts ("sem_wait returned");
-
   return NULL;
 }
 
@@ -74,47 +71,47 @@ do_test (void)
 
   if (pthread_barrier_init (&bar, NULL, 2) != 0)
     {
-      puts ("barrier_init failed");
+      puts ("error: barrier_init failed");
       exit (1);
     }
 
+  /* A value higher than 0 will check for uncontended pthread cancellation,
+     where the sem_wait operation will return immediatelly.  */
   if (sem_init (&sem, 0, 1) != 0)
     {
-      puts ("sem_init failed");
+      puts ("error: sem_init failed");
       exit (1);
     }
 
   if (pthread_create (&th, NULL, tf, NULL) != 0)
     {
-      puts ("create failed");
+      puts ("error: create failed");
       exit (1);
     }
 
-  /* Check whether cancellation is honored even before sem_wait does
-     anything.  */
   if (pthread_cancel (th) != 0)
     {
-      puts ("1st cancel failed");
+      puts ("error: pthread_cancel failed");
       exit (1);
     }
 
   int e = pthread_barrier_wait (&bar);
   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
     {
-      puts ("1st barrier_wait failed");
+      puts ("error: 1st barrier_wait failed");
       exit (1);
     }
 
   void *r;
   if (pthread_join (th, &r) != 0)
     {
-      puts ("join failed");
+      puts ("error: pthread_join failed");
       exit (1);
     }
 
   if (r != PTHREAD_CANCELED)
     {
-      puts ("thread not canceled");
+      puts ("error: thread not canceled");
       exit (1);
     }
 
diff --git a/nptl/tst-cancel13.c b/nptl/tst-cancel13.c
index c84780d..ee39b96 100644
--- a/nptl/tst-cancel13.c
+++ b/nptl/tst-cancel13.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2003-2016 Free Software Foundation, Inc.
+/* Test sem_wait cancellation for contended case.
+   Copyright (C) 2003-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
 
@@ -39,8 +40,6 @@ cleanup (void *arg)
       puts ("second call to cleanup");
       exit (1);
     }
-
-  printf ("cleanup call #%d\n", ncall);
 }
 
 
@@ -52,7 +51,7 @@ tf (void *arg)
   int e = pthread_barrier_wait (&bar);
   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
     {
-      puts ("tf: 1st barrier_wait failed");
+      puts ("error: tf: 1st barrier_wait failed");
       exit (1);
     }
 
@@ -61,8 +60,6 @@ tf (void *arg)
 
   pthread_cleanup_pop (0);
 
-  puts ("sem_wait returned");
-
   return NULL;
 }
 
@@ -74,26 +71,28 @@ do_test (void)
 
   if (pthread_barrier_init (&bar, NULL, 2) != 0)
     {
-      puts ("barrier_init failed");
+      puts ("error: barrier_init failed");
       exit (1);
     }
 
+  /* A value equal to 0 will check for contended pthread cancellation,
+     where the sem_wait operation will block.  */
   if (sem_init (&sem, 0, 0) != 0)
     {
-      puts ("sem_init failed");
+      puts ("error: sem_init failed");
       exit (1);
     }
 
   if (pthread_create (&th, NULL, tf, NULL) != 0)
     {
-      puts ("create failed");
+      puts ("error: create failed");
       exit (1);
     }
 
   int e = pthread_barrier_wait (&bar);
   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
     {
-      puts ("1st barrier_wait failed");
+      puts ("error: 1st barrier_wait failed");
       exit (1);
     }
 
@@ -103,14 +102,14 @@ do_test (void)
   /* Check whether cancellation is honored when waiting in sem_wait.  */
   if (pthread_cancel (th) != 0)
     {
-      puts ("1st cancel failed");
+      puts ("error: 1st cancel failed");
       exit (1);
     }
 
   void *r;
   if (pthread_join (th, &r) != 0)
     {
-      puts ("join failed");
+      puts ("error: join failed");
       exit (1);
     }
 
diff --git a/nptl/tst-cancel14.c b/nptl/tst-cancel14.c
index 3810d2b..b6fcbb7 100644
--- a/nptl/tst-cancel14.c
+++ b/nptl/tst-cancel14.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2003-2016 Free Software Foundation, Inc.
+/* Test sem_timedwait cancellation for uncontended case.
+   Copyright (C) 2003-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
 
@@ -40,8 +41,6 @@ cleanup (void *arg)
       puts ("second call to cleanup");
       exit (1);
     }
-
-  printf ("cleanup call #%d\n", ncall);
 }
 
 
@@ -53,7 +52,7 @@ tf (void *arg)
   int e = pthread_barrier_wait (&bar);
   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
     {
-      puts ("tf: 1st barrier_wait failed");
+      puts ("error: tf: 1st barrier_wait failed");
       exit (1);
     }
 
@@ -71,8 +70,6 @@ tf (void *arg)
 
   pthread_cleanup_pop (0);
 
-  puts ("sem_timedwait returned");
-
   return NULL;
 }
 
@@ -84,19 +81,19 @@ do_test (void)
 
   if (pthread_barrier_init (&bar, NULL, 2) != 0)
     {
-      puts ("barrier_init failed");
+      puts ("error: barrier_init failed");
       exit (1);
     }
 
   if (sem_init (&sem, 0, 1) != 0)
     {
-      puts ("sem_init failed");
+      puts ("error: sem_init failed");
       exit (1);
     }
 
   if (pthread_create (&th, NULL, tf, NULL) != 0)
     {
-      puts ("create failed");
+      puts ("error: create failed");
       exit (1);
     }
 
@@ -104,7 +101,7 @@ do_test (void)
      anything.  */
   if (pthread_cancel (th) != 0)
     {
-      puts ("1st cancel failed");
+      puts ("error: 1st cancel failed");
       exit (1);
     }
 
diff --git a/nptl/tst-cancel15.c b/nptl/tst-cancel15.c
index f413839..c8db3e4 100644
--- a/nptl/tst-cancel15.c
+++ b/nptl/tst-cancel15.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 2003-2016 Free Software Foundation, Inc.
+/* Test sem_timedwait cancellation for contended case.
+   Copyright (C) 2003-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
 
@@ -40,8 +41,6 @@ cleanup (void *arg)
       puts ("second call to cleanup");
       exit (1);
     }
-
-  printf ("cleanup call #%d\n", ncall);
 }
 
 
@@ -55,7 +54,7 @@ tf (void *arg)
   e = pthread_barrier_wait (&bar);
   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
     {
-      puts ("tf: 1st barrier_wait failed");
+      puts ("error: tf: 1st barrier_wait failed");
       exit (1);
     }
 
@@ -74,8 +73,6 @@ tf (void *arg)
 
   pthread_cleanup_pop (0);
 
-  printf ("sem_timedwait returned, e = %d, errno = %d\n", e, errno);
-
   return NULL;
 }
 
@@ -87,26 +84,26 @@ do_test (void)
 
   if (pthread_barrier_init (&bar, NULL, 2) != 0)
     {
-      puts ("barrier_init failed");
+      puts ("error: barrier_init failed");
       exit (1);
     }
 
   if (sem_init (&sem, 0, 0) != 0)
     {
-      puts ("sem_init failed");
+      puts ("error: sem_init failed");
       exit (1);
     }
 
   if (pthread_create (&th, NULL, tf, NULL) != 0)
     {
-      puts ("create failed");
+      puts ("error: create failed");
       exit (1);
     }
 
   int e = pthread_barrier_wait (&bar);
   if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD)
     {
-      puts ("1st barrier_wait failed");
+      puts ("error: 1st barrier_wait failed");
       exit (1);
     }
 
@@ -116,20 +113,20 @@ do_test (void)
   /* Check whether cancellation is honored when waiting in sem_timedwait.  */
   if (pthread_cancel (th) != 0)
     {
-      puts ("1st cancel failed");
+      puts ("error: 1st cancel failed");
       exit (1);
     }
 
   void *r;
   if (pthread_join (th, &r) != 0)
     {
-      puts ("join failed");
+      puts ("error: join failed");
       exit (1);
     }
 
   if (r != PTHREAD_CANCELED)
     {
-      puts ("thread not canceled");
+      puts ("error: thread not canceled");
       exit (1);
     }
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=49ad334ab10671dabb40eda8beba887ef902f0f3

commit 49ad334ab10671dabb40eda8beba887ef902f0f3
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Sun Aug 21 17:14:35 2016 -0300

    nptl: Remove sparc sem_wait
    
    This patch removes the sparc32 sem_wait.c implementation since it is
    identical to default nptl one.  The sparcv9 is no longer required with
    the removal.
    
    Checked with a sparcv9 build.
    
    	* sysdeps/sparc/sparc32/sem_wait.c: Remove file.
    	* sysdeps/sparc/sparc32/sparcv9/sem_wait.c: Likewise.

diff --git a/ChangeLog b/ChangeLog
index 1d3bc50..065adb5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2016-09-15  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	* sysdeps/sparc/sparc32/sem_wait.c: Remove file.
+	* sysdeps/sparc/sparc32/sparcv9/sem_wait.c: Likewise.
+
 	[BZ #15765]
 	* nptl/Makefile (tests): Add tst-sem16.
 	* nptl/tst-sem16.c: New file.
diff --git a/sysdeps/sparc/sparc32/sem_wait.c b/sysdeps/sparc/sparc32/sem_wait.c
deleted file mode 100644
index 84b523a..0000000
--- a/sysdeps/sparc/sparc32/sem_wait.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/* sem_wait -- wait on a semaphore.  Generic futex-using version.
-   Copyright (C) 2003-2016 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Paul Mackerras <paulus@au.ibm.com>, 2003.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <lowlevellock.h>	/* lll_futex* used by the old code.  */
-#include "sem_waitcommon.c"
-
-int
-__new_sem_wait (sem_t *sem)
-{
-  if (__new_sem_wait_fast ((struct new_sem *) sem, 0) == 0)
-    return 0;
-  else
-    return __new_sem_wait_slow((struct new_sem *) sem, NULL);
-}
-versioned_symbol (libpthread, __new_sem_wait, sem_wait, GLIBC_2_1);
-
-#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
-int
-attribute_compat_text_section
-__old_sem_wait (sem_t *sem)
-{
-  int *futex = (int *) sem;
-  int err;
-
-  do
-    {
-      if (atomic_decrement_if_positive (futex) > 0)
-	return 0;
-
-      /* Enable asynchronous cancellation.  Required by the standard.  */
-      int oldtype = __pthread_enable_asynccancel ();
-
-      /* Always assume the semaphore is shared.  */
-      err = lll_futex_wait (futex, 0, LLL_SHARED);
-
-      /* Disable asynchronous cancellation.  */
-      __pthread_disable_asynccancel (oldtype);
-    }
-  while (err == 0 || err == -EWOULDBLOCK);
-
-  __set_errno (-err);
-  return -1;
-}
-
-compat_symbol (libpthread, __old_sem_wait, sem_wait, GLIBC_2_0);
-#endif
-
-int
-__new_sem_trywait (sem_t *sem)
-{
-  /* We must not fail spuriously, so require a definitive result even if this
-     may lead to a long execution time.  */
-  if (__new_sem_wait_fast ((struct new_sem *) sem, 1) == 0)
-    return 0;
-  __set_errno (EAGAIN);
-  return -1;
-}
-versioned_symbol (libpthread, __new_sem_trywait, sem_trywait, GLIBC_2_1);
-#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1)
-int
-__old_sem_trywait (sem_t *sem)
-{
-  int *futex = (int *) sem;
-  int val;
-
-  if (*futex > 0)
-    {
-      val = atomic_decrement_if_positive (futex);
-      if (val > 0)
-	return 0;
-    }
-
-  __set_errno (EAGAIN);
-  return -1;
-}
-compat_symbol (libpthread, __old_sem_trywait, sem_trywait, GLIBC_2_0);
-#endif
diff --git a/sysdeps/sparc/sparc32/sparcv9/sem_wait.c b/sysdeps/sparc/sparc32/sparcv9/sem_wait.c
deleted file mode 100644
index bccdaed..0000000
--- a/sysdeps/sparc/sparc32/sparcv9/sem_wait.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <nptl/sem_wait.c>

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=91dd866ff1801b27e1db1e14a52eb89a213627e6

commit 91dd866ff1801b27e1db1e14a52eb89a213627e6
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Sat Aug 20 11:23:08 2016 -0300

    nptl: Set sem_open as a non cancellation point (BZ #15765)
    
    This patch changes sem_open to not act as a cancellation point.
    Cancellation is disable at start and reenable in function exit.
    It fixes BZ #15765.
    
    Tested on x86_64 and i686.
    
    	[BZ #15765]
    	* nptl/Makefile (tests): Add tst-sem16.
    	* nptl/tst-sem16.c: New file.
    	* nptl/sem_open.c (sem_open): Disable asynchronous cancellation.

diff --git a/ChangeLog b/ChangeLog
index 6ad743a..1d3bc50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2016-09-15  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+	[BZ #15765]
+	* nptl/Makefile (tests): Add tst-sem16.
+	* nptl/tst-sem16.c: New file.
+	* nptl/sem_open.c (sem_open): Disable asynchronous cancellation.
+
 	* nptl/sem_open.c (sem_open): Init pad value to 0.
 	* sysdeps/sparc/sparc32/sem_open.c: Remove file.
 	* sysdeps/sparc/sparc32/sparcv9/sem_open.c: Likewise.
diff --git a/nptl/Makefile b/nptl/Makefile
index e8de1bc..e9485df 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -246,7 +246,7 @@ tests = tst-typesizes \
 	tst-key1 tst-key2 tst-key3 tst-key4 \
 	tst-sem1 tst-sem2 tst-sem3 tst-sem4 tst-sem5 tst-sem6 tst-sem7 \
 	tst-sem8 tst-sem9 tst-sem10 tst-sem11 tst-sem12 tst-sem13 tst-sem14 \
-	tst-sem15 \
+	tst-sem15 tst-sem16 \
 	tst-barrier1 tst-barrier2 tst-barrier3 tst-barrier4 tst-barrier5 \
 	tst-align tst-align3 \
 	tst-basic1 tst-basic2 tst-basic3 tst-basic4 tst-basic5 tst-basic6 \
diff --git a/nptl/sem_open.c b/nptl/sem_open.c
index 5b45fad..d108286 100644
--- a/nptl/sem_open.c
+++ b/nptl/sem_open.c
@@ -31,7 +31,7 @@
 #include "semaphoreP.h"
 #include <shm-directory.h>
 #include <futex-internal.h>
-
+#include <libc-lock.h>
 
 /* Comparison function for search of existing mapping.  */
 int
@@ -153,6 +153,13 @@ sem_open (const char *name, int oflag, ...)
   /* Create the name of the final file in local variable SHM_NAME.  */
   SHM_GET_NAME (EINVAL, SEM_FAILED, SEM_SHM_PREFIX);
 
+  /* Disable asynchronous cancellation.  */
+#ifdef __libc_ptf_call
+  int state;
+  __libc_ptf_call (__pthread_setcancelstate,
+                   (PTHREAD_CANCEL_DISABLE, &state), 0);
+#endif
+
   /* If the semaphore object has to exist simply open it.  */
   if ((oflag & O_CREAT) == 0 || (oflag & O_EXCL) == 0)
     {
@@ -193,7 +200,8 @@ sem_open (const char *name, int oflag, ...)
       if (value > SEM_VALUE_MAX)
 	{
 	  __set_errno (EINVAL);
-	  return SEM_FAILED;
+	  result = SEM_FAILED;
+	  goto out;
 	}
 
       /* Create the initial file content.  */
@@ -233,7 +241,10 @@ sem_open (const char *name, int oflag, ...)
 	     mode cannot later be set since then we cannot apply the
 	     file create mask.  */
 	  if (__mktemp (tmpfname) == NULL)
-	    return SEM_FAILED;
+	    {
+	      result = SEM_FAILED;
+	      goto out;
+	    }
 
 	  /* Open the file.  Make sure we do not overwrite anything.  */
 	  fd = __libc_open (tmpfname, O_RDWR | O_CREAT | O_EXCL, mode);
@@ -247,7 +258,8 @@ sem_open (const char *name, int oflag, ...)
 		  __set_errno (EAGAIN);
 		}
 
-	      return SEM_FAILED;
+	      result = SEM_FAILED;
+	      goto out;
 	    }
 
 	  /* We got a file.  */
@@ -308,5 +320,10 @@ sem_open (const char *name, int oflag, ...)
       errno = save;
     }
 
+out:
+#ifdef __libc_ptf_call
+  __libc_ptf_call (__pthread_setcancelstate, (state, NULL), 0);
+#endif
+
   return result;
 }
diff --git a/nptl/tst-sem16.c b/nptl/tst-sem16.c
new file mode 100644
index 0000000..7006754
--- /dev/null
+++ b/nptl/tst-sem16.c
@@ -0,0 +1,130 @@
+/* Test for sem_open cancellation handling: BZ #15765.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <pthread.h>
+#include <sys/mman.h>
+#include <semaphore.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+
+static sem_t sem;	/* Use to sync with thread start.  */
+static const char pipe_name[] = "/glibc-tst-sem16";
+
+static void
+remove_sem (int status, void *arg)
+{
+  sem_unlink (arg);
+}
+
+static void *
+tf (void *arg)
+{
+  pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, 0);
+
+  if (sem_wait (&sem) != 0)
+    {
+      printf ("error: sem_wait failed: %m");
+      exit (1);
+    }
+
+  if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, 0) != 0)
+    {
+      printf ("error: pthread_setcancelstate failed: %m");
+      exit (1);
+    }
+
+  /* Neither sem_unlink or sem_open should act on thread cancellation.  */
+  sem_unlink (pipe_name);
+  on_exit (remove_sem, (void *) pipe_name);
+
+  sem_t *s = sem_open (pipe_name, O_CREAT, 0600, 1);
+  if (s == SEM_FAILED)
+    {
+      int exit_code;
+      if (errno == ENOSYS || errno == EACCES)
+	exit_code = 77;
+      else
+	exit_code = 1;
+      exit (exit_code);
+    }
+
+  if (pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, 0) != 0)
+    {
+      printf ("error: pthread_setcancelstate failed: %m");
+      exit (1);
+    }
+
+  if (sem_close (s) != 0)
+    {
+      printf ("error: sem_close failed: %m");
+      exit (1);
+    }
+
+  return NULL;
+}
+
+static int
+do_test (void)
+{
+  pthread_t td;
+
+  if (sem_init (&sem, 0, 0))
+    {
+      printf ("error: sem_init failed: %m\n");
+      exit (1);
+    }
+
+  if (pthread_create (&td, NULL, tf, NULL) != 0)
+    {
+      printf ("error: pthread_create failed: %m\n");
+      exit (1);
+    }
+
+  if (pthread_cancel (td) != 0)
+    {
+      printf ("error: pthread_cancel failed: %m\n");
+      exit (1);
+    }
+
+  if (sem_post (&sem) != 0)
+    {
+      printf ("error: sem_post failed: %m\n");
+      exit (1);
+    }
+
+  void *r;
+  if (pthread_join (td, &r) != 0)
+    {
+      printf ("error: pthread_join failed: %m\n");
+      exit (1);
+    }
+
+  if (r == PTHREAD_CANCELED)
+    {
+      puts ("error: pthread_join returned PTHREAD_CANCELED");
+      exit (1);
+    }
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include <test-skeleton.c>

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=980d25d53e748abd3365aeec0a1ccd1316b4e6d6

commit 980d25d53e748abd3365aeec0a1ccd1316b4e6d6
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Fri Aug 19 15:30:01 2016 -0300

    nptl: Consolidate sem_open implementations
    
    Current sparc32 sem_open and default one only differ on:
    
      1. Default one contains a 'futex_supports_pshared' check.
      2. sem.newsem.pad is initialized to zero.
    
    This patch removes sparc32 and sparc32v9 sem_open arch specific
    implementation and instead set sparc32 to use nptl default one.
    Using 1. is fine since it should always evaluate 0 for Linux
    (an optimized away by the compiler). Adding 2. to default
    implementation should be ok since 'pad' field is used mainly
    on sparc32 code.
    
    I checked on i686 and checked a sparc32v9 build.
    
    	* nptl/sem_open.c (sem_open): Init pad value to 0.
    	* sysdeps/sparc/sparc32/sem_open.c: Remove file.
    	* sysdeps/sparc/sparc32/sparcv9/sem_open.c: Likewise.

diff --git a/ChangeLog b/ChangeLog
index 9845c66..6ad743a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-09-15  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+	* nptl/sem_open.c (sem_open): Init pad value to 0.
+	* sysdeps/sparc/sparc32/sem_open.c: Remove file.
+	* sysdeps/sparc/sparc32/sparcv9/sem_open.c: Likewise.
+
 2016-09-15  Florian Weimer  <fweimer@redhat.com>
 
 	[BZ #20611]
diff --git a/nptl/sem_open.c b/nptl/sem_open.c
index 911b1f3..5b45fad 100644
--- a/nptl/sem_open.c
+++ b/nptl/sem_open.c
@@ -207,6 +207,8 @@ sem_open (const char *name, int oflag, ...)
       sem.newsem.data = value;
 #else
       sem.newsem.value = value << SEM_VALUE_SHIFT;
+      /* pad is used as a mutex on pre-v9 sparc and ignored otherwise.  */
+      sem.newsem.pad = 0;
       sem.newsem.nwaiters = 0;
 #endif
       /* This always is a shared semaphore.  */
diff --git a/sysdeps/sparc/sparc32/sem_open.c b/sysdeps/sparc/sparc32/sem_open.c
deleted file mode 100644
index 57796bd..0000000
--- a/sysdeps/sparc/sparc32/sem_open.c
+++ /dev/null
@@ -1,300 +0,0 @@
-/* Copyright (C) 2002-2016 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <errno.h>
-#include <fcntl.h>
-#include <pthread.h>
-#include <search.h>
-#include <semaphore.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include "semaphoreP.h"
-#include <futex-internal.h>
-#include <shm-directory.h>
-
-
-/* Comparison function for search of existing mapping.  */
-int
-attribute_hidden
-__sem_search (const void *a, const void *b)
-{
-  const struct inuse_sem *as = (const struct inuse_sem *) a;
-  const struct inuse_sem *bs = (const struct inuse_sem *) b;
-
-  if (as->ino != bs->ino)
-    /* Cannot return the difference the type is larger than int.  */
-    return as->ino < bs->ino ? -1 : (as->ino == bs->ino ? 0 : 1);
-
-  if (as->dev != bs->dev)
-    /* Cannot return the difference the type is larger than int.  */
-    return as->dev < bs->dev ? -1 : (as->dev == bs->dev ? 0 : 1);
-
-  return strcmp (as->name, bs->name);
-}
-
-
-/* The search tree for existing mappings.  */
-void *__sem_mappings attribute_hidden;
-
-/* Lock to protect the search tree.  */
-int __sem_mappings_lock attribute_hidden = LLL_LOCK_INITIALIZER;
-
-
-/* Search for existing mapping and if possible add the one provided.  */
-static sem_t *
-check_add_mapping (const char *name, size_t namelen, int fd, sem_t *existing)
-{
-  sem_t *result = SEM_FAILED;
-
-  /* Get the information about the file.  */
-  struct stat64 st;
-  if (__fxstat64 (_STAT_VER, fd, &st) == 0)
-    {
-      /* Get the lock.  */
-      lll_lock (__sem_mappings_lock, LLL_PRIVATE);
-
-      /* Search for an existing mapping given the information we have.  */
-      struct inuse_sem *fake;
-      fake = (struct inuse_sem *) alloca (sizeof (*fake) + namelen);
-      memcpy (fake->name, name, namelen);
-      fake->dev = st.st_dev;
-      fake->ino = st.st_ino;
-
-      struct inuse_sem **foundp = __tfind (fake, &__sem_mappings,
-					   __sem_search);
-      if (foundp != NULL)
-	{
-	  /* There is already a mapping.  Use it.  */
-	  result = (*foundp)->sem;
-	  ++(*foundp)->refcnt;
-	}
-      else
-	{
-	  /* We haven't found a mapping.  Install ione.  */
-	  struct inuse_sem *newp;
-
-	  newp = (struct inuse_sem *) malloc (sizeof (*newp) + namelen);
-	  if (newp != NULL)
-	    {
-	      /* If the caller hasn't provided any map it now.  */
-	      if (existing == SEM_FAILED)
-		existing = (sem_t *) mmap (NULL, sizeof (sem_t),
-					   PROT_READ | PROT_WRITE, MAP_SHARED,
-					   fd, 0);
-
-	      newp->dev = st.st_dev;
-	      newp->ino = st.st_ino;
-	      newp->refcnt = 1;
-	      newp->sem = existing;
-	      memcpy (newp->name, name, namelen);
-
-	      /* Insert the new value.  */
-	      if (existing != MAP_FAILED
-		  && __tsearch (newp, &__sem_mappings, __sem_search) != NULL)
-		/* Successful.  */
-		result = existing;
-	      else
-		/* Something went wrong while inserting the new
-		   value.  We fail completely.  */
-		free (newp);
-	    }
-	}
-
-      /* Release the lock.  */
-      lll_unlock (__sem_mappings_lock, LLL_PRIVATE);
-    }
-
-  if (result != existing && existing != SEM_FAILED && existing != MAP_FAILED)
-    {
-      /* Do not disturb errno.  */
-      int save = errno;
-      munmap (existing, sizeof (sem_t));
-      errno = save;
-    }
-
-  return result;
-}
-
-
-sem_t *
-sem_open (const char *name, int oflag, ...)
-{
-  int fd;
-  sem_t *result;
-
-  /* Create the name of the final file in local variable SHM_NAME.  */
-  SHM_GET_NAME (EINVAL, SEM_FAILED, SEM_SHM_PREFIX);
-
-  /* If the semaphore object has to exist simply open it.  */
-  if ((oflag & O_CREAT) == 0 || (oflag & O_EXCL) == 0)
-    {
-    try_again:
-      fd = __libc_open (shm_name,
-			(oflag & ~(O_CREAT|O_ACCMODE)) | O_NOFOLLOW | O_RDWR);
-
-      if (fd == -1)
-	{
-	  /* If we are supposed to create the file try this next.  */
-	  if ((oflag & O_CREAT) != 0 && errno == ENOENT)
-	    goto try_create;
-
-	  /* Return.  errno is already set.  */
-	}
-      else
-	/* Check whether we already have this semaphore mapped and
-	   create one if necessary.  */
-	result = check_add_mapping (name, namelen, fd, SEM_FAILED);
-    }
-  else
-    {
-      /* We have to open a temporary file first since it must have the
-	 correct form before we can start using it.  */
-      char *tmpfname;
-      mode_t mode;
-      unsigned int value;
-      va_list ap;
-
-    try_create:
-      va_start (ap, oflag);
-
-      mode = va_arg (ap, mode_t);
-      value = va_arg (ap, unsigned int);
-
-      va_end (ap);
-
-      if (value > SEM_VALUE_MAX)
-	{
-	  __set_errno (EINVAL);
-	  return SEM_FAILED;
-	}
-
-      /* Create the initial file content.  */
-      union
-      {
-	sem_t initsem;
-	struct new_sem newsem;
-      } sem;
-
-      sem.newsem.value = value << SEM_VALUE_SHIFT;
-      sem.newsem.pad = 0;
-      sem.newsem.nwaiters = 0;
-
-      /* This always is a shared semaphore.  */
-      sem.newsem.private = FUTEX_SHARED;
-
-      /* Initialize the remaining bytes as well.  */
-      memset ((char *) &sem.initsem + sizeof (struct new_sem), '\0',
-	      sizeof (sem_t) - sizeof (struct new_sem));
-
-      tmpfname = __alloca (shm_dirlen + sizeof SEM_SHM_PREFIX + 6);
-      char *xxxxxx = __mempcpy (tmpfname, shm_dir, shm_dirlen);
-
-      int retries = 0;
-#define NRETRIES 50
-      while (1)
-	{
-	  /* Add the suffix for mktemp.  */
-	  strcpy (xxxxxx, "XXXXXX");
-
-	  /* We really want to use mktemp here.  We cannot use mkstemp
-	     since the file must be opened with a specific mode.  The
-	     mode cannot later be set since then we cannot apply the
-	     file create mask.  */
-	  if (__mktemp (tmpfname) == NULL)
-	    return SEM_FAILED;
-
-	  /* Open the file.  Make sure we do not overwrite anything.  */
-	  fd = __libc_open (tmpfname, O_RDWR | O_CREAT | O_EXCL, mode);
-	  if (fd == -1)
-	    {
-	      if (errno == EEXIST)
-		{
-		  if (++retries < NRETRIES)
-		    continue;
-
-		  __set_errno (EAGAIN);
-		}
-
-	      return SEM_FAILED;
-	    }
-
-	  /* We got a file.  */
-	  break;
-	}
-
-      if (TEMP_FAILURE_RETRY (__libc_write (fd, &sem.initsem, sizeof (sem_t)))
-	  == sizeof (sem_t)
-	  /* Map the sem_t structure from the file.  */
-	  && (result = (sem_t *) mmap (NULL, sizeof (sem_t),
-				       PROT_READ | PROT_WRITE, MAP_SHARED,
-				       fd, 0)) != MAP_FAILED)
-	{
-	  /* Create the file.  Don't overwrite an existing file.  */
-	  if (link (tmpfname, shm_name) != 0)
-	    {
-	      /* Undo the mapping.  */
-	      (void) munmap (result, sizeof (sem_t));
-
-	      /* Reinitialize 'result'.  */
-	      result = SEM_FAILED;
-
-	      /* This failed.  If O_EXCL is not set and the problem was
-		 that the file exists, try again.  */
-	      if ((oflag & O_EXCL) == 0 && errno == EEXIST)
-		{
-		  /* Remove the file.  */
-		  (void) unlink (tmpfname);
-
-		  /* Close the file.  */
-		  (void) __libc_close (fd);
-
-		  goto try_again;
-		}
-	    }
-	  else
-	    /* Insert the mapping into the search tree.  This also
-	       determines whether another thread sneaked by and already
-	       added such a mapping despite the fact that we created it.  */
-	    result = check_add_mapping (name, namelen, fd, result);
-	}
-
-      /* Now remove the temporary name.  This should never fail.  If
-	 it fails we leak a file name.  Better fix the kernel.  */
-      (void) unlink (tmpfname);
-    }
-
-  /* Map the mmap error to the error we need.  */
-  if (MAP_FAILED != (void *) SEM_FAILED && result == MAP_FAILED)
-    result = SEM_FAILED;
-
-  /* We don't need the file descriptor anymore.  */
-  if (fd != -1)
-    {
-      /* Do not disturb errno.  */
-      int save = errno;
-      __libc_close (fd);
-      errno = save;
-    }
-
-  return result;
-}
diff --git a/sysdeps/sparc/sparc32/sparcv9/sem_open.c b/sysdeps/sparc/sparc32/sparcv9/sem_open.c
deleted file mode 100644
index bff2d2d..0000000
--- a/sysdeps/sparc/sparc32/sparcv9/sem_open.c
+++ /dev/null
@@ -1 +0,0 @@
-#include <nptl/sem_open.c>

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                |   39 ++++
 nptl/Makefile                            |    2 +-
 nptl/pthreadP.h                          |    2 +
 nptl/pthread_testcancel.c                |    4 +-
 nptl/sem_open.c                          |   27 +++-
 nptl/sem_timedwait.c                     |    3 +
 nptl/sem_wait.c                          |   13 ++
 nptl/tst-cancel12.c                      |   29 ++--
 nptl/tst-cancel13.c                      |   23 +--
 nptl/tst-cancel14.c                      |   17 +-
 nptl/tst-cancel15.c                      |   23 +--
 nptl/tst-sem16.c                         |  130 +++++++++++++
 rt/Makefile                              |    2 +-
 rt/tst-shm-cancel.c                      |  130 +++++++++++++
 sysdeps/posix/shm_open.c                 |    7 +
 sysdeps/sparc/sparc32/sem_open.c         |  300 ------------------------------
 sysdeps/sparc/sparc32/sem_wait.c         |   93 ---------
 sysdeps/sparc/sparc32/sparcv9/sem_open.c |    1 -
 sysdeps/sparc/sparc32/sparcv9/sem_wait.c |    1 -
 19 files changed, 393 insertions(+), 453 deletions(-)
 create mode 100644 nptl/tst-sem16.c
 create mode 100644 rt/tst-shm-cancel.c
 delete mode 100644 sysdeps/sparc/sparc32/sem_open.c
 delete mode 100644 sysdeps/sparc/sparc32/sem_wait.c
 delete mode 100644 sysdeps/sparc/sparc32/sparcv9/sem_open.c
 delete mode 100644 sysdeps/sparc/sparc32/sparcv9/sem_wait.c


hooks/post-receive
-- 
GNU C Library master sources


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