Page MenuHomeFreeBSD

libsys, libc: provide rfork_thread() and pdrfork_thread() on all arches
ClosedPublic

Authored by kib on Jan 26 2026, 7:37 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Mar 7, 10:09 AM
Unknown Object (File)
Wed, Mar 4, 10:15 PM
Unknown Object (File)
Mon, Mar 2, 1:19 AM
Unknown Object (File)
Sun, Mar 1, 3:19 AM
Unknown Object (File)
Sun, Mar 1, 12:38 AM
Unknown Object (File)
Sat, Feb 28, 11:00 PM
Unknown Object (File)
Sat, Feb 28, 7:13 PM
Unknown Object (File)
Wed, Feb 11, 9:17 AM
Subscribers

Details

Summary

libsys, libc: provide rfork_thread() and pdrfork_thread() on all arches

posix_spawn: use rfork_thread on all arches

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.Jan 26 2026, 7:37 PM

After this lands, RFSPAWN tests can be enabled on x86 by using *fork_thread() instead of raw *rfork().

lib/libc/gen/posix_spawn.c
346 ↗(On Diff #170487)
348 ↗(On Diff #170487)
349 ↗(On Diff #170487)

I wonder why the stack cannot be allocated in the arch-specific (pd)rfork_thread().

kib marked 3 inline comments as done.Jan 27 2026, 7:12 PM
kib added inline comments.
lib/libc/gen/posix_spawn.c
349 ↗(On Diff #170487)

I do not follow, sorry. rfork_thread() is the public API, it takes explicit pointer to the stack. I implemented it for arches where it was missed. So the implementation is arch-specific but the interface is not.

Are you proposing to add yet another function, now with the arch-specific interface? I would prefer not.

kib marked an inline comment as done.

Grammar in comment.

markj added inline comments.
lib/libc/gen/posix_spawn.c
349 ↗(On Diff #170487)

Sorry, I wasn't thinking clearly. Really, I am wondering why not keep the first ifdef in this function, and just pass a NULL pointer for the stack on !x86. It seems a bit silly to do the allocation and argv traversal there.

This revision is now accepted and ready to land.Jan 27 2026, 7:27 PM
kib marked an inline comment as done.Jan 27 2026, 8:07 PM
kib added inline comments.
lib/libc/gen/posix_spawn.c
349 ↗(On Diff #170487)

Hm, so you mean that the _gen implementation for !x86 is flawed, because it does not switch to the provided stack. I agree.

But still, having it consistently provided on all arches is a right step IMO.

kib marked an inline comment as done.

Only allocate the stack on x86 for now

This revision now requires review to proceed.Jan 27 2026, 8:07 PM
lib/libc/gen/posix_spawn.c
349 ↗(On Diff #170487)

Perhaps the generic implementation should return an error if a non-NULL stack is provided then?

kib marked an inline comment as done.

Require NULL stack on _gen

markj added inline comments.
lib/libc/gen/posix_spawn.c
289 ↗(On Diff #170612)

Just declare cnt in the if (use_env_path) { ... block below?

lib/libsys/rfork_thread_gen.c
28
This revision is now accepted and ready to land.Jan 27 2026, 9:25 PM
kib marked 2 inline comments as done.

Hopefully the final touches

This revision now requires review to proceed.Jan 27 2026, 9:37 PM
This revision is now accepted and ready to land.Jan 27 2026, 10:57 PM