/* Format trace of user ta. Inline with kernel ta */ void trace_printf(const char *function, int line, int level, bool level_ok, const char *fmt, ...) { va_list ap; char buf[MAX_PRINT_SIZE]; size_t boffs = 0; int res; if (level_ok && level > trace_level) return; if (function) { int thread_id = trace_ext_get_thread_id(); if (thread_id >= 0) res = snprintf(buf, sizeof(buf), "%s [0x%x] %s:%s:%d: ", trace_level_to_string(level, level_ok), thread_id, trace_ext_prefix, function, line); else res = snprintf(buf, sizeof(buf), "%s %s:%s:%d: ", trace_level_to_string(level, level_ok), trace_ext_prefix, function, line); if (res < 0) return; /* "Can't happen" */ boffs = res; } va_start(ap, fmt); res = vsnprintf(buf + boffs, sizeof(buf) - boffs, fmt, ap); va_end(ap); if (res > 0) boffs += res; if (boffs >= sizeof(buf)) { boffs = sizeof(buf) - 2; /* Make there's a newline at the end */ buf[boffs] = '\n'; } else if (buf[boffs - 1] != '\n') { /* Append a newline */ buf[boffs] = '\n'; buf[boffs + 1] = '\0'; } trace_ext_puts(buf); }
/* Format trace of user ta. Inline with kernel ta */ void trace_printf(const char *function, int line, int level, bool level_ok, const char *fmt, ...) { va_list ap; char buf[MAX_PRINT_SIZE]; size_t boffs = 0; int res; int thread_id; if (level_ok && level > trace_level) return; /* Print the type of message */ res = snprintk(buf, sizeof(buf), "%c/", trace_level_to_string(level, level_ok)); if (res < 0) return; boffs += res; /* Print the location, i.e., TEE core or TA */ res = snprintk(buf + boffs, sizeof(buf) - boffs, "%s:", trace_ext_prefix); if (res < 0) return; boffs += res; /* Print the Thread ID */ if (level_ok && !(BIT(level) & CFG_MSG_LONG_PREFIX_MASK)) thread_id = -1; else thread_id = trace_ext_get_thread_id(); res = print_thread_id(buf + boffs, sizeof(buf) - boffs, thread_id); if (res < 0) return; boffs += res; /* Print the function and line */ if (level_ok && !(BIT(level) & CFG_MSG_LONG_PREFIX_MASK)) function = NULL; if (function) { res = snprintk(buf + boffs, sizeof(buf) - boffs, "%s:%d ", function, line); if (res < 0) return; boffs += res; } va_start(ap, fmt); res = vsnprintk(buf + boffs, sizeof(buf) - boffs, fmt, ap); va_end(ap); if (res > 0) boffs += res; if (boffs >= (sizeof(buf) - 1)) boffs = sizeof(buf) - 2; buf[boffs] = '\n'; while (boffs && buf[boffs] == '\n') boffs--; boffs++; buf[boffs + 1] = '\0'; trace_ext_puts(buf); }