fix(libc): start the guest environment empty instead of copying the host's #5772
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5772"
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 DavidSamir on 2026-10-14T10:02:03Z.
What
PS5MC (PPSA99420) exits about a second after start with
XBMC_Run returned -1(exit code -1) when the host hasHOMEset. The guest environment is copied from the host's, so Kodi'sgetenv("HOME")returns a host path (C:\Users\<name>on Windows,/home/<name>on Linux) and it builds its profile folder from it (C:\Users\<name>/.kodi), which it then cannot use. WithoutHOMEin the host environment the title keeps running.HOMEis set on every Linux system, and on Windows by Git for Windows, MSYS2 and Cygwin shells, so this hits anyone who starts a title from them. On the console a title starts with no such variable, and libkernel'senvironexport is already an empty environment (#2090).Cause.
Environment()seeds the guest environment from the host CRT's_environ/environon first use, so every host variable (HOME,PATH,USERPROFILE,TEMPand the rest) is visible togetenv.The guest environment now starts empty.
getenv,setenv,unsetenvandputenvwork as before on the variables the title sets itself, and the host environment is still never changed. The runtime's own settings (APS5_TRACE_CALLS,ANYPS5_SYSTEM_FONTSand the others) are read by host code with the hostgetenv, so they are unaffected.Three commits:
fix(libc): start the guest environment empty instead of copying the host's:Environment.cpp, andguest_environment's first checks, which encoded the inheritance: a variable set in the host now reads as absent in the guest, and the host value is unchanged after guestsetenv.test(libc): keep the host's HOME and PATH out of the guest environment: withHOMEset in the host,getenv("HOME")andgetenv("PATH")in the guest return null.docs(debt): record that the guest environment starts empty.There is no fourth step to split out; the change is one function.
Tested
Windows (
69715e839onmain78f1aea70, Windows 11 10.0.26300, WinLibs GCC 15.2.0 r7, Release):HOMEset in the host (C:\Users\<name>), alternating: withmain's libraries it exits with code -1 after 4 s and after 1 s, its last log line[kodi-ps5] heap: 2048 MiB of direct memory; with the branch's it is still running at 40 s both times. Run withoutHOMEin the host, it keeps running withmain's libraries too. The exit messageXBMC_Run returned -1and the pathC:\Users\<name>/.kodiwere on the stack whenLibcTerminate_nid_no_patchwas reached (gdb).Environment.cppas onmainand the tests kept,guest_environmentaborts (exit 0xc0000409) at the first new check, a host variable visible to the guest. With the change it passes 5/5 (--repeat until-fail:5), andguest_getopt,guest_call_trace,guest_call_trace_abort,guest_font,guest_font_writing_line,guest_hostname,guest_audio_in_capture,guest_audio_in_no_device,file_streamsandguest_posix_filesystempass 3/3. These include the tests that set host variables for the runtime's own settings andgetopt'sPOSIXLY_CORRECT, set through the guest'ssetenv.main's libraries and with the branch's,HOMEset in the host, windows kept off-screen: ccleste (PPSA59322), RommPS (PPSA76677), SwanStationPS5 (PPSA98510), ProsperoTV (PPSA99003), DOOM (PPSA99666), ScreenTester5 (PPSA69420), Prospero Vibrate (PPSA99920), SymphonyStation5 (PPSA17641), ProsperoStore (PPSA99000), OpenNOW (PPSA99082), ProsperoRadio (PPSA99001) and PSXS5 (PPSA97510) are all still running at 35 s with both, with the same last kind of log line. PSXS5 logged fewer periodic statistics lines in the first pair of runs; four more alternating runs gave 82 lines with each set.fdopenprobe that changes from run to run.ctest --parallel 4on a full build of the last commit: 1137 of 1137 pass.guest_environment,guest_getoptandguest_hostnamepass 3/3 at each. At no commit does a rebuilt library lose an exported name.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchreports no overlap with open pull requests.Linux (same commit, WSL2 Ubuntu 24.04, GCC 13.3.0, Release):
libsbuilds, andguest_environmentandguest_getoptpass 3/3, so the guest no longer sees the Linux host's variables either.Not checked on a console. Whether the console starts a title with any environment variables at all is not measured; the debt note says so.
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)Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T02:00:22Z.
Cross-check on Windows: #5772 head
69715e839merged ontomain6239ceffc; the merge is clean.Host: Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, NVIDIA RTX 4070 (Ryzen 7 5700X).
cmake --build build -- -k 0) andlibsboth succeed, with no new warnings.--repeat until-fail:3: all 11 pass 3/3 (33 of 33 runs):guest_environment,guest_getopt,guest_hostname,guest_call_trace,guest_call_trace_abort,guest_font,guest_font_writing_line,guest_audio_in_capture,guest_audio_in_no_device,file_streamsandguest_posix_filesystem.ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip': 808 tests. 800 pass, including the 2 skipped (agc_host_import_sparse,guest_video_out_wqhd_detection_no_vulkan). 8 time out under host load and all 8 pass when run alone:conventions_function_bodies,conventions_ci_gate,debt_split,hardware_oracle_compare,conventions_bom_shebang,guest_raise_exception,guest_none_relocationsandtls_function_coverage_register_address_loads. Plainmainon the same host lost 12 the same way, and all 12 pass alone.Titles. Catalog releases,
relinker --windows --registry unused-filter=0. 60 s per run, with the display on.HOME=C:\Users\<user>was set in the host for every run. All libraries come from one build: main's or the merge's.main0xFFFFFFFFafter 5.3 s, no framePS5MC (Kodi 22) | FPS: 5.76 (211)0xFFFFFFFFafter 3.2 s, no framePS5MC (Kodi 22) | FPS: 11.89 (464)PS5MC on
main(download0/ps5-opengl.log):That run also created
C:\Users\<user>\.kodion the host (userdata/guisettings.xml,profiles.xml,temp/kodi.log).PS5MC with the PR:
The run continues, with no
XBMC_Run returned.Control:
mainwithHOMEremoved from the host environment is still running at 60 s (PS5MC (Kodi 22) | FPS: 18.60 (873),HOME=/data/ps5mc/kodi22).ProsperoRadio and ProsperoTV have no stop line with either build. The last lines are the periodic
[RADIO] frames=600 ...and[TV] frames=600 .... Frame counts follow host load, not the PR. In the third pair the PR ran first on an idle host and the counts match: Radio 3369 vs 3377 (59.95 / 59.96 fps), TV 672 vs 680.Verdict: confirmed. With
HOMEset, PS5MC exits withXBMC_Run returned -1onmainand keeps running with this PR. No regression in the tests, the suite, ProsperoRadio or ProsperoTV.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-15T02:38:27Z.
Linux evidence for PS5MC (PPSA99420, catalog release): WSL2 Ubuntu 24.04, GCC 13.3.0,
main6239ceffcwith and without this PR's two code files (unchanged onmainsince), relinked with--to-intel,HOME=/home/davidas in any Linux shell, 40 s, two runs each:main: it logs[kodi-ps5] HOME already set to /home/davidand Kodi mapsspecial://home/ is mapped to: /home/david/.kodi, the host user's home, which is not a guest folder. It keeps running, unlike on Windows, where the same inheritedHOMEmakes it exit with -1.HOME already setline is gone and Kodi mapsspecial://home/ is mapped to: /data/ps5mc/kodi22/.kodi, the title's own data folder.Nothing was written to the host's
/home/david/.kodi.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:09:27Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
docs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/tests/GuestEnvironment.cppdocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-16T08:46:46Z.
The title on Windows, for the side that only had a build and tests: with this PR PS5MC reaches Kodi's home screen from a shell with
HOMEset.Setup: Windows 11 Home 26300, AMD Radeon 860M (driver 32.0.13058.8001), WinLibs GCC 15.2.0, Release. Started from a Git for Windows bash, so
HOME=/c/Users/leandis in the host environment. Catalog PPSA99420 1.2, relinked with--windows.main5d9dcc42dagainst this head69715e839merged onto it (14e8dff43, clean merge). 60 s runs, no input.main[kodi-ps5] HOME already set to C:\Users\leand, then Kodi opensC:\Users\leand/.kodi/userdata/..., logs[kodi-ps5] exiting, and the process ends after 1 s with exit code0xffffffff[kodi-ps5] /data/ps5mc/kodi22 is usable,HOME=/data/ps5mc/kodi22; alive at 60 s, 19.2 and 19.5 FPS on the window counter, closed normallyA frame dump from a third 45 s run shows Kodi 22's home screen (Estuary: main menu from TV to Weather, clock, the weather-provider prompt). The
mainrun also left aC:\Users\<name>\.kodifolder in the host user profile, which this PR avoids as well.Not tested: Linux (covered above by @DavidSamir), NVIDIA.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T18:24:57Z.
Checked the diff,
guest_environment(fails withEnvironment.cppfrom main, passes with the change) and the libc/libs ctest scope; the runtime's own settings are read with the hostgetenv, so they are unaffected. Matches libkernel's emptyenviron(#2090) and the Windows/Linux runs of PS5MC reported in the thread; merging.