Repository navigation
fix(libSceAudioOut): return the console's codes from the legacy mastering calls - #16737
Conversation
… mastering calls On a PS5 (firmware 11.60, payload process) sceAudioOutMasteringTerm without an Init returns 0x80260203, sceAudioOutMasteringInit(1) 0x80260201 and sceAudioOutMasteringGetState 0x80260204 for a states id other than 1 and 0x80260203 for id 1 before an Init or after a Term. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ng calls sceAudioOutMasteringTerm, sceAudioOutMasteringGetState and sceAudioOutMasteringInit(1) now return the codes the console returns. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Probe sources (built with ps5-payload-sdk v0.45; sceAudioOutMasteringInit probe.c/* Probe E: sceAudioOutMasteringInit, sceAudioOutMasteringTerm and sceAudioOutMasteringGetState, payload process,
firmware 11.60 (debt libSceAudioOut.md: a repeated Init, a Term without Init and GetState before Init are unknown;
non-zero Init flags). sceAudioOutInit runs first and the probe stops if it fails. Init is called with flags 0, and
with flags 1 only after the mastering stage has been ended again. GetState gets a 336-byte marker buffer; only
the return code and the number of changed bytes in the first 32 and the rest are printed. SetParam is not called.
No NULL pointer is passed. No user ID is used. Nothing is written, nothing is sent. */
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h> /* only for kernel_get_fw_version() */
#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: the runner can only close the connection, it cannot end the process on the console, so the probe ends
itself after PROBE_MAX_S seconds at the latest (set by the build script). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
_exit(124);
}
/* Watchdog thread: alarm()/SIGALRM does not help when the main thread hangs in a blocking system call or IPC. The
thread sleeps PROBE_MAX_S seconds, writes TIMEOUT with write() and ends the process with _exit(124). alarm() stays
as a second safeguard. */
static void* probe_watchdog(void* arg) {
static const char msg[] = "TIMEOUT\tprobe watchdog thread\n";
unsigned left = PROBE_MAX_S;
(void)arg;
while (left) left = sleep(left);
(void)!write(1, msg, sizeof msg - 1);
_exit(124);
return 0;
}
static void probe_watchdog_start(void) {
pthread_t t;
if (pthread_create(&t, 0, probe_watchdog, 0) == 0) pthread_detach(t);
}
static int cases = 0;
static void probe_header(void) {
char utc[32];
time_t now = time(0);
probe_watchdog_start();
struct tm tmv;
gmtime_r(&now, &tmv);
strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
getpid(), utc);
fflush(stdout);
}
static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
fflush(stdout);
cases++;
}
static void probe_end(void) {
printf("END\t%d\n", cases);
fflush(stdout);
}
typedef int (*fn_init)(void);
typedef int (*fn_minit)(unsigned);
typedef int (*fn_mterm)(void);
typedef int (*fn_mstate)(void*);
static fn_mstate mState;
static void step(const char* id, const char* call, long r, int e) {
char extra[32];
snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
probe_case(id, call, r, e, extra);
}
static void state_case(const char* id, const char* call) {
unsigned char buf[336];
char extra[96];
memset(buf, 0x5a, sizeof buf);
errno = 0;
long r = mState(buf);
int e = errno;
int head = 0, rest = 0;
for (size_t b = 0; b < sizeof buf; ++b)
if (buf[b] != 0x5a) { if (b < 32) head++; else rest++; }
snprintf(extra, sizeof extra, "0x%08x changed_first_32=%d changed_after=%d", (unsigned)r, head, rest);
probe_case(id, call, r, e, extra);
}
int main(void) {
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
char extra[32];
probe_header();
errno = 0;
void* lib = dlopen("libSceAudioOut.sprx", RTLD_LAZY);
probe_case("0", "load libSceAudioOut.sprx", lib ? 0 : -1, errno, lib ? "loaded" : dlerror());
if (!lib) { probe_end(); return 0; }
fn_init aoInit = (fn_init)dlsym(lib, "sceAudioOutInit");
fn_minit mInit = (fn_minit)dlsym(lib, "sceAudioOutMasteringInit");
fn_mterm mTerm = (fn_mterm)dlsym(lib, "sceAudioOutMasteringTerm");
mState = (fn_mstate)dlsym(lib, "sceAudioOutMasteringGetState");
if (!aoInit || !mInit || !mTerm || !mState) {
probe_case("0b", "dlsym of the mastering functions", -1, 0, "missing");
probe_end();
return 0;
}
errno = 0;
long r = aoInit();
snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
probe_case("1", "sceAudioOutInit()", r, errno, extra);
if (r != 0) { probe_end(); return 0; } /* no further call without a successful init */
errno = 0; r = mTerm(); step("2", "sceAudioOutMasteringTerm() without Init", r, errno);
state_case("3", "sceAudioOutMasteringGetState(&states) before Init");
errno = 0; r = mInit(0); step("4", "sceAudioOutMasteringInit(0)", r, errno);
errno = 0; r = mInit(0); step("5", "sceAudioOutMasteringInit(0) again", r, errno);
state_case("6", "sceAudioOutMasteringGetState(&states) after Init");
errno = 0; r = mTerm(); step("7", "sceAudioOutMasteringTerm()", r, errno);
errno = 0; r = mTerm(); step("8", "sceAudioOutMasteringTerm() again", r, errno);
state_case("9", "sceAudioOutMasteringGetState(&states) after Term");
errno = 0; r = mInit(1); step("10", "sceAudioOutMasteringInit(1)", r, errno);
if (r == 0) { errno = 0; r = mTerm(); step("11", "sceAudioOutMasteringTerm() after Init(1)", r, errno); }
probe_end();
return 0;
}sceAudioOutMasteringInit raw outputsceAudioOutMasteringGetState probe.c/* Probe E: sceAudioOutMasteringGetState with the states id set, payload process, firmware 11.60 (debt
libSceAudioOut.md:183 and 184: GetState before and after Init, and the states id). Follow-up to the run where the
marker buffer gave 0x80260204 everywhere. The first 32-bit word of a 336-byte marker buffer is the states id (0, 1, 2
and 0xffffffff are tried); only the return code, the number of changed bytes after that word and how many of them
are non-zero are printed. sceAudioOutInit runs first and the probe stops if it fails; Init is called with flags 0
and followed by Term. SetParam is not called. No NULL pointer is passed. No user ID is used. Nothing is written,
nothing is sent. */
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <ps5/kernel.h> /* only for kernel_get_fw_version() */
#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
/* Self limit: the runner can only close the connection, it cannot end the process on the console, so the probe ends
itself after PROBE_MAX_S seconds at the latest (set by the build script). */
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
_exit(124);
}
/* Watchdog thread: alarm()/SIGALRM does not help when the main thread hangs in a blocking system call or IPC. The
thread sleeps PROBE_MAX_S seconds, writes TIMEOUT with write() and ends the process with _exit(124). alarm() stays
as a second safeguard. */
static void* probe_watchdog(void* arg) {
static const char msg[] = "TIMEOUT\tprobe watchdog thread\n";
unsigned left = PROBE_MAX_S;
(void)arg;
while (left) left = sleep(left);
(void)!write(1, msg, sizeof msg - 1);
_exit(124);
return 0;
}
static void probe_watchdog_start(void) {
pthread_t t;
if (pthread_create(&t, 0, probe_watchdog, 0) == 0) pthread_detach(t);
}
static int cases = 0;
static void probe_header(void) {
char utc[32];
time_t now = time(0);
probe_watchdog_start();
struct tm tmv;
gmtime_r(&now, &tmv);
strftime(utc, sizeof utc, "%Y-%m-%dT%H:%M:%SZ", &tmv);
printf("PROBE\t%s\tfw=0x%08x\tbuild=%s\tpid=%d\tutc=%s\n", PROBE_NAME, kernel_get_fw_version(), PROBE_BUILD,
getpid(), utc);
fflush(stdout);
}
static void probe_case(const char* id, const char* call, long ret, int err, const char* extra) {
printf("CASE\t%s\t%s\t%ld\t%d\t%s\n", id, call, ret, err, extra ? extra : "-");
fflush(stdout);
cases++;
}
static void probe_end(void) {
printf("END\t%d\n", cases);
fflush(stdout);
}
typedef int (*fn_init)(void);
typedef int (*fn_minit)(unsigned);
typedef int (*fn_mterm)(void);
typedef int (*fn_mstate)(void*);
static fn_mstate mState;
static void step(const char* id, const char* call, long r, int e) {
char extra[32];
snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
probe_case(id, call, r, e, extra);
}
static void state_case(const char* id, const char* call, unsigned states_id) {
unsigned char buf[336];
char extra[96];
memset(buf, 0x5a, sizeof buf);
memcpy(buf, &states_id, 4);
errno = 0;
long r = mState(buf);
int e = errno;
int changed = 0, nonzero = 0;
for (size_t b = 4; b < sizeof buf; ++b) {
if (buf[b] != 0x5a) changed++;
if (buf[b] != 0x5a && buf[b] != 0) nonzero++;
}
snprintf(extra, sizeof extra, "0x%08x changed_after_id=%d changed_nonzero=%d", (unsigned)r, changed, nonzero);
probe_case(id, call, r, e, extra);
}
int main(void) {
signal(SIGALRM, probe_alarm);
alarm(PROBE_MAX_S);
char extra[32];
probe_header();
errno = 0;
void* lib = dlopen("libSceAudioOut.sprx", RTLD_LAZY);
probe_case("0", "load libSceAudioOut.sprx", lib ? 0 : -1, errno, lib ? "loaded" : dlerror());
if (!lib) { probe_end(); return 0; }
fn_init aoInit = (fn_init)dlsym(lib, "sceAudioOutInit");
fn_minit mInit = (fn_minit)dlsym(lib, "sceAudioOutMasteringInit");
fn_mterm mTerm = (fn_mterm)dlsym(lib, "sceAudioOutMasteringTerm");
mState = (fn_mstate)dlsym(lib, "sceAudioOutMasteringGetState");
if (!aoInit || !mInit || !mTerm || !mState) {
probe_case("0b", "dlsym of the mastering functions", -1, 0, "missing");
probe_end();
return 0;
}
errno = 0;
long r = aoInit();
snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
probe_case("1", "sceAudioOutInit()", r, errno, extra);
if (r != 0) { probe_end(); return 0; } /* no further call without a successful init */
state_case("2", "sceAudioOutMasteringGetState(id 1) before Init", 1);
errno = 0; r = mInit(0); step("3", "sceAudioOutMasteringInit(0)", r, errno);
if (r == 0) {
state_case("4", "sceAudioOutMasteringGetState(id 1) after Init", 1);
state_case("5", "sceAudioOutMasteringGetState(id 2) after Init", 2);
state_case("6", "sceAudioOutMasteringGetState(id 0) after Init", 0);
state_case("7", "sceAudioOutMasteringGetState(id 0xffffffff) after Init", 0xffffffffu);
errno = 0; r = mTerm(); step("8", "sceAudioOutMasteringTerm()", r, errno);
state_case("9", "sceAudioOutMasteringGetState(id 1) after Term", 1);
}
probe_end();
return 0;
}sceAudioOutMasteringGetState raw outputAI-assisted (Claude Code). 🤖 Generated with Claude Code |
|
Windows check of head Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run this test on pull requests.
AI-assisted: yes. |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
gabichuuuuu
left a comment
There was a problem hiding this comment.
Windows run of head 26f2741fd2, merged onto main 286b14d2f7 in one tree with 47 other small open PRs that touch different files. Setup: Windows 11, WinLibs GCC 15.2 r7 (x86_64-ucrt-posix-seh, the CI toolchain), Release, BUILD_TESTING=ON.
audio_out2_latencywith--repeat until-fail:5: 5 / 5 pass.- Negative control, with
main'sAudioOut2Mastering.cppand this PR's test: 5 / 5 runs fail.
What
sceAudioOutMasteringTermalways returned 0,sceAudioOutMasteringInit(1)andsceAudioOutMasteringGetStatewith a states id other than 1 threw, andsceAudioOutMasteringGetStatewith id 1 answered before an Init. On a PS5 a Term without an Init returns 0x80260203,sceAudioOutMasteringInit(1)returns 0x80260201,sceAudioOutMasteringGetStatereturns 0x80260204 for a states id other than 1 and 0x80260203 for id 1 before an Init or after a Term. The legacy calls now keep an initialized flag:sceAudioOutMasteringInit(0)sets it, Term clears it, and the three calls return those codes. Other Init flags still throw because they were not measured. The 304 bytes the console writes for id 1 after an Init (8 of them non-zero) are not modelled; the debt entries say so.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-07 at 06:55 UTC and 07:25 UTC; the console's own clock read about 1 h 41 min more (see the first comment). A title process may differ.mainbeforesceAudioOutMasteringTermwithout Init, and a second TermsceAudioOutMasteringInit(1)sceAudioOutMasteringInit(0), also repeatedsceAudioOutMasteringGetState, states id 0, 2 or 0xffffffffsceAudioOutMasteringGetState, states id 1 before Init or after TermThe test
audio_out2_latencynow checks these codes. On Ubuntu 24.04 under WSL2 with GCC 13.3.0 and an AddressSanitizer build, onmain006d11fca5the test commit alone aborts, and with the fix commit on the samemainit passes. All 64audio_out*tests pass with this change.tools/check_conventions.py --base upstream/mainpasses.Overlap: the 13 other open pull requests that change
AudioOut2Mastering.cpp,AudioOut2Latency.cpp,AudioOut.cppordocs/dev/debt/libSceAudioOut.mdwere checked on 2026-11-07 between 13:45 UTC and 13:50 UTC againstmainc32f751139(the base of this change is the older006d11fca5; it still merges without a conflict). Three already conflict withmainwithout this change: #5021 and #14212 in the debt file, #12315 in other files. None conflicts only with this change; the other ten merge cleanly with and without it, among them #16597, #16614 and #16641, which edit other entries of the same files.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AI-assisted (Claude Code).
🤖 Generated with Claude Code