Mercurial > trustbridge > nss-cmake-static
comparison nss/lib/ckfw/mutex.c @ 0:1e5118fa0cb1
This is NSS with a Cmake Buildsyste
To compile a static NSS library for Windows we've used the
Chromium-NSS fork and added a Cmake buildsystem to compile
it statically for Windows. See README.chromium for chromium
changes and README.trustbridge for our modifications.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Mon, 28 Jul 2014 10:47:06 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e5118fa0cb1 |
---|---|
1 /* This Source Code Form is subject to the terms of the Mozilla Public | |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
4 | |
5 /* | |
6 * mutex.c | |
7 * | |
8 * This file implements a mutual-exclusion locking facility for Modules | |
9 * using the NSS Cryptoki Framework. | |
10 */ | |
11 | |
12 #ifndef CK_T | |
13 #include "ck.h" | |
14 #endif /* CK_T */ | |
15 | |
16 /* | |
17 * NSSCKFWMutex | |
18 * | |
19 * NSSCKFWMutex_Destroy | |
20 * NSSCKFWMutex_Lock | |
21 * NSSCKFWMutex_Unlock | |
22 * | |
23 * nssCKFWMutex_Create | |
24 * nssCKFWMutex_Destroy | |
25 * nssCKFWMutex_Lock | |
26 * nssCKFWMutex_Unlock | |
27 * | |
28 * -- debugging versions only -- | |
29 * nssCKFWMutex_verifyPointer | |
30 * | |
31 */ | |
32 | |
33 struct NSSCKFWMutexStr { | |
34 PRLock *lock; | |
35 }; | |
36 | |
37 #ifdef DEBUG | |
38 /* | |
39 * But first, the pointer-tracking stuff. | |
40 * | |
41 * NOTE: the pointer-tracking support in NSS/base currently relies | |
42 * upon NSPR's CallOnce support. That, however, relies upon NSPR's | |
43 * locking, which is tied into the runtime. We need a pointer-tracker | |
44 * implementation that uses the locks supplied through C_Initialize. | |
45 * That support, however, can be filled in later. So for now, I'll | |
46 * just do this routines as no-ops. | |
47 */ | |
48 | |
49 static CK_RV | |
50 mutex_add_pointer | |
51 ( | |
52 const NSSCKFWMutex *fwMutex | |
53 ) | |
54 { | |
55 return CKR_OK; | |
56 } | |
57 | |
58 static CK_RV | |
59 mutex_remove_pointer | |
60 ( | |
61 const NSSCKFWMutex *fwMutex | |
62 ) | |
63 { | |
64 return CKR_OK; | |
65 } | |
66 | |
67 NSS_IMPLEMENT CK_RV | |
68 nssCKFWMutex_verifyPointer | |
69 ( | |
70 const NSSCKFWMutex *fwMutex | |
71 ) | |
72 { | |
73 return CKR_OK; | |
74 } | |
75 | |
76 #endif /* DEBUG */ | |
77 | |
78 /* | |
79 * nssCKFWMutex_Create | |
80 * | |
81 */ | |
82 NSS_EXTERN NSSCKFWMutex * | |
83 nssCKFWMutex_Create | |
84 ( | |
85 CK_C_INITIALIZE_ARGS_PTR pInitArgs, | |
86 CryptokiLockingState LockingState, | |
87 NSSArena *arena, | |
88 CK_RV *pError | |
89 ) | |
90 { | |
91 NSSCKFWMutex *mutex; | |
92 | |
93 mutex = nss_ZNEW(arena, NSSCKFWMutex); | |
94 if (!mutex) { | |
95 *pError = CKR_HOST_MEMORY; | |
96 return (NSSCKFWMutex *)NULL; | |
97 } | |
98 *pError = CKR_OK; | |
99 mutex->lock = NULL; | |
100 if (LockingState == MultiThreaded) { | |
101 mutex->lock = PR_NewLock(); | |
102 if (!mutex->lock) { | |
103 *pError = CKR_HOST_MEMORY; /* we couldn't get the resource */ | |
104 } | |
105 } | |
106 | |
107 if( CKR_OK != *pError ) { | |
108 (void)nss_ZFreeIf(mutex); | |
109 return (NSSCKFWMutex *)NULL; | |
110 } | |
111 | |
112 #ifdef DEBUG | |
113 *pError = mutex_add_pointer(mutex); | |
114 if( CKR_OK != *pError ) { | |
115 if (mutex->lock) { | |
116 PR_DestroyLock(mutex->lock); | |
117 } | |
118 (void)nss_ZFreeIf(mutex); | |
119 return (NSSCKFWMutex *)NULL; | |
120 } | |
121 #endif /* DEBUG */ | |
122 | |
123 return mutex; | |
124 } | |
125 | |
126 /* | |
127 * nssCKFWMutex_Destroy | |
128 * | |
129 */ | |
130 NSS_EXTERN CK_RV | |
131 nssCKFWMutex_Destroy | |
132 ( | |
133 NSSCKFWMutex *mutex | |
134 ) | |
135 { | |
136 CK_RV rv = CKR_OK; | |
137 | |
138 #ifdef NSSDEBUG | |
139 rv = nssCKFWMutex_verifyPointer(mutex); | |
140 if( CKR_OK != rv ) { | |
141 return rv; | |
142 } | |
143 #endif /* NSSDEBUG */ | |
144 | |
145 if (mutex->lock) { | |
146 PR_DestroyLock(mutex->lock); | |
147 } | |
148 | |
149 #ifdef DEBUG | |
150 (void)mutex_remove_pointer(mutex); | |
151 #endif /* DEBUG */ | |
152 | |
153 (void)nss_ZFreeIf(mutex); | |
154 return rv; | |
155 } | |
156 | |
157 /* | |
158 * nssCKFWMutex_Lock | |
159 * | |
160 */ | |
161 NSS_EXTERN CK_RV | |
162 nssCKFWMutex_Lock | |
163 ( | |
164 NSSCKFWMutex *mutex | |
165 ) | |
166 { | |
167 #ifdef NSSDEBUG | |
168 CK_RV rv = nssCKFWMutex_verifyPointer(mutex); | |
169 if( CKR_OK != rv ) { | |
170 return rv; | |
171 } | |
172 #endif /* NSSDEBUG */ | |
173 if (mutex->lock) { | |
174 PR_Lock(mutex->lock); | |
175 } | |
176 | |
177 return CKR_OK; | |
178 } | |
179 | |
180 /* | |
181 * nssCKFWMutex_Unlock | |
182 * | |
183 */ | |
184 NSS_EXTERN CK_RV | |
185 nssCKFWMutex_Unlock | |
186 ( | |
187 NSSCKFWMutex *mutex | |
188 ) | |
189 { | |
190 PRStatus nrv; | |
191 #ifdef NSSDEBUG | |
192 CK_RV rv = nssCKFWMutex_verifyPointer(mutex); | |
193 | |
194 if( CKR_OK != rv ) { | |
195 return rv; | |
196 } | |
197 #endif /* NSSDEBUG */ | |
198 | |
199 if (!mutex->lock) | |
200 return CKR_OK; | |
201 | |
202 nrv = PR_Unlock(mutex->lock); | |
203 | |
204 /* if unlock fails, either we have a programming error, or we have | |
205 * some sort of hardware failure... in either case return CKR_DEVICE_ERROR. | |
206 */ | |
207 return nrv == PR_SUCCESS ? CKR_OK : CKR_DEVICE_ERROR; | |
208 } | |
209 | |
210 /* | |
211 * NSSCKFWMutex_Destroy | |
212 * | |
213 */ | |
214 NSS_EXTERN CK_RV | |
215 NSSCKFWMutex_Destroy | |
216 ( | |
217 NSSCKFWMutex *mutex | |
218 ) | |
219 { | |
220 #ifdef DEBUG | |
221 CK_RV rv = nssCKFWMutex_verifyPointer(mutex); | |
222 if( CKR_OK != rv ) { | |
223 return rv; | |
224 } | |
225 #endif /* DEBUG */ | |
226 | |
227 return nssCKFWMutex_Destroy(mutex); | |
228 } | |
229 | |
230 /* | |
231 * NSSCKFWMutex_Lock | |
232 * | |
233 */ | |
234 NSS_EXTERN CK_RV | |
235 NSSCKFWMutex_Lock | |
236 ( | |
237 NSSCKFWMutex *mutex | |
238 ) | |
239 { | |
240 #ifdef DEBUG | |
241 CK_RV rv = nssCKFWMutex_verifyPointer(mutex); | |
242 if( CKR_OK != rv ) { | |
243 return rv; | |
244 } | |
245 #endif /* DEBUG */ | |
246 | |
247 return nssCKFWMutex_Lock(mutex); | |
248 } | |
249 | |
250 /* | |
251 * NSSCKFWMutex_Unlock | |
252 * | |
253 */ | |
254 NSS_EXTERN CK_RV | |
255 NSSCKFWMutex_Unlock | |
256 ( | |
257 NSSCKFWMutex *mutex | |
258 ) | |
259 { | |
260 #ifdef DEBUG | |
261 CK_RV rv = nssCKFWMutex_verifyPointer(mutex); | |
262 if( CKR_OK != rv ) { | |
263 return rv; | |
264 } | |
265 #endif /* DEBUG */ | |
266 | |
267 return nssCKFWMutex_Unlock(mutex); | |
268 } | |
269 |