1 #include <stdio.h>
2 #include <rpc/rpc.h>
3 #include <assert.h>
4
5 #include <libc-lock.h>
6 #include <libc-tsd.h>
7 #include <shlib-compat.h>
8 #include <libc-symbols.h>
9
10
11 /* Variable used in non-threaded applications or for the first thread. */
12 static struct rpc_thread_variables __libc_tsd_RPC_VARS_mem;
13 static __thread struct rpc_thread_variables *thread_rpc_vars
14 attribute_tls_model_ie;
15
16 /*
17 * Task-variable destructor
18 */
19 void
20 __rpc_thread_destroy (void)
21 {
22 struct rpc_thread_variables *tvp = thread_rpc_vars;
23
24 if (tvp != NULL) {
25 __rpc_thread_svc_cleanup ();
26 __rpc_thread_clnt_cleanup ();
27 __rpc_thread_key_cleanup ();
28 free (tvp->clnt_perr_buf_s);
29 free (tvp->clntraw_private_s);
30 free (tvp->svcraw_private_s);
31 free (tvp->authdes_cache_s);
32 free (tvp->authdes_lru_s);
33 free (tvp->svc_xports_s);
34 free (tvp->svc_pollfd_s);
35 if (tvp != &__libc_tsd_RPC_VARS_mem)
36 free (tvp);
37 thread_rpc_vars = NULL;
38 }
39 }
40
41 /*
42 * Initialize RPC multi-threaded operation
43 */
44 static void
45 rpc_thread_multi (void)
46 {
47 thread_rpc_vars = &__libc_tsd_RPC_VARS_mem;
48 }
49
50
51 struct rpc_thread_variables *
52 __rpc_thread_variables (void)
53 {
54 __libc_once_define (static, once);
55 struct rpc_thread_variables *tvp = thread_rpc_vars;
56
57 if (tvp == NULL) {
58 __libc_once (once, rpc_thread_multi);
59 tvp = thread_rpc_vars;
60 if (tvp == NULL) {
61 tvp = calloc (1, sizeof *tvp);
62 if (tvp != NULL)
63 thread_rpc_vars = tvp;
64 }
65 }
66 return tvp;
67 }
68
69
70 /* Global variables If we're single-threaded, or if this is the first
71 thread using the variable, use the existing global variable. This
72 provides backwards compatibility for existing applications which
73 dynamically link against this code. */
74 #undef svc_fdset
75 #undef rpc_createerr
76 #undef svc_pollfd
77 #undef svc_max_pollfd
78
79 fd_set *
80 __rpc_thread_svc_fdset (void)
81 {
82 struct rpc_thread_variables *tvp;
83
84 tvp = __rpc_thread_variables ();
85 if (tvp == &__libc_tsd_RPC_VARS_mem)
86 return &svc_fdset;
87 return &tvp->svc_fdset_s;
88 }
89 libc_hidden_nolink_sunrpc (__rpc_thread_svc_fdset, GLIBC_2_2_3)
90
91 struct rpc_createerr *
92 __rpc_thread_createerr (void)
93 {
94 struct rpc_thread_variables *tvp;
95
96 tvp = __rpc_thread_variables ();
97 if (tvp == &__libc_tsd_RPC_VARS_mem)
98 return &rpc_createerr;
99 return &tvp->rpc_createerr_s;
100 }
101 libc_hidden_nolink_sunrpc (__rpc_thread_createerr, GLIBC_2_2_3)
102
103 struct pollfd **
104 __rpc_thread_svc_pollfd (void)
105 {
106 struct rpc_thread_variables *tvp;
107
108 tvp = __rpc_thread_variables ();
109 if (tvp == &__libc_tsd_RPC_VARS_mem)
110 return &svc_pollfd;
111 return &tvp->svc_pollfd_s;
112 }
113 #ifdef EXPORT_RPC_SYMBOLS
114 libc_hidden_def (__rpc_thread_svc_pollfd)
115 #else
116 libc_hidden_nolink_sunrpc (__rpc_thread_svc_pollfd, GLIBC_2_2_3)
117 #endif
118
119 int *
120 __rpc_thread_svc_max_pollfd (void)
121 {
122 struct rpc_thread_variables *tvp;
123
124 tvp = __rpc_thread_variables ();
125 if (tvp == &__libc_tsd_RPC_VARS_mem)
126 return &svc_max_pollfd;
127 return &tvp->svc_max_pollfd_s;
128 }
129 #ifdef EXPORT_RPC_SYMBOLS
130 libc_hidden_def (__rpc_thread_svc_max_pollfd)
131 #else
132 libc_hidden_nolink_sunrpc (__rpc_thread_svc_max_pollfd, GLIBC_2_2_3)
133 #endif