RSA BSAFE Micro Edition Suite

Streamlined security for mobile and embedded devices

Search  Print

r_lock.h

Go to the documentation of this file.
00001 /* $Id: r_lock.h,v 1.76.6.1 2005/10/17 02:07:05 hpriddle 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  */
00015 #ifndef HEADER_COMMON_R_LOCK_H
00016 #define HEADER_COMMON_R_LOCK_H
00017 
00018 #ifdef  __cplusplus
00019 extern "C" {
00020 #endif
00021 
00022 #define CRYPTO_LOCK             R_LOCK_LOCK
00023 #define CRYPTO_UNLOCK           R_LOCK_UNLOCK
00024 #define CRYPTO_READ             R_LOCK_READ
00025 #define CRYPTO_WRITE            R_LOCK_WRITE
00026 
00027 
00049 #define R_LOCK_LOCK                 1
00050 
00054 #define R_LOCK_UNLOCK               2
00055 
00059 #define R_LOCK_READ                 4
00060 
00064 #define R_LOCK_WRITE                8
00065 
00070 #ifndef NO_LOCKING
00071 #define CRYPTO_r_lock(a)            R_lock_r(a)
00072 #define CRYPTO_r_unlock(a)          R_unlock_r(a)
00073 #define CRYPTO_w_lock(a)            R_lock_w(a)
00074 #define CRYPTO_w_unlock(a)          R_unlock_w(a)
00075 #define CRYPTO_add(a,b,c)           R_add(a,b,c)
00076 #define CRYPTO_add_lock(a,b,c)      R_locked_add(a,b,c)
00077 
00078 #define CRYPTO_get_id_cb()          R_thread_id_get_cb()
00079 #define CRYPTO_set_id_cb(f)         R_thread_id_set_cb(f)
00080 #define CRYPTO_thread_id()          R_thread_id()
00081 
00082 
00083 #else /* NO_LOCKING */
00084 #define CRYPTO_w_lock(a)
00085 #define CRYPTO_w_unlock(a)
00086 #define CRYPTO_r_lock(a)
00087 #define CRYPTO_r_unlock(a)
00088 #define CRYPTO_add(a,b,c)           ((*(a))+=(b))
00089 #define CRYPTO_thread_id()          0
00090 #endif /* !NO_LOCKING */
00091 
00092 #define CRYPTO_LOCK_ERR             R_LOCK_ERR
00093 #define CRYPTO_LOCK_ERR_HASH        R_LOCK_ERR_HASH
00094 #define CRYPTO_LOCK_X509            R_LOCK_X509
00095 #define CRYPTO_LOCK_X509_INFO       R_LOCK_X509_INFO
00096 #define CRYPTO_LOCK_X509_PKEY       R_LOCK_X509_PKEY
00097 #define CRYPTO_LOCK_X509_CRL        R_LOCK_X509_CRL
00098 #define CRYPTO_LOCK_X509_REQ        R_LOCK_X509_REQ
00099 #define CRYPTO_LOCK_DSA             R_LOCK_DSA
00100 #define CRYPTO_LOCK_RSA             R_LOCK_RSA
00101 #define CRYPTO_LOCK_X509_STORE      R_LOCK_X509_STORE
00102 #define CRYPTO_LOCK_SSL_CTX         R_LOCK_SSL_CTX
00103 #define CRYPTO_LOCK_SSL_CERT        R_LOCK_SSL_CERT
00104 #define CRYPTO_LOCK_SSL_SESSION     R_LOCK_SSL_SESSION
00105 #define CRYPTO_LOCK_SSL             R_LOCK_SSL
00106 #define CRYPTO_LOCK_EVP_PKEY        R_LOCK_EVP_PKEY
00107 #define CRYPTO_LOCK_RAND            R_LOCK_RAND
00108 #define CRYPTO_LOCK_MALLOC          R_LOCK_MALLOC
00109 #define CRYPTO_LOCK_BIO             R_LOCK_BIO
00110 #define CRYPTO_LOCK_SIO_GETHOSTBYNAME   \
00111                                     R_LOCK_SIO_GETHOSTBYNAME
00112 #define CRYPTO_LOCK_MALLOC_MOD      R_LOCK_MALLOC_MOD
00113 #define CRYPTO_LOCK_RSA_HOOK        R_LOCK_RSA_HOOK
00114 #define CRYPTO_LOCK_DH              R_LOCK_DH
00115 
00127 #define R_LOCK_INVALID               0
00128 
00131 #define R_LOCK_ERR                   1
00132 /*
00133  * Indicates a lock on error hash.
00134  */
00135 #define R_LOCK_ERR_HASH              2
00136 #define R_LOCK_X509                  3
00137 #define R_LOCK_X509_INFO             4
00138 #define R_LOCK_X509_PKEY             5
00139 #define R_LOCK_X509_CRL              6
00140 #define R_LOCK_X509_REQ              7
00141 
00144 #define R_LOCK_DSA                   8
00145 
00148 #define R_LOCK_RSA                   9
00149 
00152 #define R_LOCK_EVP_PKEY             10
00153 #define R_LOCK_R_PKEY               R_LOCK_EVP_PKEY
00154 
00155 #define R_LOCK_X509_STORE           11
00156 
00159 #define R_LOCK_SSL_CTX              12
00160 
00163 #define R_LOCK_SSL_CERT             13
00164 
00167 #define R_LOCK_SSL_SESSION          14
00168 
00171 #define R_LOCK_SSL                  15
00172 
00175 #define R_LOCK_RAND                 16
00176 /*
00177  * Indicates a lock on <tt>malloc</tt>.
00178  */
00179 #define R_LOCK_MALLOC               17
00180 
00183 #define R_LOCK_BIO                  18
00184 
00187 #define R_LOCK_SIO_GETHOSTBYNAME    19
00188 /*
00189  * Indicates a lock on the malloc module.
00190  */
00191 #define R_LOCK_MALLOC_MOD           21
00192 /*
00193  * Indicates a lock on the RSA hook.
00194  */
00195 #define R_LOCK_RSA_HOOK             22
00196 
00199 #define R_LOCK_DH                   23
00200 
00203 #define R_LOCK_APP_LOCK             24
00204 #define R_LOCK_R_CACHE_LOCK         25
00205 
00208 #define R_LOCK_GET_MODULE           26
00209 #define R_LOCK_R_CERT_STORE_LOCK    27
00210 #define R_LOCK_R_CERT               28
00211 
00212 #define R_LOCK_DEVICE               29
00213 #define R_LOCK_HW_CTX               30
00214 #define R_LOCK_MALLOC_WRAP          31
00215 #define R_LOCK_HDW_SESSION_POOL     32
00216 
00221 #define R_LOCK_RAND_SHAREABLE       33
00222 
00226 #define R_LOCK_NUM                  34
00227 
00232 /* old names */
00233 #define CRYPTO_set_locking_callback(x)     CRYPTO_set_locking_cb(x)
00234 #define CRYPTO_get_locking_callback()      CRYPTO_get_locking_cb()
00235 #define CRYPTO_set_add_lock_callback(x)    CRYPTO_set_add_lock_cb(x)
00236 #define CRYPTO_get_add_lock_callback()     CRYPTO_get_add_lock_cb()
00237 #define CRYPTO_set_id_callback(x)          CRYPTO_set_id_cb(x)
00238 #define CRYPTO_get_id_callback()           CRYPTO_get_id_cb()
00239 
00240 #define CRYPTO_get_new_lockid(name)        R_lockid_new(name)
00241 #define CRYPTO_get_num_locks()             R_lock_num()
00242 #define CRYPTO_set_locking_cb(func)        R_lock_set_cb(func)
00243 #define CRYPTO_get_locking_cb()            R_lock_get_cb()
00244 #define CRYPTO_set_add_lock_cb(func)       R_locked_add_set_cb(func)
00245 #define CRYPTO_get_add_lock_cb()           R_locked_add_get_cb()
00246 #define CRYPTO_get_lock_name(lockid)       R_lock_get_name(lockid)
00247 #define CRYPTO_lock(mode,lockid,file,line) R_lock_ctrl(mode,lockid,file,line)
00248 
00249 
00250 /*
00251  * @defgroup LOCK_FUNCS Functions
00252  * This section outlines the functions that implement the toolkit's
00253  * locking functionality.
00254  * @ingroup R_LOCK_FUNCS
00255  * @{
00256  */
00257 
00258 #ifdef NO_R_LOCK
00259 
00260 #define R_lock_w(type)
00261 #define R_unlock_w(type)
00262 #define R_lock_r(type)
00263 #define R_unlock_r(type)
00264 #define R_add(addr,amount,type)         (*(addr)=*(addr)+(amount))
00265 #define R_lock(mode,type,file,line)
00266 #define R_unlock(mode,type,file,line)
00267 
00268 #else /* NO_R_LOCK */
00269 
00270 #ifndef R_lock_w
00271 
00290 #define R_lock_w(lockid)    \
00291     R_lock(R_LOCK_WRITE,lockid,__FILE__,__LINE__)
00292 
00314 #define R_unlock_w(lockid)  \
00315     R_unlock(R_LOCK_WRITE,lockid,__FILE__,__LINE__)
00316 
00338 #define R_lock_r(type)  \
00339     R_lock(R_LOCK_READ,type,__FILE__,__LINE__)
00340 
00357 #define R_unlock_r(lockid)  \
00358     R_unlock(R_LOCK_READ,lockid,__FILE__,__LINE__)
00359 
00377 #define R_add(addr,amount,type) \
00378     R_locked_add(addr,amount,type,__FILE__,__LINE__)
00379 
00405 #define R_lock(mode,lockid,file,line)   \
00406     R_lock_ctrl(R_LOCK_LOCK|(mode),lockid,file,line)
00407 
00433 #define R_unlock(mode,lockid,file,line) \
00434     R_lock_ctrl(R_LOCK_UNLOCK|(mode),lockid,file,line)
00435 
00436 #endif /* ! R_lock_w */
00437 
00438 #endif /* NO_R_LOCK */
00439 
00440 #ifdef NO_R_LOCK
00441 
00442 #define R_lockid_new(a)
00443 #define R_lockids_free()
00444 #define R_lock_num()                    0
00445 #define R_lock_get_name(a)
00446 #define R_lock_get_cb()
00447 #define R_locked_add_get_cb()
00448 #define R_lock_set_cb(a)
00449 #define R_locked_add_set_cb(a)
00450 #define R_lock_ctrl(a,b,c,d)
00451 #define R_locked_add(a,b,c,d,e)
00452 #define R_thread_id_get_cb()
00453 #define R_thread_id_set_cb(a)
00454 #define R_thread_id()                   0
00455 
00456 #else /* !NO_R_LOCK */
00457 
00476 typedef int  R_CDECL R_LOCK_CB_T(int mode, int lockid, char *file, int line);
00477 R_LOCK_CB_T * R_CDECL R_lock_get_cb(void);
00478 int R_CDECL R_lock_set_cb(R_LOCK_CB_T *func);
00479 
00493 typedef int  R_CDECL R_LOCKED_ADD_CB_T(int *num, int amount, int lockid, char *file,
00494     int line);
00495 R_LOCKED_ADD_CB_T * R_CDECL R_locked_add_get_cb(void);
00496 int R_CDECL R_locked_add_set_cb(R_LOCKED_ADD_CB_T *func);
00497 
00498 int R_CDECL R_lockid_new(char *name);
00499 void R_CDECL R_lockids_free(void);
00500 int R_CDECL R_lock_num(void);
00501 char * R_CDECL R_lock_get_name(int lockid);
00502 int R_CDECL R_lock_ctrl(int mode, int lockid, char *file, int line);
00503 int R_CDECL R_locked_add(int *pointer, int amount, int lockid, char *file, int line);
00504 
00511 typedef unsigned long  R_CDECL R_THREAD_ID_CB_T(void);
00512 
00513 int R_CDECL R_thread_id_set_cb(R_THREAD_ID_CB_T *func);
00514 R_THREAD_ID_CB_T * R_CDECL R_thread_id_get_cb(void);
00515 
00516 unsigned long R_CDECL R_thread_id(void);
00517 
00518 #endif /* NO_R_LOCK */
00519 
00520 /*
00521  * @}
00522  */
00523 
00524 #ifdef  __cplusplus
00525 }
00526 #endif
00527 
00528 #endif /* HEADER_COMMON_R_LOCK_H */
00529 
00530 

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