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>
|
2021-09-14 15:32:57 +02:00
|
|
|
#include <logging/log_internal.h>
|
2020-11-19 17:25:03 +01:00
|
|
|
#include <sys/mpsc_pbuf.h>
|
2019-06-26 10:33:49 -04:00
|
|
|
#include <sys/printk.h>
|
2020-12-22 19:55:11 +01:00
|
|
|
#include <sys_clock.h>
|
2018-10-19 14:14:27 -07:00
|
|
|
#include <init.h>
|
2020-09-22 14:42:43 +02:00
|
|
|
#include <sys/__assert.h>
|
2019-06-25 12:25:32 -04: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
|
2021-03-11 13:10:43 +01:00
|
|
|
/* Required to suppress compiler warnings related to array subscript above array bounds.
|
|
|
|
* log_strdup explicitly accesses element with index of (sizeof(log_strdup_buf.buf) - 2).
|
2021-03-23 15:47:59 +01:00
|
|
|
* Set to 2 because some compilers generate warning on strncpy(dst, src, 0).
|
2021-03-11 13:10:43 +01:00
|
|
|
*/
|
2021-03-23 15:47:59 +01:00
|
|
|
#define CONFIG_LOG_STRDUP_MAX_STRING 2
|
2019-01-10 08:37:15 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_LOG_STRDUP_BUF_COUNT
|
|
|
|
#define CONFIG_LOG_STRDUP_BUF_COUNT 0
|
|
|
|
#endif
|
|
|
|
|
2020-11-19 17:25:03 +01:00
|
|
|
#ifndef CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS
|
|
|
|
#define CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS 0
|
|
|
|
#endif
|
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
#ifndef CONFIG_LOG_BUFFER_SIZE
|
|
|
|
#define CONFIG_LOG_BUFFER_SIZE 4
|
|
|
|
#endif
|
|
|
|
|
2018-10-26 19:07:31 +08:00
|
|
|
struct log_strdup_buf {
|
|
|
|
atomic_t refcount;
|
|
|
|
char buf[CONFIG_LOG_STRDUP_MAX_STRING + 1]; /* for termination */
|
2021-04-07 12:24:02 +03:00
|
|
|
} __aligned(sizeof(uintptr_t));
|
2018-09-20 11:41:20 +02:00
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
union log_msgs {
|
|
|
|
struct log_msg *msg;
|
|
|
|
union log_msg2_generic *msg2;
|
|
|
|
};
|
|
|
|
|
2018-09-20 11:41:20 +02:00
|
|
|
#define LOG_STRDUP_POOL_BUFFER_SIZE \
|
2018-10-26 19:07:31 +08:00
|
|
|
(sizeof(struct log_strdup_buf) * CONFIG_LOG_STRDUP_BUF_COUNT)
|
2018-09-20 11:41:20 +02:00
|
|
|
|
2019-09-29 16:40:39 +08:00
|
|
|
K_SEM_DEFINE(log_process_thread_sem, 0, 1);
|
|
|
|
|
2018-11-26 23:50:28 +03: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 11:26:57 -05: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;
|
2021-11-16 13:37:12 -05:00
|
|
|
static atomic_t log_strdup_in_use;
|
2020-05-27 11:26:57 -05:00
|
|
|
static uint32_t log_strdup_max;
|
|
|
|
static uint32_t log_strdup_longest;
|
2019-09-29 16:40:39 +08:00
|
|
|
static struct k_timer log_process_thread_timer;
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
static log_timestamp_t dummy_timestamp(void);
|
|
|
|
static log_timestamp_get_t timestamp_func = dummy_timestamp;
|
2020-11-19 17:25:03 +01:00
|
|
|
|
|
|
|
struct mpsc_pbuf_buffer log_buffer;
|
|
|
|
static uint32_t __aligned(Z_LOG_MSG2_ALIGNMENT)
|
|
|
|
buf32[CONFIG_LOG_BUFFER_SIZE / sizeof(int)];
|
|
|
|
|
2021-09-23 15:43:52 +02:00
|
|
|
static void notify_drop(const struct mpsc_pbuf_buffer *buffer,
|
|
|
|
const union mpsc_pbuf_generic *item);
|
2018-07-11 12:26:31 +02:00
|
|
|
|
2020-11-19 17:25:03 +01:00
|
|
|
static const struct mpsc_pbuf_buffer_config mpsc_config = {
|
|
|
|
.buf = (uint32_t *)buf32,
|
|
|
|
.size = ARRAY_SIZE(buf32),
|
|
|
|
.notify_drop = notify_drop,
|
|
|
|
.get_wlen = log_msg2_generic_get_wlen,
|
2020-12-22 19:55:11 +01:00
|
|
|
.flags = IS_ENABLED(CONFIG_LOG_MODE_OVERFLOW) ?
|
|
|
|
MPSC_PBUF_MODE_OVERWRITE : 0
|
2020-11-19 17:25:03 +01:00
|
|
|
};
|
2019-05-21 13:03:13 +02:00
|
|
|
|
2021-12-22 15:01:15 +01:00
|
|
|
/* Check that default tag can fit in tag buffer. */
|
|
|
|
COND_CODE_0(CONFIG_LOG_TAG_MAX_LEN, (),
|
|
|
|
(BUILD_ASSERT(sizeof(CONFIG_LOG_TAG_DEFAULT) <= CONFIG_LOG_TAG_MAX_LEN + 1,
|
|
|
|
"Default string longer than tag capacity")));
|
|
|
|
|
|
|
|
static char tag[CONFIG_LOG_TAG_MAX_LEN + 1] =
|
|
|
|
COND_CODE_0(CONFIG_LOG_TAG_MAX_LEN, ({}), (CONFIG_LOG_TAG_DEFAULT));
|
|
|
|
|
2019-05-21 13:03:13 +02:00
|
|
|
bool log_is_strdup(const void *buf);
|
2020-12-22 19:55:11 +01:00
|
|
|
static void msg_process(union log_msgs msg, bool bypass);
|
2019-05-21 13:03:13 +02:00
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
static log_timestamp_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 11:26:57 -05: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;
|
2021-04-02 23:03:43 -07:00
|
|
|
uint32_t arg = 0U;
|
|
|
|
uint32_t mask = 0U;
|
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-12 17:13:05 -08:00
|
|
|
} else if (arm && isalpha((int)curr)) {
|
2019-05-21 13:03:13 +02:00
|
|
|
if (curr == 's') {
|
|
|
|
mask |= BIT(arg);
|
|
|
|
}
|
|
|
|
arm = false;
|
|
|
|
arg++;
|
2020-10-05 12:19:59 -07:00
|
|
|
} else {
|
2021-05-17 16:24:16 -07:00
|
|
|
; /* standard character, continue walk */
|
2019-05-21 13:03:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2021-04-01 13:10:38 -07:00
|
|
|
#if defined(CONFIG_ARM) || defined(CONFIG_ARC) || defined(CONFIG_X86) || \
|
|
|
|
defined(CONFIG_ARM64) || defined(CONFIG_NIOS2) || \
|
|
|
|
defined(CONFIG_RISCV) || defined(CONFIG_SPARC)
|
2021-08-09 18:16:51 +02:00
|
|
|
extern const char *__rodata_region_start[];
|
|
|
|
extern const char *__rodata_region_end[];
|
|
|
|
#define RO_START __rodata_region_start
|
|
|
|
#define RO_END __rodata_region_end
|
2019-05-21 13:03:13 +02:00
|
|
|
#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)
|
|
|
|
{
|
2021-09-09 17:28:13 +02:00
|
|
|
#define ERR_MSG "argument %d in source %s log message \"%s\" missing " \
|
2019-12-18 10:22:13 +01:00
|
|
|
"log_strdup()."
|
2020-05-27 11:26:57 -05: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 11:26:57 -05: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
|
|
|
|
}
|
|
|
|
|
2021-01-21 08:46:04 +01:00
|
|
|
static void z_log_msg_post_finalize(void)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
2021-12-29 08:06:05 +01:00
|
|
|
atomic_val_t cnt = atomic_inc(&buffered_cnt);
|
|
|
|
|
2019-01-10 08:37:15 +01:00
|
|
|
if (panic_mode) {
|
2021-01-21 08:46:04 +01:00
|
|
|
unsigned int 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);
|
2021-12-29 08:06:05 +01:00
|
|
|
} else if (proc_tid != NULL && cnt == 0) {
|
2019-09-29 16:40:39 +08:00
|
|
|
k_timer_start(&log_process_thread_timer,
|
2020-03-05 14:54:28 -08: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) {
|
2021-12-29 08:06:05 +01:00
|
|
|
if ((cnt == CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD) &&
|
2019-01-10 08:37:15 +01:00
|
|
|
(proc_tid != NULL)) {
|
2019-09-29 16:40:39 +08:00
|
|
|
k_timer_stop(&log_process_thread_timer);
|
|
|
|
k_sem_give(&log_process_thread_sem);
|
2018-07-24 13:40:33 -04:00
|
|
|
}
|
2020-10-05 12:19:59 -07:00
|
|
|
} else {
|
2021-05-17 16:24:16 -07:00
|
|
|
/* No action needed. Message processing will be triggered by the
|
|
|
|
* timeout or when number of upcoming messages exceeds the
|
|
|
|
* threshold.
|
|
|
|
*/
|
|
|
|
;
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-21 08:46:04 +01:00
|
|
|
static inline void msg_finalize(struct log_msg *msg,
|
|
|
|
struct log_msg_ids src_level)
|
|
|
|
{
|
|
|
|
unsigned int key;
|
|
|
|
|
|
|
|
msg->hdr.ids = src_level;
|
|
|
|
msg->hdr.timestamp = timestamp_func();
|
|
|
|
|
|
|
|
key = irq_lock();
|
|
|
|
|
|
|
|
log_list_add_tail(&list, msg);
|
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
|
|
|
|
z_log_msg_post_finalize();
|
|
|
|
}
|
|
|
|
|
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 14:10:15 -04: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 14:10:15 -04: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 14:10:15 -04: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 14:10:15 -04:00
|
|
|
log_arg_t *args,
|
2020-05-27 11:26:57 -05: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 11:26:57 -05: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 11:26:57 -05:00
|
|
|
log_frontend_hexdump(str, (const uint8_t *)data, length,
|
2019-12-12 21:16:17 -08:00
|
|
|
src_level);
|
2019-06-13 15:00:51 +02:00
|
|
|
} else {
|
2019-12-12 21:16:17 -08:00
|
|
|
struct log_msg *msg =
|
2020-05-27 11:26:57 -05: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
|
|
|
}
|
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
void z_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 11:26:57 -05: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
|
|
|
|
2021-03-27 12:03:18 -04:00
|
|
|
if (k_is_user_context()) {
|
2020-05-27 11:26:57 -05: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-22 17:02:45 -07: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);
|
2022-01-12 15:52:48 +01:00
|
|
|
} else if (IS_ENABLED(CONFIG_LOG_MODE_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 11:26:57 -05: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-22 17:02:45 -07: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-22 17:02:45 -07: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 11:26:57 -05: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;
|
2020-10-05 12:19:59 -07:00
|
|
|
} else {
|
2021-05-17 16:24:16 -07:00
|
|
|
; /* standard character, continue walk */
|
2018-10-08 12:00:54 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2021-03-27 12:03:18 -04:00
|
|
|
if (k_is_user_context()) {
|
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_generic_from_user(src_level, fmt, ap);
|
2022-01-12 15:52:48 +01:00
|
|
|
} else if (IS_ENABLED(CONFIG_LOG_MODE_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-12-22 19:55:11 +01: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);
|
2021-04-27 07:14:10 +02:00
|
|
|
bool runtime_ok =
|
|
|
|
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ?
|
|
|
|
(src_level.level <= log_filter_get(backend,
|
|
|
|
src_level.domain_id,
|
|
|
|
src_level.source_id,
|
|
|
|
true)) : true;
|
|
|
|
|
|
|
|
if (log_backend_is_active(backend) && runtime_ok) {
|
2020-08-06 14:11:18 +02:00
|
|
|
va_list ap_tmp;
|
|
|
|
|
|
|
|
va_copy(ap_tmp, ap);
|
2019-01-10 08:37:15 +01:00
|
|
|
log_backend_put_sync_string(backend, src_level,
|
2020-08-06 14:11:18 +02:00
|
|
|
timestamp, fmt, ap_tmp);
|
|
|
|
va_end(ap_tmp);
|
2019-01-10 08:37:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-05-21 14:10:15 -04: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-17 18:02:10 -05: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 14:10:15 -04: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 11:26:57 -05: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 11:26:57 -05:00
|
|
|
log_frontend_hexdump(metadata, (const uint8_t *)data, len,
|
2019-12-12 21:16:17 -08:00
|
|
|
src_level);
|
2019-06-13 15:00:51 +02:00
|
|
|
} else {
|
|
|
|
struct log_backend const *backend;
|
2020-12-22 19:55:11 +01:00
|
|
|
log_timestamp_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);
|
2021-04-27 07:14:10 +02:00
|
|
|
bool runtime_ok =
|
|
|
|
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ?
|
|
|
|
(src_level.level <= log_filter_get(backend,
|
|
|
|
src_level.domain_id,
|
|
|
|
src_level.source_id,
|
|
|
|
true)) : true;
|
|
|
|
|
|
|
|
if (log_backend_is_active(backend) && runtime_ok) {
|
2019-12-12 21:16:17 -08:00
|
|
|
log_backend_put_sync_hexdump(
|
|
|
|
backend, src_level, timestamp, metadata,
|
2020-05-27 11:26:57 -05: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-12-22 19:55:11 +01:00
|
|
|
static log_timestamp_t default_get_timestamp(void)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
2020-12-22 19:55:11 +01:00
|
|
|
return IS_ENABLED(CONFIG_LOG_TIMESTAMP_64BIT) ?
|
|
|
|
sys_clock_tick_get() : k_cycle_get_32();
|
|
|
|
}
|
|
|
|
|
|
|
|
static log_timestamp_t default_lf_get_timestamp(void)
|
|
|
|
{
|
|
|
|
return IS_ENABLED(CONFIG_LOG_TIMESTAMP_64BIT) ?
|
|
|
|
k_uptime_get() : k_uptime_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 11:26:57 -05:00
|
|
|
uint32_t freq;
|
2021-11-19 15:33:54 +01:00
|
|
|
log_timestamp_get_t _timestamp_func;
|
2019-03-05 18:14:45 +01:00
|
|
|
|
2021-04-28 07:50:34 +02:00
|
|
|
panic_mode = false;
|
2021-08-03 11:12:53 +02:00
|
|
|
dropped_cnt = 0;
|
2021-04-28 07:50:34 +02:00
|
|
|
|
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) {
|
2021-11-19 15:33:54 +01:00
|
|
|
_timestamp_func = default_lf_get_timestamp;
|
2021-04-02 23:03:43 -07:00
|
|
|
freq = 1000U;
|
2019-04-23 15:08:00 +02:00
|
|
|
} else {
|
2021-11-19 15:33:54 +01:00
|
|
|
_timestamp_func = default_get_timestamp;
|
2019-04-23 15:08:00 +02:00
|
|
|
freq = sys_clock_hw_cycles_per_sec();
|
|
|
|
}
|
|
|
|
|
2021-11-19 15:33:54 +01:00
|
|
|
log_set_timestamp_func(_timestamp_func, freq);
|
2018-12-04 11:22:41 +01:00
|
|
|
|
2022-01-12 15:52:48 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG2_DEFERRED)) {
|
|
|
|
z_log_msg2_init();
|
|
|
|
} else if (IS_ENABLED(CONFIG_LOG1_DEFERRED)) {
|
2020-12-22 19:55:11 +01:00
|
|
|
log_msg_pool_init();
|
|
|
|
log_list_init(&list);
|
|
|
|
|
|
|
|
k_mem_slab_init(&log_strdup_pool, log_strdup_pool_buf,
|
|
|
|
sizeof(struct log_strdup_buf),
|
|
|
|
CONFIG_LOG_STRDUP_BUF_COUNT);
|
|
|
|
}
|
|
|
|
|
2018-07-11 12:26:31 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
2021-07-14 11:49:48 +02:00
|
|
|
z_log_runtime_filters_init();
|
2018-07-11 12:26:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_init(void)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
2020-09-22 14:42:43 +02:00
|
|
|
__ASSERT_NO_MSG(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 11:33:10 -08: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 15:31:26 +03:00
|
|
|
const struct log_backend *backend = log_backend_get(i);
|
|
|
|
|
2018-10-11 06:28:18 +02:00
|
|
|
if (backend->autostart) {
|
2018-12-17 11:33:10 -08:00
|
|
|
if (backend->api->init != NULL) {
|
2021-01-29 17:25:55 +01:00
|
|
|
backend->api->init(backend);
|
2018-10-11 06:28:18 +02:00
|
|
|
}
|
2018-09-13 12:52:32 +03:00
|
|
|
|
2021-04-26 14:25:49 +02:00
|
|
|
log_backend_enable(backend,
|
|
|
|
backend->cb->ctx,
|
|
|
|
CONFIG_LOG_MAX_LEVEL);
|
2018-10-11 06:28:18 +02:00
|
|
|
}
|
2018-09-13 12:52:32 +03: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;
|
|
|
|
|
2022-01-12 15:52:48 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE)) {
|
2019-03-14 08:30:16 -05:00
|
|
|
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 16:40:39 +08: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)) {
|
2020-09-22 14:42:43 +02:00
|
|
|
__ASSERT_NO_MSG(0);
|
2018-07-10 09:43:49 +02:00
|
|
|
} else {
|
|
|
|
thread_set(process_tid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:25:03 +01:00
|
|
|
int log_set_timestamp_func(log_timestamp_get_t timestamp_getter, uint32_t freq)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
2021-04-02 16:38:39 -07:00
|
|
|
if (timestamp_getter == NULL) {
|
2018-05-16 08:50:33 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
timestamp_func = timestamp_getter;
|
2018-05-16 08:50:33 +02:00
|
|
|
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 14:45:40 -04: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 15:52:48 +01:00
|
|
|
if (!IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE)) {
|
2019-01-10 08:37:15 +01:00
|
|
|
/* 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 13:34:39 -07: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,
|
2020-12-22 19:55:11 +01:00
|
|
|
union log_msgs msg)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
2020-12-22 19:55:11 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG2) && !z_log_item_is_msg(msg.msg2)) {
|
|
|
|
return true;
|
2021-07-14 11:49:48 +02:00
|
|
|
}
|
2020-12-22 19:55:11 +01:00
|
|
|
|
2021-07-14 11:49:48 +02:00
|
|
|
if (!IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
|
2021-07-14 11:49:48 +02:00
|
|
|
uint32_t backend_level;
|
|
|
|
uint8_t level;
|
|
|
|
uint8_t domain_id;
|
|
|
|
int16_t source_id;
|
2020-12-22 19:55:11 +01:00
|
|
|
|
2021-07-14 11:49:48 +02:00
|
|
|
if (IS_ENABLED(CONFIG_LOG2)) {
|
|
|
|
struct log_msg2 *msg2 = &msg.msg2->log;
|
|
|
|
struct log_source_dynamic_data *source =
|
|
|
|
(struct log_source_dynamic_data *)
|
|
|
|
log_msg2_get_source(msg2);
|
|
|
|
|
|
|
|
level = log_msg2_get_level(msg2);
|
|
|
|
domain_id = log_msg2_get_domain(msg2);
|
|
|
|
source_id = source ? log_dynamic_source_id(source) : -1;
|
2019-01-10 08:37:15 +01:00
|
|
|
} else {
|
2021-07-14 11:49:48 +02:00
|
|
|
level = log_msg_level_get(msg.msg);
|
|
|
|
domain_id = log_msg_domain_id_get(msg.msg);
|
|
|
|
source_id = log_msg_source_id_get(msg.msg);
|
2019-01-10 08:37:15 +01:00
|
|
|
}
|
2021-07-14 11:49:48 +02:00
|
|
|
|
|
|
|
backend_level = log_filter_get(backend, domain_id,
|
|
|
|
source_id, true);
|
|
|
|
|
|
|
|
return (level <= backend_level);
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
static void msg_process(union log_msgs msg, bool bypass)
|
2018-05-16 08:50:33 +02:00
|
|
|
{
|
|
|
|
struct log_backend const *backend;
|
|
|
|
|
|
|
|
if (!bypass) {
|
2020-12-22 19:55:11 +01:00
|
|
|
if (!IS_ENABLED(CONFIG_LOG2) &&
|
|
|
|
IS_ENABLED(CONFIG_LOG_DETECT_MISSED_STRDUP) &&
|
2019-05-21 13:03:13 +02:00
|
|
|
!panic_mode) {
|
2020-12-22 19:55:11 +01:00
|
|
|
detect_missed_strdup(msg.msg);
|
2019-05-21 13:03:13 +02:00
|
|
|
}
|
|
|
|
|
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)) {
|
2020-12-22 19:55:11 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG2)) {
|
|
|
|
log_backend_msg2_process(backend,
|
|
|
|
msg.msg2);
|
|
|
|
} else {
|
|
|
|
log_backend_put(backend, msg.msg);
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 15:52:48 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG2_DEFERRED)) {
|
|
|
|
z_log_msg2_free(msg.msg2);
|
|
|
|
} else if (IS_ENABLED(CONFIG_LOG1_DEFERRED)) {
|
|
|
|
log_msg_put(msg.msg);
|
2020-12-22 19:55:11 +01:00
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
}
|
|
|
|
|
2018-11-30 15:28:16 +01:00
|
|
|
void dropped_notify(void)
|
|
|
|
{
|
2021-01-28 09:09:29 +01:00
|
|
|
uint32_t dropped = z_log_dropped_read_and_clear();
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
union log_msgs get_msg(void)
|
|
|
|
{
|
|
|
|
union log_msgs msg;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG2)) {
|
|
|
|
msg.msg2 = z_log_msg2_claim();
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
int key = irq_lock();
|
|
|
|
|
|
|
|
msg.msg = log_list_head_get(&list);
|
|
|
|
irq_unlock(key);
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool next_pending(void)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_LOG2)) {
|
|
|
|
return z_log_msg2_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (log_list_head_peek(&list) != NULL);
|
|
|
|
}
|
|
|
|
|
2021-07-14 11:49:48 +02:00
|
|
|
void z_log_notify_backend_enabled(void)
|
|
|
|
{
|
|
|
|
/* Wakeup logger thread after attaching first backend. It might be
|
|
|
|
* blocked with log messages pending.
|
|
|
|
*/
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_PROCESS_THREAD) && !backend_attached) {
|
|
|
|
k_sem_give(&log_process_thread_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
backend_attached = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2020-12-22 19:55:11 +01:00
|
|
|
union log_msgs msg;
|
2018-05-16 08:50:33 +02:00
|
|
|
|
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
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
msg = get_msg();
|
|
|
|
if (msg.msg) {
|
2021-12-29 08:08:53 +01:00
|
|
|
if (!bypass) {
|
|
|
|
atomic_dec(&buffered_cnt);
|
|
|
|
}
|
2018-05-16 08:50:33 +02:00
|
|
|
msg_process(msg, bypass);
|
|
|
|
}
|
|
|
|
|
2021-01-28 09:09:29 +01:00
|
|
|
if (!bypass && z_log_dropped_pending()) {
|
2018-11-30 15:28:16 +01:00
|
|
|
dropped_notify();
|
|
|
|
}
|
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
return next_pending();
|
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 13:34:39 -07: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 13:34:39 -07: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 13:34:39 -07: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 11:26:57 -05: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 11:26:57 -05:00
|
|
|
uint32_t z_vrfy_log_buffered_cnt(void)
|
2019-08-06 13:34:39 -07: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
|
|
|
|
|
2021-01-28 09:09:29 +01:00
|
|
|
void z_log_dropped(void)
|
2019-02-26 14:33:47 +01:00
|
|
|
{
|
|
|
|
atomic_inc(&dropped_cnt);
|
2021-11-29 15:51:16 +01:00
|
|
|
atomic_dec(&buffered_cnt);
|
2019-02-26 14:33:47 +01:00
|
|
|
}
|
|
|
|
|
2021-01-28 09:09:29 +01:00
|
|
|
uint32_t z_log_dropped_read_and_clear(void)
|
|
|
|
{
|
|
|
|
return atomic_set(&dropped_cnt, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool z_log_dropped_pending(void)
|
|
|
|
{
|
2020-12-22 19:55:11 +01:00
|
|
|
return dropped_cnt > 0;
|
|
|
|
}
|
|
|
|
|
2021-09-23 15:43:52 +02:00
|
|
|
static void notify_drop(const struct mpsc_pbuf_buffer *buffer,
|
|
|
|
const union mpsc_pbuf_generic *item)
|
2020-12-22 19:55:11 +01:00
|
|
|
{
|
2021-09-23 15:43:52 +02:00
|
|
|
ARG_UNUSED(buffer);
|
|
|
|
ARG_UNUSED(item);
|
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
z_log_dropped();
|
2021-01-28 09:09:29 +01:00
|
|
|
}
|
|
|
|
|
2018-06-28 13:17:09 +02:00
|
|
|
|
2020-12-22 19:55:11 +01:00
|
|
|
char *z_log_strdup(const char *str)
|
2018-09-20 11:41:20 +02:00
|
|
|
{
|
2018-10-26 19:07:31 +08:00
|
|
|
struct log_strdup_buf *dup;
|
2018-09-20 11:41:20 +02:00
|
|
|
int err;
|
|
|
|
|
2022-01-12 15:52:48 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ||
|
2021-03-27 12:03:18 -04:00
|
|
|
is_rodata(str) || k_is_user_context()) {
|
2019-01-10 08:37:15 +01:00
|
|
|
return (char *)str;
|
|
|
|
}
|
|
|
|
|
2018-10-26 19:07:31 +08:00
|
|
|
err = k_mem_slab_alloc(&log_strdup_pool, (void **)&dup, K_NO_WAIT);
|
2018-12-17 11:33:10 -08: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);
|
2021-01-18 11:41:23 +00:00
|
|
|
static struct k_spinlock lock;
|
2019-05-22 09:19:26 +02:00
|
|
|
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-26 17:24:45 -08:00
|
|
|
(void)atomic_set(&dup->refcount, 1);
|
2018-09-20 11:41:20 +02:00
|
|
|
|
2018-10-26 19:07:31 +08: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 19:07:31 +08:00
|
|
|
return dup->buf;
|
2018-09-20 11:41:20 +02:00
|
|
|
}
|
|
|
|
|
2021-06-01 16:04:31 -05:00
|
|
|
uint32_t log_get_strdup_pool_current_utilization(void)
|
|
|
|
{
|
|
|
|
return IS_ENABLED(CONFIG_LOG_STRDUP_POOL_PROFILING) ?
|
|
|
|
log_strdup_in_use : 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:57 -05: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 11:26:57 -05: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 11:26:57 -05: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
|
|
|
}
|
|
|
|
|
2021-09-15 07:17:23 +02:00
|
|
|
void z_log_free(void *str)
|
2018-09-20 11:41:20 +02:00
|
|
|
{
|
2018-10-26 19:07:31 +08: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 19:07:31 +08: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)) {
|
2021-11-16 13:37:12 -05:00
|
|
|
atomic_dec(&log_strdup_in_use);
|
2019-05-22 09:19:26 +02:00
|
|
|
}
|
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)
|
2021-01-07 19:58:26 -05:00
|
|
|
/* LCOV_EXCL_START */
|
2020-05-27 11:26:57 -05: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.");
|
|
|
|
}
|
2021-01-07 19:58:26 -05:00
|
|
|
/* LCOV_EXCL_STOP */
|
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 11:26:57 -05: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 11:26:57 -05: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 11:26:57 -05: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"));
|
2021-09-15 07:17:23 +02:00
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(source_id < z_log_sources_count(),
|
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
|
|
|
"Invalid log source id"));
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) &&
|
|
|
|
(level != LOG_LEVEL_INTERNAL_RAW_STRING) &&
|
2021-09-15 07:17:23 +02:00
|
|
|
(level > LOG_FILTER_SLOT_GET(z_log_dynamic_filters_get(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
|
|
|
LOG_FILTER_AGGR_SLOT_IDX))) {
|
|
|
|
/* Skip filtered out messages. */
|
2019-08-06 13:34:39 -07: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));
|
|
|
|
|
2022-01-12 15:52:48 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG1_IMMEDIATE)) {
|
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_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 13:34:39 -07: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 11:26:57 -05: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 11:26:57 -05: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);
|
|
|
|
}
|
|
|
|
|
2021-01-07 19:58:26 -05:00
|
|
|
/* LCOV_EXCL_START */
|
2020-05-27 11:26:57 -05: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.");
|
|
|
|
}
|
2021-01-07 19:58:26 -05:00
|
|
|
/* LCOV_EXCL_STOP */
|
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 11:26:57 -05: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 11:26:57 -05: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;
|
|
|
|
int err;
|
2021-03-08 10:24:18 -08:00
|
|
|
char kmeta[CONFIG_LOG_STRDUP_MAX_STRING];
|
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.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(
|
2021-09-15 07:17:23 +02:00
|
|
|
src_level_union.structure.source_id < z_log_sources_count(),
|
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
|
|
|
"Invalid log source id"));
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) &&
|
|
|
|
(src_level_union.structure.level > LOG_FILTER_SLOT_GET(
|
2021-09-15 07:17:23 +02:00
|
|
|
z_log_dynamic_filters_get(src_level_union.structure.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
|
|
|
LOG_FILTER_AGGR_SLOT_IDX))) {
|
|
|
|
/* Skip filtered out messages. */
|
2019-08-06 13:34:39 -07: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().
|
|
|
|
*/
|
2021-03-08 10:24:18 -08:00
|
|
|
err = z_user_string_copy(kmeta, metadata, sizeof(kmeta));
|
|
|
|
Z_OOPS(Z_SYSCALL_VERIFY_MSG(err == 0, "invalid meta passed in"));
|
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_MEMORY_READ(data, len));
|
|
|
|
|
2022-01-12 15:52:48 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG1_IMMEDIATE)) {
|
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_hexdump_sync(src_level_union.structure,
|
2021-03-08 10:24:18 -08:00
|
|
|
kmeta, 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
|
|
|
} else {
|
2021-03-08 10:24:18 -08:00
|
|
|
metadata = log_strdup(kmeta);
|
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_hexdump(metadata, data, len, src_level_union.structure);
|
|
|
|
}
|
|
|
|
}
|
2019-08-06 13:34:39 -07: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 11:26:57 -05: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 11:26:57 -05: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 11:26:57 -05: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-12 21:16:17 -08:00
|
|
|
z_log_hexdump_from_user(src_level_union.value, metadata,
|
2020-05-27 11:26:57 -05: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-11 20:15:40 -07:00
|
|
|
#else
|
2021-01-07 19:58:26 -05:00
|
|
|
/* LCOV_EXCL_START */
|
2020-05-27 11:26:57 -05: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 11:26:57 -05: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 11:26:57 -05: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);
|
|
|
|
}
|
2021-01-07 19:58:26 -05:00
|
|
|
/* LCOV_EXCL_STOP */
|
2019-09-11 20:15:40 -07: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
|
|
|
|
2020-11-19 17:25:03 +01:00
|
|
|
void z_log_msg2_init(void)
|
|
|
|
{
|
|
|
|
mpsc_pbuf_init(&log_buffer, &mpsc_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct log_msg2 *z_log_msg2_alloc(uint32_t wlen)
|
|
|
|
{
|
|
|
|
return (struct log_msg2 *)mpsc_pbuf_alloc(&log_buffer, wlen,
|
|
|
|
K_MSEC(CONFIG_LOG_BLOCK_IN_THREAD_TIMEOUT_MS));
|
|
|
|
}
|
|
|
|
|
|
|
|
void z_log_msg2_commit(struct log_msg2 *msg)
|
|
|
|
{
|
2020-12-22 19:55:11 +01:00
|
|
|
msg->hdr.timestamp = timestamp_func();
|
|
|
|
|
2022-01-12 15:52:48 +01:00
|
|
|
if (IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE)) {
|
2020-12-22 19:55:11 +01:00
|
|
|
union log_msgs msgs = {
|
|
|
|
.msg2 = (union log_msg2_generic *)msg
|
|
|
|
};
|
|
|
|
|
|
|
|
msg_process(msgs, false);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-19 17:25:03 +01:00
|
|
|
mpsc_pbuf_commit(&log_buffer, (union mpsc_pbuf_generic *)msg);
|
2022-01-12 15:52:48 +01:00
|
|
|
z_log_msg_post_finalize();
|
2020-11-19 17:25:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
union log_msg2_generic *z_log_msg2_claim(void)
|
|
|
|
{
|
|
|
|
return (union log_msg2_generic *)mpsc_pbuf_claim(&log_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void z_log_msg2_free(union log_msg2_generic *msg)
|
|
|
|
{
|
|
|
|
mpsc_pbuf_free(&log_buffer, (union mpsc_pbuf_generic *)msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool z_log_msg2_pending(void)
|
|
|
|
{
|
|
|
|
return mpsc_pbuf_is_pending(&log_buffer);
|
|
|
|
}
|
|
|
|
|
2021-12-22 15:01:15 +01:00
|
|
|
const char *z_log_get_tag(void)
|
|
|
|
{
|
|
|
|
return CONFIG_LOG_TAG_MAX_LEN > 0 ? tag : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int log_set_tag(const char *str)
|
|
|
|
{
|
|
|
|
if (CONFIG_LOG_TAG_MAX_LEN == 0) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str == NULL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t len = strlen(str);
|
|
|
|
size_t cpy_len = MIN(len, CONFIG_LOG_TAG_MAX_LEN);
|
|
|
|
|
|
|
|
memcpy(tag, str, cpy_len);
|
|
|
|
tag[cpy_len] = '\0';
|
|
|
|
|
|
|
|
if (cpy_len < len) {
|
|
|
|
tag[cpy_len - 1] = '~';
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-29 16:40:39 +08: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 11:33:10 -08:00
|
|
|
while (true) {
|
2018-06-28 13:17:09 +02:00
|
|
|
if (log_process(false) == false) {
|
2019-09-29 16:40:39 +08:00
|
|
|
k_sem_take(&log_process_thread_sem, K_FOREVER);
|
2018-06-28 13:17:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-31 12:50:07 -07:00
|
|
|
K_KERNEL_STACK_DEFINE(logging_stack, CONFIG_LOG_PROCESS_THREAD_STACK_SIZE);
|
2018-10-19 14:14:27 -07:00
|
|
|
struct k_thread logging_thread;
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int enable_logger(const struct device *arg)
|
2018-09-14 07:46:46 +02:00
|
|
|
{
|
|
|
|
ARG_UNUSED(arg);
|
2019-01-10 08:37:15 +01:00
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_LOG_PROCESS_THREAD)) {
|
2019-09-29 16:40:39 +08: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,
|
2020-07-31 12:50:07 -07:00
|
|
|
K_KERNEL_STACK_SIZEOF(logging_stack),
|
2019-01-10 08:37:15 +01:00
|
|
|
log_process_thread_func, NULL, NULL, NULL,
|
2021-08-13 15:56:51 +02:00
|
|
|
K_LOWEST_APPLICATION_THREAD_PRIO, 0,
|
|
|
|
COND_CODE_1(CONFIG_LOG_PROCESS_THREAD,
|
|
|
|
K_MSEC(CONFIG_LOG_PROCESS_THREAD_STARTUP_DELAY_MS),
|
|
|
|
K_NO_WAIT));
|
2019-01-10 08:37:15 +01:00
|
|
|
k_thread_name_set(&logging_thread, "logging");
|
|
|
|
} else {
|
|
|
|
log_init();
|
|
|
|
}
|
|
|
|
|
2018-09-14 07:46:46 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2018-10-19 14:14:27 -07:00
|
|
|
|
2018-09-14 07:46:46 +02:00
|
|
|
SYS_INIT(enable_logger, POST_KERNEL, 0);
|