| 1 | /* |
| 2 | * Copyright 1995-2019 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 | |
| 10 | #include <openssl/err.h> |
| 11 | #include <openssl/e_os2.h> |
| 12 | |
| 13 | static ossl_inline void err_get_slot(ERR_STATE *es) |
| 14 | { |
| 15 | es->top = (es->top + 1) % ERR_NUM_ERRORS; |
| 16 | if (es->top == es->bottom) |
| 17 | es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS; |
| 18 | } |
| 19 | |
| 20 | static ossl_inline void err_clear_data(ERR_STATE *es, size_t i, int deall) |
| 21 | { |
| 22 | if (es->err_data_flags[i] & ERR_TXT_MALLOCED) { |
| 23 | if (deall) { |
| 24 | OPENSSL_free(es->err_data[i]); |
| 25 | es->err_data[i] = NULL; |
| 26 | es->err_data_size[i] = 0; |
| 27 | es->err_data_flags[i] = 0; |
| 28 | } else if (es->err_data[i] != NULL) { |
| 29 | es->err_data[i][0] = '\0'; |
| 30 | } |
| 31 | } else { |
| 32 | es->err_data[i] = NULL; |
| 33 | es->err_data_size[i] = 0; |
| 34 | es->err_data_flags[i] = 0; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | static ossl_inline void err_set_error(ERR_STATE *es, size_t i, |
| 39 | int lib, int reason) |
| 40 | { |
| 41 | es->err_buffer[i] = ERR_PACK(lib, 0, reason); |
| 42 | } |
| 43 | |
| 44 | static ossl_inline void err_set_debug(ERR_STATE *es, size_t i, |
| 45 | const char *file, int line, |
| 46 | const char *fn) |
| 47 | { |
| 48 | es->err_file[i] = file; |
| 49 | es->err_line[i] = line; |
| 50 | es->err_func[i] = fn; |
| 51 | } |
| 52 | |
| 53 | static ossl_inline void err_set_data(ERR_STATE *es, size_t i, |
| 54 | void *data, size_t datasz, int flags) |
| 55 | { |
| 56 | es->err_data[i] = data; |
| 57 | es->err_data_size[i] = datasz; |
| 58 | es->err_data_flags[i] = flags; |
| 59 | } |
| 60 | |
| 61 | static ossl_inline void err_clear(ERR_STATE *es, size_t i, int deall) |
| 62 | { |
| 63 | err_clear_data(es, i, (deall)); |
| 64 | es->err_flags[i] = 0; |
| 65 | es->err_buffer[i] = 0; |
| 66 | es->err_file[i] = NULL; |
| 67 | es->err_line[i] = -1; |
| 68 | } |
| 69 | |
| 70 | ERR_STATE *err_get_state_int(void); |
| 71 | |