fix(libSceAudioOut): refuse sceAudioOut2Mastering calls before sceAudioOut2Initialize #11244

Merged
SeaSunPT merged 2 commits from upstream-pr/11244 into main 2026-10-28 00:02:47 +00:00
SeaSunPT commented 2026-10-25 22:28:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SeaSunPT on 2026-10-25T22:28:48Z.


What

Before sceAudioOut2Initialize, sceAudioOut2MasteringInit, sceAudioOut2MasteringInitEx, sceAudioOut2MasteringTerm, sceAudioOut2MasteringGetState and sceAudioOut2MasteringSetParam went straight to their own checks: sceAudioOut2MasteringInit(0) initialized mastering and returned 0. The console returns 0x80268006 (not initialized) from all five. Each now returns 0x80268006 first when AudioOut2IsInitialized_nid_no_patch() is false, as sceAudioOut2GetSpeakerInfo does, and changes no state.

Source: #9027 (https://github.com/boykopovar/AnyPS5/pull/9027) read the decrypted PS5 libSceAudioOut: Init (XHl38ZNknbs 0x22660) and InitEx (7ukE-Yrzqog 0x22650) jump into one routine at 0x22360; Term is 2bbBBOkH4CY 0x22690, GetState VZidxi2cYh0 0x22da0 and SetParam v8iOE+j8a5o 0x228e0. It states that the console also returns 0x80268006 from all of these before sceAudioOut2Initialize, and it left the check out only because that initialization was not tracked. #9027 calls the module 12.00; the open #10179 relabels it 13.60.

Check order:

  • Init and InitEx: 0x80268006 comes before the already-initialized return of 0 and before the flag check (0x80268201). The earlier debt entry, replaced in #9027, recorded that order: "native initialization requires AudioOut2 initialization (0x80268006 otherwise), returns success immediately when already initialized, and otherwise rejects nonzero flags with 0x80268201" (f7a7be1a2).
  • Term, GetState and SetParam: before sceAudioOut2Initialize, mastering cannot be initialized, because Init refuses. If 0x80268203 came first, the console would return it there, not 0x80268006. So 0x80268006 comes before 0x80268203, and #9027 puts 0x80268203 before the pointer, parameter and flag checks. sceAudioOut2Terminate throws here, so AudioOut2 never goes back to uninitialized after sceAudioOut2Initialize, and no other state shows the order.

The debt entry for Init and InitEx loses the closed clause; the rest stays open. Unchanged: the output/user checks and audio-server failures #9027 left out, the legacy sceAudioOutMastering* calls, and the missing 0x80268006 in sceAudioOut2SetSystemDebugState, sceAudioOut2EnableChat and sceAudioOut2DisableChat (each in its own debt entry; a separate PR).

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Ninja, Release, -DBUILD_TESTING=ON, on main b82cc9689.

  • audio_out2_latency (existing test, new TestMasteringBeforeInitialize run in main before sceAudioOut2Initialize): Init with flags 0 and 1, InitEx with 0, bit 31 and 1, Term, GetState with a null and a valid state, and SetParam with a valid parameter and with a null parameter and flags 2 all return 0x80268006, and the refused GetState leaves the states unwritten. The existing TestMasteringInit that runs next still gets 0x80268203 from Term, so the refused Init calls did not initialize mastering.
  • With AudioOut2Mastering.cpp from main and the new test kept, audio_out2_latency aborts (exit code 0xc0000409) on its first check: mastering initialization before AudioOut2 initialization is refused, since sceAudioOut2MasteringInit(0) returns 0. With the change it passes.
  • ctest --test-dir build -R "audio" --output-on-failure, three runs: 51/51 passed each time.
  • ctest --test-dir build -R "public_headers" --output-on-failure: 65/65 passed.
  • ctest --test-dir build -j 8 --output-on-failure: 2 of 2392 tests failed. The two failures, agc_host_import_cut_lifetime and agc_driver_depth_plane_partial_store, also fail on main on this machine (NVIDIA RTX 5070 Ti) and do not involve libSceAudioOut.
  • No build warnings in the changed files.
  • python tools/check_conventions.py --base origin/main passes; git diff --check origin/main is clean.
  • python tools/pr_overlap.py --branch fix/audioout2-mastering-not-initialized: the only conflict is with #10179, on debt line 16 (its 12.00 -> 13.60 label). Whichever PR merges second needs a docs-only rebase. #9818 and #9826 already conflict with main in AudioOut2Mastering.cpp. #11035 edits the same test's main and merges cleanly with this branch.

