RSA BSAFE Micro Edition Suite

Streamlined security for mobile and embedded devices

Search  Print

r_mem.h

Go to the documentation of this file.
00001 /* $Id: r_mem.h,v 1.60 2003/09/24 00:05:35 sfruenke Exp $ */
00002 /*
00003  * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved.
00004  *
00005  * This work contains proprietary information of RSA Security.
00006  * Distribution is limited to authorized licensees of RSA
00007  * Security. Any unauthorized reproduction, distribution or
00008  * modification of this work is strictly prohibited.
00009  */
00014 #ifndef HEADER_COMMON_R_MEM_H
00015 #define HEADER_COMMON_R_MEM_H
00016 
00017 #ifdef  __cplusplus
00018 extern "C" {
00019 #endif
00020 
00021 /* The Tornado 2 environment already has a define for Free.
00022  * So we discard their definition so our own definition can be used.
00023  */
00024 #if defined(VXWORKS)
00025 #if defined(Free)
00026 #undef Free
00027 #endif /* Free */
00028 #endif /* VXWORKS */
00029 
00044 #define R_malloc_init() R_set_mem_functions(\
00045     (R_MEM_MALLOC_FUNCTION_T *)malloc,\
00046     (R_MEM_REALLOC_FUNCTION_T *)realloc,\
00047     (R_MEM_FREE_FUNCTION_T *)free)
00048 
00049 #ifndef NO_CRYPTO_MEM
00050 /* Compatibility macros with the CRYPTO names */
00051 #define CRYPTO_set_mem_functions    R_set_mem_functions
00052 #define CRYPTO_get_mem_functions    R_get_mem_functions
00053 #define CRYPTO_malloc               R_malloc
00054 #define CRYPTO_realloc              R_realloc
00055 #define CRYPTO_free                 R_free
00056 #define CRYPTO_remalloc             R_remalloc
00057 #endif /*  !NO_CRYPTO_MEM */
00058 
00066 /*
00067  * R_MDEBUG can be defined when the library is compiled to include the
00068  * debug versions of memory functions. The R_MDEBUG definition cannot
00069  * be usefully defined when linking with an existing library binary
00070  * that has not been built with that definition. To include some debugging
00071  * information with an existing library binary implement debug code in a
00072  * set of functions that can be set with the R_set_mem_functions() call.
00073  *
00074  * If either CRYPTO_MDEBUG or R_MDEBUG are defined, developers must ensure
00075  * that both definitions exist.
00076  */
00077 #ifndef NO_CRYPTO_MEM
00078 #if (defined(CRYPTO_MDEBUG) && !defined(R_MDEBUG))
00079 #define R_MDEBUG
00080 #endif
00081 #endif /*  !NO_CRYPTO_MEM */
00082 
00083 #ifdef R_MDEBUG
00084 /* Get the debug versions of Malloc, and other memory macros */
00085 #include "r_memdbg.h"
00086 #else
00087 #if !defined(NO_MFUNC)
00088 
00100 #define Malloc      R_malloc
00101 
00116 #define Realloc(a,new_num,old_num)  \
00117             R_realloc((char *)(a),(new_num),(old_num))
00118 #define FreeFunc    R_free
00119 
00129 #define Free(addr)  R_free((char *)(addr))
00130 #else /* NO_MFUNC */
00131 
00143 #define Malloc      malloc
00144 
00159 #define Realloc(a,new_num,old_num)    realloc((a),(new_num))
00160 #define FreeFunc    free
00161 
00171 #define Free(addr)  free((char *)(addr))
00172 #endif /* NO_MFUNC */
00173 
00174 /* Remalloc is a call to Free an existing pointer and then Malloc a new
00175  * one of the specified size.
00176  */
00177 #define Remalloc    R_remalloc
00178 
00179 #ifndef NO_MEM_CHECK
00180 /* these macros are only used in debug mode */
00181 #define MemCheck_start()
00182 #define MemCheck_stop()
00183 #define MemCheck_on()
00184 #define MemCheck_off()
00185 #define MemCheck_begin()
00186 
00187 #ifndef Mem_get_mh_mode
00188 #define Mem_get_mh_mode()    0
00189 #endif
00190 #endif /* !NO_MEM_CHECK */
00191 
00192 #endif /* R_MDEBUG */
00193 
00194 /*
00195  * Locking memory functions may be customized to allocate memory that holds
00196  * sensitive data that should not be swapped to disk as part of a virtual
00197  * memory system. NOTE: There are no specific debug versions of these macros.
00198  */
00199 #if !defined(NO_MFUNC)
00200 #else /* !NO_MFUNC */
00201 #define Malloc_locked         malloc
00202 #define Free_locked(addr)     free((char *)(addr))
00203 #endif /* NO_MFUNC */
00204 
00215 typedef char  * R_CDECL R_MEM_MALLOC_FUNCTION_T(size_t num);
00216 
00229 typedef char  * R_CDECL R_MEM_REALLOC_FUNCTION_T(char *addr, size_t num_new,
00230                         size_t num_old);
00231 
00238 typedef void  R_CDECL R_MEM_FREE_FUNCTION_T(char *str);
00239 
00240 void R_CDECL R_set_mem_functions(R_MEM_MALLOC_FUNCTION_T *malloc_function,
00241         R_MEM_REALLOC_FUNCTION_T *realloc_function,
00242         R_MEM_FREE_FUNCTION_T *free_function);
00243 
00244 void R_CDECL R_get_mem_functions(R_MEM_MALLOC_FUNCTION_T **malloc_function,
00245         R_MEM_REALLOC_FUNCTION_T **realloc_function,
00246         R_MEM_FREE_FUNCTION_T **free_function);
00247 
00248 char * R_CDECL R_malloc(size_t num);
00249 void R_CDECL R_free(char *str);
00250 char * R_CDECL R_realloc(char *addr, size_t num_new, size_t num_old);
00251 char * R_CDECL R_remalloc(char *addr, size_t num);
00252 
00253 int R_CDECL R_mem_ctrl(int mode);
00254 
00259 #ifdef  __cplusplus
00260 }
00261 #endif
00262 #endif /* HEADER_COMMON_R_MEM_H */
00263 
00264 

Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 072-001001-2100-001-000 - 2.1