1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/base/baset.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,125 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef BASET_H 1.9 +#define BASET_H 1.10 + 1.11 +/* 1.12 + * baset.h 1.13 + * 1.14 + * This file contains definitions for the basic types used throughout 1.15 + * nss but not available publicly. 1.16 + */ 1.17 + 1.18 +#ifndef NSSBASET_H 1.19 +#include "nssbaset.h" 1.20 +#endif /* NSSBASET_H */ 1.21 + 1.22 +#include "plhash.h" 1.23 + 1.24 +PR_BEGIN_EXTERN_C 1.25 + 1.26 +/* 1.27 + * nssArenaMark 1.28 + * 1.29 + * This type is used to mark the current state of an NSSArena. 1.30 + */ 1.31 + 1.32 +struct nssArenaMarkStr; 1.33 +typedef struct nssArenaMarkStr nssArenaMark; 1.34 + 1.35 +#ifdef DEBUG 1.36 +/* 1.37 + * ARENA_THREADMARK 1.38 + * 1.39 + * Optionally, this arena implementation can be compiled with some 1.40 + * runtime checking enabled, which will catch the situation where 1.41 + * one thread "marks" the arena, another thread allocates memory, 1.42 + * and then the mark is released. Usually this is a surprise to 1.43 + * the second thread, and this leads to weird runtime errors. 1.44 + * Define ARENA_THREADMARK to catch these cases; we define it for all 1.45 + * (internal and external) debug builds. 1.46 + */ 1.47 +#define ARENA_THREADMARK 1.48 + 1.49 +/* 1.50 + * ARENA_DESTRUCTOR_LIST 1.51 + * 1.52 + * Unfortunately, our pointer-tracker facility, used in debug 1.53 + * builds to agressively fight invalid pointers, requries that 1.54 + * pointers be deregistered when objects are destroyed. This 1.55 + * conflicts with the standard arena usage where "memory-only" 1.56 + * objects (that don't hold onto resources outside the arena) 1.57 + * can be allocated in an arena, and never destroyed other than 1.58 + * when the arena is destroyed. Therefore we have added a 1.59 + * destructor-registratio facility to our arenas. This was not 1.60 + * a simple decision, since we're getting ever-further away from 1.61 + * the original arena philosophy. However, it was felt that 1.62 + * adding this in debug builds wouldn't be so bad; as it would 1.63 + * discourage them from being used for "serious" purposes. 1.64 + * This facility requires ARENA_THREADMARK to be defined. 1.65 + */ 1.66 +#ifdef ARENA_THREADMARK 1.67 +#define ARENA_DESTRUCTOR_LIST 1.68 +#endif /* ARENA_THREADMARK */ 1.69 + 1.70 +#endif /* DEBUG */ 1.71 + 1.72 +typedef struct nssListStr nssList; 1.73 +typedef struct nssListIteratorStr nssListIterator; 1.74 +typedef PRBool (* nssListCompareFunc)(void *a, void *b); 1.75 +typedef PRIntn (* nssListSortFunc)(void *a, void *b); 1.76 +typedef void (* nssListElementDestructorFunc)(void *el); 1.77 + 1.78 +typedef struct nssHashStr nssHash; 1.79 +typedef void (PR_CALLBACK *nssHashIterator)(const void *key, 1.80 + void *value, 1.81 + void *arg); 1.82 + 1.83 +/* 1.84 + * nssPointerTracker 1.85 + * 1.86 + * This type is used in debug builds (both external and internal) to 1.87 + * track our object pointers. Objects of this type must be statically 1.88 + * allocated, which means the structure size must be available to the 1.89 + * compiler. Therefore we must expose the contents of this structure. 1.90 + * But please don't access elements directly; use the accessors. 1.91 + */ 1.92 + 1.93 +#ifdef DEBUG 1.94 +struct nssPointerTrackerStr { 1.95 + PRCallOnceType once; 1.96 + PZLock *lock; 1.97 + PLHashTable *table; 1.98 +}; 1.99 +typedef struct nssPointerTrackerStr nssPointerTracker; 1.100 +#endif /* DEBUG */ 1.101 + 1.102 +/* 1.103 + * nssStringType 1.104 + * 1.105 + * There are several types of strings in the real world. We try to 1.106 + * use only UTF8 and avoid the rest, but that's not always possible. 1.107 + * So we have a couple converter routines to go to and from the other 1.108 + * string types. We have to be able to specify those string types, 1.109 + * so we have this enumeration. 1.110 + */ 1.111 + 1.112 +enum nssStringTypeEnum { 1.113 + nssStringType_DirectoryString, 1.114 + nssStringType_TeletexString, /* Not "teletext" with trailing 't' */ 1.115 + nssStringType_PrintableString, 1.116 + nssStringType_UniversalString, 1.117 + nssStringType_BMPString, 1.118 + nssStringType_UTF8String, 1.119 + nssStringType_PHGString, 1.120 + nssStringType_GeneralString, 1.121 + 1.122 + nssStringType_Unknown = -1 1.123 +}; 1.124 +typedef enum nssStringTypeEnum nssStringType; 1.125 + 1.126 +PR_END_EXTERN_C 1.127 + 1.128 +#endif /* BASET_H */