But what If I know the mach port?
Mach is a capability-based system (as defined here). You can only work with ports that you’ve been granted access to via the system. That’s why the bootstrap service is so important.
I touch on this in XPC and App-to-App Communication, and you should read that first. However, I want to expand on it a little here.
When you work with Mach ports in user space, you typically use a value of type mach_port_t
. However, this is not a Mach port. Mach ports exist within the kernel and you don’t have direct access to them. Rather, you work with a Mach port name [1]. That’s an integer that denotes an entry in your task’s Mach port namespace. That namespace is managed by the kernel. The Mach port names are pretty much equivalent to a traditional Unix file descriptor.
Within the kernel, each Mach port namespace entry points to a Mach port and tracks the rights that the task’s Mach port name holds for that port.
So, you can’t access a Mach port by ‘guessing’ its port name, in the same way you can’t access a random file by ‘guessing’ a file descriptor. For you to have access to the port the kernel must have inserted an entry for that port into your task’s Mach port namespace. Which is exactly what the bootstrap service does when you successfully look up a name.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Some APIs actually use the mach_port_name_t
type alias, but that’s not consistent. Mach is a very confusing API for historical reasons. I can only assume that the original authors didn’t understand how vital a glossary is when describing your API (-: