1 /* 2 * Copyright (c) 2024, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef __FATAL_ERROR_H__ 9 #define __FATAL_ERROR_H__ 10 11 #include <stdint.h> 12 #include <stdbool.h> 13 14 #ifdef HALT_ON_FATAL_ERROR 15 #define ERROR_HALT() while(1); 16 #else 17 #define ERROR_HALT() 18 #endif /* HALT_ON_FATAL_ERROR */ 19 20 #ifdef FATAL_ERR_LOG_FILE_AND_LINE 21 #define ERR_FILE __FILE__ 22 #define ERR_LINE __LINE__ 23 #else 24 #define ERR_FILE NULL 25 #define ERR_LINE 0 26 #endif /* FATAL_ERR_LOG_FILE_AND_LINE */ 27 28 29 bool log_error_permissions_check(uint32_t err, bool is_fatal); 30 void log_error(char *file, uint32_t line, uint32_t err, void *sp, bool is_fatal); 31 32 #ifdef LOG_FATAL_ERRORS 33 #define FATAL_ERR(x) do { \ 34 uint32_t foo; \ 35 if (log_error_permissions_check(x, true)) { \ 36 log_error(ERR_FILE, ERR_LINE, x, &foo, true); \ 37 } \ 38 ERROR_HALT(); \ 39 } while(0); 40 #else 41 #define FATAL_ERR(x) ERROR_HALT(); 42 #endif /* LOG_FATAL_ERRORS */ 43 44 #ifdef LOG_NONFATAL_ERRORS 45 #define NONFATAL_ERR(x) do { \ 46 uint32_t foo; \ 47 if (log_error_permissions_check(x, false)) { \ 48 log_error(ERR_FILE, ERR_LINE, x, &foo, false); \ 49 } \ 50 } while(0); 51 #else 52 #define NONFATAL_ERR(x) 53 #endif /* LOG_NONFATAL_ERRORS */ 54 55 #endif /* __FATAL_ERROR_H__ */ 56