chore(core): improve comments, use doxygen style
What changed, and why it matters
This commit only rewrites code comments in three header files to use a Doxygen documentation style. It does not change any program logic, function signatures, data structures, or security behavior. There is no indication of a security fix or vulnerability.
No security action required. Treat as a normal documentation cleanup commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff is a pure documentation refactor across core/embed/sys/task/inc/sys/applet.h, systask.h, and system.h. It converts C++-style // comments to Doxygen /* / blocks, adds @brief/@param/@return tags, and updates some wording. No executable code, macros, types, or control flow are modified. The only non-commentary change is a comment noting that SYSTASK_MAX_TASKS now conceptually includes a ‘user app’ (value remains 2).
Changed components
core/embed/sys/task/inc/sys/applet.hcore/embed/sys/task/inc/sys/systask.hcore/embed/sys/task/inc/sys/system.hInspect captured patch +295 / −123
diff --git a/core/embed/sys/task/inc/sys/applet.h b/core/embed/sys/task/inc/sys/applet.h
index c80a5ceb9..7f8ba0ace 100644
--- a/core/embed/sys/task/inc/sys/applet.h
+++ b/core/embed/sys/task/inc/sys/applet.h
@@ -25,41 +25,66 @@
#include <sys/systask.h>
-// Applet privileges
+/** Applet privileges */
typedef struct {
bool assets_area_access;
} applet_privileges_t;
typedef struct {
- // Applet memory layout describing the memory areas
- // the applet is allowed to use
+ /** Applet memory layout describing the memory areas
+ * the applet is allowed to use */
applet_layout_t layout;
- // Applet privileges
+ /** Applet privileges */
applet_privileges_t privileges;
- // Applet task
+ /** Task associated with the applet */
systask_t task;
#ifdef TREZOR_EMULATOR
- // Handle returned by `dlopen()`
+ /** Handle returned by `dlopen()` */
void* handle;
#endif
} applet_t;
-// Initializes the applet structure
+/**
+ * @brief Initializes the applet structure
+ *
+ * Does just basic initialization of the applet structure without
+ * initializing the task associated with the applet.
+ *
+ * @param applet Pointer to the applet to initialize.
+ * @param layout Pointer to the applet memory layout.
+ * @param privileges Pointer to the applet privileges.
+ */
void applet_init(applet_t* applet, const applet_layout_t* layout,
const applet_privileges_t* privileges);
-// Runs the applet and waits until it finishes.
+/**
+ * @brief Runs the applet task first time.
+ *
+ * When calling this function, the applet task must be initialized
+ * and not running. The function does not return until the applet
+ * gives up control (by being rescheduled out or terminated).
+ *
+ * @param applet Pointer to the applet to run.
+ */
void applet_run(applet_t* applet);
-// Release all resources help by the applet
+/**
+ * @brief Release all resources held by the applet
+ * @param applet Pointer to the applet to stop.
+ */
void applet_stop(applet_t* applet);
-// Returns `true` if the applet task is alive.
+/**
+ * @brief Returns `true` if the applet task is alive.
+ * @param applet Pointer to the applet to query.
+ * @return true if the applet task is alive, false otherwise.
+ */
bool applet_is_alive(applet_t* applet);
-// Returns the currently active applet.
-//
-// Returns `NULL` if no applet is currently active.
+/**
+ * @brief Returns the currently active applet.
+ * @return Pointer to the currently active applet, or NULL if none.
+ */
applet_t* applet_active(void);
#endif // KERNEL
diff --git a/core/embed/sys/task/inc/sys/systask.h b/core/embed/sys/task/inc/sys/systask.h
index dc0a356fb..3d0f15fe4 100644
--- a/core/embed/sys/task/inc/sys/systask.h
+++ b/core/embed/sys/task/inc/sys/systask.h
@@ -27,7 +27,7 @@
#include <pthread.h>
#endif
-// Termination reason for the task
+/** Termination reason for the task */
typedef enum {
TASK_TERM_REASON_EXIT = 0,
TASK_TERM_REASON_ERROR,
@@ -37,59 +37,58 @@ typedef enum {
} systask_term_reason_t;
typedef struct {
- // Fault/exception number (-15..-1)
+ /** Fault/exception number (-15..-1) */
int irqn;
- // Configurable Fault Status Register
- // (combined UFSR/BFSR/MMFSR)
+ /** Configurable Fault Status Register (combined UFSR/BFSR/MMFSR) */
uint32_t cfsr;
- // Hard Fault Status Register
+ /** Hard Fault Status Register */
uint32_t hfsr;
- // Address associated with MemManage fault
+ /** Address associated with MemManage fault */
uint32_t mmfar;
- // Address associated with the BusFault
+ /** Address associated with the BusFault */
uint32_t bfar;
#if defined(__ARM_FEATURE_CMSE)
- // Secure Fault Status Register
+ /** Secure Fault Status Register */
uint32_t sfsr;
- // Address associated with the SecureFault
+ /** Address associated with the SecureFault */
uint32_t sfar;
#endif
- // PC (return address) at the time of the fault
+ /** PC (return address) at the time of the fault */
uint32_t pc;
- // Stack pointer at the time of the fault
- // (MSP or PSP depending on the privilege level)
+ /** Stack pointer at the time of the fault (MSP or PSP depending on the
+ * privilege level) */
uint32_t sp;
#if !(defined(__ARM_ARCH_8M_MAIN__) || defined(__ARM_ARCH_8M_BASE__))
- // Stack pointer limit (for the stack overflow detection)
+ /** Stack pointer limit (for the stack overflow detection) */
uint32_t sp_lim;
#endif
} system_fault_t;
-// Task post-mortem information
+/** Task post-mortem information */
typedef struct {
- // Reason for the task termination
+ /** Reason for the task termination */
systask_term_reason_t reason;
- // Whether the error occurred in privileged mode
+ /** Whether the error occurred in privileged mode */
bool privileged;
union {
- // Argument passed to `systask_exit()`
+ /** Argument passed to `systask_exit()` */
struct {
int code;
} exit;
- // Fault information catched in `systask_exit_fault()`
+ /** Fault information catched in `systask_exit_fault()` */
system_fault_t fault;
- // Arguments passed to `systask_exit_fatal()`
+ /** Arguments passed to `systask_exit_fatal()` */
struct {
int32_t line;
char file[64];
char expr[64];
} fatal;
- // Arguments passed to `systask_exit_error()`
+ /** Arguments passed to `systask_exit_error()` */
struct {
char title[64];
char message[64];
@@ -99,24 +98,32 @@ typedef struct {
} systask_postmortem_t;
-// Error handler callback invoke when kernel task terminates.
-//
-// The purpose of this callbacks display RSOD (Red Screen of Death).
-//
-// The callback may be called from any context, including interrupt context.
+/**
+ * @brief Error handler callback invoked when kernel task terminates.
+ *
+ * The purpose of this callbacks is to display RSOD (Red Screen of Death).
+ *
+ * The callback may be called from any context, including interrupt context.
+ *
+ * @param pminfo Pointer to post-mortem information.
+ */
typedef void (*systask_error_handler_t)(const systask_postmortem_t* pminfo);
-// Maximum number of tasks that can be created
-// 1. kernel
-// 2. coreapp
+/**
+ * Maximum number of tasks that can be created
+ *
+ * 1. kernel
+ * 2. coreapp
+ * 3. user app
+ */
#define SYSTASK_MAX_TASKS 2
-// Zero-based task ID (up SYSTASK_MAX_TASKS - 1)
+/** Zero-based task ID (up SYSTASK_MAX_TASKS - 1) */
typedef uint8_t systask_id_t;
#ifdef KERNEL_MODE
-// Function call pushed onto the stack of the task
+/** Function call pushed onto the stack of the task */
typedef struct {
uintptr_t (*fn)(uintptr_t, uintptr_t, uintptr_t);
uintptr_t arg1;
@@ -124,155 +131,258 @@ typedef struct {
uintptr_t arg3;
} systask_fn_call_t;
-// Task context used by the kernel to save the state of each task
-// when switching between them
+/**
+ * Task context used by the kernel to save the state of each task
+ * when switching between them
+ */
typedef struct {
+ // `sp`, `sp_lim`, `exc_return` and `killed` should at the beginning
+ // and in this order to be compatible with the PendSV_Handler
#ifndef TREZOR_EMULATOR
- // `sp`, `sp_lim`, `exc_return` and `killed` should at the beginning
- // and in this order to be compatible with the PendSV_Handler
- // Stack pointer value
+ /** Stack pointer value */
uint32_t sp;
- // Stack pointer limit (ARMv8-M only)
+ /** Stack pointer limit (ARMv8-M only) */
uint32_t sp_lim;
- // Exception return value
+ /** Exception return value */
uint32_t exc_return;
#endif
- // Set to nonzero, if the task is killed
+ /** Set to nonzero, if the task is killed */
volatile uint32_t killed;
- // Task id
+ /** Task id */
systask_id_t id;
- // Task post-mortem information
+ /** Task post-mortem information */
systask_postmortem_t pminfo;
- // Applet bound to the task
+ /** Applet bound to the task */
void* applet;
#ifndef TREZOR_EMULATOR
- // MPU mode the task is running in
+ /** MPU mode the task is running in */
mpu_mode_t mpu_mode;
- // Original stack base
+ /** Original stack base */
uint32_t stack_base;
- // Original stack end
+ /** Original stack end */
uint32_t stack_end;
- // Static base (SB) address of RW segment
- // used with dynamically linked apps, otherwise set to 0.
+ /** Static base (SB) address of RW segment used with dynamically linked
+ * apps, otherwise set to 0. */
uint32_t sb_addr;
- // Address of the global TLS area
+ /** Address of the global TLS area */
void* tls_addr;
- // Number of bytes used in the TLS area
+ /** Number of bytes used in the TLS area */
size_t tls_size;
- // TLS copy if the task is inactive
+ /** TLS copy if the task is inactive */
uint32_t tls_copy[20];
- // Set if the task is processing the kernel callback
+ /** Set if the task is processing the kernel callback */
bool in_callback;
#else
- // System thread handle
+ /** System thread handle */
pthread_t pthread;
- // Condition variable used to signal the task
- // is ready to run
+ /** Condition variable used to signal the task is ready to run */
pthread_cond_t cv;
- // Emulation of the call pushed onto the stack
+ /** Emulation of the call pushed onto the stack */
systask_fn_call_t pushed_fn_call;
#endif
} systask_t;
-// Initializes the scheduler for tasks
-//
-// No other task functions should be called before this function
+/**
+ * @brief Initializes the scheduler for tasks
+ *
+ * No other task functions should be called before this function
+ *
+ * @param error_handler Callback invoked when a kernel task terminates with an
+ * error.
+ */
void systask_scheduler_init(systask_error_handler_t error_handler);
-// Returns the currently running task
+/**
+ * @brief Returns the currently running task
+ * @return Pointer to the currently running task.
+ */
systask_t* systask_active(void);
-// Returns the kernel task
+/**
+ * @brief Returns the kernel task
+ * @return Pointer to the kernel task.
+ */
systask_t* systask_kernel(void);
#ifndef TREZOR_EMULATOR
-// Enables automatics restoring of TLS area
-//
-// When task is deactivated, the tls area is automatically stored in the
-// `task->tls_copy` array and restored when the task is activated again.
+/**
+ * @brief Enables automatics restoring of TLS area
+ *
+ * When task is deactivated, the tls area is automatically stored in the
+ * `task->tls_copy` array and restored when the task is activated again.
+ *
+ * @param task Pointer to the task.
+ * @param tls TLS MPU area.
+ */
void systask_enable_tls(systask_t* task, mpu_area_t tls);
#endif
-// Makes the given task the currently running task.
+/**
+ * @brief Makes the given task the currently running task.
+ * @param task Pointer to the task to yield to.
+ */
void systask_yield_to(systask_t* task);
-// Initializes a task with the given stack pointer, stack size
-//
-// The task must be not be running when the function is called
+/**
+ * @brief Initializes a task with the given stack pointer, stack size
+ *
+ * The task must be not be running when the function is called
+ *
+ * @param task Pointer to the task to initialize.
+ * @param stack_base Stack base address.
+ * @param stack_size Stack size in bytes.
+ * @param sb_addr Static base address.
+ * @param context Context pointer.
+ * @return true on success, false otherwise.
+ */
bool systask_init(systask_t* task, uint32_t stack_base, uint32_t stack_size,
uint32_t sb_addr, void* context);
-// Returns true if the task is alive (not terminated, killed or crashed)
+/**
+ * @brief Returns true if the task is alive (not terminated, killed or crashed)
+ * @param task Pointer to the task.
+ * @return true if the task is alive, false otherwise.
+ */
bool systask_is_alive(const systask_t* task);
-// Pushes data onto the stack of the task
-//
-// The task must be not be running when the function is called
+/**
+ * @brief Pushes data onto the stack of the task
+ *
+ * The task must be not be running when the function is called
+ *
+ * @param task Pointer to the task.
+ * @param data Pointer to data to push.
+ * @param size Number of bytes to push.
+ * @return Pointer to the location on the stack where data was pushed.
+ */
uint32_t* systask_push_data(systask_t* task, const void* data, size_t size);
-// Pops data from the stack of the task
-//
-// The task must be not be running when the function is called
+/**
+ * @brief Pops data from the stack of the task
+ *
+ * The task must be not be running when the function is called
+ *
+ * @param task Pointer to the task.
+ * @param size Number of bytes to pop.
+ */
void systask_pop_data(systask_t* task, size_t size);
-// Runs the task with the given entrypoint and arguments
-//
-// The task must be not be running when the function is called
-// Return `true` in case of success, `false` otherwise
+/**
+ * @brief Runs the task with the given entrypoint and arguments
+ *
+ * The task must be not be running when the function is called
+ *
+ * @param task Pointer to the task.
+ * @param fn Entry function pointer.
+ * @param arg1 First argument.
+ * @param arg2 Second argument.
+ * @param arg3 Third argument.
+ * @return true in case of success, false otherwise.
+ */
bool systask_push_call(systask_t* task, void* fn, uintptr_t arg1,
uintptr_t arg2, uintptr_t arg3);
-// Invokes the callback function in the context of the given task
+/**
+ * @brief Invokes the callback function in the context of the given task
+ *
+ * @param task Pointer to the task.
+ * @param arg1 First callback argument.
+ * @param arg2 Second callback argument.
+ * @param arg3 Third callback argument.
+ * @param callback Pointer to the callback function.
+ * @return Result returned by the callback.
+ */
// uint32_t callback(uint32_t arg1, uint32_t arg2, uint32_t arg3);
uint32_t systask_invoke_callback(systask_t* task, uintptr_t arg1,
uintptr_t arg2, uintptr_t arg3,
void* callback);
#ifndef TREZOR_EMULATOR
-// Sets R0 and R1 registers of the suspended task
+/**
+ * @brief Sets R0 and R1 registers of the suspended task
+ * @param task Pointer to the task.
+ * @param r0 Value to set in R0.
+ * @param r1 Value to set in R1.
+ */
void systask_set_r0r1(systask_t* task, uint32_t r0, uint32_t r1);
-// Gets R0 register value of the suspended task
+/**
+ * @brief Gets R0 register value of the suspended task
+ * @param task Pointer to the task.
+ * @return Value of R0 register.
+ */
uint32_t systask_get_r0(systask_t* task);
#endif
-// Gets the ID (zero-based index up SYSTASK_MAX_TASKS - 1) of the given task.
+/**
+ * @brief Gets the ID (zero-based index up SYSTASK_MAX_TASKS - 1) of the given
+ * task.
+ * @param task Pointer to the task.
+ * @return Task ID.
+ */
systask_id_t systask_id(const systask_t* task);
-// Terminates the task with the given exit code
-//
-// If the task is not specified (NULL), it's automatically determined:
-// 1) If the function is called in thread mode, the active task will be
-// terminated.
-// 2) If the function is called in handler mode, the kernel task will be
-// terminated even if it is not the active task.
-//
-// If the terminated task is unprivileged, the kernel task will be scheduled
-// next.
+/**
+ * @brief Terminates the task with the given exit code
+ *
+ * If the task is not specified (NULL), it's automatically determined:
+ * 1) If the function is called in thread mode, the active task will be
+ * terminated.
+ * 2) If the function is called in handler mode, the kernel task will be
+ * terminated even if it is not the active task.
+ *
+ * If the terminated task is unprivileged, the kernel task will be scheduled
+ * next.
+ *
+ * @param task Pointer to the task to terminate, or NULL.
+ * @param exit_code Exit code for the task.
+ */
void systask_exit(systask_t* task, int exit_code);
-// Terminates the task with an error message
-//
-// (see `systask_exit()` for more details)
+/**
+ * @brief Terminates the task with an error message
+ *
+ * (see `systask_exit()` for more details)
+ *
+ * @param task Pointer to the task.
+ * @param title Title string.
+ * @param title_len Length of the title.
+ * @param message Message string.
+ * @param message_len Length of the message.
+ * @param footer Footer string.
+ * @param footer_len Length of the footer.
+ */
void systask_exit_error(systask_t* task, const char* title, size_t title_len,
const char* message, size_t message_len,
const char* footer, size_t footer_len);
-// Terminates the task with a fatal error message
-//
-// (see `systask_exit()` for more details)
+/**
+ * @brief Terminates the task with a fatal error message
+ *
+ * (see `systask_exit()` for more details)
+ *
+ * @param task Pointer to the task.
+ * @param message Message string.
+ * @param message_len Length of the message.
+ * @param file File string.
+ * @param file_len Length of the file string.
+ * @param line Line number.
+ */
void systask_exit_fatal(systask_t* task, const char* message,
size_t message_len, const char* file, size_t file_len,
int line);
-// Prints the post-mortem information about the task to the debug output
+/**
+ * @brief Prints the post-mortem information about the task to the debug output
+ * @param task Pointer to the task.
+ */
void systask_print_pminfo(systask_t* task);
#endif // KERNEL_MODE
diff --git a/core/embed/sys/task/inc/sys/system.h b/core/embed/sys/task/inc/sys/system.h
index 4e83c7833..ff6f25ccd 100644
--- a/core/embed/sys/task/inc/sys/system.h
+++ b/core/embed/sys/task/inc/sys/system.h
@@ -24,16 +24,17 @@
#ifdef KERNEL_MODE
/**
- * @brief Initializes fundamental system services (MPU, SysTick, systimer
- * and task scheduler)
+ * @brief Initializes the fundamental system services (MPU, SysTick, systimer
+ * and task scheduler).
*
- * @param error_handler Callback that is called when a kernel task
- * terminates with an error
+ * @param error_handler Callback that is called when a kernel task terminates
+ * with an error
*/
void system_init(systask_error_handler_t error_handler);
/**
- * Deinitializes the system services before handover to next booting stage.
+ * @brief Deinitializes the system services before handover to next booting
+ * stage.
*/
void system_deinit(void);
@@ -56,8 +57,8 @@ void system_deinit(void);
* leave the postmortem information in the bootargs allowing the bootloader
* to display the RSOD.
*
- * @param error_handler Callback that is called in the emergency mode
- * @param pminfo Postmortem information about the error
+ * @param error_handler Callback invoked in emergency mode (may be NULL).
+ * @param pminfo Postmortem information passed to the error handler.
*/
__attribute__((noreturn)) void system_emergency_rescue(
systask_error_handler_t error_handler, const systask_postmortem_t* pminfo);
@@ -71,27 +72,63 @@ __attribute__((noreturn)) void system_emergency_rescue(
* postmortem information. If the task is not the kernel task, the task is
* terminated immediately and the kernel task is scheduled.
*
- * @param exitcode Exit code passed to the error handler
+ * @param exitcode Exit code returned by the terminating task.
*/
void system_exit(int exitcode);
+/**
+ * @brief Terminates the current task with an error message.
+ *
+ * See the notes for `system_exit` regarding the behavior of the error handler
+ *
+ * @param title Title of the error.
+ * @param message Main error message.
+ * @param footer Footer text for the error display.
+ */
+void system_exit_error(const char* title, const char* message,
+ const char* footer);
+
/**
* @brief Like `system_exit_error`, but with explicit lengths for the strings.
+ *
+ * @param title Title of the error.
+ * @param title_len Length of the title.
+ * @param message Main error message.
+ * @param message_len Length of the message.
+ * @param footer Footer text for the error display.
+ * @param footer_len Length of the footer.
*/
void system_exit_error_ex(const char* title, size_t title_len,
const char* message, size_t message_len,
const char* footer, size_t footer_len);
+/**
+ * @brief Terminates the current task with a fatal error message.
+ *
+ * See the notes for `system_exit` regarding the behavior of the error handler
+ *
+ * @param message Fatal error message.
+ * @param file Source file where the fatal error occurred.
+ * @param line Line number in the source file.
+ */
+void system_exit_fatal(const char* message, const char* file, int line);
+
/**
* @brief Like `system_exit_fatal`, but with explicit lengths for the strings.
+ *
+ * @param message Fatal error message.
+ * @param message_len Length of the message.
+ * @param file Source file where the fatal error occurred.
+ * @param file_len Length of the file string.
+ * @param line Line number in the source file.
*/
void system_exit_fatal_ex(const char* message, size_t message_len,
const char* file, size_t file_len, int line);
/**
- * Returns string representation of the system fault.
+ * @brief Returns string representation of the system fault.
*
- * @param fault Pointer to the system fault information
- * @return String representation of the fault
+ * @param fault Pointer to the system fault structure.
+ * @return const char* String describing the fault.
*/
const char* system_fault_message(const system_fault_t* fault);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.