40 EM_ESCOPE_API_IS_NOT_PART_EM_ESCOPE__ERROR);
42 EM_ESCOPE_INTERNAL_IS_NOT_PART_OF_EM_ESCOPE__ERROR);
44 static int error_handler_initialized;
46 static early_log_t early_log = {default_log, vdefault_log};
53 increment_global_err_cnt(
void)
55 env_atomic64_inc(&
em_shm->error_handler.global_error_count);
59 load_global_err_cnt(
void)
62 env_atomic64_get(&
em_shm->error_handler.global_error_count);
67 ODP_PRINTF_FORMAT(2, 0)
68 int vdefault_log(
em_log_level_t level, const
char *fmt, va_list args)
84 r = vfprintf(logfd, fmt, args);
88 ODP_PRINTF_FORMAT(2, 3)
95 r = vdefault_log(level, fmt, args);
122 int core_id = odp_cpu_id();
131 char *file = va_arg(args,
char*);
132 const char *func = va_arg(args,
const char*);
133 const int line = va_arg(args,
const int);
134 const char *format = va_arg(args,
const char*);
135 const char *base = basename(file);
138 log_fn(EM_LOG_ERR,
"\n"
139 "EM ERROR:0x%08X ESCOPE:0x%08X (Early Error)\n"
140 "core:%02i %s:%i %s()\n",
141 error, escope, core_id, base, line, func);
142 vlog_fn(EM_LOG_ERR, format, args);
143 log_fn(EM_LOG_ERR,
"\n");
146 log_fn(EM_LOG_ERR,
"\n"
147 "APPL ERROR:0x%08X ESCOPE:0x%08X (Early Error)\n"
149 error, escope, core_id);
154 "FATAL EM ERROR:0x%08X (Early Error) - ABORT!\n",
186 const uint64_t global_err_cnt = load_global_err_cnt();
195 eo_name[nlen] =
'\0';
197 snprintf(eo_str,
sizeof(eo_str),
198 "EO:%" PRI_EO "-\"%s\" ", eo, eo_name);
199 eo_str[
sizeof(eo_str) - 1] =
'\0';
207 char *file = va_arg(args,
char*);
208 const char *func = va_arg(args,
const char*);
209 const int line = va_arg(args,
const int);
210 const char *format = va_arg(args,
const char*);
211 const char *base = basename(file);
213 EM_LOG(EM_LOG_ERR,
"\n"
214 "EM ERROR:0x%08X ESCOPE:0x%08X %s\n"
215 "core:%02i ecount:%" PRIu64
"(%" PRIu64
") %s:%i %s()\n",
216 error, escope, eo_str, core_id,
217 global_err_cnt, local_err_cnt,
219 EM_VLOG(EM_LOG_ERR, format, args);
220 EM_LOG(EM_LOG_ERR,
"\n");
223 EM_LOG(EM_LOG_ERR,
"\n"
224 "APPL ERROR:0x%08X ESCOPE:0x%08X %s\n"
225 "core:%02i ecount:%" PRIu64
"(%" PRIu64
")\n",
226 error, escope, eo_str, core_id,
227 global_err_cnt, local_err_cnt);
231 EM_LOG(EM_LOG_ERR,
"FATAL EM ERROR:0x%08X - ABORT!\n", error);
252 if (unlikely(!error_handler_initialized)) {
257 error = early_error_handler(
EM_EO_UNDEF, error, escope,
265 const eo_elem_t *
const eo_elem = eo_elem_current();
269 error_handler =
em_shm->error_handler.em_error_handler;
271 if (eo_elem && eo_allocated(eo_elem)) {
275 error_handler = eo_handler;
279 if (unlikely(error_handler == NULL)) {
280 error_handler = early_error_handler;
281 log_fn = early_log.log_fn;
287 error = error_handler(eo, error, escope, args_list);
289 if (error !=
EM_OK) {
291 increment_global_err_cnt();
300 "FATAL EM ERROR:0x%08X ESCOPE:0x%08X - ABORT!\n"
301 "EM: an error-handler must not return a fatal EM-error!",
324 va_start(args, escope);
341 env_spinlock_init(&
em_shm->error_handler.lock);
345 env_atomic64_init(&
em_shm->error_handler.global_error_count);
347 em_shm->error_handler.initialized = 1;
348 error_handler_initialized = 1;
355 int is_log_null = user_log_fn == NULL;
356 int is_vlog_null = user_vlog_fn == NULL;
358 if (is_log_null != is_vlog_null)
362 if (user_log_fn != NULL) {
363 early_log.log_fn = user_log_fn;
364 early_log.vlog_fn = user_vlog_fn;