OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 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 | 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/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 /* | 5 /* |
6 * tracker.c | 6 * tracker.c |
7 * | 7 * |
8 * This file contains the code used by the pointer-tracking calls used | 8 * This file contains the code used by the pointer-tracking calls used |
9 * in the debug builds to catch bad pointers. The entire contents are | 9 * in the debug builds to catch bad pointers. The entire contents are |
10 * only available in debug builds (both internal and external builds). | 10 * only available in debug builds (both internal and external builds). |
11 */ | 11 */ |
12 | 12 |
13 #ifndef BASE_H | 13 #ifndef BASE_H |
14 #include "base.h" | 14 #include "base.h" |
15 #endif /* BASE_H */ | 15 #endif /* BASE_H */ |
16 | 16 |
17 #ifdef DEBUG | 17 #ifdef DEBUG |
18 /* | 18 /* |
19 * identity_hash | 19 * identity_hash |
20 * | 20 * |
21 * This static callback is a PLHashFunction as defined in plhash.h | 21 * This static callback is a PLHashFunction as defined in plhash.h |
22 * It merely returns the value of the object pointer as its hash. | 22 * It merely returns the value of the object pointer as its hash. |
23 * There are no possible errors. | 23 * There are no possible errors. |
24 */ | 24 */ |
25 | 25 |
26 static PLHashNumber PR_CALLBACK | 26 static PLHashNumber PR_CALLBACK |
27 identity_hash | 27 identity_hash(const void *key) |
28 ( | |
29 const void *key | |
30 ) | |
31 { | 28 { |
32 return (PLHashNumber)((char *)key - (char *)NULL); | 29 return (PLHashNumber)((char *)key - (char *)NULL); |
33 } | 30 } |
34 | 31 |
35 /* | 32 /* |
36 * trackerOnceFunc | 33 * trackerOnceFunc |
37 * | 34 * |
38 * This function is called once, using the nssCallOnce function above. | 35 * This function is called once, using the nssCallOnce function above. |
39 * It creates a new pointer tracker object; initialising its hash | 36 * It creates a new pointer tracker object; initialising its hash |
40 * table and protective lock. | 37 * table and protective lock. |
41 */ | 38 */ |
42 | 39 |
43 static PRStatus | 40 static PRStatus |
44 trackerOnceFunc | 41 trackerOnceFunc(void *arg) |
45 ( | |
46 void *arg | |
47 ) | |
48 { | 42 { |
49 nssPointerTracker *tracker = (nssPointerTracker *)arg; | 43 nssPointerTracker *tracker = (nssPointerTracker *)arg; |
50 | 44 |
51 tracker->lock = PZ_NewLock(nssILockOther); | 45 tracker->lock = PZ_NewLock(nssILockOther); |
52 if( (PZLock *)NULL == tracker->lock ) { | 46 if ((PZLock *)NULL == tracker->lock) { |
53 return PR_FAILURE; | 47 return PR_FAILURE; |
54 } | 48 } |
55 | 49 |
56 tracker->table = PL_NewHashTable(0, | 50 tracker->table = |
57 identity_hash, | 51 PL_NewHashTable(0, identity_hash, PL_CompareValues, PL_CompareValues, |
58 PL_CompareValues, | 52 (PLHashAllocOps *)NULL, (void *)NULL); |
59 PL_CompareValues, | 53 if ((PLHashTable *)NULL == tracker->table) { |
60 (PLHashAllocOps *)NULL, | 54 PZ_DestroyLock(tracker->lock); |
61 (void *)NULL); | 55 tracker->lock = (PZLock *)NULL; |
62 if( (PLHashTable *)NULL == tracker->table ) { | 56 return PR_FAILURE; |
63 PZ_DestroyLock(tracker->lock); | 57 } |
64 tracker->lock = (PZLock *)NULL; | |
65 return PR_FAILURE; | |
66 } | |
67 | 58 |
68 return PR_SUCCESS; | 59 return PR_SUCCESS; |
69 } | 60 } |
70 | 61 |
71 /* | 62 /* |
72 * nssPointerTracker_initialize | 63 * nssPointerTracker_initialize |
73 * | 64 * |
74 * This method is only present in debug builds. | 65 * This method is only present in debug builds. |
75 * | 66 * |
76 * This routine initializes an nssPointerTracker object. Note that | 67 * This routine initializes an nssPointerTracker object. Note that |
77 * the object must have been declared *static* to guarantee that it | 68 * the object must have been declared *static* to guarantee that it |
78 * is in a zeroed state initially. This routine is idempotent, and | 69 * is in a zeroed state initially. This routine is idempotent, and |
79 * may even be safely called by multiple threads simultaneously with | 70 * may even be safely called by multiple threads simultaneously with |
80 * the same argument. This routine returns a PRStatus value; if | 71 * the same argument. This routine returns a PRStatus value; if |
81 * successful, it will return PR_SUCCESS. On failure it will set an | 72 * successful, it will return PR_SUCCESS. On failure it will set an |
82 * error on the error stack and return PR_FAILURE. | 73 * error on the error stack and return PR_FAILURE. |
83 * | 74 * |
84 * The error may be one of the following values: | 75 * The error may be one of the following values: |
85 * NSS_ERROR_NO_MEMORY | 76 * NSS_ERROR_NO_MEMORY |
86 * | 77 * |
87 * Return value: | 78 * Return value: |
88 * PR_SUCCESS | 79 * PR_SUCCESS |
89 * PR_FAILURE | 80 * PR_FAILURE |
90 */ | 81 */ |
91 | 82 |
92 NSS_IMPLEMENT PRStatus | 83 NSS_IMPLEMENT PRStatus |
93 nssPointerTracker_initialize | 84 nssPointerTracker_initialize(nssPointerTracker *tracker) |
94 ( | |
95 nssPointerTracker *tracker | |
96 ) | |
97 { | 85 { |
98 PRStatus rv = PR_CallOnceWithArg(&tracker->once, trackerOnceFunc, tracker); | 86 PRStatus rv = PR_CallOnceWithArg(&tracker->once, trackerOnceFunc, tracker); |
99 if( PR_SUCCESS != rv ) { | 87 if (PR_SUCCESS != rv) { |
100 nss_SetError(NSS_ERROR_NO_MEMORY); | 88 nss_SetError(NSS_ERROR_NO_MEMORY); |
101 } | 89 } |
102 | 90 |
103 return rv; | 91 return rv; |
104 } | 92 } |
105 | 93 |
106 #ifdef DONT_DESTROY_EMPTY_TABLES | 94 #ifdef DONT_DESTROY_EMPTY_TABLES |
107 /* See same #ifdef below */ | 95 /* See same #ifdef below */ |
108 /* | 96 /* |
109 * count_entries | 97 * count_entries |
110 * | 98 * |
111 * This static routine is a PLHashEnumerator, as defined in plhash.h. | 99 * This static routine is a PLHashEnumerator, as defined in plhash.h. |
112 * It merely causes the enumeration function to count the number of | 100 * It merely causes the enumeration function to count the number of |
113 * entries. | 101 * entries. |
114 */ | 102 */ |
115 | 103 |
116 static PRIntn PR_CALLBACK | 104 static PRIntn PR_CALLBACK |
117 count_entries | 105 count_entries(PLHashEntry *he, PRIntn index, void *arg) |
118 ( | |
119 PLHashEntry *he, | |
120 PRIntn index, | |
121 void *arg | |
122 ) | |
123 { | 106 { |
124 return HT_ENUMERATE_NEXT; | 107 return HT_ENUMERATE_NEXT; |
125 } | 108 } |
126 #endif /* DONT_DESTROY_EMPTY_TABLES */ | 109 #endif /* DONT_DESTROY_EMPTY_TABLES */ |
127 | 110 |
128 /* | 111 /* |
129 * zero_once | 112 * zero_once |
130 * | 113 * |
131 * This is a guaranteed zeroed once block. It's used to help clear | 114 * This is a guaranteed zeroed once block. It's used to help clear |
132 * the tracker. | 115 * the tracker. |
133 */ | 116 */ |
134 | 117 |
135 static const PRCallOnceType zero_once; | 118 static const PRCallOnceType zero_once; |
136 | 119 |
137 /* | 120 /* |
138 * nssPointerTracker_finalize | 121 * nssPointerTracker_finalize |
139 * | 122 * |
140 * This method is only present in debug builds. | 123 * This method is only present in debug builds. |
141 * | 124 * |
142 * This routine returns the nssPointerTracker object to the pre- | 125 * This routine returns the nssPointerTracker object to the pre- |
143 * initialized state, releasing all resources used by the object. | 126 * initialized state, releasing all resources used by the object. |
144 * It will *NOT* destroy the objects being tracked by the pointer | 127 * It will *NOT* destroy the objects being tracked by the pointer |
145 * (should any remain), and therefore cannot be used to "sweep up" | 128 * (should any remain), and therefore cannot be used to "sweep up" |
146 * remaining objects. This routine returns a PRStatus value; if | 129 * remaining objects. This routine returns a PRStatus value; if |
147 * successful, it will return PR_SUCCES. On failure it will set an | 130 * successful, it will return PR_SUCCES. On failure it will set an |
148 * error on the error stack and return PR_FAILURE. If any objects | 131 * error on the error stack and return PR_FAILURE. If any objects |
149 * remain in the tracker when it is finalized, that will be treated | 132 * remain in the tracker when it is finalized, that will be treated |
150 * as an error. | 133 * as an error. |
151 * | 134 * |
152 * The error may be one of the following values: | 135 * The error may be one of the following values: |
153 * NSS_ERROR_INVALID_POINTER | 136 * NSS_ERROR_INVALID_POINTER |
154 * NSS_ERROR_TRACKER_NOT_INITIALIZED | 137 * NSS_ERROR_TRACKER_NOT_INITIALIZED |
155 * NSS_ERROR_TRACKER_NOT_EMPTY | 138 * NSS_ERROR_TRACKER_NOT_EMPTY |
156 * | 139 * |
157 * Return value: | 140 * Return value: |
158 * PR_SUCCESS | 141 * PR_SUCCESS |
159 * PR_FAILURE | 142 * PR_FAILURE |
160 */ | 143 */ |
161 | 144 |
162 NSS_IMPLEMENT PRStatus | 145 NSS_IMPLEMENT PRStatus |
163 nssPointerTracker_finalize | 146 nssPointerTracker_finalize(nssPointerTracker *tracker) |
164 ( | |
165 nssPointerTracker *tracker | |
166 ) | |
167 { | 147 { |
168 PZLock *lock; | 148 PZLock *lock; |
169 | 149 |
170 if( (nssPointerTracker *)NULL == tracker ) { | 150 if ((nssPointerTracker *)NULL == tracker) { |
171 nss_SetError(NSS_ERROR_INVALID_POINTER); | 151 nss_SetError(NSS_ERROR_INVALID_POINTER); |
172 return PR_FAILURE; | 152 return PR_FAILURE; |
173 } | 153 } |
174 | 154 |
175 if( (PZLock *)NULL == tracker->lock ) { | 155 if ((PZLock *)NULL == tracker->lock) { |
176 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); | 156 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); |
177 return PR_FAILURE; | 157 return PR_FAILURE; |
178 } | 158 } |
179 | 159 |
180 lock = tracker->lock; | 160 lock = tracker->lock; |
181 PZ_Lock(lock); | 161 PZ_Lock(lock); |
182 | 162 |
183 if( (PLHashTable *)NULL == tracker->table ) { | 163 if ((PLHashTable *)NULL == tracker->table) { |
184 PZ_Unlock(lock); | 164 PZ_Unlock(lock); |
185 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); | 165 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); |
186 return PR_FAILURE; | 166 return PR_FAILURE; |
187 } | 167 } |
188 | 168 |
189 #ifdef DONT_DESTROY_EMPTY_TABLES | 169 #ifdef DONT_DESTROY_EMPTY_TABLES |
190 /* | 170 /* |
191 * I changed my mind; I think we don't want this after all. | 171 * I changed my mind; I think we don't want this after all. |
192 * Comments? | 172 * Comments? |
193 */ | 173 */ |
194 count = PL_HashTableEnumerateEntries(tracker->table, | 174 count = PL_HashTableEnumerateEntries(tracker->table, count_entries, |
195 count_entries, | 175 (void *)NULL); |
196 (void *)NULL); | |
197 | 176 |
198 if( 0 != count ) { | 177 if (0 != count) { |
199 PZ_Unlock(lock); | 178 PZ_Unlock(lock); |
200 nss_SetError(NSS_ERROR_TRACKER_NOT_EMPTY); | 179 nss_SetError(NSS_ERROR_TRACKER_NOT_EMPTY); |
201 return PR_FAILURE; | 180 return PR_FAILURE; |
202 } | 181 } |
203 #endif /* DONT_DESTROY_EMPTY_TABLES */ | 182 #endif /* DONT_DESTROY_EMPTY_TABLES */ |
204 | 183 |
205 PL_HashTableDestroy(tracker->table); | 184 PL_HashTableDestroy(tracker->table); |
206 /* memset(tracker, 0, sizeof(nssPointerTracker)); */ | 185 /* memset(tracker, 0, sizeof(nssPointerTracker)); */ |
207 tracker->once = zero_once; | 186 tracker->once = zero_once; |
208 tracker->lock = (PZLock *)NULL; | 187 tracker->lock = (PZLock *)NULL; |
209 tracker->table = (PLHashTable *)NULL; | 188 tracker->table = (PLHashTable *)NULL; |
210 | 189 |
211 PZ_Unlock(lock); | 190 PZ_Unlock(lock); |
212 PZ_DestroyLock(lock); | 191 PZ_DestroyLock(lock); |
213 | 192 |
214 return PR_SUCCESS; | 193 return PR_SUCCESS; |
215 } | 194 } |
216 | 195 |
217 /* | 196 /* |
218 * nssPointerTracker_add | 197 * nssPointerTracker_add |
219 * | 198 * |
220 * This method is only present in debug builds. | 199 * This method is only present in debug builds. |
221 * | 200 * |
222 * This routine adds the specified pointer to the nssPointerTracker | 201 * This routine adds the specified pointer to the nssPointerTracker |
223 * object. It should be called in constructor objects to register | 202 * object. It should be called in constructor objects to register |
224 * new valid objects. The nssPointerTracker is threadsafe, but this | 203 * new valid objects. The nssPointerTracker is threadsafe, but this |
225 * call is not idempotent. This routine returns a PRStatus value; | 204 * call is not idempotent. This routine returns a PRStatus value; |
226 * if successful it will return PR_SUCCESS. On failure it will set | 205 * if successful it will return PR_SUCCESS. On failure it will set |
227 * an error on the error stack and return PR_FAILURE. | 206 * an error on the error stack and return PR_FAILURE. |
228 * | 207 * |
229 * The error may be one of the following values: | 208 * The error may be one of the following values: |
230 * NSS_ERROR_INVALID_POINTER | 209 * NSS_ERROR_INVALID_POINTER |
231 * NSS_ERROR_NO_MEMORY | 210 * NSS_ERROR_NO_MEMORY |
232 * NSS_ERROR_TRACKER_NOT_INITIALIZED | 211 * NSS_ERROR_TRACKER_NOT_INITIALIZED |
233 * NSS_ERROR_DUPLICATE_POINTER | 212 * NSS_ERROR_DUPLICATE_POINTER |
234 * | 213 * |
235 * Return value: | 214 * Return value: |
236 * PR_SUCCESS | 215 * PR_SUCCESS |
237 * PR_FAILURE | 216 * PR_FAILURE |
238 */ | 217 */ |
239 | 218 |
240 NSS_IMPLEMENT PRStatus | 219 NSS_IMPLEMENT PRStatus |
241 nssPointerTracker_add | 220 nssPointerTracker_add(nssPointerTracker *tracker, const void *pointer) |
242 ( | |
243 nssPointerTracker *tracker, | |
244 const void *pointer | |
245 ) | |
246 { | 221 { |
247 void *check; | 222 void *check; |
248 PLHashEntry *entry; | 223 PLHashEntry *entry; |
249 | 224 |
250 if( (nssPointerTracker *)NULL == tracker ) { | 225 if ((nssPointerTracker *)NULL == tracker) { |
251 nss_SetError(NSS_ERROR_INVALID_POINTER); | 226 nss_SetError(NSS_ERROR_INVALID_POINTER); |
252 return PR_FAILURE; | 227 return PR_FAILURE; |
253 } | 228 } |
254 | 229 |
255 if( (PZLock *)NULL == tracker->lock ) { | 230 if ((PZLock *)NULL == tracker->lock) { |
256 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); | 231 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); |
257 return PR_FAILURE; | 232 return PR_FAILURE; |
258 } | 233 } |
259 | 234 |
260 PZ_Lock(tracker->lock); | 235 PZ_Lock(tracker->lock); |
261 | 236 |
262 if( (PLHashTable *)NULL == tracker->table ) { | 237 if ((PLHashTable *)NULL == tracker->table) { |
| 238 PZ_Unlock(tracker->lock); |
| 239 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); |
| 240 return PR_FAILURE; |
| 241 } |
| 242 |
| 243 check = PL_HashTableLookup(tracker->table, pointer); |
| 244 if ((void *)NULL != check) { |
| 245 PZ_Unlock(tracker->lock); |
| 246 nss_SetError(NSS_ERROR_DUPLICATE_POINTER); |
| 247 return PR_FAILURE; |
| 248 } |
| 249 |
| 250 entry = PL_HashTableAdd(tracker->table, pointer, (void *)pointer); |
| 251 |
263 PZ_Unlock(tracker->lock); | 252 PZ_Unlock(tracker->lock); |
264 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); | |
265 return PR_FAILURE; | |
266 } | |
267 | 253 |
268 check = PL_HashTableLookup(tracker->table, pointer); | 254 if ((PLHashEntry *)NULL == entry) { |
269 if( (void *)NULL != check ) { | 255 nss_SetError(NSS_ERROR_NO_MEMORY); |
270 PZ_Unlock(tracker->lock); | 256 return PR_FAILURE; |
271 nss_SetError(NSS_ERROR_DUPLICATE_POINTER); | 257 } |
272 return PR_FAILURE; | |
273 } | |
274 | 258 |
275 entry = PL_HashTableAdd(tracker->table, pointer, (void *)pointer); | 259 return PR_SUCCESS; |
| 260 } |
276 | 261 |
277 PZ_Unlock(tracker->lock); | |
278 | |
279 if( (PLHashEntry *)NULL == entry ) { | |
280 nss_SetError(NSS_ERROR_NO_MEMORY); | |
281 return PR_FAILURE; | |
282 } | |
283 | |
284 return PR_SUCCESS; | |
285 } | |
286 | |
287 /* | 262 /* |
288 * nssPointerTracker_remove | 263 * nssPointerTracker_remove |
289 * | 264 * |
290 * This method is only present in debug builds. | 265 * This method is only present in debug builds. |
291 * | 266 * |
292 * This routine removes the specified pointer from the | 267 * This routine removes the specified pointer from the |
293 * nssPointerTracker object. It does not call any destructor for the | 268 * nssPointerTracker object. It does not call any destructor for the |
294 * object; rather, this should be called from the object's destructor. | 269 * object; rather, this should be called from the object's destructor. |
295 * The nssPointerTracker is threadsafe, but this call is not | 270 * The nssPointerTracker is threadsafe, but this call is not |
296 * idempotent. This routine returns a PRStatus value; if successful | 271 * idempotent. This routine returns a PRStatus value; if successful |
297 * it will return PR_SUCCESS. On failure it will set an error on the | 272 * it will return PR_SUCCESS. On failure it will set an error on the |
298 * error stack and return PR_FAILURE. | 273 * error stack and return PR_FAILURE. |
299 * | 274 * |
300 * The error may be one of the following values: | 275 * The error may be one of the following values: |
301 * NSS_ERROR_INVALID_POINTER | 276 * NSS_ERROR_INVALID_POINTER |
302 * NSS_ERROR_TRACKER_NOT_INITIALIZED | 277 * NSS_ERROR_TRACKER_NOT_INITIALIZED |
303 * NSS_ERROR_POINTER_NOT_REGISTERED | 278 * NSS_ERROR_POINTER_NOT_REGISTERED |
304 * | 279 * |
305 * Return value: | 280 * Return value: |
306 * PR_SUCCESS | 281 * PR_SUCCESS |
307 * PR_FAILURE | 282 * PR_FAILURE |
308 */ | 283 */ |
309 | 284 |
310 NSS_IMPLEMENT PRStatus | 285 NSS_IMPLEMENT PRStatus |
311 nssPointerTracker_remove | 286 nssPointerTracker_remove(nssPointerTracker *tracker, const void *pointer) |
312 ( | |
313 nssPointerTracker *tracker, | |
314 const void *pointer | |
315 ) | |
316 { | 287 { |
317 PRBool registered; | 288 PRBool registered; |
318 | 289 |
319 if( (nssPointerTracker *)NULL == tracker ) { | 290 if ((nssPointerTracker *)NULL == tracker) { |
320 nss_SetError(NSS_ERROR_INVALID_POINTER); | 291 nss_SetError(NSS_ERROR_INVALID_POINTER); |
321 return PR_FAILURE; | 292 return PR_FAILURE; |
322 } | 293 } |
323 | 294 |
324 if( (PZLock *)NULL == tracker->lock ) { | 295 if ((PZLock *)NULL == tracker->lock) { |
325 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); | 296 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); |
326 return PR_FAILURE; | 297 return PR_FAILURE; |
327 } | 298 } |
328 | 299 |
329 PZ_Lock(tracker->lock); | 300 PZ_Lock(tracker->lock); |
330 | 301 |
331 if( (PLHashTable *)NULL == tracker->table ) { | 302 if ((PLHashTable *)NULL == tracker->table) { |
| 303 PZ_Unlock(tracker->lock); |
| 304 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); |
| 305 return PR_FAILURE; |
| 306 } |
| 307 |
| 308 registered = PL_HashTableRemove(tracker->table, pointer); |
332 PZ_Unlock(tracker->lock); | 309 PZ_Unlock(tracker->lock); |
333 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); | |
334 return PR_FAILURE; | |
335 } | |
336 | 310 |
337 registered = PL_HashTableRemove(tracker->table, pointer); | 311 if (!registered) { |
338 PZ_Unlock(tracker->lock); | 312 nss_SetError(NSS_ERROR_POINTER_NOT_REGISTERED); |
| 313 return PR_FAILURE; |
| 314 } |
339 | 315 |
340 if( !registered ) { | 316 return PR_SUCCESS; |
341 nss_SetError(NSS_ERROR_POINTER_NOT_REGISTERED); | |
342 return PR_FAILURE; | |
343 } | |
344 | |
345 return PR_SUCCESS; | |
346 } | 317 } |
347 | 318 |
348 /* | 319 /* |
349 * nssPointerTracker_verify | 320 * nssPointerTracker_verify |
350 * | 321 * |
351 * This method is only present in debug builds. | 322 * This method is only present in debug builds. |
352 * | 323 * |
353 * This routine verifies that the specified pointer has been registered | 324 * This routine verifies that the specified pointer has been registered |
354 * with the nssPointerTracker object. The nssPointerTracker object is | 325 * with the nssPointerTracker object. The nssPointerTracker object is |
355 * threadsafe, and this call may be safely called from multiple threads | 326 * threadsafe, and this call may be safely called from multiple threads |
356 * simultaneously with the same arguments. This routine returns a | 327 * simultaneously with the same arguments. This routine returns a |
357 * PRStatus value; if the pointer is registered this will return | 328 * PRStatus value; if the pointer is registered this will return |
358 * PR_SUCCESS. Otherwise it will set an error on the error stack and | 329 * PR_SUCCESS. Otherwise it will set an error on the error stack and |
359 * return PR_FAILURE. Although the error is suitable for leaving on | 330 * return PR_FAILURE. Although the error is suitable for leaving on |
360 * the stack, callers may wish to augment the information available by | 331 * the stack, callers may wish to augment the information available by |
361 * placing a more type-specific error on the stack. | 332 * placing a more type-specific error on the stack. |
362 * | 333 * |
363 * The error may be one of the following values: | 334 * The error may be one of the following values: |
364 * NSS_ERROR_INVALID_POINTER | 335 * NSS_ERROR_INVALID_POINTER |
365 * NSS_ERROR_TRACKER_NOT_INITIALIZED | 336 * NSS_ERROR_TRACKER_NOT_INITIALIZED |
366 * NSS_ERROR_POINTER_NOT_REGISTERED | 337 * NSS_ERROR_POINTER_NOT_REGISTERED |
367 * | 338 * |
368 * Return value: | 339 * Return value: |
369 * PR_SUCCESS | 340 * PR_SUCCESS |
370 * PR_FAILRUE | 341 * PR_FAILRUE |
371 */ | 342 */ |
372 | 343 |
373 NSS_IMPLEMENT PRStatus | 344 NSS_IMPLEMENT PRStatus |
374 nssPointerTracker_verify | 345 nssPointerTracker_verify(nssPointerTracker *tracker, const void *pointer) |
375 ( | |
376 nssPointerTracker *tracker, | |
377 const void *pointer | |
378 ) | |
379 { | 346 { |
380 void *check; | 347 void *check; |
381 | 348 |
382 if( (nssPointerTracker *)NULL == tracker ) { | 349 if ((nssPointerTracker *)NULL == tracker) { |
383 nss_SetError(NSS_ERROR_INVALID_POINTER); | 350 nss_SetError(NSS_ERROR_INVALID_POINTER); |
384 return PR_FAILURE; | 351 return PR_FAILURE; |
385 } | 352 } |
386 | 353 |
387 if( (PZLock *)NULL == tracker->lock ) { | 354 if ((PZLock *)NULL == tracker->lock) { |
388 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); | 355 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); |
389 return PR_FAILURE; | 356 return PR_FAILURE; |
390 } | 357 } |
391 | 358 |
392 PZ_Lock(tracker->lock); | 359 PZ_Lock(tracker->lock); |
393 | 360 |
394 if( (PLHashTable *)NULL == tracker->table ) { | 361 if ((PLHashTable *)NULL == tracker->table) { |
| 362 PZ_Unlock(tracker->lock); |
| 363 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); |
| 364 return PR_FAILURE; |
| 365 } |
| 366 |
| 367 check = PL_HashTableLookup(tracker->table, pointer); |
395 PZ_Unlock(tracker->lock); | 368 PZ_Unlock(tracker->lock); |
396 nss_SetError(NSS_ERROR_TRACKER_NOT_INITIALIZED); | |
397 return PR_FAILURE; | |
398 } | |
399 | 369 |
400 check = PL_HashTableLookup(tracker->table, pointer); | 370 if ((void *)NULL == check) { |
401 PZ_Unlock(tracker->lock); | 371 nss_SetError(NSS_ERROR_POINTER_NOT_REGISTERED); |
| 372 return PR_FAILURE; |
| 373 } |
402 | 374 |
403 if( (void *)NULL == check ) { | 375 return PR_SUCCESS; |
404 nss_SetError(NSS_ERROR_POINTER_NOT_REGISTERED); | |
405 return PR_FAILURE; | |
406 } | |
407 | |
408 return PR_SUCCESS; | |
409 } | 376 } |
410 | 377 |
411 #endif /* DEBUG */ | 378 #endif /* DEBUG */ |
OLD | NEW |