This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 68c4b5bdc42 arch/arm64/irq.h: fix up_getsp() to return real SP instead
of FP
68c4b5bdc42 is described below
commit 68c4b5bdc42211f8db711083ed059f13e2bcee8e
Author: hujun5 <[email protected]>
AuthorDate: Wed May 6 10:04:33 2026 +0800
arch/arm64/irq.h: fix up_getsp() to return real SP instead of FP
The arm64 up_getsp() was implemented as __builtin_frame_address(0),
which returns the frame pointer (X29), not the stack pointer (SP).
This is inconsistent with all other architectures (arm32, risc-v,
xtensa, x86_64, etc.) which read the actual SP register.
The incorrect FP value causes arm64_stack_color() to corrupt its
own local variables when colorizing the running stack (nbytes=0),
because FP > SP means the coloration range includes the current
frame's locals. With -O0 this triggers a page fault; with -O3 it
is masked because loop variables stay in registers.
Fix by replacing the macro with an inline function that reads SP
via 'mov %0, sp'. This aligns arm64 with all other architectures
and fixes the stack coloration self-corruption bug.
Signed-off-by: hujun5 <[email protected]>
---
arch/arm64/include/irq.h | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/include/irq.h b/arch/arm64/include/irq.h
index e36b94a8d5b..9f92d62c3d0 100644
--- a/arch/arm64/include/irq.h
+++ b/arch/arm64/include/irq.h
@@ -56,8 +56,6 @@
# define __ARM_ARCH 8
#endif
-#define up_getsp() (uintptr_t)__builtin_frame_address(0)
-
/* MPIDR_EL1, Multiprocessor Affinity Register */
#define MPIDR_AFFLVL_MASK (0xff)
@@ -433,6 +431,13 @@ static inline_function void up_irq_restore(irqstate_t
flags)
__asm__ __volatile__("msr daif, %0" :: "r" (flags): "memory");
}
+static inline_function uintptr_t up_getsp(void)
+{
+ register uintptr_t sp;
+ __asm__ __volatile__("mov %0, sp" : "=r"(sp));
+ return sp;
+}
+
/****************************************************************************
* Public Function Prototypes
****************************************************************************/