feat(libkernel_sys): export fork and implement setsid and umask #3160
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3160"
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 babyhuey on 2026-10-10T23:36:19Z.
What
Three
libkernel_sysexports that XashPS5 (PPSA19111) imports and fails to load without:fork(cjt-4ySmYTs) throwsNotImplemented, since creating a child process is not supported (the same asexecvpin #2827).setsid(edJoqV2FIWs) fails withEPERM, as FreeBSD's does for a process group leader. The guest is already taken to lead its own process group (TechnicalDebt forkill).umask(Rb6ziJKvCCQ) keeps the guest's mask (initially 022, masked to 0777) and returns the previous one. Files are still created with the host process's mask; TechnicalDebt says so.XashPS5's engine (Xash3D FWGS
engine/platform/posix/sys_posix.c, as @SleglJan traced below) calls them from two functions:Posix_Daemonize(fork,setsid,umask), only with-daemonize, andPlatform_ShellExecute(fork, thenexecvp("xdg-open")), which the main menu's Previews button reaches. Neither runs during start-up, but pressing Previews ends in theforkthrow; TechnicalDebt says so.On
mainad336923(catalog build,eboot.binandsce_module/libc.prxunwrapped as #2605 requires; tracked in #1578), now thatrealpath(#3147) is in:main, Linux:app.elf: symbol lookup error: app.elf: undefined symbol: cjt-4ySmYTsmain, Windows:FAIL: unresolved ELF import cjt-4ySmYTs (fork) from libkernel_sys.prxforkalone:edJoqV2FIWs(setsid); withsetsidtoo:Rb6ziJKvCCQ(umask)main77bd928a(afterctime, #3201), Linux:app.elf: symbol lookup error: app.elf: undefined symbol: 5AMS0IntU8I(creat)Tested
Linux (Ubuntu 24.04, GCC 13, Release) on
ad336923:guest_kernel_syspasses 5/5 (--repeat until-fail:5). The new cases check thatsetsidreturns -1 withEPERM, and thatumaskreturns 022 at first, keeps only the permission bits of07777, and returns the previous mask each time. There is no test for theforkexport, since it only throws.check_conventions.pypasses. Windows 11 (MinGW-w64 GCC 15.2 from WinLibs, Release):guest_kernel_sys5/5 with no warnings; with this PR XashPS5 gets pastforkand the Windows loader reportsFAIL: unresolved ELF import 5AMS0IntU8I (creat) from libkernel.prxfirst, which is also missing onmainand is now the Linux stop as well.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T23:36:45Z.
Progress report (
833e5eb→d4b9808)📉 System libraries: 85.78% (-0.02%, +2 implemented, +1 declared functions)
✅ 2 implemented
setsid_nid_postfixumask_nid_postfix🆕 1 declared as stubs
fork_nid_postfixImported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-10T23:45:05Z.
Linux cross-test of 6b7213af merged onto
mainc0763883. Setup: CachyOS (kernel 7.2.9, GCC 16.2.1), RTX 3080 (NVIDIA 615.71.09), Release, SPIRV-Tools on.guest_kernel_syspasses 5/5. Of the 746 tests in the full suite, 741 pass and 4 are skipped:video_out_flip_*, under the offscreen SDL driver. One fails:agc_driver_dcc_keys_first_write(#2767).check_conventions.pypasses.eboot.binandsce_module/libc.prxunwrapped. Onmainthe loader stops oncjt-4ySmYTs, with 17 absent imports in the audit. With this PR, 14 are absent and it stops on0uAUs3hYuG4(ctime), as in your Linux line.Two notes:
Where
forkis called. In the engine source,forksits in two functions, not one. The source is Xash3D FWGS at 1414fc28, the engine commit xash3d-ps5 builds on, inengine/platform/posix/sys_posix.c:Platform_ShellExecuteis at 0x87250 in the eboot. It callsforkat 0x87275, thenexecvp("xdg-open").Posix_Daemonizeis at 0x872d0. It checks-daemonize, then callsforkat 0x872e8,setsidat 0x872f8 andumaskat 0x87308.Your 0x87275 is the first of these
forkcalls. The main menu's Previews button callsPlatform_ShellExecutethroughEngFuncs::ShellExecute(menus/Main.cpp), and the port's mainui patch keeps that button. Its URL defaults to the Steam store page (mainui string 402, which is in the eboot), so the button works unless a game'sstrings.lstblanks the string. Pressing Previews therefore reaches the throw. That may be worth a clause in theforkTechnicalDebt entry.Pinning the throw.
guest_execvpchecks its message, and the same works forforkinGuestKernelSys.cpp. It needs#include <stdexcept>andint APS5_VABI fork_nid_postfix(void);in theextern "C"block:Then add
Require(ForkReportsNotImplemented());inmain. I had the same check on a branch I didn't open once this PR appeared. There it fails ifforksets an error and returns -1 instead of throwing.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T23:45:45Z.
Review: COMMENTED
The bar is answered before anyone has to ask: XashPS5 (PPSA19111) imports all three, fails to load without them, and the routine that calls them is given by address. Everything after that follows from the fact that this is a system library with no child processes behind it.
forkthrowing is the honest choice, and citingexecvpin #2827 makes it a decision rather than a gap.setsidfailing withEPERMas FreeBSD does for a process group leader — with the note that the guest is already taken to lead its own group, cross-referencing thekillentry — is the detail that stops that one looking arbitrary. Andumaskkeeping the guest's mask, seeded at 022 and masked to 0777 with the previous value returned, is the right half of that call to implement.The limitation is stated rather than hidden, which is the part worth keeping: files are still created with the host process's mask, and the entry says so. That is the one place a guest could notice — set a restrictive mask, create a file, read its mode back, and the answer comes from the host — so naming it is what makes this landable as a partial implementation rather than a wrong one. If a title ever reaches that check, the entry is where the next person will look first.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T00:31:30Z.
@SleglJan thanks for tracing the call sites, my "one routine" was wrong. I pushed a commit that names both functions in the
forkTechnicalDebt entry, including that the Previews button reaches the throw, and updated the description to match.On the test: I left
forkout on purpose, since @oneandonlydean asked on #2887 that exports which only throw don't get a test ("stubs don't need a test"). Happy to add yours if a maintainer would rather have it here.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:12:54Z.
Checked build and
guest_kernel_syson Linux (merged onto currentmain); the test doesn't link without the change. Third-party Linux/Windows runs in the thread cover XashPS5.One fix, pushed as a commit on top:
umaskmasked the new value with0777, but FreeBSD'ssys_umask(sys/kern/vfs_syscalls.c) storesnewmask & ALLPERMS(07777). Changed inExport.cpp, the test (umask(07777)thenumask(022)returns07777) and the TechnicalDebt line.Merging once CI is green.