25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

239 satır
10 KiB

  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.] */
  56. #ifndef OPENSSL_HEADER_THREAD_H
  57. #define OPENSSL_HEADER_THREAD_H
  58. #include <openssl/base.h>
  59. #if defined(__cplusplus)
  60. extern "C" {
  61. #endif
  62. /* Functions to support multithreading.
  63. *
  64. * OpenSSL can safely be used in multi-threaded applications provided that at
  65. * least |CRYPTO_set_locking_callback| is set.
  66. *
  67. * The locking callback performs mutual exclusion. Rather than using a single
  68. * lock for all, shared data-structures, OpenSSL requires that the locking
  69. * callback support a fixed (at run-time) number of different locks, given by
  70. * |CRYPTO_num_locks|. */
  71. /* CRYPTO_num_locks returns the number of static locks that the callback
  72. * function passed to |CRYPTO_set_locking_callback| must be able to handle. */
  73. OPENSSL_EXPORT int CRYPTO_num_locks(void);
  74. /* CRYPTO_set_locking_callback sets a callback function that implements locking
  75. * on behalf of OpenSSL. The callback is called whenever OpenSSL needs to lock
  76. * or unlock a lock, and locks are specified as a number between zero and
  77. * |CRYPTO_num_locks()-1|.
  78. *
  79. * The mode argument to the callback is a bitwise-OR of either CRYPTO_LOCK or
  80. * CRYPTO_UNLOCK, to denote the action, and CRYPTO_READ or CRYPTO_WRITE, to
  81. * indicate the type of lock. The |file| and |line| arguments give the location
  82. * in the OpenSSL source where the locking action originated. */
  83. OPENSSL_EXPORT void CRYPTO_set_locking_callback(
  84. void (*func)(int mode, int lock_num, const char *file, int line));
  85. /* CRYPTO_set_add_lock_callback sets an optional callback which is used when
  86. * OpenSSL needs to add a fixed amount to an integer. For example, this is used
  87. * when maintaining reference counts. Normally the reference counts are
  88. * maintained by performing the addition under a lock but, if this callback
  89. * has been set, the application is free to implement the operation using
  90. * faster methods (i.e. atomic operations).
  91. *
  92. * The callback is given a pointer to the integer to be altered (|num|), the
  93. * amount to add to the integer (|amount|, which may be negative), the number
  94. * of the lock which would have been taken to protect the operation and the
  95. * position in the OpenSSL code where the operation originated. */
  96. OPENSSL_EXPORT void CRYPTO_set_add_lock_callback(int (*func)(
  97. int *num, int amount, int lock_num, const char *file, int line));
  98. /* CRYPTO_get_lock_name returns the name of the lock given by |lock_num|. This
  99. * can be used in a locking callback for debugging purposes. */
  100. OPENSSL_EXPORT const char *CRYPTO_get_lock_name(int lock_num);
  101. /* Deprecated functions */
  102. /* CRYPTO_THREADID is a dummy value. */
  103. typedef int CRYPTO_THREADID;
  104. /* CRYPTO_THREADID_set_callback does nothing. */
  105. OPENSSL_EXPORT int CRYPTO_THREADID_set_callback(
  106. void (*threadid_func)(CRYPTO_THREADID *threadid));
  107. /* CRYPTO_THREADID_set_numeric does nothing. */
  108. OPENSSL_EXPORT void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id,
  109. unsigned long val);
  110. /* CRYPTO_THREADID_set_pointer does nothing. */
  111. OPENSSL_EXPORT void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr);
  112. /* CRYPTO_THREADID_current does nothing. */
  113. OPENSSL_EXPORT void CRYPTO_THREADID_current(CRYPTO_THREADID *id);
  114. /* Private functions: */
  115. /* CRYPTO_get_locking_callback returns the callback, if any, that was most
  116. * recently set using |CRYPTO_set_locking_callback|. */
  117. void (*CRYPTO_get_locking_callback(void))(int mode, int lock_num,
  118. const char *file, int line);
  119. /* CRYPTO_get_add_lock_callback returns the callback, if any, that was most
  120. * recently set using |CRYPTO_set_add_lock_callback|. */
  121. int (*CRYPTO_get_add_lock_callback(void))(int *num, int amount, int lock_num,
  122. const char *file, int line);
  123. /* CRYPTO_lock locks or unlocks the lock specified by |lock_num| (one of
  124. * |CRYPTO_LOCK_*|). Don't call this directly, rather use one of the
  125. * CRYPTO_[rw]_(un)lock macros. */
  126. OPENSSL_EXPORT void CRYPTO_lock(int mode, int lock_num, const char *file,
  127. int line);
  128. /* CRYPTO_add_lock adds |amount| to |*pointer|, protected by the lock specified
  129. * by |lock_num|. It returns the new value of |*pointer|. Don't call this
  130. * function directly, rather use the |CRYPTO_add| macro. */
  131. OPENSSL_EXPORT int CRYPTO_add_lock(int *pointer, int amount, int lock_num,
  132. const char *file, int line);
  133. /* Lock IDs start from 1. CRYPTO_LOCK_INVALID_LOCK is an unused placeholder
  134. * used to ensure no lock has ID 0. */
  135. #define CRYPTO_LOCK_LIST \
  136. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_INVALID_LOCK), \
  137. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_BIO), \
  138. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_DH), \
  139. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_DSA), \
  140. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EC), \
  141. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EC_PRE_COMP), \
  142. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_ERR), \
  143. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EVP_PKEY), \
  144. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_EX_DATA), \
  145. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_OBJ), \
  146. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_RAND), \
  147. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_READDIR), \
  148. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_RSA), \
  149. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_RSA_BLINDING), \
  150. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_SSL_CTX), \
  151. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_SSL_SESSION), \
  152. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509), \
  153. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_INFO), \
  154. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_PKEY), \
  155. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_CRL), \
  156. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_REQ), \
  157. CRYPTO_LOCK_ITEM(CRYPTO_LOCK_X509_STORE), \
  158. #define CRYPTO_LOCK_ITEM(x) x
  159. enum {
  160. CRYPTO_LOCK_LIST
  161. };
  162. #undef CRYPTO_LOCK_ITEM
  163. #define CRYPTO_LOCK 1
  164. #define CRYPTO_UNLOCK 2
  165. #define CRYPTO_READ 4
  166. #define CRYPTO_WRITE 8
  167. #define CRYPTO_w_lock(lock_num) \
  168. CRYPTO_lock(CRYPTO_LOCK | CRYPTO_WRITE, lock_num, __FILE__, __LINE__)
  169. #define CRYPTO_w_unlock(lock_num) \
  170. CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_WRITE, lock_num, __FILE__, __LINE__)
  171. #define CRYPTO_r_lock(lock_num) \
  172. CRYPTO_lock(CRYPTO_LOCK | CRYPTO_READ, lock_num, __FILE__, __LINE__)
  173. #define CRYPTO_r_unlock(lock_num) \
  174. CRYPTO_lock(CRYPTO_UNLOCK | CRYPTO_READ, lock_num, __FILE__, __LINE__)
  175. #define CRYPTO_add(addr, amount, lock_num) \
  176. CRYPTO_add_lock(addr, amount, lock_num, __FILE__, __LINE__)
  177. /* Private functions.
  178. *
  179. * Some old code calls these functions and so no-op implementations are
  180. * provided.
  181. *
  182. * TODO(fork): cleanup callers and remove. */
  183. OPENSSL_EXPORT void CRYPTO_set_id_callback(unsigned long (*func)(void));
  184. typedef struct {
  185. int references;
  186. struct CRYPTO_dynlock_value *data;
  187. } CRYPTO_dynlock;
  188. OPENSSL_EXPORT void CRYPTO_set_dynlock_create_callback(
  189. struct CRYPTO_dynlock_value *(*dyn_create_function)(const char *file,
  190. int line));
  191. OPENSSL_EXPORT void CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)(
  192. int mode, struct CRYPTO_dynlock_value *l, const char *file, int line));
  193. OPENSSL_EXPORT void CRYPTO_set_dynlock_destroy_callback(
  194. void (*dyn_destroy_function)(struct CRYPTO_dynlock_value *l,
  195. const char *file, int line));
  196. #if defined(__cplusplus)
  197. } /* extern C */
  198. #endif
  199. #endif /* OPENSSL_HEADER_THREAD_H */