hujun260 opened a new pull request, #22173:
URL: https://github.com/apache/nuttx/pull/22173
# arm64: fix `up_getsp()` to return the real stack pointer
## Summary
Fix the ARM64 implementation of `up_getsp()` so that it returns the current
stack pointer (`SP`) instead of the frame pointer (`X29`).
The previous implementation used `__builtin_frame_address(0)`, which returns
the current frame address. When `arm64_stack_color()` colors the running
stack
with `nbytes == 0`, this value can include the current function's local frame
and corrupt local variables. The issue is more visible with `-O0` and can be
masked by optimization.
## Changes
- Replace the `up_getsp()` macro based on `__builtin_frame_address(0)`.
- Add an inline ARM64 implementation that reads `SP` with `mov %0, sp`.
- Keep the return type as `uintptr_t`, consistent with the ARM64 address
size.
## Commit
```text
a7eacca8fced5071107bc85881636f95ce06db28
arch/arm64/irq.h: fix up_getsp() to return real SP instead of FP
```
## Testing
### ARM64 QEMU GNU build
Command:
```text
$ export
PATH=/home/hujun5/work/ssd/dev_vela/prebuilts/gcc/linux-x86_64/aarch64-none-elf/bin:$PATH
$ make distclean
$ tools/configure.sh -l qemu-armv8a:nsh
$ make -j$(nproc)
```
Result: **PASS**
Captured output:
```text
LD: nuttx
Memory region Used Size Region Size %age Used
CP: nuttx.hex
CP: nuttx.bin
BUILD_EXIT_CODE=0
```
### ARM64 QEMU runtime
Command:
```text
$ timeout 12s qemu-system-aarch64 -cpu cortex-a53 -nographic \
-machine virt,virtualization=on,gic-version=3 \
-net none -chardev stdio,id=con,mux=on -serial chardev:con \
-mon chardev=con,mode=readline -kernel ./nuttx
```
Result: **PASS: NuttX boots to the NSH prompt**
Captured output:
```text
- Ready to Boot Primary CPU
- Boot from EL2
- Boot from EL1
- Boot to C runtime for OS Initialize
nsh>
QEMU_TIMEOUT_EXIT_CODE=124
```
The QEMU process was stopped by the test timeout after reaching the NSH
prompt. No hardware test was run.
### Static checks
```text
$ tools/checkpatch.sh -c -u -m -g HEAD^..HEAD
Used config files:
1: .codespellrc
✔️ All checks pass.
$ git diff --check HEAD^ HEAD
[no output]
```
## Scope not tested
- No physical ARM64 hardware test was run.
- No dedicated regression test was added for stack-coloring self-corruption.
- Protected, kernel, and SMP variants were not built separately.
- CMake/Ninja builds were not run.
- The complete GitHub Actions ARM64 matrix was not reproduced locally.
## Note about example logs
The logs above are copied from local validation runs. If this description is
used as a template for a different environment, replace the command paths and
output with the corresponding captured logs; do not present simulated output
as actual test evidence.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]