Making a mach server

Posted by cwright on 2019.08.17 @ 13:23

Filed under:

(This is a sort of simplified retelling of http://fdiv.net/2011/01/14/machportt-inter-process-communication with some added lore. You should probably start there.)

Much of the magic behind macOS and iOS (and all the derived xOSs - watch, appleTV, the stripped down versions in cables and touch bars and wherever else these things invariably end up) is performed with the assistance of other processes (including the kernel). Communicating between them is accomplished by various ways, but for macOS, the underlying mechanism is a client/server IPC mechanism powered by Mach, and the underlying currency is the mach port (mach_port_t). [more...]

Mirror, Mirror, or, Don't fly off the Handle

Posted by cwright on 2019.08.13 @ 09:12

Filed under:

During my time at Apple, I dealt with a lot of rather low-level systems treachery. It’s poorly documented, even internally, and asking for help has roughly even odds on getting a passive aggressive non-answer.

The cool trick for today is creating a “memory object.” A memory object is one or more physical pages that are wrapped in a mach port. With this, you can pass the port to another process, who can map the pages, creating shared memory. Or you can map the pages again in your own address space, to create a mirror, or with different permissions so you can expose read-only pages at an interface boundary while still having the pages be writable at a different address. [more...]

Example of IOSurfaceCreateMachPort and IOSurfaceLookupFromMachPort Example of IOSurfaceCreateMachPort and IOSurfaceLookupFromMachPort

Posted by jstrecker on 2011.01.27 @ 00:30

Filed under:

The IOSurface framework lets you pass a reference to an IOSurface – a kind of pixel buffer – from one process to another. Here’s an example of how to pass an IOSurface through a mach port using the functions IOSurfaceCreateMachPort and IOSurfaceLookupFromMachPort. [more...]

mach_port_t for inter-process communication mach_port_t for inter-process communication

Posted by jstrecker on 2011.01.14 @ 11:14

Filed under:

Mach ports are a way for processes to communicate in Mac OS X. (Other mechanisms for inter-process communication include distributed objects and sockets.) A mach port is an endpoint of a communication channel. If 2 processes hold endpoints to the same communication channel, then one process can send messages to the other.

Mac OS X provides wrappers around mach ports – NSMachPort and CFMachPort. But sometimes you have to drop down to the native mach_port_t API.

Don’t do this on whim. [more...]

mythical