Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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. */
  57. /* ====================================================================
  58. * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
  59. *
  60. * Redistribution and use in source and binary forms, with or without
  61. * modification, are permitted provided that the following conditions
  62. * are met:
  63. *
  64. * 1. Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. *
  67. * 2. Redistributions in binary form must reproduce the above copyright
  68. * notice, this list of conditions and the following disclaimer in
  69. * the documentation and/or other materials provided with the
  70. * distribution.
  71. *
  72. * 3. All advertising materials mentioning features or use of this
  73. * software must display the following acknowledgment:
  74. * "This product includes software developed by the OpenSSL Project
  75. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  76. *
  77. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  78. * endorse or promote products derived from this software without
  79. * prior written permission. For written permission, please contact
  80. * openssl-core@openssl.org.
  81. *
  82. * 5. Products derived from this software may not be called "OpenSSL"
  83. * nor may "OpenSSL" appear in their names without prior written
  84. * permission of the OpenSSL Project.
  85. *
  86. * 6. Redistributions of any form whatsoever must retain the following
  87. * acknowledgment:
  88. * "This product includes software developed by the OpenSSL Project
  89. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  90. *
  91. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  92. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  93. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  94. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  95. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  96. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  97. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  98. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  99. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  100. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  101. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  102. * OF THE POSSIBILITY OF SUCH DAMAGE.
  103. * ====================================================================
  104. *
  105. * This product includes cryptographic software written by Eric Young
  106. * (eay@cryptsoft.com). This product includes software written by Tim
  107. * Hudson (tjh@cryptsoft.com). */
  108. #ifndef OPENSSL_HEADER_ERR_H
  109. #define OPENSSL_HEADER_ERR_H
  110. #include <openssl/base.h>
  111. #include <openssl/thread.h>
  112. #include <openssl/lhash.h>
  113. #if defined(__cplusplus)
  114. extern "C" {
  115. #endif
  116. /* Error queue handling functions.
  117. *
  118. * Errors in OpenSSL are generally signalled by the return value of a function.
  119. * When a function fails it may add an entry to a per-thread error queue,
  120. * which is managed by the functions in this header.
  121. *
  122. * Each error contains:
  123. * 1) The library (i.e. ec, pem, rsa) which created it.
  124. * 2) A function identifier and reason code.
  125. * 3) The file and line number of the call that added the error.
  126. * 4) A pointer to some error specific data, which may be NULL.
  127. *
  128. * The library identifier, function identifier and reason code are packed in a
  129. * uint32_t and there exist various functions for unpacking it.
  130. *
  131. * The typical behaviour is that an error will occur deep in a call queue and
  132. * that code will push an error onto the error queue. As the error queue
  133. * unwinds, other functions will push their own errors. Thus, the "least
  134. * recent" error is the most specific and the other errors will provide a
  135. * backtrace of sorts. */
  136. /* Startup and shutdown. */
  137. /* ERR_load_crypto_strings initialises the error string hash with builtin
  138. * values. If this is not called then the string forms of errors produced by
  139. * the functions below will contain numeric identifiers rather than
  140. * human-readable strings. */
  141. OPENSSL_EXPORT void ERR_load_crypto_strings(void);
  142. /* ERR_free_strings frees any internal error values that have been loaded. This
  143. * should only be called at process shutdown. */
  144. OPENSSL_EXPORT void ERR_free_strings(void);
  145. /* Reading and formatting errors. */
  146. /* ERR_get_error gets the packed error code for the least recent error and
  147. * removes that error from the queue. If there are no errors in the queue then
  148. * it returns zero. */
  149. OPENSSL_EXPORT uint32_t ERR_get_error(void);
  150. /* ERR_get_error_line acts like |ERR_get_error|, except that the file and line
  151. * number of the call that added the error are also returned. */
  152. OPENSSL_EXPORT uint32_t ERR_get_error_line(const char **file, int *line);
  153. /* ERR_get_error_line_data acts like |ERR_get_error_line|, but also returns the
  154. * error-specific data pointer and flags. The flags are a bitwise-OR of
  155. * |ERR_FLAG_*| values. The error-specific data is owned by the error queue
  156. * and the pointer becomes invalid after the next call that affects the same
  157. * thread's error queue. If |*flags| contains |ERR_FLAG_STRING| then |*data| is
  158. * human-readable. */
  159. OPENSSL_EXPORT uint32_t ERR_get_error_line_data(const char **file, int *line,
  160. const char **data, int *flags);
  161. /* The "peek" functions act like the |ERR_get_error| functions, above, but they
  162. * do not remove the error from the queue. */
  163. OPENSSL_EXPORT uint32_t ERR_peek_error(void);
  164. OPENSSL_EXPORT uint32_t ERR_peek_error_line(const char **file, int *line);
  165. OPENSSL_EXPORT uint32_t ERR_peek_error_line_data(const char **file, int *line,
  166. const char **data, int *flags);
  167. /* The "peek last" functions act like the "peek" functions, above, except that
  168. * they return the most recent error. */
  169. OPENSSL_EXPORT uint32_t ERR_peek_last_error(void);
  170. OPENSSL_EXPORT uint32_t ERR_peek_last_error_line(const char **file, int *line);
  171. OPENSSL_EXPORT uint32_t
  172. ERR_peek_last_error_line_data(const char **file, int *line,
  173. const char **data, int *flags);
  174. /* ERR_error_string generates a human-readable string representing
  175. * |packed_error|, places it at |buf| (which must be at least
  176. * ERR_ERROR_STRING_BUF_LEN bytes long) and returns |buf|. If |buf| is NULL,
  177. * the error string is placed in a static buffer which is returned. (The static
  178. * buffer may be overridden by concurrent calls in other threads so this form
  179. * is deprecated.)
  180. *
  181. * The string will have the following format:
  182. *
  183. * error:[error code]:[library name]:[function name]:[reason string]
  184. *
  185. * error code is an 8 digit hexadecimal number; library name, function name
  186. * and reason string are ASCII text.
  187. *
  188. * TODO(fork): remove in favour of |ERR_error_string_n|. */
  189. OPENSSL_EXPORT char *ERR_error_string(uint32_t packed_error, char *buf);
  190. #define ERR_ERROR_STRING_BUF_LEN 256
  191. /* ERR_error_string_n is a variant of |ERR_error_string| that writes at most
  192. * len characters (including the terminating NUL) and truncates the string if
  193. * necessary. If |len| is greater than zero then |buf| is always NUL
  194. * terminated. */
  195. OPENSSL_EXPORT void ERR_error_string_n(uint32_t packed_error, char *buf,
  196. size_t len);
  197. /* ERR_lib_error_string returns a string representation of the library that
  198. * generated |packed_error|. */
  199. OPENSSL_EXPORT const char *ERR_lib_error_string(uint32_t packed_error);
  200. /* ERR_func_error_string returns a string representation of the function that
  201. * generated |packed_error|. */
  202. OPENSSL_EXPORT const char *ERR_func_error_string(uint32_t packed_error);
  203. /* ERR_reason_error_string returns a string representation of the reason for
  204. * |packed_error|. */
  205. OPENSSL_EXPORT const char *ERR_reason_error_string(uint32_t packed_error);
  206. /* ERR_print_errors_callback_t is the type of a function used by
  207. * |ERR_print_errors_cb|. It takes a pointer to a human readable string (and
  208. * its length) that describes an entry in the error queue. The |ctx| argument
  209. * is an opaque pointer given to |ERR_print_errors_cb|.
  210. *
  211. * It should return one on success or zero on error, which will stop the
  212. * iteration over the error queue. */
  213. typedef int (*ERR_print_errors_callback_t)(const char *str, size_t len,
  214. void *ctx);
  215. /* ERR_print_errors_cb calls |callback| with a string representation of each
  216. * error in the current thread's error queue, from the least recent to the most
  217. * recent error.
  218. *
  219. * The string will have the following format (which differs from
  220. * |ERR_error_string|):
  221. *
  222. * [thread id]:error:[error code]:[library name]:[function name]:
  223. * [reason string]:[file]:[line number]:[optional string data]
  224. *
  225. * (All in one line.)
  226. *
  227. * The callback can return one to continue the iteration or zero to stop it.
  228. * The |ctx| argument is an opaque value that is passed through to the
  229. * callback. */
  230. OPENSSL_EXPORT void ERR_print_errors_cb(ERR_print_errors_callback_t callback,
  231. void *ctx);
  232. /* Clearing errors. */
  233. /* ERR_clear_error clears the error queue for the current thread. */
  234. OPENSSL_EXPORT void ERR_clear_error(void);
  235. /* ERR_remove_thread_state deletes the error queue for the given thread. If
  236. * |tid| is NULL then the error queue for the current thread is deleted. */
  237. OPENSSL_EXPORT void ERR_remove_thread_state(const CRYPTO_THREADID *tid);
  238. /* Custom errors. */
  239. /* ERR_get_next_error_library returns a value suitable for passing as the
  240. * |library| argument to |ERR_put_error|. This is intended for code that wishes
  241. * to push its own, non-standard errors to the error queue. */
  242. OPENSSL_EXPORT int ERR_get_next_error_library(void);
  243. /* Private functions. */
  244. /* ERR_clear_system_error clears the system's error value (i.e. errno). */
  245. OPENSSL_EXPORT void ERR_clear_system_error(void);
  246. /* OPENSSL_PUT_ERROR is used by OpenSSL code to add an error to the error
  247. * queue. */
  248. #define OPENSSL_PUT_ERROR(library, func, reason) \
  249. ERR_put_error(ERR_LIB_##library, library##_F_##func, reason, __FILE__, \
  250. __LINE__)
  251. /* OPENSSL_PUT_SYSTEM_ERROR is used by OpenSSL code to add an error from the
  252. * operating system to the error queue. */
  253. /* TODO(fork): include errno. */
  254. #define OPENSSL_PUT_SYSTEM_ERROR(func) \
  255. ERR_put_error(ERR_LIB_SYS, SYS_F_##func, 0, __FILE__, __LINE__);
  256. /* ERR_put_error adds an error to the error queue, dropping the least recent
  257. * error if neccessary for space reasons. */
  258. OPENSSL_EXPORT void ERR_put_error(int library, int func, int reason,
  259. const char *file, unsigned line);
  260. /* ERR_add_error_data takes a variable number (|count|) of const char*
  261. * pointers, concatenates them and sets the result as the data on the most
  262. * recent error. */
  263. OPENSSL_EXPORT void ERR_add_error_data(unsigned count, ...);
  264. /* ERR_add_error_dataf takes a printf-style format and arguments, and sets the
  265. * result as the data on the most recent error. */
  266. OPENSSL_EXPORT void ERR_add_error_dataf(const char *format, ...);
  267. /* ERR_set_mark "marks" the most recent error for use with |ERR_pop_to_mark|.
  268. * It returns one if an error was marked and zero if there are no errors. */
  269. OPENSSL_EXPORT int ERR_set_mark(void);
  270. /* ERR_pop_to_mark removes errors from the most recent to the least recent
  271. * until (and not including) a "marked" error. It returns zero if no marked
  272. * error was found (and thus all errors were removed) and one otherwise. Errors
  273. * are marked using |ERR_set_mark|. */
  274. OPENSSL_EXPORT int ERR_pop_to_mark(void);
  275. struct err_error_st {
  276. /* file contains the filename where the error occured. */
  277. const char *file;
  278. /* data contains optional data. It must be freed with |OPENSSL_free| if
  279. * |flags&ERR_FLAG_MALLOCED|. */
  280. char *data;
  281. /* packed contains the error library, function and reason, as packed by
  282. * ERR_PACK. */
  283. uint32_t packed;
  284. /* line contains the line number where the error occured. */
  285. uint16_t line;
  286. /* flags contains a bitwise-OR of ERR_FLAG_* values. */
  287. uint8_t flags;
  288. };
  289. /* ERR_FLAG_STRING means that the |data| member is a NUL-terminated string that
  290. * can be printed. */
  291. #define ERR_FLAG_STRING 1
  292. /* ERR_TXT_STRING is provided for compatibility with code that assumes that
  293. * it's using OpenSSL. */
  294. #define ERR_TXT_STRING ERR_FLAG_STRING
  295. /* ERR_FLAG_PUBLIC_MASK is applied to the flags field before it is returned
  296. * from functions like |ERR_get_error_line_data|. */
  297. #define ERR_FLAG_PUBLIC_MASK 0xf
  298. /* The following flag values are internal and are masked when flags are
  299. * returned from functions like |ERR_get_error_line_data|. */
  300. /* ERR_FLAG_MALLOCED means the the |data| member must be freed when no longer
  301. * needed. */
  302. #define ERR_FLAG_MALLOCED 16
  303. /* ERR_FLAG_MARK is used to indicate a reversion point in the queue. See
  304. * |ERR_pop_to_mark|. */
  305. #define ERR_FLAG_MARK 32
  306. /* ERR_NUM_ERRORS is the limit of the number of errors in the queue. */
  307. #define ERR_NUM_ERRORS 16
  308. /* ERR_STATE contains the per-thread, error queue. */
  309. typedef struct err_state_st {
  310. /* tid is the identifier of the thread that owns this queue. */
  311. CRYPTO_THREADID tid;
  312. /* errors contains the ERR_NUM_ERRORS most recent errors, organised as a ring
  313. * buffer. */
  314. struct err_error_st errors[ERR_NUM_ERRORS];
  315. /* top contains the index one past the most recent error. If |top| equals
  316. * |bottom| then the queue is empty. */
  317. unsigned top;
  318. /* bottom contains the index of the last error in the queue. */
  319. unsigned bottom;
  320. /* to_free, if not NULL, contains a pointer owned by this structure that was
  321. * previously a |data| pointer of one of the elements of |errors|. */
  322. void *to_free;
  323. } ERR_STATE;
  324. enum {
  325. ERR_LIB_NONE = 1,
  326. ERR_LIB_SYS,
  327. ERR_LIB_BN,
  328. ERR_LIB_RSA,
  329. ERR_LIB_DH,
  330. ERR_LIB_EVP,
  331. ERR_LIB_BUF,
  332. ERR_LIB_OBJ,
  333. ERR_LIB_PEM,
  334. ERR_LIB_DSA,
  335. ERR_LIB_X509,
  336. ERR_LIB_ASN1,
  337. ERR_LIB_CONF,
  338. ERR_LIB_CRYPTO,
  339. ERR_LIB_EC,
  340. ERR_LIB_SSL,
  341. ERR_LIB_BIO,
  342. ERR_LIB_PKCS7,
  343. ERR_LIB_PKCS8,
  344. ERR_LIB_X509V3,
  345. ERR_LIB_PKCS12,
  346. ERR_LIB_RAND,
  347. ERR_LIB_ENGINE,
  348. ERR_LIB_OCSP,
  349. ERR_LIB_UI,
  350. ERR_LIB_COMP,
  351. ERR_LIB_ECDSA,
  352. ERR_LIB_ECDH,
  353. ERR_LIB_HMAC,
  354. ERR_LIB_DIGEST,
  355. ERR_LIB_CIPHER,
  356. ERR_LIB_USER,
  357. ERR_NUM_LIBS
  358. };
  359. #define ERR_R_SYS_LIB ERR_LIB_SYS
  360. #define ERR_R_BN_LIB ERR_LIB_BN
  361. #define ERR_R_RSA_LIB ERR_LIB_RSA
  362. #define ERR_R_DH_LIB ERR_LIB_DH
  363. #define ERR_R_EVP_LIB ERR_LIB_EVP
  364. #define ERR_R_BUF_LIB ERR_LIB_BUF
  365. #define ERR_R_OBJ_LIB ERR_LIB_OBJ
  366. #define ERR_R_PEM_LIB ERR_LIB_PEM
  367. #define ERR_R_DSA_LIB ERR_LIB_DSA
  368. #define ERR_R_X509_LIB ERR_LIB_X509
  369. #define ERR_R_ASN1_LIB ERR_LIB_ASN1
  370. #define ERR_R_CONF_LIB ERR_LIB_CONF
  371. #define ERR_R_CRYPTO_LIB ERR_LIB_CRYPTO
  372. #define ERR_R_EC_LIB ERR_LIB_EC
  373. #define ERR_R_SSL_LIB ERR_LIB_SSL
  374. #define ERR_R_BIO_LIB ERR_LIB_BIO
  375. #define ERR_R_PKCS7_LIB ERR_LIB_PKCS7
  376. #define ERR_R_PKCS8_LIB ERR_LIB_PKCS8
  377. #define ERR_R_X509V3_LIB ERR_LIB_X509V3
  378. #define ERR_R_PKCS12_LIB ERR_LIB_PKCS12
  379. #define ERR_R_RAND_LIB ERR_LIB_RAND
  380. #define ERR_R_DSO_LIB ERR_LIB_DSO
  381. #define ERR_R_ENGINE_LIB ERR_LIB_ENGINE
  382. #define ERR_R_OCSP_LIB ERR_LIB_OCSP
  383. #define ERR_R_UI_LIB ERR_LIB_UI
  384. #define ERR_R_COMP_LIB ERR_LIB_COMP
  385. #define ERR_R_ECDSA_LIB ERR_LIB_ECDSA
  386. #define ERR_R_ECDH_LIB ERR_LIB_ECDH
  387. #define ERR_R_STORE_LIB ERR_LIB_STORE
  388. #define ERR_R_FIPS_LIB ERR_LIB_FIPS
  389. #define ERR_R_CMS_LIB ERR_LIB_CMS
  390. #define ERR_R_TS_LIB ERR_LIB_TS
  391. #define ERR_R_HMAC_LIB ERR_LIB_HMAC
  392. #define ERR_R_JPAKE_LIB ERR_LIB_JPAKE
  393. #define ERR_R_USER_LIB ERR_LIB_USER
  394. #define ERR_R_DIGEST_LIB ERR_LIB_DIGEST
  395. #define ERR_R_CIPHER_LIB ERR_LIB_CIPHER
  396. /* Global reasons. */
  397. #define ERR_R_FATAL 64
  398. #define ERR_R_MALLOC_FAILURE (1 | ERR_R_FATAL)
  399. #define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2 | ERR_R_FATAL)
  400. #define ERR_R_PASSED_NULL_PARAMETER (3 | ERR_R_FATAL)
  401. #define ERR_R_INTERNAL_ERROR (4 | ERR_R_FATAL)
  402. #define ERR_R_OVERFLOW (5 | ERR_R_FATAL)
  403. /* System error functions */
  404. #define SYS_F_fopen 100
  405. #define SYS_F_fclose 101
  406. #define SYS_F_fread 102
  407. #define SYS_F_fwrite 103
  408. #define SYS_F_socket 104
  409. #define SYS_F_setsockopt 105
  410. #define SYS_F_connect 106
  411. #define SYS_F_getaddrinfo 107
  412. #define ERR_PACK(lib, func, reason) \
  413. (((((uint32_t)lib) & 0xff) << 24) | ((((uint32_t)func) & 0xfff) << 12) | \
  414. ((((uint32_t)reason) & 0xfff)))
  415. #define ERR_GET_LIB(packed_error) ((int)(((packed_error) >> 24) & 0xff))
  416. #define ERR_GET_FUNC(packed_error) ((int)(((packed_error) >> 12) & 0xfff))
  417. #define ERR_GET_REASON(packed_error) ((int)((packed_error) & 0xfff))
  418. /* ERR_STRING_DATA is the type of an lhash node that contains a mapping from a
  419. * library, function or reason code to a string representation of it. */
  420. typedef struct err_string_data_st {
  421. uint32_t error;
  422. const char *string;
  423. } ERR_STRING_DATA;
  424. /* ERR_load_strings loads an array of ERR_STRING_DATA into the hash table. The
  425. * array must be terminated by an entry with a NULL string. */
  426. OPENSSL_EXPORT void ERR_load_strings(const ERR_STRING_DATA *str);
  427. /* ERR_FNS_st is a structure of function pointers that contains the actual
  428. * implementation of the error queue handling functions. */
  429. struct ERR_FNS_st {
  430. void (*shutdown)(void);
  431. ERR_STRING_DATA *(*get_item)(uint32_t packed_error);
  432. ERR_STRING_DATA *(*set_item)(const ERR_STRING_DATA *);
  433. ERR_STRING_DATA *(*del_item)(uint32_t packed_error);
  434. /* get_state returns the ERR_STATE for the current thread. This function
  435. * never returns NULL. */
  436. ERR_STATE *(*get_state)(void);
  437. /* release_state returns the |ERR_STATE| for the given thread, or NULL if
  438. * none exists. It the return value is not NULL, it also returns ownership of
  439. * the |ERR_STATE| and deletes it from its data structures. */
  440. ERR_STATE *(*release_state)(const CRYPTO_THREADID *tid);
  441. /* get_next_library returns a unique value suitable for passing as the
  442. * |library| to error calls. It will be distinct from all built-in library
  443. * values. */
  444. int (*get_next_library)(void);
  445. };
  446. /* OPENSSL_DECLARE_ERROR_REASON is used by util/make_errors.h (which generates
  447. * the error defines) to recognise that an additional reason value is needed.
  448. * This is needed when the reason value is used outside of an
  449. * |OPENSSL_PUT_ERROR| macro. The resulting define will be
  450. * ${lib}_R_${reason}. */
  451. #define OPENSSL_DECLARE_ERROR_REASON(lib, reason)
  452. /* OPENSSL_DECLARE_ERROR_FUNCTION is used by util/make_errors.h (which
  453. * generates the error * defines to recognise that an additional function value
  454. * is needed. This is * needed when the function value is used outside of an
  455. * |OPENSSL_PUT_ERROR| * macro. The resulting define will be
  456. * ${lib}_F_${reason}. */
  457. #define OPENSSL_DECLARE_ERROR_FUNCTION(lib, function_name)
  458. /* ERR_load_BIO_strings does nothing.
  459. *
  460. * TODO(fork): remove. libjingle calls this. */
  461. OPENSSL_EXPORT void ERR_load_BIO_strings(void);
  462. #if defined(__cplusplus)
  463. } /* extern C */
  464. #endif
  465. #endif /* OPENSSL_HEADER_ERR_H */