Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions src/debug/debug_stream/debug_stream_text_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,59 @@

#include <user/debug_stream_text_msg.h>

#ifdef CONFIG_USERSPACE
#include <zephyr/internal/syscall_handler.h>
#endif

LOG_MODULE_REGISTER(debug_stream_text_msg);

void ds_vamsg(const char *format, va_list args)
#ifdef CONFIG_USERSPACE
void z_impl_ds_send_text_record(const char *text, size_t len)
#else
void ds_send_text_record(const char *text, size_t len)
#endif
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually we don't have to do this - we just define z_impl_...() functions and the Zephyr syscall magic calls those when userspace is disabled. Why is this needed here?

{
struct {
struct debug_stream_text_msg msg;
char text[128];
char text[DS_TEXT_MSG_MAX_LEN];
} __packed buf = { 0 };
ssize_t len;

len = vsnprintf(buf.text, sizeof(buf.text), format, args);

if (len < 0)
if (!text || len == 0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a curious mix of == 0 and !x styles ;-) I won't say which one I prefer, but can we have just one of them at least within a single if? :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I drop len check. The code can cope with zero length.

return;

len = MIN(len, sizeof(buf.text));
memcpy(buf.text, text, len);

buf.msg.hdr.id = DEBUG_STREAM_RECORD_ID_TEXT_MSG;
buf.msg.hdr.size_words = SOF_DIV_ROUND_UP(sizeof(buf.msg) + len,
sizeof(buf.msg.hdr.data[0]));
debug_stream_slot_send_record(&buf.msg.hdr);
}

#ifdef CONFIG_USERSPACE
static inline void z_vrfy_ds_send_text_record(const char *text, size_t len)
{
len = MIN(len, DS_TEXT_MSG_MAX_LEN);
K_OOPS(K_SYSCALL_MEMORY_READ(text, len));
z_impl_ds_send_text_record(text, len);
}
#include <zephyr/syscalls/ds_send_text_record_mrsh.c>
#endif

void ds_vamsg(const char *format, va_list args)
{
char text[DS_TEXT_MSG_MAX_LEN];
ssize_t len;

len = vsnprintf(text, sizeof(text), format, args);

if (len < 0)
return;
len = MIN(len, sizeof(text));

ds_send_text_record(text, len);
}
Comment on lines +55 to +67
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I'll make debug_stream_slot_send_record() a syscall instead.


void ds_msg(const char *format, ...)
{
va_list args;
Expand All @@ -43,6 +74,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
Expand Down
12 changes: 12 additions & 0 deletions src/include/user/debug_stream_text_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,16 @@ struct debug_stream_text_msg {
void ds_msg(const char *format, ...);
void ds_vamsg(const char *format, va_list ap);

#define DS_TEXT_MSG_MAX_LEN 128

#if defined(__ZEPHYR__) && defined(CONFIG_USERSPACE)
__syscall void ds_send_text_record(const char *text, size_t len);
#else
void ds_send_text_record(const char *text, size_t len);
#endif
Comment thread
jsarha marked this conversation as resolved.

#if defined(__ZEPHYR__) && defined(CONFIG_USERSPACE)
#include <zephyr/syscalls/debug_stream_text_msg.h>
#endif

#endif /* __SOC_DEBUG_STREAM_TEXT_MSG_H__ */
2 changes: 2 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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_text_msg.h)

zephyr_library_link_libraries(SOF)
target_link_libraries(SOF INTERFACE zephyr_interface)

Expand Down
Loading