1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/nss/lib/base/nssbase.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,266 @@ 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 NSSBASE_H 1.9 +#define NSSBASE_H 1.10 + 1.11 +/* 1.12 + * nssbase.h 1.13 + * 1.14 + * This header file contains the prototypes of the basic public 1.15 + * NSS routines. 1.16 + */ 1.17 + 1.18 +#ifndef NSSBASET_H 1.19 +#include "nssbaset.h" 1.20 +#endif /* NSSBASET_H */ 1.21 + 1.22 +PR_BEGIN_EXTERN_C 1.23 + 1.24 +/* 1.25 + * NSSArena 1.26 + * 1.27 + * The public methods relating to this type are: 1.28 + * 1.29 + * NSSArena_Create -- constructor 1.30 + * NSSArena_Destroy 1.31 + * NSS_ZAlloc 1.32 + * NSS_ZRealloc 1.33 + * NSS_ZFreeIf 1.34 + */ 1.35 + 1.36 +/* 1.37 + * NSSArena_Create 1.38 + * 1.39 + * This routine creates a new memory arena. This routine may return 1.40 + * NULL upon error, in which case it will have created an error stack. 1.41 + * 1.42 + * The top-level error may be one of the following values: 1.43 + * NSS_ERROR_NO_MEMORY 1.44 + * 1.45 + * Return value: 1.46 + * NULL upon error 1.47 + * A pointer to an NSSArena upon success 1.48 + */ 1.49 + 1.50 +NSS_EXTERN NSSArena * 1.51 +NSSArena_Create 1.52 +( 1.53 + void 1.54 +); 1.55 + 1.56 +extern const NSSError NSS_ERROR_NO_MEMORY; 1.57 + 1.58 +/* 1.59 + * NSSArena_Destroy 1.60 + * 1.61 + * This routine will destroy the specified arena, freeing all memory 1.62 + * allocated from it. This routine returns a PRStatus value; if 1.63 + * successful, it will return PR_SUCCESS. If unsuccessful, it will 1.64 + * create an error stack and return PR_FAILURE. 1.65 + * 1.66 + * The top-level error may be one of the following values: 1.67 + * NSS_ERROR_INVALID_ARENA 1.68 + * 1.69 + * Return value: 1.70 + * PR_SUCCESS upon success 1.71 + * PR_FAILURE upon failure 1.72 + */ 1.73 + 1.74 +NSS_EXTERN PRStatus 1.75 +NSSArena_Destroy 1.76 +( 1.77 + NSSArena *arena 1.78 +); 1.79 + 1.80 +extern const NSSError NSS_ERROR_INVALID_ARENA; 1.81 + 1.82 +/* 1.83 + * The error stack 1.84 + * 1.85 + * The public methods relating to the error stack are: 1.86 + * 1.87 + * NSS_GetError 1.88 + * NSS_GetErrorStack 1.89 + */ 1.90 + 1.91 +/* 1.92 + * NSS_GetError 1.93 + * 1.94 + * This routine returns the highest-level (most general) error set 1.95 + * by the most recent NSS library routine called by the same thread 1.96 + * calling this routine. 1.97 + * 1.98 + * This routine cannot fail. It may return NSS_ERROR_NO_ERROR, which 1.99 + * indicates that the previous NSS library call did not set an error. 1.100 + * 1.101 + * Return value: 1.102 + * 0 if no error has been set 1.103 + * A nonzero error number 1.104 + */ 1.105 + 1.106 +NSS_EXTERN NSSError 1.107 +NSS_GetError 1.108 +( 1.109 + void 1.110 +); 1.111 + 1.112 +extern const NSSError NSS_ERROR_NO_ERROR; 1.113 + 1.114 +/* 1.115 + * NSS_GetErrorStack 1.116 + * 1.117 + * This routine returns a pointer to an array of NSSError values, 1.118 + * containingthe entire sequence or "stack" of errors set by the most 1.119 + * recent NSS library routine called by the same thread calling this 1.120 + * routine. NOTE: the caller DOES NOT OWN the memory pointed to by 1.121 + * the return value. The pointer will remain valid until the calling 1.122 + * thread calls another NSS routine. The lowest-level (most specific) 1.123 + * error is first in the array, and the highest-level is last. The 1.124 + * array is zero-terminated. This routine may return NULL upon error; 1.125 + * this indicates a low-memory situation. 1.126 + * 1.127 + * Return value: 1.128 + * NULL upon error, which is an implied NSS_ERROR_NO_MEMORY 1.129 + * A NON-caller-owned pointer to an array of NSSError values 1.130 + */ 1.131 + 1.132 +NSS_EXTERN NSSError * 1.133 +NSS_GetErrorStack 1.134 +( 1.135 + void 1.136 +); 1.137 + 1.138 +/* 1.139 + * NSS_ZNEW 1.140 + * 1.141 + * This preprocessor macro will allocate memory for a new object 1.142 + * of the specified type with nss_ZAlloc, and will cast the 1.143 + * return value appropriately. If the optional arena argument is 1.144 + * non-null, the memory will be obtained from that arena; otherwise, 1.145 + * the memory will be obtained from the heap. This routine may 1.146 + * return NULL upon error, in which case it will have set an error 1.147 + * upon the error stack. 1.148 + * 1.149 + * The error may be one of the following values: 1.150 + * NSS_ERROR_INVALID_ARENA 1.151 + * NSS_ERROR_NO_MEMORY 1.152 + * 1.153 + * Return value: 1.154 + * NULL upon error 1.155 + * A pointer to the new segment of zeroed memory 1.156 + */ 1.157 + 1.158 +/* The following line exceeds 72 characters, but emacs barfs if we split it. */ 1.159 +#define NSS_ZNEW(arenaOpt, type) ((type *)NSS_ZAlloc((arenaOpt), sizeof(type))) 1.160 + 1.161 +/* 1.162 + * NSS_ZNEWARRAY 1.163 + * 1.164 + * This preprocessor macro will allocate memory for an array of 1.165 + * new objects, and will cast the return value appropriately. 1.166 + * If the optional arena argument is non-null, the memory will 1.167 + * be obtained from that arena; otherwise, the memory will be 1.168 + * obtained from the heap. This routine may return NULL upon 1.169 + * error, in which case it will have set an error upon the error 1.170 + * stack. The array size may be specified as zero. 1.171 + * 1.172 + * The error may be one of the following values: 1.173 + * NSS_ERROR_INVALID_ARENA 1.174 + * NSS_ERROR_NO_MEMORY 1.175 + * 1.176 + * Return value: 1.177 + * NULL upon error 1.178 + * A pointer to the new segment of zeroed memory 1.179 + */ 1.180 + 1.181 +/* The following line exceeds 72 characters, but emacs barfs if we split it. */ 1.182 +#define NSS_ZNEWARRAY(arenaOpt, type, quantity) ((type *)NSS_ZAlloc((arenaOpt), sizeof(type) * (quantity))) 1.183 + 1.184 + 1.185 +/* 1.186 + * NSS_ZAlloc 1.187 + * 1.188 + * This routine allocates and zeroes a section of memory of the 1.189 + * size, and returns to the caller a pointer to that memory. If 1.190 + * the optional arena argument is non-null, the memory will be 1.191 + * obtained from that arena; otherwise, the memory will be obtained 1.192 + * from the heap. This routine may return NULL upon error, in 1.193 + * which case it will have set an error upon the error stack. The 1.194 + * value specified for size may be zero; in which case a valid 1.195 + * zero-length block of memory will be allocated. This block may 1.196 + * be expanded by calling NSS_ZRealloc. 1.197 + * 1.198 + * The error may be one of the following values: 1.199 + * NSS_ERROR_INVALID_ARENA 1.200 + * NSS_ERROR_NO_MEMORY 1.201 + * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD 1.202 + * 1.203 + * Return value: 1.204 + * NULL upon error 1.205 + * A pointer to the new segment of zeroed memory 1.206 + */ 1.207 + 1.208 +NSS_EXTERN void * 1.209 +NSS_ZAlloc 1.210 +( 1.211 + NSSArena *arenaOpt, 1.212 + PRUint32 size 1.213 +); 1.214 + 1.215 +/* 1.216 + * NSS_ZRealloc 1.217 + * 1.218 + * This routine reallocates a block of memory obtained by calling 1.219 + * nss_ZAlloc or nss_ZRealloc. The portion of memory 1.220 + * between the new and old sizes -- which is either being newly 1.221 + * obtained or released -- is in either case zeroed. This routine 1.222 + * may return NULL upon failure, in which case it will have placed 1.223 + * an error on the error stack. 1.224 + * 1.225 + * The error may be one of the following values: 1.226 + * NSS_ERROR_INVALID_POINTER 1.227 + * NSS_ERROR_NO_MEMORY 1.228 + * NSS_ERROR_ARENA_MARKED_BY_ANOTHER_THREAD 1.229 + * 1.230 + * Return value: 1.231 + * NULL upon error 1.232 + * A pointer to the replacement segment of memory 1.233 + */ 1.234 + 1.235 +NSS_EXTERN void * 1.236 +NSS_ZRealloc 1.237 +( 1.238 + void *pointer, 1.239 + PRUint32 newSize 1.240 +); 1.241 + 1.242 + 1.243 +/* 1.244 + * NSS_ZFreeIf 1.245 + * 1.246 + * If the specified pointer is non-null, then the region of memory 1.247 + * to which it points -- which must have been allocated with 1.248 + * nss_ZAlloc -- will be zeroed and released. This routine 1.249 + * returns a PRStatus value; if successful, it will return PR_SUCCESS. 1.250 + * If unsuccessful, it will set an error on the error stack and return 1.251 + * PR_FAILURE. 1.252 + * 1.253 + * The error may be one of the following values: 1.254 + * NSS_ERROR_INVALID_POINTER 1.255 + * 1.256 + * Return value: 1.257 + * PR_SUCCESS 1.258 + * PR_FAILURE 1.259 + */ 1.260 + 1.261 +NSS_EXTERN PRStatus 1.262 +NSS_ZFreeIf 1.263 +( 1.264 + void *pointer 1.265 +); 1.266 + 1.267 +PR_END_EXTERN_C 1.268 + 1.269 +#endif /* NSSBASE_H */