Repository navigation
fix(linux): enter the guest entry on a main stack at the console's address - #7532
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
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.
|
|
Thanks, the design looks right, and the stub, the 16-byte alignment and the bounds query all check out. One small safety change before merge: On order: as discussed on #7594, this lands first and #7594 rebases with its MXCSR set before |
|
I reproduced Dean's collision concern and tested the requested exclusive call locally on exact head With soft
The local production change is only: DoMapAnon(&mapping, bytes, 3, GUEST_MAP_FIXED, PS5_PAGE_SIZE, true)Both refused cases report Boundary/guard checks, on both the submitted head and the local proposal: an extension of
All 14 processes pass. Every reported upper bound is
I restored the submitted source; the worktree is clean. The exclusive call above is a tested local proposal, not a pushed change. Generated-input/runtime-helper checks only: no Mirage/title, Windows, ASan-offset or full-suite result. |
|
@oneandonlydean Sorry for the slow reply, I missed this comment. Done in cdfddff, on top of the existing head:
Linux (Arch, kernel 7.2.11, GCC 16.2.1, Release, RX 9070 XT with RADV, Mesa 26.2.5): full CTest 1439 of 1440, the failure being @simonbbby Thanks for reproducing it and testing the exclusive call; the new case is your in-stack sentinel row. |
|
Verified on Windows with MinGW GCC 15.2.0: As a negative control, the previous Prepared with AI assistance. |
|
Merged current |
|
@hugodearaujo a title that needs this: ProsperoCraft (PPSA99874 01.000.117), the catalog's Minecraft Java launcher. Its Java 25 HotSpot runtime
So this PR is what lets the JVM guard its main thread's stack; #9684 does the same for the threads it creates. AI-assisted: yes (Claude Code) |
|
@milescoviello thank you, that is the first title I know of that this PR changes on Linux beyond the ones in Tested. I added your ProsperoCraft runs to the description (with #9684 for the threads it creates). |
# Conflicts: # core/libs/prx/libkernel/CMakeLists.txt
# Conflicts: # core/relinker/elfpatcher/src/general/EntryStubBuilder.cpp
# Conflicts: # docs/dev/debt/libkernel.md
|
Observed a narrow startup regression with Outer Wilds (PPSA08102) on plain upstream
For the control, an The faulting instruction bytes uniquely match file offset The actual relinker command was Follow-up: the argument-relocation-only control still exits 139. A deterministic CPU fixture now confirms a separate defect: call Native follow-through: upstream fix #15436, head |
|
@JJenkx thanks for tracking this down, and sorry for the regression. My change moved execution to the guest stack but never refreshed a thread record that was adopted before the move, so I checked #15436 locally on its head
I didn't run Outer Wilds or any other title with it. |
What
On Linux the relinked executable entered the title's entry point on the host process stack, near the top of the address space (
0x7ffc...). On the console a process's main thread stack sits inside the user area: a payload on a PS5 (FW 13.60) reports its main thread stack at0x7eedfc000-0x7eeffc000throughpthread_attr_get_np, right above a worker thread's stack at0x7eede8000-0x7eedf8000.When the executable loads
libkernel.prx, its Linux entry stub now callsEnterGuestMainStack_nid_no_patch(libkernel) through aGLOB_DATslot, with the initial stack pointer and the entry point.0x7eeffc000, moved by the arena's offset in ASan builds). Below it is a 16 KiB guard. Its size is the host'sRLIMIT_STACK(8 MiB when unlimited, at most 1 GiB).sceKernelIsStackand the main thread's attributes report that range.libkernel.prxkeeps the stub as it was.#3965 does the same on Windows, with a helper in libc that is built only there.
Title
Assassin's Creed Mirage (PPSA13960, 01.007.000) first stops on
mainat a kevent read event, which #6343 implements. With #6343 applied, it stops with SIGSEGV on the main thread 6 s after start, with nothing in the log.pointer >> 28(eboot0x570b9c1-0x570b9ec).0x7fffffff42c8gives index0x7ffff, so the lookup reads past the table and dereferences what it finds there (0x8232f00).0x7eeffc000, which gives index0x7e.With this PR and #6343 it passes that point and goes through its start-up screens (photosensitivity warning, Ubisoft logo, intro video, disclaimer, autosave notice; screenshots from two runs) to the next unimplemented path:
Tested
mainf911371 merged in (67658c0): only the debt file conflicted, wheremainadded an entry next to this PR's; both are kept. The same test set passes 93 of 93.maina5939f1 merged in (003002a):EntryStubBuilder.cppconflicted with fix(elfpatcher): reject an entry-stub rel32 distance that only fits after a 64-bit wrap #12554, which checks the entry call's rel32 throughSignedDistanceso an entry point more than 2^63 away is rejected instead of wrapping. The resolution keeps this PR's stub (thelea/indirect call through the helper slot when there is one) and runs its sharedappendRel32throughSignedDistance, so both rel32 fields get fix(elfpatcher): reject an entry-stub rel32 distance that only fits after a 64-bit wrap #12554's check; fix(elfpatcher): reject an entry-stub rel32 distance that only fits after a 64-bit wrap #12554's new test passesstd::nulloptfor the slot. The same test set as below passes 93 of 93.mainbb04a4f merged in (7348d46):core/libs/prx/libkernel/CMakeLists.txtconflicted with fix(libkernel): move the macOS main stack out of the guest arena #12126, which registers the macOS-onlyguest_main_stack_movetest next to this PR's Linux-onlyguest_main_stack; both registrations are kept. With the same test set as below (ctest -j8 --output-on-failure),mainbb04a4f passes 91 of 91 and this head 93 of 93, the two extra tests beingguest_main_stackandlinux_main_stack_entry.main74acfad merged in (0c55cfc), without conflicts: the overlaps with feat(relinker): support --trace-imports for Linux output #7417's trace-import symbol, relocation and prologue inLinuxElfPatcher::Patchand with the entries fix(libkernel): prevent 100% CPU busy-spinning on pthread yield on Windows #8061, feat(libkernel): implement __tls_get_addr #9059 and fix(libkernel): measure the TSC frequency on one CPU #9461 indocs/dev/debt/libkernel.mdwere already resolved in the earlier merge (both undefined symbols and bothGLOB_DATrelocations are kept, the trace import's first, and the trace prologue falls through to this entry stub). The PR's own diff is unchanged.PS5 (FW 13.60): a payload prints the address of a local in
main, itspthread_attr_get_npstack range, a worker thread's range, and amallocand anmmapaddress:Linux (Arch, kernel 7.2.11, GCC 16.2.1, Release), on
main74acfad and on this head,ctest -j8 --output-on-failureofguest_main_stack,linux_main_stack_entry,entry_stub,public_headersand its 64 compile batches,guest_kernel_is_stack,guest_kernel_stack_protect,guest_pthread_attr,guest_pthread_attr_stack,guest_pthread_stack,guest_pthread_start,guest_module_argsand thelinux_*relinker tests (linux_trace_importsamong them):mainpasses 90 of 90 and this head 92 of 92, the two more being the new tests.guest_main_stackenters a test entry through the helper and checks the argument; thatsceKernelIsStackreports a range ending at0x7eeffc000that holds the entry's locals; the guard page below it; that a guest thread created there gets a separate stack; and that an entry over an existing guest mapping is refused and leaves the mapping as it was. WithHostStackLimitsas onmainit fails atGuestMainStack.cpp:67, the check that the reported range ends at0x7eeffc000.linux_main_stack_entryrelinks an executable that loadslibkernel.prxand one that does not, and checks the stub and the imports of both. On Linux x86-64 it also runs the first with a testlibkernel.prxwhose helper calls the entry point; the entry exits with itsargcplus 41. With thelibkernel.prxcheck forced off, the first executable gets noDT_RELAentry for the helper's slot and the test fails (KeyError: 7inhelper_slots).entry_stubchecks both stubs.Full CTest with
-j8,ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1on the same machine (AMD Radeon RX 9070 XT, RADV GFX1201, Mesa 26.2.5):main74acfad passes 2396 of 2431 tests and this head 2398 of 2433. On both, the same 34 tests are skipped andagc_driver_tessellationsegfaults (agc_driver_tessellation segfaults on RADV with Mesa 26.2+: nir_opt_varyings corrupts the TCS input offset's use list (Mesa bug) #5444).Reported by milescoviello on this PR (Linux, RTX 4070 Ti,
main750cf6c with fix(libkernel): answer vm.loadavg with the host's load averages #12436): ProsperoCraft (PPSA99874 01.000.117), a Java launcher whose HotSpot runtimemprotects guard pages at the bottom of each thread's stack, aborts at start-up on the primordial thread (Native memory allocation (mprotect) failed to protect 49152 bytes), whose stack is the host process's. With this PR (head 0c55cfc) the primordial thread gets past it, and with fix(libkernel): start thread stacks on a 16 KiB page boundary on Linux #9684 as well, which does the same for the threads the title creates, it runs the full 120 s.Earlier heads, not repeated on this base:
main0d078f75d, each title relinked twice from the same ELF with the same options, with this PR's relinker (for A built with thelibkernel.prxcheck forced off, so the stub ismain's) and this PR's runtime libraries. Assassin's Creed Mirage, with feat(libkernel): accept a kevent read event on descriptor 0 #6343'sKqueue.cppchange: A stops with SIGSEGV 6 s after start, as onmain; B reaches the cube texture error above 120 s after start. Hades (PPSA03355, 01.003.000), CONTROL Resonant (PPSA34547, 01.300.300), Alan Wake 2 (PPSA02572, 01.200.007) and ASTRO BOT (PPSA21567, 01.018.000) reach the same screens in A and B.main137a8fa merged in (deec037), Assassin's Creed Mirage, 20 s runs: onmain, 7 of 22 runs stop with SIGSEGV 3 s after start at eboot0x570b9ec, and 12 of 12 with this PR get past start-up.BUILD_TESTING=ON, onmain0d078f75d: of 1479 tests, 924 pass, 554 are skipped (the VM has no GPU) andguest_positioned_closefails, as it does intermittently onmainthere (5 of 30 runs). Windows does not use this stub.tools/check_conventions.py --base origin/mainpasses andgit diff --checkis clean. Of the overlaps the earlier description discussed, feat(relinker): support --trace-imports for Linux output #7417 and fix(libkernel): keep a protected host stack's guard page, and protect the Linux main stack #6443 are merged and part of this base; fix(windows): enter guest startup on an arena-backed main stack #3965's head 8029f87 still merges with this branch without conflicts, and fix(relinker): initialize main guest MXCSR at entry #7594 rebases after this one, as agreed on fix(relinker): initialize main guest MXCSR at entry #7594.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)