casaroli opened a new pull request, #19773:
URL: https://github.com/apache/nuttx/pull/19773

   > **Draft.** The evidence is emulation only. I keep this as a draft until 
`fork()` runs on ARM64 hardware. A Raspberry Pi test is planned.
   
   ## Summary
   
   `fork()` was withdrawn from every architecture by #19562, and each 
architecture restores it with the correct behaviour. This pull request restores 
it for ARM64.
   
   `up_addrenv_fork()` duplicates an address environment into freshly allocated 
pages mapped at the same virtual addresses. The text, data and heap regions of 
the source are walked one page at a time and copied into fresh pages hung off 
the page tables of the child.
   
   The other half is already in master. #19562 added the saved-syscall-frame 
path, where `dispatch_syscall()` stores the exception frame of the caller in 
`xcp.sregs` and `arm64_fork()` builds the child from it. `arm64_fork.c` also 
already takes both paths: a child that keeps the stack addresses of the parent 
needs no relocation, which is what a duplicated address environment gives it. 
Only the hook and the Kconfig default were missing.
   
   ## Impact
   
   The change is specific to ARM64. It adds capability and removes none.
   
   `fork()` becomes available on ARM64 in a kernel build over an MMU. 
`ARCH_HAVE_FORK` keeps `depends on ARCH_ADDRENV`, so a configuration without 
address environments is not affected. A protected build is excluded.
   
   `vfork()` does not change. No board configuration changes.
   
   ## Testing
   
   Emulation only. `qemu-armv8a:knsh`, a kernel build, under QEMU 11.0.3 on 
macOS 15 with Apple Silicon, `aarch64-none-elf-gcc` 14.2.rel1.
   
   ```
   qemu-system-aarch64 -cpu cortex-a53 -nographic \
     -machine virt,virtualization=on,gic-version=3 \
     -net none -semihosting -kernel nuttx
   ```
   
   `-semihosting` is necessary. A kernel build loads its applications over 
hostfs, and without the flag the guest traps in `smh_call` and panics in 
`AppBringUp`, which looks like a kernel defect and is not one.
   
   `ostest` runs to the end:
   
   ```
   user_main: vfork() test
   vfork_test: Child 7 ran and exited before the parent resumed
   user_main: fork() test
   fork_test: Child running independently (child)
   fork_test: Parent and child had independent memory
   ostest_main: Exiting with status 0
   ```
   
   `tools/checkpatch.sh -c -u -m -g` gives no errors.
   
   ### What is not tested
   
   No ARM64 hardware. This is the reason for the draft status.
   
   The protected build is not tested at run time either. The only ARM64 
protected configurations in the tree are the ARMv8-R FVPs, and QEMU has no 
Cortex-R82. `fork()` is excluded from a protected build in any case.
   
   **A report from an ARM64 board is welcome.** Take this branch with 
apache/nuttx-apps#3685, build a kernel configuration and run `ostest`. The fork 
tests are the first output.
   


-- 
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]

Reply via email to