mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
arch/risc-v: preserve ra in up_idle() for fp-chain backtrace
up_idle() is a leaf function; with frame pointers enabled the compiler skips spilling ra, corrupting the fp chain. Clobber "ra" in the WFI inline asm so backtrace can walk past the idle frame correctly. Assisted-by: Claude Code:claude-sonnet-5 Signed-off-by: liang.huang <liang.huang@houmo.ai>
This commit is contained in:
parent
eea880f1ac
commit
7c75dbae2b
1 changed files with 12 additions and 1 deletions
|
|
@ -71,7 +71,18 @@ void up_idle(void)
|
|||
* sleep in a reduced power mode until an interrupt occurs to save power
|
||||
*/
|
||||
|
||||
asm("WFI");
|
||||
/* up_idle() never calls another function, so with frame pointers
|
||||
* enabled the compiler has no need to spill ra and skips it, leaving
|
||||
* its slot in the fp-chain holding whatever was on the stack before.
|
||||
* Clobbering "ra" forces it to be spilled/reloaded around WFI so the
|
||||
* fp-chain backtrace sched_backtrace() relies on can find it.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_SCHED_BACKTRACE)
|
||||
asm volatile ("WFI" : : : "ra");
|
||||
#else
|
||||
asm volatile ("WFI");
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue