1 #include <wintirpc.h> 2 3 //#include <sys/cdefs.h> 4 //#include <pthread.h> 5 #include <reentrant.h> 6 #include <rpc/rpc.h> 7 //#include <sys/time.h> 8 #include <stdlib.h> 9 #include <string.h> 10 11 /* 12 * XXX 13 * For Windows, these must initialized in the DLLMain() function. 14 * Cannot do static initialization!! 15 * XXX 16 */ 17 18 /* protects the services list (svc.c) */ 19 rwlock_t svc_lock; 20 21 /* protects svc_fdset and the xports[] array */ 22 rwlock_t svc_fd_lock; 23 24 /* protects the RPCBIND address cache */ 25 rwlock_t rpcbaddr_cache_lock; 26 27 /* protects authdes cache (svcauth_des.c) */ 28 mutex_t authdes_lock; 29 30 /* serializes authdes ops initializations */ 31 mutex_t authdes_ops_lock; 32 33 /* protects des stats list */ 34 mutex_t svcauthdesstats_lock; 35 36 #ifdef KERBEROS 37 /* auth_kerb.c serialization */ 38 mutex_t authkerb_lock = PTHREAD_MUTEX_INITIALIZER; 39 /* protects kerb stats list */ 40 mutex_t svcauthkerbstats_lock = PTHREAD_MUTEX_INITIALIZER; 41 #endif /* KERBEROS */ 42 43 /* auth_none.c serialization */ 44 mutex_t authnone_lock; 45 46 /* protects the Auths list (svc_auth.c) */ 47 mutex_t authsvc_lock; 48 49 /* protects client-side fd lock array */ 50 mutex_t clnt_fd_lock; 51 52 /* clnt_raw.c serialization */ 53 mutex_t clntraw_lock; 54 55 /* domainname and domain_fd (getdname.c) and default_domain (rpcdname.c) */ 56 mutex_t dname_lock; 57 58 /* dupreq variables (svc_dg.c) */ 59 mutex_t dupreq_lock; 60 61 /* protects first_time and hostname (key_call.c) */ 62 mutex_t keyserv_lock; 63 64 /* serializes rpc_trace() (rpc_trace.c) */ 65 mutex_t libnsl_trace_lock; 66 67 /* loopnconf (rpcb_clnt.c) */ 68 mutex_t loopnconf_lock; 69 70 /* serializes ops initializations */ 71 mutex_t ops_lock; 72 73 /* protects ``port'' static in bindresvport() */ 74 mutex_t portnum_lock; 75 76 /* protects proglst list (svc_simple.c) */ 77 mutex_t proglst_lock; 78 79 /* serializes clnt_com_create() (rpc_soc.c) */ 80 mutex_t rpcsoc_lock; 81 82 /* svc_raw.c serialization */ 83 mutex_t svcraw_lock; 84 85 /* protects TSD key creation */ 86 mutex_t tsd_lock; 87 88 /* Library global tsd keys */ 89 thread_key_t clnt_broadcast_key; 90 thread_key_t rpc_call_key = -1; 91 thread_key_t tcp_key = -1; 92 thread_key_t udp_key = -1; 93 thread_key_t nc_key = -1; 94 thread_key_t rce_key = -1; 95 96 /* xprtlist (svc_generic.c) */ 97 mutex_t xprtlist_lock; 98 99 /* serializes calls to public key routines */ 100 mutex_t serialize_pkey; 101 102 /* netconfig serialization */ 103 mutex_t nc_lock; 104 105 #ifdef _WIN32 106 /* 107 * Initialize all the mutexes (CriticalSections) 108 */ 109 void multithread_init(void) 110 { 111 InitializeCriticalSection(&authdes_lock); 112 InitializeCriticalSection(&authdes_ops_lock); 113 InitializeCriticalSection(&svcauthdesstats_lock); 114 InitializeCriticalSection(&authnone_lock); 115 InitializeCriticalSection(&authsvc_lock); 116 InitializeCriticalSection(&clnt_fd_lock); 117 InitializeCriticalSection(&clntraw_lock); 118 InitializeCriticalSection(&dname_lock); 119 InitializeCriticalSection(&dupreq_lock); 120 InitializeCriticalSection(&keyserv_lock); 121 InitializeCriticalSection(&libnsl_trace_lock); 122 InitializeCriticalSection(&loopnconf_lock); 123 InitializeCriticalSection(&ops_lock); 124 InitializeCriticalSection(&portnum_lock); 125 InitializeCriticalSection(&proglst_lock); 126 InitializeCriticalSection(&rpcsoc_lock); 127 InitializeCriticalSection(&svcraw_lock); 128 InitializeCriticalSection(&tsd_lock); 129 InitializeCriticalSection(&xprtlist_lock); 130 InitializeCriticalSection(&serialize_pkey); 131 InitializeCriticalSection(&nc_lock); 132 } 133 #endif 134 135 #undef rpc_createerr 136 137 struct rpc_createerr rpc_createerr; 138 139 struct rpc_createerr * 140 __rpc_createerr() 141 { 142 struct rpc_createerr *rce_addr; 143 144 mutex_lock(&tsd_lock); 145 if (rce_key == -1) 146 rce_key = TlsAlloc(); //thr_keycreate(&rce_key, free); 147 mutex_unlock(&tsd_lock); 148 149 rce_addr = (struct rpc_createerr *)thr_getspecific(rce_key); 150 if (!rce_addr) { 151 rce_addr = (struct rpc_createerr *) 152 malloc(sizeof (struct rpc_createerr)); 153 if (!rce_addr || 154 thr_setspecific(rce_key, (void *) rce_addr) == 0) { 155 if (rce_addr) 156 free(rce_addr); 157 return (&rpc_createerr); 158 } 159 memset(rce_addr, 0, sizeof (struct rpc_createerr)); 160 } 161 return (rce_addr); 162 } 163 164 void tsd_key_delete(void) 165 { 166 if (clnt_broadcast_key != -1) 167 thr_keydelete(clnt_broadcast_key); 168 if (rpc_call_key != -1) 169 thr_keydelete(rpc_call_key); 170 if (tcp_key != -1) 171 thr_keydelete(tcp_key); 172 if (udp_key != -1) 173 thr_keydelete(udp_key); 174 if (nc_key != -1) 175 thr_keydelete(nc_key); 176 if (rce_key != -1) 177 thr_keydelete(rce_key); 178 return; 179 } 180 181