From a0bd0aee2bd5a28c548b06f7af885137e9bb818c Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Thu, 28 May 2026 17:59:52 +0300 Subject: [PATCH 1/2] debug_stream: Export ds_msg() to allow using it in loadable modules Export ds_msg() to allow using it in loadable modules. Signed-off-by: Jyri Sarha --- src/debug/debug_stream/debug_stream_text_msg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/debug/debug_stream/debug_stream_text_msg.c b/src/debug/debug_stream/debug_stream_text_msg.c index 97db0fd29330..f4b67d4d307a 100644 --- a/src/debug/debug_stream/debug_stream_text_msg.c +++ b/src/debug/debug_stream/debug_stream_text_msg.c @@ -43,6 +43,7 @@ void ds_msg(const char *format, ...) ds_vamsg(format, args); va_end(args); } +EXPORT_SYMBOL(ds_msg); #if defined(CONFIG_EXCEPTION_DUMP_HOOK) /* The debug stream debug window slot is 4k, and when it is split From d9364e56b5f30fb0353ecb561d39d4b9cfaf9e0b Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Fri, 5 Jun 2026 14:57:10 +0300 Subject: [PATCH 2/2] debug_stream: make debug_stream_slot_send_record() a syscall Make debug_stream_slot_send_record() a Zephyr syscall when CONFIG_USERSPACE is enabled. This allows user-space threads to send debug stream records directly. Rename the implementation to z_impl_debug_stream_slot_send_record() and add z_vrfy_debug_stream_slot_send_record() with K_SYSCALL_MEMORY_READ validation of the record buffer. Register the syscall header in CMakeLists.txt. Signed-off-by: Jyri Sarha --- src/debug/debug_stream/debug_stream_slot.c | 16 +++++++++++++++- src/include/user/debug_stream_slot.h | 8 ++++++++ zephyr/CMakeLists.txt | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/debug/debug_stream/debug_stream_slot.c b/src/debug/debug_stream/debug_stream_slot.c index 82816a6788f3..db27490a98a4 100644 --- a/src/debug/debug_stream/debug_stream_slot.c +++ b/src/debug/debug_stream/debug_stream_slot.c @@ -12,6 +12,10 @@ #include #include +#ifdef CONFIG_USERSPACE +#include +#endif + LOG_MODULE_REGISTER(debug_stream_slot); struct cpu_mutex { @@ -66,7 +70,7 @@ debug_stream_get_circular_buffer(struct debug_stream_section_descriptor *desc, u return (struct debug_stream_circular_buf *) (((uint8_t *)hdr) + desc->offset); } -int debug_stream_slot_send_record(struct debug_stream_record *rec) +int z_impl_debug_stream_slot_send_record(struct debug_stream_record *rec) { struct debug_stream_section_descriptor desc = { 0 }; struct debug_stream_circular_buf *buf = @@ -119,6 +123,16 @@ int debug_stream_slot_send_record(struct debug_stream_record *rec) return 0; } +#ifdef CONFIG_USERSPACE +static inline int z_vrfy_debug_stream_slot_send_record(struct debug_stream_record *rec) +{ + K_OOPS(K_SYSCALL_MEMORY_READ(rec, sizeof(*rec))); + K_OOPS(K_SYSCALL_MEMORY_READ(rec, rec->size_words * sizeof(uint32_t))); + return z_impl_debug_stream_slot_send_record(rec); +} +#include +#endif + static int debug_stream_slot_init(void) { struct debug_stream_slot_hdr *hdr = debug_stream_get_slot(); diff --git a/src/include/user/debug_stream_slot.h b/src/include/user/debug_stream_slot.h index 4464c9ed56b8..ca3e6b34ba59 100644 --- a/src/include/user/debug_stream_slot.h +++ b/src/include/user/debug_stream_slot.h @@ -127,6 +127,14 @@ struct debug_stream_record; * -ENODEV if debug stream slot is not configured * -ENOMEM if the record is too big */ +#if defined(__ZEPHYR__) && defined(CONFIG_USERSPACE) +__syscall int debug_stream_slot_send_record(struct debug_stream_record *rec); +#else int debug_stream_slot_send_record(struct debug_stream_record *rec); +#endif + +#if defined(__ZEPHYR__) && defined(CONFIG_USERSPACE) +#include +#endif #endif /* __SOC_DEBUG_WINDOW_SLOT_H__ */ diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 9bdaa6453ad4..f363fd104596 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -623,6 +623,8 @@ zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/lib/fast-get.h) zephyr_syscall_header(include/rtos/alloc.h) zephyr_library_sources_ifdef(CONFIG_SOF_USERSPACE_INTERFACE_ALLOC syscall/alloc.c) +zephyr_syscall_header(${SOF_SRC_PATH}/include/user/debug_stream_slot.h) + zephyr_library_link_libraries(SOF) target_link_libraries(SOF INTERFACE zephyr_interface)