From 507e27da91e4d75512481ea718c7abb91c96ab8d Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Wed, 11 Nov 2026 15:26:26 +0300 Subject: [PATCH] Treat an invalid optional reference at object +0x6b0 as absent on 1.4.3, so the random crash in main+0x1bd0138 stops (#1005) The game checks the reference only for null, and players' crash dumps show it holding 0xffffffffffffffff after minutes to hours of play. MacNativeGames met the same field holding 0xffff0000ffffffff during a save load. Set optref (TOTK_OPTREF_GUARD, on by default) turns the cbz into a test for null or negative; valid holders are heap addresses below 2^63. Co-Authored-By: Claude Opus 5.5 --- docs/agents/symptoms.md | 1 + recomp/patches-v143.txt | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/docs/agents/symptoms.md b/docs/agents/symptoms.md index 55a2aca0..c654c712 100644 --- a/docs/agents/symptoms.md +++ b/docs/agents/symptoms.md @@ -49,6 +49,7 @@ GPU semantics behind the graphics rows: [maxwell.md](../maxwell.md). The method | a host core at 100% while the game waits | game spin loops without system calls | profile: which guest function spins | | crash on world load | sizes the game reads from the driver (command memory used) differ from the console's | the sizes the game asks for against the console's | | crash with one save only | the save itself; some crash on a real Switch | the same save on another build and, if possible, on hardware | +| random crash after minutes to hours, access violation reading `0xffffffffffffffff` in a game function | an invalid value (-1, `0xffff0000ffffffff`) in an optional reference the game checks only for null; set `optref` in `recomp/patches-v143.txt` guards main+0x1bd0138 | the crash dump's faulting host instruction, the register it loads through and the field that register came from | ## Device lost, hangs, black window diff --git a/recomp/patches-v143.txt b/recomp/patches-v143.txt index 07ef3af9..c67f95ae 100644 --- a/recomp/patches-v143.txt +++ b/recomp/patches-v143.txt @@ -1116,3 +1116,15 @@ site grass main a38e94 52802002 @page:x2 b9408842 # mov w2, #0x100 -> ldr site grass main a38ef4 52801002 @page:x2 b9408c42 # mov w2, #0x80 -> ldr w2, [page+140] site grass main 2063454 52a84f48 @page:x8 b9408108 # mov w8, #62.5 -> ldr w8, [page+128] site grass main 2063460 52a83f48 @page:x8 b9409108 # mov w8, #31.25 -> ldr w8, [page+144] + + +# Optional reference with an invalid value (#1005). main+0x1bd0138 reads an optional reference at object +0x6b0 (null or +# a holder whose first word is the target, bit 0 a tag) and checks it only for null: ldr x8, [x19, #0x6b0]; cbz x8; +# ldr x21, [x8]. Players' crash reports show the field holding 0xffffffffffffffff after minutes to hours of play, and +# the load of the holder faults. MacNativeGames (games/totk/runtime/loader.c, crash) met the same field holding +# 0xffff0000ffffffff during a save load and treats the reference as absent there. Every valid holder is a heap address +# below 2^63, so the cbz becomes a test for null or negative: x9 = x8 >> 63 (arithmetic, all ones when negative), +# x8 &= ~x9, cbz x8. Both x8 and x9 are dead at the branch target 0x1bd01f0, which loads x8 again and writes x9 before +# any read; on the fall-through path x8 is unchanged. +set optref TOTK_OPTREF_GUARD 1 +site optref main 1bd01c0 b4000188 937ffd09 8a290108 b4000188 # cbz x8 -> asr x9, x8, #63; bic x8, x8, x9; cbz x8