os/arch/arm/src/armv7-m: Preserve EXC_RETURN across trampoline - #7456
os/arch/arm/src/armv7-m: Preserve EXC_RETURN across trampoline#7456seokhun-eom24 wants to merge 1 commit into
Conversation
4af6d8f to
c7e320b
Compare
|
Similar PR: #7385 |
|
LGTM |
|
we have verified it on mediatek_2.0 . It's working fine.
After these changes, all build issues will be resolved when we enable CONFIG_ARM_CMNVECTOR in Mediatek_2.0 with PR#7456 |
c7e320b to
7edee8a
Compare
| #ifdef CONFIG_BUILD_PROTECTED | ||
| tcb->xcp.saved_lr = current_regs[REG_LR]; | ||
| #endif | ||
| #if defined(CONFIG_ARM_CMNVECTOR) || defined(CONFIG_BUILD_PROTECTED) |
There was a problem hiding this comment.
Could you please explan why CONFIG_ARM_CMNVECTOR checking is added?
There was a problem hiding this comment.
REG_EXC_RETURN is only available when CONFIG_ARM_CMNVECTOR or CONFIG_BUILD_PROTECTED is enabled.
Therefore, the usage should be guarded with #if defined(CONFIG_ARM_CMNVECTOR) || defined(CONFIG_BUILD_PROTECTED) to handle the case where both options are disabled like qemu/build_test.
There was a problem hiding this comment.
| ARM_CMNVECTOR | BUILD_PROTECTED | Context Layout Header | REG_EXC_RETURN | saved_exc_ret | Reason |
|---|---|---|---|---|---|
| ❌ | ❌ | irq_lazyfpu.h | ❌ | ❌ | Standard lazy-FPU / flat context does not have a dedicated slot for storing EXC_RETURN. |
| ❌ | ⭕ | irq_lazyfpu.h | ⭕ | ⭕ | In protected builds, EXC_RETURN must be saved in slot 10 to manage privilege return states. |
| ⭕ | ❌ | irq_cmnvector.h | ⭕ | ⭕ | Common-vector context always preserves EXC_RETURN, even in flat builds. |
| ⭕ | ⭕ | irq_cmnvector.h | ⭕ | ⭕ | Applies both common-vector requirements and protected-build privilege tracking. |
There was a problem hiding this comment.
#if defined(CONFIG_ARM_CMNVECTOR) || defined(CONFIG_BUILD_PROTECTED)
/* All tasks start via a stub function in kernel space. So all
* tasks must start in privileged thread mode. If CONFIG_BUILD_PROTECTED
* is defined, then that stub function will switch to unprivileged
* mode before transferring control to the user task.
*/
xcp->regs[REG_EXC_RETURN] = EXC_RETURN_PRIVTHR;
#endif /* CONFIG_ARM_CMNVECTOR || CONFIG_BUILD_PROTECTED */https://github.com/Samsung/TizenRT/blob/master/os/arch/arm/src/armv7-m/up_initialstate.c#L150
This is why we need to use #if defined(CONFIG_ARM_CMNVECTOR) || defined(CONFIG_BUILD_PROTECTED)
The common-vector register contains REG_EXC_RETURN in both flat and protected builds.
Signal delivery temporarily redirects the saved context to up_sigdeliver, so it must save the original EXC_RETURN, force the trampoline to return through privileged Thread mode, and restore the original value after the handler completes.
Move the EXC_RETURN save, update, and restore outside the protected-build guard while keeping LR handling protected-only.
Always select EXC_RETURN_PRIVTHR for a non-running target instead of only converting handler-mode contexts.
This prevents a blocked task from entering the kernel signal trampoline with an incompatible handler or unprivileged return state and avoids exception-return integrity faults.
In `CONFIG_ARM_CMNVECTOR is not set` and `CONFIG_BUILD_PROTECTED is not set` case we're setting `EXC_RETURN_PRIVTHR` in up_lazyexception.S
```
#ifdef CONFIG_BUILD_PROTECTED
ldmia r0, {r2-r11,r14} /* Recover R4-R11, r14 + 2 temp values */
#else
ldmia r0, {r2-r11} /* Recover R4-R11 + 2 temp values */
ldr r14, =EXC_RETURN_PRIVTHR /* Load the special value */
#endif
```
Signed-off-by: seokhun-eom <seokhun.eom@samsung.com>
7edee8a to
d276a0e
Compare
The common-vector register contains REG_EXC_RETURN in both flat and protected builds.
Signal delivery temporarily redirects the saved context to up_sigdeliver, so it must save the original EXC_RETURN, force the trampoline to return through privileged Thread mode, and restore the original value after the handler completes.
Move the EXC_RETURN save, update, and restore outside the protected-build guard while keeping LR handling protected-only.
Always select EXC_RETURN_PRIVTHR for a non-running target instead of only converting handler-mode contexts.
This prevents a blocked task from entering the kernel signal trampoline with an incompatible handler or unprivileged return state and avoids exception-return integrity faults.
In
CONFIG_ARM_CMNVECTOR is not setandCONFIG_BUILD_PROTECTED is not setcase we're settingEXC_RETURN_PRIVTHRin up_lazyexception.S