Skip to content

posix_spawn + Mach extensions #519

Closed
@willglynn

Description

@willglynn

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:

  1. Adding Mach bindings to libc, which is perhaps also in scope considering Mach mach_port_allocate() is literally a syscall just like BSD pipe(), but which is not a small project, or
  2. Not adding Mach bindings to libc, which leaves the posix_spawn() family only partially-baked, and in particular means there's no useful way to call posix_spawnattr_setexceptionports_np() without additional bindings outside libc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions