feat(libSceLibcInternal): implement posix_spawn process creation and reaping #9133
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9133"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-21T12:57:48Z.
What
posix_spawnandposix_spawnp(libSceLibcInternal) create a real child process, andwaitpid/wait(libkernel) reap it. The child runs the already-converted image of the requested guest program: the path must be under/app0/(/app0/eboot.binmaps to the running image itself; anything else is found beside the running image under its flattened name),posix_spawnpsearchesPATHas FreeBSD 11's_execvpedoes (_PATH_DEFPATHwhen unset,ENOENTotherwise), file actions and attributes come from the FreeBSD 11.4 objects, a nullargvreturnsEFAULT(14) and a nullenvpgives the child the parent's environment. Guest process IDs are the host's on both hosts. On Linux the spawn delegates to the hostposix_spawnwith full file-action fidelity and thePOSIX_SPAWN_RESETIDS/POSIX_SPAWN_SETPGROUPflags translated. On Windows the child keeps the parent's stdin/stdout/stderr through duplicated inheritable handles with aSTARTF_USESTDHANDLEShandle list, file actions deliver only descriptors 0-2 (addopen/adddup2/addclose; a target beyond that throws), and a nonzero attribute flag set throws where FreeBSD would apply signal attributes.waitpidreaps these children: on Linux straight from the host call with the stopped child's signal, from bits 8-15, and a killed child's signal, from bits 0-6, translated to the guest's BSD numbering (7, 10, 12, 17, 18, 19, 20, 23, 29, 31 -> 10, 30, 31, 20, 19, 17, 18, 16, 23, 12; Linux 16 and 30 throw), a continued status reported as 0x13, and the guestWCONTINUEDoption (4) translated to Linux's 8; on Windows through a child-handle registry in libc (internal glue NIDsRegisterChildProcess_nid_no_patch/WaitChildProcess_nid_no_patch, needed because libSceLibcInternal imports libc but not libkernel) with an exit-status decode: host exit codes keep the guestexitbyte layout, access violation/stack overflow ->SIGSEGV, illegal instruction ->SIGILL, breakpoint ->SIGTRAP, division ->SIGFPE, fastfail/heap corruption ->SIGABRT, and any other code, including a guestexit(-1)(0xFFFFFFFF), keeps the guestexitbyte layout; no stop/continue states are ever produced on Windows. Unknownoptionsbits keepEINVAL; calls without aposix_spawnchild keepECHILD. Limitations are recorded in the debt notes: the child executes the conversion made at relink time, and the console spawn sandbox is unverified.Tested
Windows 11 x64, MinGW-w64 GCC 15.2:
guest_posix_spawnpasses, including the new real-execution coverage (two staged child copies: immediate exit 42 reaped, sleeping child reportingWNOHANGand reaped with 43, thenECHILDwith untouchederrno) and the waitpid rows: a naturalexit(-1)reading as 255, andTerminateProcesscodes 0xC0000005 -> 11, 0xC0000096 -> 4, 0x80000003 -> 5, 0xC0000094 -> 8 and 0xC0000409 -> 6 through the decoder; all pre-existing FreeBSD error-path locks still pass.guest_waitpid,guest_kernel_sys,guest_system_exit,guest_system_exit_parametersandloadexec_argumentspass with the rebuiltlibc,libkernelandlibSceSystemService. Linux x64 Debian (gcc 14.2, WSL2 native ext4):guest_posix_spawn(same real-child coverage plus the waitpid rows:WUNTRACEDreports a stopped child as guest 17 keeping the 0x7f marker,SIGCONTcontinues it andWCONTINUEDreports 0x13, then exit 44; killed rowsSIGBUS7 -> 10 andSIGSYS31 -> 12),guest_waitpid,guest_kernel_sys,guest_system_exit,guest_system_exit_parametersandloadexec_argumentsall pass.guest_kernel_sysfails only when run from a/mnt/ddrvfs working directory (the directory rename/replacement marker behind it), reproduced before this change as well and unrelated to the spawn/waitpid diff. PPSA99305 (Dusklight) not run end to end; the spawn path it reaches is covered byguest_posix_spawn.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)zenitythroughposix_spawn); other spawn/waitpid titles from discussion #7971 (aforkfollow-up stays separate)Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T07:51:31Z.
The reverted-function flag is the progress bot's stub classifier, not an actual revert.
tools/progress.pycounts a function as implemented only when its body — directly or through any helper — no longer reachesNotImplemented_nid_no_patch(theSTUB_WRAPPERclosure feedingscan_library). Thewaitpidchange could not avoid that: its Linux arm throws for child-death signals 16/29/30 that have no mapping on the console's BSD axis, which the project convention requires (unrepresentable behaviour throws and is recorded indocs/dev/debt/libkernel.md). Everything else inwaitpidis implemented and covered byguest_waitpid; the old code simply failed those cases silently, which is why the base counted it as done.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-23T20:15:21Z.
Review: CHANGES_REQUESTED
Thanks, the structure is good (Linux host
posix_spawn, Windows child registry in libc, debt notes). A few things to fix before merge:core/libs/prx/libkernel/System/src/Process.cpp:466-479(Linuxwaitpid): a stopped status is(signal << 8) | 0x7f, but(encoded & ~0x7f) | 10writes the BSD number into the low bits and destroys the0x7fmarker. Translate the signal in bits 8-15 forWIFSTOPPED, and in bits 0-6 only forWIFSIGNALED.WUNTRACED, a stopped child reports the wrong signal today (SIGSTOP would read as SIGCHLD...). Please map the whole table (FreeBSDsys/sys/signal.h) and throw only for the unmapped ones, with a test using a child that stops/is killed.WCONTINUEDis 4 on FreeBSD but 8 on Linux, sooptions & (WNOHANG | WUNTRACED | WCONTINUED)silently drops it; translate the bit, and the continued status (0xffffon Linux,SIGCONT << 8 | 0x7f-style 0x13 on FreeBSD).core/libs/prx/libc/src/Process.cpp:295-312(Windows): any exit code >= 0x80000000 throws as "not representable", including a guestexit(-1)/exit(255)seen as 0xFFFFFFFF. Please show how the guestexitstatus reachesExitProcessand keep that layout for it (only NTSTATUS-looking codes with the 0xC/0x8 severity should hit the signal mapping), with a test row forexit(-1).core/libs/prx/libc/src/Process.cpp:357-365:WaitForMultipleObjects(..., 250)runs withchildProcessMutexheld, so everyRegisterChildProcess/otherwaitpidstalls up to 250 ms per 64 children. Copy the handles under the lock and wait outside it (and drop thehangname: that flag isWNOHANG).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T06:30:46Z.
Review: CHANGES_REQUESTED
Thanks for the update. The new head only changes docs and the Apple
_NSGetExecutablePathdeclaration; the points from the previous review are still open:core/libs/prx/libkernel/System/src/Process.cpp:466-479(Linuxwaitpid):(encoded & ~0x7f) | 10still overwrites the low 7 bits, so a stopped status(sig << 8) | 0x7floses its marker. Translate the signal in bits 8-15 forWIFSTOPPED, bits 0-6 forWIFSIGNALED.sys/sys/signal.h(SIGCHLD 17→20, SIGCONT 18→19, SIGSTOP 19→17, SIGTSTP 20→18, SIGURG 23→16, SIGIO 29→23, SIGSYS 31→12) and throw only for unmapped ones.WCONTINUEDis 4, Linux's is 8, sooptions & (WNOHANG | WUNTRACED | WCONTINUED)drops it. Translate the bit and the continued status.core/libs/prx/libc/src/Process.cpp:295-312(Windows): every code >= 0x80000000 throws, including a guestexit(-1)(0xFFFFFFFF). Keep the guest exit layout and only map NTSTATUS-looking codes (0xC/0x8 severity) as signals; add a test row forexit(-1).core/libs/prx/libc/src/Process.cpp:357-365:WaitForMultipleObjects(..., 250)still runs underchildProcessMutex. Copy the handles under the lock and wait outside it (and renamehang, that flag isWNOHANG).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T14:44:27Z.
Review: CHANGES_REQUESTED
Re-checked on 21b467c6c9: the stopped/killed status marker and the signal table (FreeBSD 11.4 numbering) are now right, and the earlier points are met.
One point left:
core/libs/prx/libc/src/Process.cpp:352-353(WindowsWaitChildProcess_nid_no_patch): if another thread reaps the child this call is waiting for, the loop never returns. With no children left,continuespins forever; with other children left, it waits on them instead of failing. POSIX returnsECHILDin that case. Buildhandlesonly from the children matchingprocessId, and return -2 when none is left.Please also add a test that two waiters on one child don't both block (or a note in the debt if it can't be tested on Windows).