Skip to content

docs(debt): record the wait4, wait3 and _wait4 results without a child on firmware 11.60 - #22494

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:docs/libkernel-sys-wait4-no-child-console-1160
Nov 18, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:docs/libkernel-sys-wait4-no-child-console-1160

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

What

The wait3 and wait4 entry and the _wait4 entry in docs/dev/debt/libkernel_sys.md say that Windows child resource accounting is not implemented and that the console behaviour is unverified (for _wait4 as a whole). A probe has now called all three in libkernel.sprx from 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 errno 10 (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, ...) and wait4(0x7fffffff, ...) with WNOHANG (1.3 and 1.4, lines 6 and 7), wait4 with the option value 0x80000000 (1.5, line 8), wait4 with 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 blocking wait4(-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 outside freebsdWaitOptions (line 88, 0x8000003F, which contains bit 31), and for a process without a registered child WaitChildProcess_nid_no_patch (libc/src/Process.cpp, lines 321 to 327) returns -2, which is turned into ECHILD before status or rusage are touched (Process.cpp lines 731 to 734). wait3 and _wait4 call wait4 (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's wait4 answers instead. The test GuestKernelSysWait already pins ECHILD for 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_version 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr) that loads libkernel.sprx and takes wait4, wait3 and _wait4 with dlsym, 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.

Call PS5 payload process, firmware 11.60 AnyPS5 main (code read, not run) in the entry
wait4(-1, &status, WNOHANG, NULL), and with a rusage buffer -1, ECHILD, status and rusage unchanged (lines 4, 5) ECHILD now stated
wait4(1, ...), wait4(0x7fffffff, ...) with WNOHANG -1, ECHILD (lines 6, 7) ECHILD now stated
wait4(-1, &status, 0x80000000, NULL) -1, ECHILD (line 8) ECHILD (the option mask includes bit 31) now stated
wait4(-1, NULL, WNOHANG, NULL) -1, ECHILD (line 9) ECHILD now stated
wait3(&status, WNOHANG, NULL) -1, ECHILD (line 10) ECHILD now stated
_wait4(-1, &status, WNOHANG, NULL) -1, ECHILD (line 11) ECHILD now stated
blocking wait4(-1, &status, 0, NULL) -1, ECHILD, no wait (line 12) ECHILD now stated

tools/check_conventions.py --base upstream/main passes 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.cpp or core/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 in docs/dev/debt/libkernel_sys.md and in the fragments under docs/dev/debt/changes/ for wait3, wait4 and _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 against main 4b83e9d2234 (the branch is based on e7988a85b0a, an ancestor of it) and merges into it without a conflict; tools/debt_fold.py --check applies the fragment to the libkernel_sys debt file of main without an error (checked without the fragment libressl3-20171-inventory.md, which already conflicts with feat-libressl3-evp-pkey-new-mac-key-v2.md on main and 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 the libkernel_web _wait4 to the libkernel_sys implementation and says in its own fragment that the limits in the libkernel_sys debt 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 names wait3, wait4 or _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

  • 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 (documentation only)
  • AI-assisted: yes

…d on firmware 11.60

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

xXPBSXx commented Nov 17, 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, 973a02f10603) and its raw output from the run on 2026-11-17 at 14:05 UTC. The clock in the PROBE line is the console's own clock. The probe loads libkernel.sprx, takes wait4, wait3 and _wait4 with dlsym and calls them without any child process: wait4 with WNOHANG for pids -1, 1 and 0x7fffffff, with a 144-byte rusage buffer, with the option value 0x80000000 and with a null status pointer, then wait3 and _wait4, and last one blocking wait4; every call is guarded against signals and by a self limit. An internal probe number in the header comment was removed; the code is unchanged, and the build ID is the hash of the original file.

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;
}
stdout
PROBE	libkernel_sys_wait4_nochild	fw=0x11600005	build=973a02f10603	pid=221	utc=2026-11-17T15:47:34Z
CASE	0	load libkernel.sprx	0	2	loaded
CASE	0b	dlsym of the functions	0	0	wait4=1 wait3=1 _wait4=1
CASE	1.1	wait4(-1, &status, WNOHANG, NULL)	-1	10	rc=-1 errno=10 status_changed=0 rusage_changed=-1
CASE	1.2	wait4(-1, &status, WNOHANG, &rusage)	-1	10	rc=-1 errno=10 status_changed=0 rusage_changed=0
CASE	1.3	wait4(1, &status, WNOHANG, NULL)	-1	10	rc=-1 errno=10 status_changed=0 rusage_changed=-1
CASE	1.4	wait4(0x7fffffff, &status, WNOHANG, NULL)	-1	10	rc=-1 errno=10 status_changed=0 rusage_changed=-1
CASE	1.5	wait4(-1, &status, options 0x80000000, NULL)	-1	10	rc=-1 errno=10 status_changed=0 rusage_changed=-1
CASE	1.6	wait4(-1, NULL, WNOHANG, NULL)	-1	10	rc=-1 errno=10 status_changed=-1 rusage_changed=-1
CASE	2	wait3(&status, WNOHANG, NULL)	-1	10	rc=-1 errno=10 status_changed=0
CASE	3	_wait4(-1, &status, WNOHANG, NULL)	-1	10	rc=-1 errno=10 status_changed=0 rusage_changed=-1
CASE	4	wait4(-1, &status, 0, NULL) blocking, no child	-1	10	rc=-1 errno=10 status_changed=0 rusage_changed=-1
END	11

AI-assisted (Claude Code).

@github-actions github-actions Bot added the docs label Nov 17, 2026
@oneandonlydean
oneandonlydean merged commit 64da164 into boykopovar:main Nov 18, 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