2018-05-16 08:50:33 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Nordic Semiconductor ASA
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
#include <logging/log_msg.h>
|
|
|
|
#include "log_list.h"
|
|
|
|
#include <logging/log.h>
|
|
|
|
#include <logging/log_backend.h>
|
|
|
|
#include <logging/log_ctrl.h>
|
|
|
|
#include <logging/log_output.h>
|
2019-06-26 16:33:49 +02:00
|
|
|
#include <sys/printk.h>
|
2018-10-19 23:14:27 +02:00
|
|
|
#include <init.h>
|
2018-05-16 08:50:33 +02:00
|
|
|
#include <assert.h>
|
2019-06-25 18:25:32 +02:00
|
|
|
#include <sys/atomic.h>
|
2019-05-21 13:03:13 +02:00
|
|
|
#include <ctype.h>
|
2019-06-13 15:00:51 +02:00
|
|
|
#include <logging/log_frontend.h>
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#include <syscall_handler.h>
|
2019-05-21 13:03:13 +02:00
|
|
|
|
|
|
|
LOG_MODULE_REGISTER(log);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
|
|
|
#ifndef CONFIG_LOG_PRINTK_MAX_STRING_LENGTH
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#define CONFIG_LOG_PRINTK_MAX_STRING_LENGTH 0
|
2018-05-16 08:50:33 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-10 08:37:15 +01:00
|
|
|
#ifndef CONFIG_LOG_PROCESS_THREAD_SLEEP_MS
|
|
|
|
#define CONFIG_LOG_PROCESS_THREAD_SLEEP_MS 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD
|
|
|
|
#define CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_LOG_PROCESS_THREAD_STACK_SIZE
|
|
|
|
#define CONFIG_LOG_PROCESS_THREAD_STACK_SIZE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_LOG_STRDUP_MAX_STRING
|
|
|
|
#define CONFIG_LOG_STRDUP_MAX_STRING 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_LOG_STRDUP_BUF_COUNT
|
|
|
|
#define CONFIG_LOG_STRDUP_BUF_COUNT 0
|
|
|
|
#endif
|
|
|
|
|
2018-10-26 13:07:31 +02:00
|
|
|
struct log_strdup_buf {
|
|
|
|
atomic_t refcount;
|
|
|
|
char buf[CONFIG_LOG_STRDUP_MAX_STRING + 1]; /* for termination */
|
|
|
|
};
|
2018-09-20 11:41:20 +02:00
|
|
|
|
|
|
|
#define LOG_STRDUP_POOL_BUFFER_SIZE \
|
2018-10-26 13:07:31 +02:00
|
|
|
(sizeof(struct log_strdup_buf) * CONFIG_LOG_STRDUP_BUF_COUNT)
|
2018-09-20 11:41:20 +02:00
|
|
|
|
2019-09-29 10:40:39 +02:00
|
|
|
K_SEM_DEFINE(log_process_thread_sem, 0, 1);
|
|
|
|
|
2018-11-26 21:50:28 +01:00
|
|
|
static const char *log_strdup_fail_msg = "<log_strdup alloc failed>";
|
2018-09-20 11:41:20 +02:00
|
|
|
struct k_mem_slab log_strdup_pool;
|
2020-05-27 18:26:57 +02:00
|
|
|
static uint8_t __noinit __aligned(sizeof(void *))
|
2018-09-20 11:41:20 +02:00
|
|
|
log_strdup_pool_buf[LOG_STRDUP_POOL_BUFFER_SIZE];
|
|
|
|
|
2018-05-16 08:50:33 +02:00
|
|
|
static struct log_list_t list;
|
2018-07-11 12:26:31 +02:00
|
|
|
static atomic_t initialized;
|
2018-05-16 08:50:33 +02:00
|
|
|
static bool panic_mode;
|
2018-10-11 08:28:44 +02:00
|
|
|
static bool backend_attached;
|
2018-06-27 10:47:14 +02:00
|
|
|
static atomic_t buffered_cnt;
|
2018-11-30 15:28:16 +01:00
|
|
|
static atomic_t dropped_cnt;
|
2018-06-27 10:47:14 +02:00
|
|
|
static k_tid_t proc_tid;
|
2020-05-27 18:26:57 +02:00
|
|
|
static uint32_t log_strdup_in_use;
|
|
|
|
static uint32_t log_strdup_max;
|
|
|
|
static uint32_t log_strdup_longest;
|
2019-09-29 10:40:39 +02:00
|
|
|
static struct k_timer log_process_thread_timer;
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
static uint32_t dummy_timestamp(void);
|
2018-07-11 12:26:31 +02:00
|
|
|
static timestamp_get_t timestamp_func = dummy_timestamp;
|
|
|
|
|
2019-05-21 13:03:13 +02:00
|
|
|
|
|
|
|
bool log_is_strdup(const void *buf);
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
static uint32_t dummy_timestamp(void)
|
2018-07-11 12:26:31 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t z_log_get_s_mask(const char *str, uint32_t nargs)
|
2019-05-21 13:03:13 +02:00
|
|
|
{
|
|
|
|
char curr;
|
|
|
|
bool arm = false;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t arg = 0;
|
|
|
|
uint32_t mask = 0;
|
2019-05-21 13:03:13 +02:00
|
|
|
|
|
|
|
__ASSERT_NO_MSG(nargs <= 8*sizeof(mask));
|
|
|
|
|
|
|
|
while ((curr = *str++) && arg < nargs) {
|
|
|
|
if (curr == '%') {
|
|
|
|
arm = !arm;
|
2019-12-13 02:13:05 +01:00
|
|
|
} else if (arm && isalpha((int)curr)) {
|
2019-05-21 13:03:13 +02:00
|
|
|
if (curr == 's') {
|
|
|
|
mask |= BIT(arg);
|
|
|
|
}
|
|
|
|
arm = false;
|
|
|
|
arg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check if address is in read only section.
|
|
|
|
*
|
|
|
|
* @param addr Address.
|
|
|
|
*
|
|
|
|
* @return True if address identified within read only section.
|
|
|
|
*/
|
|
|
|
static bool is_rodata(const void *addr)
|
|
|
|
{
|
2019-06-25 22:06:40 +02:00
|
|
|
#if defined(CONFIG_ARM) || defined(CONFIG_ARC) || defined(CONFIG_X86)
|
2019-05-21 13:03:13 +02:00
|
|
|
extern const char *_image_rodata_start[];
|
|
|
|
extern const char *_image_rodata_end[];
|
|
|
|
#define RO_START _image_rodata_start
|
|
|
|
#define RO_END _image_rodata_end
|
2019-07-17 19:17:05 +02:00
|
|
|
#elif defined(CONFIG_NIOS2) || defined(CONFIG_RISCV)
|
2019-05-21 13:03:13 +02:00
|
|
|
extern const char *_image_rom_start[];
|
|
|
|
extern const char *_image_rom_end[];
|
|
|
|
#define RO_START _image_rom_start
|
|
|
|
#define RO_END _image_rom_end
|
|
|
|
#elif defined(CONFIG_XTENSA)
|
|
|
|
extern const char *_rodata_start[];
|
|
|
|
extern const char *_rodata_end[];
|
|
|
|
#define RO_START _rodata_start
|
|
|
|
#define RO_END _rodata_end
|
|
|
|
#else
|
|
|
|
#define RO_START 0
|
|
|
|
#define RO_END 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (((const char *)addr >= (const char *)RO_START) &&
|
|
|
|
((const char *)addr < (const char *)RO_END));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-06-10 12:31:34 +02:00
|
|
|
* @brief Scan string arguments and report every address which is not in read
|
2019-05-21 13:03:13 +02:00
|
|
|
* only memory and not yet duplicated.
|
|
|
|
*
|
|
|
|
* @param msg Log message.
|
|
|
|
*/
|
|
|
|
static void detect_missed_strdup(struct log_msg *msg)
|
|
|
|
{
|
2019-12-18 10:22:13 +01:00
|
|
|
#define ERR_MSG "argument %d in source %s log message \"%s\" missing" \
|
|
|
|
"log_strdup()."
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t idx;
|
2019-05-21 13:03:13 +02:00
|
|
|
const char *str;
|
2019-06-10 12:31:34 +02:00
|
|
|
const char *msg_str;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t mask;
|
2019-06-10 12:31:34 +02:00
|
|
|
|
|
|
|
if (!log_msg_is_std(msg)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_str = log_msg_str_get(msg);
|
2019-12-12 11:51:00 +01:00
|
|
|
mask = z_log_get_s_mask(msg_str, log_msg_nargs_get(msg));
|
2019-05-21 13:03:13 +02:00
|
|
|
|
|
|
|
while (mask) {
|
|
|
|
idx = 31 - __builtin_clz(mask);
|
|
|
|
str = (const char *)log_msg_arg_get(msg, idx);
|
|
|
|
if (!is_rodata(str) && !log_is_strdup(str) &&
|
|
|
|
(str != log_strdup_fail_msg)) {
|
2019-12-18 10:22:13 +01:00
|
|
|
const char *src_name =
|
|
|
|
log_source_name_get(CONFIG_LOG_DOMAIN_ID,
|
|
|
|
log_msg_source_id_get(msg));
|
|
|
|
|
2019-05-21 13:03:13 +02:00
|
|
|
if (IS_ENABLED(CONFIG_ASSERT)) {
|
2019-12-18 10:22:13 +01:00
|
|
|
__ASSERT(0, ERR_MSG, idx, src_name, msg_str);
|
2019-05-21 13:03:13 +02:00
|
|
|
} else {
|
2019-12-18 10:22:13 +01:00
|
|
|
LOG_ERR(ERR_MSG, idx, src_name, msg_str);
|
2019-05-21 13:03:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mask &= ~BIT(idx);
|
|
|
|
}
|
|
|
|
#undef ERR_MSG
|
|
|
|
}
|
|
|
|
|
2018-05-16 08:50:33 +02:00
|
|
|
static inline void msg_finalize(struct log_msg *msg,
|
|
|
|
struct log_msg_ids src_level)
|
|
|
|
{
|
2018-06-27 10:47:14 +02:00
|
|
|
unsigned int key;
|
|
|
|
|
2018-05-16 08:50:33 +02:00
|
|
|
msg->hdr.ids = src_level;
|
|
|
|
msg->hdr.timestamp = timestamp_func();
|
2018-06-27 10:47:14 +02:00
|
|
|
|
2018-07-10 09:43:49 +02:00
|
|
|
atomic_inc(&buffered_cnt);
|
|
|
|
|
2018-06-27 10:47:14 +02:00
|
|
|
key = irq_lock();
|
2018-05-16 08:50:33 +02:00
|
|
|
|
|
|
|
log_list_add_tail(&list, msg);
|
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
|
2019-01-10 08:37:15 +01:00
|
|
|
if (panic_mode) {
|
2019-07-03 13:09:21 +02:00
|
|
|
key = irq_lock();
|
2018-05-16 08:50:33 +02:00
|
|
|
(void)log_process(false);
|
2019-07-03 13:09:21 +02:00
|
|
|
irq_unlock(key);
|
2019-09-29 10:40:39 +02:00
|
|
|
} else if (proc_tid != NULL && buffered_cnt == 1) {
|
|
|
|
k_timer_start(&log_process_thread_timer,
|
2020-03-05 23:54:28 +01:00
|
|
|
K_MSEC(CONFIG_LOG_PROCESS_THREAD_SLEEP_MS), K_NO_WAIT);
|
2019-01-10 08:37:15 +01:00
|
|
|
} else if (CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) {
|
|
|
|
if ((buffered_cnt == CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) &&
|
|
|
|
(proc_tid != NULL)) {
|
2019-09-29 10:40:39 +02:00
|
|
|
k_timer_stop(&log_process_thread_timer);
|
|
|
|
k_sem_give(&log_process_thread_sem);
|
2018-07-24 19:40:33 +02:00
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_0(const char *str, struct log_msg_ids src_level)
|
|
|
|
{
|
2019-06-13 15:00:51 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
|
|
|
|
log_frontend_0(str, src_level);
|
|
|
|
} else {
|
|
|
|
struct log_msg *msg = log_msg_create_0(str);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
if (msg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
msg_finalize(msg, src_level);
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_1(const char *str,
|
2019-05-21 20:10:15 +02:00
|
|
|
log_arg_t arg0,
|
2018-05-16 08:50:33 +02:00
|
|
|
struct log_msg_ids src_level)
|
|
|
|
{
|
2019-06-13 15:00:51 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
|
|
|
|
log_frontend_1(str, arg0, src_level);
|
|
|
|
} else {
|
|
|
|
struct log_msg *msg = log_msg_create_1(str, arg0);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
if (msg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
msg_finalize(msg, src_level);
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_2(const char *str,
|
2019-05-21 20:10:15 +02:00
|
|
|
log_arg_t arg0,
|
|
|
|
log_arg_t arg1,
|
2018-05-16 08:50:33 +02:00
|
|
|
struct log_msg_ids src_level)
|
|
|
|
{
|
2019-06-13 15:00:51 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
|
|
|
|
log_frontend_2(str, arg0, arg1, src_level);
|
|
|
|
} else {
|
|
|
|
struct log_msg *msg = log_msg_create_2(str, arg0, arg1);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
if (msg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
msg_finalize(msg, src_level);
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void log_3(const char *str,
|
2019-05-21 20:10:15 +02:00
|
|
|
log_arg_t arg0,
|
|
|
|
log_arg_t arg1,
|
|
|
|
log_arg_t arg2,
|
2018-05-16 08:50:33 +02:00
|
|
|
struct log_msg_ids src_level)
|
|
|
|
{
|
2019-06-13 15:00:51 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
|
|
|
|
log_frontend_3(str, arg0, arg1, arg2, src_level);
|
|
|
|
} else {
|
|
|
|
struct log_msg *msg = log_msg_create_3(str, arg0, arg1, arg2);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
if (msg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
msg_finalize(msg, src_level);
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void log_n(const char *str,
|
2019-05-21 20:10:15 +02:00
|
|
|
log_arg_t *args,
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t narg,
|
2018-05-16 08:50:33 +02:00
|
|
|
struct log_msg_ids src_level)
|
|
|
|
{
|
2019-06-13 15:00:51 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
|
|
|
|
log_frontend_n(str, args, narg, src_level);
|
|
|
|
} else {
|
|
|
|
struct log_msg *msg = log_msg_create_n(str, args, narg);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
if (msg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
msg_finalize(msg, src_level);
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
void log_hexdump(const char *str, const void *data, uint32_t length,
|
2018-05-16 08:50:33 +02:00
|
|
|
struct log_msg_ids src_level)
|
|
|
|
{
|
2019-06-13 15:00:51 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
|
2020-05-27 18:26:57 +02:00
|
|
|
log_frontend_hexdump(str, (const uint8_t *)data, length,
|
2019-12-13 06:16:17 +01:00
|
|
|
src_level);
|
2019-06-13 15:00:51 +02:00
|
|
|
} else {
|
2019-12-13 06:16:17 +01:00
|
|
|
struct log_msg *msg =
|
2020-05-27 18:26:57 +02:00
|
|
|
log_msg_hexdump_create(str, (const uint8_t *)data, length);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
if (msg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
msg_finalize(msg, src_level);
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
2019-09-23 02:02:45 +02:00
|
|
|
void log_printk(const char *fmt, va_list ap)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
2019-01-10 08:37:15 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_PRINTK)) {
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
union {
|
|
|
|
struct log_msg_ids structure;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t value;
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
} src_level_union = {
|
|
|
|
{
|
|
|
|
.level = LOG_LEVEL_INTERNAL_RAW_STRING
|
|
|
|
}
|
2019-01-10 08:37:15 +01:00
|
|
|
};
|
2018-05-16 08:50:33 +02:00
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
if (_is_user_context()) {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t str[CONFIG_LOG_PRINTK_MAX_STRING_LENGTH + 1];
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
|
2019-09-23 02:02:45 +02:00
|
|
|
vsnprintk(str, sizeof(str), fmt, ap);
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
|
|
|
|
z_log_string_from_user(src_level_union.value, str);
|
|
|
|
} else if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
|
2020-03-27 08:24:53 +01:00
|
|
|
log_generic(src_level_union.structure, fmt, ap,
|
|
|
|
LOG_STRDUP_SKIP);
|
2019-01-10 08:37:15 +01:00
|
|
|
} else {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t str[CONFIG_LOG_PRINTK_MAX_STRING_LENGTH + 1];
|
2019-01-10 08:37:15 +01:00
|
|
|
struct log_msg *msg;
|
2019-09-23 02:02:45 +02:00
|
|
|
int length;
|
2018-05-16 08:50:33 +02:00
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
length = vsnprintk(str, sizeof(str), fmt, ap);
|
|
|
|
length = MIN(length, sizeof(str));
|
2018-05-16 08:50:33 +02:00
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
msg = log_msg_hexdump_create(NULL, str, length);
|
2019-01-10 08:37:15 +01:00
|
|
|
if (msg == NULL) {
|
2019-09-23 02:02:45 +02:00
|
|
|
return;
|
2019-01-10 08:37:15 +01:00
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
msg_finalize(msg, src_level_union.structure);
|
2019-01-10 08:37:15 +01:00
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-08 12:00:54 +02:00
|
|
|
/** @brief Count number of arguments in formatted string.
|
|
|
|
*
|
|
|
|
* Function counts number of '%' not followed by '%'.
|
|
|
|
*/
|
2020-03-27 08:24:53 +01:00
|
|
|
uint32_t log_count_args(const char *fmt)
|
2018-10-08 12:00:54 +02:00
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t args = 0U;
|
2018-10-08 12:00:54 +02:00
|
|
|
bool prev = false; /* if previous char was a modificator. */
|
|
|
|
|
|
|
|
while (*fmt != '\0') {
|
|
|
|
if (*fmt == '%') {
|
|
|
|
prev = !prev;
|
|
|
|
} else if (prev) {
|
|
|
|
args++;
|
|
|
|
prev = false;
|
|
|
|
}
|
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2020-03-27 08:24:53 +01:00
|
|
|
void log_generic(struct log_msg_ids src_level, const char *fmt, va_list ap,
|
|
|
|
enum log_strdup_action strdup_action)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
if (_is_user_context()) {
|
|
|
|
log_generic_from_user(src_level, fmt, ap);
|
2020-03-27 08:24:53 +01:00
|
|
|
} else if (IS_ENABLED(CONFIG_LOG_IMMEDIATE) &&
|
2019-06-13 15:00:51 +02:00
|
|
|
(!IS_ENABLED(CONFIG_LOG_FRONTEND))) {
|
2019-01-10 08:37:15 +01:00
|
|
|
struct log_backend const *backend;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t timestamp = timestamp_func();
|
2019-01-10 08:37:15 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < log_backend_count_get(); i++) {
|
|
|
|
backend = log_backend_get(i);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-01-10 08:37:15 +01:00
|
|
|
if (log_backend_is_active(backend)) {
|
|
|
|
log_backend_put_sync_string(backend, src_level,
|
|
|
|
timestamp, fmt, ap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-05-21 20:10:15 +02:00
|
|
|
log_arg_t args[LOG_MAX_NARGS];
|
2020-03-27 08:24:53 +01:00
|
|
|
uint32_t nargs = log_count_args(fmt);
|
2019-01-10 08:37:15 +01:00
|
|
|
|
2019-08-18 01:02:10 +02:00
|
|
|
__ASSERT_NO_MSG(nargs < LOG_MAX_NARGS);
|
2019-01-10 08:37:15 +01:00
|
|
|
for (int i = 0; i < nargs; i++) {
|
2019-05-21 20:10:15 +02:00
|
|
|
args[i] = va_arg(ap, log_arg_t);
|
2019-01-10 08:37:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-27 08:24:53 +01:00
|
|
|
if (strdup_action != LOG_STRDUP_SKIP) {
|
|
|
|
uint32_t mask = z_log_get_s_mask(fmt, nargs);
|
|
|
|
|
|
|
|
while (mask) {
|
|
|
|
uint32_t idx = 31 - __builtin_clz(mask);
|
|
|
|
const char *str = (const char *)args[idx];
|
|
|
|
|
|
|
|
/* is_rodata(str) is not checked,
|
|
|
|
* because log_strdup does it.
|
|
|
|
* Hence, we will do only optional check
|
|
|
|
* if already not duplicated.
|
|
|
|
*/
|
|
|
|
if (strdup_action == LOG_STRDUP_EXEC
|
|
|
|
|| !log_is_strdup(str)) {
|
|
|
|
args[idx] = (log_arg_t)log_strdup(str);
|
|
|
|
}
|
|
|
|
mask &= ~BIT(idx);
|
|
|
|
}
|
|
|
|
}
|
2019-01-10 08:37:15 +01:00
|
|
|
log_n(fmt, args, nargs, src_level);
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
2019-01-10 08:37:15 +01:00
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-01-10 08:37:15 +01:00
|
|
|
void log_string_sync(struct log_msg_ids src_level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
|
2020-03-27 08:24:53 +01:00
|
|
|
log_generic(src_level, fmt, ap, LOG_STRDUP_SKIP);
|
2019-01-10 08:37:15 +01:00
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_hexdump_sync(struct log_msg_ids src_level, const char *metadata,
|
2020-05-27 18:26:57 +02:00
|
|
|
const void *data, uint32_t len)
|
2019-01-10 08:37:15 +01:00
|
|
|
{
|
2019-06-13 15:00:51 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
|
2020-05-27 18:26:57 +02:00
|
|
|
log_frontend_hexdump(metadata, (const uint8_t *)data, len,
|
2019-12-13 06:16:17 +01:00
|
|
|
src_level);
|
2019-06-13 15:00:51 +02:00
|
|
|
} else {
|
|
|
|
struct log_backend const *backend;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t timestamp = timestamp_func();
|
2019-01-10 08:37:15 +01:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
for (int i = 0; i < log_backend_count_get(); i++) {
|
|
|
|
backend = log_backend_get(i);
|
2019-01-10 08:37:15 +01:00
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
if (log_backend_is_active(backend)) {
|
2019-12-13 06:16:17 +01:00
|
|
|
log_backend_put_sync_hexdump(
|
|
|
|
backend, src_level, timestamp, metadata,
|
2020-05-27 18:26:57 +02:00
|
|
|
(const uint8_t *)data, len);
|
2019-06-13 15:00:51 +02:00
|
|
|
}
|
2019-01-10 08:37:15 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
static uint32_t k_cycle_get_32_wrapper(void)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
2019-04-23 15:08:00 +02:00
|
|
|
/*
|
|
|
|
* The k_cycle_get_32() is a define which cannot be referenced
|
|
|
|
* by timestamp_func. Instead, this wrapper is used.
|
|
|
|
*/
|
|
|
|
return k_cycle_get_32();
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
2018-07-11 12:26:31 +02:00
|
|
|
void log_core_init(void)
|
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t freq;
|
2019-03-05 18:14:45 +01:00
|
|
|
|
2019-01-10 08:37:15 +01:00
|
|
|
if (!IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
|
|
|
|
log_msg_pool_init();
|
|
|
|
log_list_init(&list);
|
2018-07-11 12:26:31 +02:00
|
|
|
|
2019-01-10 08:37:15 +01:00
|
|
|
k_mem_slab_init(&log_strdup_pool, log_strdup_pool_buf,
|
|
|
|
sizeof(struct log_strdup_buf),
|
|
|
|
CONFIG_LOG_STRDUP_BUF_COUNT);
|
|
|
|
}
|
2018-12-04 11:22:41 +01:00
|
|
|
|
|
|
|
/* Set default timestamp. */
|
2019-04-23 15:08:00 +02:00
|
|
|
if (sys_clock_hw_cycles_per_sec() > 1000000) {
|
|
|
|
timestamp_func = k_uptime_get_32;
|
|
|
|
freq = 1000;
|
|
|
|
} else {
|
|
|
|
timestamp_func = k_cycle_get_32_wrapper;
|
|
|
|
freq = sys_clock_hw_cycles_per_sec();
|
|
|
|
}
|
|
|
|
|
2019-03-05 18:14:45 +01:00
|
|
|
log_output_timestamp_freq_set(freq);
|
2018-12-04 11:22:41 +01:00
|
|
|
|
2018-07-26 02:58:52 +02:00
|
|
|
/*
|
|
|
|
* Initialize aggregated runtime filter levels (no backends are
|
|
|
|
* attached yet, so leave backend slots in each dynamic filter set
|
|
|
|
* alone for now).
|
|
|
|
*
|
|
|
|
* Each log source's aggregated runtime level is set to match its
|
|
|
|
* compile-time level. When backends are attached later on in
|
|
|
|
* log_init(), they'll be initialized to the same value.
|
2018-07-11 12:26:31 +02:00
|
|
|
*/
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
|
|
|
for (int i = 0; i < log_sources_count(); i++) {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t *filters = log_dynamic_filters_get(i);
|
|
|
|
uint8_t level = log_compiled_level_get(i);
|
2018-07-11 12:26:31 +02:00
|
|
|
|
|
|
|
LOG_FILTER_SLOT_SET(filters,
|
|
|
|
LOG_FILTER_AGGR_SLOT_IDX,
|
2018-07-26 02:58:52 +02:00
|
|
|
level);
|
2018-07-11 12:26:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_init(void)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
|
|
|
assert(log_backend_count_get() < LOG_FILTERS_NUM_OF_SLOTS);
|
2018-07-11 12:26:31 +02:00
|
|
|
int i;
|
|
|
|
|
2019-06-13 15:00:51 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
|
|
|
|
log_frontend_init();
|
|
|
|
}
|
|
|
|
|
2018-12-17 20:33:10 +01:00
|
|
|
if (atomic_inc(&initialized) != 0) {
|
2018-07-11 12:26:31 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2018-07-11 12:26:31 +02:00
|
|
|
/* Assign ids to backends. */
|
|
|
|
for (i = 0; i < log_backend_count_get(); i++) {
|
2018-09-14 14:31:26 +02:00
|
|
|
const struct log_backend *backend = log_backend_get(i);
|
|
|
|
|
2018-10-11 06:28:18 +02:00
|
|
|
if (backend->autostart) {
|
2018-12-17 20:33:10 +01:00
|
|
|
if (backend->api->init != NULL) {
|
2018-10-11 06:28:18 +02:00
|
|
|
backend->api->init();
|
|
|
|
}
|
2018-09-13 11:52:32 +02:00
|
|
|
|
2018-12-05 09:53:45 +01:00
|
|
|
log_backend_enable(backend, NULL, CONFIG_LOG_MAX_LEVEL);
|
2018-10-11 06:28:18 +02:00
|
|
|
}
|
2018-09-13 11:52:32 +02:00
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
2018-07-10 09:43:49 +02:00
|
|
|
static void thread_set(k_tid_t process_tid)
|
2018-06-27 10:47:14 +02:00
|
|
|
{
|
|
|
|
proc_tid = process_tid;
|
|
|
|
|
2019-03-14 14:30:16 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD &&
|
2018-06-27 10:47:14 +02:00
|
|
|
process_tid &&
|
|
|
|
buffered_cnt >= CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) {
|
2019-09-29 10:40:39 +02:00
|
|
|
k_sem_give(&log_process_thread_sem);
|
2018-06-27 10:47:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-10 09:43:49 +02:00
|
|
|
void log_thread_set(k_tid_t process_tid)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_PROCESS_THREAD)) {
|
|
|
|
assert(0);
|
|
|
|
} else {
|
|
|
|
thread_set(process_tid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
int log_set_timestamp_func(timestamp_get_t timestamp_getter, uint32_t freq)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
|
|
|
if (!timestamp_getter) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
timestamp_func = timestamp_getter;
|
|
|
|
log_output_timestamp_freq_set(freq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
void z_impl_log_panic(void)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
|
|
|
struct log_backend const *backend;
|
|
|
|
|
2018-09-19 11:14:43 +02:00
|
|
|
if (panic_mode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-18 20:45:40 +02:00
|
|
|
/* If panic happened early logger might not be initialized.
|
2019-01-30 14:34:31 +01:00
|
|
|
* Forcing initialization of the logger and auto-starting backends.
|
|
|
|
*/
|
|
|
|
log_init();
|
|
|
|
|
2018-05-16 08:50:33 +02:00
|
|
|
for (int i = 0; i < log_backend_count_get(); i++) {
|
|
|
|
backend = log_backend_get(i);
|
|
|
|
|
|
|
|
if (log_backend_is_active(backend)) {
|
|
|
|
log_backend_panic(backend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 08:37:15 +01:00
|
|
|
if (!IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
|
|
|
|
/* Flush */
|
|
|
|
while (log_process(false) == true) {
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
2019-02-11 15:03:01 +01:00
|
|
|
|
|
|
|
panic_mode = true;
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2019-08-06 22:34:39 +02:00
|
|
|
void z_vrfy_log_panic(void)
|
|
|
|
{
|
|
|
|
z_impl_log_panic();
|
|
|
|
}
|
|
|
|
#include <syscalls/log_panic_mrsh.c>
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#endif
|
|
|
|
|
2018-05-16 08:50:33 +02:00
|
|
|
static bool msg_filter_check(struct log_backend const *backend,
|
|
|
|
struct log_msg *msg)
|
|
|
|
{
|
2019-01-10 08:37:15 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t backend_level;
|
|
|
|
uint32_t msg_level;
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-01-10 08:37:15 +01:00
|
|
|
backend_level = log_filter_get(backend,
|
|
|
|
log_msg_domain_id_get(msg),
|
|
|
|
log_msg_source_id_get(msg),
|
|
|
|
true /*enum RUNTIME, COMPILETIME*/);
|
|
|
|
msg_level = log_msg_level_get(msg);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2019-01-10 08:37:15 +01:00
|
|
|
return (msg_level <= backend_level);
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void msg_process(struct log_msg *msg, bool bypass)
|
|
|
|
{
|
|
|
|
struct log_backend const *backend;
|
|
|
|
|
|
|
|
if (!bypass) {
|
2019-05-21 13:03:13 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_DETECT_MISSED_STRDUP) &&
|
|
|
|
!panic_mode) {
|
|
|
|
detect_missed_strdup(msg);
|
|
|
|
}
|
|
|
|
|
2018-05-16 08:50:33 +02:00
|
|
|
for (int i = 0; i < log_backend_count_get(); i++) {
|
|
|
|
backend = log_backend_get(i);
|
|
|
|
|
|
|
|
if (log_backend_is_active(backend) &&
|
|
|
|
msg_filter_check(backend, msg)) {
|
|
|
|
log_backend_put(backend, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log_msg_put(msg);
|
|
|
|
}
|
|
|
|
|
2018-11-30 15:28:16 +01:00
|
|
|
void dropped_notify(void)
|
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t dropped = atomic_set(&dropped_cnt, 0);
|
2018-11-30 15:28:16 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < log_backend_count_get(); i++) {
|
|
|
|
struct log_backend const *backend = log_backend_get(i);
|
|
|
|
|
|
|
|
if (log_backend_is_active(backend)) {
|
|
|
|
log_backend_dropped(backend, dropped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
bool z_impl_log_process(bool bypass)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
|
|
|
struct log_msg *msg;
|
|
|
|
|
2019-01-11 14:39:41 +01:00
|
|
|
if (!backend_attached && !bypass) {
|
2018-10-11 08:28:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
unsigned int key = irq_lock();
|
|
|
|
|
|
|
|
msg = log_list_head_get(&list);
|
|
|
|
irq_unlock(key);
|
|
|
|
|
|
|
|
if (msg != NULL) {
|
2018-06-27 10:47:14 +02:00
|
|
|
atomic_dec(&buffered_cnt);
|
2018-05-16 08:50:33 +02:00
|
|
|
msg_process(msg, bypass);
|
|
|
|
}
|
|
|
|
|
2018-11-30 15:28:16 +01:00
|
|
|
if (!bypass && dropped_cnt) {
|
|
|
|
dropped_notify();
|
|
|
|
}
|
|
|
|
|
2018-05-16 08:50:33 +02:00
|
|
|
return (log_list_head_peek(&list) != NULL);
|
|
|
|
}
|
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2019-08-06 22:34:39 +02:00
|
|
|
bool z_vrfy_log_process(bool bypass)
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
{
|
2019-08-06 22:34:39 +02:00
|
|
|
return z_impl_log_process(bypass);
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
}
|
2019-08-06 22:34:39 +02:00
|
|
|
#include <syscalls/log_process_mrsh.c>
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#endif
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t z_impl_log_buffered_cnt(void)
|
2018-07-10 09:43:49 +02:00
|
|
|
{
|
|
|
|
return buffered_cnt;
|
|
|
|
}
|
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t z_vrfy_log_buffered_cnt(void)
|
2019-08-06 22:34:39 +02:00
|
|
|
{
|
|
|
|
return z_impl_log_buffered_cnt();
|
|
|
|
}
|
|
|
|
#include <syscalls/log_buffered_cnt_mrsh.c>
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#endif
|
|
|
|
|
2019-02-26 14:33:47 +01:00
|
|
|
void log_dropped(void)
|
|
|
|
{
|
|
|
|
atomic_inc(&dropped_cnt);
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t log_src_cnt_get(uint32_t domain_id)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
|
|
|
return log_sources_count();
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
const char *log_source_name_get(uint32_t domain_id, uint32_t src_id)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
2018-08-09 11:44:03 +02:00
|
|
|
return src_id < log_sources_count() ? log_name_get(src_id) : NULL;
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
static uint32_t max_filter_get(uint32_t filters)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t max_filter = LOG_LEVEL_NONE;
|
2018-05-16 08:50:33 +02:00
|
|
|
int first_slot = LOG_FILTER_FIRST_BACKEND_SLOT_IDX;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = first_slot; i < LOG_FILTERS_NUM_OF_SLOTS; i++) {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t tmp_filter = LOG_FILTER_SLOT_GET(&filters, i);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
|
|
|
if (tmp_filter > max_filter) {
|
|
|
|
max_filter = tmp_filter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return max_filter;
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t z_impl_log_filter_set(struct log_backend const *const backend,
|
|
|
|
uint32_t domain_id,
|
|
|
|
uint32_t src_id,
|
|
|
|
uint32_t level)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
|
|
|
assert(src_id < log_sources_count());
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t new_aggr_filter;
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t *filters = log_dynamic_filters_get(src_id);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
|
|
|
if (backend == NULL) {
|
|
|
|
struct log_backend const *backend;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t max = 0U;
|
|
|
|
uint32_t current;
|
2018-05-16 08:50:33 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < log_backend_count_get(); i++) {
|
|
|
|
backend = log_backend_get(i);
|
2018-11-16 14:33:29 +01:00
|
|
|
current = log_filter_set(backend, domain_id,
|
|
|
|
src_id, level);
|
2019-02-11 18:14:19 +01:00
|
|
|
max = MAX(current, max);
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
2018-11-16 14:33:29 +01:00
|
|
|
|
|
|
|
level = max;
|
2018-05-16 08:50:33 +02:00
|
|
|
} else {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t max = log_filter_get(backend, domain_id,
|
2018-11-16 14:33:29 +01:00
|
|
|
src_id, false);
|
|
|
|
|
2019-02-11 18:14:19 +01:00
|
|
|
level = MIN(level, max);
|
2018-11-16 14:33:29 +01:00
|
|
|
|
2018-05-16 08:50:33 +02:00
|
|
|
LOG_FILTER_SLOT_SET(filters,
|
|
|
|
log_backend_id_get(backend),
|
|
|
|
level);
|
|
|
|
|
|
|
|
/* Once current backend filter is updated recalculate
|
|
|
|
* aggregated maximal level
|
|
|
|
*/
|
|
|
|
new_aggr_filter = max_filter_get(*filters);
|
|
|
|
|
|
|
|
LOG_FILTER_SLOT_SET(filters,
|
|
|
|
LOG_FILTER_AGGR_SLOT_IDX,
|
|
|
|
new_aggr_filter);
|
|
|
|
}
|
|
|
|
}
|
2018-11-16 14:33:29 +01:00
|
|
|
|
|
|
|
return level;
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#ifdef CONFIG_USERSPACE
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t z_vrfy_log_filter_set(struct log_backend const *const backend,
|
|
|
|
uint32_t domain_id,
|
|
|
|
uint32_t src_id,
|
|
|
|
uint32_t level)
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
{
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(backend == 0,
|
|
|
|
"Setting per-backend filters from user mode is not supported"));
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(domain_id == CONFIG_LOG_DOMAIN_ID,
|
|
|
|
"Invalid log domain_id"));
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(src_id < log_sources_count(),
|
|
|
|
"Invalid log source id"));
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(
|
|
|
|
(level <= LOG_LEVEL_DBG) && (level >= LOG_LEVEL_NONE),
|
|
|
|
"Invalid log level"));
|
|
|
|
|
|
|
|
return z_impl_log_filter_set(NULL, domain_id, src_id, level);
|
|
|
|
}
|
2019-08-06 22:34:39 +02:00
|
|
|
#include <syscalls/log_filter_set_mrsh.c>
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#endif
|
|
|
|
|
2018-05-16 08:50:33 +02:00
|
|
|
static void backend_filter_set(struct log_backend const *const backend,
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t level)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
|
|
|
for (int i = 0; i < log_sources_count(); i++) {
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
log_filter_set(backend, CONFIG_LOG_DOMAIN_ID, i, level);
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_backend_enable(struct log_backend const *const backend,
|
|
|
|
void *ctx,
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t level)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
2018-12-05 09:53:45 +01:00
|
|
|
/* As first slot in filtering mask is reserved, backend ID has offset.*/
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t id = LOG_FILTER_FIRST_BACKEND_SLOT_IDX;
|
2018-12-05 09:53:45 +01:00
|
|
|
|
|
|
|
id += backend - log_backend_get(0);
|
|
|
|
|
|
|
|
log_backend_id_set(backend, id);
|
2018-05-16 08:50:33 +02:00
|
|
|
backend_filter_set(backend, level);
|
2018-07-26 02:58:52 +02:00
|
|
|
log_backend_activate(backend, ctx);
|
2019-10-14 14:23:27 +02:00
|
|
|
|
|
|
|
/* Wakeup logger thread after attaching first backend. It might be
|
|
|
|
* blocked with log messages pending.
|
|
|
|
*/
|
|
|
|
if (!backend_attached) {
|
|
|
|
k_sem_give(&log_process_thread_sem);
|
|
|
|
}
|
|
|
|
|
2018-10-11 08:28:44 +02:00
|
|
|
backend_attached = true;
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void log_backend_disable(struct log_backend const *const backend)
|
|
|
|
{
|
|
|
|
log_backend_deactivate(backend);
|
|
|
|
backend_filter_set(backend, LOG_LEVEL_NONE);
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t log_filter_get(struct log_backend const *const backend,
|
|
|
|
uint32_t domain_id,
|
|
|
|
uint32_t src_id,
|
2018-05-16 08:50:33 +02:00
|
|
|
bool runtime)
|
|
|
|
{
|
|
|
|
assert(src_id < log_sources_count());
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) && runtime) {
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t *filters = log_dynamic_filters_get(src_id);
|
2018-05-16 08:50:33 +02:00
|
|
|
|
|
|
|
return LOG_FILTER_SLOT_GET(filters,
|
|
|
|
log_backend_id_get(backend));
|
|
|
|
} else {
|
|
|
|
return log_compiled_level_get(src_id);
|
|
|
|
}
|
|
|
|
}
|
2018-06-28 13:17:09 +02:00
|
|
|
|
2018-10-02 13:32:30 +02:00
|
|
|
char *log_strdup(const char *str)
|
2018-09-20 11:41:20 +02:00
|
|
|
{
|
2018-10-26 13:07:31 +02:00
|
|
|
struct log_strdup_buf *dup;
|
2018-09-20 11:41:20 +02:00
|
|
|
int err;
|
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_IMMEDIATE) ||
|
|
|
|
is_rodata(str) || _is_user_context()) {
|
2019-01-10 08:37:15 +01:00
|
|
|
return (char *)str;
|
|
|
|
}
|
|
|
|
|
2018-10-26 13:07:31 +02:00
|
|
|
err = k_mem_slab_alloc(&log_strdup_pool, (void **)&dup, K_NO_WAIT);
|
2018-12-17 20:33:10 +01:00
|
|
|
if (err != 0) {
|
2018-09-20 11:41:20 +02:00
|
|
|
/* failed to allocate */
|
|
|
|
return (char *)log_strdup_fail_msg;
|
|
|
|
}
|
|
|
|
|
2019-05-22 09:19:26 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_STRDUP_POOL_PROFILING)) {
|
|
|
|
size_t slen = strlen(str);
|
|
|
|
struct k_spinlock lock;
|
|
|
|
k_spinlock_key_t key;
|
|
|
|
|
|
|
|
key = k_spin_lock(&lock);
|
|
|
|
log_strdup_in_use++;
|
|
|
|
log_strdup_max = MAX(log_strdup_in_use, log_strdup_max);
|
|
|
|
log_strdup_longest = MAX(slen, log_strdup_longest);
|
|
|
|
k_spin_unlock(&lock, key);
|
|
|
|
}
|
|
|
|
|
2018-09-20 11:41:20 +02:00
|
|
|
/* Set 'allocated' flag. */
|
2018-11-27 02:24:45 +01:00
|
|
|
(void)atomic_set(&dup->refcount, 1);
|
2018-09-20 11:41:20 +02:00
|
|
|
|
2018-10-26 13:07:31 +02:00
|
|
|
strncpy(dup->buf, str, sizeof(dup->buf) - 2);
|
|
|
|
dup->buf[sizeof(dup->buf) - 2] = '~';
|
|
|
|
dup->buf[sizeof(dup->buf) - 1] = '\0';
|
2018-09-20 11:41:20 +02:00
|
|
|
|
2018-10-26 13:07:31 +02:00
|
|
|
return dup->buf;
|
2018-09-20 11:41:20 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t log_get_strdup_pool_utilization(void)
|
2019-05-22 09:19:26 +02:00
|
|
|
{
|
|
|
|
return IS_ENABLED(CONFIG_LOG_STRDUP_POOL_PROFILING) ?
|
|
|
|
log_strdup_max : 0;
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t log_get_strdup_longest_string(void)
|
2019-05-22 09:19:26 +02:00
|
|
|
{
|
|
|
|
return IS_ENABLED(CONFIG_LOG_STRDUP_POOL_PROFILING) ?
|
|
|
|
log_strdup_longest : 0;
|
|
|
|
}
|
|
|
|
|
2019-05-21 13:03:13 +02:00
|
|
|
bool log_is_strdup(const void *buf)
|
2018-09-20 11:41:20 +02:00
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
return PART_OF_ARRAY(log_strdup_pool_buf, (uint8_t *)buf);
|
2018-10-08 12:00:54 +02:00
|
|
|
|
2018-09-20 11:41:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void log_free(void *str)
|
|
|
|
{
|
2018-10-26 13:07:31 +02:00
|
|
|
struct log_strdup_buf *dup = CONTAINER_OF(str, struct log_strdup_buf,
|
|
|
|
buf);
|
2018-09-20 11:41:20 +02:00
|
|
|
|
2018-10-26 13:07:31 +02:00
|
|
|
if (atomic_dec(&dup->refcount) == 1) {
|
|
|
|
k_mem_slab_free(&log_strdup_pool, (void **)&dup);
|
2019-05-22 09:19:26 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_STRDUP_POOL_PROFILING)) {
|
|
|
|
atomic_dec((atomic_t *)&log_strdup_in_use);
|
|
|
|
}
|
2018-09-20 11:41:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
#if defined(CONFIG_USERSPACE)
|
2020-05-27 18:26:57 +02:00
|
|
|
void z_impl_z_log_string_from_user(uint32_t src_level_val, const char *str)
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
{
|
|
|
|
ARG_UNUSED(src_level_val);
|
|
|
|
ARG_UNUSED(str);
|
|
|
|
|
|
|
|
__ASSERT(false, "This function can be called from user mode only.");
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
void z_vrfy_z_log_string_from_user(uint32_t src_level_val, const char *str)
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
uint8_t level, domain_id, source_id;
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
union {
|
|
|
|
struct log_msg_ids structure;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t value;
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
} src_level_union;
|
|
|
|
size_t len;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
src_level_union.value = src_level_val;
|
|
|
|
level = src_level_union.structure.level;
|
|
|
|
domain_id = src_level_union.structure.domain_id;
|
|
|
|
source_id = src_level_union.structure.source_id;
|
|
|
|
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(
|
|
|
|
(IS_ENABLED(CONFIG_LOG_PRINTK) || (level >= LOG_LEVEL_ERR)) &&
|
|
|
|
(level <= LOG_LEVEL_DBG),
|
|
|
|
"Invalid log level"));
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(domain_id == CONFIG_LOG_DOMAIN_ID,
|
|
|
|
"Invalid log domain_id"));
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(source_id < log_sources_count(),
|
|
|
|
"Invalid log source id"));
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) &&
|
|
|
|
(level != LOG_LEVEL_INTERNAL_RAW_STRING) &&
|
|
|
|
(level > LOG_FILTER_SLOT_GET(log_dynamic_filters_get(source_id),
|
|
|
|
LOG_FILTER_AGGR_SLOT_IDX))) {
|
|
|
|
/* Skip filtered out messages. */
|
2019-08-06 22:34:39 +02:00
|
|
|
return;
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate and make a copy of the source string. Because we need
|
|
|
|
* the log subsystem to eventually free it, we're going to use
|
|
|
|
* log_strdup().
|
|
|
|
*/
|
|
|
|
len = z_user_string_nlen(str, (level == LOG_LEVEL_INTERNAL_RAW_STRING) ?
|
|
|
|
CONFIG_LOG_PRINTK_MAX_STRING_LENGTH :
|
|
|
|
CONFIG_LOG_STRDUP_MAX_STRING, &err);
|
|
|
|
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(err == 0, "invalid string passed in"));
|
|
|
|
Z_OOPS(Z_SYSCALL_MEMORY_READ(str, len));
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
|
|
|
|
log_string_sync(src_level_union.structure, "%s", str);
|
|
|
|
} else if (IS_ENABLED(CONFIG_LOG_PRINTK) &&
|
|
|
|
(level == LOG_LEVEL_INTERNAL_RAW_STRING)) {
|
|
|
|
struct log_msg *msg;
|
|
|
|
|
|
|
|
msg = log_msg_hexdump_create(NULL, str, len);
|
|
|
|
if (msg != NULL) {
|
|
|
|
msg_finalize(msg, src_level_union.structure);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
str = log_strdup(str);
|
|
|
|
log_1("%s", (log_arg_t)str, src_level_union.structure);
|
|
|
|
}
|
|
|
|
}
|
2019-08-06 22:34:39 +02:00
|
|
|
#include <syscalls/z_log_string_from_user_mrsh.c>
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
|
|
|
|
void log_generic_from_user(struct log_msg_ids src_level,
|
|
|
|
const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
char buffer[CONFIG_LOG_STRDUP_MAX_STRING + 1];
|
|
|
|
union {
|
|
|
|
struct log_msg_ids structure;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t value;
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
} src_level_union;
|
|
|
|
|
|
|
|
vsnprintk(buffer, sizeof(buffer), fmt, ap);
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
__ASSERT_NO_MSG(sizeof(src_level) <= sizeof(uint32_t));
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
src_level_union.structure = src_level;
|
|
|
|
z_log_string_from_user(src_level_union.value, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_from_user(struct log_msg_ids src_level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
log_generic_from_user(src_level, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
void z_impl_z_log_hexdump_from_user(uint32_t src_level_val, const char *metadata,
|
|
|
|
const uint8_t *data, uint32_t len)
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
{
|
|
|
|
ARG_UNUSED(src_level_val);
|
|
|
|
ARG_UNUSED(metadata);
|
|
|
|
ARG_UNUSED(data);
|
|
|
|
ARG_UNUSED(len);
|
|
|
|
|
|
|
|
__ASSERT(false, "This function can be called from user mode only.");
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
void z_vrfy_z_log_hexdump_from_user(uint32_t src_level_val, const char *metadata,
|
|
|
|
const uint8_t *data, uint32_t len)
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
struct log_msg_ids structure;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t value;
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
} src_level_union;
|
|
|
|
size_t mlen;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
src_level_union.value = src_level_val;
|
|
|
|
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(
|
|
|
|
(src_level_union.structure.level <= LOG_LEVEL_DBG) &&
|
|
|
|
(src_level_union.structure.level >= LOG_LEVEL_ERR),
|
|
|
|
"Invalid log level"));
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(
|
|
|
|
src_level_union.structure.domain_id == CONFIG_LOG_DOMAIN_ID,
|
|
|
|
"Invalid log domain_id"));
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(
|
|
|
|
src_level_union.structure.source_id < log_sources_count(),
|
|
|
|
"Invalid log source id"));
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) &&
|
|
|
|
(src_level_union.structure.level > LOG_FILTER_SLOT_GET(
|
|
|
|
log_dynamic_filters_get(src_level_union.structure.source_id),
|
|
|
|
LOG_FILTER_AGGR_SLOT_IDX))) {
|
|
|
|
/* Skip filtered out messages. */
|
2019-08-06 22:34:39 +02:00
|
|
|
return;
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Validate and make a copy of the metadata string. Because we
|
|
|
|
* need the log subsystem to eventually free it, we're going
|
|
|
|
* to use log_strdup().
|
|
|
|
*/
|
|
|
|
mlen = z_user_string_nlen(metadata, CONFIG_LOG_STRDUP_MAX_STRING, &err);
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(err == 0, "invalid string passed in"));
|
|
|
|
Z_OOPS(Z_SYSCALL_MEMORY_READ(metadata, mlen));
|
|
|
|
Z_OOPS(Z_SYSCALL_MEMORY_READ(data, len));
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
|
|
|
|
log_hexdump_sync(src_level_union.structure,
|
|
|
|
metadata, data, len);
|
|
|
|
} else {
|
|
|
|
metadata = log_strdup(metadata);
|
|
|
|
log_hexdump(metadata, data, len, src_level_union.structure);
|
|
|
|
}
|
|
|
|
}
|
2019-08-06 22:34:39 +02:00
|
|
|
#include <syscalls/z_log_hexdump_from_user_mrsh.c>
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
|
|
|
|
void log_hexdump_from_user(struct log_msg_ids src_level, const char *metadata,
|
2020-05-27 18:26:57 +02:00
|
|
|
const void *data, uint32_t len)
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
struct log_msg_ids structure;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t value;
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
} src_level_union;
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
__ASSERT_NO_MSG(sizeof(src_level) <= sizeof(uint32_t));
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
src_level_union.structure = src_level;
|
2019-12-13 06:16:17 +01:00
|
|
|
z_log_hexdump_from_user(src_level_union.value, metadata,
|
2020-05-27 18:26:57 +02:00
|
|
|
(const uint8_t *)data, len);
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
}
|
2019-09-12 05:15:40 +02:00
|
|
|
#else
|
2020-05-27 18:26:57 +02:00
|
|
|
void z_impl_z_log_string_from_user(uint32_t src_level_val, const char *str)
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
{
|
|
|
|
ARG_UNUSED(src_level_val);
|
|
|
|
ARG_UNUSED(str);
|
|
|
|
|
|
|
|
__ASSERT_NO_MSG(false);
|
|
|
|
}
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
void z_vrfy_z_log_hexdump_from_user(uint32_t src_level_val, const char *metadata,
|
|
|
|
const uint8_t *data, uint32_t len)
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
{
|
|
|
|
ARG_UNUSED(src_level_val);
|
|
|
|
ARG_UNUSED(metadata);
|
|
|
|
ARG_UNUSED(data);
|
|
|
|
ARG_UNUSED(len);
|
|
|
|
|
|
|
|
__ASSERT_NO_MSG(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_from_user(struct log_msg_ids src_level, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(src_level);
|
|
|
|
ARG_UNUSED(fmt);
|
|
|
|
|
|
|
|
__ASSERT_NO_MSG(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_generic_from_user(struct log_msg_ids src_level,
|
|
|
|
const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(src_level);
|
|
|
|
ARG_UNUSED(fmt);
|
|
|
|
ARG_UNUSED(ap);
|
|
|
|
|
|
|
|
__ASSERT_NO_MSG(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_hexdump_from_user(struct log_msg_ids src_level, const char *metadata,
|
2020-05-27 18:26:57 +02:00
|
|
|
const void *data, uint32_t len)
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
{
|
|
|
|
ARG_UNUSED(src_level);
|
|
|
|
ARG_UNUSED(metadata);
|
|
|
|
ARG_UNUSED(data);
|
|
|
|
ARG_UNUSED(len);
|
|
|
|
|
|
|
|
__ASSERT_NO_MSG(false);
|
|
|
|
}
|
2019-09-12 05:15:40 +02:00
|
|
|
#endif /* !defined(CONFIG_USERSPACE) */
|
logging: Add basic userspace support
This commit adds basic userspace support to the logging subsystem.
With this change, the following API could be called from user mode:
- LOG_*()
- LOG_INST_*(),
- LOG_HEXDUMP_*(),
- LOG_HEXDUMP_INST_*(),
- LOG_PANIC(), LOG_PROCESS(),
- log_printk(), log_generic(), log_buffrered_cnt(),
- log_filter_set(NULL, ...)
With userspace disabled, the logger behavior and performance
is not affected. With userspace enabled, the calls from kernel
space have an additional overhead introduced by _is_user_context().
The logger behavior changes when it is called from the user context.
All strings logged using LOG_*() and LOG_INST_*() API from userspace
are rendered in place for security reasons and then placed in
log_strdup() memory pool, which should be large enough to hold bursts
of log messages.
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-08-22 11:13:22 +02:00
|
|
|
|
2019-09-29 10:40:39 +02:00
|
|
|
static void log_process_thread_timer_expiry_fn(struct k_timer *timer)
|
|
|
|
{
|
|
|
|
k_sem_give(&log_process_thread_sem);
|
|
|
|
}
|
|
|
|
|
2018-06-28 13:17:09 +02:00
|
|
|
static void log_process_thread_func(void *dummy1, void *dummy2, void *dummy3)
|
|
|
|
{
|
2018-10-11 10:43:07 +02:00
|
|
|
__ASSERT_NO_MSG(log_backend_count_get() > 0);
|
|
|
|
|
2018-06-28 13:17:09 +02:00
|
|
|
log_init();
|
2018-07-10 09:43:49 +02:00
|
|
|
thread_set(k_current_get());
|
2018-06-28 13:17:09 +02:00
|
|
|
|
2018-12-17 20:33:10 +01:00
|
|
|
while (true) {
|
2018-06-28 13:17:09 +02:00
|
|
|
if (log_process(false) == false) {
|
2019-09-29 10:40:39 +02:00
|
|
|
k_sem_take(&log_process_thread_sem, K_FOREVER);
|
2018-06-28 13:17:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 23:14:27 +02:00
|
|
|
K_THREAD_STACK_DEFINE(logging_stack, CONFIG_LOG_PROCESS_THREAD_STACK_SIZE);
|
|
|
|
struct k_thread logging_thread;
|
|
|
|
|
2018-09-14 07:46:46 +02:00
|
|
|
static int enable_logger(struct device *arg)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(arg);
|
2019-01-10 08:37:15 +01:00
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_PROCESS_THREAD)) {
|
2019-09-29 10:40:39 +02:00
|
|
|
k_timer_init(&log_process_thread_timer,
|
|
|
|
log_process_thread_timer_expiry_fn, NULL);
|
2019-01-10 08:37:15 +01:00
|
|
|
/* start logging thread */
|
|
|
|
k_thread_create(&logging_thread, logging_stack,
|
|
|
|
K_THREAD_STACK_SIZEOF(logging_stack),
|
|
|
|
log_process_thread_func, NULL, NULL, NULL,
|
|
|
|
K_LOWEST_APPLICATION_THREAD_PRIO, 0, K_NO_WAIT);
|
|
|
|
k_thread_name_set(&logging_thread, "logging");
|
|
|
|
} else {
|
|
|
|
log_init();
|
|
|
|
}
|
|
|
|
|
2018-09-14 07:46:46 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2018-10-19 23:14:27 +02:00
|
|
|
|
2018-09-14 07:46:46 +02:00
|
|
|
SYS_INIT(enable_logger, POST_KERNEL, 0);
|