nuttx/arch/arm64/src
Marco Casaroli 3557791ae2 arch/arm64: Build fork() children from the caller's syscall frame.
In a kernel or protected build vfork() is reached through a system call, so
the return address and stack pointer that the entry point in
arm64_fork_func.S can snapshot for itself belong to the kernel-side stub, not
to the caller.  A child built from that snapshot resumes at a kernel address
on a kernel stack.  This is why arm64 selected the fork family only for the
flat build.

Record what the caller was actually doing instead.  arm64_sync_exc passes the
exception frame to dispatch_syscall() in x7 -- x0-x6 carry the call number and
its six parameters, so x7 is free -- and dispatch_syscall() stores it in
xcp.sregs, mirroring what riscv_swint.c does.

arm64_fork() then chooses where the caller's registers live:

  arm64_fork_syscall()  when TCB_FLAG_SYSCALL is set, rebuilding the child
                        from xcp.sregs so that it returns from the very same
                        SVC as the parent;
  arm64_fork_direct()   otherwise, which is the flat build and any kernel
                        thread that calls the entry point as a plain function.

The stack copy and the relocation of pointers into it are shared by both
paths in arm64_fork_stack() and arm64_fork_reloc().

With that in place ARCH_ARM64 can select ARCH_HAVE_VFORK unconditionally.

Verified on qemu-armv8a:knsh (BUILD_KERNEL), qemu-armv8a:nsh (BUILD_FLAT) and
qemu-armv8a:citest_smp under qemu-system-aarch64:  ostest's vfork_test passes
on all three, and it was absent from knsh before the change.  The protected
configurations are build-verified only (fvp-armv8r:pnsh), there being no
emulator for them here.

Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-08-10 08:57:30 -03:00
..
a64 include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
a527 include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
am62x arm64/am62x: Add TISCI client, GPIO and I2C drivers 2026-08-02 11:40:13 +08:00
bcm2711 arm64/bcm2711/pwm: Fix PWM defconfigs 2026-07-28 02:46:42 +08:00
cmake cmake: Use NUTTX(_DIR/_BIN_DIR) instead CMAKE(_SRC_DIR/_BIN_DIR) 2026-08-09 11:13:08 -03:00
common arch/arm64: Build fork() children from the caller's syscall frame. 2026-08-10 08:57:30 -03:00
fvp-v8r include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
goldfish include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
imx8 include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
imx9 arch/arm64/src/imx9/imx9_usdhc.c: Fix imx9 usdhc DMA initialization 2026-08-04 13:55:31 +02:00
qemu include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
rk3399 include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
rk3588 arm64: add RK3588 support 2026-07-20 20:55:52 -03:00
zynq-mpsoc include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
.gitignore arch: arm64: ARMv8-A support for NuttX 2022-07-14 09:35:49 -04:00
CMakeLists.txt arch: fix arch_interface guard for kernel builds 2026-08-06 02:39:03 +08:00
Makefile tools: fix stale archive members surviving a Kconfig-driven CSRCS change 2026-07-28 21:26:03 -03:00
Toolchain.defs build/cmake: Add toolchain C++ library linking for all platforms. 2026-01-24 19:30:21 +08:00