Skip to content

docs(libSceNgs2): record the measured parse and enumerate results on firmware 11.60 - #23413

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:docs/libscengs2-parse-enum-measured
Nov 19, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:docs/libscengs2-parse-enum-measured

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

What

The sceNgs2ParseWaveformUser, sceNgs2SystemEnumHandles and sceNgs2SystemEnumRackHandles entry in docs/dev/debt/libSceNgs2.md (line 6) states what the firmware 11.00 module does: a negative handler return and a null handler become 0x804A0408, a null output 0x804A0053, the enumerators return the count of live systems, a null array with a nonzero count returns 0x804A0053 and an unknown system 0x804A0230. A probe on a PS5 with firmware 11.60, from a payload process and without sceNgs2SystemCreate, measured these cases: a handler returning -1 gave 0x804A0408 after one call of the handler (offset 0, size 4; case 2.parse, line 7 of the raw output); a null handler gave 0x804A0408 without a call (case 4.parse, line 12); a null output gave 0x804A0053 without a call (case 5.parse, line 14); sceNgs2SystemEnumHandles with an array of 4 and a count of 4 and no system returned 0 and left the array unchanged (case 6.enum, line 9); sceNgs2SystemEnumRackHandles with the system 0 returned 0x804A0230 (case 8.rack, line 10); sceNgs2SystemEnumHandles with a null array and a count of 4 returned 0x804A0053 (case 9.enum, line 16). Nothing faulted and the run ended with its END line (line 17). The entry now says that, and that a handler that succeeds was not measured. Only this one entry changes, as a new fragment in docs/dev/debt/changes/; no code does.

The handler that serves a 36-byte RIFF header with a fmt chunk and no data chunk was called 10 times (the last call at offset 12, size 8) and sceNgs2ParseWaveformUser still returned 0x804A0408 (case 3.parse, line 8). That is not recorded in the entry: the probe's waveform has no data chunk, so the result does not show what a successful parse returns, and a waveform with fmt and data was not measured.

Tested

Measured on a PS5 with firmware 11.60 (kernel_get_fw_version 0x11600005, line 1 of the raw output), from a homebrew payload process, on 2026-11-18 at 22:06 UTC (the console's own clock in the PROBE line reads 23:48:33Z, 1 h 42 min ahead of the runner's clock). A title process may differ. The cases are 0.dlopen to 9.enum, lines 2 to 16 of the raw output in the first comment. The signatures are not measured: the probe assumes ParseWaveformUser(handler, user_data, out_info), SystemEnumHandles(array, max) and SystemEnumRackHandles(system, array, max) (probe.c header comment), and presets its output buffers to 0xAA so that an unchanged output shows (info64 and arr in the raw output). dlsym of a name that does not exist returned 0 (case 1.ctrl, line 6).

Call PS5, payload process, firmware 11.60 the entry says here
handler returns -1 0x804A0408, 1 call (line 7) a negative return becomes 0x804A0408 entry states it is measured
null handler 0x804A0408, no call (line 12) the same entry states it
null output 0x804A0053, no call (line 14) 0x804A0053 entry states it
sceNgs2SystemEnumHandles(arr, 4), no system 0, array unchanged (line 9) the count of live systems entry states it
sceNgs2SystemEnumHandles(NULL, 4) 0x804A0053 (line 16) 0x804A0053 entry states it
sceNgs2SystemEnumRackHandles(0, arr, 4) 0x804A0230 (line 10) an unknown system 0x804A0230 entry states it

The right-hand statements are the entry's text, which describes libSceNgs2.native/src/System.cpp; that source was not read or run for this change. tools/check_conventions.py reports no error with this fragment added to main and debt_fold --check returns 0; the changed entry is 1512 characters without the list marker. This is a documentation change, so no test was added or run. Not tested: Linux, macOS, the CI runner, a title process, a created system, a handler that succeeds and firmware other than 11.60.

