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

@@ -106,6 +106,21 @@ static void probe_device_and_pools(void) {
CHECK(nvn_pool_find(U(pmem) + 0x100, 0x200) == P() && !nvn_pool_find(U(pmem) + PROBE_POOL_SIZE - 8, 16), "pool index");
n_objects += 6;
// getters asked of no object answer 0 instead of reading address 0 (nvn_no_object); a buffer with no pool maps to
// writable memory of its own, not to 0
CHECK(CALL(nvnMemoryPoolGetFlags, 0) == 0 && CALL(nvnMemoryPoolGetSize, 0) == 0 && CALL(nvnMemoryPoolMap, 0) == 0 &&
CALL(nvnMemoryPoolGetBufferAddress, 0) == 0, "pool getters of no pool");
CALL(nvnMemoryPoolInvalidateMappedRange, 0, 0, 0x100);
CHECK(CALL(nvnTextureBuilderGetStorageSize, 0) == 0 && CALL(nvnTextureBuilderGetStorageAlignment, 0) == 0,
"storage size and alignment of no texture builder");
{
static NVNbuffer nopool; // zeroed, as a buffer whose initialization failed
uint8_t *m = (uint8_t *)(uintptr_t)CALL(nvnBufferMap, U(&nopool));
int ok = m != NULL;
if (ok) memset(m, 0xab, 0x3d0), ok = m[0x3cf] == 0xab;
CHECK(ok, "a buffer with no pool maps to writable memory");
}
// refused: no storage, PHYSICAL | VIRTUAL, a size that is not a 64 KiB multiple
static NVNmemoryPool bad;
CHECK(make_pool(&bad, NULL, 0x10000, NVN_MEMORY_POOL_FLAGS_CPU_CACHED) == 0, "a pool without storage is refused");