security/nss/lib/base/baset.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef BASET_H
michael@0 6 #define BASET_H
michael@0 7
michael@0 8 /*
michael@0 9 * baset.h
michael@0 10 *
michael@0 11 * This file contains definitions for the basic types used throughout
michael@0 12 * nss but not available publicly.
michael@0 13 */
michael@0 14
michael@0 15 #ifndef NSSBASET_H
michael@0 16 #include "nssbaset.h"
michael@0 17 #endif /* NSSBASET_H */
michael@0 18
michael@0 19 #include "plhash.h"
michael@0 20
michael@0 21 PR_BEGIN_EXTERN_C
michael@0 22
michael@0 23 /*
michael@0 24 * nssArenaMark
michael@0 25 *
michael@0 26 * This type is used to mark the current state of an NSSArena.
michael@0 27 */
michael@0 28
michael@0 29 struct nssArenaMarkStr;
michael@0 30 typedef struct nssArenaMarkStr nssArenaMark;
michael@0 31
michael@0 32 #ifdef DEBUG
michael@0 33 /*
michael@0 34 * ARENA_THREADMARK
michael@0 35 *
michael@0 36 * Optionally, this arena implementation can be compiled with some
michael@0 37 * runtime checking enabled, which will catch the situation where
michael@0 38 * one thread "marks" the arena, another thread allocates memory,
michael@0 39 * and then the mark is released. Usually this is a surprise to
michael@0 40 * the second thread, and this leads to weird runtime errors.
michael@0 41 * Define ARENA_THREADMARK to catch these cases; we define it for all
michael@0 42 * (internal and external) debug builds.
michael@0 43 */
michael@0 44 #define ARENA_THREADMARK
michael@0 45
michael@0 46 /*
michael@0 47 * ARENA_DESTRUCTOR_LIST
michael@0 48 *
michael@0 49 * Unfortunately, our pointer-tracker facility, used in debug
michael@0 50 * builds to agressively fight invalid pointers, requries that
michael@0 51 * pointers be deregistered when objects are destroyed. This
michael@0 52 * conflicts with the standard arena usage where "memory-only"
michael@0 53 * objects (that don't hold onto resources outside the arena)
michael@0 54 * can be allocated in an arena, and never destroyed other than
michael@0 55 * when the arena is destroyed. Therefore we have added a
michael@0 56 * destructor-registratio facility to our arenas. This was not
michael@0 57 * a simple decision, since we're getting ever-further away from
michael@0 58 * the original arena philosophy. However, it was felt that
michael@0 59 * adding this in debug builds wouldn't be so bad; as it would
michael@0 60 * discourage them from being used for "serious" purposes.
michael@0 61 * This facility requires ARENA_THREADMARK to be defined.
michael@0 62 */
michael@0 63 #ifdef ARENA_THREADMARK
michael@0 64 #define ARENA_DESTRUCTOR_LIST
michael@0 65 #endif /* ARENA_THREADMARK */
michael@0 66
michael@0 67 #endif /* DEBUG */
michael@0 68
michael@0 69 typedef struct nssListStr nssList;
michael@0 70 typedef struct nssListIteratorStr nssListIterator;
michael@0 71 typedef PRBool (* nssListCompareFunc)(void *a, void *b);
michael@0 72 typedef PRIntn (* nssListSortFunc)(void *a, void *b);
michael@0 73 typedef void (* nssListElementDestructorFunc)(void *el);
michael@0 74
michael@0 75 typedef struct nssHashStr nssHash;
michael@0 76 typedef void (PR_CALLBACK *nssHashIterator)(const void *key,
michael@0 77 void *value,
michael@0 78 void *arg);
michael@0 79
michael@0 80 /*
michael@0 81 * nssPointerTracker
michael@0 82 *
michael@0 83 * This type is used in debug builds (both external and internal) to
michael@0 84 * track our object pointers. Objects of this type must be statically
michael@0 85 * allocated, which means the structure size must be available to the
michael@0 86 * compiler. Therefore we must expose the contents of this structure.
michael@0 87 * But please don't access elements directly; use the accessors.
michael@0 88 */
michael@0 89
michael@0 90 #ifdef DEBUG
michael@0 91 struct nssPointerTrackerStr {
michael@0 92 PRCallOnceType once;
michael@0 93 PZLock *lock;
michael@0 94 PLHashTable *table;
michael@0 95 };
michael@0 96 typedef struct nssPointerTrackerStr nssPointerTracker;
michael@0 97 #endif /* DEBUG */
michael@0 98
michael@0 99 /*
michael@0 100 * nssStringType
michael@0 101 *
michael@0 102 * There are several types of strings in the real world. We try to
michael@0 103 * use only UTF8 and avoid the rest, but that's not always possible.
michael@0 104 * So we have a couple converter routines to go to and from the other
michael@0 105 * string types. We have to be able to specify those string types,
michael@0 106 * so we have this enumeration.
michael@0 107 */
michael@0 108
michael@0 109 enum nssStringTypeEnum {
michael@0 110 nssStringType_DirectoryString,
michael@0 111 nssStringType_TeletexString, /* Not "teletext" with trailing 't' */
michael@0 112 nssStringType_PrintableString,
michael@0 113 nssStringType_UniversalString,
michael@0 114 nssStringType_BMPString,
michael@0 115 nssStringType_UTF8String,
michael@0 116 nssStringType_PHGString,
michael@0 117 nssStringType_GeneralString,
michael@0 118
michael@0 119 nssStringType_Unknown = -1
michael@0 120 };
michael@0 121 typedef enum nssStringTypeEnum nssStringType;
michael@0 122
michael@0 123 PR_END_EXTERN_C
michael@0 124
michael@0 125 #endif /* BASET_H */

mercurial