nvn: answer memory-pool calls made with no pool #510
No reviewers
Labels
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
No milestone
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!510
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/nvn-null-pool"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #509. Related tracking issue: #287.
What the crash was
While Kakariko Village changed from day to night, the
OptimizeChangeBancthread callednvnMemoryPoolGetFlags(NULL). The HLE getter readflagsatA64_MEM + 4(guest0x4) and took an access violation:hookshot.exe+0x1a53b5ddisn_nvnMemoryPoolGetFlags+0xd. The guest caller is the texture-building helperf_80905130: it passes the pool pointer[x21]to the storage setter and tonvnTextureInitialize(which already handles a null pool), then asks the same[x21] = 0for its flags. This is a texture with no storage pool being prepared during the banc change.P(0)returnsNULLfor a zero argument, but((nvn_pool *)NULL)->flagsis undefined behaviour, so the compiler is free to fold the check away — and did, readingA64_MEM + 4. A guard has to come before the dereference.Changes
no_pool(), followingno_builder()from #284/#287.nvnMemoryPoolGetFlags/GetSize/GetBufferAddressreturn0nvnMemoryPoolMapreturns0nvnMemoryPoolInvalidateMappedRange,Finalize,MapVirtualdo nothingno_builder.tests/test_nvn_null_pool.py, a game-free regression test that extracts the actual getter bodies fromhost/nvn_native.c, compiles them at-O2, and calls them with a null pool and with a real pool.Verification
Against the pre-fix source, the fixture crashes with
0xC0000005:Against this branch:
Also added the test to the Linux source-regressions workflow. A full game build was not run; the change is host-side and game-free tested.
Note
This is the same family as #284/#287: a null NVN object was dereferenced during a scene/banc change. The
no_builderfix covered the texture-builder queries; this covers the memory-pool calls.CI note: the Ubuntu job's existing "Check import windows" step fails on
prefetch_chunks/Pool::prefetched. That is pre-existing onmain—nx2/test_import_windows.pyhas not been updated for the AMD prefetch code ingpu/vk/vk_memory.cpp— and is unrelated to this PR. The new "Check a null NVN memory pool is answered, not dereferenced" step passed, as did every step before the import-windows one.The failing step is the Ubuntu job's existing
Check import windowsstep (nx2/test_import_windows.py), not the new NVN regression test. It fails while compiling the generated C++ fixture:nx2/test_import_windows.pyextractspool_lookup/pool_of/import_poolfromgpu/vk/vk_memory.cppand compiles them against a small hand-written fixture. The fixture'sstruct Pooland stubs have not been updated for the import-prefetch code added inf174cfc:gpu/vk/vk_memory.cpp:55—bool prefetched = false;inPoolgpu/vk/vk_memory.cpp:1246—st_prefetch_sent,st_prefetch_used,st_prefetch_droppedgpu/vk/vk_memory.cpp:1319—prefetch_chunks(...)gpu/vk/vk_memory.cpp:1469-1476—pool_lookupuses all of themThis is pre-existing and unrelated to this PR:
origin/main(cdb4f1a) fails the same test with the same errors.git log -S"prefetch_chunks" -- nx2/test_import_windows.pyis empty — the test was never updated forf174cfc.mainalready has failing source-regressions runs at the same step: 42450422930 and 42454098719.This PR only changes
host/nvn_native.c,tests/test_nvn_null_pool.pyand.github/workflows/source-regressions.yml; it does not touchgpu/vk/vk_memory.cppornx2/test_import_windows.py. The newCheck a null NVN memory pool is answered, not dereferencedstep passed, and the Windows job passed.The fixture can be unblocked separately by adding
bool prefetched=false;to itsPool, declaring the three counters, and stubbingprefetch_chunks. I have left that out of this PR to keep it to one topic; I can send it as a separate PR.