err_local.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <openssl/err.h>
  10. #include <openssl/e_os2.h>
  11. static ossl_inline void err_get_slot(ERR_STATE *es)
  12. {
  13. es->top = (es->top + 1) % ERR_NUM_ERRORS;
  14. if (es->top == es->bottom)
  15. es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS;
  16. }
  17. static ossl_inline void err_clear_data(ERR_STATE *es, size_t i, int deall)
  18. {
  19. if (es->err_data_flags[i] & ERR_TXT_MALLOCED) {
  20. if (deall) {
  21. OPENSSL_free(es->err_data[i]);
  22. es->err_data[i] = NULL;
  23. es->err_data_size[i] = 0;
  24. es->err_data_flags[i] = 0;
  25. } else if (es->err_data[i] != NULL) {
  26. es->err_data[i][0] = '\0';
  27. }
  28. } else {
  29. es->err_data[i] = NULL;
  30. es->err_data_size[i] = 0;
  31. es->err_data_flags[i] = 0;
  32. }
  33. }
  34. static ossl_inline void err_set_error(ERR_STATE *es, size_t i,
  35. int lib, int reason)
  36. {
  37. es->err_buffer[i] =
  38. lib == ERR_LIB_SYS
  39. ? (unsigned int)(ERR_SYSTEM_FLAG | reason)
  40. : ERR_PACK(lib, 0, reason);
  41. }
  42. static ossl_inline void err_set_debug(ERR_STATE *es, size_t i,
  43. const char *file, int line,
  44. const char *fn)
  45. {
  46. es->err_file[i] = file;
  47. es->err_line[i] = line;
  48. es->err_func[i] = fn;
  49. }
  50. static ossl_inline void err_set_data(ERR_STATE *es, size_t i,
  51. void *data, size_t datasz, int flags)
  52. {
  53. es->err_data[i] = data;
  54. es->err_data_size[i] = datasz;
  55. es->err_data_flags[i] = flags;
  56. }
  57. static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall)
  58. {
  59. err_clear_data(es, i, (deall));
  60. es->err_flags[i] = 0;
  61. es->err_buffer[i] = 0;
  62. es->err_file[i] = NULL;
  63. es->err_line[i] = -1;
  64. }
  65. ERR_STATE *err_get_state_int(void);