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

Side by Side Diff: mozilla/security/nss/lib/base/base.h

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/base/arena.c ('k') | mozilla/security/nss/lib/base/baset.h » ('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 #ifndef BASE_H
6 #define BASE_H
7
8 #ifdef DEBUG
9 static const char BASE_CVS_ID[] = "@(#) $RCSfile: base.h,v $ $Revision: 1.21 $ $ Date: 2012/04/25 14:49:25 $";
10 #endif /* DEBUG */
11
12 /*
13 * base.h
14 *
15 * This header file contains basic prototypes and preprocessor
16 * definitions used throughout nss but not available publicly.
17 */
18
19 #ifndef BASET_H
20 #include "baset.h"
21 #endif /* BASET_H */
22
23 #ifndef NSSBASE_H
24 #include "nssbase.h"
25 #endif /* NSSBASE_H */
26
27 #include "plhash.h"
28
29 PR_BEGIN_EXTERN_C
30
31 /*
32 * NSSArena
33 *
34 * The nonpublic methods relating to this type are:
35 *
36 * nssArena_Create -- constructor
37 * nssArena_Destroy
38 * nssArena_Mark
39 * nssArena_Release
40 * nssArena_Unmark
41 *
42 * nss_ZAlloc
43 * nss_ZFreeIf
44 * nss_ZRealloc
45 *
46 * Additionally, there are some preprocessor macros:
47 *
48 * nss_ZNEW
49 * nss_ZNEWARRAY
50 *
51 * In debug builds, the following calls are available:
52 *
53 * nssArena_verifyPointer
54 * nssArena_registerDestructor
55 * nssArena_deregisterDestructor
56 *
57 * The following preprocessor macro is also always available:
58 *
59 * nssArena_VERIFYPOINTER
60 *
61 * A constant PLHashAllocOps structure is available for users
62 * of the NSPL PLHashTable routines.
63 *
64 * nssArenaHashAllocOps
65 */
66
67 /*
68 * nssArena_Create
69 *
70 * This routine creates a new memory arena. This routine may return
71 * NULL upon error, in which case it will have set an error on the
72 * error stack.
73 *
74 * The error may be one of the following values:
75 * NSS_ERROR_NO_MEMORY
76 *
77 * Return value:
78 * NULL upon error
79 * A pointer to an NSSArena upon success
80 */
81
82 /*
83 * XXX fgmr
84 * Arenas can be named upon creation; this is mostly of use when
85 * debugging. Should we expose that here, allowing an optional
86 * "const char *name" argument? Should the public version of this
87 * call (NSSArena_Create) have it too?
88 */
89
90 NSS_EXTERN NSSArena *
91 nssArena_Create
92 (
93 void
94 );
95
96 extern const NSSError NSS_ERROR_NO_MEMORY;
97
98 /*
99 * nssArena_Destroy
100 *
101 * This routine will destroy the specified arena, freeing all memory
102 * allocated from it. This routine returns a PRStatus value; if
103 * successful, it will return PR_SUCCESS. If unsuccessful, it will
104 * set an error on the error stack and return PR_FAILURE.
105 *
106 * The error may be one of the following values:
107 * NSS_ERROR_INVALID_ARENA
108 *
109 * Return value:
110 * PR_SUCCESS
111 * PR_FAILURE
112 */
113
114 NSS_EXTERN PRStatus
115 nssArena_Destroy
116 (
117 NSSArena *arena
118 );
119
120 extern const NSSError NSS_ERROR_INVALID_ARENA;
121
122 /*
123 * nssArena_Mark
124 *
125 * This routine "marks" the current state of an arena. Space
126 * allocated after the arena has been marked can be freed by
127 * releasing the arena back to the mark with nssArena_Release,
128 * or committed by calling nssArena_Unmark. When successful,
129 * this routine returns a valid nssArenaMark pointer. This
130 * routine may return NULL upon error, in which case it will
131 * have set an error on the error stack.
132 *
133 * The error may be one of the following values:
134 * NSS_ERROR_INVALID_ARENA
135 * NSS_ERROR_NO_MEMORY
136 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
137 *
138 * Return value:
139 * NULL upon failure
140 * An nssArenaMark pointer upon success
141 */
142
143 NSS_EXTERN nssArenaMark *
144 nssArena_Mark
145 (
146 NSSArena *arena
147 );
148
149 extern const NSSError NSS_ERROR_INVALID_ARENA;
150 extern const NSSError NSS_ERROR_NO_MEMORY;
151 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD;
152
153 /*
154 * nssArena_Release
155 *
156 * This routine invalidates and releases all memory allocated from
157 * the specified arena after the point at which the specified mark
158 * was obtained. This routine returns a PRStatus value; if successful,
159 * it will return PR_SUCCESS. If unsuccessful, it will set an error
160 * on the error stack and return PR_FAILURE.
161 *
162 * The error may be one of the following values:
163 * NSS_ERROR_INVALID_ARENA
164 * NSS_ERROR_INVALID_ARENA_MARK
165 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
166 *
167 * Return value:
168 * PR_SUCCESS
169 * PR_FAILURE
170 */
171
172 NSS_EXTERN PRStatus
173 nssArena_Release
174 (
175 NSSArena *arena,
176 nssArenaMark *arenaMark
177 );
178
179 extern const NSSError NSS_ERROR_INVALID_ARENA;
180 extern const NSSError NSS_ERROR_INVALID_ARENA_MARK;
181
182 /*
183 * nssArena_Unmark
184 *
185 * This routine "commits" the indicated mark and any marks after
186 * it, making them unreleasable. Note that any earlier marks can
187 * still be released, and such a release will invalidate these
188 * later unmarked regions. If an arena is to be safely shared by
189 * more than one thread, all marks must be either released or
190 * unmarked. This routine returns a PRStatus value; if successful,
191 * it will return PR_SUCCESS. If unsuccessful, it will set an error
192 * on the error stack and return PR_FAILURE.
193 *
194 * The error may be one of the following values:
195 * NSS_ERROR_INVALID_ARENA
196 * NSS_ERROR_INVALID_ARENA_MARK
197 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
198 *
199 * Return value:
200 * PR_SUCCESS
201 * PR_FAILURE
202 */
203
204 NSS_EXTERN PRStatus
205 nssArena_Unmark
206 (
207 NSSArena *arena,
208 nssArenaMark *arenaMark
209 );
210
211 extern const NSSError NSS_ERROR_INVALID_ARENA;
212 extern const NSSError NSS_ERROR_INVALID_ARENA_MARK;
213 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD;
214
215 #ifdef ARENA_DESTRUCTOR_LIST
216
217 /*
218 * nssArena_registerDestructor
219 *
220 * This routine stores a pointer to a callback and an arbitrary
221 * pointer-sized argument in the arena, at the current point in
222 * the mark stack. If the arena is destroyed, or an "earlier"
223 * mark is released, then this destructor will be called at that
224 * time. Note that the destructor will be called with the arena
225 * locked, which means the destructor may free memory in that
226 * arena, but it may not allocate or cause to be allocated any
227 * memory. This callback facility was included to support our
228 * debug-version pointer-tracker feature; overuse runs counter to
229 * the the original intent of arenas. This routine returns a
230 * PRStatus value; if successful, it will return PR_SUCCESS. If
231 * unsuccessful, it will set an error on the error stack and
232 * return PR_FAILURE.
233 *
234 * The error may be one of the following values:
235 * NSS_ERROR_INVALID_ARENA
236 * NSS_ERROR_NO_MEMORY
237 *
238 * Return value:
239 * PR_SUCCESS
240 * PR_FAILURE
241 */
242
243 NSS_EXTERN PRStatus
244 nssArena_registerDestructor
245 (
246 NSSArena *arena,
247 void (*destructor)(void *argument),
248 void *arg
249 );
250
251 extern const NSSError NSS_ERROR_INVALID_ARENA;
252 extern const NSSError NSS_ERROR_NO_MEMORY;
253
254 /*
255 * nssArena_deregisterDestructor
256 *
257 * This routine will remove the first destructor in the specified
258 * arena which has the specified destructor and argument values.
259 * The destructor will not be called. This routine returns a
260 * PRStatus value; if successful, it will return PR_SUCCESS. If
261 * unsuccessful, it will set an error on the error stack and
262 * return PR_FAILURE.
263 *
264 * The error may be one of the following values:
265 * NSS_ERROR_INVALID_ARENA
266 * NSS_ERROR_NOT_FOUND
267 *
268 * Return value:
269 * PR_SUCCESS
270 * PR_FAILURE
271 */
272
273 NSS_EXTERN PRStatus
274 nssArena_deregisterDestructor
275 (
276 NSSArena *arena,
277 void (*destructor)(void *argument),
278 void *arg
279 );
280
281 extern const NSSError NSS_ERROR_INVALID_ITEM;
282 extern const NSSError NSS_ERROR_INVALID_ARENA;
283 extern const NSSError NSS_ERROR_NOT_FOUND;
284
285 #endif /* ARENA_DESTRUCTOR_LIST */
286
287 /*
288 * nss_ZAlloc
289 *
290 * This routine allocates and zeroes a section of memory of the
291 * size, and returns to the caller a pointer to that memory. If
292 * the optional arena argument is non-null, the memory will be
293 * obtained from that arena; otherwise, the memory will be obtained
294 * from the heap. This routine may return NULL upon error, in
295 * which case it will have set an error upon the error stack. The
296 * value specified for size may be zero; in which case a valid
297 * zero-length block of memory will be allocated. This block may
298 * be expanded by calling nss_ZRealloc.
299 *
300 * The error may be one of the following values:
301 * NSS_ERROR_INVALID_ARENA
302 * NSS_ERROR_NO_MEMORY
303 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
304 *
305 * Return value:
306 * NULL upon error
307 * A pointer to the new segment of zeroed memory
308 */
309
310 NSS_EXTERN void *
311 nss_ZAlloc
312 (
313 NSSArena *arenaOpt,
314 PRUint32 size
315 );
316
317 extern const NSSError NSS_ERROR_INVALID_ARENA;
318 extern const NSSError NSS_ERROR_NO_MEMORY;
319 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD;
320
321 /*
322 * nss_ZFreeIf
323 *
324 * If the specified pointer is non-null, then the region of memory
325 * to which it points -- which must have been allocated with
326 * nss_ZAlloc -- will be zeroed and released. This routine
327 * returns a PRStatus value; if successful, it will return PR_SUCCESS.
328 * If unsuccessful, it will set an error on the error stack and return
329 * PR_FAILURE.
330 *
331 * The error may be one of the following values:
332 * NSS_ERROR_INVALID_POINTER
333 *
334 * Return value:
335 * PR_SUCCESS
336 * PR_FAILURE
337 */
338
339 NSS_EXTERN PRStatus
340 nss_ZFreeIf
341 (
342 void *pointer
343 );
344
345 extern const NSSError NSS_ERROR_INVALID_POINTER;
346
347 /*
348 * nss_ZRealloc
349 *
350 * This routine reallocates a block of memory obtained by calling
351 * nss_ZAlloc or nss_ZRealloc. The portion of memory
352 * between the new and old sizes -- which is either being newly
353 * obtained or released -- is in either case zeroed. This routine
354 * may return NULL upon failure, in which case it will have placed
355 * an error on the error stack.
356 *
357 * The error may be one of the following values:
358 * NSS_ERROR_INVALID_POINTER
359 * NSS_ERROR_NO_MEMORY
360 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
361 *
362 * Return value:
363 * NULL upon error
364 * A pointer to the replacement segment of memory
365 */
366
367 NSS_EXTERN void *
368 nss_ZRealloc
369 (
370 void *pointer,
371 PRUint32 newSize
372 );
373
374 extern const NSSError NSS_ERROR_INVALID_POINTER;
375 extern const NSSError NSS_ERROR_NO_MEMORY;
376 extern const NSSError NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD;
377
378 /*
379 * nss_ZNEW
380 *
381 * This preprocessor macro will allocate memory for a new object
382 * of the specified type with nss_ZAlloc, and will cast the
383 * return value appropriately. If the optional arena argument is
384 * non-null, the memory will be obtained from that arena; otherwise,
385 * the memory will be obtained from the heap. This routine may
386 * return NULL upon error, in which case it will have set an error
387 * upon the error stack.
388 *
389 * The error may be one of the following values:
390 * NSS_ERROR_INVALID_ARENA
391 * NSS_ERROR_NO_MEMORY
392 *
393 * Return value:
394 * NULL upon error
395 * A pointer to the new segment of zeroed memory
396 */
397
398 /* The following line exceeds 72 characters, but emacs screws up if I split it. */
399 #define nss_ZNEW(arenaOpt, type) ((type *)nss_ZAlloc((arenaOpt), sizeof(type)))
400
401 /*
402 * nss_ZNEWARRAY
403 *
404 * This preprocessor macro will allocate memory for an array of
405 * new objects, and will cast the return value appropriately.
406 * If the optional arena argument is non-null, the memory will
407 * be obtained from that arena; otherwise, the memory will be
408 * obtained from the heap. This routine may return NULL upon
409 * error, in which case it will have set an error upon the error
410 * stack. The array size may be specified as zero.
411 *
412 * The error may be one of the following values:
413 * NSS_ERROR_INVALID_ARENA
414 * NSS_ERROR_NO_MEMORY
415 *
416 * Return value:
417 * NULL upon error
418 * A pointer to the new segment of zeroed memory
419 */
420
421 /* The following line exceeds 72 characters, but emacs screws up if I split it. */
422 #define nss_ZNEWARRAY(arenaOpt, type, quantity) ((type *)nss_ZAlloc((arenaOpt), sizeof(type) * (quantity)))
423
424 /*
425 * nss_ZREALLOCARRAY
426 *
427 * This preprocessor macro will reallocate memory for an array of
428 * new objects, and will cast the return value appropriately.
429 * This routine may return NULL upon error, in which case it will
430 * have set an error upon the error stack.
431 *
432 * The error may be one of the following values:
433 * NSS_ERROR_INVALID_POINTER
434 * NSS_ERROR_NO_MEMORY
435 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
436 *
437 * Return value:
438 * NULL upon error
439 * A pointer to the replacement segment of memory
440 */
441 #define nss_ZREALLOCARRAY(p, type, quantity) ((type *)nss_ZRealloc((p), sizeof(t ype) * (quantity)))
442
443 /*
444 * nssArena_verifyPointer
445 *
446 * This method is only present in debug builds.
447 *
448 * If the specified pointer is a valid pointer to an NSSArena object,
449 * this routine will return PR_SUCCESS. Otherwise, it will put an
450 * error on the error stack and return PR_FAILURE.
451 *
452 * The error may be one of the following values:
453 * NSS_ERROR_INVALID_ARENA
454 *
455 * Return value:
456 * PR_SUCCESS if the pointer is valid
457 * PR_FAILURE if it isn't
458 */
459
460 #ifdef DEBUG
461 NSS_EXTERN PRStatus
462 nssArena_verifyPointer
463 (
464 const NSSArena *arena
465 );
466
467 extern const NSSError NSS_ERROR_INVALID_ARENA;
468 #endif /* DEBUG */
469
470 /*
471 * nssArena_VERIFYPOINTER
472 *
473 * This macro is always available. In debug builds it will call
474 * nssArena_verifyPointer; in non-debug builds, it will merely
475 * check that the pointer is not null. Note that in non-debug
476 * builds it cannot place an error on the error stack.
477 *
478 * Return value:
479 * PR_SUCCESS if the pointer is valid
480 * PR_FAILURE if it isn't
481 */
482
483 #ifdef DEBUG
484 #define nssArena_VERIFYPOINTER(p) nssArena_verifyPointer(p)
485 #else /* DEBUG */
486 /* The following line exceeds 72 characters, but emacs screws up if I split it. */
487 #define nssArena_VERIFYPOINTER(p) (((NSSArena *)NULL == (p))?PR_FAILURE:PR_SUCCE SS)
488 #endif /* DEBUG */
489
490 /*
491 * Private function to be called by NSS_Shutdown to cleanup nssArena
492 * bookkeeping.
493 */
494 extern PRStatus
495 nssArena_Shutdown(void);
496
497 /*
498 * nssArenaHashAllocOps
499 *
500 * This constant structure contains allocation callbacks designed for
501 * use with the NSPL routine PL_NewHashTable. For example:
502 *
503 * NSSArena *hashTableArena = nssArena_Create();
504 * PLHashTable *t = PL_NewHashTable(n, hasher, key_compare,
505 * value_compare, nssArenaHashAllocOps, hashTableArena);
506 */
507
508 NSS_EXTERN_DATA PLHashAllocOps nssArenaHashAllocOps;
509
510 /*
511 * The error stack
512 *
513 * The nonpublic methods relating to the error stack are:
514 *
515 * nss_SetError
516 * nss_ClearErrorStack
517 */
518
519 /*
520 * nss_SetError
521 *
522 * This routine places a new error code on the top of the calling
523 * thread's error stack. Calling this routine wiht an error code
524 * of zero will clear the error stack.
525 */
526
527 NSS_EXTERN void
528 nss_SetError
529 (
530 PRUint32 error
531 );
532
533 /*
534 * nss_ClearErrorStack
535 *
536 * This routine clears the calling thread's error stack.
537 */
538
539 NSS_EXTERN void
540 nss_ClearErrorStack
541 (
542 void
543 );
544
545 /*
546 * nss_DestroyErrorStack
547 *
548 * This routine frees the calling thread's error stack.
549 */
550
551 NSS_EXTERN void
552 nss_DestroyErrorStack
553 (
554 void
555 );
556
557 /*
558 * NSSItem
559 *
560 * nssItem_Create
561 * nssItem_Duplicate
562 * nssItem_Equal
563 */
564
565 NSS_EXTERN NSSItem *
566 nssItem_Create
567 (
568 NSSArena *arenaOpt,
569 NSSItem *rvOpt,
570 PRUint32 length,
571 const void *data
572 );
573
574 NSS_EXTERN void
575 nssItem_Destroy
576 (
577 NSSItem *item
578 );
579
580 NSS_EXTERN NSSItem *
581 nssItem_Duplicate
582 (
583 NSSItem *obj,
584 NSSArena *arenaOpt,
585 NSSItem *rvOpt
586 );
587
588 NSS_EXTERN PRBool
589 nssItem_Equal
590 (
591 const NSSItem *one,
592 const NSSItem *two,
593 PRStatus *statusOpt
594 );
595
596 /*
597 * NSSUTF8
598 *
599 * nssUTF8_CaseIgnoreMatch
600 * nssUTF8_Duplicate
601 * nssUTF8_Size
602 * nssUTF8_Length
603 * nssUTF8_CopyIntoFixedBuffer
604 */
605
606 /*
607 * nssUTF8_CaseIgnoreMatch
608 *
609 * Returns true if the two UTF8-encoded strings pointed to by the
610 * two specified NSSUTF8 pointers differ only in typcase.
611 *
612 * The error may be one of the following values:
613 * NSS_ERROR_INVALID_POINTER
614 *
615 * Return value:
616 * PR_TRUE if the strings match, ignoring case
617 * PR_FALSE if they don't
618 * PR_FALSE upon error
619 */
620
621 NSS_EXTERN PRBool
622 nssUTF8_CaseIgnoreMatch
623 (
624 const NSSUTF8 *a,
625 const NSSUTF8 *b,
626 PRStatus *statusOpt
627 );
628
629 /*
630 * nssUTF8_Duplicate
631 *
632 * This routine duplicates the UTF8-encoded string pointed to by the
633 * specified NSSUTF8 pointer. If the optional arenaOpt argument is
634 * not null, the memory required will be obtained from that arena;
635 * otherwise, the memory required will be obtained from the heap.
636 * A pointer to the new string will be returned. In case of error,
637 * an error will be placed on the error stack and NULL will be
638 * returned.
639 *
640 * The error may be one of the following values:
641 * NSS_ERROR_INVALID_POINTER
642 * NSS_ERROR_INVALID_ARENA
643 * NSS_ERROR_NO_MEMORY
644 */
645
646 NSS_EXTERN NSSUTF8 *
647 nssUTF8_Duplicate
648 (
649 const NSSUTF8 *s,
650 NSSArena *arenaOpt
651 );
652
653 /*
654 * nssUTF8_PrintableMatch
655 *
656 * Returns true if the two Printable strings pointed to by the
657 * two specified NSSUTF8 pointers match when compared with the
658 * rules for Printable String (leading and trailing spaces are
659 * disregarded, extents of whitespace match irregardless of length,
660 * and case is not significant), then PR_TRUE will be returned.
661 * Otherwise, PR_FALSE will be returned. Upon failure, PR_FALSE
662 * will be returned. If the optional statusOpt argument is not
663 * NULL, then PR_SUCCESS or PR_FAILURE will be stored in that
664 * location.
665 *
666 * The error may be one of the following values:
667 * NSS_ERROR_INVALID_POINTER
668 *
669 * Return value:
670 * PR_TRUE if the strings match, ignoring case
671 * PR_FALSE if they don't
672 * PR_FALSE upon error
673 */
674
675 NSS_EXTERN PRBool
676 nssUTF8_PrintableMatch
677 (
678 const NSSUTF8 *a,
679 const NSSUTF8 *b,
680 PRStatus *statusOpt
681 );
682
683 /*
684 * nssUTF8_Size
685 *
686 * This routine returns the length in bytes (including the terminating
687 * null) of the UTF8-encoded string pointed to by the specified
688 * NSSUTF8 pointer. Zero is returned on error.
689 *
690 * The error may be one of the following values:
691 * NSS_ERROR_INVALID_POINTER
692 * NSS_ERROR_VALUE_TOO_LARGE
693 *
694 * Return value:
695 * nonzero size of the string
696 * 0 on error
697 */
698
699 NSS_EXTERN PRUint32
700 nssUTF8_Size
701 (
702 const NSSUTF8 *s,
703 PRStatus *statusOpt
704 );
705
706 extern const NSSError NSS_ERROR_INVALID_POINTER;
707 extern const NSSError NSS_ERROR_VALUE_TOO_LARGE;
708
709 /*
710 * nssUTF8_Length
711 *
712 * This routine returns the length in characters (not including the
713 * terminating null) of the UTF8-encoded string pointed to by the
714 * specified NSSUTF8 pointer.
715 *
716 * The error may be one of the following values:
717 * NSS_ERROR_INVALID_POINTER
718 * NSS_ERROR_VALUE_TOO_LARGE
719 * NSS_ERROR_INVALID_STRING
720 *
721 * Return value:
722 * length of the string (which may be zero)
723 * 0 on error
724 */
725
726 NSS_EXTERN PRUint32
727 nssUTF8_Length
728 (
729 const NSSUTF8 *s,
730 PRStatus *statusOpt
731 );
732
733 extern const NSSError NSS_ERROR_INVALID_POINTER;
734 extern const NSSError NSS_ERROR_VALUE_TOO_LARGE;
735 extern const NSSError NSS_ERROR_INVALID_STRING;
736
737 /*
738 * nssUTF8_Create
739 *
740 * This routine creates a UTF8 string from a string in some other
741 * format. Some types of string may include embedded null characters,
742 * so for them the length parameter must be used. For string types
743 * that are null-terminated, the length parameter is optional; if it
744 * is zero, it will be ignored. If the optional arena argument is
745 * non-null, the memory used for the new string will be obtained from
746 * that arena, otherwise it will be obtained from the heap. This
747 * routine may return NULL upon error, in which case it will have
748 * placed an error on the error stack.
749 *
750 * The error may be one of the following:
751 * NSS_ERROR_INVALID_POINTER
752 * NSS_ERROR_NO_MEMORY
753 * NSS_ERROR_UNSUPPORTED_TYPE
754 *
755 * Return value:
756 * NULL upon error
757 * A non-null pointer to a new UTF8 string otherwise
758 */
759
760 NSS_EXTERN NSSUTF8 *
761 nssUTF8_Create
762 (
763 NSSArena *arenaOpt,
764 nssStringType type,
765 const void *inputString,
766 PRUint32 size /* in bytes, not characters */
767 );
768
769 extern const NSSError NSS_ERROR_INVALID_POINTER;
770 extern const NSSError NSS_ERROR_NO_MEMORY;
771 extern const NSSError NSS_ERROR_UNSUPPORTED_TYPE;
772
773 NSS_EXTERN NSSItem *
774 nssUTF8_GetEncoding
775 (
776 NSSArena *arenaOpt,
777 NSSItem *rvOpt,
778 nssStringType type,
779 NSSUTF8 *string
780 );
781
782 /*
783 * nssUTF8_CopyIntoFixedBuffer
784 *
785 * This will copy a UTF8 string into a fixed-length buffer, making
786 * sure that the all characters are valid. Any remaining space will
787 * be padded with the specified ASCII character, typically either
788 * null or space.
789 *
790 * Blah, blah, blah.
791 */
792
793 extern const NSSError NSS_ERROR_INVALID_POINTER;
794 extern const NSSError NSS_ERROR_INVALID_ARGUMENT;
795
796 NSS_EXTERN PRStatus
797 nssUTF8_CopyIntoFixedBuffer
798 (
799 NSSUTF8 *string,
800 char *buffer,
801 PRUint32 bufferSize,
802 char pad
803 );
804
805 /*
806 * nssUTF8_Equal
807 *
808 */
809
810 NSS_EXTERN PRBool
811 nssUTF8_Equal
812 (
813 const NSSUTF8 *a,
814 const NSSUTF8 *b,
815 PRStatus *statusOpt
816 );
817
818 /*
819 * nssList
820 *
821 * The goal is to provide a simple, optionally threadsafe, linked list
822 * class. Since NSS did not seem to use the circularity of PRCList
823 * much before, this provides a list that appears to be a linear,
824 * NULL-terminated list.
825 */
826
827 /*
828 * nssList_Create
829 *
830 * If threadsafe is true, the list will be locked during modifications
831 * and traversals.
832 */
833 NSS_EXTERN nssList *
834 nssList_Create
835 (
836 NSSArena *arenaOpt,
837 PRBool threadSafe
838 );
839
840 /*
841 * nssList_Destroy
842 */
843 NSS_EXTERN PRStatus
844 nssList_Destroy
845 (
846 nssList *list
847 );
848
849 NSS_EXTERN void
850 nssList_Clear
851 (
852 nssList *list,
853 nssListElementDestructorFunc destructor
854 );
855
856 /*
857 * nssList_SetCompareFunction
858 *
859 * By default, two list elements will be compared by comparing their
860 * data pointers. By setting this function, the user can control
861 * how elements are compared.
862 */
863 NSS_EXTERN void
864 nssList_SetCompareFunction
865 (
866 nssList *list,
867 nssListCompareFunc compareFunc
868 );
869
870 /*
871 * nssList_SetSortFunction
872 *
873 * Sort function to use for an ordered list.
874 */
875 NSS_EXTERN void
876 nssList_SetSortFunction
877 (
878 nssList *list,
879 nssListSortFunc sortFunc
880 );
881
882 /*
883 * nssList_Add
884 */
885 NSS_EXTERN PRStatus
886 nssList_Add
887 (
888 nssList *list,
889 void *data
890 );
891
892 /*
893 * nssList_AddUnique
894 *
895 * This will use the compare function to see if the element is already
896 * in the list.
897 */
898 NSS_EXTERN PRStatus
899 nssList_AddUnique
900 (
901 nssList *list,
902 void *data
903 );
904
905 /*
906 * nssList_Remove
907 *
908 * Uses the compare function to locate the element and remove it.
909 */
910 NSS_EXTERN PRStatus
911 nssList_Remove(nssList *list, void *data);
912
913 /*
914 * nssList_Get
915 *
916 * Uses the compare function to locate an element. Also serves as
917 * nssList_Exists.
918 */
919 NSS_EXTERN void *
920 nssList_Get
921 (
922 nssList *list,
923 void *data
924 );
925
926 /*
927 * nssList_Count
928 */
929 NSS_EXTERN PRUint32
930 nssList_Count
931 (
932 nssList *list
933 );
934
935 /*
936 * nssList_GetArray
937 *
938 * Fill rvArray, up to maxElements, with elements in the list. The
939 * array is NULL-terminated, so its allocated size must be maxElements + 1.
940 */
941 NSS_EXTERN PRStatus
942 nssList_GetArray
943 (
944 nssList *list,
945 void **rvArray,
946 PRUint32 maxElements
947 );
948
949 /*
950 * nssList_CreateIterator
951 *
952 * Create an iterator for list traversal.
953 */
954 NSS_EXTERN nssListIterator *
955 nssList_CreateIterator
956 (
957 nssList *list
958 );
959
960 NSS_EXTERN nssList *
961 nssList_Clone
962 (
963 nssList *list
964 );
965
966 /*
967 * nssListIterator_Destroy
968 */
969 NSS_EXTERN void
970 nssListIterator_Destroy
971 (
972 nssListIterator *iter
973 );
974
975 /*
976 * nssListIterator_Start
977 *
978 * Begin a list iteration. After this call, if the list is threadSafe,
979 * the list is *locked*.
980 */
981 NSS_EXTERN void *
982 nssListIterator_Start
983 (
984 nssListIterator *iter
985 );
986
987 /*
988 * nssListIterator_Next
989 *
990 * Continue a list iteration.
991 */
992 NSS_EXTERN void *
993 nssListIterator_Next
994 (
995 nssListIterator *iter
996 );
997
998 /*
999 * nssListIterator_Finish
1000 *
1001 * Complete a list iteration. This *must* be called in order for the
1002 * lock to be released.
1003 */
1004 NSS_EXTERN PRStatus
1005 nssListIterator_Finish
1006 (
1007 nssListIterator *iter
1008 );
1009
1010 /*
1011 * nssHash
1012 *
1013 * nssHash_Create
1014 * nssHash_Destroy
1015 * nssHash_Add
1016 * nssHash_Remove
1017 * nssHash_Count
1018 * nssHash_Exists
1019 * nssHash_Lookup
1020 * nssHash_Iterate
1021 */
1022
1023 /*
1024 * nssHash_Create
1025 *
1026 */
1027
1028 NSS_EXTERN nssHash *
1029 nssHash_Create
1030 (
1031 NSSArena *arenaOpt,
1032 PRUint32 numBuckets,
1033 PLHashFunction keyHash,
1034 PLHashComparator keyCompare,
1035 PLHashComparator valueCompare
1036 );
1037
1038 NSS_EXTERN nssHash *
1039 nssHash_CreatePointer
1040 (
1041 NSSArena *arenaOpt,
1042 PRUint32 numBuckets
1043 );
1044
1045 NSS_EXTERN nssHash *
1046 nssHash_CreateString
1047 (
1048 NSSArena *arenaOpt,
1049 PRUint32 numBuckets
1050 );
1051
1052 NSS_EXTERN nssHash *
1053 nssHash_CreateItem
1054 (
1055 NSSArena *arenaOpt,
1056 PRUint32 numBuckets
1057 );
1058
1059 /*
1060 * nssHash_Destroy
1061 *
1062 */
1063 NSS_EXTERN void
1064 nssHash_Destroy
1065 (
1066 nssHash *hash
1067 );
1068
1069 /*
1070 * nssHash_Add
1071 *
1072 */
1073
1074 extern const NSSError NSS_ERROR_HASH_COLLISION;
1075
1076 NSS_EXTERN PRStatus
1077 nssHash_Add
1078 (
1079 nssHash *hash,
1080 const void *key,
1081 const void *value
1082 );
1083
1084 /*
1085 * nssHash_Remove
1086 *
1087 */
1088 NSS_EXTERN void
1089 nssHash_Remove
1090 (
1091 nssHash *hash,
1092 const void *it
1093 );
1094
1095 /*
1096 * nssHash_Count
1097 *
1098 */
1099 NSS_EXTERN PRUint32
1100 nssHash_Count
1101 (
1102 nssHash *hash
1103 );
1104
1105 /*
1106 * nssHash_Exists
1107 *
1108 */
1109 NSS_EXTERN PRBool
1110 nssHash_Exists
1111 (
1112 nssHash *hash,
1113 const void *it
1114 );
1115
1116 /*
1117 * nssHash_Lookup
1118 *
1119 */
1120 NSS_EXTERN void *
1121 nssHash_Lookup
1122 (
1123 nssHash *hash,
1124 const void *it
1125 );
1126
1127 /*
1128 * nssHash_Iterate
1129 *
1130 */
1131 NSS_EXTERN void
1132 nssHash_Iterate
1133 (
1134 nssHash *hash,
1135 nssHashIterator fcn,
1136 void *closure
1137 );
1138
1139
1140 /*
1141 * nssPointerTracker
1142 *
1143 * This type and these methods are only present in debug builds.
1144 *
1145 * The nonpublic methods relating to this type are:
1146 *
1147 * nssPointerTracker_initialize
1148 * nssPointerTracker_finalize
1149 * nssPointerTracker_add
1150 * nssPointerTracker_remove
1151 * nssPointerTracker_verify
1152 */
1153
1154 /*
1155 * nssPointerTracker_initialize
1156 *
1157 * This method is only present in debug builds.
1158 *
1159 * This routine initializes an nssPointerTracker object. Note that
1160 * the object must have been declared *static* to guarantee that it
1161 * is in a zeroed state initially. This routine is idempotent, and
1162 * may even be safely called by multiple threads simultaneously with
1163 * the same argument. This routine returns a PRStatus value; if
1164 * successful, it will return PR_SUCCESS. On failure it will set an
1165 * error on the error stack and return PR_FAILURE.
1166 *
1167 * The error may be one of the following values:
1168 * NSS_ERROR_NO_MEMORY
1169 *
1170 * Return value:
1171 * PR_SUCCESS
1172 * PR_FAILURE
1173 */
1174
1175 #ifdef DEBUG
1176 NSS_EXTERN PRStatus
1177 nssPointerTracker_initialize
1178 (
1179 nssPointerTracker *tracker
1180 );
1181
1182 extern const NSSError NSS_ERROR_NO_MEMORY;
1183 #endif /* DEBUG */
1184
1185 /*
1186 * nssPointerTracker_finalize
1187 *
1188 * This method is only present in debug builds.
1189 *
1190 * This routine returns the nssPointerTracker object to the pre-
1191 * initialized state, releasing all resources used by the object.
1192 * It will *NOT* destroy the objects being tracked by the pointer
1193 * (should any remain), and therefore cannot be used to "sweep up"
1194 * remaining objects. This routine returns a PRStatus value; if
1195 * successful, it will return PR_SUCCES. On failure it will set an
1196 * error on the error stack and return PR_FAILURE. If any objects
1197 * remain in the tracker when it is finalized, that will be treated
1198 * as an error.
1199 *
1200 * The error may be one of the following values:
1201 * NSS_ERROR_TRACKER_NOT_EMPTY
1202 *
1203 * Return value:
1204 * PR_SUCCESS
1205 * PR_FAILURE
1206 */
1207
1208 #ifdef DEBUG
1209 NSS_EXTERN PRStatus
1210 nssPointerTracker_finalize
1211 (
1212 nssPointerTracker *tracker
1213 );
1214
1215 extern const NSSError NSS_ERROR_TRACKER_NOT_EMPTY;
1216 #endif /* DEBUG */
1217
1218 /*
1219 * nssPointerTracker_add
1220 *
1221 * This method is only present in debug builds.
1222 *
1223 * This routine adds the specified pointer to the nssPointerTracker
1224 * object. It should be called in constructor objects to register
1225 * new valid objects. The nssPointerTracker is threadsafe, but this
1226 * call is not idempotent. This routine returns a PRStatus value;
1227 * if successful it will return PR_SUCCESS. On failure it will set
1228 * an error on the error stack and return PR_FAILURE.
1229 *
1230 * The error may be one of the following values:
1231 * NSS_ERROR_NO_MEMORY
1232 * NSS_ERROR_TRACKER_NOT_INITIALIZED
1233 * NSS_ERROR_DUPLICATE_POINTER
1234 *
1235 * Return value:
1236 * PR_SUCCESS
1237 * PR_FAILURE
1238 */
1239
1240 #ifdef DEBUG
1241 NSS_EXTERN PRStatus
1242 nssPointerTracker_add
1243 (
1244 nssPointerTracker *tracker,
1245 const void *pointer
1246 );
1247
1248 extern const NSSError NSS_ERROR_NO_MEMORY;
1249 extern const NSSError NSS_ERROR_TRACKER_NOT_INITIALIZED;
1250 extern const NSSError NSS_ERROR_DUPLICATE_POINTER;
1251 #endif /* DEBUG */
1252
1253 /*
1254 * nssPointerTracker_remove
1255 *
1256 * This method is only present in debug builds.
1257 *
1258 * This routine removes the specified pointer from the
1259 * nssPointerTracker object. It does not call any destructor for the
1260 * object; rather, this should be called from the object's destructor.
1261 * The nssPointerTracker is threadsafe, but this call is not
1262 * idempotent. This routine returns a PRStatus value; if successful
1263 * it will return PR_SUCCESS. On failure it will set an error on the
1264 * error stack and return PR_FAILURE.
1265 *
1266 * The error may be one of the following values:
1267 * NSS_ERROR_TRACKER_NOT_INITIALIZED
1268 * NSS_ERROR_POINTER_NOT_REGISTERED
1269 *
1270 * Return value:
1271 * PR_SUCCESS
1272 * PR_FAILURE
1273 */
1274
1275 #ifdef DEBUG
1276 NSS_EXTERN PRStatus
1277 nssPointerTracker_remove
1278 (
1279 nssPointerTracker *tracker,
1280 const void *pointer
1281 );
1282
1283 extern const NSSError NSS_ERROR_TRACKER_NOT_INITIALIZED;
1284 extern const NSSError NSS_ERROR_POINTER_NOT_REGISTERED;
1285 #endif /* DEBUG */
1286
1287 /*
1288 * nssPointerTracker_verify
1289 *
1290 * This method is only present in debug builds.
1291 *
1292 * This routine verifies that the specified pointer has been registered
1293 * with the nssPointerTracker object. The nssPointerTracker object is
1294 * threadsafe, and this call may be safely called from multiple threads
1295 * simultaneously with the same arguments. This routine returns a
1296 * PRStatus value; if the pointer is registered this will return
1297 * PR_SUCCESS. Otherwise it will set an error on the error stack and
1298 * return PR_FAILURE. Although the error is suitable for leaving on
1299 * the stack, callers may wish to augment the information available by
1300 * placing a more type-specific error on the stack.
1301 *
1302 * The error may be one of the following values:
1303 * NSS_ERROR_POINTER_NOT_REGISTERED
1304 *
1305 * Return value:
1306 * PR_SUCCESS
1307 * PR_FAILRUE
1308 */
1309
1310 #ifdef DEBUG
1311 NSS_EXTERN PRStatus
1312 nssPointerTracker_verify
1313 (
1314 nssPointerTracker *tracker,
1315 const void *pointer
1316 );
1317
1318 extern const NSSError NSS_ERROR_POINTER_NOT_REGISTERED;
1319 #endif /* DEBUG */
1320
1321 /*
1322 * libc
1323 *
1324 * nsslibc_memcpy
1325 * nsslibc_memset
1326 * nsslibc_offsetof
1327 */
1328
1329 /*
1330 * nsslibc_memcpy
1331 *
1332 * Errors:
1333 * NSS_ERROR_INVALID_POINTER
1334 *
1335 * Return value:
1336 * NULL on error
1337 * The destination pointer on success
1338 */
1339
1340 NSS_EXTERN void *
1341 nsslibc_memcpy
1342 (
1343 void *dest,
1344 const void *source,
1345 PRUint32 n
1346 );
1347
1348 extern const NSSError NSS_ERROR_INVALID_POINTER;
1349
1350 /*
1351 * nsslibc_memset
1352 *
1353 * Errors:
1354 * NSS_ERROR_INVALID_POINTER
1355 *
1356 * Return value:
1357 * NULL on error
1358 * The destination pointer on success
1359 */
1360
1361 NSS_EXTERN void *
1362 nsslibc_memset
1363 (
1364 void *dest,
1365 PRUint8 byte,
1366 PRUint32 n
1367 );
1368
1369 extern const NSSError NSS_ERROR_INVALID_POINTER;
1370
1371 /*
1372 * nsslibc_memequal
1373 *
1374 * Errors:
1375 * NSS_ERROR_INVALID_POINTER
1376 *
1377 * Return value:
1378 * PR_TRUE if they match
1379 * PR_FALSE if they don't
1380 * PR_FALSE upon error
1381 */
1382
1383 NSS_EXTERN PRBool
1384 nsslibc_memequal
1385 (
1386 const void *a,
1387 const void *b,
1388 PRUint32 len,
1389 PRStatus *statusOpt
1390 );
1391
1392 extern const NSSError NSS_ERROR_INVALID_POINTER;
1393
1394 #define nsslibc_offsetof(str, memb) ((PRPtrdiff)(&(((str *)0)->memb)))
1395
1396 PR_END_EXTERN_C
1397
1398 #endif /* BASE_H */
OLDNEW
« no previous file with comments | « mozilla/security/nss/lib/base/arena.c ('k') | mozilla/security/nss/lib/base/baset.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698