about summary refs log tree commit diff
path: root/sysdeps/pthread
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-05-05 17:15:57 +0200
committerFlorian Weimer <fweimer@redhat.com>2021-05-05 17:19:38 +0200
commit0b7d48d1062e4383b4a78e0bb78c5f0f29479780 (patch)
tree7f68d1ddf402078c5ba49416a076b7875fb18b75 /sysdeps/pthread
parent19cc20ef2e8b9e09429741a3108e55c50758a273 (diff)
downloadglibc-0b7d48d1062e4383b4a78e0bb78c5f0f29479780.tar.gz
glibc-0b7d48d1062e4383b4a78e0bb78c5f0f29479780.tar.xz
glibc-0b7d48d1062e4383b4a78e0bb78c5f0f29479780.zip
nptl: Move sem_close, sem_open into libc
The symbols were moved using move-symbol-to-libc.py.

Both functions are moved at the same time because they depend
on internal functions in sysdeps/pthread/sem_routines.c, which
are moved in this commit as well.  Additional hidden prototypes
are required to avoid check-localplt failures.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps/pthread')
-rw-r--r--sysdeps/pthread/sem_close.c10
-rw-r--r--sysdeps/pthread/sem_open.c40
-rw-r--r--sysdeps/pthread/sem_routines.c10
3 files changed, 41 insertions, 19 deletions
diff --git a/sysdeps/pthread/sem_close.c b/sysdeps/pthread/sem_close.c
index 6649196cac..212848f745 100644
--- a/sysdeps/pthread/sem_close.c
+++ b/sysdeps/pthread/sem_close.c
@@ -21,7 +21,7 @@
 #include <sem_routines.h>
 
 int
-sem_close (sem_t *sem)
+__sem_close (sem_t *sem)
 {
   if (!__sem_remove_mapping (sem))
     {
@@ -31,3 +31,11 @@ sem_close (sem_t *sem)
 
   return 0;
 }
+#if PTHREAD_IN_LIBC
+versioned_symbol (libc, __sem_close, sem_close, GLIBC_2_34);
+# if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_1_1, GLIBC_2_34)
+compat_symbol (libpthread, __sem_close, sem_close, GLIBC_2_1_1);
+# endif
+#else /* !PTHREAD_IN_LIBC */
+strong_alias (__sem_close, sem_close)
+#endif
diff --git a/sysdeps/pthread/sem_open.c b/sysdeps/pthread/sem_open.c
index 0265abc45b..770ab17cdb 100644
--- a/sysdeps/pthread/sem_open.c
+++ b/sysdeps/pthread/sem_open.c
@@ -27,8 +27,14 @@
 #include <futex-internal.h>
 #include <libc-lock.h>
 
+#if !PTHREAD_IN_LIBC
+/* The private names are not exported from libc.  */
+# define __link link
+# define __unlink unlink
+#endif
+
 sem_t *
-sem_open (const char *name, int oflag, ...)
+__sem_open (const char *name, int oflag, ...)
 {
   int fd;
   sem_t *result;
@@ -59,8 +65,8 @@ sem_open (const char *name, int oflag, ...)
   if ((oflag & O_CREAT) == 0 || (oflag & O_EXCL) == 0)
     {
     try_again:
-      fd = open (dirname.name,
-		 (oflag & ~(O_CREAT|O_ACCMODE)) | O_NOFOLLOW | O_RDWR);
+      fd = __open (dirname.name,
+		   (oflag & ~(O_CREAT|O_ACCMODE)) | O_NOFOLLOW | O_RDWR);
 
       if (fd == -1)
 	{
@@ -127,7 +133,7 @@ sem_open (const char *name, int oflag, ...)
 	    }
 
 	  /* Open the file.  Make sure we do not overwrite anything.  */
-	  fd = open (tmpfname, O_RDWR | O_CREAT | O_EXCL, mode);
+	  fd = __open (tmpfname, O_RDWR | O_CREAT | O_EXCL, mode);
 	  if (fd == -1)
 	    {
 	      if (errno == EEXIST)
@@ -154,15 +160,15 @@ sem_open (const char *name, int oflag, ...)
       if (TEMP_FAILURE_RETRY (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)
+	  && (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, dirname.name) != 0)
+	  if (__link (tmpfname, dirname.name) != 0)
 	    {
 	      /* Undo the mapping.  */
-	      (void) munmap (result, sizeof (sem_t));
+	      __munmap (result, sizeof (sem_t));
 
 	      /* Reinitialize 'result'.  */
 	      result = SEM_FAILED;
@@ -172,10 +178,10 @@ sem_open (const char *name, int oflag, ...)
 	      if ((oflag & O_EXCL) == 0 && errno == EEXIST)
 		{
 		  /* Remove the file.  */
-		  (void) unlink (tmpfname);
+		  __unlink (tmpfname);
 
 		  /* Close the file.  */
-		  close (fd);
+		  __close (fd);
 
 		  goto try_again;
 		}
@@ -189,7 +195,7 @@ sem_open (const char *name, int oflag, ...)
 
       /* Now remove the temporary name.  This should never fail.  If
 	 it fails we leak a file name.  Better fix the kernel.  */
-      (void) unlink (tmpfname);
+      __unlink (tmpfname);
     }
 
   /* Map the mmap error to the error we need.  */
@@ -201,7 +207,7 @@ sem_open (const char *name, int oflag, ...)
     {
       /* Do not disturb errno.  */
       int save = errno;
-      close (fd);
+      __close (fd);
       errno = save;
     }
 
@@ -212,3 +218,11 @@ out:
 
   return result;
 }
+#if PTHREAD_IN_LIBC
+versioned_symbol (libc, __sem_open, sem_open, GLIBC_2_34);
+# if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_1_1, GLIBC_2_34)
+compat_symbol (libpthread, __sem_open, sem_open, GLIBC_2_1_1);
+# endif
+#else /* !PTHREAD_IN_LIBC */
+strong_alias (__sem_open, sem_open)
+#endif
diff --git a/sysdeps/pthread/sem_routines.c b/sysdeps/pthread/sem_routines.c
index 34e6410729..9a78dab5d3 100644
--- a/sysdeps/pthread/sem_routines.c
+++ b/sysdeps/pthread/sem_routines.c
@@ -106,9 +106,9 @@ __sem_check_add_mapping (const char *name, int fd, sem_t *existing)
 	    {
 	      /* 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);
+		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;
@@ -136,7 +136,7 @@ __sem_check_add_mapping (const char *name, int fd, sem_t *existing)
     {
       /* Do not disturb errno.  */
       int save = errno;
-      munmap (existing, sizeof (sem_t));
+      __munmap (existing, sizeof (sem_t));
       errno = save;
     }
 
@@ -183,7 +183,7 @@ __sem_remove_mapping (sem_t *sem)
 	  /* Remove the record from the tree.  */
 	  __tdelete (rec, &sem_mappings, sem_search);
 
-	  if (munmap (rec->sem, sizeof (sem_t)) == -1)
+	  if (__munmap (rec->sem, sizeof (sem_t)) == -1)
 	    ret = false;
 
 	  free (rec);