Skip to content

fix(libSceAudioOut): return the closed-port code for a closed handle - #16614

Merged
oneandonlydean merged 6 commits into
boykopovar:mainfrom
xXPBSXx:k/audioout-closed-handle
Dec 3, 2026
Merged

oneandonlydean merged 6 commits into
boykopovar:mainfrom
xXPBSXx:k/audioout-closed-handle

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What

sceAudioOutGetLastOutputTime, sceAudioOutGetPortState and sceAudioOutSetVolume returned 0x80260003 for a handle that had been closed. On a PS5 they return 0x80260001 for a closed main port and 0x80260003 for handle -1. A main port handle closed with sceAudioOutClose now returns 0x80260001. Any other handle that is not open still returns 0x80260003, which is AnyPS5's own choice: the console was measured for handle -1 and for a closed main port only. A closed handle of another port type also keeps 0x80260003 here and is not measured. The other calls that take a handle are not measured, and 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-06 at 18:51 UTC (sceAudioOutSetVolume) and on 2026-11-07 at 04:56 UTC (the other two calls); the console's own clock read about 1 h 41 min more (see the first comment). A title process may differ.

call on a handle PS5, payload process, firmware 11.60 main before here now
the three calls after sceAudioOutClose of a main port 0x80260001 0x80260003 0x80260001
the three calls with handle -1 0x80260003 0x80260003 0x80260003

At the first head: the tests audio_out_last_output_time and audio_out_set_volume now check both codes. On Ubuntu 24.04 under WSL2 with GCC 13.3.0 and an AddressSanitizer build, on main 3988999f6c and on this change on the same main, both abort on main ("a closed port must be rejected as closed", "closed port returns the closed-port code") and pass with this change. All 65 audio_out* tests pass with this change. tools/check_conventions.py --base upstream/main passes.

After merging main into this branch, three tests expected 0x80260003 for a closed main port and failed on the Windows build: guest_audio_out, guest_audio_out_volume_bounds and guest_audio_out_system_state_output_time_bounds. Two of them are new on main, and the closed-handle checks in guest_audio_out came with a commit on main that the first head did not have. They now expect 0x80260001 for a closed main port and 0x80260003 for a closed handle of every other port type, and a new case in guest_audio_out checks the latter. On Windows 10 (build 19045) with MinGW GCC 15.2.0, ninja and ccache, on the test commit with the code unchanged, 2 of 82 audio_out tests fail (guest_audio_out, guest_audio_out_system_state_output_time_bounds); with the code change 82 of 82 pass. On the merge commit 5a5e7beebf6, before the tests were adjusted, all three of the tests above fail. These runs were made on the commits before one blank line was added to a test file; the code and the checks are the same. tools/check_conventions.py --base upstream/main and tools/debt_fold.py --check pass.

Overlap: the 13 other open pull requests that change AudioOut.cpp, AudioOutLastOutputTime.cpp, AudioOutSetVolume.cpp or docs/dev/debt/libSceAudioOut.md were checked on 2026-11-07 between 09:10 UTC and 09:15 UTC against main d86a06f7c6. Three already conflict with main without this change: #5021 in the debt file, #12315 and #14212 in other files. #14212 also conflicts in docs/dev/debt/libSceAudioOut.md with this change, because it adds a blank line between every entry; the new entry does not edit an existing one. The other ten merge cleanly with and without this change, among them #16542 and #16597, which edit other entries of the same files.