Linux not tested.

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
  • 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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009357111 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11244). Originally posted by [SeaSunPT](https://github.com/SeaSunPT) on 2026-10-25T22:28:48Z. --- ### What Before `sceAudioOut2Initialize`, `sceAudioOut2MasteringInit`, `sceAudioOut2MasteringInitEx`, `sceAudioOut2MasteringTerm`, `sceAudioOut2MasteringGetState` and `sceAudioOut2MasteringSetParam` went straight to their own checks: `sceAudioOut2MasteringInit(0)` initialized mastering and returned 0. The console returns `0x80268006` (not initialized) from all five. Each now returns `0x80268006` first when `AudioOut2IsInitialized_nid_no_patch()` is false, as `sceAudioOut2GetSpeakerInfo` does, and changes no state. Source: #9027 (https://github.com/boykopovar/AnyPS5/pull/9027) read the decrypted PS5 `libSceAudioOut`: Init (`XHl38ZNknbs` 0x22660) and InitEx (`7ukE-Yrzqog` 0x22650) jump into one routine at 0x22360; Term is `2bbBBOkH4CY` 0x22690, GetState `VZidxi2cYh0` 0x22da0 and SetParam `v8iOE+j8a5o` 0x228e0. It states that the console also returns `0x80268006` from all of these before `sceAudioOut2Initialize`, and it left the check out only because that initialization was not tracked. #9027 calls the module 12.00; the open #10179 relabels it 13.60. Check order: - Init and InitEx: `0x80268006` comes before the already-initialized return of 0 and before the flag check (`0x80268201`). The earlier debt entry, replaced in #9027, recorded that order: "native initialization requires AudioOut2 initialization (0x80268006 otherwise), returns success immediately when already initialized, and otherwise rejects nonzero flags with 0x80268201" (f7a7be1a2). - Term, GetState and SetParam: before `sceAudioOut2Initialize`, mastering cannot be initialized, because Init refuses. If `0x80268203` came first, the console would return it there, not `0x80268006`. So `0x80268006` comes before `0x80268203`, and #9027 puts `0x80268203` before the pointer, parameter and flag checks. `sceAudioOut2Terminate` throws here, so AudioOut2 never goes back to uninitialized after `sceAudioOut2Initialize`, and no other state shows the order. The debt entry for Init and InitEx loses the closed clause; the rest stays open. Unchanged: the `output`/`user` checks and audio-server failures #9027 left out, the legacy `sceAudioOutMastering*` calls, and the missing `0x80268006` in `sceAudioOut2SetSystemDebugState`, `sceAudioOut2EnableChat` and `sceAudioOut2DisableChat` (each in its own debt entry; a separate PR). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Ninja, Release, `-DBUILD_TESTING=ON`, on `main` b82cc9689. - `audio_out2_latency` (existing test, new `TestMasteringBeforeInitialize` run in `main` before `sceAudioOut2Initialize`): Init with flags 0 and 1, InitEx with 0, bit 31 and 1, Term, GetState with a null and a valid state, and SetParam with a valid parameter and with a null parameter and flags 2 all return `0x80268006`, and the refused GetState leaves the states unwritten. The existing `TestMasteringInit` that runs next still gets `0x80268203` from Term, so the refused Init calls did not initialize mastering. - With `AudioOut2Mastering.cpp` from `main` and the new test kept, `audio_out2_latency` aborts (exit code 0xc0000409) on its first check: `mastering initialization before AudioOut2 initialization is refused`, since `sceAudioOut2MasteringInit(0)` returns 0. With the change it passes. - `ctest --test-dir build -R "audio" --output-on-failure`, three runs: 51/51 passed each time. - `ctest --test-dir build -R "public_headers" --output-on-failure`: 65/65 passed. - `ctest --test-dir build -j 8 --output-on-failure`: 2 of 2392 tests failed. The two failures, `agc_host_import_cut_lifetime` and `agc_driver_depth_plane_partial_store`, also fail on `main` on this machine (NVIDIA RTX 5070 Ti) and do not involve libSceAudioOut. - No build warnings in the changed files. - `python tools/check_conventions.py --base origin/main` passes; `git diff --check origin/main` is clean. - `python tools/pr_overlap.py --branch fix/audioout2-mastering-not-initialized`: the only conflict is with #10179, on debt line 16 (its `12.00` -> `13.60` label). Whichever PR merges second needs a docs-only rebase. #9818 and #9826 already conflict with `main` in `AudioOut2Mastering.cpp`. #11035 edits the same test's `main` and merges cleanly with this branch. Linux not tested. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 22:31:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:31:02Z.

Review: APPROVED


Reviewed exact head 4128be2f60327e5bc90fdbcd03f05d90a6b17b7e. The initialization guard precedes each mastering method’s existing mastering-state, flag, pointer, and state-ID checks, matching the measured not-initialized result without mutating state; the test runs before sceAudioOut2Initialize and confirms refused state reads leave output untouched. Current-main conventions and diff-check pass. The author reports the focused Windows audio tests and full-suite baseline failures; hosted product jobs were skipped by path policy, and I did not rerun the runtime tests locally. #10179 and #11035 remain open; their stated overlap is documented.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645687880 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11244#pullrequestreview-5645687880). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T22:31:02Z. **Review:** APPROVED --- Reviewed exact head `4128be2f60327e5bc90fdbcd03f05d90a6b17b7e`. The initialization guard precedes each mastering method’s existing mastering-state, flag, pointer, and state-ID checks, matching the measured not-initialized result without mutating state; the test runs before `sceAudioOut2Initialize` and confirms refused state reads leave output untouched. Current-main conventions and diff-check pass. The author reports the focused Windows audio tests and full-suite baseline failures; hosted product jobs were skipped by path policy, and I did not rerun the runtime tests locally. #10179 and #11035 remain open; their stated overlap is documented.
thepoppfish commented 2026-10-25 22:53:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T22:53:20Z.

Review: APPROVED


Reviewed exact head 4128be2f60327e5bc90fdbcd03f05d90a6b17b7e and independently reproduced the initialization-state fix on native Windows with GCC 16.2.0-6 UCRT, C++20, -O1 -g -fno-inline -flto, static C++ runtime.

The new guards preserve the check order documented by the module reading in #9027. That source explicitly reports 0x80268006 for all five calls before AudioOut2 initialization; #10179 corrects its firmware label to 13.60. I did not inspect a console binary or run a console probe myself.

Validation:

  • Built isolated executables from the complete production AudioOut2Mastering.cpp, AudioOut.cpp, AudioOut2Context.cpp, AudioOut2System.cpp and AudioOut2Low.cpp, using this checkout's real headers and SDL headers at the pinned submodule 4b69833bc54abf3dd3288d4aa7afbba527775e5b. The actual production global initialization state and all four initialization entry points are used. The only support implementation is the usual NotImplemented throwing boundary; LTO removes unused device/backend paths.
  • The complete committed AudioOut2Latency.cpp passes. Four additional process-isolated modes (sceAudioOut2Initialize, legacy sceAudioOutInit, sceAudioOut2InitializeEx, sceAudioOut2LoInit) each pass 114 checks, 456 total. These include all five early refusals, pointer/flag/state-ID precedence, unchanged output bytes, PAGE_NOACCESS input/output pointers rejected without touching memory, no mastering-state mutation on refusal, all individual flag bits after initialization, and repeated mastering-init/term behavior. CTest: 5/5 pass, 0 skipped, 0.24 s.
  • Negative control: replacing only the complete mastering source with parent b82cc9689498cf7a0e2565b44001e9deb00d2f6b makes the committed test abort at mastering initialization before AudioOut2 initialization is refused (exit 0xc0000409). Each additional mode reports 35 failed checks on that parent implementation, versus 0 on this head. The other four production modules are byte-identical to the parent after checkout line-ending normalization.
  • Also made a clean local merge with #11035 at 9925a9e401ac5fde5cf0fe7dd12b1b906f2f4263 and pinned main b90d009d9f73354cbea239a74a8f7e2dcd138772 (local commit 546e5bd2dc01b4c634ca5fa551a8373912fe7c01, tree aecde74cd489295437e05f963a7076756690ac8b). The combined committed test retains the before-initialization mastering checks and #11035's repeated-initialization checks. Rebuilt from that tree: 5/5 pass, 0 skipped, 0.38 s, including another 456/456 probe checks. This establishes compatibility for these pinned revisions; merge-order coordination and the reported #10179 docs overlap remain separate.
  • Conventions against pinned main and whitespace checks pass for the reviewed and merged trees; both tracked working trees are clean. No warnings in the successful focused builds.

Scope: focused native implementation tests with unused backend paths removed. No full shared-library/product build, SDL playback, Linux/macOS, retail-console or title run, and no canonical PR-overlap scan by me. AI-assisted review and fixture: Codex.

Complete standalone fixture for reproduction

Initialize the SDL submodule in the checkout of the exact reviewed head. Save the three files below in a separate directory. Before configuring, create ParentMastering.cpp in that directory with this Python snippet, setting repo to the reviewed checkout:

import subprocess
from pathlib import Path
repo = Path("C:/path/to/AnyPS5-review")
source = "b82cc9689498cf7a0e2565b44001e9deb00d2f6b:core/libs/prx/libSceAudioOut/src/AudioOut2Mastering.cpp"
Path("ParentMastering.cpp").write_bytes(subprocess.check_output(["git", "-C", str(repo), "show", source]))

Configure with GCC/MinGW, setting REPO and SDL_INCLUDE to the checkout and its 3rdparty/SDL2/include directory, then build and run CTest:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DREPO="C:/path/to/AnyPS5-review" -DSDL_INCLUDE="C:/path/to/AnyPS5-review/3rdparty/SDL2/include"
cmake --build build -j 3
ctest --test-dir build --output-on-failure

parent_author.exe is the expected-aborting negative control. parent_probe.exe direct (or legacy, extended, low) prints 114 checks/35 failures and exits 1; the corresponding head_probe.exe prints 114/0 and exits 0. Each mode starts in a fresh process. The objcopy post-build step follows the project's Windows unwind-section handling for exceptions across the guest ABI.

CMakeLists.txt

cmake_minimum_required(VERSION 3.20)
project(AudioMasteringReview LANGUAGES CXX)
get_filename_component(DEFAULT_REPO "${CMAKE_CURRENT_LIST_DIR}/../review-11244" ABSOLUTE)
set(REPO "${DEFAULT_REPO}" CACHE PATH "Exact source checkout")
set(SDL_INCLUDE "${DEFAULT_REPO}/3rdparty/SDL2/include" CACHE PATH "Pinned SDL headers")
set(VARIANTS "head;parent" CACHE STRING "Production variants to build")
set(AUDIO "${REPO}/core/libs/prx/libSceAudioOut")
enable_testing()
foreach(variant IN LISTS VARIANTS)
    if(variant STREQUAL head)
        set(mastering "${AUDIO}/src/AudioOut2Mastering.cpp")
    else()
        set(mastering "${CMAKE_CURRENT_LIST_DIR}/ParentMastering.cpp")
    endif()
    add_library(${variant}_modules OBJECT "${mastering}" "${AUDIO}/src/AudioOut.cpp" "${AUDIO}/src/AudioOut2System.cpp" "${AUDIO}/src/AudioOut2Low.cpp" "${AUDIO}/src/AudioOut2Context.cpp" Support.cpp)
    target_compile_features(${variant}_modules PRIVATE cxx_std_20)
    target_compile_options(${variant}_modules PRIVATE -O1 -g -fno-inline -flto -ffunction-sections -fdata-sections)
    target_compile_definitions(${variant}_modules PRIVATE SDL_MAIN_HANDLED)
    target_include_directories(${variant}_modules PRIVATE "${REPO}/core/libs" "${SDL_INCLUDE}")
    foreach(kind IN ITEMS author probe)
        if(kind STREQUAL author)
            set(entry "${AUDIO}/tests/AudioOut2Latency.cpp")
        else()
            set(entry "${CMAKE_CURRENT_LIST_DIR}/Probe.cpp")
        endif()
        add_executable(${variant}_${kind} "${entry}" $<TARGET_OBJECTS:${variant}_modules>)
        target_compile_features(${variant}_${kind} PRIVATE cxx_std_20)
        target_compile_options(${variant}_${kind} PRIVATE -O1 -g -fno-inline -flto -ffunction-sections -fdata-sections)
        target_compile_definitions(${variant}_${kind} PRIVATE SDL_MAIN_HANDLED)
        target_include_directories(${variant}_${kind} PRIVATE "${REPO}/core/libs" "${SDL_INCLUDE}")
        target_link_options(${variant}_${kind} PRIVATE -O1 -flto -static-libstdc++ -static-libgcc -Wl,--gc-sections)
        add_custom_command(TARGET ${variant}_${kind} POST_BUILD COMMAND "${CMAKE_OBJCOPY}" --rename-section .eh_frame=.ehfram --rename-section .eh_fram=.ehfram "$<TARGET_FILE:${variant}_${kind}>" VERBATIM)
    endforeach()
endforeach()
add_test(NAME author_head COMMAND head_author)
foreach(mode IN ITEMS direct legacy extended low)
    add_test(NAME guard_${mode} COMMAND head_probe ${mode})
endforeach()
set_tests_properties(author_head guard_direct guard_legacy guard_extended guard_low PROPERTIES TIMEOUT 8)

Support.cpp

#include "prx/libc/include/General.hpp"
#include <stdexcept>

extern "C" [[noreturn]] void NotImplemented_nid_no_patch(const char* name) {
    throw std::runtime_error(name);
}

Probe.cpp

#include "prx/libSceAudioOut/include/AudioOut.hpp"
#include "prx/libSceAudioOut/include/AudioOut2.hpp"
#include "prx/libSceAudioOut/src/AudioOut2Internal.hpp"
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <string_view>
#include <windows.h>

namespace {
constexpr int notInitialized = static_cast<int>(0x80268006);
constexpr int masteringNotInitialized = static_cast<int>(0x80268203);
constexpr int invalidFlags = static_cast<int>(0x80268201);
std::size_t checks = 0;
std::size_t failures = 0;
void Check(bool value, const char* name) {
    ++checks;
    if (value) return;
    ++failures;
    if (failures <= 12) std::fprintf(stderr, "FAIL: %s\n", name);
}
}

int main(int argc, char** argv) {
    if (argc != 2) return 2;
    SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
    Check(!AudioOut2IsInitialized_nid_no_patch(), "actual module starts uninitialized");
    Check(sceAudioOut2MasteringTerm() == notInitialized, "term early guard");
    void* inaccessible = VirtualAlloc(nullptr, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_NOACCESS);
    if (!inaccessible) return 3;
    Check(sceAudioOut2MasteringGetState(static_cast<AudioOut2MasteringStatesHeader*>(inaccessible), 0xFFFFFFFFu, -1) == notInitialized, "get rejects before reading inaccessible memory");
    Check(sceAudioOut2MasteringSetParam(static_cast<const AudioOut2MasteringParamsHeader*>(inaccessible), 0xFFFFFFFFu, 0xFFFFFFFFu) == notInitialized, "set rejects before reading inaccessible memory");
    for (std::uint32_t id : {0u, 1u, 2u, 3u, 0x01010001u, 0xFFFFFFFFu}) {
        alignas(16) std::array<std::uint8_t, 512> storage;
        storage.fill(0xA5);
        std::memcpy(storage.data(), &id, sizeof(id));
        const auto before = storage;
        Check(sceAudioOut2MasteringGetState(reinterpret_cast<AudioOut2MasteringStatesHeader*>(storage.data()), 0, 0) == notInitialized, "get early code for every state id");
        Check(storage == before, "get refusal leaves all output bytes untouched");
    }
    Check(sceAudioOut2MasteringGetState(nullptr, 0, 0) == notInitialized, "get initialization precedes null check");
    for (std::uint32_t flags : {0u, 1u, 2u, 0x80000000u, 0x80000001u, 0xFFFFFFFFu}) {
        const AudioOut2MasteringParamsHeader param{1};
        Check(sceAudioOut2MasteringSetParam(nullptr, 0, flags) == notInitialized, "set initialization precedes null and flag checks");
        Check(sceAudioOut2MasteringSetParam(&param, 0, flags) == notInitialized, "set initialization precedes flag check");
    }
    for (std::uint32_t flags : {0u, 1u, 2u, 0x80000000u, 0x80000001u, 0xFFFFFFFFu}) {
        Check(sceAudioOut2MasteringInit(flags) == notInitialized, "init early code");
        Check(sceAudioOut2MasteringInitEx(flags) == notInitialized, "initEx early code");
    }
    Check(!AudioOut2IsInitialized_nid_no_patch(), "refused mastering calls do not initialize AudioOut2");
    VirtualFree(inaccessible, 0, MEM_RELEASE);
    const std::string_view mode(argv[1]);
    int result = -1;
    if (mode == "direct") result = sceAudioOut2Initialize();
    else if (mode == "legacy") result = sceAudioOutInit();
    else if (mode == "extended") result = sceAudioOut2InitializeEx(0);
    else if (mode == "low") result = sceAudioOut2LoInit();
    else return 2;
    Check(result == 0 && AudioOut2IsInitialized_nid_no_patch(), "real initialization transition");
    Check(sceAudioOut2MasteringTerm() == masteringNotInitialized, "refused calls left mastering uninitialized");
    Check(sceAudioOut2MasteringGetState(nullptr, 0, 0) == masteringNotInitialized, "mastering-state guard still precedes null after AudioOut2 init");
    for (unsigned bit = 0; bit < 32; ++bit) {
        const auto flag = std::uint32_t{1} << bit;
        Check(sceAudioOut2MasteringInit(flag) == invalidFlags, "Init refuses all individual nonzero flag bits");
        Check(sceAudioOut2MasteringInitEx(flag) == (bit == 31 ? 0 : invalidFlags), "InitEx accepts only bit31");
        if (bit == 31) Check(sceAudioOut2MasteringTerm() == 0, "InitEx allowed-bit success transitioned mastering");
    }
    Check(sceAudioOut2MasteringInit(0) == 0, "normal mastering initialization");
    Check(sceAudioOut2MasteringInit(0xFFFFFFFFu) == 0 && sceAudioOut2MasteringInitEx(0xFFFFFFFFu) == 0, "already initialized wins over invalid flags");
    AudioOut2MasteringStates storage{};
    storage.states_header.states_id = 1;
    Check(sceAudioOut2MasteringGetState(&storage.states_header, 0, 0) == 0, "post-init state query succeeds");
    Check(sceAudioOut2MasteringTerm() == 0 && sceAudioOut2MasteringTerm() == masteringNotInitialized, "mastering init is not counted");
    std::printf("{\"mode\":\"%s\",\"checks\":%zu,\"failures\":%zu}\n", argv[1], checks, failures);
    return failures ? 1 : 0;
}
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645765999 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11244#pullrequestreview-5645765999). Originally posted by [thepoppfish](https://github.com/thepoppfish) on 2026-10-25T22:53:20Z. **Review:** APPROVED --- Reviewed exact head `4128be2f60327e5bc90fdbcd03f05d90a6b17b7e` and independently reproduced the initialization-state fix on native Windows with GCC **16.2.0-6 UCRT**, C++20, `-O1 -g -fno-inline -flto`, static C++ runtime. The new guards preserve the check order documented by the module reading in #9027. That source explicitly reports `0x80268006` for all five calls before AudioOut2 initialization; #10179 corrects its firmware label to 13.60. I did not inspect a console binary or run a console probe myself. Validation: - Built isolated executables from the **complete production** `AudioOut2Mastering.cpp`, `AudioOut.cpp`, `AudioOut2Context.cpp`, `AudioOut2System.cpp` and `AudioOut2Low.cpp`, using this checkout's real headers and SDL headers at the pinned submodule `4b69833bc54abf3dd3288d4aa7afbba527775e5b`. The actual production global initialization state and all four initialization entry points are used. The only support implementation is the usual `NotImplemented` throwing boundary; LTO removes unused device/backend paths. - The complete committed `AudioOut2Latency.cpp` passes. Four additional process-isolated modes (`sceAudioOut2Initialize`, legacy `sceAudioOutInit`, `sceAudioOut2InitializeEx`, `sceAudioOut2LoInit`) each pass **114 checks**, **456 total**. These include all five early refusals, pointer/flag/state-ID precedence, unchanged output bytes, `PAGE_NOACCESS` input/output pointers rejected without touching memory, no mastering-state mutation on refusal, all individual flag bits after initialization, and repeated mastering-init/term behavior. CTest: **5/5 pass, 0 skipped, 0.24 s**. - Negative control: replacing only the complete mastering source with parent `b82cc9689498cf7a0e2565b44001e9deb00d2f6b` makes the committed test abort at `mastering initialization before AudioOut2 initialization is refused` (exit `0xc0000409`). Each additional mode reports **35 failed checks** on that parent implementation, versus **0** on this head. The other four production modules are byte-identical to the parent after checkout line-ending normalization. - Also made a **clean local merge** with #11035 at `9925a9e401ac5fde5cf0fe7dd12b1b906f2f4263` and pinned main `b90d009d9f73354cbea239a74a8f7e2dcd138772` (local commit `546e5bd2dc01b4c634ca5fa551a8373912fe7c01`, tree `aecde74cd489295437e05f963a7076756690ac8b`). The combined committed test retains the before-initialization mastering checks and #11035's repeated-initialization checks. Rebuilt from that tree: **5/5 pass, 0 skipped, 0.38 s**, including another **456/456** probe checks. This establishes compatibility for these pinned revisions; merge-order coordination and the reported #10179 docs overlap remain separate. - Conventions against pinned main and whitespace checks pass for the reviewed and merged trees; both tracked working trees are clean. No warnings in the successful focused builds. Scope: focused native implementation tests with unused backend paths removed. No full shared-library/product build, SDL playback, Linux/macOS, retail-console or title run, and no canonical PR-overlap scan by me. AI-assisted review and fixture: Codex. <details> <summary>Complete standalone fixture for reproduction</summary> Initialize the SDL submodule in the checkout of the exact reviewed head. Save the three files below in a separate directory. Before configuring, create `ParentMastering.cpp` in that directory with this Python snippet, setting `repo` to the reviewed checkout: ```python import subprocess from pathlib import Path repo = Path("C:/path/to/AnyPS5-review") source = "b82cc9689498cf7a0e2565b44001e9deb00d2f6b:core/libs/prx/libSceAudioOut/src/AudioOut2Mastering.cpp" Path("ParentMastering.cpp").write_bytes(subprocess.check_output(["git", "-C", str(repo), "show", source])) ``` Configure with GCC/MinGW, setting `REPO` and `SDL_INCLUDE` to the checkout and its `3rdparty/SDL2/include` directory, then build and run CTest: ```powershell cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DREPO="C:/path/to/AnyPS5-review" -DSDL_INCLUDE="C:/path/to/AnyPS5-review/3rdparty/SDL2/include" cmake --build build -j 3 ctest --test-dir build --output-on-failure ``` `parent_author.exe` is the expected-aborting negative control. `parent_probe.exe direct` (or `legacy`, `extended`, `low`) prints 114 checks/35 failures and exits 1; the corresponding `head_probe.exe` prints 114/0 and exits 0. Each mode starts in a fresh process. The `objcopy` post-build step follows the project's Windows unwind-section handling for exceptions across the guest ABI. **CMakeLists.txt** ```cmake cmake_minimum_required(VERSION 3.20) project(AudioMasteringReview LANGUAGES CXX) get_filename_component(DEFAULT_REPO "${CMAKE_CURRENT_LIST_DIR}/../review-11244" ABSOLUTE) set(REPO "${DEFAULT_REPO}" CACHE PATH "Exact source checkout") set(SDL_INCLUDE "${DEFAULT_REPO}/3rdparty/SDL2/include" CACHE PATH "Pinned SDL headers") set(VARIANTS "head;parent" CACHE STRING "Production variants to build") set(AUDIO "${REPO}/core/libs/prx/libSceAudioOut") enable_testing() foreach(variant IN LISTS VARIANTS) if(variant STREQUAL head) set(mastering "${AUDIO}/src/AudioOut2Mastering.cpp") else() set(mastering "${CMAKE_CURRENT_LIST_DIR}/ParentMastering.cpp") endif() add_library(${variant}_modules OBJECT "${mastering}" "${AUDIO}/src/AudioOut.cpp" "${AUDIO}/src/AudioOut2System.cpp" "${AUDIO}/src/AudioOut2Low.cpp" "${AUDIO}/src/AudioOut2Context.cpp" Support.cpp) target_compile_features(${variant}_modules PRIVATE cxx_std_20) target_compile_options(${variant}_modules PRIVATE -O1 -g -fno-inline -flto -ffunction-sections -fdata-sections) target_compile_definitions(${variant}_modules PRIVATE SDL_MAIN_HANDLED) target_include_directories(${variant}_modules PRIVATE "${REPO}/core/libs" "${SDL_INCLUDE}") foreach(kind IN ITEMS author probe) if(kind STREQUAL author) set(entry "${AUDIO}/tests/AudioOut2Latency.cpp") else() set(entry "${CMAKE_CURRENT_LIST_DIR}/Probe.cpp") endif() add_executable(${variant}_${kind} "${entry}" $<TARGET_OBJECTS:${variant}_modules>) target_compile_features(${variant}_${kind} PRIVATE cxx_std_20) target_compile_options(${variant}_${kind} PRIVATE -O1 -g -fno-inline -flto -ffunction-sections -fdata-sections) target_compile_definitions(${variant}_${kind} PRIVATE SDL_MAIN_HANDLED) target_include_directories(${variant}_${kind} PRIVATE "${REPO}/core/libs" "${SDL_INCLUDE}") target_link_options(${variant}_${kind} PRIVATE -O1 -flto -static-libstdc++ -static-libgcc -Wl,--gc-sections) add_custom_command(TARGET ${variant}_${kind} POST_BUILD COMMAND "${CMAKE_OBJCOPY}" --rename-section .eh_frame=.ehfram --rename-section .eh_fram=.ehfram "$<TARGET_FILE:${variant}_${kind}>" VERBATIM) endforeach() endforeach() add_test(NAME author_head COMMAND head_author) foreach(mode IN ITEMS direct legacy extended low) add_test(NAME guard_${mode} COMMAND head_probe ${mode}) endforeach() set_tests_properties(author_head guard_direct guard_legacy guard_extended guard_low PROPERTIES TIMEOUT 8) ``` **Support.cpp** ```cpp #include "prx/libc/include/General.hpp" #include <stdexcept> extern "C" [[noreturn]] void NotImplemented_nid_no_patch(const char* name) { throw std::runtime_error(name); } ``` **Probe.cpp** ```cpp #include "prx/libSceAudioOut/include/AudioOut.hpp" #include "prx/libSceAudioOut/include/AudioOut2.hpp" #include "prx/libSceAudioOut/src/AudioOut2Internal.hpp" #include <algorithm> #include <array> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstring> #include <string_view> #include <windows.h> namespace { constexpr int notInitialized = static_cast<int>(0x80268006); constexpr int masteringNotInitialized = static_cast<int>(0x80268203); constexpr int invalidFlags = static_cast<int>(0x80268201); std::size_t checks = 0; std::size_t failures = 0; void Check(bool value, const char* name) { ++checks; if (value) return; ++failures; if (failures <= 12) std::fprintf(stderr, "FAIL: %s\n", name); } } int main(int argc, char** argv) { if (argc != 2) return 2; SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); Check(!AudioOut2IsInitialized_nid_no_patch(), "actual module starts uninitialized"); Check(sceAudioOut2MasteringTerm() == notInitialized, "term early guard"); void* inaccessible = VirtualAlloc(nullptr, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_NOACCESS); if (!inaccessible) return 3; Check(sceAudioOut2MasteringGetState(static_cast<AudioOut2MasteringStatesHeader*>(inaccessible), 0xFFFFFFFFu, -1) == notInitialized, "get rejects before reading inaccessible memory"); Check(sceAudioOut2MasteringSetParam(static_cast<const AudioOut2MasteringParamsHeader*>(inaccessible), 0xFFFFFFFFu, 0xFFFFFFFFu) == notInitialized, "set rejects before reading inaccessible memory"); for (std::uint32_t id : {0u, 1u, 2u, 3u, 0x01010001u, 0xFFFFFFFFu}) { alignas(16) std::array<std::uint8_t, 512> storage; storage.fill(0xA5); std::memcpy(storage.data(), &id, sizeof(id)); const auto before = storage; Check(sceAudioOut2MasteringGetState(reinterpret_cast<AudioOut2MasteringStatesHeader*>(storage.data()), 0, 0) == notInitialized, "get early code for every state id"); Check(storage == before, "get refusal leaves all output bytes untouched"); } Check(sceAudioOut2MasteringGetState(nullptr, 0, 0) == notInitialized, "get initialization precedes null check"); for (std::uint32_t flags : {0u, 1u, 2u, 0x80000000u, 0x80000001u, 0xFFFFFFFFu}) { const AudioOut2MasteringParamsHeader param{1}; Check(sceAudioOut2MasteringSetParam(nullptr, 0, flags) == notInitialized, "set initialization precedes null and flag checks"); Check(sceAudioOut2MasteringSetParam(&param, 0, flags) == notInitialized, "set initialization precedes flag check"); } for (std::uint32_t flags : {0u, 1u, 2u, 0x80000000u, 0x80000001u, 0xFFFFFFFFu}) { Check(sceAudioOut2MasteringInit(flags) == notInitialized, "init early code"); Check(sceAudioOut2MasteringInitEx(flags) == notInitialized, "initEx early code"); } Check(!AudioOut2IsInitialized_nid_no_patch(), "refused mastering calls do not initialize AudioOut2"); VirtualFree(inaccessible, 0, MEM_RELEASE); const std::string_view mode(argv[1]); int result = -1; if (mode == "direct") result = sceAudioOut2Initialize(); else if (mode == "legacy") result = sceAudioOutInit(); else if (mode == "extended") result = sceAudioOut2InitializeEx(0); else if (mode == "low") result = sceAudioOut2LoInit(); else return 2; Check(result == 0 && AudioOut2IsInitialized_nid_no_patch(), "real initialization transition"); Check(sceAudioOut2MasteringTerm() == masteringNotInitialized, "refused calls left mastering uninitialized"); Check(sceAudioOut2MasteringGetState(nullptr, 0, 0) == masteringNotInitialized, "mastering-state guard still precedes null after AudioOut2 init"); for (unsigned bit = 0; bit < 32; ++bit) { const auto flag = std::uint32_t{1} << bit; Check(sceAudioOut2MasteringInit(flag) == invalidFlags, "Init refuses all individual nonzero flag bits"); Check(sceAudioOut2MasteringInitEx(flag) == (bit == 31 ? 0 : invalidFlags), "InitEx accepts only bit31"); if (bit == 31) Check(sceAudioOut2MasteringTerm() == 0, "InitEx allowed-bit success transitioned mastering"); } Check(sceAudioOut2MasteringInit(0) == 0, "normal mastering initialization"); Check(sceAudioOut2MasteringInit(0xFFFFFFFFu) == 0 && sceAudioOut2MasteringInitEx(0xFFFFFFFFu) == 0, "already initialized wins over invalid flags"); AudioOut2MasteringStates storage{}; storage.states_header.states_id = 1; Check(sceAudioOut2MasteringGetState(&storage.states_header, 0, 0) == 0, "post-init state query succeeds"); Check(sceAudioOut2MasteringTerm() == 0 && sceAudioOut2MasteringTerm() == masteringNotInitialized, "mastering init is not counted"); std::printf("{\"mode\":\"%s\",\"checks\":%zu,\"failures\":%zu}\n", argv[1], checks, failures); return failures ? 1 : 0; } ``` </details>
jotitadev commented 2026-10-27 01:07:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T01:07:03Z.

Review: COMMENTED


Linux run of the current head, since the description says Linux was not tested.

Machine: Linux x86_64, i7-8700 (6 cores / 12 threads, AVX2), Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON. Head d736ea814 merged onto main cb45ae2dd.

  • Build ok. All 47 tests matching audio_out/audioout pass, audio_out2_latency among them.
  • Restoring AudioOut2Mastering.cpp to main and keeping the test aborts audio_out2_latency with mastering initialization before AudioOut2 initialization is refused, so the test catches the regression on Linux too.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5661087486 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11244#pullrequestreview-5661087486). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T01:07:03Z. **Review:** COMMENTED --- Linux run of the current head, since the description says Linux was not tested. Machine: Linux x86_64, i7-8700 (6 cores / 12 threads, AVX2), Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`. Head `d736ea814` merged onto `main` `cb45ae2dd`. - Build ok. All 47 tests matching `audio_out`/`audioout` pass, `audio_out2_latency` among them. - Restoring `AudioOut2Mastering.cpp` to `main` and keeping the test aborts `audio_out2_latency` with `mastering initialization before AudioOut2 initialization is refused`, so the test catches the regression on Linux too. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11244
No description provided.