machportsrs

Crates.io

Summary

Mach ports are a powerful IPC mechanism used for most of the low-level communications between processes and kernel on Darwin. I/O Kit, largely the only way to communicate with kernel drivers on these platforms, and XPC, the most widespread userspace IPC mechanism, are both built using the Mach ports. Exposing low-level APIs on these systems in a safe way requires abstractions mach_ports_rs library aims to provide.

Mach port name wrappers

Mach ports are represented by handles called "names" in userspace. Unlike file descriptors, these refer to one or multiple "rights" on a port:

While send and receive rights, for example, are referenced by the same name inside the same process (IPC space) the reference counts for the rights are managed separately. mach_ports_rs makes this distinction on the type level by providing 3 wrappers for Mach port names (there is no need to represent dead names separately):

Sending/Receiving Mach messages

Mach message format is quite non-trivial. All Mach messages start with a fixed-size header followed by optional descriptors, inline data and a trailer that is only present in received messages.

Complex Mach message format diagram

mach_ports_rs provides data structures that can be used to build and parse such messages. See docs for the msg module for more info.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.