arch/x86: Provide vfork() - #19777
Draft
casaroli wants to merge 1 commit into
Draft
Conversation
x86 selected neither fork primitive, so vfork() was not available on this architecture at all. fork.S takes the register snapshot and hands it to x86_fork(), which allocates the child, copies the used part of the caller's stack, and starts it. There is one entry point for both primitives, because the snapshot is the same for either. Unlike the register-passing architectures, cdecl puts the flag on the stack, so up_fork() loads it from 4(%esp). That slot is also the stack pointer the caller had: it pushed the argument, then `call' pushed the return address. So the low end of the region that x86_fork() copies is unchanged. POSIX fork() is not provided. It needs an address environment that can be duplicated and this architecture has none, so CONFIG_ARCH_HAVE_FORK is never set here. x86_fork.c makes that a build error rather than a silent omission. Verified under QEMU with qemu-i486:nsh. ostest runs to the end and reports "Child 5 ran and exited before the parent resumed", with fork() correctly absent. Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
x86 selected neither fork primitive.
vfork()was not available on this architecture at all. This pull request provides it.fork.Stakes the register snapshot of the caller and hands it tox86_fork(), which allocates the child, copies the used part of the stack of the caller, and starts it. There is one entry point for both primitives, because the snapshot is the same for either.The calling convention differs from every other architecture that has this. cdecl puts the flag on the stack, so
up_fork()loads it from4(%esp)rather than keeping a register alive. That slot is also the stack pointer the caller had: the caller pushed the argument, thencallpushed the return address. The low end of the region thatx86_fork()copies is therefore unchanged.Impact
The change is specific to x86. It adds capability and removes none.
vfork()becomes available on x86. Code that testsCONFIG_ARCH_HAVE_VFORKnow finds it here.POSIX
fork()is not provided. It needs an address environment that can be duplicated, and this architecture has none, soCONFIG_ARCH_HAVE_FORKis never set.x86_fork.cmakes that a build error rather than a silent omission:No board configuration changes.
Testing
Emulation only. QEMU 11.0.3 on macOS 15 with Apple Silicon,
i686-elf-gccfrom Homebrew.qemu-i486:nsh, withostesttyped at the prompt:fork()is correctly absent from that run.tools/checkpatch.sh -c -u -m -ggives no errors.Two notes for anyone repeating this.
i686-elf-gccis a bare cross compiler with no libc, so nothing providesmath.hand the build stops inlib_strtold.c. SelectCONFIG_LIBMinstead ofCONFIG_LIBM_TOOLCHAIN. And useqemu-i486:nsh, notqemu-i486:ostest: that configuration consoles throughCONFIG_CONSOLE_SYSLOGand floods the output, which is #19568 and unrelated to this change.What is not tested
No x86 hardware.
A report from a board would be welcome. Take this branch with apache/nuttx-apps#3685, build
qemu-i486:nshand runostest. Thevfork()test is the first output.