security/nss/lib/base/nssbase.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 NSSBASE_H
michael@0 6 #define NSSBASE_H
michael@0 7
michael@0 8 /*
michael@0 9 * nssbase.h
michael@0 10 *
michael@0 11 * This header file contains the prototypes of the basic public
michael@0 12 * NSS routines.
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 PR_BEGIN_EXTERN_C
michael@0 20
michael@0 21 /*
michael@0 22 * NSSArena
michael@0 23 *
michael@0 24 * The public methods relating to this type are:
michael@0 25 *
michael@0 26 * NSSArena_Create -- constructor
michael@0 27 * NSSArena_Destroy
michael@0 28 * NSS_ZAlloc
michael@0 29 * NSS_ZRealloc
michael@0 30 * NSS_ZFreeIf
michael@0 31 */
michael@0 32
michael@0 33 /*
michael@0 34 * NSSArena_Create
michael@0 35 *
michael@0 36 * This routine creates a new memory arena. This routine may return
michael@0 37 * NULL upon error, in which case it will have created an error stack.
michael@0 38 *
michael@0 39 * The top-level error may be one of the following values:
michael@0 40 * NSS_ERROR_NO_MEMORY
michael@0 41 *
michael@0 42 * Return value:
michael@0 43 * NULL upon error
michael@0 44 * A pointer to an NSSArena upon success
michael@0 45 */
michael@0 46
michael@0 47 NSS_EXTERN NSSArena *
michael@0 48 NSSArena_Create
michael@0 49 (
michael@0 50 void
michael@0 51 );
michael@0 52
michael@0 53 extern const NSSError NSS_ERROR_NO_MEMORY;
michael@0 54
michael@0 55 /*
michael@0 56 * NSSArena_Destroy
michael@0 57 *
michael@0 58 * This routine will destroy the specified arena, freeing all memory
michael@0 59 * allocated from it. This routine returns a PRStatus value; if
michael@0 60 * successful, it will return PR_SUCCESS. If unsuccessful, it will
michael@0 61 * create an error stack and return PR_FAILURE.
michael@0 62 *
michael@0 63 * The top-level error may be one of the following values:
michael@0 64 * NSS_ERROR_INVALID_ARENA
michael@0 65 *
michael@0 66 * Return value:
michael@0 67 * PR_SUCCESS upon success
michael@0 68 * PR_FAILURE upon failure
michael@0 69 */
michael@0 70
michael@0 71 NSS_EXTERN PRStatus
michael@0 72 NSSArena_Destroy
michael@0 73 (
michael@0 74 NSSArena *arena
michael@0 75 );
michael@0 76
michael@0 77 extern const NSSError NSS_ERROR_INVALID_ARENA;
michael@0 78
michael@0 79 /*
michael@0 80 * The error stack
michael@0 81 *
michael@0 82 * The public methods relating to the error stack are:
michael@0 83 *
michael@0 84 * NSS_GetError
michael@0 85 * NSS_GetErrorStack
michael@0 86 */
michael@0 87
michael@0 88 /*
michael@0 89 * NSS_GetError
michael@0 90 *
michael@0 91 * This routine returns the highest-level (most general) error set
michael@0 92 * by the most recent NSS library routine called by the same thread
michael@0 93 * calling this routine.
michael@0 94 *
michael@0 95 * This routine cannot fail. It may return NSS_ERROR_NO_ERROR, which
michael@0 96 * indicates that the previous NSS library call did not set an error.
michael@0 97 *
michael@0 98 * Return value:
michael@0 99 * 0 if no error has been set
michael@0 100 * A nonzero error number
michael@0 101 */
michael@0 102
michael@0 103 NSS_EXTERN NSSError
michael@0 104 NSS_GetError
michael@0 105 (
michael@0 106 void
michael@0 107 );
michael@0 108
michael@0 109 extern const NSSError NSS_ERROR_NO_ERROR;
michael@0 110
michael@0 111 /*
michael@0 112 * NSS_GetErrorStack
michael@0 113 *
michael@0 114 * This routine returns a pointer to an array of NSSError values,
michael@0 115 * containingthe entire sequence or "stack" of errors set by the most
michael@0 116 * recent NSS library routine called by the same thread calling this
michael@0 117 * routine. NOTE: the caller DOES NOT OWN the memory pointed to by
michael@0 118 * the return value. The pointer will remain valid until the calling
michael@0 119 * thread calls another NSS routine. The lowest-level (most specific)
michael@0 120 * error is first in the array, and the highest-level is last. The
michael@0 121 * array is zero-terminated. This routine may return NULL upon error;
michael@0 122 * this indicates a low-memory situation.
michael@0 123 *
michael@0 124 * Return value:
michael@0 125 * NULL upon error, which is an implied NSS_ERROR_NO_MEMORY
michael@0 126 * A NON-caller-owned pointer to an array of NSSError values
michael@0 127 */
michael@0 128
michael@0 129 NSS_EXTERN NSSError *
michael@0 130 NSS_GetErrorStack
michael@0 131 (
michael@0 132 void
michael@0 133 );
michael@0 134
michael@0 135 /*
michael@0 136 * NSS_ZNEW
michael@0 137 *
michael@0 138 * This preprocessor macro will allocate memory for a new object
michael@0 139 * of the specified type with nss_ZAlloc, and will cast the
michael@0 140 * return value appropriately. If the optional arena argument is
michael@0 141 * non-null, the memory will be obtained from that arena; otherwise,
michael@0 142 * the memory will be obtained from the heap. This routine may
michael@0 143 * return NULL upon error, in which case it will have set an error
michael@0 144 * upon the error stack.
michael@0 145 *
michael@0 146 * The error may be one of the following values:
michael@0 147 * NSS_ERROR_INVALID_ARENA
michael@0 148 * NSS_ERROR_NO_MEMORY
michael@0 149 *
michael@0 150 * Return value:
michael@0 151 * NULL upon error
michael@0 152 * A pointer to the new segment of zeroed memory
michael@0 153 */
michael@0 154
michael@0 155 /* The following line exceeds 72 characters, but emacs barfs if we split it. */
michael@0 156 #define NSS_ZNEW(arenaOpt, type) ((type *)NSS_ZAlloc((arenaOpt), sizeof(type)))
michael@0 157
michael@0 158 /*
michael@0 159 * NSS_ZNEWARRAY
michael@0 160 *
michael@0 161 * This preprocessor macro will allocate memory for an array of
michael@0 162 * new objects, and will cast the return value appropriately.
michael@0 163 * If the optional arena argument is non-null, the memory will
michael@0 164 * be obtained from that arena; otherwise, the memory will be
michael@0 165 * obtained from the heap. This routine may return NULL upon
michael@0 166 * error, in which case it will have set an error upon the error
michael@0 167 * stack. The array size may be specified as zero.
michael@0 168 *
michael@0 169 * The error may be one of the following values:
michael@0 170 * NSS_ERROR_INVALID_ARENA
michael@0 171 * NSS_ERROR_NO_MEMORY
michael@0 172 *
michael@0 173 * Return value:
michael@0 174 * NULL upon error
michael@0 175 * A pointer to the new segment of zeroed memory
michael@0 176 */
michael@0 177
michael@0 178 /* The following line exceeds 72 characters, but emacs barfs if we split it. */
michael@0 179 #define NSS_ZNEWARRAY(arenaOpt, type, quantity) ((type *)NSS_ZAlloc((arenaOpt), sizeof(type) * (quantity)))
michael@0 180
michael@0 181
michael@0 182 /*
michael@0 183 * NSS_ZAlloc
michael@0 184 *
michael@0 185 * This routine allocates and zeroes a section of memory of the
michael@0 186 * size, and returns to the caller a pointer to that memory. If
michael@0 187 * the optional arena argument is non-null, the memory will be
michael@0 188 * obtained from that arena; otherwise, the memory will be obtained
michael@0 189 * from the heap. This routine may return NULL upon error, in
michael@0 190 * which case it will have set an error upon the error stack. The
michael@0 191 * value specified for size may be zero; in which case a valid
michael@0 192 * zero-length block of memory will be allocated. This block may
michael@0 193 * be expanded by calling NSS_ZRealloc.
michael@0 194 *
michael@0 195 * The error may be one of the following values:
michael@0 196 * NSS_ERROR_INVALID_ARENA
michael@0 197 * NSS_ERROR_NO_MEMORY
michael@0 198 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
michael@0 199 *
michael@0 200 * Return value:
michael@0 201 * NULL upon error
michael@0 202 * A pointer to the new segment of zeroed memory
michael@0 203 */
michael@0 204
michael@0 205 NSS_EXTERN void *
michael@0 206 NSS_ZAlloc
michael@0 207 (
michael@0 208 NSSArena *arenaOpt,
michael@0 209 PRUint32 size
michael@0 210 );
michael@0 211
michael@0 212 /*
michael@0 213 * NSS_ZRealloc
michael@0 214 *
michael@0 215 * This routine reallocates a block of memory obtained by calling
michael@0 216 * nss_ZAlloc or nss_ZRealloc. The portion of memory
michael@0 217 * between the new and old sizes -- which is either being newly
michael@0 218 * obtained or released -- is in either case zeroed. This routine
michael@0 219 * may return NULL upon failure, in which case it will have placed
michael@0 220 * an error on the error stack.
michael@0 221 *
michael@0 222 * The error may be one of the following values:
michael@0 223 * NSS_ERROR_INVALID_POINTER
michael@0 224 * NSS_ERROR_NO_MEMORY
michael@0 225 * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD
michael@0 226 *
michael@0 227 * Return value:
michael@0 228 * NULL upon error
michael@0 229 * A pointer to the replacement segment of memory
michael@0 230 */
michael@0 231
michael@0 232 NSS_EXTERN void *
michael@0 233 NSS_ZRealloc
michael@0 234 (
michael@0 235 void *pointer,
michael@0 236 PRUint32 newSize
michael@0 237 );
michael@0 238
michael@0 239
michael@0 240 /*
michael@0 241 * NSS_ZFreeIf
michael@0 242 *
michael@0 243 * If the specified pointer is non-null, then the region of memory
michael@0 244 * to which it points -- which must have been allocated with
michael@0 245 * nss_ZAlloc -- will be zeroed and released. This routine
michael@0 246 * returns a PRStatus value; if successful, it will return PR_SUCCESS.
michael@0 247 * If unsuccessful, it will set an error on the error stack and return
michael@0 248 * PR_FAILURE.
michael@0 249 *
michael@0 250 * The error may be one of the following values:
michael@0 251 * NSS_ERROR_INVALID_POINTER
michael@0 252 *
michael@0 253 * Return value:
michael@0 254 * PR_SUCCESS
michael@0 255 * PR_FAILURE
michael@0 256 */
michael@0 257
michael@0 258 NSS_EXTERN PRStatus
michael@0 259 NSS_ZFreeIf
michael@0 260 (
michael@0 261 void *pointer
michael@0 262 );
michael@0 263
michael@0 264 PR_END_EXTERN_C
michael@0 265
michael@0 266 #endif /* NSSBASE_H */

mercurial