The generated code lays a command out as the SDK's service framework does (Atmosphère's
sf_impl_command_serialization.hpp and libnx's cmif.h describe the same layout; Atmosphère is GPL-2.0-only and
only read):
(u32 a, u64 b, u8 c) puts c at 0, a at 4 and b at 8. The outputs are placed the same way, and the reply's raw size
is rounded up to 4. A few commands are laid out in declaration order instead, as the SDK's own client code shows
(fsp-srv's CreateSaveDataFileSystem and CreateSaveDataFileSystemWithHashSalt): those are marked @unsorted. The
game's SDK names each command's layout in its client templates (InRawArgumentInfo<size, alignment, offset>), which
is where to check a declaration.ptrbuf (nsd's is 0, as
the console's is).respond in ipc.c).ipc.c closes and drops a failed request's (drop_outputs) once the dispatcher has
returned, outside any lock a service's own dispatcher holds.ipc.c does as it does (Mesosphere): a header that
describes more than the client's message buffer, its receive list included, or a receive list inside the raw data
(InvalidCombination, which the console finds at the reply, after the descriptors); raw data that ends past the
server's 0x100 bytes (MessageTooLarge); a move handle, which a client can't send a server (InvalidCombination); a
buffer outside the address space (InvalidCurrentMemory). A SendSyncRequestWithUserBuffer's own buffer has to be
page-aligned (InvalidAddress), whole pages (InvalidSize), and memory that allows IPC user buffers, read-write with no
attribute, with one state and permission across the range (InvalidCurrentMemory): ipc_user_buffer.pid or aruid, as many A, B and X
descriptors (an AutoSelect buffer counts in both of its lists, and X descriptors past them must be empty: the
console takes the empty half of a libnx AutoSelect buffer beside the mapped one a command declares), no exchange (W)
buffer, as many copy handles, and at least the command's raw data. Otherwise it is answered with sf's InvalidCmifRequest, RC(11, 420), before the handler
runs, and logged as [bad request] (ipc_counts and ipc_bad_request), as Atmosphère's HipcCommandProcessor checks
it. C descriptors aren't counted. A domain request with another number of objects is answered InvalidInObjectCount
(ipc_objects), checked before the rest as sf's DomainServiceObjectProcessor does, and a command that takes objects
answers NotSupported on a plain session, which can't send them. A TIPC request (sm, from newer SDKs) carries its pid
in the special header only, so its raw data has no pid slot, and the generated code reads its arguments where TIPC
puts them. sm's RegisterService and UnregisterService also take the Switch 2 TIPC forms, which carry a service
space before the name (RegisterService is 20 bytes then, with max_sessions before is_light, where CMIF has
is_light first; without a space they are 16 and 8 bytes). sm.c's own dispatcher reads those two commands, and
the runtime serves one service space, so the space is logged and otherwise ignored, as the SM proxy of the public CFW
does. A request whose data region doesn't hold its CmifInHeader (or domain header) is answered InvalidHeaderSize,
and one without the SFCI magic or with a version above 1 InvalidInHeader. So a declaration that differs from what the
game's SDK sends fails every such request. One difference from the console, on purpose: sf closes the session for
these refusals (the client's SendSyncRequest gets SessionClosed), while the runtime answers the result in a reply and
keeps the session. Its own declarations can be wrong where the console's aren't, and a game may survive an error
result but not a dead session.Made from docs/platforms/nx/ipc.md at 69237645142c. GPL-3.0-or-later.