Answer NVN getters asked of no object with 0, and map a buffer with no pool to memory of its own.

The game's scene-loading thread makes a few NVN calls with a null object while an area loads or Kakariko's time of day
changes: a memory pool's flags (and the other pool getters), a texture builder's storage size or alignment, and the
mapping of a buffer that has no pool, into which it then writes 0x3d0 bytes. Each read the object at address 0 plus a
field's offset, an access violation. The pool getters, nvnMemoryPoolInvalidateMappedRange and the two builder queries
now answer 0 for a null object (nvn_no_object), and nvnBufferMap of a buffer with no pool returns a block of scratch
memory (64 KiB, or the buffer's size when it records a larger one) instead of 0. The first such calls are logged with
their caller. These fit the crash reports in Castle Town and in Kakariko before Death Mountain (#605, #602), which have
not been confirmed to be this.

Checked: --probe-nvn gains three checks (pool getters of no pool, builder queries of no builder, a 0x3d0-byte write
through the mapping of a buffer with no pool) and they pass; its four other failures are the same on the baseline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-11 17:05:39 -05:00
parent e8b4d29f91
commit b5c9a9b38e
5 changed files with 72 additions and 5 deletions

View File

@@ -22,6 +22,11 @@ void nvn_called(uint8_t *seen, const char *name); // the counting prolo
// A wait for the GPU, the display or another thread gives the virtual core up until the end of the enclosing scope.
#define NVN_BLOCKING() __attribute__((cleanup(kern_core_back))) int nvn_away_ = kern_core_away()
static inline int nvn_arg_bool(const Cpu *c, int i) { return (int)(arg_x(c, i) & 0xff); } // NVNboolean: low 8 bits only
// 1 when argument 0, the object of a getter, is NULL: the call is answered with 0 instead of reading the object at
// address 0 plus a field's offset. The game's scene-loading thread makes a few such calls while an area or Kakariko's
// time of day changes (a memory pool's flags, a texture builder's storage size). The first calls are logged with
// their caller (nvn_api_core.c).
int nvn_no_object(Cpu *c, const char *what);
#define NVN_POOL_MAGIC MAGIC('P', 'O', 'O', 'L') // pool_t.magic of an initialized pool
#define NVN_VPOOL_PAGE 0x10000ull // NVN virtual mapping granularity (64 KiB)