casaroli opened a new pull request, #19776:
URL: https://github.com/apache/nuttx/pull/19776
> **Draft.** The evidence is emulation only. I keep this as a draft until
`fork()` runs on x86_64 hardware.
## Summary
`fork()` was withdrawn from every architecture by #19562, and each
architecture restores it with the correct behaviour. This pull request restores
it for x86_64.
`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 saved-syscall-frame half is already in master. #19562 added it, so
`x86_64_syscall()` stores the exception frame of the caller in `xcp.sregs` and
`x86_64_fork()` chooses between `x86_64_fork_syscall()` and
`x86_64_fork_direct()`.
## Impact
The change is specific to x86_64. It adds capability and removes none.
`fork()` becomes available on x86_64 outside a protected build.
`ARCH_HAVE_FORK` keeps `depends on ARCH_ADDRENV`, so a configuration without
address environments is unaffected.
`vfork()` does not change. No board configuration changes.
## Testing
Emulation only. QEMU 11.0.3 on macOS 15 with Apple Silicon, `x86_64-elf-gcc`
16.1.0. There is no hardware x86 acceleration on this host, so this ran under
TCG.
`qemu-intel64:knsh_romfs`, a kernel build:
```
qemu-system-x86_64 -machine pc,hpet=on -cpu max -m 2G \
-kernel nuttx -nographic -no-reboot -net none
```
```
user_main: vfork() test
vfork_test: Child 6 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.
Two notes for anyone repeating this under TCG. `-cpu max` is the flag that
matters, and a named Intel model is much slower. Three configuration changes
are necessary as well: disable `ARCH_INTEL64_HAVE_PCID` and
`ARCH_INTEL64_TSC_DEADLINE`, and enable `ARCH_INTEL64_HPET_ALARM`. Without them
the console stops after SeaBIOS and looks like a hang.
### What is not tested
No x86_64 hardware, and no KVM. This is the reason for the draft status.
The protected build is excluded by the Kconfig condition and is not tested.
**A report from real x86_64 hardware is welcome.** Take this branch with
apache/nuttx-apps#3685, build `qemu-intel64:knsh_romfs` and run
`/system/bin/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]