Overlap: counted on 2026-11-19 at 00:09 UTC from the 2024 open pull requests (file lists from the GitHub API; the ten with 100 or more files were read in full through the files API) against main at 973026d. This pull request adds one file, docs/dev/debt/changes/docs-libscengs2-parse-enum-measured.md, and no code; no open pull request has a file of that name. No open pull request changes docs/dev/debt/libSceNgs2.md, and the diffs of the Ngs2 pull requests that change libSceNgs2.native or add a Ngs2 fragment (#23227, #22860, #22536, #21141, #18501, #12315) do not name sceNgs2ParseWaveformUser, sceNgs2SystemEnumHandles or sceNgs2SystemEnumRackHandles; #22860 changes libSceNgs2.native/src/System.cpp in the sceNgs2SystemRender area only, and the entry cites that file without line numbers. A search of the open pull requests for the three function names finds nothing. This pull request does not depend on any of them (Depends on: none).

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

…firmware 11.60

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

xXPBSXx commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Probe source (built with ps5-payload-sdk; PROBE_BUILD is the first 12 hex digits of the source's SHA-256, 7faa89b3b11b) and its raw output from the run of 2026-11-18 at 22:06 UTC (runner clock). The clock in the PROBE line is the console's own clock. The probe never creates a system. In the first line of the header comment an internal label (N3) was removed; nothing else differs from the original, and the build ID is the hash of the original file. The comments in the source are in German.

probe.c
/* Probe cd2_ngs2_parse_v2 (Debt libSceNgs2.md:6): sceNgs2ParseWaveformUser und die Enumerierer
   sceNgs2SystemEnumHandles / sceNgs2SystemEnumRackHandles in libSceNgs2.sprx. Payload-Prozess, Firmware 11.60. KEIN
   sceNgs2SystemCreate. ABBRUCH ERWARTET moeglich: die Zeigerfaelle (NULL-Handler, NULL-Ausgabe, EnumHandles(NULL,4))
   stehen zuletzt und einzeln; ein SIGSEGV/SIGBUS wird als FAULT-Zeile mit END gemeldet. Aenderung gegen die erste Fassung:
   (1) Zeigerfaelle nach den Enum-Faellen, (2) Signal-Handler, (3) der Handler liefert jetzt ein echtes RIFF/WAVE
   (36 Byte, fmt-Chunk, PCM 16 Bit mono 48000) je nach offset/size statt Nullbytes - die erste Fassung gab bei
   Rueckgabe 0 ein ungueltiges RIFF und der Fall 3 war deshalb nicht aussagekraeftig. Signaturen NICHT gemessen:
   angenommen ParseWaveformUser(handler, user_data, out_info), SystemEnumHandles(array, max),
   SystemEnumRackHandles(system, array, max); Handler int handler(user, offset, data, size). */
#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>   /* nur fuer kernel_get_fw_version() */

#ifndef PROBE_NAME
#define PROBE_NAME "unnamed"
#endif
#ifndef PROBE_BUILD
#define PROBE_BUILD "unbuilt"
#endif
#ifndef PROBE_MAX_S
#define PROBE_MAX_S 50
#endif

static int cases = 0;
static const char* g_cur_id = "-";

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 void sig_handler(int s) {
  printf("CASE\t%s\tsignal during call\t%d\t0\tFAULT\n", g_cur_id, s);
  printf("END\t%d\n", cases + 1);
  fflush(stdout);
  _exit(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_note(const char* text) {
  printf("NOTE\t%s\n", text);
  fflush(stdout);
}

static void probe_end(void) {
  printf("END\t%d\n", cases);
  fflush(stdout);
}

static void hex(const unsigned char* p, int n, char* out) {
  static const char d[] = "0123456789abcdef";
  for (int i = 0; i < n; i++) {
    out[2 * i] = d[p[i] >> 4];
    out[2 * i + 1] = d[p[i] & 15];
  }
  out[2 * n] = 0;
}

typedef int (*handler_t)(uintptr_t, uint32_t, void*, size_t);
typedef int (*parse_t)(handler_t, uintptr_t, void*);
typedef int (*enum_sys_t)(void*, uint32_t);
typedef int (*enum_rack_t)(uintptr_t, void*, uint32_t);

static const unsigned char riff[36] = {'R', 'I', 'F', 'F', 0x1c, 0, 0, 0, 'W', 'A', 'V', 'E', 'f', 'm', 't', ' ', 16, 0, 0,
                                       0,   1,   0,   1,   0,    0x80, 0xbb, 0, 0, 0, 0x77, 1, 0, 2, 0, 16, 0};
static int hcalls = 0;
static int hret = 0;
static int hmode = 0;
static unsigned long hlast_off = 0, hlast_size = 0;

static int handler(uintptr_t user, uint32_t offset, void* data, size_t size) {
  (void)user;
  hcalls++;
  hlast_off = offset;
  hlast_size = size;
  if (hmode == 1 && data) {
    memset(data, 0, size);
    if (offset < sizeof riff) {
      size_t n = sizeof riff - offset;
      memcpy(data, riff + offset, n < size ? n : size);
    }
    return 0;
  }
  return hret;
}

static unsigned char info[512];

static void run_parse(const char* id, const char* call, parse_t f, handler_t h, void* out, int handler_ret, int mode) {
  char extra[700], hx[2 * 64 + 1];
  memset(info, 0xAA, sizeof info);
  hcalls = 0;
  hret = handler_ret;
  hmode = mode;
  hlast_off = hlast_size = 0;
  g_cur_id = id;
  errno = 0;
  int r = f(h, 0x1234, out);
  int er = errno;
  hex(info, 64, hx);
  snprintf(extra, sizeof extra, "ret32=0x%08x;handler_calls=%d;last_off=%lu;last_size=%lu;info64=%s", (unsigned)r,
           hcalls, hlast_off, hlast_size, hx);
  probe_case(id, call, r, er, extra);
}

int main(void) {
  signal(SIGALRM, probe_alarm);
  alarm(PROBE_MAX_S);
  probe_header();

  void* lib = dlopen("libSceNgs2.sprx", RTLD_LAZY);
  probe_case("0.dlopen", "dlopen(libSceNgs2.sprx)", lib != 0, 0, "-");
  if (!lib) { probe_end(); return 0; }
  parse_t parse = (parse_t)dlsym(lib, "sceNgs2ParseWaveformUser");
  enum_sys_t enum_sys = (enum_sys_t)dlsym(lib, "sceNgs2SystemEnumHandles");
  enum_rack_t enum_rack = (enum_rack_t)dlsym(lib, "sceNgs2SystemEnumRackHandles");
  void* ctrl_neg = dlsym(lib, "sceNgs2NoSuchFunctionControl");
  probe_case("1.name", "dlsym(sceNgs2ParseWaveformUser)", parse != 0, 0, "1 = name resolves");
  probe_case("1.name", "dlsym(sceNgs2SystemEnumHandles)", enum_sys != 0, 0, "-");
  probe_case("1.name", "dlsym(sceNgs2SystemEnumRackHandles)", enum_rack != 0, 0, "-");
  probe_case("1.ctrl", "dlsym(sceNgs2NoSuchFunctionControl) expect 0", ctrl_neg != 0, 0, "negative control");

  struct sigaction sa;
  memset(&sa, 0, sizeof sa);
  sa.sa_handler = sig_handler;
  sigaction(SIGSEGV, &sa, 0);
  sigaction(SIGBUS, &sa, 0);

  if (parse) {
    run_parse("2.parse", "ParseWaveformUser(handler ret -1, user, info)", parse, handler, info, -1, 0);
    run_parse("3.parse", "ParseWaveformUser(handler serves RIFF36, user, info)", parse, handler, info, 0, 1);
  }
  if (enum_sys) {
    unsigned long arr[4];
    memset(arr, 0xAA, sizeof arr);
    g_cur_id = "6.enum";
    errno = 0;
    int r = enum_sys(arr, 4);
    int er = errno;
    char extra[96], hx[2 * 32 + 1];
    hex((unsigned char*)arr, 32, hx);
    snprintf(extra, sizeof extra, "ret32=0x%08x;arr=%s", (unsigned)r, hx);
    probe_case("6.enum", "SystemEnumHandles(arr4,4)", r, er, extra);
  }
  if (enum_rack) {
    unsigned long arr[4];
    memset(arr, 0xAA, sizeof arr);
    g_cur_id = "8.rack";
    errno = 0;
    int r = enum_rack(0, arr, 4);
    probe_case("8.rack", "SystemEnumRackHandles(0,arr4,4)", r, errno, "-");
  }
  /* Zeigerfaelle zuletzt, jeweils einzeln; ein Signal beendet die Probe mit FAULT + END. */
  if (parse) {
    probe_note("next: ParseWaveformUser(NULL handler); a fault ends the run here");
    run_parse("4.parse", "ParseWaveformUser(NULL handler, user, info)", parse, 0, info, 0, 0);
    probe_note("next: ParseWaveformUser(handler, user, NULL out); a fault ends the run here");
    run_parse("5.parse", "ParseWaveformUser(handler serves RIFF36, user, NULL out)", parse, handler, 0, 0, 1);
  }
  if (enum_sys) {
    probe_note("last: SystemEnumHandles(NULL,4); a fault ends the run here");
    g_cur_id = "9.enum";
    errno = 0;
    int r = enum_sys(0, 4);
    probe_case("9.enum", "SystemEnumHandles(NULL,4)", r, errno, "-");
  }
  probe_end();
  return 0;
}
raw output (stdout)
PROBE	cd2_ngs2_parse_v2	fw=0x11600005	build=7faa89b3b11b	pid=342	utc=2026-11-18T23:48:33Z
CASE	0.dlopen	dlopen(libSceNgs2.sprx)	1	0	-
CASE	1.name	dlsym(sceNgs2ParseWaveformUser)	1	0	1 = name resolves
CASE	1.name	dlsym(sceNgs2SystemEnumHandles)	1	0	-
CASE	1.name	dlsym(sceNgs2SystemEnumRackHandles)	1	0	-
CASE	1.ctrl	dlsym(sceNgs2NoSuchFunctionControl) expect 0	0	0	negative control
CASE	2.parse	ParseWaveformUser(handler ret -1, user, info)	-2142632952	0	ret32=0x804a0408;handler_calls=1;last_off=0;last_size=4;info64=0000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
CASE	3.parse	ParseWaveformUser(handler serves RIFF36, user, info)	-2142632952	0	ret32=0x804a0408;handler_calls=10;last_off=12;last_size=8;info64=0000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
CASE	6.enum	SystemEnumHandles(arr4,4)	0	0	ret32=0x00000000;arr=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
CASE	8.rack	SystemEnumRackHandles(0,arr4,4)	-2142633424	0	-
NOTE	next: ParseWaveformUser(NULL handler); a fault ends the run here
CASE	4.parse	ParseWaveformUser(NULL handler, user, info)	-2142632952	0	ret32=0x804a0408;handler_calls=0;last_off=0;last_size=0;info64=0000000000000000aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
NOTE	next: ParseWaveformUser(handler, user, NULL out); a fault ends the run here
CASE	5.parse	ParseWaveformUser(handler serves RIFF36, user, NULL out)	-2142633901	0	ret32=0x804a0053;handler_calls=0;last_off=0;last_size=0;info64=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
NOTE	last: SystemEnumHandles(NULL,4); a fault ends the run here
CASE	9.enum	SystemEnumHandles(NULL,4)	-2142633901	0	-
END	12

@github-actions github-actions Bot added the docs label Nov 19, 2026
@oneandonlydean
oneandonlydean merged commit d44cbb3 into boykopovar:main Nov 19, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants