about summary refs log tree commit diff
path: root/rt
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-06-25 10:30:35 +0200
committerFlorian Weimer <fweimer@redhat.com>2021-06-25 11:48:25 +0200
commitd12506b2dbbeb259468e0f06e87a98174e69a743 (patch)
tree7dd428bde261bd9f75ab54c86696a8220f203ef9 /rt
parent97ed4749becdc20481688ee074e90507ca3501dd (diff)
downloadglibc-d12506b2dbbeb259468e0f06e87a98174e69a743.tar.gz
glibc-d12506b2dbbeb259468e0f06e87a98174e69a743.tar.xz
glibc-d12506b2dbbeb259468e0f06e87a98174e69a743.zip
Linux: Move aio_init from librt into libc
This commit also moves the aio_misc and aio_sigquue helper,
so GLIBC_PRIVATE exports need to be added.

The symbol was moved using scripts/move-symbol-to-libc.py.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'rt')
-rw-r--r--rt/Makefile6
-rw-r--r--rt/Versions23
-rw-r--r--rt/aio_misc.c107
-rw-r--r--rt/aio_notify.c21
-rw-r--r--rt/aio_sigqueue.c2
5 files changed, 116 insertions, 43 deletions
diff --git a/rt/Makefile b/rt/Makefile
index 6c7728a318..048aacce86 100644
--- a/rt/Makefile
+++ b/rt/Makefile
@@ -32,12 +32,9 @@ librt-routines = \
   aio_cancel \
   aio_error \
   aio_fsync \
-  aio_misc \
-  aio_notify \
   aio_read \
   aio_read64 \
   aio_return \
-  aio_sigqueue \
   aio_suspend \
   aio_write \
   aio_write64 \
@@ -60,6 +57,9 @@ librt-routines = \
   timer_settime \
 
 $(librt-routines-var) += \
+  aio_misc \
+  aio_notify \
+  aio_sigqueue \
 
 tests := tst-shm tst-timer tst-timer2 \
 	 tst-aio tst-aio64 tst-aio2 tst-aio3 tst-aio4 tst-aio5 tst-aio6 \
