Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: mozilla/security/nss/lib/ckfw/mutex.c

Issue 14249009: Change the NSS and NSPR source tree to the new directory structure to be (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mozilla/security/nss/lib/ckfw/mechanism.c ('k') | mozilla/security/nss/lib/ckfw/nssck.api » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #ifdef DEBUG
6 static const char CVS_ID[] = "@(#) $RCSfile: mutex.c,v $ $Revision: 1.10 $ $Date : 2012/04/25 14:49:28 $";
7 #endif /* DEBUG */
8
9 /*
10 * mutex.c
11 *
12 * This file implements a mutual-exclusion locking facility for Modules
13 * using the NSS Cryptoki Framework.
14 */
15
16 #ifndef CK_T
17 #include "ck.h"
18 #endif /* CK_T */
19
20 /*
21 * NSSCKFWMutex
22 *
23 * NSSCKFWMutex_Destroy
24 * NSSCKFWMutex_Lock
25 * NSSCKFWMutex_Unlock
26 *
27 * nssCKFWMutex_Create
28 * nssCKFWMutex_Destroy
29 * nssCKFWMutex_Lock
30 * nssCKFWMutex_Unlock
31 *
32 * -- debugging versions only --
33 * nssCKFWMutex_verifyPointer
34 *
35 */
36
37 struct NSSCKFWMutexStr {
38 PRLock *lock;
39 };
40
41 #ifdef DEBUG
42 /*
43 * But first, the pointer-tracking stuff.
44 *
45 * NOTE: the pointer-tracking support in NSS/base currently relies
46 * upon NSPR's CallOnce support. That, however, relies upon NSPR's
47 * locking, which is tied into the runtime. We need a pointer-tracker
48 * implementation that uses the locks supplied through C_Initialize.
49 * That support, however, can be filled in later. So for now, I'll
50 * just do this routines as no-ops.
51 */
52
53 static CK_RV
54 mutex_add_pointer
55 (
56 const NSSCKFWMutex *fwMutex
57 )
58 {
59 return CKR_OK;
60 }
61
62 static CK_RV
63 mutex_remove_pointer
64 (
65 const NSSCKFWMutex *fwMutex
66 )
67 {
68 return CKR_OK;
69 }
70
71 NSS_IMPLEMENT CK_RV
72 nssCKFWMutex_verifyPointer
73 (
74 const NSSCKFWMutex *fwMutex
75 )
76 {
77 return CKR_OK;
78 }
79
80 #endif /* DEBUG */
81
82 /*
83 * nssCKFWMutex_Create
84 *
85 */
86 NSS_EXTERN NSSCKFWMutex *
87 nssCKFWMutex_Create
88 (
89 CK_C_INITIALIZE_ARGS_PTR pInitArgs,
90 CryptokiLockingState LockingState,
91 NSSArena *arena,
92 CK_RV *pError
93 )
94 {
95 NSSCKFWMutex *mutex;
96
97 mutex = nss_ZNEW(arena, NSSCKFWMutex);
98 if (!mutex) {
99 *pError = CKR_HOST_MEMORY;
100 return (NSSCKFWMutex *)NULL;
101 }
102 *pError = CKR_OK;
103 mutex->lock = NULL;
104 if (LockingState == MultiThreaded) {
105 mutex->lock = PR_NewLock();
106 if (!mutex->lock) {
107 *pError = CKR_HOST_MEMORY; /* we couldn't get the resource */
108 }
109 }
110
111 if( CKR_OK != *pError ) {
112 (void)nss_ZFreeIf(mutex);
113 return (NSSCKFWMutex *)NULL;
114 }
115
116 #ifdef DEBUG
117 *pError = mutex_add_pointer(mutex);
118 if( CKR_OK != *pError ) {
119 if (mutex->lock) {
120 PR_DestroyLock(mutex->lock);
121 }
122 (void)nss_ZFreeIf(mutex);
123 return (NSSCKFWMutex *)NULL;
124 }
125 #endif /* DEBUG */
126
127 return mutex;
128 }
129
130 /*
131 * nssCKFWMutex_Destroy
132 *
133 */
134 NSS_EXTERN CK_RV
135 nssCKFWMutex_Destroy
136 (
137 NSSCKFWMutex *mutex
138 )
139 {
140 CK_RV rv = CKR_OK;
141
142 #ifdef NSSDEBUG
143 rv = nssCKFWMutex_verifyPointer(mutex);
144 if( CKR_OK != rv ) {
145 return rv;
146 }
147 #endif /* NSSDEBUG */
148
149 if (mutex->lock) {
150 PR_DestroyLock(mutex->lock);
151 }
152
153 #ifdef DEBUG
154 (void)mutex_remove_pointer(mutex);
155 #endif /* DEBUG */
156
157 (void)nss_ZFreeIf(mutex);
158 return rv;
159 }
160
161 /*
162 * nssCKFWMutex_Lock
163 *
164 */
165 NSS_EXTERN CK_RV
166 nssCKFWMutex_Lock
167 (
168 NSSCKFWMutex *mutex
169 )
170 {
171 #ifdef NSSDEBUG
172 CK_RV rv = nssCKFWMutex_verifyPointer(mutex);
173 if( CKR_OK != rv ) {
174 return rv;
175 }
176 #endif /* NSSDEBUG */
177 if (mutex->lock) {
178 PR_Lock(mutex->lock);
179 }
180
181 return CKR_OK;
182 }
183
184 /*
185 * nssCKFWMutex_Unlock
186 *
187 */
188 NSS_EXTERN CK_RV
189 nssCKFWMutex_Unlock
190 (
191 NSSCKFWMutex *mutex
192 )
193 {
194 PRStatus nrv;
195 #ifdef NSSDEBUG
196 CK_RV rv = nssCKFWMutex_verifyPointer(mutex);
197
198 if( CKR_OK != rv ) {
199 return rv;
200 }
201 #endif /* NSSDEBUG */
202
203 if (!mutex->lock)
204 return CKR_OK;
205
206 nrv = PR_Unlock(mutex->lock);
207
208 /* if unlock fails, either we have a programming error, or we have
209 * some sort of hardware failure... in either case return CKR_DEVICE_ERROR.
210 */
211 return nrv == PR_SUCCESS ? CKR_OK : CKR_DEVICE_ERROR;
212 }
213
214 /*
215 * NSSCKFWMutex_Destroy
216 *
217 */
218 NSS_EXTERN CK_RV
219 NSSCKFWMutex_Destroy
220 (
221 NSSCKFWMutex *mutex
222 )
223 {
224 #ifdef DEBUG
225 CK_RV rv = nssCKFWMutex_verifyPointer(mutex);
226 if( CKR_OK != rv ) {
227 return rv;
228 }
229 #endif /* DEBUG */
230
231 return nssCKFWMutex_Destroy(mutex);
232 }
233
234 /*
235 * NSSCKFWMutex_Lock
236 *
237 */
238 NSS_EXTERN CK_RV
239 NSSCKFWMutex_Lock
240 (
241 NSSCKFWMutex *mutex
242 )
243 {
244 #ifdef DEBUG
245 CK_RV rv = nssCKFWMutex_verifyPointer(mutex);
246 if( CKR_OK != rv ) {
247 return rv;
248 }
249 #endif /* DEBUG */
250
251 return nssCKFWMutex_Lock(mutex);
252 }
253
254 /*
255 * NSSCKFWMutex_Unlock
256 *
257 */
258 NSS_EXTERN CK_RV
259 NSSCKFWMutex_Unlock
260 (
261 NSSCKFWMutex *mutex
262 )
263 {
264 #ifdef DEBUG
265 CK_RV rv = nssCKFWMutex_verifyPointer(mutex);
266 if( CKR_OK != rv ) {
267 return rv;
268 }
269 #endif /* DEBUG */
270
271 return nssCKFWMutex_Unlock(mutex);
272 }
273
OLDNEW
« no previous file with comments | « mozilla/security/nss/lib/ckfw/mechanism.c ('k') | mozilla/security/nss/lib/ckfw/nssck.api » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698