Skip to content

An input stream that never opened answers every call: Ocarina of Time no longer crashes at the first note of the ocarina - #1527

Closed
lunks wants to merge 1 commit into
seedds:mainfrom
lunks:fix/input-stream-never-opened
Closed

lunks wants to merge 1 commit into
seedds:mainfrom
lunks:fix/input-stream-never-opened

Conversation

@lunks

@lunks lunks commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #1525.

What and why

The host fails every OpenInputStream (no microphone) and hooks StartInputStream, StopInputStream, CloseInputStream, ReadInputStream, the filled frame count and the format. The other input stream calls still ran the SDK's own code on the stream's Impl pointer, which is null for a stream that never opened.

Ocarina of Time (0400486024DEC000, v131072) purges its two microphone streams when they are not started. #1525 crashes on the first note at the closed Door of Time (three runs, rumble off in the third):

CRASH sig=11 addr=0x340 pc=sdk+0x1f7050 lr=main+0x336ee80

main+0x336ee7c is a call through the import stub at main+0x3c42250, whose relocation (GOT 0x4cbf2f0, read from main.elf) is _ZN2nn5audio16PurgeInputStreamEPNS0_15InputStreamTypeE. The SDK function at sdk+0x1f7040 starts with ldr x1, [x0, #0x340], and x0 is the null Impl pointer.

This adds hooks for the calls that go to the Impl pointer (the same list our own tree has carried since Star Fox): GetInputStreamState (closed), PurgeInputStream (nothing), GetInputStreamStatistics (zero, returned by value through x8 like the output stream's), GetInputStreamFreeFrameCount and GetInputStreamCapacityFrameCount (0), GetInputStreamGain (1) and SetInputStreamGain (nothing to ramp).

Checked

  • Tests: make -C dm/host GAME=0400486024DEC000 dmhost builds. Each new symbol is defined once in dm/host (no duplicate hook).
  • Games run: none on main. I did not play Ocarina of Time with this change on main. The first note is what starts the microphone path, so it needs the ocarina played at a door, and the reasoning above comes from the binary and the relocation. Our own tree carries the same hooks for these calls; I have no run of it with a note played.
  • Devices and OS: M5 Pro, macOS 27.
  • regress.py not run: the hooks answer only for a stream that never opened.

Docs

  • No finding for a reference entry: a missing hook, the symptom is in [deleted] #1525
  • No chain tool changed
  • No game files, keys or data extracted from a game in the change or the attachments

… no longer crashes at the first note of the ocarina (GetInputStreamState, PurgeInputStream and the statistics, counts and gain calls)

The host fails every OpenInputStream (no microphone), and hooks Start, Stop, Close, Read, the filled count and the format. The other input stream calls ran the SDK's code on the stream's Impl pointer, which is null for a stream that never opened: Ocarina of Time purges its two microphone streams when they are not started (main+0x336ee7c, PurgeInputStream), and the SDK function at sdk+0x1f7040 reads [Impl+0x340] first: SIGSEGV at address 0x340, pc=sdk+0x1f7050, lr=main+0x336ee80, on a guest thread (issue seedds#1525, three runs).

GetInputStreamState answers closed, PurgeInputStream does nothing, the statistics are zero (returned by value through x8 as for the output stream's), the free and capacity counts are 0 and the gain is 1; SetInputStreamGain ramps nothing.
@lunks lunks mentioned this pull request Nov 6, 2026
@github-actions github-actions Bot added the host The Horizon host: SVCs, services, threads, memory (dm/host) label Nov 6, 2026
seedds added a commit that referenced this pull request Nov 6, 2026
… no longer crashes at the first note of the ocarina (PR #1527, issue #1525)

- The host fails every OpenInputStream (no microphone) and answered start, stop, close, read, the filled count and the format; purge, the statistics, the free and capacity counts and the gain still ran the SDK's code on the stream's null Impl pointer. Ocarina of Time purges its two microphone streams whenever they are not started (main+0x336ee7c), without checking its own opened flag, which only a successful open sets (main+0xf481cc); PurgeInputStream tail-calls InputStreamImpl::Purge, which reads [Impl+0x340] (sdk+0x1f7050, the crash in #1525).
- Now the state is closed, a purge does nothing, the statistics are 24 zero bytes (as InputStreamImpl::GetStatistics zeroes its result first), the counts are 0 and the gain is 1.
- Host builds; not run in game (needs the ocarina played at a door). Regression run skipped: the hooks answer only calls that faulted on a null Impl, and the state, which the SDK already answered closed.

Co-authored-by: lunks <91118+lunks@users.noreply.github.com>
@seedds

seedds commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Landed on main as 46404e8, unchanged, with you credited as co-author. I checked the reading against Ocarina's binaries: PurgeInputStream (sdk+0x1f6060) tail-calls InputStreamImpl::Purge on the null Impl, and the game's purge at main+0x336ee10 checks the stream state but not its own opened flag (+0x53a0, set only by a successful open at main+0xf481cc). The statistics hook's 24 zero bytes match what InputStreamImpl::GetStatistics writes. It is not run in game yet, so #1525 stays open for the reporter's run at the Door of Time.

@seedds seedds closed this Nov 6, 2026
Aeonitis pushed a commit to Aeonitis/nxnative that referenced this pull request Nov 7, 2026
…ixes (chain 844bf1a5ea8f, exactly upstream's), raw pool table words at commit (seedds#1427), incremental pool tables (seedds#1489), ocarina input stream (seedds#1527), damaged .zs check (seedds#1530)

Conflicts: chain tools and shader_split.py taken from upstream (dmsh_depth.py dropped: upstream compiles the 259-bracket shaders its own way); the build script keeps shader.noindex and takes upstream's progress watch; docs keep both packing entries.
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
… no longer crashes at the first note of the ocarina (PR seedds#1527, issue seedds#1525)

- The host fails every OpenInputStream (no microphone) and answered start, stop, close, read, the filled count and the format; purge, the statistics, the free and capacity counts and the gain still ran the SDK's code on the stream's null Impl pointer. Ocarina of Time purges its two microphone streams whenever they are not started (main+0x336ee7c), without checking its own opened flag, which only a successful open sets (main+0xf481cc); PurgeInputStream tail-calls InputStreamImpl::Purge, which reads [Impl+0x340] (sdk+0x1f7050, the crash in seedds#1525).
- Now the state is closed, a purge does nothing, the statistics are 24 zero bytes (as InputStreamImpl::GetStatistics zeroes its result first), the counts are 0 and the gain is 1.
- Host builds; not run in game (needs the ocarina played at a door). Regression run skipped: the hooks answer only calls that faulted on a null Impl, and the state, which the SDK already answered closed.

Co-authored-by: lunks <91118+lunks@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

host The Horizon host: SVCs, services, threads, memory (dm/host)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[deleted]

2 participants