]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - sunrpc/rpc_thread.c
elf: Refuse to dlopen PIE objects [BZ #24323]
[thirdparty/glibc.git] / sunrpc / rpc_thread.c
index 312ca8c573927fed4db5256659e2eb277dcf9272..0abe6dc17204012569e49a77fab5790437ff0273 100644 (file)
@@ -1,16 +1,17 @@
 #include <stdio.h>
-#include <bits/libc-lock.h>
 #include <rpc/rpc.h>
 #include <assert.h>
 
-#include <bits/libc-lock.h>
-#include <bits/libc-tsd.h>
+#include <libc-lock.h>
+#include <libc-tsd.h>
+#include <shlib-compat.h>
+#include <libc-symbols.h>
 
-#ifdef _RPC_THREAD_SAFE_
 
 /* Variable used in non-threaded applications or for the first thread.  */
 static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem;
-__libc_tsd_define (, RPC_VARS)
+static __thread struct rpc_thread_variables *thread_rpc_vars
+        attribute_tls_model_ie;
 
 /*
  * Task-variable destructor
@@ -18,9 +19,9 @@ __libc_tsd_define (, RPC_VARS)
 void
 __rpc_thread_destroy (void)
 {
-       struct rpc_thread_variables *tvp = __libc_tsd_get (RPC_VARS);
+       struct rpc_thread_variables *tvp = thread_rpc_vars;
 
-       if (tvp != NULL && tvp != &__libc_tsd_RPC_VARS_mem) {
+       if (tvp != NULL) {
                __rpc_thread_svc_cleanup ();
                __rpc_thread_clnt_cleanup ();
                __rpc_thread_key_cleanup ();
@@ -29,10 +30,14 @@ __rpc_thread_destroy (void)
                free (tvp->svcraw_private_s);
                free (tvp->authdes_cache_s);
                free (tvp->authdes_lru_s);
-               free (tvp);
+               free (tvp->svc_xports_s);
+               free (tvp->svc_pollfd_s);
+               if (tvp != &__libc_tsd_RPC_VARS_mem)
+                       free (tvp);
+               thread_rpc_vars = NULL;
        }
 }
-
+text_set_element (__libc_subfreeres, __rpc_thread_destroy);
 
 /*
  * Initialize RPC multi-threaded operation
@@ -40,7 +45,7 @@ __rpc_thread_destroy (void)
 static void
 rpc_thread_multi (void)
 {
-  __libc_tsd_set (RPC_VARS, &__libc_tsd_RPC_VARS_mem);
+  thread_rpc_vars = &__libc_tsd_RPC_VARS_mem;
 }
 
 
@@ -48,18 +53,15 @@ struct rpc_thread_variables *
 __rpc_thread_variables (void)
 {
        __libc_once_define (static, once);
-       struct rpc_thread_variables *tvp;
+       struct rpc_thread_variables *tvp = thread_rpc_vars;
 
-       tvp = __libc_tsd_get (RPC_VARS);
        if (tvp == NULL) {
                __libc_once (once, rpc_thread_multi);
-               tvp = __libc_tsd_get (RPC_VARS);
+               tvp = thread_rpc_vars;
                if (tvp == NULL) {
                        tvp = calloc (1, sizeof *tvp);
                        if (tvp != NULL)
-                               __libc_tsd_set (RPC_VARS, tvp);
-                       else
-                               tvp = __libc_tsd_get (RPC_VARS);
+                               thread_rpc_vars = tvp;
                }
        }
        return tvp;
@@ -68,7 +70,7 @@ __rpc_thread_variables (void)
 
 /* Global variables If we're single-threaded, or if this is the first
    thread using the variable, use the existing global variable.  This
-   provides backwards compatability for existing applications which
+   provides backwards compatibility for existing applications which
    dynamically link against this code.  */
 #undef svc_fdset
 #undef rpc_createerr
@@ -85,6 +87,7 @@ __rpc_thread_svc_fdset (void)
                return &svc_fdset;
        return &tvp->svc_fdset_s;
 }
+libc_hidden_nolink_sunrpc (__rpc_thread_svc_fdset, GLIBC_2_2_3)
 
 struct rpc_createerr *
 __rpc_thread_createerr (void)
@@ -96,6 +99,7 @@ __rpc_thread_createerr (void)
                return &rpc_createerr;
        return &tvp->rpc_createerr_s;
 }
+libc_hidden_nolink_sunrpc (__rpc_thread_createerr, GLIBC_2_2_3)
 
 struct pollfd **
 __rpc_thread_svc_pollfd (void)
@@ -107,6 +111,11 @@ __rpc_thread_svc_pollfd (void)
                return &svc_pollfd;
        return &tvp->svc_pollfd_s;
 }
+#ifdef EXPORT_RPC_SYMBOLS
+libc_hidden_def (__rpc_thread_svc_pollfd)
+#else
+libc_hidden_nolink_sunrpc (__rpc_thread_svc_pollfd, GLIBC_2_2_3)
+#endif
 
 int *
 __rpc_thread_svc_max_pollfd (void)
@@ -118,4 +127,8 @@ __rpc_thread_svc_max_pollfd (void)
                return &svc_max_pollfd;
        return &tvp->svc_max_pollfd_s;
 }
-#endif /* _RPC_THREAD_SAFE_ */
+#ifdef EXPORT_RPC_SYMBOLS
+libc_hidden_def (__rpc_thread_svc_max_pollfd)
+#else
+libc_hidden_nolink_sunrpc (__rpc_thread_svc_max_pollfd, GLIBC_2_2_3)
+#endif