Overlap, repeated on 2026-11-28 for the head a41ca46a7c85 of this pull request (a test commit and a fix commit on top of the previous head 5a5e7beebf65): the file lists of the 2094 open pull requests and the patches of the 1132 that were opened or updated since 08:50 UTC were read from the GitHub API from 14:58 to 15:02 UTC (the patches of all 2077 open pull requests had been read the same morning from 08:58 to 09:04 UTC), and the paths and the changed lines were searched for sceAudioOutGetLastOutputTime, sceAudioOutGetPortState, sceAudioOutSetVolume, g_closedMainHandles, 0x80260001, AudioOut.cpp, AudioOutLastOutputTime.cpp, AudioOutSetVolume.cpp, GuestAudioOut.cpp, GuestAudioOutVolumeBounds.cpp, GuestAudioOutSystemStateOutputTimeBounds.cpp and libSceAudioOut.md. No open pull request changes the two test files GuestAudioOutVolumeBounds.cpp and GuestAudioOutSystemStateOutputTimeBounds.cpp. The pull requests that change the same source files are #16597, #18272, #24632 and #24639 (AudioOutLastOutputTime.cpp, AudioOutSetVolume.cpp) and, in AudioOut.cpp only, #20630, #18431, #24296, #22585, #24624, #12863 and #27628, and #18441 and #18819 change docs/dev/debt/libSceAudioOut.md; the head merges cleanly with main at bb89b8a4f5c4 and with each of #16597, #18272, #24632, #24639, #24624, #18441, #18819, #21021 and #27628 (git merge-tree, from 15:05 to 15:10 UTC), and it conflicts with #20630, #18431, #24296, #22585 and #12863 only in the same files in which these already conflict with main alone. #21021 tests handles that were never opened (-1, 0, 1, 2, 33 and 999), which still return 0x80260003, so its expectations stay correct.

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

Summary by CodeRabbit

  • Bug Fixes
    • Queries for volume, port state, and last output time now return the closed-main-port error for handles of closed main audio ports.
    • Closed non-main ports and invalid or out-of-range handles continue to return the invalid-port error, distinguishing closed main ports from these cases.
    • Opening a port clears any previous closed-main-port status associated with its handle.

xXPBSXx and others added 3 commits November 7, 2026 08:00
On a PS5 (firmware 11.60, payload process) sceAudioOutGetLastOutputTime and
sceAudioOutGetPortState return 0x80260001 for a handle that was closed and
0x80260003 for handle -1. sceAudioOutSetVolume does the same.

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

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

xXPBSXx commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Probe sources (built with ps5-payload-sdk v0.45; PROBE_BUILD is the first 12 hex digits of the source's SHA-256) and their raw output. The clock in each PROBE line is the console's own clock, which was about 1 h 41 min ahead of the host clock (runs at 18:51 UTC on 2026-11-06 and 04:56 UTC on 2026-11-07). A local notes file named in one source header is replaced by [local notes file]. Comments translated from German in the first source; the code is identical to the one that ran (build ids 4f1bfbe6c4ba and cacbea9945d6).

sceAudioOutSetVolume probe.c
/* Probe K: sceAudioOutSetVolume (debt libSceAudioOut.md line 95, main 399e7fb57e; cases from
   [local notes file]). Volumes are only set on a port this probe opened itself, which is closed
   again in the same case; no sample is ever output and the system volume is never touched. No NULL volume pointer.
   Nothing is written, nothing is sent. */
#include <dlfcn.h>
#include <errno.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: on a timeout the runner can only close the connection, not end the process on the console. The probe
   ends itself after at most PROBE_MAX_S seconds (the build script sets the timeout minus 10 s). */
#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);
}

static int cases = 0;

static void probe_header(void) {
  char utc[32];
  time_t now = time(0);
  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_open)(int, int, int, uint32_t, uint32_t, uint32_t);
typedef int (*fn_close)(int);
typedef int (*fn_setvol)(int, int32_t, int32_t*);

struct vol_case { const char* id; int32_t flag; int32_t value; };

/* flag is the channel mask; every channel slot of the array gets the same value. */
static const struct vol_case table[] = {
  /* title forms (I's case set) */
  {"v1", 0xFF, 0},
  {"v2", 0xFF, 32768},
  {"v3", 3, 0},
  {"v4", 3, 32768},
  {"v5", 1, 32768},
  /* line 95: values above 0 dB and negative */
  {"g1", 0xFF, 32769},
  {"g2", 0xFF, 65535},
  {"g3", 0xFF, (int32_t)0xFFFFFFFF},
  {"g4", 0xFF, -32768},
};

