nuttx/arch/arm64/include
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 arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00
a527 arch/arm64/a527: Add support for Allwinner A527 SoC 2025-03-17 08:58:29 +01:00
am62x arm64/am62x: Add TISCI client, GPIO and I2C drivers 2026-08-02 11:40:13 +08:00
bcm2711 bcm2711/oneshot: Implement oneshot timer driver for BCM2711 2026-07-12 09:52:26 +08:00
fvp-v8r arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00
goldfish arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00
imx8 arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00
imx9 imx9: imx95 fix uSDHC IRQ naming to match NuttX USDHC convention 2026-03-24 15:39:07 +08:00
qemu arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00
rk3399 fix nxstyle 2024-12-10 01:29:00 +08:00
rk3588 arm64: add RK3588 support 2026-07-20 20:55:52 -03:00
zynq-mpsoc style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
.gitignore
arch.h arm64: add MPU-based address environment support and refactor MMU variant 2026-01-22 15:39:34 +08:00
barriers.h barrier: add UP_RMB UP_WMB 2025-12-22 10:22:06 -03:00
elf.h arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00
inttypes.h arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00
irq.h arch/arm64: Build fork() children from the caller's syscall frame. 2026-08-10 08:57:30 -03:00
limits.h arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00
setjmp.h arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00
spinlock.h spinlock: fix stxr instruction status register requirement 2025-06-26 20:31:19 +08:00
stdarg.h arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00
syscall.h drivers/misc/optee: Add SMC backend for arm archs 2025-05-09 10:29:26 +08:00
types.h arch/arm64: migrate to SPDX identifier 2024-12-02 22:43:23 +08:00