Skip to content

fix(libSceAudioOut): check the param pointer first in sceAudioOut2SetSystemDebugState - #17633

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
xXPBSXx:k/audioout2-debugstate-order
Nov 12, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
xXPBSXx:k/audioout2-debugstate-order

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

What

sceAudioOut2SetSystemDebugState checked the id and size of the debug state before the pointer inside the struct, threw for state 1 with a null inner pointer, and returned 0x80268001 for state 2. On a PS5 a null inner pointer returned 0x8026800c for state 2 with size 8 and for state 1 with sizes 4 and 8, so the pointer is checked before the id and the size, and state 2 with an 8-byte param returned 0x80268000. The call now does the same; it applies the same pointer check to states 1 and 2 with any size, which was not measured for the other sizes. Everything else is unchanged: other ids and sizes still return 0x80268001, and state 1 with an 8-byte param and a valid pointer still returns 0. That case and id 0x20 were not measured, because the valid call would change a system debug state; the debt entry says so.

Tested

Measured on a PS5 with firmware 11.60 (kernel_get_fw_version 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-09 at 03:24 UTC; the console's own clock read about 1 h 41 min more (see the first comment). A title process may differ.

sceAudioOut2SetSystemDebugState with a param struct PS5, payload process, firmware 11.60 main before here now
state 2, size 8, valid pointer 0x80268000 0x80268001 0x80268000
state 2, size 8, null inner pointer 0x8026800c 0x80268001 0x8026800c
state 1, size 4, null inner pointer 0x8026800c 0x80268001 0x8026800c
state 1, size 8, null inner pointer 0x8026800c throws 0x8026800c
state 1 with size 4 or 16, state 0 or 0xffffffff with size 8, valid pointer 0x80268001 0x80268001 0x80268001

The test audio_out2_latency now expects these codes. On Ubuntu 24.04 under WSL2 with GCC 13.3.0 and an AddressSanitizer build, on main 8e34d2642d the test commit alone aborts ("debug state id 2 with an 8-byte param returns 0x80268000"), and with the fix commit on the same main it passes; all 65 audio_out* tests pass with this change. tools/check_conventions.py --base upstream/main passes.

Overlap: the 15 other open pull requests that change AudioOut2System.cpp, AudioOut2Latency.cpp or docs/dev/debt/libSceAudioOut.md were checked on 2026-11-09 between 04:55 UTC and 05:01 UTC against main 3d61c0b24f (the base of this change is the older 8e34d2642d; it still merges without a conflict). Four already conflict with main without this change (#12863, #5021, #12315 and #14212). #17468 (the AudioOut2 mastering entries, lines 103 and 104 of the debt file) conflicts in docs/dev/debt/libSceAudioOut.md only with this change, because this change edits the entry on line 105 right below it; it does not edit the same entry, and whichever merges second needs a small rebase. The other ten merge cleanly with and without this change, among them #17546, #16737, #16736, #16641, #16614 and #16597.

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 (audio change)
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

xXPBSXx and others added 3 commits November 9, 2026 04:55
…t2SetSystemDebugState

On a PS5 (firmware 11.60, payload process) the call checks the param
pointer inside the struct first and returns 0x8026800c for debug states 1
and 2 with a null pointer, and returns 0x80268000 for state 2 with an
8-byte param.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…SystemDebugState

A null param pointer inside the struct returns 0x8026800c for debug states
1 and 2 before the id and size are checked, and state 2 with an 8-byte param
returns 0x80268000, as on a PS5.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ate codes

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xXPBSXx

xXPBSXx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Probe source (built with ps5-payload-sdk v0.45; PROBE_BUILD is the first 12 hex digits of the source's SHA-256) and its raw output. The clock in the PROBE line is the console's own clock, which was about 1 h 41 min ahead of the host clock (run at 03:24 UTC on 2026-11-09). The source is unchanged (build id 01d4ebd130c1).

sceAudioOut2SetSystemDebugState probe.c
/* Probe E: sceAudioOut2SetSystemDebugState, payload process, firmware 11.60 (debt libSceAudioOut.md:105: the answers
   for other ids and sizes, for a null parameter and for a null inner pointer are not measured on a console).
   sceAudioOut2Initialize runs first and the probe stops if it fails. The parameter is a 24-byte record (id, reserved,
   inner pointer, size). Only combinations that the debt entry says are rejected are called, plus a null inner
   pointer last, so no debug state is ever set; the accepted combination (id 1, size 8, valid pointer) is NOT
   called because it would change a system debug state. The inner buffer holds zero bytes. No user ID of a person 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_v)(void);
struct dbg_param {
  unsigned id;
  int reserved;
  void* param;
  unsigned long size;
};
typedef int (*fn_dbg)(const struct dbg_param*);

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 dbg_case(fn_dbg f, const char* id, const char* call, unsigned state_id, void* inner, unsigned long size) {
  struct dbg_param p;
  p.id = state_id;
  p.reserved = 0;
  p.param = inner;
  p.size = size;
  errno = 0;
  long r = f(&p);
  step(id, call, r, errno);
}

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_v ao2Init = (fn_v)dlsym(lib, "sceAudioOut2Initialize");
  fn_dbg dbg = (fn_dbg)dlsym(lib, "sceAudioOut2SetSystemDebugState");
  if (!ao2Init || !dbg) {
    probe_case("0b", "dlsym of the audio out 2 functions", -1, 0, "missing");
    probe_end();
    return 0;
  }

  errno = 0;
  long r = ao2Init();
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
  probe_case("1", "sceAudioOut2Initialize()", r, errno, extra);
  if (r != 0) { probe_end(); return 0; }   /* no further call without a successful init */

  static unsigned char inner[64];
  memset(inner, 0, sizeof inner);

  errno = 0; r = dbg(0); step("2", "sceAudioOut2SetSystemDebugState(NULL)", r, errno);
  dbg_case(dbg, "3", "SetSystemDebugState({id 2, size 8, inner buffer})", 2, inner, 8);
  dbg_case(dbg, "4", "SetSystemDebugState({id 1, size 4, inner buffer})", 1, inner, 4);
  dbg_case(dbg, "5", "SetSystemDebugState({id 1, size 16, inner buffer})", 1, inner, 16);
  dbg_case(dbg, "6", "SetSystemDebugState({id 0, size 8, inner buffer})", 0, inner, 8);
  dbg_case(dbg, "7", "SetSystemDebugState({id 0xffffffff, size 8, inner buffer})", 0xffffffffu, inner, 8);
  dbg_case(dbg, "8", "SetSystemDebugState({id 2, size 8, inner NULL})", 2, 0, 8);
  dbg_case(dbg, "9", "SetSystemDebugState({id 1, size 4, inner NULL})", 1, 0, 4);
  dbg_case(dbg, "10", "SetSystemDebugState({id 1, size 8, inner NULL})", 1, 0, 8);

  probe_end();
  return 0;
}
raw output
PROBE	sceAudioOut2SetSystemDebugState	fw=0x11600005	build=01d4ebd130c1	pid=99	utc=2026-11-09T05:05:34Z
CASE	0	load libSceAudioOut.sprx	0	3	loaded
CASE	1	sceAudioOut2Initialize()	0	0	0x00000000
CASE	2	sceAudioOut2SetSystemDebugState(NULL)	-2144960500	0	0x8026800c
CASE	3	SetSystemDebugState({id 2, size 8, inner buffer})	-2144960512	0	0x80268000
CASE	4	SetSystemDebugState({id 1, size 4, inner buffer})	-2144960511	0	0x80268001
CASE	5	SetSystemDebugState({id 1, size 16, inner buffer})	-2144960511	0	0x80268001
CASE	6	SetSystemDebugState({id 0, size 8, inner buffer})	-2144960511	0	0x80268001
CASE	7	SetSystemDebugState({id 0xffffffff, size 8, inner buffer})	-2144960511	0	0x80268001
CASE	8	SetSystemDebugState({id 2, size 8, inner NULL})	-2144960500	0	0x8026800c
CASE	9	SetSystemDebugState({id 1, size 4, inner NULL})	-2144960500	0	0x8026800c
CASE	10	SetSystemDebugState({id 1, size 8, inner NULL})	-2144960500	0	0x8026800c
END	11

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 5021 docs/dev/debt/libSceAudioOut.md
PR 14212 docs/dev/debt/libSceAudioOut.md

@JJenkx

JJenkx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Windows check of head a3b2d8def3, merged onto main 2877881468 (5680907a94, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • audio_out2_latency passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@gabichuuuuu gabichuuuuu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read a3b2d8def3 against main.

Correctness. In AudioOut2System.cpp:sceAudioOut2SetSystemDebugState the order is now: not initialized, then null param, then id 0x20 with size 4 (throws), then a null inner pointer for ids 1 and 2 at any size, then id 2 with size 8 (returns 0x80268000), then 0x80268001 for everything except state 1 with size 8. Each measured row in the table comes out as described. State 1 with size 8 and a valid pointer still returns 0. The NotImplemented that followed the size check on main was reachable only with a null inner pointer, so removing it loses no unimplemented path.

Test. On main, set(2, loudness, 8) returns 0x80268001 and set(1, nullptr, 8) throws, so the changed rows in TestSetSystemDebugState fail there. The new rows set(1, nullptr, 4) and set(2, nullptr, 8) pin the pointer-before-id/size order.

Non-blocking. The null-inner-pointer check is limited to ids 1 and 2. If the console checks the pointer before the id, a null inner pointer with id 0 or 0xffffffff would also return 0x8026800C, but those combinations were measured only with a valid pointer. The debt entry is accurate as written ("the same check covers states 1 and 2"); it could add that other ids with a null inner pointer are unmeasured.

Not run here; this is from reading the code.

AI-assisted: yes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@xXPBSXx

xXPBSXx commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the read. You are right that a null inner pointer with id 0 or 0xffffffff was never measured: those ids were only run with a valid pointer. The head did not say so, so a follow-up commit adds it to the debt entry (what the call returns for them here, 0x80268001 without looking at the pointer, and that the console's answer is not measured). The code is unchanged.

AI-assisted (Claude Code).

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Windows check of head b146cf7198, merged onto main 94d70921fa (clean merge, built together with other open PRs that touch different files).

Setup: Windows 11 x64, WinLibs GCC 15.2.0 (r7), Ninja, Release, BUILD_TESTING=ON, Python 3.15.

  • Tests built from this PR's test files: audio_out2_latency.
  • All of them pass in 3 of 3 runs.
  • Negative control: with this PR's code reverted to main (files it adds removed) and rebuilt, audio_out2_latency fails in 2 of 2 runs, so the tests detect the change.

AI-assisted: yes.

@oneandonlydean
oneandonlydean merged commit ed3a289 into boykopovar:main Nov 12, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants