Declaring a hook

Hooks are declared in src/nx/nn/hooks.hook, one per line, each under the family line before it:

family libc
hook memcpy(void* dst, const void* src, u64 size) -> void* = hook_memmove

Function types

With an include line, the generated header also includes that header, and gives each hooked function its type as the guest calls it, PFN<SYMBOL in capitals>PROC:

hook nvnTextureWriteTexelsStrided(const NVNtexture* t, const NVNtextureView* v, const NVNcopyRegion* region, const void* src, i64 row, i64 image)
typedef void (*PFNNVNTEXTUREWRITETEXELSSTRIDEDPROC)(const NVNtexture* t, const NVNtextureView* v, const NVNcopyRegion* region, const void* src, int64_t row, int64_t image);

gpu/nvn/nvn.hook is thus the one prototype of each NVN function the runtime implements: nvn.h keeps only the types of the callbacks and the resolvers, which no hook declares, and tools/nvn_hash.py reads the prototypes from nvn.hook (tools/hook_spec.py). Each type has the guest's size, whatever the host:

Nothing calls through these types: a guest function runs at a guest address, through its dispatch slot. All the declarations of one symbol take the same types, as it has one function type. tests/nvn_header.c checks some of them against prototypes in NVN's own types, with -pedantic-errors.

tools/hookgen generates the adapters (a GuestFn that unpacks the registers, calls the handler, puts the result in x0 or v0 and returns to x30) and the table sorted by symbol. tests/hook_adapters.c checks the register mapping, and the hookgen_refuses_* tests the declarations it refuses.

The Vita's system functions are declared in the same language, by NID ([0x99ba173e] hook sceIoLseek(...)), and hookgen --vita generates their adapters and table: The system's functions by NID.


Made from docs/platforms/nx/hooks.md at 69237645142c. GPL-3.0-or-later.