diff --git a/rt/Versions b/rt/Versions
index 26c6d1ac63..2e991a9d93 100644
--- a/rt/Versions
+++ b/rt/Versions
@@ -1,12 +1,33 @@
 libc {
+  GLIBC_2.1 {
+%if PTHREAD_IN_LIBC
+    aio_init;
+%endif
+  }
   GLIBC_2.2 {
     shm_open;
     shm_unlink;
   }
   GLIBC_2.34 {
+%if PTHREAD_IN_LIBC
+    aio_init;
+%endif
     shm_open;
     shm_unlink;
   }
+%if PTHREAD_IN_LIBC
+  GLIBC_PRIVATE {
+    __aio_enqueue_request;
+    __aio_find_req;
+    __aio_find_req_fd;
+    __aio_free_request;
+    __aio_notify;
+    __aio_notify_only;
+    __aio_remove_request;
+    __aio_requests_mutex;
+    __aio_sigqueue;
+  }
+%endif
 }
 librt {
   GLIBC_2.1 {
@@ -16,7 +37,9 @@ librt {
     aio_error64;
     aio_fsync;
     aio_fsync64;
+%if !PTHREAD_IN_LIBC
     aio_init;
+%endif
     aio_read;
     aio_read64;
     aio_return;
diff --git a/rt/aio_misc.c b/rt/aio_misc.c
index b95f07d9d3..953d6e7613 100644
--- a/rt/aio_misc.c
+++ b/rt/aio_misc.c
@@ -21,7 +21,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <limits.h>
-#include <pthread.h>
+#include <pthreadP.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/param.h>
@@ -29,6 +29,20 @@
 #include <sys/time.h>
 #include <aio_misc.h>
 
+#if !PTHREAD_IN_LIBC
+/* The available function names differ outside of libc.  (In libc, we
+   need to use hidden aliases to avoid the PLT.)  */
+# define __pread __libc_pread
+# define __pthread_attr_destroy pthread_attr_destroy
+# define __pthread_attr_init pthread_attr_init
+# define __pthread_attr_setdetachstate pthread_attr_setdetachstate
+# define __pthread_cond_signal pthread_cond_signal
+# define __pthread_cond_timedwait pthread_cond_timedwait
+# define __pthread_getschedparam pthread_getschedparam
+# define __pthread_setschedparam pthread_setschedparam
+# define __pwrite __libc_pwrite
+#endif
+
 #ifndef aio_create_helper_thread
 # define aio_create_helper_thread __aio_create_helper_thread
 
@@ -38,12 +52,12 @@ __aio_create_helper_thread (pthread_t *threadp, void *(*tf) (void *), void *arg)
   pthread_attr_t attr;
 
   /* Make sure the thread is created detached.  */
-  pthread_attr_init (&attr);
-  pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+  __pthread_attr_init (&attr);
+  __pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
 
-  int ret = pthread_create (threadp, &attr, tf, arg);
+  int ret = __pthread_create (threadp, &attr, tf, arg);
 
-  (void) pthread_attr_destroy (&attr);
+  __pthread_attr_destroy (&attr);
   return ret;
 }
 #endif
@@ -271,7 +285,7 @@ void
 __aio_init (const struct aioinit *init)
 {
   /* Get the mutex.  */
-  pthread_mutex_lock (&__aio_requests_mutex);
+  __pthread_mutex_lock (&__aio_requests_mutex);
 
   /* Only allow writing new values if the table is not yet allocated.  */
   if (pool == NULL)
@@ -287,9 +301,8 @@ __aio_init (const struct aioinit *init)
     optim.aio_idle_time = init->aio_idle_time;
 
   /* Release the mutex.  */
-  pthread_mutex_unlock (&__aio_requests_mutex);
+  __pthread_mutex_unlock (&__aio_requests_mutex);
 }
-weak_alias (__aio_init, aio_init)
 
 
 /* The main function of the async I/O handling.  It enqueues requests
@@ -319,11 +332,11 @@ __aio_enqueue_request (aiocb_union *aiocbp, int operation)
     }
 
   /* Compute priority for this request.  */
-  pthread_getschedparam (pthread_self (), &policy, &param);
+  __pthread_getschedparam (__pthread_self (), &policy, &param);
   prio = param.sched_priority - aiocbp->aiocb.aio_reqprio;
 
   /* Get the mutex.  */
-  pthread_mutex_lock (&__aio_requests_mutex);
+  __pthread_mutex_lock (&__aio_requests_mutex);
 
   last = NULL;
   runp = requests;
@@ -340,7 +353,7 @@ __aio_enqueue_request (aiocb_union *aiocbp, int operation)
   newp = get_elem ();
   if (newp == NULL)
     {
-      pthread_mutex_unlock (&__aio_requests_mutex);
+      __pthread_mutex_unlock (&__aio_requests_mutex);
       __set_errno (EAGAIN);
       return NULL;
     }
@@ -454,7 +467,7 @@ __aio_enqueue_request (aiocb_union *aiocbp, int operation)
       /* If there is a thread waiting for work, then let it know that we
 	 have just given it something to do. */
       if (idle_thread_count > 0)
-	pthread_cond_signal (&__aio_new_request_notification);
+	__pthread_cond_signal (&__aio_new_request_notification);
     }
 
   if (result == 0)
@@ -469,7 +482,7 @@ __aio_enqueue_request (aiocb_union *aiocbp, int operation)
     }
 
   /* Release the mutex.  */
-  pthread_mutex_unlock (&__aio_requests_mutex);
+  __pthread_mutex_unlock (&__aio_requests_mutex);
 
   return newp;
 }