static fn_open aoOpen;
static fn_close aoClose;

/* Opens the probe's own port (type 0, as the titles), or returns a negative code. */
static long open_port(void) { return aoOpen(0xFF, 0, 0, 1024, 48000, 1); }

int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  char extra[64];
  char call[128];
  char cid[16];
  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");
  aoOpen = (fn_open)dlsym(lib, "sceAudioOutOpen");
  aoClose = (fn_close)dlsym(lib, "sceAudioOutClose");
  fn_setvol setVol = (fn_setvol)dlsym(lib, "sceAudioOutSetVolume");
  if (!aoInit || !aoOpen || !aoClose || !setVol) { probe_case("0b", "dlsym of the audio out 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);

  /* Each case opens its own port, sets the volume on it and closes it at once (A-0193). No sample is output. */
  for (size_t i = 0; i < sizeof table / sizeof table[0]; ++i) {
    const struct vol_case* c = &table[i];
    errno = 0;
    long h = open_port();
    if (h < 0) {
      snprintf(extra, sizeof extra, "0x%08x", (unsigned)h);
      snprintf(cid, sizeof cid, "%so", c->id);
      probe_case(cid, "sceAudioOutOpen(0xff, 0, 0, 1024, 48000, 0x1) for the case", h, errno, extra);
      continue;
    }
    int32_t vol[8];
    for (int k = 0; k < 8; ++k) vol[k] = c->value;
    snprintf(call, sizeof call, "sceAudioOutSetVolume(own port, 0x%x, {%d,...})", (unsigned)c->flag, c->value);
    errno = 0;
    r = setVol((int)h, c->flag, vol);
    int e = errno;
    snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
    probe_case(c->id, call, r, e, extra);
    errno = 0;
    long cr = aoClose((int)h);
    snprintf(extra, sizeof extra, "0x%08x", (unsigned)cr);
    snprintf(cid, sizeof cid, "%sc", c->id);
    probe_case(cid, "sceAudioOutClose(port of the case above)", cr, errno, extra);
  }

  /* Handle after Close and handle -1: only the return code. */
  errno = 0;
  long h = open_port();
  if (h >= 0) {
    aoClose((int)h);
    int32_t vol[8] = {32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768};
    errno = 0;
    r = setVol((int)h, 0xFF, vol);
    snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
    probe_case("h1", "sceAudioOutSetVolume(handle after its Close, 0xff, {32768,...})", r, errno, extra);
  } else {
    snprintf(extra, sizeof extra, "0x%08x", (unsigned)h);
    probe_case("h1o", "sceAudioOutOpen for the closed-handle case", h, errno, extra);
  }
  {
    int32_t vol[8] = {32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768};
    errno = 0;
    r = setVol(-1, 0xFF, vol);
    snprintf(extra, sizeof extra, "0x%08x", (unsigned)r);
    probe_case("h2", "sceAudioOutSetVolume(-1, 0xff, {32768,...})", r, errno, extra);
  }

  probe_end();
  return 0;
}
sceAudioOutSetVolume raw output
PROBE	sceAudioOutSetVolume	fw=0x11600005	build=4f1bfbe6c4ba	pid=118	utc=2026-11-06T20:33:18Z
CASE	0	load libSceAudioOut.sprx	0	3	loaded
CASE	1	sceAudioOutInit()	0	0	0x00000000
CASE	v1	sceAudioOutSetVolume(own port, 0xff, {0,...})	0	0	0x00000000
CASE	v1c	sceAudioOutClose(port of the case above)	0	0	0x00000000
CASE	v2	sceAudioOutSetVolume(own port, 0xff, {32768,...})	0	0	0x00000000
CASE	v2c	sceAudioOutClose(port of the case above)	0	0	0x00000000
CASE	v3	sceAudioOutSetVolume(own port, 0x3, {0,...})	0	0	0x00000000
CASE	v3c	sceAudioOutClose(port of the case above)	0	0	0x00000000
CASE	v4	sceAudioOutSetVolume(own port, 0x3, {32768,...})	0	0	0x00000000
CASE	v4c	sceAudioOutClose(port of the case above)	0	0	0x00000000
CASE	v5	sceAudioOutSetVolume(own port, 0x1, {32768,...})	0	0	0x00000000
CASE	v5c	sceAudioOutClose(port of the case above)	0	0	0x00000000
CASE	g1	sceAudioOutSetVolume(own port, 0xff, {32769,...})	-2144993271	0	0x80260009
CASE	g1c	sceAudioOutClose(port of the case above)	0	0	0x00000000
CASE	g2	sceAudioOutSetVolume(own port, 0xff, {65535,...})	-2144993271	0	0x80260009
CASE	g2c	sceAudioOutClose(port of the case above)	0	0	0x00000000
CASE	g3	sceAudioOutSetVolume(own port, 0xff, {-1,...})	-2144993271	0	0x80260009
CASE	g3c	sceAudioOutClose(port of the case above)	0	0	0x00000000
CASE	g4	sceAudioOutSetVolume(own port, 0xff, {-32768,...})	-2144993271	0	0x80260009
CASE	g4c	sceAudioOutClose(port of the case above)	0	0	0x00000000
CASE	h1	sceAudioOutSetVolume(handle after its Close, 0xff, {32768,...})	-2144993279	0	0x80260001
CASE	h2	sceAudioOutSetVolume(-1, 0xff, {32768,...})	-2144993277	0	0x80260003
END	22
sceAudioOutGetLastOutputTime probe.c
/* Probe E: sceAudioOutGetLastOutputTime and sceAudioOutGetPortState, payload process, firmware 11.60 (debt
   libSceAudioOut.md: what the last output time is, and the answer before any output). One port is opened with
   sceAudioOutOpen(0xff, 0, 0, 1024, 48000, 0x1), one block of silence (1024 samples, 16-bit stereo, all zero) is output
   and the port is closed. The output time is printed raw and as the difference to sceKernelGetProcessTime() taken
   just before and just after the output call. The port state record is a 64-byte marker buffer: only the return
   code, the number of changed bytes and its first 16 bytes are printed. No user ID of a person is used (0xff is the
   system user). 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_open)(int, int, int, unsigned, unsigned, unsigned);
typedef int (*fn_close)(int);
typedef int (*fn_output)(int, const void*);
typedef int (*fn_lastout)(int, uint64_t*);
typedef int (*fn_portstate)(int, void*);
typedef uint64_t (*fn_proctime)(void);

static fn_lastout aoLast;
static fn_portstate aoState;
static fn_proctime procTime;

static uint64_t now_us(void) { return procTime ? procTime() : 0; }

static void last_case(const char* id, const char* call, int handle, uint64_t t0, uint64_t t1) {
  uint64_t v = 0xdeadbeefdeadbeefULL;
  char extra[160];
  errno = 0;
  long r = aoLast(handle, &v);
  int e = errno;
  if (v == 0xdeadbeefdeadbeefULL)
    snprintf(extra, sizeof extra, "0x%08x value=untouched", (unsigned)r);
  else
    snprintf(extra, sizeof extra, "0x%08x value=%llu delta_to_before=%lld delta_to_after=%lld", (unsigned)r,
             (unsigned long long)v, (long long)(v - t0), (long long)(v - t1));
  probe_case(id, call, r, e, extra);
}

static void state_case(const char* id, const char* call, int handle) {
  unsigned char buf[64];
  char extra[160];
  memset(buf, 0x5a, sizeof buf);
  errno = 0;
  long r = aoState(handle, buf);
  int e = errno;
  int changed = 0;
  for (size_t b = 0; b < sizeof buf; ++b)
    if (buf[b] != 0x5a) changed++;
  snprintf(extra, sizeof extra, "0x%08x changed=%d first16=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
           (unsigned)r, changed, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10],
           buf[11], buf[12], buf[13], buf[14], buf[15]);
  probe_case(id, call, r, e, extra);
}

int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  char extra[64];
  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_open aoOpen = (fn_open)dlsym(lib, "sceAudioOutOpen");
  fn_close aoClose = (fn_close)dlsym(lib, "sceAudioOutClose");
  fn_output aoOutput = (fn_output)dlsym(lib, "sceAudioOutOutput");
  aoLast = (fn_lastout)dlsym(lib, "sceAudioOutGetLastOutputTime");
  aoState = (fn_portstate)dlsym(lib, "sceAudioOutGetPortState");
  procTime = (fn_proctime)dlsym(RTLD_DEFAULT, "sceKernelGetProcessTime");
  if (!aoInit || !aoOpen || !aoClose || !aoOutput || !aoLast || !aoState) {
    probe_case("0b", "dlsym of the audio out functions", -1, 0, "missing");
    probe_end();
    return 0;
  }
  probe_case("0c", "dlsym(sceKernelGetProcessTime)", procTime ? 0 : -1, 0, procTime ? "found" : "missing");

  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;
  long h = aoOpen(0xff, 0, 0, 1024, 48000, 0x1);
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)h);
  probe_case("2", "sceAudioOutOpen(0xff, 0, 0, 1024, 48000, 0x1)", h, errno, extra);
  if (h <= 0) { probe_end(); return 0; }

  state_case("3", "sceAudioOutGetPortState(own port, &state)", (int)h);
  last_case("4", "sceAudioOutGetLastOutputTime(own port) before any output", (int)h, 0, 0);

  static short block[2048];   /* 1024 samples, stereo, all zero */
  memset(block, 0, sizeof block);
  uint64_t t0 = now_us();
  errno = 0;
  r = aoOutput((int)h, block);
  uint64_t t1 = now_us();
  snprintf(extra, sizeof extra, "0x%08x took_us=%llu", (unsigned)r, (unsigned long long)(t1 - t0));
  probe_case("5", "sceAudioOutOutput(own port, one silent block)", r, errno, extra);

  last_case("6", "sceAudioOutGetLastOutputTime(own port) after one output", (int)h, t0, t1);
  state_case("7", "sceAudioOutGetPortState(own port) after output", (int)h);

  errno = 0;
  long c = aoClose((int)h);
  snprintf(extra, sizeof extra, "0x%08x", (unsigned)c);
  probe_case("8", "sceAudioOutClose(own port)", c, errno, extra);

  last_case("9", "sceAudioOutGetLastOutputTime(closed handle)", (int)h, t0, t1);
  state_case("10", "sceAudioOutGetPortState(closed handle)", (int)h);
  last_case("11", "sceAudioOutGetLastOutputTime(handle -1)", -1, t0, t1);
  state_case("12", "sceAudioOutGetPortState(handle -1)", -1);

  probe_end();
  return 0;
}
sceAudioOutGetLastOutputTime raw output
PROBE	sceAudioOutGetLastOutputTime	fw=0x11600005	build=cacbea9945d6	pid=99	utc=2026-11-07T06:37:51Z
CASE	0	load libSceAudioOut.sprx	0	3	loaded
CASE	0c	dlsym(sceKernelGetProcessTime)	0	0	found
CASE	1	sceAudioOutInit()	0	0	0x00000000
CASE	2	sceAudioOutOpen(0xff, 0, 0, 1024, 48000, 0x1)	536870912	0	0x20000000
CASE	3	sceAudioOutGetPortState(own port, &state)	0	0	0x00000000 changed=15 first16=0000025affff05000000000000000000
CASE	4	sceAudioOutGetLastOutputTime(own port) before any output	0	0	0x00000000 value=0 delta_to_before=0 delta_to_after=0
CASE	5	sceAudioOutOutput(own port, one silent block)	1024	0	0x00000400 took_us=12
CASE	6	sceAudioOutGetLastOutputTime(own port) after one output	0	0	0x00000000 value=228641 delta_to_before=2 delta_to_after=-10
CASE	7	sceAudioOutGetPortState(own port) after output	0	0	0x00000000 changed=15 first16=0000025affff05000000000000000000
CASE	8	sceAudioOutClose(own port)	0	0	0x00000000
CASE	9	sceAudioOutGetLastOutputTime(closed handle)	-2144993279	0	0x80260001 value=untouched
CASE	10	sceAudioOutGetPortState(closed handle)	-2144993279	0	0x80260001 changed=0 first16=5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a
CASE	11	sceAudioOutGetLastOutputTime(handle -1)	-2144993277	0	0x80260003 value=untouched
CASE	12	sceAudioOutGetPortState(handle -1)	-2144993277	0	0x80260003 changed=0 first16=5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a
END	14

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@JJenkx

