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