@@ -478,14 +491,14 @@ __aio_enqueue_request (aiocb_union *aiocbp, int operation)
 static void *
 handle_fildes_io (void *arg)
 {
-  pthread_t self = pthread_self ();
+  pthread_t self = __pthread_self ();
   struct sched_param param;
   struct requestlist *runp = (struct requestlist *) arg;
   aiocb_union *aiocbp;
   int policy;
   int fildes;
 
-  pthread_getschedparam (self, &policy, &param);
+  __pthread_getschedparam (self, &policy, &param);
 
   do
     {
@@ -495,7 +508,7 @@ handle_fildes_io (void *arg)
 	 "get work off the work queue" part of this loop, which is near the
 	 end. */
       if (runp == NULL)
-	pthread_mutex_lock (&__aio_requests_mutex);
+	__pthread_mutex_lock (&__aio_requests_mutex);
       else
 	{
 	  /* Hopefully this request is marked as running.  */
@@ -511,7 +524,7 @@ handle_fildes_io (void *arg)
 	    {
 	      param.sched_priority = aiocbp->aiocb.__abs_prio;
 	      policy = aiocbp->aiocb.__policy;
-	      pthread_setschedparam (self, policy, &param);
+	      __pthread_setschedparam (self, policy, &param);
 	    }
 
 	  /* Process request pointed to by RUNP.  We must not be disturbed
@@ -527,11 +540,11 @@ handle_fildes_io (void *arg)
 						 aiocbp->aiocb64.aio_offset));
 	      else
 		aiocbp->aiocb.__return_value =
-		  TEMP_FAILURE_RETRY (__libc_pread (fildes,
-						    (void *)
-						    aiocbp->aiocb.aio_buf,
-						    aiocbp->aiocb.aio_nbytes,
-						    aiocbp->aiocb.aio_offset));
+		  TEMP_FAILURE_RETRY (__pread (fildes,
+					       (void *)
+					       aiocbp->aiocb.aio_buf,
+					       aiocbp->aiocb.aio_nbytes,
+					       aiocbp->aiocb.aio_offset));
 
 	      if (aiocbp->aiocb.__return_value == -1 && errno == ESPIPE)
 		/* The Linux kernel is different from others.  It returns
@@ -554,10 +567,10 @@ handle_fildes_io (void *arg)
 						  aiocbp->aiocb64.aio_offset));
 	      else
 		aiocbp->aiocb.__return_value =
-		  TEMP_FAILURE_RETRY (__libc_pwrite (fildes, (const void *)
-					      aiocbp->aiocb.aio_buf,
-					      aiocbp->aiocb.aio_nbytes,
-					      aiocbp->aiocb.aio_offset));
+		  TEMP_FAILURE_RETRY (__pwrite (fildes, (const void *)
+						aiocbp->aiocb.aio_buf,
+						aiocbp->aiocb.aio_nbytes,
+						aiocbp->aiocb.aio_offset));
 
 	      if (aiocbp->aiocb.__return_value == -1 && errno == ESPIPE)
 		/* The Linux kernel is different from others.  It returns
@@ -583,7 +596,7 @@ handle_fildes_io (void *arg)
 	    }
 
 	  /* Get the mutex.  */
-	  pthread_mutex_lock (&__aio_requests_mutex);
+	  __pthread_mutex_lock (&__aio_requests_mutex);
 
 	  if (aiocbp->aiocb.__return_value == -1)
 	    aiocbp->aiocb.__error_code = errno;
@@ -626,9 +639,9 @@ handle_fildes_io (void *arg)
 	      wakeup_time.tv_nsec -= 1000000000;
 	      ++wakeup_time.tv_sec;
 	    }
-	  pthread_cond_timedwait (&__aio_new_request_notification,
-				  &__aio_requests_mutex,
-				  &wakeup_time);
+	  __pthread_cond_timedwait (&__aio_new_request_notification,
+				    &__aio_requests_mutex,
+				    &wakeup_time);
 	  --idle_thread_count;
 	  runp = runlist;
 	}
@@ -651,20 +664,21 @@ handle_fildes_io (void *arg)
 		 up for these other work elements; otherwise, we should try
 		 to create a new thread. */
 	      if (idle_thread_count > 0)
-		pthread_cond_signal (&__aio_new_request_notification);
+		__pthread_cond_signal (&__aio_new_request_notification);
 	      else if (nthreads < optim.aio_threads)
 		{
 		  pthread_t thid;
 		  pthread_attr_t attr;
 
 		  /* Make sure the thread is created detached.  */
-		  pthread_attr_init (&attr);
-		  pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+		  __pthread_attr_init (&attr);
+		  __pthread_attr_setdetachstate (&attr,
+						 PTHREAD_CREATE_DETACHED);
 
 		  /* Now try to start a thread. If we fail, no big deal,
 		     because we know that there is at least one thread (us)
 		     that is working on AIO operations. */
-		  if (pthread_create (&thid, &attr, handle_fildes_io, NULL)
+		  if (__pthread_create (&thid, &attr, handle_fildes_io, NULL)
 		      == 0)
 		    ++nthreads;
 		}
@@ -672,7 +686,7 @@ handle_fildes_io (void *arg)
 	}
 
       /* Release the mutex.  */
-      pthread_mutex_unlock (&__aio_requests_mutex);
+      __pthread_mutex_unlock (&__aio_requests_mutex);
     }
   while (runp != NULL);
 
