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