security/nss/lib/base/nssbase.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial