Skip to content

Commit

Permalink
core: support fault mitigations in non-threaded code
Browse files Browse the repository at this point in the history
Fault mitigation won't work in non-threaded code due to the following
error:
assertion 'ct >= 0 && ct < CFG_NUM_THREADS' failed at core/arch/arm/kernel
/thread.c:799 <thread_get_id>

The problem is in  __ftmn_get_tsd_func_arg_pp which calls thread_get_tsd
which thread_get_id. The reason is that the interrupt handler is not
associated with any thread, so the ct (current_thread_id) value is -1 which
would cause an assert problem.

The fix is to add ftmn_arg to thread_core_local and the new variable would
be used when the current thread is < 0.

Signed-off-by: Sichun Qin <sichun.qin@amlogic.com>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
Sichun Qin authored and jforissier committed Sep 29, 2023
1 parent c90dc99 commit ce56605
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/arch/arm/include/kernel/thread_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ struct thread_core_local {
#ifdef CFG_CORE_DEBUG_CHECK_STACKS
bool stackcheck_recursion;
#endif
#ifdef CFG_FAULT_MITIGATION
struct ftmn_func_arg *ftmn_arg;
#endif
} THREAD_CORE_LOCAL_ALIGNED;

struct thread_vector_table {
Expand Down
5 changes: 4 additions & 1 deletion lib/libutils/ext/include/fault_mitigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ extern struct ftmn_func_arg *__ftmn_global_func_arg;
static inline struct ftmn_func_arg **__ftmn_get_tsd_func_arg_pp(void)
{
#if defined(CFG_FAULT_MITIGATION) && defined(__KERNEL__)
return &thread_get_tsd()->ftmn_arg;
if (thread_get_id_may_fail() >= 0)
return &thread_get_tsd()->ftmn_arg;
else
return &thread_get_core_local()->ftmn_arg;
#elif defined(CFG_FAULT_MITIGATION)
return &__ftmn_global_func_arg;
#else
Expand Down

0 comments on commit ce56605

Please sign in to comment.