Repository navigation
docs(debt): record the wait4, wait3 and _wait4 results without a child on firmware 11.60 - #22494
Conversation
…d on firmware 11.60 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Probe source (built with ps5-payload-sdk v0.45; probe.c/* wait4, wait3 and _wait4 without a child process, payload process, firmware 11.60 (debt libkernel_sys.md wait3 and
wait4 entry: Windows child resource accounting is not implemented; and _wait4 is unverified on the console, it follows
FreeBSD 11.4 where _wait4 is the wait4 system call under its underscore name). The probe starts no process: no fork,
vfork, execve or posix_spawn is called, so there is no child to wait for. It looks wait4, wait3 and _wait4 up with dlsym
in libkernel.sprx and calls: wait4(-1, &status, WNOHANG, NULL); wait4(-1, &status, WNOHANG, &rusage) with a 144-byte
rusage filled with 0xaa (does it change on ECHILD); wait4(1, ...) and wait4(0x7fffffff, ...) with WNOHANG; wait4(-1, ...)
with options 0x80000000 (invalid options); wait4(-1, NULL, WNOHANG, NULL); wait3(&status, WNOHANG, NULL) and
_wait4(-1, &status, WNOHANG, NULL) where exported; and, last, one blocking wait4(-1, &status, 0, NULL), which can only
return ECHILD at once or block until the 50 s safeguards of the probe end it. The status word is filled with
0x5a5a5a5a before each call and reported as changed or not. 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 volatile int g_handle = -1;
static int (*volatile g_setmargins)(int, int, int) = 0; /* unused here */
static void reset_rate(void) {
if (g_setmargins && g_handle >= 0) g_setmargins(g_handle, 0, 0);
}
static void probe_alarm(int sig) {
static const char msg[] = "TIMEOUT\tprobe self limit\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
reset_rate();
_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);
reset_rate();
_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);
}
#include <sys/wait.h>
#include <sys/resource.h>
typedef int (*fn_wait4)(int, int*, int, void*);
typedef int (*fn_wait3)(int*, int, void*);
static void fault(int sig) {
static const char msg[] = "FAULT\tsignal in the call\n";
(void)sig;
(void)!write(1, msg, sizeof msg - 1);
_exit(125);
}
static void w4_case(const char* id, const char* label, fn_wait4 f, int pid, int options, int use_status, int use_ru) {
int status = 0x5a5a5a5a;
unsigned char ru[144];
memset(ru, 0xaa, sizeof ru);
char extra[120];
errno = 0;
int r = f(pid, use_status ? &status : 0, options, use_ru ? (void*)ru : 0);
int e = errno, ru_changed = 0;
for (size_t i = 0; i < sizeof ru; ++i) if (ru[i] != 0xaa) ru_changed++;
snprintf(extra, sizeof extra, "rc=%d errno=%d status_changed=%d rusage_changed=%d", r, e, use_status ? status != 0x5a5a5a5a : -1,
use_ru ? ru_changed : -1);
probe_case(id, label, r, e, extra);
}
int main(void) {
signal(SIGALRM, probe_alarm);
signal(SIGSEGV, fault);
signal(SIGBUS, fault);
alarm(PROBE_MAX_S);
probe_header();
char extra[160];
errno = 0;
void* lk = dlopen("libkernel.sprx", RTLD_LAZY);
probe_case("0", "load libkernel.sprx", lk ? 0 : -1, errno, lk ? "loaded" : dlerror());
if (!lk) { probe_end(); return 0; }
fn_wait4 w4 = (fn_wait4)dlsym(lk, "wait4");
fn_wait3 w3 = (fn_wait3)dlsym(lk, "wait3");
fn_wait4 uw4 = (fn_wait4)dlsym(lk, "_wait4");
snprintf(extra, sizeof extra, "wait4=%d wait3=%d _wait4=%d", w4 != 0, w3 != 0, uw4 != 0);
probe_case("0b", "dlsym of the functions", 0, 0, extra);
if (w4) {
w4_case("1.1", "wait4(-1, &status, WNOHANG, NULL)", w4, -1, WNOHANG, 1, 0);
w4_case("1.2", "wait4(-1, &status, WNOHANG, &rusage)", w4, -1, WNOHANG, 1, 1);
w4_case("1.3", "wait4(1, &status, WNOHANG, NULL)", w4, 1, WNOHANG, 1, 0);
w4_case("1.4", "wait4(0x7fffffff, &status, WNOHANG, NULL)", w4, 0x7fffffff, WNOHANG, 1, 0);
w4_case("1.5", "wait4(-1, &status, options 0x80000000, NULL)", w4, -1, (int)0x80000000, 1, 0);
w4_case("1.6", "wait4(-1, NULL, WNOHANG, NULL)", w4, -1, WNOHANG, 0, 0);
}
if (w3) {
int status = 0x5a5a5a5a;
errno = 0;
int r = w3(&status, WNOHANG, 0);
snprintf(extra, sizeof extra, "rc=%d errno=%d status_changed=%d", r, errno, status != 0x5a5a5a5a);
probe_case("2", "wait3(&status, WNOHANG, NULL)", r, errno, extra);
}
if (uw4) w4_case("3", "_wait4(-1, &status, WNOHANG, NULL)", uw4, -1, WNOHANG, 1, 0);
if (w4) w4_case("4", "wait4(-1, &status, 0, NULL) blocking, no child", w4, -1, 0, 1, 0);
probe_end();
return 0;
}stdoutAI-assisted (Claude Code). |
What
The
wait3 and wait4entry and the_wait4entry indocs/dev/debt/libkernel_sys.mdsay that Windows child resource accounting is not implemented and that the console behaviour is unverified (for_wait4as a whole). A probe has now called all three inlibkernel.sprxfrom a payload process on firmware 11.60 that has no child process. The pull request adds what it measured to both entries through a debt fragment, as the contribution rules ask; no code changes.On firmware 11.60 all 9 calls returned -1 with
errno10 (ECHILD):wait4(-1, &status, WNOHANG, NULL)(case 1.1, line 4), the same with a 144-byte rusage buffer (1.2, line 5),wait4(1, ...)andwait4(0x7fffffff, ...)withWNOHANG(1.3 and 1.4, lines 6 and 7),wait4with the option value 0x80000000 (1.5, line 8),wait4with a null status pointer (1.6, line 9),wait3(&status, WNOHANG, NULL)(2, line 10),_wait4(-1, &status, WNOHANG, NULL)(3, line 11) and a blockingwait4(-1, &status, 0, NULL)(4, line 12), which returned at once instead of waiting. The status word, filled with 0x5a5a5a5a beforehand, was unchanged wherever one was passed, and none of the 144 bytes of the rusage buffer changed (line 5).AnyPS5 gives the same for every one of these when its code is read, including the option value 0x80000000:
WaitProcess_nid_no_patch(libkernel/System/src/Process.cpp, line 724) rejects only option bits outsidefreebsdWaitOptions(line 88, 0x8000003F, which contains bit 31), and for a process without a registered childWaitChildProcess_nid_no_patch(libc/src/Process.cpp, lines 321 to 327) returns -2, which is turned intoECHILDbefore status or rusage are touched (Process.cpplines 731 to 734).wait3and_wait4callwait4(libkernel_sys/Wait.cpp, lines 6 to 12;AdditionalExports.cpp, line 460). Those lines are the Windows branch (#ifdef _WIN32); on Linux and macOS the host'swait4answers instead. The testGuestKernelSysWaitalready pinsECHILDfor these option values and leaves status and rusage unchanged on every host (lines 81 to 95), except that for the most negative pid it expects the host's own error (lines 86 to 90); the emulator itself was not run for this pull request.Not measured: a process with a child (including what the console returns for resource accounting and for the option value 0x80000000 when a child exists), and a title process.
Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr) that loadslibkernel.sprxand takeswait4,wait3and_wait4withdlsym, on 2026-11-17 at 14:05 UTC. A title process may differ. The cases are 0 to 4, lines 2 to 12 of the raw output in the first comment.main(code read, not run)wait4(-1, &status, WNOHANG, NULL), and with a rusage bufferECHILD, status and rusage unchanged (lines 4, 5)ECHILDwait4(1, ...),wait4(0x7fffffff, ...)withWNOHANGECHILD(lines 6, 7)ECHILDwait4(-1, &status, 0x80000000, NULL)ECHILD(line 8)ECHILD(the option mask includes bit 31)wait4(-1, NULL, WNOHANG, NULL)ECHILD(line 9)ECHILDwait3(&status, WNOHANG, NULL)ECHILD(line 10)ECHILD_wait4(-1, &status, WNOHANG, NULL)ECHILD(line 11)ECHILDwait4(-1, &status, 0, NULL)ECHILD, no wait (line 12)ECHILDtools/check_conventions.py --base upstream/mainpasses with no error and no warning (the two entries are now 709 and 604 characters, up from 296 and 391). This is a documentation change, so no test was added or run, and no GPU test applies. Not tested: the emulator against these calls, a title process, other firmware, and the cases listed above as not measured.Overlap: the other open pull requests that change the file of this branch (the fragment
docs/dev/debt/changes/docs-libkernel-sys-wait4-no-child-console-1160.md, a new file),core/libs/prx/libkernel_sys/Wait.cpporcore/libs/prx/libkernel_sys/AdditionalExports.cpp, which the two entries link, or the debt entries it changes, found by reading the changed files of all 1735 open pull requests at about 16:37 UTC, by reading what they change indocs/dev/debt/libkernel_sys.mdand in the fragments underdocs/dev/debt/changes/forwait3,wait4and_wait4, and by searching their titles and branch names for the same names, were test-merged on 2026-11-17 at about 17:30 UTC againstmain4b83e9d2234(the branch is based one7988a85b0a, an ancestor of it) and merges into it without a conflict;tools/debt_fold.py --checkapplies the fragment to thelibkernel_sysdebt file ofmainwithout an error (checked without the fragmentlibressl3-20171-inventory.md, which already conflicts withfeat-libressl3-evp-pkey-new-mac-key-v2.mdonmainand is not part of this change), the text each change names occurs in exactly one entry, and no other fragment changes those entries. Eight pull requests list one of the two source files; as this branch adds only a fragment, none of them conflicts only with this change. One of them names the function: #21989 (feat(libkernel_web): forward _wait4, __sys_is_development_mode and __sys_namedobj_create) forwards thelibkernel_web_wait4to thelibkernel_sysimplementation and says in its own fragment that the limits in thelibkernel_sysdebt apply to it; it changes a different entry, not the two entries of this branch, and it does not change what these entries say about the console. #18190, #18112, #17908, #17897, #17885, #12315 and #6918 list the files without changing a line that nameswait3,wait4or_wait4. No open pull request changes the two debt entries this fragment changes. The merged result was not built or run; this is a documentation change.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)