Description
I have a project that wants posix_spawn()
support. That's a POSIX API (as the name implies) which seems like it's in scope for the libc
crate, and adding it seems pretty straightforward.
I specifically want this API for posix_spawnattr_setexceptionports_np()
. This is an Apple extension to posix_spawn()
which to would therefore also seem in scope for libc
, but this is where the slope gets very slippery, and that's why I'm opening an issue instead of going straight to a PR.
See, this call is really just a posix_spawn()
ified version of the Mach task_set_exception_ports()
function. This means adding it would instantly would instantly drag in a bunch of Mach stuff: types and constants for exception_mask_t
, exception_behavior_t
, and thread_state_flavor_t
, plus mach_port_t
itself. It also prompts a choice between:
- Adding Mach bindings to
libc
, which is perhaps also in scope considering Machmach_port_allocate()
is literally a syscall just like BSDpipe()
, but which is not a small project, or - Not adding Mach bindings to
libc
, which leaves theposix_spawn()
family only partially-baked, and in particular means there's no useful way to callposix_spawnattr_setexceptionports_np()
without additional bindings outsidelibc
Both of these options seem terrible. What's worse: the alternative to this unholy union of the Mach + BSD subsystems is to use both subsystems independently, which requires either clobbering the parent process/task's exception ports (which is racy) or passing ports indirectly via NSMachBootstrapServer
(which requires Objective-C). posix_spawnattr_setexceptionports_np()
really is the best way to spawn a child process with exception ports of the parent's choosing.
So: how do we feel about adding posix_spawn()
? What about posix_spawnattr_setexceptionports_np()
? What about #include <mach/mach.h>
?