1# Linux Sandbox IPC
2
3The Sandbox IPC system is separate from the 'main' IPC system. The sandbox IPC
4is a lower level system which deals with cases where we need to route requests
5from the bottom of the call stack up into the browser.
6
7The motivating example used to be Skia, which uses fontconfig to load
8fonts. Howvever, the OOP IPC for FontConfig was moved to using Font Service and
9the `components/services/font/public/cpp/font_loader.h` interface.
10
11These days, only the out-of-process localtime implementation as well as
12an OOP call for making a shared memory segment are using the Sandbox IPC
13file-descriptor based system. See `sandbox/linux/services/libc_interceptor.cc`.
14
15Thus we define a small IPC system which doesn't depend on anything but `base`
16and which can make synchronous requests to the browser process.
17
18The [zygote](zygote.md) starts with a `UNIX DGRAM` socket installed in a
19well known file descriptor slot (currently 4). Requests can be written to this
20socket which are then processed on a special "sandbox IPC" process. Requests
21have a magic `int` at the beginning giving the type of the request.
22
23All renderers share the same socket, so replies are delivered via a reply
24channel which is passed as part of the request. So the flow looks like:
25
261.  The renderer creates a `UNIX DGRAM` socketpair.
271.  The renderer writes a request to file descriptor 4 with an `SCM_RIGHTS`
28    control message containing one end of the fresh socket pair.
291.  The renderer blocks reading from the other end of the fresh socketpair.
301.  A special "sandbox IPC" process receives the request, processes it and
31    writes the reply to the end of the socketpair contained in the request.
321.  The renderer wakes up and continues.
33
34The browser side of the processing occurs in
35`chrome/browser/renderer_host/render_sandbox_host_linux.cc`. The renderer ends
36could occur anywhere, but the browser side has to know about all the possible
37requests so that should be a good starting point.
38
39Here is a (possibly incomplete) list of endpoints in the renderer:
40
41### localtime
42
43`content/browser/sandbox_ipc_linux.h` defines HandleLocalTime which is
44implemented in `sandbox/linux/services/libc_interceptor.cc`.
45
46### Creating a shared memory segment
47
48`content/browser/sandbox_ipc_linux.h` defines HandleMakeSharedMemorySegment
49which is implemented in `content/browser/sandbox_ipc_linux.cc`.
50