For hle/services/acc.swipc the build writes hle/services/acc.swipc.h and acc.swipc.inc under
build/<preset>/src/nx/snx_hle-swipc/, from the list in src/nx/CMakeLists.txt (snx_swipc in
cmake/swipc.cmake). For each interface I (its name with :: as _) the header has the types, with their padding
spelled out and their size and field offsets checked by the compiler, and what other files use:
int nn_account_IAccountServiceForApplication_dispatch(SvcObj* self, IpcCtx* c);
#define nn_account_IAccountServiceForApplication_register(ctor) ... /* when it has service names */
The .inc is included by the C file that defines the handlers, and by no other. It declares the handlers static and
defines the dispatchers, so each handler is compiled with its only caller:
static int nn_account_IAccountServiceForApplication_GetProfile(SvcObj* self, const nn_account_Uid* uid,
SvcObj** profile);
#define nn_account_IAccountServiceForApplication_new(data_size) svcobj_new("nn::account::IAccountServiceForApplication", ...)
int nn_account_IAccountServiceForApplication_dispatch(SvcObj* self, IpcCtx* c) { ... }
The service's C file defines one static handler per command that isn't a @stub, and its own @fallback function
if it has one. The compiler checks each definition against its prototype, and a missing handler is an error. A
handler gets the object, then the arguments in declaration order, then a pointer for each output, which starts
zeroed:
| Argument | Input | Output |
|---|---|---|
| scalar | the value | T* |
pid, aruid | the value (u64) | |
| struct, named bytes or array | const T* | T* |
bytes<N>, T[N] written in place | const T* to the first element | T* |
| buffer | IpcBuf (address, size; empty when the client sent none) | |
| object | SvcObj*, NULL when the client sent none: a reference the handler takes its own of to keep it | SvcObj**, a new object |
| handle | the client's handle value, 0 when it sent none | u32*, a handle for the reply |
The message is little-endian, as the guest is, whatever the host's byte order. A handler's raw arguments and outputs
are host numbers: the generated code converts each scalar after it reads it from the request and before it writes it
into the reply, and a struct field by field, with a function the header defines for each struct that has words in it
(swipc_le_<Type>(void* p), the type's name with :: as _, nested structs and arrays included). bytes<N>, u8 and b8 need nothing.
The process id, the handles and the domain object ids are host numbers too, as ipc.c reads the headers and writes
the reply through converting accessors. What a buffer holds stays in the guest's byte order: the handler reads and
writes its numbers with snx_ld_le32, snx_st_le32 and their kin (common/utilities/endian.h), or gr32 and
gw32 for a guest address. So does code that reads the request by hand (ipc_in, c->raw) or writes the reply
(c->out) in a @fallback or a dispatcher of its own, while out32 takes a host number. On a little-endian host
every conversion compiles to nothing.
It returns the result: 0, or one of hle/result_codes.inc (Results, below). I_new makes an object whose dispatcher is the generated
one. An object that needs a lock around every command, or a check before each one, has a dispatcher of its own that
calls I_dispatch: fs.c's file_disp, dir_disp and fs_disp, ldr.c's ro_dispatch. I_register registers a
constructor under the interface's service names, in services.c or in the service's own init (fs, nvdrv, hid, vi,
pl). Names that need constructors of their own register by hand: ldr:ro and ro:1 are one interface with two kinds of
session, and bsd:u, bsd:a and bsd:s share one interface with bsd:s the system's.
The generator is strict ISO C23 with no dependencies, so a cross build also builds it for the machine doing the build
(cmake/swipc.cmake, with that machine's compiler, SNX_HOST_CC). Its output is ISO C23 as well. The tests
(ctest -R swipc in build/default): tests/swipc_dispatch.c drives the dispatchers generated from
tests/swipc/test.swipc and other.swipc through the layout rules and the byte order of every raw argument, against
stand-ins for what ipc.c gives them.
The same output is compiled with -std=c23 -pedantic-errors against an ISO C stand-in for ipc.h
(tests/swipc/iso/). tests/swipc/bad/ holds definitions the generator has to
refuse, each with its line and message. What ipc.c itself does with a reply (the order of out objects among the move
handles, domain ids, a NULL object) is not covered by these tests, nor by the services' own, which give the
dispatchers stand-ins too: only the homebrew smoke test (nx_runtime_homebrew, with SNX_TEST_VULKAN) and the games go
through it.
Made from docs/platforms/nx/ipc.md at 69237645142c. GPL-3.0-or-later.