Skip to content

Commit

Permalink
arch: xtensa: Fix xtensa error handler
Browse files Browse the repository at this point in the history
Force an early return from exception when a stack check failure
is detected at interrupt/exception level. This helps to ensure
that ARCH_EXCEPT() does not return.

Signed-off-by: Aastha Grover <aastha.grover@intel.com>
  • Loading branch information
aasthagr committed Apr 6, 2023
1 parent 148c0e1 commit 3eb65f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions arch/xtensa/core/xtensa-asm2.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ void *xtensa_excint1_c(int *interrupted_stack)
reason = bsa[BSA_A2_OFF/4];
/* Skip ILL to RETW */
bsa[BSA_PC_OFF/4] += 3;
/* This would ensure nested count is reset to one when an exception
* is triggered from ISR context. When nested count <=1 the handler would
* switch the thread context, otherwise would return the interrupted stack.
* This would cause xtensa_arch_except to return when it is not expected to.
* Resetting the cpu nested count prevents xtensa_arch_except from returning
* in ISR context.
*/
if ((arch_curr_cpu()->nested > 1) && (reason == K_ERR_STACK_CHK_FAIL)) {
arch_curr_cpu()->nested = 1U;
}
pc = (void *)bsa[BSA_PC_OFF/4];
}

Expand Down
1 change: 1 addition & 0 deletions include/zephyr/arch/xtensa/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern void xtensa_arch_except(int reason_p);

#define ARCH_EXCEPT(reason_p) do { \
xtensa_arch_except(reason_p); \
CODE_UNREACHABLE; \
} while (false)

/* internal routine documented in C file, needed by IRQ_CONNECT() macro */
Expand Down

0 comments on commit 3eb65f2

Please sign in to comment.