@@ -719,3 +733,26 @@ add_request_to_runlist (struct requestlist *newrequest)
       runp->next_run = newrequest;
     }
 }
+
+#if PTHREAD_IN_LIBC
+libc_hidden_data_def (__aio_requests_mutex)
+libc_hidden_def (__aio_enqueue_request)
+libc_hidden_def (__aio_find_req)
+libc_hidden_def (__aio_find_req_fd)
+libc_hidden_def (__aio_free_request)
+libc_hidden_def (__aio_remove_request)
+
+versioned_symbol (libc, __aio_init, aio_init, GLIBC_2_34);
+# if OTHER_SHLIB_COMPAT (librt, GLIBC_2_1, GLIBC_2_34)
+compat_symbol (librt, __aio_init, aio_init, GLIBC_2_1);
+# endif
+
+#else /* !PTHREAD_IN_LIBC */
+librt_hidden_data_def (__aio_requests_mutex)
+librt_hidden_def (__aio_enqueue_request)
+librt_hidden_def (__aio_find_req)
+librt_hidden_def (__aio_find_req_fd)
+librt_hidden_def (__aio_free_request)
+librt_hidden_def (__aio_remove_request)
+weak_alias (__aio_init, aio_init)
+#endif /* !PTHREAD_IN_LIBC */
diff --git a/rt/aio_notify.c b/rt/aio_notify.c
index a8d61503d8..432000e34b 100644
--- a/rt/aio_notify.c
+++ b/rt/aio_notify.c
@@ -18,12 +18,17 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
-#include <pthread.h>
+#include <pthreadP.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <aio_misc.h>
 #include <signal.h>
 
+#if !PTHREAD_IN_LIBC
+# define __pthread_attr_init pthread_attr_init
+# define __pthread_attr_setdetachstate pthread_attr_setdetachstate
+#endif
+
 #ifndef aio_start_notify_thread
 # define aio_start_notify_thread() do { } while (0)
 #endif
@@ -62,8 +67,8 @@ __aio_notify_only (struct sigevent *sigev)
       pattr = (pthread_attr_t *) sigev->sigev_notify_attributes;
       if (pattr == NULL)
 	{
-	  pthread_attr_init (&attr);
-	  pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+	  __pthread_attr_init (&attr);
+	  __pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
 	  pattr = &attr;
 	}
 
@@ -81,7 +86,7 @@ __aio_notify_only (struct sigevent *sigev)
 	{
 	  nf->func = sigev->sigev_notify_function;
 	  nf->value = sigev->sigev_value;
-	  if (pthread_create (&tid, pattr, notify_func_wrapper, nf) < 0)
+	  if (__pthread_create (&tid, pattr, notify_func_wrapper, nf) < 0)
 	    {
 	      free (nf);
 	      result = -1;
@@ -155,3 +160,11 @@ __aio_notify (struct requestlist *req)
       waitlist = next;
     }
 }
+
+#if PTHREAD_IN_LIBC
+libc_hidden_def (__aio_notify)
+libc_hidden_def (__aio_notify_only)
+#else
+librt_hidden_def (__aio_notify)
+librt_hidden_def (__aio_notify_only)
+#endif
diff --git a/rt/aio_sigqueue.c b/rt/aio_sigqueue.c
index 2f7da00ad3..0ad95ae04c 100644
--- a/rt/aio_sigqueue.c
+++ b/rt/aio_sigqueue.c
@@ -28,5 +28,5 @@ __aio_sigqueue (int sig, const union sigval val, pid_t caller_pid)
   __set_errno (ENOSYS);
   return -1;
 }
-
+librt_hidden_def (__aio_sigqueue)
 stub_warning (__aio_sigqueue)