Skip to content

Commit

Permalink
add seL4_DebugNameThreadFmt()
Browse files Browse the repository at this point in the history
This is a convenient way to create thread names dynamically.
Also change seL4_DebugNameThread() to use strncpy() instead of
strcpy() to honor the IPC buffer size.

Signed-off-by: Axel Heider <axel.heider@hensoldt.net>
  • Loading branch information
Axel Heider committed Aug 13, 2023
1 parent 91e9ef0 commit 9032f9b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
8 changes: 6 additions & 2 deletions libsel4/arch_include/arm/sel4/arch/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,14 @@ LIBSEL4_INLINE_FUNC seL4_Uint32 seL4_DebugCapIdentify(seL4_CPtr cap)
return (seL4_Uint32)cap;
}

char *strcpy(char *, const char *);
char *strncpy(char *, const char *, seL4_Word);
LIBSEL4_INLINE_FUNC void seL4_DebugNameThread(seL4_CPtr tcb, const char *name)
{
strcpy((char *)seL4_GetIPCBuffer()->msg, name);
/* IPC buffer can be used directly, otherwise buffers must not overlap. */
char *ipc_buf = (char *)seL4_GetIPCBuffer()->msg;
if (name != ipc_buf) {
strncpy(ipc_buf, name, seL4_MsgMaxLength);
}

seL4_Word unused0 = 0;
seL4_Word unused1 = 0;
Expand Down
8 changes: 6 additions & 2 deletions libsel4/arch_include/riscv/sel4/arch/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,14 @@ LIBSEL4_INLINE_FUNC seL4_Uint32 seL4_DebugCapIdentify(seL4_CPtr cap)
return (seL4_Uint32)cap;
}

char *strcpy(char *, const char *);
char *strncpy(char *, const char *, seL4_Word);
LIBSEL4_INLINE_FUNC void seL4_DebugNameThread(seL4_CPtr tcb, const char *name)
{
strcpy((char *)seL4_GetIPCBuffer()->msg, name);
/* IPC buffer can be used directly, otherwise buffers must not overlap. */
char *ipc_buf = (char *)seL4_GetIPCBuffer()->msg;
if (name != ipc_buf) {
strncpy(ipc_buf, name, seL4_MsgMaxLength);
}

seL4_Word unused0 = 0;
seL4_Word unused1 = 0;
Expand Down
21 changes: 21 additions & 0 deletions libsel4/include/sel4/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,24 @@ LIBSEL4_INLINE_FUNC void seL4_SetCapReceivePath(seL4_CPtr receiveCNode, seL4_CPt
ipcbuffer->receiveDepth = receiveDepth;
}

#if CONFIG_DEBUG_BUILD

/* Making this a macro avoids requiring stdarg.h to get va_start() */
#define seL4_DebugNameThreadFmt(tcb, fmt, ...) \
do { \
char *ipc_buf = (char *)seL4_GetIPCBuffer()->msg; \
snprintf(ipc_buf, seL4_MsgMaxLength, fmt, __VA_ARGS__); \
seL4_DebugNameThread(tcb, ipc_buf); \
} while(0)

// LIBSEL4_INLINE_FUNC void seL4_DebugNameThreadFmt(seL4_CPtr tcb, const char *fmt, ...)
// {
// char *ipc_buf = (char *)seL4_GetIPCBuffer()->msg;
// va_list args;
// va_start(args, fmt);
// vsnprintf(ipc_buf, seL4_MsgMaxLength, fmt, args)
// va_end(args);
// seL4_DebugNameThread(tcb, ipc_buf);
// }

#endif /* CONFIG_DEBUG_BUILD */
8 changes: 6 additions & 2 deletions libsel4/sel4_arch_include/ia32/sel4/sel4_arch/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,14 @@ LIBSEL4_INLINE_FUNC seL4_Uint32 seL4_DebugCapIdentify(seL4_CPtr cap)
return (seL4_Uint32)cap;
}

char *strcpy(char *, const char *);
char *strncpy(char *, const char *, seL4_Word);
LIBSEL4_INLINE_FUNC void seL4_DebugNameThread(seL4_CPtr tcb, const char *name)
{
strcpy((char *)seL4_GetIPCBuffer()->msg, name);
/* IPC buffer can be used directly, otherwise buffers must not overlap. */
char *ipc_buf = (char *)seL4_GetIPCBuffer()->msg;
if (name != ipc_buf) {
strncpy(ipc_buf, name, seL4_MsgMaxLength);
}

seL4_Word unused0 = 0;
seL4_Word unused1 = 0;
Expand Down
9 changes: 6 additions & 3 deletions libsel4/sel4_arch_include/x86_64/sel4/sel4_arch/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,14 @@ LIBSEL4_INLINE_FUNC seL4_Uint32 seL4_DebugCapIdentify(seL4_CPtr cap)
#endif

#ifdef CONFIG_DEBUG_BUILD
char *strcpy(char *, const char *);
char *strncpy(char *, const char *, seL4_Word);
LIBSEL4_INLINE_FUNC void seL4_DebugNameThread(seL4_CPtr tcb, const char *name)
{

strcpy((char *)seL4_GetIPCBuffer()->msg, name);
/* IPC buffer can be used directly, otherwise buffers must not overlap. */
char *ipc_buf = (char *)seL4_GetIPCBuffer()->msg;
if (name != ipc_buf) {
strncpy(ipc_buf, name, seL4_MsgMaxLength);
}

seL4_Word unused0 = 0;
seL4_Word unused1 = 0;
Expand Down

0 comments on commit 9032f9b

Please sign in to comment.