Skip to content

fix(libSceNgs2.native): write the voice state through guest copies in sceNgs2VoiceGetState - #20941

Merged
oneandonlydean merged 10 commits into
boykopovar:mainfrom
MarcZX10:fix/libsceNgs2-voice-state-guest-copy
Nov 15, 2026
Merged

oneandonlydean merged 10 commits into
boykopovar:mainfrom
MarcZX10:fix/libsceNgs2-voice-state-guest-copy

Conversation

@MarcZX10

Copy link
Copy Markdown
Contributor

What

sceNgs2VoiceGetState built the voice state directly in the guest output, through the caller's pointer, for each rack type. An unmapped output faulted the host part way through the write.

For each rack type (sampler, reverb, submixer, custom mastering and custom sampler), the state is now built in a local struct and written once with WriteGuest or WriteGuestBytes.

  • Sampler: the common part is written for the PS4 common-only size, the whole Ngs2SamplerVoiceState otherwise, as before.
  • Custom sampler: a pending play reports only the in-use flag; an idle voice without a render reports its flags with no decoded count; everything else reports the decoded count, as before.
  • Reverb, submixer and custom mastering: the same fields as before, written at once.
  • An unwritable output returns SCE_NGS2_ERROR_INVALID_OUT_ADDRESS, the code the rest of this function already uses for outputs. Writable output receives the same bytes as before.

Commits: one fix and one test per rack type, ten in total. Each fix and each test builds and passes on its own. The tests are added to the existing voice-handle, filter and custom-rack test files.

No external source is needed: the change only copies the state, and the error code is the one this function already returns for its other outputs.

Tested

Host: Linux, kernel 6.1, x86_64. Throwaway archive build of the tree, with the CPU startup gate patched in that build only (no change to HostCpu.cpp in this branch).

  • At the final head 3a826f1fcf, on upstream/main c53d8bb2d7: all 49 ngs2_* tests Passed (35 test executables built).
  • Per commit: each of the ten commits was built and its ngs2_voicehandles, ngs2_filter and ngs2_custom tests run on their own; all pass.
  • Negative control: with upstream/main's Voice.cpp and this branch's tests, ngs2_voicehandles stops with SIGSEGV at address 0x40, inside the write of the unwritable sampler state (the test passes the address 0x10).
  • Not covered: the PS4 common-only path of the sampler state is built only when PS4_LIBRARY is set, and the test binaries here do not take it, so it is not exercised by these tests.
  • Not run: Windows, macOS, a real console, any title.
  • Overlap, checked by hand because pr_overlap.py failed closed:

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

…est in sceNgs2VoiceGetState

For a sampler voice, sceNgs2VoiceGetState built the state directly in the guest
output through its pointer, so an unmapped output faulted the host part way
through. The state is now built in a local Ngs2SamplerVoiceState and written
once: the common part for the PS4 common-only size, the whole struct otherwise.
An unwritable output returns SCE_NGS2_ERROR_INVALID_OUT_ADDRESS, the code the
rest of this function uses for outputs. Writable output receives the same bytes
as before.
…ceNgs2VoiceGetState

An unwritable output of the full sampler state size must return
SCE_NGS2_ERROR_INVALID_OUT_ADDRESS and keep errno. The common-only size applies
to the PS4 library only and is not covered here.
…st in sceNgs2VoiceGetState

For a reverb voice, sceNgs2VoiceGetState cleared the guest output and set its
flags through the pointer, so an unmapped output faulted the host. The state is
now built in a local Ngs2VoiceState and written with WriteGuest. An unwritable
output returns SCE_NGS2_ERROR_INVALID_OUT_ADDRESS. Writable output receives the
same bytes as before.
…eNgs2VoiceGetState

An unwritable output for a reverb voice must return SCE_NGS2_ERROR_INVALID_OUT_ADDRESS.
…h WriteGuest in sceNgs2VoiceGetState

For a custom mastering voice, sceNgs2VoiceGetState cleared the guest output and
set its flags through the pointer, so an unmapped output faulted the host. The
state is now built in a local Ngs2VoiceState and written with WriteGuest. An
unwritable output returns SCE_NGS2_ERROR_INVALID_OUT_ADDRESS. Writable output
receives the same bytes as before.
…tate

An unwritable output for a custom mastering voice must return
SCE_NGS2_ERROR_INVALID_OUT_ADDRESS.
…uest in sceNgs2VoiceGetState

For a submixer voice, sceNgs2VoiceGetState built the state directly in the guest
output through its pointer, so an unmapped output faulted the host. The state is
now built in a local Ngs2SubmixerVoiceState and written with WriteGuestBytes. An
unwritable output returns SCE_NGS2_ERROR_INVALID_OUT_ADDRESS. Writable output
receives the same bytes as before.
…sceNgs2VoiceGetState

An unwritable output for a submixer voice must return SCE_NGS2_ERROR_INVALID_OUT_ADDRESS.
…WriteGuestBytes in sceNgs2VoiceGetState

For a custom sampler voice, sceNgs2VoiceGetState built the state directly in the
guest output through its pointer, so an unmapped output faulted the host. The
state is now built in a local Ngs2CustomSamplerVoiceState and written once with
WriteGuestBytes. The branches keep their previous results: a pending play
reports only the in-use flag, and an idle voice without a render reports its
flags with no decoded count. An unwritable output returns
SCE_NGS2_ERROR_INVALID_OUT_ADDRESS.
…te in sceNgs2VoiceGetState

The custom sampler voice helper of the filter test now checks that an unwritable
output returns SCE_NGS2_ERROR_INVALID_OUT_ADDRESS, before it returns the voice. The
check has no effect on the voice.
@oneandonlydean
oneandonlydean merged commit a650037 into boykopovar:main Nov 15, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants