A result is a 32-bit value: 0 for success, otherwise a module in bits 0 to 8 and a description from bit 9,
RC(module, description) (RC(1, 123) is the kernel's SessionClosed, 0xF601), which the console shows as 2000 + the
module, then the description: 2001-0123.
Every result the runtime answers is a row of hle/result_codes.inc, once, whichever services answer it:
SNX_RESULT(ACCOUNT, MEMBERSHIP_REQUIRED, 5113, MembershipRequired, SWITCHBREW) is the constant
SNX_RC_ACCOUNT_MEMBERSHIP_REQUIRED, 2124-5113. The module goes by its name in Switchbrew's Error codes
(SNX_RESULT_MODULE(ACCOUNT, 124)), the result by the name public sources give it, spelled as they spell it, with
the first source that names it: Switchbrew, then Ryubing's ResultNames.cs, the service's ResultCode.cs in
Ryubing, Eden; NONE marks a name of ours, for a result no public source has. A result a service needs that has no
row gets one there, never a #define or an RC(...) of its own. snx_result_info(rc) gives a result's row, its
name and source, and snx_result_text writes it as the console shows it with its name, "2124-5113
MembershipRequired", for a log line or the error applet. tests/result_codes.c (ctest -R result_codes) checks each
row is there once and named by the rule, and the lookup; tests/result_codes.py (result_codes_sources) refuses an
RC(...) outside result.h and, in hle/, a result written as a number.
hle/result.h, which ipc.h includes, holds RC, RC_OK, the table's constants and helpers in the style of
Atmosphère's, written anew in ISO C:
| Macro | What it does |
|---|---|
R_SUCCEEDED(rc), R_FAILED(rc) | whether rc is 0, or not |
R_SUCCEED() | returns success |
R_THROW(rc) | returns rc |
R_UNLESS(cond, rc) | returns rc when cond is false, evaluating rc only then |
R_TRY(expr) | evaluates expr once and returns its result when it isn't 0 |
Each statement macro is a single statement (do { } while (0)), so it is safe as the body of an if or else
without braces, and evaluates each argument at most once. R_TRY keeps the result in a 32-bit unsigned int in a
block of its own, which converts back to the function's return type, int for a handler or u32 for the kernel's
svc_ functions. The header includes only <stddef.h> and the table, so strict ISO C code can use it. tests/result_macros.c
(ctest -R result_macros) builds them with -std=c23 -pedantic-errors.
Made from docs/platforms/nx/ipc.md at 69237645142c. GPL-3.0-or-later.