You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Application can hit mpu fault before starting main thread. This is caused by stack misuse. In function z_arch_switch_to_main_thread thread entry is provided as forth argument (_main). Then within the function stack pointer is changed:
After stack is changed, call to thread entry occurs which is using _main as the argument. If variable is stored on stack, it will be fetched from stack but at that point this is already different stack and value is corrupted:
This commit partially reverts the changes introduced in
(bbe1a19), where the PSP
modification, the interrupt enabling, and the branch to main
thread were refactored in C functions. This introduced an issue
with stack usage when compiling without any optimization.
Reverting to use assembly functions to jump to main thread
ensures, now, that the pointer to main() is preserved intact
while changing the PSP and passed correctly to z_thread_entry().
Fixeszephyrproject-rtos#14471.
Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit partially reverts the changes introduced in
(bbe1a19), where the PSP
modification, the interrupt enabling, and the branch to main
thread were refactored in C functions. This introduced an issue
with stack usage when compiling without any optimization.
Reverting to use assembly functions to jump to main thread
ensures, now, that the pointer to main() is preserved intact
while changing the PSP and passed correctly to z_thread_entry().
Fixes#14471.
Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
Describe the bug
Application can hit mpu fault before starting main thread. This is caused by stack misuse. In function
z_arch_switch_to_main_thread
thread entry is provided as forth argument (_main
). Then within the function stack pointer is changed:zephyr/arch/arm/include/kernel_arch_func.h
Line 106 in 269935d
After stack is changed, call to thread entry occurs which is using
_main
as the argument. If variable is stored on stack, it will be fetched from stack but at that point this is already different stack and value is corrupted:zephyr/arch/arm/include/kernel_arch_func.h
Line 115 in 269935d
So
_main
variable will be corrupted.To Reproduce
Modify hello_world example by using following prj.conf:
Steps to reproduce the behavior:
Expected behavior
Sample should start.
Impact
Suddenly system crashes during initialization.
The text was updated successfully, but these errors were encountered: