There are too many IPC methods and not nearly enough documentation in iOS,
especially at lower-level interfaces. How is one to check and audit security
if the basic hello world app using the C API is impossible to find! Now you
might say doesn't apple provide useful documentation on the man pages
and at developer.apple[1]. And you'd be half right while the man page does
have a ton of information explaining how XPC works but it has well-formed working
examples to build and run. The same is true of the developer.apple page it's
kinda sad because these API are very interesting to work with. Thus let's
build a basic XPC server and client and learn a little more about how XPC is
works.
All the code here is on Github
at https://github.com/lquinn2015/xpcCDemo. and was generated with mostly with the help of a discord person named capt. Skip the explanation of everything else and skip to the code if you
just want something working now
Whats IPC?
First, we need a little background on what IPCis and why it is the way it is. Thus let's take a slide from Ian Beer presentation on IPC on iOS[2]
IPC or Interprocess communication is a Zoo. This is quite literally as who
makes over 7 different interfaces for IPC. Well, Apple did because kernel
design despite feeling monolithic is an iterative process. And so API's can
and should be extended to make achieving certain things easier and faster.
IPC is all about sending messages between 2 processes. After all, the whole
idea of having an operating system is to write a bunch of processes each
accomplishing a unique goal to get work done. What we want to send should be
abstract as each process's or task's needs will differ. And the first thing
to start with is Mach Messages. These are the primitives on which most
of iOS is built. It's very labored to explain them and they can be very
error-prone to use however they are the most powerful IPC method in iOS
because they are used to implement all other methods of IPC. However just because they are
powerful doesn't make them usable, having a heavy sword is much harder to
wield thus Apple has several other methods built on top of them. However,
understanding how they function a little will shape our understanding of how
anything built on top of them must work. Also from an operating systems perspective, they are really cool, and in my opinion the style of the XNU in general scales better to multicore systems which are the future.
Brief Mach Messages
Let's finally look at some code just some structure definitions