JJenkx commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 7119429ece, merged onto main e4f4f564a3 (cab7bccf0a, 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_out_last_output_time and audio_out_set_volume pass 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.

Windows run of head 7119429ece, 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_out_last_output_time with --repeat until-fail:5: 5 / 5 pass.
  • audio_out_set_volume with --repeat until-fail:5: 5 / 5 pass.
  • Negative control, with main's AudioOut.cpp and this PR's test: 5 / 5 runs fail.

@github-actions

github-actions Bot commented Nov 16, 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 18431 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
PR 20630 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
PR 24296 core/libs/prx/libSceAudioOut/src/AudioOut.cpp
PR 27628 core/libs/prx/libSceAudioOut/src/AudioOut.cpp

@MarcZX10 MarcZX10 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.

Reviewed — no blocking findings

The inspected code consistently returns the closed-port error for a handle closed since its last allocation; I could not run the tests in this review environment.

What I ran

Reviewed head 7119429ece3db572ab9a496b21153cad1e3876ba. Read the prepared description, commits, manifest and diff, then the changed-line contexts in each changed file and targeted source context with repo_read.py. No tests or build commands were run. The author reports console measurements and passing test runs in the description; these were not independently verified.

Results

Check Result Note
Changed-line review passed All four changed files read
Tests and build not run No command execution available
Console behavior not run Author-reported measurements only

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

The reported PS5 measurements, Ubuntu/WSL2 test runs, all 65 audio tests, and convention check were not independently run. Read: core/libs/prx/libSceAudioOut/src/AudioOut.cpp, core/libs/prx/libSceAudioOut/tests/AudioOutLastOutputTime.cpp, core/libs/prx/libSceAudioOut/tests/AudioOutSetVolume.cpp, and docs/dev/debt/libSceAudioOut.md. No changed files were excluded from review.

To get this to a good state

Nothing is required. Optional: independently run the reported audio tests and convention check.

The one conflict is in allocatePort in AudioOut.cpp: the branch resets g_closedHandles[i] and upstream stamps port.generation. Both lines are kept.

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

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: AudioOut handle errors

Layer / File(s) Summary
Track port lifecycle
core/libs/prx/libSceAudioOut/src/AudioOut.cpp
Port allocation clears the closed-main marker. Port close records whether the port was a main port.
Apply and verify handle errors
core/libs/prx/libSceAudioOut/src/AudioOut.cpp, core/libs/prx/libSceAudioOut/tests/*, core/libs/tests/GuestAudioOut*.cpp, docs/dev/debt/libSceAudioOut.md
The three APIs use the marker when no open port matches the handle. Tests cover closed main and non-main ports, invalid handles, reopening, and unchanged timestamp output. The debt entry records measured error results.

Suggested reviewers: boykopovar, marczx10, gabichuuuuu

Change: Bug fix

Merge Risk: Minimal · up to a41ca

This change makes closed main-port handles return the error code measured on PS5 firmware. Other missing handles keep their previous error. The tests cover the new distinction, and no merge-blocking risk is evident.

Security architecture risk: Minimal · up to a41ca

Three existing audio calls now distinguish a closed main audio port from an invalid handle. Both outcomes still reject the handle, and the change does not grant access to audio data or controls.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The added observable state is whether an in-range unused slot is marked as a closed main port. It is exposed only through the error returns of the three existing guest calls.

Trust Boundaries and Controls

  • observed — A guest-supplied handle must pass the existing live-port lookup to reach volume writes or guest-memory copy-out. The new missing-port branch checks the handle range before reading the flag and returns before either operation.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6223d73e-f547-497b-837d-360e49bc2f33
Commits

Reviewing files that changed from the base of the PR and between 5a5e7be and a41ca46.

Files selected for processing: 5

  • core/libs/prx/libSceAudioOut/src/AudioOut.cpp
  • core/libs/tests/GuestAudioOut.cpp
  • core/libs/tests/GuestAudioOutSystemStateOutputTimeBounds.cpp
  • core/libs/tests/GuestAudioOutVolumeBounds.cpp
  • docs/dev/debt/libSceAudioOut.md
Files skipped from review as they are similar to previous changes: 1

  • docs/dev/debt/libSceAudioOut.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@MarcZX10 MarcZX10 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.

Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 5a5e7beebf65ff6dee9e736d2c96882e6af979c2. No build or tests were run in this review; the commands and test results in the PR description are author-reported.

Results

Check Result Note
Changed source and tests passed All four changed files read
Build and tests not run PR description reports successful author runs

Findings

Blocking

None.

Non-blocking

None.

Not verified

No runtime behavior, build, or tests were independently verified. The change adds per-slot closed-handle tracking, clears it when a port is allocated, and marks it on successful close; the affected API paths consult that state when a handle does not resolve to an open port. files.json was unavailable through the reader, so the review does not independently confirm the separate excluded-file listing. The four changed files listed in manifest.json were all read.

To get this to a good state

Nothing is required.

xXPBSXx and others added 2 commits November 28, 2026 12:24
…andle

A handle closed with sceAudioOutClose returns 0x80260001 from sceAudioOutGetLastOutputTime, sceAudioOutGetPortState and sceAudioOutSetVolume only for the main port type, which is the only type measured on the console. The existing checks for these three calls now expect it for a closed main port, in every test that closes one. Closed handles of the other port types keep 0x80260003, and a new case checks that; this is not a measurement of the console for those types.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…he main port type

sceAudioOutGetLastOutputTime, sceAudioOutGetPortState and sceAudioOutSetVolume return 0x80260001 for a handle closed with sceAudioOutClose only when the port type was main, the one type measured on the console. A closed handle of another type keeps 0x80260003, which is not a measurement for those types. The debt entry says so.

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

@MarcZX10 MarcZX10 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.

Reviewed — looks good

The reviewed change at a41ca46a7c85d33189c1ac70339c6ef5258d3a5d tracks recently closed main-port handles and returns the closed-port error from the three targeted calls; the included tests cover main and non-main ports, invalid handles, and reopening.

What I ran

Read the prepared description, commit list, manifest, diff, and all seven changed files at the pinned head through repo_read.py. No tests or builds were run during this review.

Results

Check Result Note
Changed-file review passed All seven changed files read
Tests and build not run Author-reported results only
Runtime behavior not run No console measurement performed

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports PS5 firmware 11.60 measurements for the closed-main-port error and handle -1; those measurements were not independently verified. No tests or build were run during this review. No files were excluded from the changed-file review.

To get this to a good state

Nothing is required.

@oneandonlydean
oneandonlydean merged commit 95891ce into boykopovar:main Dec 3, 2026
15 of 19 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.

5 participants